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 USBHost_DISCO-F746NG by
Diff: USBHost/USBHost.cpp
- Revision:
- 10:40c7f6788902
- Parent:
- 9:7f9f64cf5ded
--- a/USBHost/USBHost.cpp Mon Feb 03 13:00:16 2014 +0000 +++ b/USBHost/USBHost.cpp Wed Feb 05 13:34:37 2014 +0000 @@ -23,11 +23,10 @@ USBHost::USBHost() { } -/* virtual */ bool USBHost::addDevice(int hub, int port, bool lowSpeed) { +/* virtual */ bool USBHost::addDevice(USBDeviceConnected* parent, int port, bool lowSpeed) { USBDeviceConnected* dev = new USBDeviceConnected; - USBEndpoint* ep = new USBEndpoint; - ep->setDevice(dev); - dev->init(hub, port, lowSpeed); + USBEndpoint* ep = new USBEndpoint(dev); + dev->init(0, port, lowSpeed); dev->setAddress(0); dev->setEpCtl(ep); uint8_t desc[18]; @@ -35,6 +34,9 @@ int rc = controlRead(dev, 0x80, GET_DESCRIPTOR, 1<<8, 0, desc, 8); USB_TEST_ASSERT(rc == USB_TYPE_OK); + if (rc != USB_TYPE_OK) { + USB_ERR("ADD DEVICE FAILD"); + } USB_DBG_HEX(desc, 8); DeviceDescriptor* dev_desc = reinterpret_cast<DeviceDescriptor*>(desc); ep->setSize(dev_desc->bMaxPacketSize); @@ -52,11 +54,11 @@ dev->setVid(dev_desc->idVendor); dev->setPid(dev_desc->idProduct); dev->setClass(dev_desc->bDeviceClass); - USB_INFO("hub: %d port: %d speed: %s vid: %04x pid: %04x class: %02x addr: %d", - hub, port, (lowSpeed ? "low " : "full"), dev->getVid(), dev->getPid(), dev->getClass(), + USB_INFO("parent:%p port:%d speed:%s VID:%04x PID:%04x class:%02x addr:%d", + parent, port, (lowSpeed ? "low " : "full"), dev->getVid(), dev->getPid(), dev->getClass(), dev->getAddress()); - DeviceLists.push(dev); + DeviceLists.push_back(dev); if (dev->getClass() == HUB_CLASS) { const int config = 1; @@ -105,7 +107,7 @@ int config = 1; USB_TYPE res = controlWrite(dev, 0x00, SET_CONFIGURATION, config, 0, NULL, 0); if (res != USB_TYPE_OK) { - USB_DBG("SET CONF FAILED"); + USB_ERR("SET CONF FAILED"); return res; } // Some devices may require this delay @@ -155,11 +157,8 @@ ENDPOINT_TYPE type = (ENDPOINT_TYPE)(ep_desc->bmAttributes & 0x03); ENDPOINT_DIRECTION dir = (ep_desc->bEndpointAddress & 0x80) ? IN : OUT; if(pEnumerator->useEndpoint(current_intf, type, dir)) { - ep = new USBEndpoint; - ep->setDevice(dev); - ep->setType(type); - ep->setAddress(ep_desc->bEndpointAddress); - ep->setSize(ep_desc->wMaxPacketSize); + ep = new USBEndpoint(dev); + ep->init(type, dir, ep_desc->wMaxPacketSize, ep_desc->bEndpointAddress); USB_DBG("ADD USBEndpoint %p, on interf %d on device %p", ep, current_intf, dev); dev->addEndpoint(current_intf, ep); } @@ -195,7 +194,6 @@ USB_TYPE USBHost::bulkRead(USBDeviceConnected* dev, USBEndpoint* ep, uint8_t* buf, uint32_t len, bool blocking) { if (blocking == false) { - ep->setType(BULK_ENDPOINT); ep->setBuffer(buf, len); ep_queue.push(ep); return USB_TYPE_PROCESSING; @@ -220,7 +218,6 @@ USB_TYPE USBHost::interruptRead(USBDeviceConnected* dev, USBEndpoint* ep, uint8_t* buf, uint32_t len, bool blocking) { if (blocking == false) { - ep->setType(INTERRUPT_ENDPOINT); ep->setBuffer(buf, len); ep_queue.push(ep); return USB_TYPE_PROCESSING; @@ -237,7 +234,6 @@ USB_TYPE USBHost::isochronousRead(USBDeviceConnected* dev, USBEndpoint* ep, uint8_t* buf, uint32_t len, bool blocking) { if (blocking == false) { - ep->setType(ISOCHRONOUS_ENDPOINT); ep->setBuffer(buf, len); ep_queue.push(ep); return USB_TYPE_PROCESSING;