aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-03-23 01:41:08 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-03-23 01:41:08 -0400
commit8d6bf3b196c2a0bc1adda4a04669e54fdc5b65cb (patch)
tree830da6f6d88f61ef4264905f7138cfc73b903ab2
parent3639ad2cf027da7425ebe76382842c006acec05a (diff)
downloadlibrambutan-8d6bf3b196c2a0bc1adda4a04669e54fdc5b65cb.tar.gz
librambutan-8d6bf3b196c2a0bc1adda4a04669e54fdc5b65cb.zip
Removed main.cpp and updated example_main.cpp and added a blinky
version. New users are expected to write their or main.cpp or copy from an example version.
-rw-r--r--src/example_main.cpp71
-rw-r--r--src/example_main_bk.cpp74
-rw-r--r--src/example_main_blinky.cpp66
-rw-r--r--src/main.cpp37
4 files changed, 112 insertions, 136 deletions
diff --git a/src/example_main.cpp b/src/example_main.cpp
index 7202c66..8275452 100644
--- a/src/example_main.cpp
+++ b/src/example_main.cpp
@@ -1,48 +1,69 @@
+/* *****************************************************************************
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Created: 03/23/10 01:31:15
+ * Copyright (c) 2010 Perry L. Hung. All rights reserved.
+ *
+ * ****************************************************************************/
+
+/**
+ * @file example_main.cpp
+ *
+ * @brief Sample main.cpp file. Blinks an LED, sends a message out USART2 and
+ * the USB virtual COM port, and turns on PWM on pin 2
+ */
+
+#ifndef _EXAMPLE_MAIN_H_
+#define _EXAMPLE_MAIN_H_
+
+#endif
#include "wiring.h"
#include "HardwareSerial.h"
#include "HardwareUsb.h"
#include "math.h"
#include "usb.h"
-int ledPin = 13;
uint8_t bytes_in;
+#define LED_PIN 13
+#define PWM_PIN 2
+
HardwareUsb Usb;
void setup()
{
- pinMode(ledPin, OUTPUT);
- Serial2.begin(9600);
- Serial2.println("setup start");
+ /* Set up the LED to blink */
+ pinMode(LED_PIN, OUTPUT);
- pinMode(6, PWM);
- pwmWrite(6, 0x8000);
- pinMode(7, OUTPUT);
+ /* Send a message out USART2 */
+ Serial2.begin(9600);
+ Serial2.println("Hello world!");
- Serial2.println("setup end");
+ /* Turn on PWM on pin PWM_PIN */
+ pinMode(PWM_PIN, PWM);
+ pwmWrite(PWM_PIN, 0x8000);
- Usb.begin();
- Usb.flush();
+ /* Send a message out the USB virtual com port */
+ Usb.println("Hello world!");
}
int toggle = 0;
-const char* testMsg = "hello world!\n";
-const char x = 'a';
-static inline void loop() {
+void loop() {
toggle ^= 1;
- digitalWrite(ledPin, toggle);
- delay(50);
-
- uint8_t numBytes=Usb.available();
-
- if (numBytes > 0) {
- while (numBytes-->0) {
- Usb.print(Usb.read());
- }
- }
-
- Usb.flush();
+ digitalWrite(LED_PIN, toggle);
+ delay(100);
}
diff --git a/src/example_main_bk.cpp b/src/example_main_bk.cpp
deleted file mode 100644
index ce1b1c1..0000000
--- a/src/example_main_bk.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-#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)
- ;
-}
diff --git a/src/example_main_blinky.cpp b/src/example_main_blinky.cpp
new file mode 100644
index 0000000..1970529
--- /dev/null
+++ b/src/example_main_blinky.cpp
@@ -0,0 +1,66 @@
+/* *****************************************************************************
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Created: 03/23/10 01:40:50
+ * Copyright (c) 2010 Perry L. Hung. All rights reserved.
+ *
+ * ****************************************************************************/
+
+/**
+ * @file example_main_blinky.cpp
+ *
+ * @brief Example main.cpp. Blinks the LED, pin 13
+ */
+
+#ifndef _EXAMPLE_MAIN_BLINKY_H_
+#define _EXAMPLE_MAIN_BLINKY_H_
+
+#endif
+#include "wiring.h"
+#include "HardwareSerial.h"
+#include "wiring_math.h"
+#include "HardwareUsb.h"
+#include "usb.h"
+
+#define TEST_PIN 13
+
+void setup() {
+ pinMode(TEST_PIN, OUTPUT);
+}
+
+int toggle = 1;
+
+void loop() {
+ digitalWrite(TEST_PIN, toggle);
+ toggle ^= 1;
+ delay(100);
+}
+
+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)
+ ;
+}
diff --git a/src/main.cpp b/src/main.cpp
deleted file mode 100644
index 013ffdf..0000000
--- a/src/main.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include "wiring.h"
-#include "HardwareSerial.h"
-#include "wiring_math.h"
-#include "HardwareUsb.h"
-#include "usb.h"
-
-#define TEST_PIN 13
-
-void setup() {
- pinMode(TEST_PIN, OUTPUT);
-}
-
-int toggle = 1;
-
-void loop() {
- digitalWrite(TEST_PIN, toggle);
- toggle ^= 1;
- delay(100);
-}
-
-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)
- ;
-}