diff options
author | Perry Hung <iperry@alum.mit.edu> | 2010-04-29 01:14:03 -0400 |
---|---|---|
committer | Perry Hung <iperry@alum.mit.edu> | 2010-04-29 01:14:03 -0400 |
commit | b5ddce7dc81a0ae313cce635bce02028db32d5de (patch) | |
tree | ea67f3f0c3c288c3c0e4b31454e54cb016a9b1b0 | |
parent | 2c51cc19ccb5c08eb4d89d197623da6cd92b35f7 (diff) | |
download | librambutan-b5ddce7dc81a0ae313cce635bce02028db32d5de.tar.gz librambutan-b5ddce7dc81a0ae313cce635bce02028db32d5de.zip |
Fixed examples, added spi example, moved pure virtual function handler
out of main to cxxabi-compat.cpp.
-rw-r--r-- | Makefile | 5 | ||||
-rwxr-xr-x | copy-to-ide | 1 | ||||
-rw-r--r-- | examples/blinky.cpp | 22 | ||||
-rw-r--r-- | examples/spi_master.cpp | 71 | ||||
-rw-r--r-- | main.cpp.example | 15 | ||||
-rw-r--r-- | wirish/main.cxx | 18 | ||||
-rw-r--r-- | wirish/wirish.c | 2 |
7 files changed, 78 insertions, 56 deletions
@@ -44,7 +44,7 @@ CFLAGS = $(INCLUDES) -c \ -ffunction-sections -fdata-sections -Wl,--gc-sections \ -D$(DEFFLAGS) -CPPFLAGS = -fno-rtti -fno-exceptions -Wall +CXXFLAGS = -fno-rtti -fno-exceptions -Wall #LINKER=lanchon-stm32.ld LFLAGS = -Tstm32conf/$(LINKER) -L stm32conf/lanchon-stm32 \ @@ -84,6 +84,7 @@ CPPSRC = wirish/wirish_math.cpp \ wirish/comm/HardwareSerial.cpp \ wirish/comm/HardwareUsb.cpp \ wirish/comm/HardwareSPI.cpp \ + wirish/cxxabi-compat.cpp \ main.cpp # i really have no idea what i'm doing @@ -144,7 +145,7 @@ $(COBJ) : $(BUILD_PATH)/%.o : %.c $(CPPOBJ) : $(BUILD_PATH)/%.o : %.cpp @echo $(MSG_COMPILING) $< - $(CPP) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ + $(CPP) $(CFLAGS) $(CXXFLAGS) -c $< -o $@ @echo # targets diff --git a/copy-to-ide b/copy-to-ide index 689966f..b14b8bd 100755 --- a/copy-to-ide +++ b/copy-to-ide @@ -58,6 +58,7 @@ FILES="LICENSE ./wirish/wirish_math.h ./wirish/wirish_shift.c ./wirish/WProgram.h + ./wirish/cxxabi-compat.cpp ./wirish/comm/HardwareSerial.cpp ./wirish/comm/HardwareSerial.h ./wirish/comm/HardwareSPI.cpp diff --git a/examples/blinky.cpp b/examples/blinky.cpp index 8a8b0d8..e156bf2 100644 --- a/examples/blinky.cpp +++ b/examples/blinky.cpp @@ -23,20 +23,10 @@ * ****************************************************************************/
/**
- * @file example_main_blinky.cpp
- *
- * @brief Example main.cpp. Blinks the LED, pin 13
+ * @brief blinky.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"
+#include "wirish.h"
#define TEST_PIN 13
@@ -61,11 +51,3 @@ int main(void) { }
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/examples/spi_master.cpp b/examples/spi_master.cpp new file mode 100644 index 0000000..19679f7 --- /dev/null +++ b/examples/spi_master.cpp @@ -0,0 +1,71 @@ +/* *****************************************************************************
+ * The MIT License
+ *
+ * Copyright (c) 2010 LeafLabs LLC.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * ****************************************************************************/
+
+/**
+ * @brief Sample main.cpp file. Sends "Hello world!" out SPI1.
+ *
+ * SPI1 is set up to be a master transmitter at 4.5MHz, little endianness,
+ * and SPI mode 0.
+ *
+ * Pin 10 is used as Chip Select
+ *
+ */
+
+#include "wirish.h"
+#include "HardwareSPI.h"
+
+#define CS 10
+
+byte buf[] = "Hello world!";
+
+HardwareSPI spi1(1);
+
+void setup() {
+ /* Set up chip select as output */
+ pinMode(CS, OUTPUT);
+
+ /* CS is usually active low, so initialize it high */
+ digitalWrite(CS, HIGH);
+
+ /* Initialize SPI */
+ spi1.begin(SPI_4_5MHZ, LSBFIRST, 0);
+}
+
+void loop() {
+ /* Send message */
+ digitalWrite(CS, LOW);
+ spi1.send(buf, sizeof buf);
+ digitalWrite(CS,HIGH);
+ delay(1000);
+}
+
+int main(void) {
+ init();
+ setup();
+
+ while (1) {
+ loop();
+ }
+ return 0;
+}
diff --git a/main.cpp.example b/main.cpp.example index 1067030..ae63996 100644 --- a/main.cpp.example +++ b/main.cpp.example @@ -23,20 +23,15 @@ * ****************************************************************************/
/**
- * @file example_main.cpp
- *
* @brief Sample main.cpp file. Blinks an LED, sends a message out USART2
* and turns on PWM on pin 2
*/
-#include "wiring.h"
+#include "wirish.h"
#include "HardwareSerial.h"
#include "HardwareUsb.h"
-#include "math.h"
#include "usb.h"
-uint8 bytes_in;
-
#define LED_PIN 13
#define PWM_PIN 2
@@ -77,11 +72,3 @@ int main(void) { }
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/wirish/main.cxx b/wirish/main.cxx index 440d464..d13e2eb 100644 --- a/wirish/main.cxx +++ b/wirish/main.cxx @@ -32,21 +32,3 @@ int main(void) }
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)
- ;
-}
-
-/* Implemented:
- * void pinMode(pin, mode)
- * void digitalWrite(pin, value)
- * uint32_t digitalRead(pin)
- * uint32_t analogRead(pin)
- * void randomSeed(seed)
- * long random(max)
- * long random(min, max)
- * */
diff --git a/wirish/wirish.c b/wirish/wirish.c index 5102124..3cfc12e 100644 --- a/wirish/wirish.c +++ b/wirish/wirish.c @@ -43,5 +43,3 @@ void init(void) { timer_init(3, 1); timer_init(4, 1); } - - |