BaseUsbHost example program
Dependencies: BaseUsbHost FATFileSystem mbed mbed-rtos
UsbMouseHost/UsbMouseHost.cpp@0:2a9734a95d55, 2012-12-04 (annotated)
- Committer:
- va009039
- Date:
- Tue Dec 04 13:39:57 2012 +0000
- Revision:
- 0:2a9734a95d55
- Child:
- 1:80205a2de336
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:2a9734a95d55 | 1 | // UsbMouseHost.cpp |
va009039 | 0:2a9734a95d55 | 2 | #include "mbed.h" |
va009039 | 0:2a9734a95d55 | 3 | #include "rtos.h" |
va009039 | 0:2a9734a95d55 | 4 | #include "BaseUsbHost.h" |
va009039 | 0:2a9734a95d55 | 5 | //#define DEBUG |
va009039 | 0:2a9734a95d55 | 6 | #include "BaseUsbHostDebug.h" |
va009039 | 0:2a9734a95d55 | 7 | #define TEST |
va009039 | 0:2a9734a95d55 | 8 | #include "BaseUsbHostTest.h" |
va009039 | 0:2a9734a95d55 | 9 | #include "UsbMouseHost.h" |
va009039 | 0:2a9734a95d55 | 10 | |
va009039 | 0:2a9734a95d55 | 11 | UsbMouseHost::UsbMouseHost(ControlEp* ctlEp) |
va009039 | 0:2a9734a95d55 | 12 | { |
va009039 | 0:2a9734a95d55 | 13 | if (ctlEp == NULL) { // root hub |
va009039 | 0:2a9734a95d55 | 14 | DBG_OHCI(LPC_USB->HcRhPortStatus1); |
va009039 | 0:2a9734a95d55 | 15 | int lowSpeed = 0; |
va009039 | 0:2a9734a95d55 | 16 | if (LPC_USB->HcRhPortStatus1 & 0x200) { |
va009039 | 0:2a9734a95d55 | 17 | lowSpeed = 1; |
va009039 | 0:2a9734a95d55 | 18 | } |
va009039 | 0:2a9734a95d55 | 19 | m_ctlEp = new ControlEp(lowSpeed); |
va009039 | 0:2a9734a95d55 | 20 | TEST_ASSERT_TRUE(m_ctlEp); |
va009039 | 0:2a9734a95d55 | 21 | } else { |
va009039 | 0:2a9734a95d55 | 22 | m_ctlEp = ctlEp; |
va009039 | 0:2a9734a95d55 | 23 | } |
va009039 | 0:2a9734a95d55 | 24 | |
va009039 | 0:2a9734a95d55 | 25 | int rc = m_ctlEp->SetConfiguration(1); |
va009039 | 0:2a9734a95d55 | 26 | TEST_ASSERT_EQUAL(rc, USB_OK); |
va009039 | 0:2a9734a95d55 | 27 | |
va009039 | 0:2a9734a95d55 | 28 | int addr = m_ctlEp->GetAddr(); |
va009039 | 0:2a9734a95d55 | 29 | int lowSpeed = m_ctlEp->GetLowSpeed(); |
va009039 | 0:2a9734a95d55 | 30 | m_intEp = new InterruptEp(addr, 0x81, 8, lowSpeed); |
va009039 | 0:2a9734a95d55 | 31 | TEST_ASSERT_TRUE(m_intEp); |
va009039 | 0:2a9734a95d55 | 32 | } |
va009039 | 0:2a9734a95d55 | 33 | |
va009039 | 0:2a9734a95d55 | 34 | int UsbMouseHost::read(uint32_t* status, int millisec) |
va009039 | 0:2a9734a95d55 | 35 | { |
va009039 | 0:2a9734a95d55 | 36 | int rc = m_intEp->read(reinterpret_cast<uint8_t*>(status), 4, millisec); |
va009039 | 0:2a9734a95d55 | 37 | if (rc < 0) { // error? |
va009039 | 0:2a9734a95d55 | 38 | *status = 0x00000000; |
va009039 | 0:2a9734a95d55 | 39 | return rc; |
va009039 | 0:2a9734a95d55 | 40 | } |
va009039 | 0:2a9734a95d55 | 41 | return USB_OK; |
va009039 | 0:2a9734a95d55 | 42 | } |