USBDevice with MAX32620HSP platform support

Fork of USBDevice by mbed official

Files at this revision

API Documentation at this revision

Comitter:
samux
Date:
Thu Dec 20 17:05:37 2012 +0000
Parent:
5:d27e4c226965
Child:
7:f8f057664123
Commit message:
USBSerial: detect when a terminal is connected

Changed in this revision

USBSerial/USBCDC.cpp Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBCDC.h Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBSerial.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/USBSerial/USBCDC.cpp	Sun Oct 14 15:08:52 2012 +0000
+++ b/USBSerial/USBCDC.cpp	Thu Dec 20 17:05:37 2012 +0000
@@ -30,6 +30,7 @@
 #define MAX_CDC_REPORT_SIZE MAX_PACKET_SIZE_EPBULK
 
 USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
+    terminal_connected = false;
     USBDevice::connect();
 }
 
@@ -52,8 +53,11 @@
             case CDC_SET_LINE_CODING:
                 transfer->remaining = 7;
                 success = true;
+                terminal_connected = true;
                 break;
             case CDC_SET_CONTROL_LINE_STATE:
+                if (terminal_connected)
+                    terminal_connected = false;
                 success = true;
                 break;
             default:
--- a/USBSerial/USBCDC.h	Sun Oct 14 15:08:52 2012 +0000
+++ b/USBSerial/USBCDC.h	Thu Dec 20 17:05:37 2012 +0000
@@ -99,9 +99,11 @@
     * @returns true if successful
     */
     bool readEP_NB(uint8_t * buffer, uint32_t * size);
-
+    
+protected:
     virtual bool USBCallback_request();
     virtual bool USBCallback_setConfiguration(uint8_t configuration);
+    volatile bool terminal_connected;
 
 };
 
--- a/USBSerial/USBSerial.cpp	Sun Oct 14 15:08:52 2012 +0000
+++ b/USBSerial/USBSerial.cpp	Thu Dec 20 17:05:37 2012 +0000
@@ -20,6 +20,8 @@
 #include "USBSerial.h"
 
 int USBSerial::_putc(int c) {
+    if (!terminal_connected)
+        return 0;
     send((uint8_t *)&c, 1);
     return 1;
 }