supported GR-PEACH original: http://developer.mbed.org/users/va009039/code/USBHostC270_example/ The function of Isochronous has moved to USBHost_AddIso library.

Dependencies:   USBHost_custom_Addiso

Fork of USBHostC270_example_GR-PEACH by GR-PEACH_producer_meeting

Files at this revision

API Documentation at this revision

Comitter:
Osamu Nakamura
Date:
Fri Apr 21 20:09:15 2017 +0900
Parent:
14:7d4864959eb7
Commit message:
Update main.cpp so that it can run on mbed OS 5

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7d4864959eb7 -r ac8b6c6dfb3f main.cpp
--- a/main.cpp	Fri Apr 21 17:03:37 2017 +0900
+++ b/main.cpp	Fri Apr 21 20:09:15 2017 +0900
@@ -1,6 +1,17 @@
+#include "FATFileSystem.h"
 #include "USBHostMSD.h"
 #include "USBHostC270.h"
 
+#if defined(TARGET_RZ_A1H)
+#include "usb_host_setting.h"
+#else
+#define USB_HOST_CH     0
+#endif
+
+#if (USB_HOST_CH == 1) //Audio Camera Shield USB1
+DigitalOut usb1en(P3_8);
+#endif
+
 Serial pc(USBTX, USBRX);
 BusOut leds(LED1, LED2, LED3);
 
@@ -9,7 +20,23 @@
 int main() {
     pc.baud(921600);
 
-    USBHostMSD* msd = new USBHostMSD("usb"); // USB flash drive
+    
+#if (USB_HOST_CH == 1) //Audio Shield USB1
+    //Audio Shield USB1 enable
+    usb1en = 1;        //Outputs high level
+    Thread::wait(5);
+    usb1en = 0;        //Outputs low level
+#endif
+
+     // USB flash drive
+    FATFileSystem fs("usb");
+    USBHostMSD msd;
+    
+    while(!msd.connect()) {
+        Thread::wait(500);
+    }
+    fs.mount(&msd);
+    
     USBHostC270* cam = new USBHostC270(C270_MJPEG, C270_160x120, _5FPS); // Logitech C270
 
     Timer interval_t;
@@ -22,7 +49,7 @@
             char path[32];
             snprintf(path, sizeof(path), "/usb/image%02d.jpg", shot % 20);
             printf("%d %s %d bytes\n", shot, path, r);
-            if (msd->connected()) {
+            if (msd.connected()) {
                 FILE* fp = fopen(path, "wb");
                 if (fp) {
                     fwrite(buf, r, 1, fp);
@@ -33,10 +60,15 @@
             }
             interval_t.reset();
         }
-        if (!msd->connected()) {
-            msd->connect();
-            Thread::wait(500);
+        // If USB flash disk is unplugged, wait until USB is re-plugged
+        if (!msd.connected()) {
+            while(!msd.connect())
+            {
+                Thread::wait(500);
+            }
+            fs.mount(&msd);
         }
+        // If Logitech C270 is unplugged, try to re-plug it
         if (!cam->connected()) {
             cam->connect();
             Thread::wait(500);