Change USBSerial.h constructor to allow to label the stream for, eg., redirecting stdin/out/err to a USBSerial object. Will not break existing default use as tested with mbed-os 5.11.5

Dependents:   max32630fthr_stdout2usb_mbed_v5-11-5 firmware_framework1

Files at this revision

API Documentation at this revision

Comitter:
psionprime
Date:
Tue Apr 30 21:38:03 2019 +0000
Parent:
71:bf73f57c4b9c
Commit message:
- updated docs

Changed in this revision

USBSerial/USBSerial.h Show annotated file Show diff for this revision Revisions of this file
diff -r bf73f57c4b9c -r 6ef9c5c0250e USBSerial/USBSerial.h
--- a/USBSerial/USBSerial.h	Tue Apr 30 21:28:31 2019 +0000
+++ b/USBSerial/USBSerial.h	Tue Apr 30 21:38:03 2019 +0000
@@ -25,7 +25,7 @@
 
 
 /**
-* USBSerial example
+* USBSerial original example
 *
 * @code
 * #include "mbed.h"
@@ -44,6 +44,37 @@
 * }
 * @endcode
 */
+/**
+* USBSerial stdio redirect example
+*
+* @code
+* #include "mbed.h"
+* #include "USBSerial.h"
+* #include <stdio.h>
+* #include <errno.h>
+*
+* //Virtual serial port over USB
+* USBSerial usbSerial("usb");
+*
+* int main(void) {
+*    // redirect stdin, stdout, stderr to USBSerial object
+*    freopen("/usb", "r", stdin);
+*    freopen("/usb", "w", stdout);
+*    freopen("/usb", "w", stderr);
+*
+*    // wait until user ready
+*    while(!usbSerial.terminal_connected) {
+*        ThisThread::yield();
+*    }
+*
+*    while(1)
+*    {
+*        printf("--- mbed-os 5.11.5 stdout redirect to USBSerial ---\n");
+*        wait(1);
+*    }
+* }
+* @endcode
+*/
 class USBSerial: public USBCDC, public Stream {
 public:
 
@@ -60,6 +91,16 @@
         settingsChangedCallback = 0;
     };
 
+    /**
+    *   Constructor
+    *
+    * @param name Your name (default: NULL) (passed to Stream to enable stdio redirection)
+    * @param vendor_id Your vendor_id (default: 0x1f00)
+    * @param product_id Your product_id (default: 0x2012)
+    * @param product_release Your preoduct_release (default: 0x0001)
+    * @param connect_blocking define if the connection must be blocked if USB not plugged in
+    *
+    */
     USBSerial(const char *name = NULL, 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), Stream(name){
         settingsChangedCallback = 0;
     };