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.
Dependencies: FatFileSystem TB6612FNG2 mbed
usb/UsbHostMgr2.cpp@0:de03cbbcd0ff, 2015-11-30 (annotated)
- Committer:
- mbed_Cookbook_SE
- Date:
- Mon Nov 30 09:32:15 2015 +0000
- Revision:
- 0:de03cbbcd0ff
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 1 | #include "UsbHostMgr.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 2 | //#define __DEBUG |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | #include "mydbg.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | UsbDevice* UsbHostMgr::getDeviceByClass(uint8_t IfClass, int count) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | DBG("IfClass=%02X count=%d\n", IfClass, count); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | UsbDevice* dev = m_lpDevices[i]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | if (dev) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | if(dev->m_connected && dev->m_enumerated) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | if (dev->m_InterfaceClass == IfClass) { // found |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | if (count-- <= 0) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | return dev; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | void UsbHostMgr::onUsbDeviceConnected(int hub, int port) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | DBG("%p hub=%d port=%d\n", this, hub, port); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | UsbDevice* dev = m_lpDevices[i]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | if (dev) { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | if (dev->m_hub == hub && dev->m_port == port) { // skip |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | return; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | int item = devicesCount(); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | DBG_ASSERT(item < USB_HOSTMGR_MAX_DEVS); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | if( item == USB_HOSTMGR_MAX_DEVS ) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | return; //List full... |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | //Find a free address (not optimized, but not really important) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | int addr = 1; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | for(int i = 0; i < item; i++) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | { |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | DBG_ASSERT(m_lpDevices[i]); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | addr = MAX( addr, m_lpDevices[i]->m_addr + 1 ); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | DBG("item=%d addr=%d\n", item, addr); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | UsbDevice* dev = new UsbDevice( this, hub, port, addr ); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | DBG_ASSERT(dev); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 49 | dev->m_connected = true; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 50 | m_lpDevices[item] = dev; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 51 | } |