From 3493c1c0878db2b2c367fcdd9e69e4dcc104cad6 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Tue, 30 Aug 2016 04:02:27 +0200 Subject: fix bmRequestType field - use of defines Signed-off-by: Amir Hammad --- src/usbh_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index e1076cd..5e35da9 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -337,7 +337,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ struct usb_setup_data setup_data; - setup_data.bmRequestType = 0b10000000; + setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; setup_data.wValue = USB_DT_DEVICE << 8; setup_data.wIndex = 0; @@ -394,7 +394,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ dev->packet_size_max0 = ddt->bMaxPacketSize0; struct usb_setup_data setup_data; - setup_data.bmRequestType = 0b10000000; + setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; setup_data.wValue = USB_DT_CONFIGURATION << 8; setup_data.wIndex = 0; @@ -457,7 +457,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; struct usb_setup_data setup_data; LOG_PRINTF("WRITE: LEN: %d", cdt->wTotalLength); - setup_data.bmRequestType = 0b10000000; + setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; setup_data.wValue = USB_DT_CONFIGURATION << 8; setup_data.wIndex = 0; @@ -573,7 +573,7 @@ void device_enumeration_start(usbh_device_t *dev) struct usb_setup_data setup_data; - setup_data.bmRequestType = 0b00000000; + setup_data.bmRequestType = USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; setup_data.bRequest = USB_REQ_SET_ADDRESS; setup_data.wValue = address; setup_data.wIndex = 0; -- cgit From e0fbb799bd0dcf8592d08d6a8734e0afcb7e2b81 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Thu, 1 Sep 2016 10:38:18 +0200 Subject: usbh_core refactor Signed-off-by: Amir Hammad --- src/usbh_core.c | 182 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 82 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 5e35da9..cd631a4 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -172,10 +172,9 @@ void usbh_init(const void *low_level_drivers[], const usbh_dev_driver_t * const usbh_data.lld_drivers = (const usbh_low_level_driver_t **)low_level_drivers; usbh_data.dev_drivers = device_drivers; - // TODO: init structures uint32_t k = 0; while (usbh_data.lld_drivers[k]) { - LOG_PRINTF("DRIVER %d\n", k); + LOG_PRINTF("Initialization low-level driver with index=%d\n", k); usbh_device_t * usbh_device = ((usbh_generic_data_t *)(usbh_data.lld_drivers[k])->driver_data)->usbh_device; @@ -186,7 +185,6 @@ void usbh_init(const void *low_level_drivers[], const usbh_dev_driver_t * const usbh_device[i].drv = 0; usbh_device[i].drvdata = 0; } - LOG_PRINTF("DRIVER %d", k); usbh_data.lld_drivers[k]->init(usbh_data.lld_drivers[k]->driver_data); k++; @@ -289,17 +287,22 @@ usbh_device_t *usbh_get_free_device(const usbh_device_t *dev) return 0; } -static void device_enumeration_terminate(usbh_device_t *dev) +static void device_enumeration_finish(usbh_device_t *dev) { reset_enumeration(); - dev->state = 0; + dev->state = USBH_ENUM_STATE_FIRST; +} + +static void device_enumeration_terminate(usbh_device_t *dev) +{ dev->address = -1; + device_enumeration_finish(dev); } -/* Do not call this function directly, - * only via callback passing into low-level function - * If you must, call it carefully ;) - */ +#define CONTINUE_WITH(en) \ + dev->state = en;\ + device_enumerate(dev, cb_data); + static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) { const usbh_low_level_driver_t *lld = dev->lld; @@ -308,12 +311,12 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ uint8_t state_start = dev->state; // Detection of hang // LOG_PRINTF("\nSTATE: %d\n", state); switch (dev->state) { - case 1: + case USBH_ENUM_STATE_SET_ADDRESS_EMPTY_READ: { switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: - dev->state++; - LOG_PRINTF("::%d::", dev->address); + dev->state = USBH_ENUM_STATE_SET_ADDRESS_EMPTY_READ_COMPLETE; + LOG_PRINTF("Assigning address: %d\n", usbh_data.address_temporary); device_xfer_control_read(0, 0, device_enumerate, dev); break; @@ -327,14 +330,27 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case 2: + case USBH_ENUM_STATE_SET_ADDRESS_EMPTY_READ_COMPLETE: switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: if (dev->address == 0) { dev->address = usbh_data.address_temporary; - LOG_PRINTF("ADDR: %d\n", dev->address); + LOG_PRINTF("Assigned address: %d\n", dev->address); } + CONTINUE_WITH(USBH_ENUM_STATE_DEVICE_DT_READ_SETUP); + break; + case USBH_PACKET_CALLBACK_STATUS_EFATAL: + case USBH_PACKET_CALLBACK_STATUS_EAGAIN: + case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + device_enumeration_terminate(dev); + ERROR(cb_data.status); + break; + } + break; + + case USBH_ENUM_STATE_DEVICE_DT_READ_SETUP: + { struct usb_setup_data setup_data; setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; @@ -343,36 +359,24 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ setup_data.wIndex = 0; setup_data.wLength = USB_DT_DEVICE_SIZE; - dev->state++; + dev->state = USBH_ENUM_STATE_DEVICE_DT_READ; device_xfer_control_write_setup(&setup_data, sizeof(setup_data), device_enumerate, dev); - break; - - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: - device_enumeration_terminate(dev); - ERROR(cb_data.status); - break; } break; - case 3: + + case USBH_ENUM_STATE_DEVICE_DT_READ: { switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: - dev->state++; + dev->state = USBH_ENUM_STATE_DEVICE_DT_READ_COMPLETE; device_xfer_control_read(&usbh_buffer[0], USB_DT_DEVICE_SIZE, device_enumerate, dev); break; case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - dev->state = 2; - - // WARNING: Recursion - // .. but should work - cb_data.status = USBH_PACKET_CALLBACK_STATUS_OK; - device_enumerate(dev, cb_data); + CONTINUE_WITH(USBH_ENUM_STATE_DEVICE_DT_READ_SETUP); break; case USBH_PACKET_CALLBACK_STATUS_EFATAL: @@ -384,7 +388,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case 4: + case USBH_ENUM_STATE_DEVICE_DT_READ_COMPLETE: { switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: @@ -392,17 +396,9 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ struct usb_device_descriptor *ddt = (struct usb_device_descriptor *)&usbh_buffer[0]; dev->packet_size_max0 = ddt->bMaxPacketSize0; - struct usb_setup_data setup_data; - - setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; - setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; - setup_data.wValue = USB_DT_CONFIGURATION << 8; - setup_data.wIndex = 0; - setup_data.wLength = ddt->bMaxPacketSize0;//USB_DT_CONFIGURATION_SIZE; - - dev->state++; - device_xfer_control_write_setup(&setup_data, sizeof(setup_data), - device_enumerate, dev); + LOG_PRINTF("Found device with vid=0x%04x pid=0x%04x\n", ddt->idVendor, ddt->idProduct); + LOG_PRINTF("class=0x%02x subclass=0x%02x protocol=0x%02x\n", ddt->bDeviceClass, ddt->bDeviceSubClass, ddt->bDeviceProtocol); + CONTINUE_WITH(USBH_ENUM_STATE_CONFIGURATION_DT_HEADER_READ_SETUP) } break; @@ -411,12 +407,10 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ struct usb_device_descriptor *ddt = (struct usb_device_descriptor *)&usbh_buffer[0]; dev->packet_size_max0 = ddt->bMaxPacketSize0; - dev->state = 2; - - // WARNING: Recursion - // .. but should work - cb_data.status = USBH_PACKET_CALLBACK_STATUS_OK; - device_enumerate(dev, cb_data); + CONTINUE_WITH(USBH_ENUM_STATE_DEVICE_DT_READ_SETUP); + } else { + device_enumeration_terminate(dev); + ERROR(cb_data.status); } break; @@ -429,11 +423,27 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case 5: + case USBH_ENUM_STATE_CONFIGURATION_DT_HEADER_READ_SETUP: + { + struct usb_setup_data setup_data; + + setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_DEVICE; + setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; + setup_data.wValue = USB_DT_CONFIGURATION << 8; + setup_data.wIndex = 0; + setup_data.wLength = dev->packet_size_max0; + + dev->state = USBH_ENUM_STATE_CONFIGURATION_DT_HEADER_READ; + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), + device_enumerate, dev); + } + break; + + case USBH_ENUM_STATE_CONFIGURATION_DT_HEADER_READ: { switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: - dev->state++; + dev->state = USBH_ENUM_STATE_CONFIGURATION_DT_HEADER_READ_COMPLETE; device_xfer_control_read(&usbh_buffer[USB_DT_DEVICE_SIZE], dev->packet_size_max0, device_enumerate, dev); break; @@ -448,38 +458,20 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case 6: + case USBH_ENUM_STATE_CONFIGURATION_DT_HEADER_READ_COMPLETE: { switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: - { - struct usb_config_descriptor *cdt = - (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; - struct usb_setup_data setup_data; - LOG_PRINTF("WRITE: LEN: %d", cdt->wTotalLength); - setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; - setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; - setup_data.wValue = USB_DT_CONFIGURATION << 8; - setup_data.wIndex = 0; - setup_data.wLength = cdt->wTotalLength; - - dev->state++; - device_xfer_control_write_setup(&setup_data, sizeof(setup_data), - device_enumerate, dev); - } + CONTINUE_WITH(USBH_ENUM_STATE_CONFIGURATION_DT_READ_SETUP); break; case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: if (cb_data.transferred_length >= USB_DT_CONFIGURATION_SIZE) { struct usb_config_descriptor *cdt = (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; - if (cb_data.transferred_length <= cdt->wTotalLength) { - dev->state = 8; - - // WARNING: Recursion - // .. but should work - cb_data.status = USBH_PACKET_CALLBACK_STATUS_OK; - device_enumerate(dev, cb_data); + if (cb_data.transferred_length == cdt->wTotalLength) { + LOG_PRINTF("Configuration descriptor read complete. length: %d\n", cdt->wTotalLength); + CONTINUE_WITH(USBH_ENUM_STATE_FIND_DRIVER); } } break; @@ -493,14 +485,32 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case 7: + case USBH_ENUM_STATE_CONFIGURATION_DT_READ_SETUP: + { + struct usb_config_descriptor *cdt = + (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; + struct usb_setup_data setup_data; + LOG_PRINTF("Getting complete configuration descriptor of length: %d bytes\n", cdt->wTotalLength); + setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_DEVICE; + setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; + setup_data.wValue = USB_DT_CONFIGURATION << 8; + setup_data.wIndex = 0; + setup_data.wLength = cdt->wTotalLength; + + dev->state = USBH_ENUM_STATE_CONFIGURATION_DT_READ; + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), + device_enumerate, dev); + } + break; + + case USBH_ENUM_STATE_CONFIGURATION_DT_READ: { switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: { struct usb_config_descriptor *cdt = (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; - dev->state++; + dev->state = USBH_ENUM_STATE_CONFIGURATION_DT_READ_COMPLETE; device_xfer_control_read(&usbh_buffer[USB_DT_DEVICE_SIZE], cdt->wTotalLength, device_enumerate, dev); } @@ -516,18 +526,16 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case 8: + case USBH_ENUM_STATE_CONFIGURATION_DT_READ_COMPLETE: { switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: { struct usb_config_descriptor *cdt = (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; - LOG_PRINTF("TOTAL_LENGTH: %d\n", cdt->wTotalLength); - device_register(usbh_buffer, cdt->wTotalLength + USB_DT_DEVICE_SIZE, dev); - dev->state++; + LOG_PRINTF("Configuration descriptor read complete. length: %d\n", cdt->wTotalLength); + CONTINUE_WITH(USBH_ENUM_STATE_FIND_DRIVER); - reset_enumeration(); } break; @@ -542,6 +550,16 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; + case USBH_ENUM_STATE_FIND_DRIVER: + { + struct usb_config_descriptor *cdt = + (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; + device_register(usbh_buffer, cdt->wTotalLength + USB_DT_DEVICE_SIZE, dev); + + device_enumeration_finish(dev); + } + break; + default: LOG_PRINTF("Error: Unknown state "__FILE__"/%d\n", __LINE__); break; @@ -555,7 +573,6 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ void device_enumeration_start(usbh_device_t *dev) { set_enumeration(); - dev->state = 1; // save address uint8_t address = dev->address; @@ -571,6 +588,7 @@ void device_enumeration_start(usbh_device_t *dev) LOG_PRINTF("\n\n\n ENUMERATION OF DEVICE@%d STARTED \n\n", address); + dev->state = USBH_ENUM_STATE_SET_ADDRESS; struct usb_setup_data setup_data; setup_data.bmRequestType = USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; -- cgit From 4aa69b4eaf44757aa71997e4a59f0889ea6e23f4 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Thu, 1 Sep 2016 14:16:17 +0200 Subject: make usbh_packet->data of union type out: const void * in: void * Signed-off-by: Amir Hammad --- src/usbh_core.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index cd631a4..60baf64 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -196,11 +196,11 @@ void usbh_init(const void *low_level_drivers[], const usbh_dev_driver_t * const * NEW ENUMERATE * */ -void device_xfer_control_write_setup(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +void device_xfer_control_write_setup(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; - packet.data = data; + packet.data.out = data; packet.datalen = datalen; packet.address = dev->address; packet.endpoint_address = 0; @@ -216,11 +216,11 @@ void device_xfer_control_write_setup(void *data, uint16_t datalen, usbh_packet_c LOG_PRINTF("WR-setup@device...%d \n", dev->address); } -void device_xfer_control_write_data(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +void device_xfer_control_write_data(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; - packet.data = data; + packet.data.out = data; packet.datalen = datalen; packet.address = dev->address; packet.endpoint_address = 0; @@ -240,7 +240,7 @@ void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback { usbh_packet_t packet; - packet.data = data; + packet.data.in = data; packet.datalen = datalen; packet.address = dev->address; packet.endpoint_address = 0; -- cgit From 28ccd32608bb3daf0f8137eb1521f382f69d120d Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Thu, 1 Sep 2016 16:07:48 +0200 Subject: core: adjust search for the device driver in finding compatibility there are 3 steps how to find out whether the provided device driver supports currently inserted device. 1. compare fields in the driver info structure If there is a match (all CHECK_PARTIAL_COMPATIBILITY() macros return true), we proceed to step 2. If all device drivers are searched, but none is compatible -> that means no device driver is available for currently inserted device. 2. try to call driver's init function. If it return non-null pointer to data we may proceed to the step 3. Otherwise, we continue in the loop handling step 1. 3. call analyze descriptor for all descriptors. When it returns true, it means success and that the driver supports current device. From now on poll function is allowed to be called. If all descriptors were provided to the analyze_descriptor method and it still returns false, it means device driver is not initialized and should not be used with this device. Signed-off-by: Amir Hammad --- src/usbh_core.c | 57 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 60baf64..d6f6ff4 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -53,7 +53,7 @@ static bool enumeration(void) /** * */ -static const usbh_dev_driver_t *find_driver(const usbh_dev_driver_info_t * device_info) +static bool find_driver(usbh_device_t *dev, const usbh_dev_driver_info_t * device_info) { #define CHECK_PARTIAL_COMPATIBILITY(what) \ @@ -63,7 +63,6 @@ static const usbh_dev_driver_t *find_driver(const usbh_dev_driver_info_t * devic continue;\ } - int i = 0; while (usbh_data.dev_drivers[i]) { @@ -77,9 +76,16 @@ static const usbh_dev_driver_t *find_driver(const usbh_dev_driver_info_t * devic CHECK_PARTIAL_COMPATIBILITY(idVendor); CHECK_PARTIAL_COMPATIBILITY(idProduct); - return usbh_data.dev_drivers[i]; + dev->drv = usbh_data.dev_drivers[i]; + dev->drvdata = dev->drv->init(dev); + if (!dev->drvdata) { + LOG_PRINTF("Unable to initialize device driver at index %d\n", i); + i++; + continue; + } + return true; } - return 0; + return false; #undef CHECK_PARTIAL_COMPATIBILITY } @@ -122,14 +128,26 @@ static void device_register(void *descriptors, uint16_t descriptors_len, usbh_de device_info.ifaceClass = iface->bInterfaceClass; device_info.ifaceSubClass = iface->bInterfaceSubClass; device_info.ifaceProtocol = iface->bInterfaceProtocol; - const usbh_dev_driver_t *driver = find_driver(&device_info); - if (driver) { - dev->drv = driver; - dev->drvdata = dev->drv->init(dev); - if (!dev->drvdata) { - LOG_PRINTF("CANT TOUCH THIS"); + if (find_driver(dev, &device_info)) { + int k = 0; + while (k < descriptors_len) { + desc_len = buf[k]; + void *drvdata = dev->drvdata; + LOG_PRINTF("[%d]", buf[k+1]); + if (dev->drv->analyze_descriptor(drvdata, &buf[k])) { + LOG_PRINTF("Device Initialized\n"); + return; + } + + if (desc_len == 0) { + LOG_PRINTF("Problem occured while parsing complete configuration descriptor"); + return; + } + k += desc_len; } - break; + LOG_PRINTF("Device driver isn't compatible with this device\n"); + } else { + LOG_PRINTF("No compatible driver has been found for interface #%d\n", iface->bInterfaceNumber); } } break; @@ -142,23 +160,6 @@ static void device_register(void *descriptors, uint16_t descriptors_len, usbh_de return; } i += desc_len; - - } - - if (dev->drv && dev->drvdata) { - // analyze descriptors - LOG_PRINTF("ANALYZE"); - i = 0; - while (i < descriptors_len) { - desc_len = buf[i]; - void *drvdata = dev->drvdata; - LOG_PRINTF("[%d]",buf[i+1]); - if (dev->drv->analyze_descriptor(drvdata, &buf[i])) { - LOG_PRINTF("Device Initialized\n"); - return; - } - i += desc_len; - } } LOG_PRINTF("Device NOT Initialized\n"); } -- cgit From a75535e52b9500a82cd0e9aebe6a987b68390895 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Mon, 5 Sep 2016 20:10:17 +0200 Subject: core: Simplify device removes Signed-off-by: Amir Hammad --- src/usbh_core.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/usbh_core.c') 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; -- cgit From 58fec7a17ceb6814d64e702e7829556c3ece01e4 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Mon, 5 Sep 2016 19:48:56 +0200 Subject: Drop need for the set configuration request in dev drivers Signed-off-by: Amir Hammad --- src/usbh_core.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index dbdec0c..7071281 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -483,7 +483,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; if (cb_data.transferred_length == cdt->wTotalLength) { LOG_PRINTF("Configuration descriptor read complete. length: %d\n", cdt->wTotalLength); - CONTINUE_WITH(USBH_ENUM_STATE_FIND_DRIVER); + CONTINUE_WITH(USBH_ENUM_STATE_SET_CONFIGURATION_SETUP); } } break; @@ -546,7 +546,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ struct usb_config_descriptor *cdt = (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; LOG_PRINTF("Configuration descriptor read complete. length: %d\n", cdt->wTotalLength); - CONTINUE_WITH(USBH_ENUM_STATE_FIND_DRIVER); + CONTINUE_WITH(USBH_ENUM_STATE_SET_CONFIGURATION_SETUP); } break; @@ -562,6 +562,60 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; + case USBH_ENUM_STATE_SET_CONFIGURATION_SETUP: + { + struct usb_config_descriptor *cdt = + (struct usb_config_descriptor *)&usbh_buffer[USB_DT_DEVICE_SIZE]; + + struct usb_setup_data setup_data; + + setup_data.bmRequestType = USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; + setup_data.bRequest = USB_REQ_SET_CONFIGURATION; + setup_data.wValue = cdt->bConfigurationValue; + setup_data.wIndex = 0; + setup_data.wLength = 0; + + dev->state = USBH_ENUM_STATE_SET_CONFIGURATION_EMPTY_READ; + + device_xfer_control_write_setup(&setup_data, sizeof(setup_data), device_enumerate, dev); + } + break; + + case USBH_ENUM_STATE_SET_CONFIGURATION_EMPTY_READ: + { + switch (cb_data.status) { + case USBH_PACKET_CALLBACK_STATUS_OK: + dev->state = USBH_ENUM_STATE_SET_CONFIGURATION_COMPLETE; + device_xfer_control_read(0, 0, device_enumerate, dev); + break; + + case USBH_PACKET_CALLBACK_STATUS_EFATAL: + case USBH_PACKET_CALLBACK_STATUS_EAGAIN: + case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + device_enumeration_terminate(dev); + ERROR(cb_data.status); + break; + } + } + break; + + case USBH_ENUM_STATE_SET_CONFIGURATION_COMPLETE: + { + switch (cb_data.status) { + case USBH_PACKET_CALLBACK_STATUS_OK: + CONTINUE_WITH(USBH_ENUM_STATE_FIND_DRIVER); + break; + + case USBH_PACKET_CALLBACK_STATUS_EFATAL: + case USBH_PACKET_CALLBACK_STATUS_EAGAIN: + case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + device_enumeration_terminate(dev); + ERROR(cb_data.status); + break; + } + } + break; + case USBH_ENUM_STATE_FIND_DRIVER: { struct usb_config_descriptor *cdt = -- cgit From c4e6f3b55b03b29b9f6ac269c4ce591944cb8cab Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Mon, 5 Sep 2016 21:21:02 +0200 Subject: core: add helper state machine for control read/write Signed-off-by: Amir Hammad --- src/usbh_core.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 8 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 7071281..4e0f112 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -28,6 +28,8 @@ #include #include +#include + static struct { bool enumeration_run; const usbh_low_level_driver_t * const *lld_drivers; @@ -204,11 +206,7 @@ void usbh_init(const void *low_level_drivers[], const usbh_dev_driver_t * const } -/* - * NEW ENUMERATE - * - */ -void device_xfer_control_write_setup(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +static void device_xfer_control_write_setup(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; @@ -228,7 +226,7 @@ void device_xfer_control_write_setup(const void *data, uint16_t datalen, usbh_pa LOG_PRINTF("WR-setup@device...%d \n", dev->address); } -void device_xfer_control_write_data(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +static void device_xfer_control_write_data(const void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; @@ -248,7 +246,7 @@ void device_xfer_control_write_data(const void *data, uint16_t datalen, usbh_pac LOG_PRINTF("WR-data@device...%d \n", dev->address); } -void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) +static void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback_t callback, usbh_device_t *dev) { usbh_packet_t packet; @@ -268,6 +266,85 @@ void device_xfer_control_read(void *data, uint16_t datalen, usbh_packet_callback } +static void control_state_machine(usbh_device_t *dev, usbh_packet_callback_data_t cb_data) +{ + switch (dev->control.state) { + case USBH_CONTROL_STATE_SETUP: + if (cb_data.status != USBH_PACKET_CALLBACK_STATUS_OK) { + dev->control.state = USBH_CONTROL_STATE_NONE; + // Unable to deliver setup control packet - this is a fatal error + usbh_packet_callback_data_t ret_data; + ret_data.status = USBH_PACKET_CALLBACK_STATUS_EFATAL; + ret_data.transferred_length = 0; + dev->control.callback(dev, ret_data); + break; + } + if (dev->control.setup_data.bmRequestType & USB_REQ_TYPE_IN) { + dev->control.state = USBH_CONTROL_STATE_DATA; + device_xfer_control_read(dev->control.data.in, dev->control.data_length, control_state_machine, dev); + } else { + if (dev->control.data_length == 0) { + dev->control.state = USBH_CONTROL_STATE_STATUS; + device_xfer_control_read(0, 0, control_state_machine, dev); + } else { + dev->control.state = USBH_CONTROL_STATE_DATA; + device_xfer_control_write_data(dev->control.data.out, dev->control.data_length, control_state_machine, dev); + } + } + break; + + case USBH_CONTROL_STATE_DATA: + if (dev->control.setup_data.bmRequestType & USB_REQ_TYPE_IN) { + dev->control.state = USBH_CONTROL_STATE_NONE; + dev->control.callback(dev, cb_data); + } else { + if (cb_data.status != USBH_PACKET_CALLBACK_STATUS_OK) { + dev->control.state = USBH_CONTROL_STATE_NONE; + // Unable to deliver data control packet - this is a fatal error + usbh_packet_callback_data_t ret_data; + ret_data.status = USBH_PACKET_CALLBACK_STATUS_EFATAL; + ret_data.transferred_length = 0; + dev->control.callback(dev, ret_data); + break; + } + + if (dev->control.data_length == 0) { + // we should be in status state when the length of data is zero + LOG_PRINTF("Control logic error\n"); + dev->control.state = USBH_CONTROL_STATE_NONE; + dev->control.callback(dev, cb_data); + } else { + dev->control.state = USBH_CONTROL_STATE_STATUS; + device_xfer_control_read(0, 0, control_state_machine, dev); + } + } + break; + + case USBH_CONTROL_STATE_STATUS: + dev->control.state = USBH_CONTROL_STATE_NONE; + dev->control.callback(dev, cb_data); + break; + + default: + break; + } +} + +void device_control(usbh_device_t *dev, usbh_packet_callback_t callback, const struct usb_setup_data *setup_data, void *data) +{ + if (dev->control.state != USBH_CONTROL_STATE_NONE) { + LOG_PRINTF("ERROR: Use of control state machine while not idle\n"); + return; + } + + dev->control.state = USBH_CONTROL_STATE_SETUP; + dev->control.callback = callback; + dev->control.data.out = data; + dev->control.data_length = setup_data->wLength; + dev->control.setup_data = *setup_data; + device_xfer_control_write_setup(&dev->control.setup_data, sizeof(dev->control.setup_data), control_state_machine, dev); +} + bool usbh_enum_available(void) { @@ -675,7 +752,7 @@ void usbh_poll(uint32_t time_curr_us) { uint32_t k = 0; while (usbh_data.lld_drivers[k]) { - usbh_device_t * usbh_device = + usbh_device_t *usbh_device = ((usbh_generic_data_t *)(usbh_data.lld_drivers[k]->driver_data))->usbh_device; usbh_generic_data_t *lld_data = usbh_data.lld_drivers[k]->driver_data; @@ -689,12 +766,14 @@ void usbh_poll(uint32_t time_curr_us) usbh_device[0].lld = usbh_data.lld_drivers[k]; usbh_device[0].speed = usbh_data.lld_drivers[k]->root_speed(lld_data); usbh_device[0].address = 1; + usbh_device[0].control.state = USBH_CONTROL_STATE_NONE; device_enumeration_start(&usbh_device[0]); break; case USBH_POLL_STATUS_DEVICE_DISCONNECTED: { + usbh_device[0].control.state = USBH_CONTROL_STATE_NONE; uint32_t i; for (i = 0; i < USBH_MAX_DEVICES; i++) { device_remove(&usbh_device[i]); -- cgit From d4c74c55c3af5384bae94f27b213ddd0fcbd4c5d Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Mon, 5 Sep 2016 21:22:39 +0200 Subject: core: use new control wrapper to set device's address Signed-off-by: Amir Hammad --- src/usbh_core.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 4e0f112..216a149 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -400,26 +400,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ uint8_t state_start = dev->state; // Detection of hang // LOG_PRINTF("\nSTATE: %d\n", state); switch (dev->state) { - case USBH_ENUM_STATE_SET_ADDRESS_EMPTY_READ: - { - switch (cb_data.status) { - case USBH_PACKET_CALLBACK_STATUS_OK: - dev->state = USBH_ENUM_STATE_SET_ADDRESS_EMPTY_READ_COMPLETE; - LOG_PRINTF("Assigning address: %d\n", usbh_data.address_temporary); - device_xfer_control_read(0, 0, device_enumerate, dev); - break; - - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: - device_enumeration_terminate(dev); - ERROR(cb_data.status); - break; - } - } - break; - - case USBH_ENUM_STATE_SET_ADDRESS_EMPTY_READ_COMPLETE: + case USBH_ENUM_STATE_SET_ADDRESS: switch (cb_data.status) { case USBH_PACKET_CALLBACK_STATUS_OK: if (dev->address == 0) { @@ -740,8 +721,7 @@ void device_enumeration_start(usbh_device_t *dev) setup_data.wIndex = 0; setup_data.wLength = 0; - device_xfer_control_write_setup(&setup_data, sizeof(setup_data), - device_enumerate, dev); + device_control(dev, device_enumerate, &setup_data, 0); } /** -- cgit From 7c4ae8d7aa72e2e32cf456007d52ef11545b7f62 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Mon, 5 Sep 2016 21:24:15 +0200 Subject: core: use new control wrapper to read device descriptor Signed-off-by: Amir Hammad --- src/usbh_core.c | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 216a149..c7eca7f 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -423,38 +423,14 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ { struct usb_setup_data setup_data; - setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_STANDARD | USB_REQ_TYPE_DEVICE; + setup_data.bmRequestType = USB_REQ_TYPE_IN | USB_REQ_TYPE_DEVICE; setup_data.bRequest = USB_REQ_GET_DESCRIPTOR; setup_data.wValue = USB_DT_DEVICE << 8; setup_data.wIndex = 0; setup_data.wLength = USB_DT_DEVICE_SIZE; - dev->state = USBH_ENUM_STATE_DEVICE_DT_READ; - device_xfer_control_write_setup(&setup_data, sizeof(setup_data), - device_enumerate, dev); - } - break; - - - case USBH_ENUM_STATE_DEVICE_DT_READ: - { - switch (cb_data.status) { - case USBH_PACKET_CALLBACK_STATUS_OK: - dev->state = USBH_ENUM_STATE_DEVICE_DT_READ_COMPLETE; - device_xfer_control_read(&usbh_buffer[0], USB_DT_DEVICE_SIZE, - device_enumerate, dev); - break; - - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - CONTINUE_WITH(USBH_ENUM_STATE_DEVICE_DT_READ_SETUP); - break; - - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: - device_enumeration_terminate(dev); - ERROR(cb_data.status); - break; - } + dev->state = USBH_ENUM_STATE_DEVICE_DT_READ_COMPLETE; + device_control(dev, device_enumerate, &setup_data, &usbh_buffer[0]); } break; -- cgit From 2c23090d49a51a59f293ae1afdf763d2cd9fbb49 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Mon, 5 Sep 2016 21:24:51 +0200 Subject: core: use new control wrapper to set configuration to device Signed-off-by: Amir Hammad --- src/usbh_core.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index c7eca7f..0570ac3 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -609,27 +609,8 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ setup_data.wIndex = 0; setup_data.wLength = 0; - dev->state = USBH_ENUM_STATE_SET_CONFIGURATION_EMPTY_READ; - - device_xfer_control_write_setup(&setup_data, sizeof(setup_data), device_enumerate, dev); - } - break; - - case USBH_ENUM_STATE_SET_CONFIGURATION_EMPTY_READ: - { - switch (cb_data.status) { - case USBH_PACKET_CALLBACK_STATUS_OK: - dev->state = USBH_ENUM_STATE_SET_CONFIGURATION_COMPLETE; - device_xfer_control_read(0, 0, device_enumerate, dev); - break; - - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: - device_enumeration_terminate(dev); - ERROR(cb_data.status); - break; - } + dev->state = USBH_ENUM_STATE_SET_CONFIGURATION_COMPLETE; + device_control(dev, device_enumerate, &setup_data, 0); } break; -- cgit From c9869466ddfab7e7f6258397d1b8863c27e37149 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Tue, 6 Sep 2016 08:39:53 +0200 Subject: remove detection of hang Signed-off-by: Amir Hammad --- src/usbh_core.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 0570ac3..e673a59 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -397,7 +397,6 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ const usbh_low_level_driver_t *lld = dev->lld; usbh_generic_data_t *lld_data = lld->driver_data; uint8_t *usbh_buffer = lld_data->usbh_buffer; - uint8_t state_start = dev->state; // Detection of hang // LOG_PRINTF("\nSTATE: %d\n", state); switch (dev->state) { case USBH_ENUM_STATE_SET_ADDRESS: @@ -645,10 +644,6 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ LOG_PRINTF("Error: Unknown state "__FILE__"/%d\n", __LINE__); break; } - - if (state_start == dev->state) { - LOG_PRINTF("\n !HANG %d\n", state_start); - } } void device_enumeration_start(usbh_device_t *dev) -- cgit From b895498df9be02eba1c285c5cdc58eb088bb86fc Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Tue, 6 Sep 2016 08:40:32 +0200 Subject: hub: use common code to remove device Signed-off-by: Amir Hammad --- src/usbh_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index e673a59..fd1dca5 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -52,7 +52,7 @@ static bool enumeration(void) return usbh_data.enumeration_run; } -static void device_remove(usbh_device_t *dev) +void device_remove(usbh_device_t *dev) { if (dev->drv && dev->drvdata) { dev->drv->remove(dev->drvdata); -- cgit From 1d1b697bc6b13b5db1594c3dafe5452b6b2c1668 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Thu, 8 Sep 2016 06:27:35 +0200 Subject: use NULL instead of 0 for assigning null pointer Signed-off-by: Amir Hammad --- src/usbh_core.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index fd1dca5..5448d6c 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -35,7 +35,7 @@ static struct { const usbh_low_level_driver_t * const *lld_drivers; const usbh_dev_driver_t * const *dev_drivers; int8_t address_temporary; -} usbh_data = {0}; +} usbh_data = {}; static void set_enumeration(void) { @@ -58,8 +58,8 @@ void device_remove(usbh_device_t *dev) dev->drv->remove(dev->drvdata); } dev->address = -1; - dev->drv = 0; - dev->drvdata = 0; + dev->drv = NULL; + dev->drvdata = NULL; } /** @@ -105,11 +105,10 @@ static bool find_driver(usbh_device_t *dev, const usbh_dev_driver_info_t * devic static void device_register(void *descriptors, uint16_t descriptors_len, usbh_device_t *dev) { uint32_t i = 0; - dev->drv = 0; uint8_t *buf = (uint8_t *)descriptors; - dev->drv = 0; - dev->drvdata = 0; + dev->drv = NULL; + dev->drvdata = NULL; uint8_t desc_len = buf[i]; uint8_t desc_type = buf[i + 1]; @@ -285,7 +284,7 @@ static void control_state_machine(usbh_device_t *dev, usbh_packet_callback_data_ } else { if (dev->control.data_length == 0) { dev->control.state = USBH_CONTROL_STATE_STATUS; - device_xfer_control_read(0, 0, control_state_machine, dev); + device_xfer_control_read(NULL, 0, control_state_machine, dev); } else { dev->control.state = USBH_CONTROL_STATE_DATA; device_xfer_control_write_data(dev->control.data.out, dev->control.data_length, control_state_machine, dev); @@ -315,7 +314,7 @@ static void control_state_machine(usbh_device_t *dev, usbh_packet_callback_data_ dev->control.callback(dev, cb_data); } else { dev->control.state = USBH_CONTROL_STATE_STATUS; - device_xfer_control_read(0, 0, control_state_machine, dev); + device_xfer_control_read(NULL, 0, control_state_machine, dev); } } break; -- cgit From 8946cb522b10465d3fe3a9846158dbff4e924240 Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Fri, 9 Sep 2016 18:33:26 +0200 Subject: lld: rework low level driver initialization Signed-off-by: Amir Hammad --- src/usbh_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 5448d6c..88fd665 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -176,7 +176,7 @@ static void device_register(void *descriptors, uint16_t descriptors_len, usbh_de LOG_PRINTF("Device NOT Initialized\n"); } -void usbh_init(const void *low_level_drivers[], const usbh_dev_driver_t * const device_drivers[]) +void usbh_init(const usbh_low_level_driver_t * const low_level_drivers[], const usbh_dev_driver_t * const device_drivers[]) { if (!low_level_drivers) { return; -- cgit From 4415d960c3d1e52573db02be4aee6e22d22809cf Mon Sep 17 00:00:00 2001 From: Amir Hammad Date: Sun, 11 Sep 2016 12:03:20 +0200 Subject: use default case instead of handling other packet statuses explicitely Signed-off-by: Amir Hammad --- src/usbh_core.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'src/usbh_core.c') diff --git a/src/usbh_core.c b/src/usbh_core.c index 88fd665..1a60285 100644 --- a/src/usbh_core.c +++ b/src/usbh_core.c @@ -408,9 +408,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ CONTINUE_WITH(USBH_ENUM_STATE_DEVICE_DT_READ_SETUP); break; - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + default: device_enumeration_terminate(dev); ERROR(cb_data.status); break; @@ -458,8 +456,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: + default: device_enumeration_terminate(dev); ERROR(cb_data.status); break; @@ -492,9 +489,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ dev->packet_size_max0, device_enumerate, dev); break; - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + default: device_enumeration_terminate(dev); ERROR(cb_data.status); break; @@ -520,8 +515,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_EFATAL: + default: device_enumeration_terminate(dev); ERROR(cb_data.status); break; @@ -560,9 +554,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + default: device_enumeration_terminate(dev); ERROR(cb_data.status); break; @@ -583,9 +575,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ } break; - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + default: device_enumeration_terminate(dev); ERROR(cb_data.status); break; @@ -619,9 +609,7 @@ static void device_enumerate(usbh_device_t *dev, usbh_packet_callback_data_t cb_ CONTINUE_WITH(USBH_ENUM_STATE_FIND_DRIVER); break; - case USBH_PACKET_CALLBACK_STATUS_EFATAL: - case USBH_PACKET_CALLBACK_STATUS_EAGAIN: - case USBH_PACKET_CALLBACK_STATUS_ERRSIZ: + default: device_enumeration_terminate(dev); ERROR(cb_data.status); break; -- cgit