A USB to UART bridge

Dependencies:   USBDevice BufferedSerial mbed

Files at this revision

API Documentation at this revision

Comitter:
yihui
Date:
Thu Jul 24 07:18:44 2014 +0000
Parent:
3:2b4d2284bab0
Child:
5:10fccccbbb11
Commit message:
use buffered serial

Changed in this revision

Buffer.lib Show diff for this revision Revisions of this file
BufferedSerial.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Buffer.lib	Wed Jul 23 09:40:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/sam_grove/code/Buffer/#cd0a1f4c623f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BufferedSerial.lib	Thu Jul 24 07:18:44 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sam_grove/code/BufferedSerial/#4d6a311fc8bf
--- 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);
         }
     }
 }