aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2010-09-05 23:48:31 -0400
committerbnewbold <bnewbold@robocracy.org>2010-09-05 23:48:31 -0400
commit5bfeb40e4795eb5cf21ea84311936acf97969365 (patch)
tree3c7a9e42e7a756a9258c97a63462bda0bf343bbe /examples
parent552da8705245a876c2e816bab93edc2cb39f94e3 (diff)
downloadlibrambutan-5bfeb40e4795eb5cf21ea84311936acf97969365.tar.gz
librambutan-5bfeb40e4795eb5cf21ea84311936acf97969365.zip
systick testing and simplification
ripped out marti's SystemTick for the sake of simplicity and added a systick_resume function to libmaple. new example program demonstrates the functionality, also demonstrates micros()/USB bug
Diffstat (limited to 'examples')
-rw-r--r--examples/test-systick.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/test-systick.cpp b/examples/test-systick.cpp
new file mode 100644
index 0000000..247892d
--- /dev/null
+++ b/examples/test-systick.cpp
@@ -0,0 +1,60 @@
+// Tests the SysTick enable/disable functions
+//
+#include "wirish.h"
+#include "systick.h"
+
+#define LED_PIN 13
+#define PWM_PIN 2
+#define BUT 38
+
+void setup()
+{
+ /* Set up the LED to blink */
+ pinMode(LED_PIN, OUTPUT);
+
+ /* Turn on PWM on pin PWM_PIN */
+ pinMode(PWM_PIN, PWM);
+ pwmWrite(PWM_PIN, 0x8000);
+
+ pinMode(BUT, INPUT_PULLDOWN);
+}
+
+int toggle = 0;
+long time = 0;
+
+void loop() {
+ toggle ^= 1;
+ digitalWrite(LED_PIN, toggle);
+
+ // An artificial delay
+ int16 i = 1;
+ float j = 1;
+ for(i=0; i<6553; i++) {
+ j = sqrt(j) + 1;
+ }
+
+ if(digitalRead(BUT)) {
+ systick_disable();
+ } else {
+ systick_resume();
+ }
+
+ //SerialUSB.println(micros()); // there is a bug with this
+ SerialUSB.println(millis());
+}
+
+// Force init to be called *first*, i.e. before static object allocation.
+// Otherwise, statically allocated object that need libmaple may fail.
+ __attribute__(( constructor )) void premain() {
+ init();
+}
+
+int main(void)
+{
+ setup();
+
+ while (1) {
+ loop();
+ }
+ return 0;
+}