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:
- 9:c9e9817c398c
- Parent:
- 8:0d1ec493842c
- Child:
- 10:08bce4cd973a
- Child:
- 12:a712bad7a979
--- a/USBHost/USBHost.cpp Mon Jul 30 13:51:34 2012 +0000 +++ b/USBHost/USBHost.cpp Tue Jul 31 10:37:16 2012 +0000 @@ -88,7 +88,7 @@ } while(addr); //Now we can process the list - Endpoint * volatile iter = NULL; + USBEndpoint * volatile iter = NULL; while(tdList != NULL) { @@ -169,7 +169,7 @@ if (!controlEndpointAllocated) { control = newEndpoint(CONTROL_ENDPOINT, OUT, 0x08, 0x00); - addEndpoint(NULL, 0, (Endpoint*)control); + addEndpoint(NULL, 0, (USBEndpoint*)control); controlEndpointAllocated = true; } } @@ -202,7 +202,7 @@ } void USBHost::freeDevice(USBDeviceConnected * dev) { - Endpoint * ep = NULL; + USBEndpoint * ep = NULL; // HCTD * td = NULL; HCED * ed = NULL; @@ -210,10 +210,10 @@ DBG("FREE INTF %d, %p, nb_endpot: %d", j, (void *)dev->getInterface(j), dev->getInterface(j)->nb_endpoint); for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) { if ((ep = dev->getEndpoint(j, i)) != NULL) { - DBG("Freeing endpoint"); + DBG("Freeing USBEndpoint"); ed = (HCED *)ep->getHCED(); ed->control |= (1 << 13); //sKip bit - DBG("Dequeueing endpoint"); + DBG("Dequeueing USBEndpoint"); unqueueEndpoint(ep); DBG("Freeing first transfer descriptor"); @@ -221,7 +221,7 @@ DBG("Freeing second transfer descriptor"); freeTD((volatile uint8_t*)ep->getTDList()[1]); - DBG("Freeing endpoint descriptor"); + DBG("Freeing USBEndpoint descriptor"); freeED((uint8_t *)ep->getHCED()); } //printBulk(); @@ -234,19 +234,19 @@ } -void USBHost::unqueueEndpoint(Endpoint * ep) { - Endpoint * prec = NULL; - Endpoint * current = NULL; +void USBHost::unqueueEndpoint(USBEndpoint * ep) { + USBEndpoint * prec = NULL; + USBEndpoint * current = NULL; bool found = false; DBG("want to unqueue ep: %p", (void *)ep->getHCED()); for (int i = 0; i < 2; i++) { if (found) { - DBG("endpoint unqueued: %p", (void *)ep->getHCED()); + DBG("USBEndpoint unqueued: %p", (void *)ep->getHCED()); break; } - current = (i == 0) ? (Endpoint*)headBulkEndpoint : (Endpoint*)headInterruptEndpoint; + current = (i == 0) ? (USBEndpoint*)headBulkEndpoint : (USBEndpoint*)headInterruptEndpoint; prec = current; while (current != NULL) { if (current == ep) { @@ -293,8 +293,8 @@ -// create an endpoint descriptor. the endpoint is not linked -Endpoint * USBHost::newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) { +// create an USBEndpoint descriptor. the USBEndpoint is not linked +USBEndpoint * USBHost::newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) { int i = 0; HCED * ed = (HCED *)getED(); HCTD* td_list[2] = { (HCTD*)getTD(), (HCTD*)getTD() }; @@ -302,13 +302,13 @@ memset((void *)td_list[0], 0x00, sizeof(HCTD)); memset((void *)td_list[1], 0x00, sizeof(HCTD)); - // search a free endpoint + // search a free USBEndpoint for (i = 0; i < MAX_ENDPOINT; i++) { if (endpoints[i].getState() == USB_TYPE_FREE) { DBG("Trying to create ep"); endpoints[i].init(ed, type, dir, size, addr, td_list); //endpoints[i].queueTransfer(nullTd); - DBG("Endpoint created (%p): type: %d, dir: %d, size: %d, addr: %d", &endpoints[i], type, dir, size, addr); + DBG("USBEndpoint created (%p): type: %d, dir: %d, size: %d, addr: %d", &endpoints[i], type, dir, size, addr); return &endpoints[i]; } } @@ -325,8 +325,8 @@ } } -// link the endpoint to the linked list and attach an endpoint to a device -bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, Endpoint * ep) { +// link the USBEndpoint to the linked list and attach an USBEndpoint to a device +bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep) { if (ep == NULL) { return false; @@ -336,7 +336,7 @@ HCED * prevEd; - // set device address in the endpoint descriptor + // set device address in the USBEndpoint descriptor if (dev == NULL) { ep->setDeviceAddress(0); } else { @@ -344,18 +344,18 @@ } if (dev != NULL && dev->getSpeed()) { - DBG("add endpoint: set speed"); + DBG("add USBEndpoint: set speed"); ep->setSpeed(dev->getSpeed()); } - // queue the new endpoint on the ED list + // queue the new USBEndpoint on the ED list switch (ep->getType()) { case CONTROL_ENDPOINT: prevEd = ( HCED*) controlHeadED(); if (!prevEd) { updateControlHeadED((uint32_t) ep->getHCED()); - DBG("First control endpoint: %08X", (uint32_t) ep->getHCED()); + DBG("First control USBEndpoint: %08X", (uint32_t) ep->getHCED()); headControlEndpoint = ep; tailControlEndpoint = ep; return true; @@ -368,7 +368,7 @@ prevEd = ( HCED*) bulkHeadED(); if (!prevEd) { updateBulkHeadED((uint32_t) ep->getHCED()); - //DBG("First bulk endpoint: %08X\r\n", (uint32_t) ep->getHCED()); + //DBG("First bulk USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); headBulkEndpoint = ep; tailBulkEndpoint = ep; break; @@ -381,7 +381,7 @@ prevEd = ( HCED*) interruptHeadED(); if (!prevEd) { updateInterruptHeadED((uint32_t) ep->getHCED()); - //DBG("First interrupt endpoint: %08X\r\n", (uint32_t) ep->getHCED()); + //DBG("First interrupt USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); headInterruptEndpoint = ep; tailInterruptEndpoint = ep; break; @@ -446,7 +446,7 @@ // add a transfer on the TD linked list -USB_TYPE USBHost::addTransfer(Endpoint * ed, uint8_t * buf, uint32_t len) { +USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) { // allocate a TD which will be freed in TDcompletion volatile HCTD * td = ed->getNextTD(); @@ -557,7 +557,7 @@ } -// enumerate a device with the control endpoint +// enumerate a device with the control USBEndpoint USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator) { uint8_t data[384]; uint16_t total_conf_descr_length = 0; @@ -569,7 +569,7 @@ return USB_TYPE_OK; } - // first step: get the size of endpoint 0 + // first step: get the size of USBEndpoint 0 DBG("Get size of EP 0"); res = controlRead( dev, USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, @@ -584,7 +584,7 @@ return res; } dev->setSizeControlEndpoint(data[7]); - DBG("size control Endpoint: %d", dev->getSizeControlEndpoint()); + DBG("size control USBEndpoint: %d", dev->getSizeControlEndpoint()); DBG("Now set addr"); // second step: set an address to the device @@ -654,7 +654,7 @@ uint32_t len_desc = 0; uint8_t id = 0; int nb_endpoints_used = 0; - Endpoint * ep = NULL; + USBEndpoint * ep = NULL; uint8_t intf_nb = 0; bool parsing_intf = false; @@ -687,13 +687,13 @@ if (nb_endpoints_used < MAX_ENDPOINT_PER_INTERFACE) { 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 the USBEndpoint 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); + DBG("ADD USBEndpoint %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 { @@ -701,12 +701,12 @@ } nb_endpoints_used++; } else { - DBG("ISO ENDPOINT NOT SUPPORTED"); + DBG("ISO USBEndpoint NOT SUPPORTED"); } } } } - //DBG("ENDPOINT DESCR"); + //DBG("USBEndpoint DESCR"); break; case HID_DESCRIPTOR: lenReportDescr = conf_descr[index + 7] | (conf_descr[index + 8] << 8); @@ -719,7 +719,7 @@ } -USB_TYPE USBHost::bulkRead(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -727,11 +727,11 @@ } if ((ep->getDir() != IN) || (ep->getType() != BULK_ENDPOINT)) { - DBG("wrong dir or bad endpoint type"); + DBG("wrong dir or bad USBEndpoint type"); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - DBG("endpoint addr and device addr don't match"); + DBG("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len); @@ -747,7 +747,7 @@ return USB_TYPE_PROCESSING; } -USB_TYPE USBHost::bulkWrite(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -755,11 +755,11 @@ } if ((ep->getDir() != OUT) || (ep->getType() != BULK_ENDPOINT)) { - DBG("wrong dir or bad endpoint type"); + DBG("wrong dir or bad USBEndpoint type"); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - DBG("endpoint addr and device addr don't match"); + DBG("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len); @@ -780,7 +780,7 @@ return USB_TYPE_PROCESSING; } -USB_TYPE USBHost::interruptWrite(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -792,11 +792,11 @@ } if ((ep->getDir() != OUT) || (ep->getType() != INTERRUPT_ENDPOINT)) { - ERR("wrong dir or bad endpoint type: %d, %d", ep->getDir(), ep->getType()); + ERR("wrong dir or bad USBEndpoint type: %d, %d", ep->getDir(), ep->getType()); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - ERR("endpoint addr and device addr don't match"); + ERR("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len); @@ -810,7 +810,7 @@ return USB_TYPE_PROCESSING; } -USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -822,12 +822,12 @@ } if ((ep->getDir() != IN) || (ep->getType() != INTERRUPT_ENDPOINT)) { - ERR("wrong dir or bad endpoint type"); + ERR("wrong dir or bad USBEndpoint type"); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - ERR("endpoint addr and device addr don't match"); + ERR("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len);