BaseUsbHost example program
Dependencies: BaseUsbHost FATFileSystem mbed mbed-rtos
Diff: UsbMouseHost/UsbMouseHost.cpp
- Revision:
- 3:6ae9a03a6145
- Parent:
- 2:c10029b87439
- Child:
- 4:41ff237a64ec
--- a/UsbMouseHost/UsbMouseHost.cpp Tue Dec 11 15:28:00 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -// UsbMouseHost.cpp 2012/12/5 -#include "mbed.h" -#include "rtos.h" -#include "BaseUsbHost.h" -#define DEBUG -#include "BaseUsbHostDebug.h" -#define TEST -#include "BaseUsbHostTest.h" -#include "UsbMouseHost.h" - -UsbMouseHost::UsbMouseHost(ControlEp* ctlEp) -{ - if (ctlEp == NULL) { // root hub - DBG_OHCI(LPC_USB->HcRhPortStatus1); - int lowSpeed = 0; - if (LPC_USB->HcRhPortStatus1 & 0x200) { - lowSpeed = 1; - } - ctlEp = new ControlEp(lowSpeed); - TEST_ASSERT_TRUE(ctlEp); - } - bool r = check(ctlEp); - TEST_ASSERT(r); - - int rc = ctlEp->SetConfiguration(1); - TEST_ASSERT_EQUAL(rc, USB_OK); - - 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->interruptReceive(reinterpret_cast<uint8_t*>(status), 4, millisec); - if (rc < 0) { // error? - *status = 0x00000000; - return rc; - } - return USB_OK; -}