Create a UART to USB Serial bridge with the DipCortex

Dependencies:   USBDevice mbed

Fork of DipCortex-USB-CDC by Carl - SolderSplash Labs

Committer:
SolderSplashLabs
Date:
Sun Feb 23 23:02:12 2014 +0000
Revision:
5:dbe3aba53ebf
Parent:
3:5fffa4cb4ca1
Removing changes committed to wrong repo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:8c4eea221dcf 1 /**
yihui 0:8c4eea221dcf 2 * USB to UART Bridge
yihui 0:8c4eea221dcf 3 */
yihui 0:8c4eea221dcf 4
yihui 0:8c4eea221dcf 5 #include "mbed.h"
yihui 0:8c4eea221dcf 6 #include "USBSerial.h"
yihui 0:8c4eea221dcf 7
SolderSplashLabs 2:ec470dd97c6e 8 // Serial TX Pin19, Serial RX Pin20
SolderSplashLabs 2:ec470dd97c6e 9 // Using port and pin names as the mbed definitions pin defs for the M0 are incorrect
SolderSplashLabs 2:ec470dd97c6e 10 Serial uart(P1_13, P1_14);
yihui 0:8c4eea221dcf 11 USBSerial pc;
yihui 0:8c4eea221dcf 12
yihui 0:8c4eea221dcf 13 // Called by ISR
yihui 0:8c4eea221dcf 14 void settingsChanged(int baud, int bits, int parity, int stop)
yihui 0:8c4eea221dcf 15 {
yihui 0:8c4eea221dcf 16 const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1};
yihui 0:8c4eea221dcf 17
yihui 0:8c4eea221dcf 18 if (stop != 2) {
yihui 0:8c4eea221dcf 19 stop = 1; // stop bit(s) = 1 or 1.5
yihui 0:8c4eea221dcf 20 }
yihui 0:8c4eea221dcf 21
yihui 0:8c4eea221dcf 22 uart.baud(baud);
yihui 0:8c4eea221dcf 23 uart.format(bits, parityTable[parity], stop);
yihui 0:8c4eea221dcf 24 }
yihui 0:8c4eea221dcf 25
yihui 0:8c4eea221dcf 26 int main()
yihui 0:8c4eea221dcf 27 {
yihui 0:8c4eea221dcf 28 pc.attach(settingsChanged);
yihui 0:8c4eea221dcf 29
SolderSplashLabs 5:dbe3aba53ebf 30 while (1) {
SolderSplashLabs 5:dbe3aba53ebf 31 while (uart.readable()) {
SolderSplashLabs 5:dbe3aba53ebf 32 pc.putc(uart.getc());
SolderSplashLabs 5:dbe3aba53ebf 33 }
yihui 0:8c4eea221dcf 34
SolderSplashLabs 5:dbe3aba53ebf 35 while (pc.readable()) {
SolderSplashLabs 5:dbe3aba53ebf 36 uart.putc(pc.getc());
SolderSplashLabs 5:dbe3aba53ebf 37 }
yihui 0:8c4eea221dcf 38 }
yihui 0:8c4eea221dcf 39 }