USB Host Driver with Socket Modem support. Works with revision 323 of mbed-src but broken with any later version.

Dependencies:   FATFileSystem

Fork of F401RE-USBHost by Norimasa Okamoto

Revision:
18:61554f238584
Parent:
16:981c3104f6c0
Child:
19:47978c25c9b8
--- a/USBHost/USBHALHost_F401RE.cpp	Mon Jun 23 20:48:53 2014 +0900
+++ b/USBHost/USBHALHost_F401RE.cpp	Tue Jul 01 18:33:31 2014 +0900
@@ -1,13 +1,7 @@
-// Simple USBHost for Nucleo F401RE
 #if defined(TARGET_NUCLEO_F401RE)
-#include "USBHALHost_F401RE.h"
+#include "USBHALHost.h"
 #include <algorithm>
 
-template <bool>struct CtAssert;
-template <>struct CtAssert<true> {};
-#define CTASSERT(A) CtAssert<A>();
-
-
 #ifdef _USB_DBG
 extern RawSerial pc;
 //RawSerial pc(USBTX,USBRX);
@@ -20,25 +14,11 @@
 #define USB_DBG_HEX(A,B) while(0)
 #endif
 
-#ifdef _USB_TEST
-#define USB_TEST_ASSERT(A) while(!(A)){fprintf(stderr,"\n\n%s@%d %s ASSERT!\n\n",__PRETTY_FUNCTION__,__LINE__,#A);exit(1);};
-#define USB_TEST_ASSERT_FALSE(A) USB_TEST_ASSERT(!(A))
-#else
-#define USB_TEST_ASSERT(A) while(0)
-#define USB_TEST_ASSERT_FALSE(A) while(0)
-#endif
+#undef USB_TEST_ASSERT
+void usb_test_assert_internal(const char *expr, const char *file, int line);
+#define USB_TEST_ASSERT(EXPR) while(!(EXPR)){usb_test_assert_internal(#EXPR,__FILE__,__LINE__);}
 
-#ifdef _USB_TRACE
-#define USB_TRACE() while(0)
 #define USB_TRACE1(A) while(0)
-#define USB_TRACE_VIEW() while(0)
-#define USB_TRACE_CLEAR() while(0)
-#else
-#define USB_TRACE() while(0)
-#define USB_TRACE1(A) while(0)
-#define USB_TRACE_VIEW() while(0)
-#define USB_TRACE_CLEAR() while(0)
-#endif
 
 #define USB_INFO(...) do{fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\n");}while(0);
 
@@ -83,7 +63,7 @@
 extern "C" {
 void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
 {
-    USB_TRACE();
+    USB_TRACE1(hhcd);
     attach_done = true;
 }
 
@@ -410,7 +390,7 @@
     return read_len;
 }
 
-int USBHALHost::multi_token_out(USBEndpoint* ep, const uint8_t* data, size_t total, bool block) {
+int USBHALHost::multi_token_out(USBEndpoint* ep, const uint8_t* data, size_t total) {
     if (total == 0) {
         return token_out(ep);
     }
@@ -435,12 +415,39 @@
     }
     return write_len;
 }
+void USBHALHost::multi_token_inNB(USBEndpoint* ep, uint8_t* data, int size) {
+    USB_TRACE1(size);
+    USB_TEST_ASSERT(ep->getState() != USB_TYPE_PROCESSING);
+    ep->setBuffer(data, size);
+    ep->setState(USB_TYPE_PROCESSING);
+}
+
+USB_TYPE USBHALHost::multi_token_inNB_result(USBEndpoint* ep) {
+    USB_TEST_ASSERT(ep->getState() == USB_TYPE_PROCESSING);
+    uint8_t* buf = ep->getBufStart();
+    int size = ep->getBufSize();
+    int result = multi_token_in(ep, buf, size, false);
+    USB_TRACE1(result);
+    if (result < 0) {
+        return USB_TYPE_PROCESSING;
+    }
+    ep->setLengthTransferred(result);
+    ep->setState(USB_TYPE_IDLE);
+    return USB_TYPE_OK;
+
+}
+
+void USBHALHost::setToggle(USBEndpoint* ep, uint8_t toggle) {
+    USB_TEST_ASSERT(toggle == 1);
+    ep->setData01(toggle == 0 ? DATA0 : DATA1);
+}
 
 uint8_t HC::slot = 0x00;
 
 HC::HC() {
-    uint8_t mask = 0x01;
-    for(int i = 1; i < 8; i++, mask <<= 1) {
+    static const int start = 1;
+    uint8_t mask = (1<<start);
+    for(int i = start; i < 8; i++, mask <<= 1) {
         if (!(slot & mask)) {
             slot |= mask;
             _ch = i;