Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBHostWANDongle by
Diff: USBHost/USBHost.cpp
- Revision:
- 6:075e36a3463e
- Parent:
- 3:4394986752db
- Child:
- 7:c4483d48fe96
diff -r 3189db174f6b -r 075e36a3463e USBHost/USBHost.cpp --- a/USBHost/USBHost.cpp Wed Jul 25 11:13:50 2012 +0000 +++ b/USBHost/USBHost.cpp Fri Jul 27 16:14:07 2012 +0000 @@ -29,7 +29,7 @@ #include "rtos.h" -#define NB_MAX_INTF 5 +#define NB_MAX_INTF 2 USBHost * USBHost::instHost = NULL; @@ -558,7 +558,7 @@ // enumerate a device with the control endpoint -USB_TYPE USBHost::enumerate(USBDeviceConnected * dev) { +USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator) { uint8_t data[256]; uint8_t total_conf_descr_length = 0; USB_TYPE res; @@ -585,7 +585,7 @@ } dev->setSizeControlEndpoint(data[7]); DBG("size control Endpoint: %d", dev->getSizeControlEndpoint()); - + DBG("Now set addr"); // second step: set an address to the device res = controlWrite( dev, @@ -617,6 +617,8 @@ dev->setVid(data[8] | (data[9] << 8)); dev->setPid(data[10] | (data[11] << 8)); DBG("CLASS: %02X \t VID: %04X \t PID: %04X", data[4], data[8] | (data[9] << 8), data[10] | (data[11] << 8)); + + pEnumerator->setVidPid( data[8] | (data[9] << 8), data[10] | (data[11] << 8) ); res = getConfigurationDescriptor(dev, data, &total_conf_descr_length); if (res != USB_TYPE_OK) { @@ -624,7 +626,7 @@ } // Parse the configuration descriptor - parseConfDescr(dev, data, total_conf_descr_length); + parseConfDescr(dev, data, total_conf_descr_length, pEnumerator); // sixth step: set configuration (only 1 supported) @@ -647,13 +649,14 @@ } // this method fills the USBDeviceConnected object: class,.... . It also add endpoints found in the descriptor. -void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len) { +void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator) { uint32_t index = 0; uint32_t len_desc = 0; uint8_t id = 0; int nb_endpoints_used = 0; Endpoint * ep = NULL; uint8_t intf_nb = 0; + bool parsing_intf = false; while (index < len) { len_desc = conf_descr[index]; @@ -662,33 +665,44 @@ case CONFIGURATION_DESCRIPTOR: break; case INTERFACE_DESCRIPTOR: - if (intf_nb++ <= NB_MAX_INTF) { - dev->addInterface(intf_nb - 1, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7]); - nb_endpoints_used = 0; - DBG("ADD INTF %d on device %p: class: %d, subclass: %d, proto: %d", intf_nb - 1, (void *)dev, conf_descr[index + 5],conf_descr[index + 6],conf_descr[index + 7]); - } else { - DBG("Drop intf..."); + if(pEnumerator->parseInterface(intf_nb, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7])) + { + if (intf_nb++ <= NB_MAX_INTF) { + dev->addInterface(intf_nb - 1, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7]); + nb_endpoints_used = 0; + DBG("ADD INTF %d on device %p: class: %d, subclass: %d, proto: %d", intf_nb - 1, (void *)dev, conf_descr[index + 5],conf_descr[index + 6],conf_descr[index + 7]); + } else { + DBG("Drop intf..."); + } + parsing_intf = true; + } + else + { + parsing_intf = false; } break; case ENDPOINT_DESCRIPTOR: DBG("Ep DESC"); - if (intf_nb <= NB_MAX_INTF) { + if (parsing_intf && (intf_nb <= NB_MAX_INTF) ) { if (nb_endpoints_used < MAX_ENDPOINT_PER_INTERFACE) { - // if the endpoint is isochronous -> skip it (TODO: fix this) - if ((conf_descr[index + 3] & 0x03) != ISOCHRONOUS_ENDPOINT) { - ep = newEndpoint((ENDPOINT_TYPE)(conf_descr[index+3] & 0x03), - (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1), - conf_descr[index + 4] | (conf_descr[index + 5] << 8), - conf_descr[index + 2] & 0x0f); - DBG("ADD ENDPOINT %p, on interf %d on device %p", (void *)ep, intf_nb - 1, (void *)dev); - if (ep != NULL && dev != NULL) { - addEndpoint(dev, intf_nb - 1, ep); + if( pEnumerator->useEndpoint(intf_nb - 1, (ENDPOINT_TYPE)(conf_descr[index + 3] & 0x03), (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1)) ) + { + // if the endpoint is isochronous -> skip it (TODO: fix this) + if ((conf_descr[index + 3] & 0x03) != ISOCHRONOUS_ENDPOINT) { + ep = newEndpoint((ENDPOINT_TYPE)(conf_descr[index+3] & 0x03), + (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1), + conf_descr[index + 4] | (conf_descr[index + 5] << 8), + conf_descr[index + 2] & 0x0f); + DBG("ADD ENDPOINT %p, on interf %d on device %p", (void *)ep, intf_nb - 1, (void *)dev); + if (ep != NULL && dev != NULL) { + addEndpoint(dev, intf_nb - 1, ep); + } else { + DBG("EP NULL"); + } + nb_endpoints_used++; } else { - DBG("EP NULL"); + DBG("ISO ENDPOINT NOT SUPPORTED"); } - nb_endpoints_used++; - } else { - DBG("ISO ENDPOINT NOT SUPPORTED"); } } }