keyboard->mbed->PC (mbed->SDcard)

Dependencies:   mbed-rtos

Fork of USBHost by mbed official

Revision:
37:f1e388e7b752
Parent:
27:4206883f4cb7
--- a/USBHostHub/USBHostHub.cpp	Sun Apr 30 04:17:16 2017 +0000
+++ b/USBHostHub/USBHostHub.cpp	Thu Jul 20 10:13:56 2017 +0100
@@ -50,12 +50,14 @@
 #define C_PORT_OVER_CURRENT (1 << 19)
 #define C_PORT_RESET        (1 << 20)
 
-USBHostHub::USBHostHub() {
+USBHostHub::USBHostHub()
+{
     host = NULL;
     init();
 }
 
-void USBHostHub::init() {
+void USBHostHub::init()
+{
     dev_connected = false;
     dev = NULL;
     int_in = NULL;
@@ -70,7 +72,8 @@
     }
 }
 
-void USBHostHub::setHost(USBHost * host_) {
+void USBHostHub::setHost(USBHost * host_)
+{
     host = host_;
 }
 
@@ -129,7 +132,8 @@
     return false;
 }
 
-void USBHostHub::disconnect() {
+void USBHostHub::disconnect()
+{
     init();
 }
 
@@ -141,9 +145,9 @@
 /*virtual*/ bool USBHostHub::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
 {
     if ((hub_intf == -1) &&
-        (intf_class == HUB_CLASS) &&
-        (intf_subclass == 0) &&
-        (intf_protocol == 0)) {
+            (intf_class == HUB_CLASS) &&
+            (intf_subclass == 0) &&
+            (intf_protocol == 0)) {
         hub_intf = intf_nb;
         return true;
     }
@@ -161,15 +165,18 @@
     return false;
 }
 
-void USBHostHub::deviceConnected(USBDeviceConnected * dev) {
+void USBHostHub::deviceConnected(USBDeviceConnected * dev)
+{
     device_children[dev->getPort() - 1] = dev;
 }
 
-void USBHostHub::deviceDisconnected(USBDeviceConnected * dev) {
+void USBHostHub::deviceDisconnected(USBDeviceConnected * dev)
+{
     device_children[dev->getPort() - 1] = NULL;
 }
 
-void USBHostHub::hubDisconnected() {
+void USBHostHub::hubDisconnected()
+{
     for (uint8_t i = 0; i < MAX_HUB_PORT; i++) {
         if (device_children[i] != NULL) {
             host->freeDevice(device_children[i]);
@@ -177,10 +184,11 @@
     }
 }
 
-void USBHostHub::rxHandler() {
+void USBHostHub::rxHandler()
+{
     uint32_t status;
     if (int_in) {
-        if (int_in->getState() == USB_TYPE_IDLE) {
+        if ((int_in->getLengthTransferred())&&(int_in->getState() == USB_TYPE_IDLE)) {
             for (int port = 1; port <= nb_port; port++) {
                 status = getPortStatus(port);
                 USB_DBG("[hub handler hub: %d] status port %d [hub: %p]: 0x%X", dev->getHub(), port, dev, status);
@@ -217,7 +225,8 @@
     }
 }
 
-void USBHostHub::portReset(uint8_t port) {
+void USBHostHub::portReset(uint8_t port)
+{
     // reset port
     uint32_t status;
     USB_DBG("reset port %d on hub: %p [this: %p]", port, dev, this)
@@ -227,8 +236,13 @@
 #endif
     while(1) {
         status = getPortStatus(port);
-        if (status & (PORT_ENABLE | PORT_RESET))
+        /*  disconnection since reset request */
+        if (!(status & PORT_CONNECTION)) {
             break;
+        }
+        if (status & (PORT_ENABLE | PORT_RESET)) {
+            break;
+        }
         if (status & PORT_OVER_CURRENT) {
             USB_ERR("OVER CURRENT DETECTED\r\n");
             clearPortFeature(PORT_OVER_CURRENT, port);
@@ -239,7 +253,8 @@
     }
 }
 
-void USBHostHub::setPortFeature(uint32_t feature, uint8_t port) {
+void USBHostHub::setPortFeature(uint32_t feature, uint8_t port)
+{
     host->controlWrite( dev,
                         USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
                         SET_FEATURE,
@@ -249,7 +264,8 @@
                         0);
 }
 
-void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port) {
+void USBHostHub::clearPortFeature(uint32_t feature, uint8_t port)
+{
     host->controlWrite( dev,
                         USB_HOST_TO_DEVICE | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,
                         CLEAR_FEATURE,
@@ -259,7 +275,8 @@
                         0);
 }
 
-uint32_t USBHostHub::getPortStatus(uint8_t port) {
+uint32_t USBHostHub::getPortStatus(uint8_t port)
+{
     uint32_t st;
     host->controlRead(  dev,
                         USB_DEVICE_TO_HOST | USB_REQUEST_TYPE_CLASS | USB_RECIPIENT_INTERFACE | USB_RECIPIENT_ENDPOINT,