Kazuki Yamamoto / USBCDCMSC

Dependents:   USBMSD_CDC_11U35test

Files at this revision

API Documentation at this revision

Comitter:
k4zuki
Date:
Wed Apr 22 16:41:59 2015 +0000
Parent:
2:8f01347859d0
Commit message:
[ FIX ] EndPoint changed to EP4; added disconnect() function

Changed in this revision

USBCDCMSC.cpp Show annotated file Show diff for this revision Revisions of this file
USBCDCMSC.h Show annotated file Show diff for this revision Revisions of this file
--- a/USBCDCMSC.cpp	Wed Apr 22 04:54:29 2015 +0000
+++ b/USBCDCMSC.cpp	Wed Apr 22 16:41:59 2015 +0000
@@ -21,9 +21,9 @@
 #include "USBEndpoints.h"
 
 /* Bulk endpoint */
-#define MSDBULK_OUT  (EP3OUT)
-#define MSDBULK_IN   (EP3IN)
-#define MAX_PACKET_SIZE_MSDBULK  (MAX_PACKET_SIZE_EP3)
+#define MSDBULK_OUT  (EP4OUT)
+#define MSDBULK_IN   (EP4IN)
+#define MAX_PACKET_SIZE_MSDBULK  (MAX_PACKET_SIZE_EP4)
 
 static uint8_t cdc_line_coding[7]= {0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08};
 
@@ -381,7 +381,7 @@
 }
 
 int USBCDCMSC::_getc() {
-    uint8_t c;
+    uint8_t c='\n';
     while (cdcbuf.isEmpty());
     cdcbuf.dequeue(&c);
     return c;
@@ -454,6 +454,13 @@
     return true;
 }
 
+void USBCDCMSC::disconnect() {
+    //De-allocate MSD page size:
+    free(page);
+    page = NULL;
+    USBDevice::disconnect();
+}
+
 
 void USBCDCMSC::reset() {
     stage = READ_CBW;
@@ -461,7 +468,7 @@
 
 
 // Called in ISR context called when a data is received
-bool USBCDCMSC::EP3_OUT_callback() {
+bool USBCDCMSC::EP4_OUT_callback() {
     uint32_t size = 0;
     uint8_t buf[MAX_PACKET_SIZE_EPBULK];
     USBDevice::readEP(MSDBULK_OUT, buf, &size, MAX_PACKET_SIZE_EPBULK);
@@ -498,7 +505,7 @@
 }
 
 // Called in ISR context when a data has been transferred
-bool USBCDCMSC::EP3_IN_callback() {
+bool USBCDCMSC::EP4_IN_callback() {
     switch (stage) {
 
             // the device has to send data to the host
--- a/USBCDCMSC.h	Wed Apr 22 04:54:29 2015 +0000
+++ b/USBCDCMSC.h	Wed Apr 22 16:41:59 2015 +0000
@@ -31,11 +31,13 @@
 
 #include "USBSDFileSystem.h"
 
-
+/**
+class USBCDCMSC: public USBDevice, public Stream
+*/
 class USBCDCMSC: public USBDevice, public Stream {
 public:
 
-    /*
+    /**
     * Constructor
     *
     * @param vendor_id Your vendor_id
@@ -102,7 +104,6 @@
         }
     }
 
-
     /**
     * Connect the USB MSD device. Establish disk initialization before really connect the device.
     *
@@ -110,6 +111,11 @@
     */
     bool connect();
 
+    /**
+    * Disconnect the USB MSD device.
+    */
+    void disconnect();
+
 protected:
     
     /*
@@ -221,12 +227,12 @@
     /*
     * Callback called when a MSD packet is received
     */
-    virtual bool EP3_OUT_callback();
+    virtual bool EP4_OUT_callback();
 
     /*
     * Callback called when a MSD packet has been sent
     */
-    virtual bool EP3_IN_callback();
+    virtual bool EP4_IN_callback();
 
 private: