USB host library, support isochronous,bulk,interrupt and control.

Dependents:   BaseUsbHost_example BaseJpegDecode_example SimpleJpegDecode_example

Import programBaseUsbHost_example

BaseUsbHost example program

Revision:
2:fe1e62051d88
Parent:
0:b7d6879637a8
Child:
3:ae77d63a1eda
--- a/BaseUsbHostHub.cpp	Wed Dec 05 13:23:06 2012 +0000
+++ b/BaseUsbHostHub.cpp	Tue Dec 11 15:26:54 2012 +0000
@@ -1,4 +1,4 @@
-// BaseUsbHostHub.cpp 2012/12/4
+// BaseUsbHostHub.cpp 2012/12/11
 #include "mbed.h"
 #include "rtos.h"
 #include "BaseUsbHost.h"
@@ -21,31 +21,6 @@
 #define C_PORT_OVER_CURRENT 19
 #define C_PORT_RESET 20
 
-int UsbHub::SetPortFeature(int feature, int index)
-{
-    return m_ctlEp->controlSend(0x23, SET_FEATURE,feature,index,0,0);
-}
-
-int UsbHub::ClearPortFeature(int feature, int index)
-{
-    return m_ctlEp->controlSend(0x23, CLEAR_FEATURE,feature,index,0,0);
-}
-
-int UsbHub::SetPortPower(int port)
-{
-    return SetPortFeature(PORT_POWER, port);
-}
-
-int UsbHub::SetPortReset(int port)
-{
-    return SetPortFeature(PORT_RESET, port);
-}
-
-int UsbHub::GetPortStatus(int port, uint32_t* status)
-{
-    return m_ctlEp->controlReceive(0xa3, GET_STATUS, 0, port, (uint8_t*)status, 4);
-}
-
 UsbHub::UsbHub(ControlEp* ctlEp)
 {
     for(int i = 0; i < MAX_HUB_PORT; i++) {
@@ -86,10 +61,7 @@
     DBG("HUB STATUS: %08X\n", status);
 
     for(int i = 1; i <= bNbrPorts; i++) {
-        SetPortFeature(PORT_POWER, i); // power on
-    }
-
-    for(int i = 1; i <= bNbrPorts; i++) {
+        SetPortPower(i); // power on
         uint32_t status;
         GetPortStatus(i, &status);
         DBG("port: %d status: %08X\n", i, status);
@@ -101,10 +73,50 @@
                 low_speed = true;
             }
             DeviceConnected(i, low_speed);
+        } else {
+            ClearPortPower(i); // power on
         }
     }
 }
 
+ControlEp* UsbHub::GetPortEp(int port)
+{
+    if (port >= 1 && port <= MAX_HUB_PORT) {
+        return PortEp[port-1];
+    }
+    return NULL;
+}
+
+int UsbHub::SetPortPower(int port)
+{
+    return SetPortFeature(PORT_POWER, port);
+}
+
+int UsbHub::ClearPortPower(int port)
+{
+    return ClearPortFeature(PORT_POWER, port);
+}
+
+int UsbHub::SetPortFeature(int feature, int index)
+{
+    return m_ctlEp->controlSend(0x23, SET_FEATURE,feature,index,0,0);
+}
+
+int UsbHub::ClearPortFeature(int feature, int index)
+{
+    return m_ctlEp->controlSend(0x23, CLEAR_FEATURE,feature,index,0,0);
+}
+
+int UsbHub::SetPortReset(int port)
+{
+    return SetPortFeature(PORT_RESET, port);
+}
+
+int UsbHub::GetPortStatus(int port, uint32_t* status)
+{
+    return m_ctlEp->controlReceive(0xa3, GET_STATUS, 0, port, (uint8_t*)status, 4);
+}
+
 void UsbHub::DeviceConnected(int port, int low_speed)
 {
     DBG("port=%d low_speed=%d\n", port, low_speed);