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

Dependents:   BaseUsbHost_example BaseJpegDecode_example SimpleJpegDecode_example

Import programBaseUsbHost_example

BaseUsbHost example program

Revision:
0:b7d6879637a8
Child:
1:3b7bc4f87a61
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BaseUsbHostIntEp.cpp	Tue Dec 04 13:29:41 2012 +0000
@@ -0,0 +1,55 @@
+// BaseUsbHostIntEp.cpp 2012/12/4
+#include "mbed.h"
+#include "rtos.h"
+#include "BaseUsbHost.h"
+#define DEBUG
+#include "BaseUsbHostDebug.h"
+#define TEST
+#include "BaseUsbHostTest.h"
+
+InterruptEp::InterruptEp(int addr, uint8_t ep, uint16_t size, int lowSpeed)
+    :BaseEp(addr, ep, size, lowSpeed)
+{
+    HCTD* td = new_HCTD();
+    TEST_ASSERT(td);
+    m_pED->TailTd = td;
+    m_pED->HeadTd = td; 
+
+    HCCA* pHcca = reinterpret_cast<HCCA*>(LPC_USB->HcHCCA);
+    TEST_ASSERT(pHcca);
+    int n = 0;
+    m_pED->Next = pHcca->InterruptTable[n];
+    pHcca->InterruptTable[n] = reinterpret_cast<uint32_t>(m_pED);
+    LPC_USB->HcControl |= OR_CONTROL_PLE;
+}
+    
+int InterruptEp::read(uint8_t* buf, int len, int millisec)
+{
+    if (m_td_queue_count == 0) {
+        HCTD* data_td = m_pED->TailTd;
+        TEST_ASSERT(data_td);
+        data_td->Control |= TD_IN;
+        data_td->CurrBufPtr = buf;
+        data_td->BufEnd = const_cast<uint8_t*>(buf)+len-1;
+        HCTD* blank_td = new_HCTD();
+        TEST_ASSERT(blank_td);
+        data_td->Next = reinterpret_cast<uint32_t>(blank_td);
+        m_pED->TailTd = blank_td;
+        m_td_queue_count++;
+        DBG_ED(m_pED);
+        LPC_USB->HcControl |= OR_CONTROL_PLE; // Enable Periodic
+    }
+        
+    HCTD* td = get_queue_HCTD(millisec);
+    if (td) {
+        DBG_TD(td);
+        int ret = len;
+        if (td->CurrBufPtr) {
+            ret = td->CurrBufPtr - buf;
+        }
+        delete_HCTD(td); 
+        m_td_queue_count--;
+        return ret;
+    }
+    return USB_TIMEOUT;
+}