diff options
| author | ajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123> | 2010-01-07 03:31:35 +0000 | 
|---|---|---|
| committer | ajmeyer@mit.edu <ajmeyer@mit.edu@749a229e-a60e-11de-b98f-4500b42dc123> | 2010-01-07 03:31:35 +0000 | 
| commit | 2addfe8c42c6bcdc0a15c751e2436447b73d03fe (patch) | |
| tree | 07e569cd0fe7fd4a06cb5f71e12ba76dda3d5e2c /src/example_main_bk.cpp | |
| parent | 5f423270cde82f9dfffb52bdd617e5eb439921c5 (diff) | |
| download | librambutan-2addfe8c42c6bcdc0a15c751e2436447b73d03fe.tar.gz librambutan-2addfe8c42c6bcdc0a15c751e2436447b73d03fe.zip  | |
Added a print class for USB, works identically to the Serial object. Bugs out if you try and pump more than 64 bytes through it in a single packet (which is really the OS's decision). This can be fixed
git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@93 749a229e-a60e-11de-b98f-4500b42dc123
Diffstat (limited to 'src/example_main_bk.cpp')
| -rw-r--r-- | src/example_main_bk.cpp | 74 | 
1 files changed, 74 insertions, 0 deletions
diff --git a/src/example_main_bk.cpp b/src/example_main_bk.cpp new file mode 100644 index 0000000..ce1b1c1 --- /dev/null +++ b/src/example_main_bk.cpp @@ -0,0 +1,74 @@ +#include "wiring.h"
 +#include "HardwareSerial.h"
 +#include "HardwareUsb.h"
 +#include "math.h"
 +#include "usb.h"
 +
 +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()
 +{
 +    pinMode(ledPin, OUTPUT);
 +    Serial2.begin(9600);
 +    Serial2.println("setup start");
 +
 +    pinMode(6, PWM);
 +    pwmWrite(6, 0x8000);
 +    pinMode(7, OUTPUT);
 +
 +    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;
 +
 +const char* testMsg = "hello world!\n";
 +
 +static inline void loop() {
 +    toggle ^= 1;
 +    digitalWrite(ledPin, toggle);
 +    delay(1000);
 +    usb_serialWriteStr("blink...\n");
 +
 +    if (bytes_in > 0) {
 +      int i;
 +      for (i=0;i<bytes_in;i++) {
 +	usb_serialWriteStr("b,");
 +      }
 +      bytes_in = 0;
 +      usb_serialWriteStr("\n");
 +    }
 +}
 +
 +
 +int main(void) {
 +    init();
 +    setup();
 +
 +    while (1) {
 +        loop();
 +    }
 +    return 0;
 +}
 +
 +/* Required for C++ hackery */
 +/* TODO: This really shouldn't go here... move it later
 + * */
 +extern "C" void __cxa_pure_virtual(void) {
 +    while(1)
 +        ;
 +}
  | 
