aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-06-01 01:29:23 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2012-06-01 01:29:23 -0400
commit51e0ae832fdf909cea09f72dd9f7d36edf274780 (patch)
treede48ec1e2c77321cd7905cbc0473ef2c0b6752d2
parentd483f8fa0c7c1f65c926b24d6c66275953d03c4f (diff)
downloadlibrambutan-51e0ae832fdf909cea09f72dd9f7d36edf274780.tar.gz
librambutan-51e0ae832fdf909cea09f72dd9f7d36edf274780.zip
Add examples/serial-echo.cpp.
Serial1 writes back what it receives. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
-rw-r--r--examples/serial-echo.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/serial-echo.cpp b/examples/serial-echo.cpp
new file mode 100644
index 0000000..204f011
--- /dev/null
+++ b/examples/serial-echo.cpp
@@ -0,0 +1,30 @@
+// Simple serial port "echo". Send back any received data.
+
+#include <wirish/wirish.h>
+
+// Note: you can change "Serial1" to any other serial port you have on
+// your board.
+
+void setup() {
+ Serial1.begin(115200);
+}
+
+void loop() {
+ while (Serial1.available()) {
+ Serial1.write(Serial1.read());
+ }
+}
+
+// Force init() to be called before anything else.
+__attribute__((constructor)) void premain() {
+ init();
+}
+
+int main(void) {
+ setup();
+
+ while (true) {
+ loop();
+ }
+ return 0;
+}