Update for new version of mbed.

Dependents:   DHT11_USBSerial

Fork of USBDevice_STM32F103 by Zoltan Hudak

Revision:
71:52ef20e36cab
Parent:
66:c86eab438152
--- a/USBSerial/USBSerial.h	Sun Dec 03 21:14:26 2017 +0000
+++ b/USBSerial/USBSerial.h	Mon Dec 04 23:05:41 2017 +0000
@@ -22,7 +22,7 @@
 #include "USBCDC.h"
 #include "Stream.h"
 #include "CircBuffer.h"
-
+#include "Callback.h"
 
 /**
 * USBSerial example
@@ -56,7 +56,9 @@
     * @param connect_blocking define if the connection must be blocked if USB not plugged in
     *
     */
-    USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001,  bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking), buf(128){ };
+    USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking){
+        settingsChangedCallback = 0;
+    };
 
 
     /**
@@ -66,23 +68,46 @@
     * @returns true if there is no error, false otherwise
     */
     virtual int _putc(int c);
-    
+
     /**
     * Read a character: blocking
     *
     * @returns character read
     */
     virtual int _getc();
-    
+
     /**
     * Check the number of bytes available.
     *
     * @returns the number of bytes available
     */
-    uint8_t available(); 
-    
+    uint8_t available();
+
+     /**
+    * Check if the terminal is connected.
+    *
+    * @returns connection status
+    */
+    bool connected();
+
+    /** Determine if there is a character available to read
+     *
+     *  @returns
+     *    1 if there is a character available to read,
+     *    0 otherwise
+     */
+    int readable() { return available() ? 1 : 0; }
+
+    /** Determine if there is space available to write a character
+     *
+     *  @returns
+     *    1 if there is space to write a character,
+     *    0 otherwise
+     */
+    int writeable() { return 1; } // always return 1, for write operation is blocking
+
     /**
-    * Write a block of data. 
+    * Write a block of data.
     *
     * For more efficiency, a block of size 64 (maximum size of a bulk endpoint) has to be written.
     *
@@ -94,7 +119,7 @@
     bool writeBlock(uint8_t * buf, uint16_t size);
 
     /**
-     *  Attach a member function to call when a packet is received. 
+     *  Attach a member function to call when a packet is received.
      *
      *  @param tptr pointer to the object to call the member function on
      *  @param mptr pointer to the member function to be called
@@ -111,19 +136,33 @@
      *
      * @param fptr function pointer
      */
-    void attach(void (*fn)(void)) {
-        if(fn != NULL) {
-            rx.attach(fn);
+    void attach(void (*fptr)(void)) {
+        if(fptr != NULL) {
+            rx.attach(fptr);
         }
     }
 
+    /**
+     * Attach a callback to call when serial's settings are changed.
+     *
+     * @param fptr function pointer
+     */
+    void attach(void (*fptr)(int baud, int bits, int parity, int stop)) {
+        settingsChangedCallback = fptr;
+    }
 
 protected:
-    virtual bool EP2_OUT_callback();
+    virtual bool EPBULK_OUT_callback();
+    virtual void lineCodingChanged(int baud, int bits, int parity, int stop){
+        if (settingsChangedCallback) {
+            settingsChangedCallback(baud, bits, parity, stop);
+        }
+    }
 
 private:
-    FunctionPointer rx;
-    CircBuffer<uint8_t> buf;
+    Callback<void()> rx;
+    CircBuffer<uint8_t,128> buf;
+    void (*settingsChangedCallback)(int baud, int bits, int parity, int stop);
 };
 
 #endif