From 3bb04834ffd3f90dc9015997ea11a56d9d150099 Mon Sep 17 00:00:00 2001 From: "ajmeyer@mit.edu" Date: Sat, 19 Dec 2009 18:23:31 +0000 Subject: added demo code on main.cpp to build a simple two way channel over the virtual serial port. To use this, run ln -s /dev/ttyACM0 /dev/ttyS9 then open up Maple IDE and select ttyS9 as the serial port. you should be able to see the count of the number of bytes in as well as the blink message git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@78 749a229e-a60e-11de-b98f-4500b42dc123 --- src/main.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 46037bd..cf79329 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,16 @@ void setup(); void loop(); int ledPin = 13; +uint8_t bytes_in; +BootVectTable* mapleVect; + +void usb_tx_cb(void) { +} + +void usb_rx_cb(void) { + bytes_in = usb_serialGetRecvLen(); +} void setup() { @@ -19,8 +28,13 @@ void setup() pwmWrite(6, 0x8000); Serial2.println("setup end"); + + mapleVect = (BootVectTable*)(BOOTLOADER_VECT_TABLE); + mapleVect->serial_tx_cb = usb_tx_cb; + mapleVect->serial_rx_cb = usb_rx_cb; } + int toggle = 0; char* testMsg = "0123456\n"; @@ -28,10 +42,16 @@ void loop() { toggle ^= 1; digitalWrite(ledPin, toggle); delay(1000); + usb_serialWriteStr("blink...\n"); - usb_userToPMABufferCopy((u8*)testMsg,USB_SERIAL_ENDP_TXADDR,8); - _SetEPTxCount(USB_SERIAL_ENDP_TX,8); - _SetEPTxValid(USB_SERIAL_ENDP_TX); + if (bytes_in > 0) { + int i; + for (i=0;i