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 uvchost by
UsbHostMgr2.cpp
00001 #include "UsbHostMgr.h" 00002 //#define __DEBUG 00003 #include "mydbg.h" 00004 00005 UsbDevice* UsbHostMgr::getDeviceByClass(uint8_t IfClass, int count) 00006 { 00007 DBG("IfClass=%02X count=%d\n", IfClass, count); 00008 for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) { 00009 UsbDevice* dev = m_lpDevices[i]; 00010 if (dev) { 00011 if(dev->m_connected && dev->m_enumerated) { 00012 if (dev->m_InterfaceClass == IfClass) { // found 00013 if (count-- <= 0) { 00014 return dev; 00015 } 00016 } 00017 } 00018 } 00019 } 00020 return NULL; 00021 } 00022 00023 UsbDevice* UsbHostMgr::getDeviceByVidPid(uint16_t vid, uint16_t pid, int count) 00024 { 00025 for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) { 00026 UsbDevice* dev = m_lpDevices[i]; 00027 if (dev) { 00028 if(dev->m_connected && dev->m_enumerated) { 00029 if (dev->m_vid == vid && dev->m_pid == pid) { // found 00030 if (count-- <= 0) { 00031 return dev; 00032 } 00033 } 00034 } 00035 } 00036 } 00037 return NULL; 00038 } 00039 00040 void UsbHostMgr::onUsbDeviceConnected(int hub, int port, bool low_speed) 00041 { 00042 DBG("%p hub=%d port=%d %s\n", this, hub, port, low_speed ? "slow" : "full"); 00043 for(int i = 0; i < USB_HOSTMGR_MAX_DEVS; i++) { 00044 UsbDevice* dev = m_lpDevices[i]; 00045 if (dev) { 00046 if (dev->m_hub == hub && dev->m_port == port) { // skip 00047 return; 00048 } 00049 } 00050 } 00051 00052 int item = devicesCount(); 00053 DBG_ASSERT(item < USB_HOSTMGR_MAX_DEVS); 00054 if( item == USB_HOSTMGR_MAX_DEVS ) 00055 return; //List full... 00056 //Find a free address (not optimized, but not really important) 00057 int addr = 1; 00058 for(int i = 0; i < item; i++) 00059 { 00060 DBG_ASSERT(m_lpDevices[i]); 00061 addr = MAX( addr, m_lpDevices[i]->m_addr + 1 ); 00062 } 00063 DBG("item=%d addr=%d\n", item, addr); 00064 UsbDevice* dev = new UsbDevice( this, hub, port, addr , low_speed); 00065 DBG_ASSERT(dev); 00066 dev->m_connected = true; 00067 m_lpDevices[item] = dev; 00068 }
Generated on Wed Jul 13 2022 01:34:55 by
1.7.2
