summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmir Hammad <amir.hammad@hotmail.com>2016-09-05 20:10:17 +0200
committerAmir Hammad <amir.hammad@hotmail.com>2016-09-11 13:31:47 +0200
commita75535e52b9500a82cd0e9aebe6a987b68390895 (patch)
tree6ac0b048a6fc90d3812d9dd1e3336bb7f0d93249
parent1d08641a15eef8fb0590113c96e3f985f7e32a23 (diff)
downloadsecure-hid-a75535e52b9500a82cd0e9aebe6a987b68390895.tar.gz
secure-hid-a75535e52b9500a82cd0e9aebe6a987b68390895.tar.bz2
secure-hid-a75535e52b9500a82cd0e9aebe6a987b68390895.zip
core: Simplify device removes
Signed-off-by: Amir Hammad <amir.hammad@hotmail.com>
-rw-r--r--src/usbh_core.c24
-rw-r--r--src/usbh_driver_hub.c16
2 files changed, 15 insertions, 25 deletions
diff --git a/src/usbh_core.c b/src/usbh_core.c
index d6f6ff4..dbdec0c 100644
--- a/src/usbh_core.c
+++ b/src/usbh_core.c
@@ -50,6 +50,16 @@ static bool enumeration(void)
return usbh_data.enumeration_run;
}
+static void device_remove(usbh_device_t *dev)
+{
+ if (dev->drv && dev->drvdata) {
+ dev->drv->remove(dev->drvdata);
+ }
+ dev->address = -1;
+ dev->drv = 0;
+ dev->drvdata = 0;
+}
+
/**
*
*/
@@ -146,6 +156,7 @@ static void device_register(void *descriptors, uint16_t descriptors_len, usbh_de
k += desc_len;
}
LOG_PRINTF("Device driver isn't compatible with this device\n");
+ device_remove(dev);
} else {
LOG_PRINTF("No compatible driver has been found for interface #%d\n", iface->bInterfaceNumber);
}
@@ -630,18 +641,9 @@ void usbh_poll(uint32_t time_curr_us)
case USBH_POLL_STATUS_DEVICE_DISCONNECTED:
{
- // Device disconnected
- if (usbh_device[0].drv && usbh_device[0].drvdata) {
- usbh_device[0].drv->remove(usbh_device[0].drvdata);
- }
- usbh_device[0].drv = 0;
- usbh_device[0].drvdata = 0;
-
uint32_t i;
- for (i = 1; i < USBH_MAX_DEVICES; i++) {
- usbh_device[i].address = -1;
- usbh_device[i].drv = 0;
- usbh_device[i].drvdata = 0;
+ for (i = 0; i < USBH_MAX_DEVICES; i++) {
+ device_remove(&usbh_device[i]);
}
}
break;
diff --git a/src/usbh_driver_hub.c b/src/usbh_driver_hub.c
index 1beed01..c185b6a 100644
--- a/src/usbh_driver_hub.c
+++ b/src/usbh_driver_hub.c
@@ -835,23 +835,11 @@ static void remove(void *drvdata)
hub_device_t *hub = (hub_device_t *)drvdata;
uint8_t i;
- // Call fast... to avoid polling
hub->state = 0;
hub->endpoint_in_address = 0;
hub->busy = 0;
- for (i = 1; i < USBH_HUB_MAX_DEVICES + 1; i++) {
- if (hub->device[i]) {
- if (hub->device[i]->drv && hub->device[i]->drvdata) {
- if (hub->device[i]->drv->remove != remove) {
- LOG_PRINTF("\t\t\t\tHUB REMOVE %d\n",hub->device[i]->address);
- hub->device[i]->drv->remove(hub->device[i]->drvdata);
- }
- }
- hub->device[i] = 0;
- }
- hub->device[0]->drv = 0;
- hub->device[0]->drvdata = 0;
- hub->device[0] = 0;
+ for (i = 0; i < USBH_HUB_MAX_DEVICES + 1; i++) {
+ hub->device[i] = 0;
}
}