BaseUsbHost example program

Dependencies:   BaseUsbHost FATFileSystem mbed mbed-rtos

Revision:
1:80205a2de336
Parent:
0:2a9734a95d55
--- a/UsbMouseHost/UsbMouseHost.cpp	Tue Dec 04 13:39:57 2012 +0000
+++ b/UsbMouseHost/UsbMouseHost.cpp	Wed Dec 05 13:25:18 2012 +0000
@@ -1,8 +1,8 @@
-// UsbMouseHost.cpp
+// UsbMouseHost.cpp 2012/12/5
 #include "mbed.h"
 #include "rtos.h"
 #include "BaseUsbHost.h"
-//#define DEBUG
+#define DEBUG
 #include "BaseUsbHostDebug.h"
 #define TEST
 #include "BaseUsbHostTest.h"
@@ -16,24 +16,41 @@
         if (LPC_USB->HcRhPortStatus1 & 0x200) {
             lowSpeed = 1;
         }
-        m_ctlEp = new ControlEp(lowSpeed);
-        TEST_ASSERT_TRUE(m_ctlEp);
-    } else {
-        m_ctlEp = ctlEp;
+        ctlEp = new ControlEp(lowSpeed);
+        TEST_ASSERT_TRUE(ctlEp);
     }
-
-    int rc = m_ctlEp->SetConfiguration(1);
+    bool r = check(ctlEp);
+    TEST_ASSERT(r);
+ 
+    int rc = ctlEp->SetConfiguration(1);
     TEST_ASSERT_EQUAL(rc, USB_OK);
 
-    int addr = m_ctlEp->GetAddr();
-    int lowSpeed = m_ctlEp->GetLowSpeed();
+    int addr = ctlEp->GetAddr();
+    int lowSpeed = ctlEp->GetLowSpeed();
     m_intEp = new InterruptEp(addr, 0x81, 8, lowSpeed);
     TEST_ASSERT_TRUE(m_intEp);
 }
 
+bool UsbMouseHost::check(ControlEp* ctlEp)
+{
+    if (ctlEp == NULL) {
+        return false;
+    }
+    uint8_t buf[8];
+    int r = ctlEp->GetDescriptor(1, 0, buf, 8);
+    if (r != USB_OK) {
+        return false;
+    }
+    DBG_HEX(buf, 8);
+    if (buf[4] != 0x00) { // HID ?
+        return false;
+    }    
+    return true;
+}
+
 int UsbMouseHost::read(uint32_t* status, int millisec)
 {
-    int rc = m_intEp->read(reinterpret_cast<uint8_t*>(status), 4, millisec);
+    int rc = m_intEp->interruptReceive(reinterpret_cast<uint8_t*>(status), 4, millisec);
     if (rc < 0) { // error?
         *status = 0x00000000;
         return rc;