Update for new version of mbed.

Dependents:   DHT11_USBSerial

Fork of USBDevice_STM32F103 by Zoltan Hudak

Revision:
71:52ef20e36cab
Parent:
66:c86eab438152
--- a/USBSerial/USBCDC.cpp	Sun Dec 03 21:14:26 2017 +0000
+++ b/USBSerial/USBCDC.cpp	Mon Dec 04 23:05:41 2017 +0000
@@ -27,6 +27,10 @@
 #define CDC_GET_LINE_CODING        0x21
 #define CDC_SET_CONTROL_LINE_STATE 0x22
 
+// Control Line State bits
+#define CLS_DTR   (1 << 0)
+#define CLS_RTS   (1 << 1)
+
 #define MAX_CDC_REPORT_SIZE MAX_PACKET_SIZE_EPBULK
 
 USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking): USBDevice(vendor_id, product_id, product_release) {
@@ -34,6 +38,10 @@
     USBDevice::connect(connect_blocking);
 }
 
+void USBCDC::USBCallback_busReset(void) {
+    terminal_connected = false;
+};
+
 bool USBCDC::USBCallback_request(void) {
     /* Called in ISR context */
 
@@ -52,11 +60,15 @@
                 break;
             case CDC_SET_LINE_CODING:
                 transfer->remaining = 7;
+                transfer->notify = true;
                 success = true;
-                terminal_connected = true;
                 break;
             case CDC_SET_CONTROL_LINE_STATE:
-                terminal_connected = false;
+                if (transfer->setup.wValue & CLS_DTR) {
+                    terminal_connected = true;
+                } else {
+                    terminal_connected = false;
+                }
                 success = true;
                 break;
             default:
@@ -67,6 +79,31 @@
     return success;
 }
 
+void USBCDC::USBCallback_requestCompleted(uint8_t *buf, uint32_t length) {
+    // Request of setting line coding has 7 bytes
+    if (length != 7) {
+        return;
+    }
+
+    CONTROL_TRANSFER * transfer = getTransferPtr();
+
+    /* Process class-specific requests */
+    if (transfer->setup.bmRequestType.Type == CLASS_TYPE) {
+        if (transfer->setup.bRequest == CDC_SET_LINE_CODING) {
+            if (memcmp(cdc_line_coding, buf, 7)) {
+                memcpy(cdc_line_coding, buf, 7);
+
+                int baud = buf[0] + (buf[1] << 8)
+                         + (buf[2] << 16) + (buf[3] << 24);
+                int stop = buf[4];
+                int bits = buf[6];
+                int parity = buf[5];
+
+                lineCodingChanged(baud, bits, parity, stop);
+            }
+        }
+    }
+}
 
 // Called in ISR context
 // Set configuration. Return false if the
@@ -116,8 +153,8 @@
         0,                    // bDeviceSubClass
         0,                    // bDeviceProtocol
         MAX_PACKET_SIZE_EP0,  // bMaxPacketSize0
-        LSB(VENDOR_ID), MSB(VENDOR_ID),  // idVendor
-        LSB(PRODUCT_ID), MSB(PRODUCT_ID),// idProduct
+        (uint8_t)(LSB(VENDOR_ID)), (uint8_t)(MSB(VENDOR_ID)),  // idVendor
+        (uint8_t)(LSB(PRODUCT_ID)), (uint8_t)(MSB(PRODUCT_ID)),// idProduct
         0x00, 0x01,           // bcdDevice
         1,                    // iManufacturer
         2,                    // iProduct
@@ -160,7 +197,7 @@
         0,                      // iConfiguration
         0x80,                   // bmAttributes
         50,                     // bMaxPower
-        
+
         // IAD to associate the two CDC interfaces
         0x08,                   // bLength
         0x0b,                   // bDescriptorType
@@ -251,4 +288,3 @@
     };
     return configDescriptor;
 }
-