usb vritual serial to uart

Dependencies:   BufferedSerial USBDevice mbed

Fork of USB2UART by Yihui Xiong

Revision:
4:9c038f12d460
Parent:
3:2b4d2284bab0
Child:
5:10fccccbbb11
--- a/main.cpp	Wed Jul 23 09:40:47 2014 +0000
+++ b/main.cpp	Thu Jul 24 07:18:44 2014 +0000
@@ -4,18 +4,15 @@
  
 #include "mbed.h"
 #include "USBSerial.h"
-#include "Buffer.h"
+#include "BufferedSerial.h"
 
-Serial uart(USBTX, USBRX);
+BufferedSerial uart(USBTX, USBRX);
 USBSerial pc;
 DigitalOut led1(LED1);
 DigitalOut led2(LED2);
 DigitalOut led3(LED3);
 DigitalOut led4(LED4);
 
-Buffer <char> rxbuf;
-Buffer <char> txbuf;
-
 Ticker ticker;
 volatile bool rxflag = false;
 volatile bool txflag = false;
@@ -60,27 +57,20 @@
 int main()
 {
     pc.attach(settings_changed);
-    ticker.attach_us(indicate, 10000);
+    ticker.attach_us(indicate, 500);
     
     while (1) {
         while (uart.readable()) {
             rxflag = true;
             char r = uart.getc();
-            rxbuf.put(r);
-        }
-        
-        while (txbuf.available() && uart.writeable()) {
-            txflag = true;
-            uart.putc(txbuf.get());
+            pc.putc(r);
         }
         
-        if (pc.readable()) {
+        while (pc.readable()) {
             char r = pc.getc();
-            txbuf.put(r);
-        }
-        
-        if (rxbuf.available() && pc.writeable()) {
-            pc.putc(rxbuf.get());
+            
+            txflag = true;
+            uart.putc(r);
         }
     }
 }