[ FORK ] USBFileSytem; fork from sissors/USBFileSystem

Dependents:   USBMSD_CDC_11U35test

Fork of USBFileSystem by Erik -

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Fri Aug 02 18:49:27 2013 +0000
Parent:
0:dabe3383ef23
Child:
2:9af05743d551
Commit message:
Added usbdevice without memory leaks
; added option to automatically disconnect usb drive

Changed in this revision

USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
USBFileSystem.cpp Show annotated file Show diff for this revision Revisions of this file
USBFileSystem.h Show annotated file Show diff for this revision Revisions of this file
--- a/USBDevice.lib	Wed Jul 31 19:15:55 2013 +0000
+++ b/USBDevice.lib	Fri Aug 02 18:49:27 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/USBDevice/#1e3d126a322b
+http://mbed.org/users/Sissors/code/USBDevice/#0e8e73ebaa40
--- a/USBFileSystem.cpp	Wed Jul 31 19:15:55 2013 +0000
+++ b/USBFileSystem.cpp	Fri Aug 02 18:49:27 2013 +0000
@@ -7,6 +7,7 @@
   usbFunction = NULL;
   usbfree = true;
   local_count = 0;
+  usbmode = 0;
 }
 
 
@@ -98,10 +99,16 @@
     }
     
     //Pseudo-IRQ
-    if (localFunction != NULL) {
-        if (open && (local_count == 1))
+    if (open && (local_count == 1)) {
+        if (usbmode == 1)
+            disconnect();
+        if (localFunction != NULL) 
             (*localFunction)(false);
-        if (!open && (local_count == 0))
+    }
+    if (!open && (local_count == 0)) {
+        if (usbmode == 1)
+            connect();
+        if (localFunction != NULL) 
             (*localFunction)(true);
     }
 }
@@ -118,4 +125,8 @@
     usbfree = true;
     if (usbFunction != NULL)
         usbFunction(true);
+}
+
+void USBFileSystem::usbMode(int mode) {
+    usbmode = mode;
 }
\ No newline at end of file
--- a/USBFileSystem.h	Wed Jul 31 19:15:55 2013 +0000
+++ b/USBFileSystem.h	Fri Aug 02 18:49:27 2013 +0000
@@ -90,6 +90,15 @@
     */
     bool usbSafe( void );
     
+    /** Sets the USB mode
+    *
+    * Argument = 0: USB is write protected when not available (default).
+    * Argument = 1: USB is disconnected when not available
+    *
+    * @param mode - USB safety mode
+    */
+    void usbMode( int mode );
+    
     
 protected:
     //Functions to be implemented by child:
@@ -112,6 +121,7 @@
     virtual int disk_write(const uint8_t * buffer, uint64_t sector);
     
     int local_count;
+    int usbmode;
     Timeout usb_write;
     bool usbfree;