aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-19 18:23:31 +0000
committerajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-19 18:23:31 +0000
commit3bb04834ffd3f90dc9015997ea11a56d9d150099 (patch)
treeace229d4399c535a0fc874d1ad22efd7bfbf35de /src/main.cpp
parent6a0091418a8cdad33f7cb9b2a576e91c6960e07a (diff)
downloadlibrambutan-3bb04834ffd3f90dc9015997ea11a56d9d150099.tar.gz
librambutan-3bb04834ffd3f90dc9015997ea11a56d9d150099.zip
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
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp26
1 files changed, 23 insertions, 3 deletions
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<bytes_in;i++) {
+ usb_serialWriteStr("b,");
+ }
+ bytes_in = 0;
+ usb_serialWriteStr("\n");
+ }
}