summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-01-12 15:07:44 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-01-12 15:07:44 +0100
commit8cdcdcf7572d08d5def7fddc7a9438826eeed22b (patch)
tree73af74dfcd30d102cea5ceceda71115f88ee26f1
parent3875f37b2ce1d020aaf5174ea2a885bfdb98db98 (diff)
add arduino nano stdin driver
-rw-r--r--include/arduino-nano/driver/stdin.h24
-rw-r--r--src/arch/arduino-nano/Makefile.inc4
-rw-r--r--src/arch/arduino-nano/arch.cc9
-rw-r--r--src/arch/arduino-nano/driver/stdin.cc32
4 files changed, 68 insertions, 1 deletions
diff --git a/include/arduino-nano/driver/stdin.h b/include/arduino-nano/driver/stdin.h
new file mode 100644
index 0000000..6462e0c
--- /dev/null
+++ b/include/arduino-nano/driver/stdin.h
@@ -0,0 +1,24 @@
+#ifndef STANDARDINPUT_H
+#define STANDARDINPUT_H
+
+class StandardInput {
+ private:
+ StandardInput(const StandardInput &copy);
+ char buffer[8];
+ unsigned char write_pos, read_pos;
+
+ public:
+ StandardInput() : write_pos(0), read_pos(0) {}
+ void setup();
+ bool hasKey();
+ char getKey();
+
+ inline void addKey(char key) {
+ buffer[write_pos++] = key;
+ write_pos %= 8;
+ }
+};
+
+extern StandardInput kin;
+
+#endif
diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc
index f4dd78e..958eda2 100644
--- a/src/arch/arduino-nano/Makefile.inc
+++ b/src/arch/arduino-nano/Makefile.inc
@@ -23,6 +23,10 @@ TARGETS += src/arch/arduino-nano/driver/gpio.cc
TARGETS += src/arch/arduino-nano/driver/stdout.cc
TARGETS += src/arch/arduino-nano/driver/uptime.cc
+ifneq ($(findstring stdin,${arch_drivers}), )
+ TARGETS += src/arch/arduino-nano/driver/stdin.cc
+endif
+
OBJECTS = ${TARGETS:.cc=.o}
.cc.o:
diff --git a/src/arch/arduino-nano/arch.cc b/src/arch/arduino-nano/arch.cc
index 28fe34b..f35cb1d 100644
--- a/src/arch/arduino-nano/arch.cc
+++ b/src/arch/arduino-nano/arch.cc
@@ -24,10 +24,14 @@ void Arch::setup(void)
sei();
}
+#ifdef WITH_WAKEUP
+void wakeup();
+#endif
+
#if defined(WITH_LOOP) || defined(TIMER_S)
#include "driver/uptime.h"
-extern void loop();
+void loop();
#endif
@@ -41,6 +45,9 @@ void Arch::idle_loop(void)
#ifdef WITH_LOOP
loop();
#endif
+#ifdef WITH_WAKEUP
+ wakeup();
+#endif
#ifdef TIMER_S
uptime.tick_s();
#endif
diff --git a/src/arch/arduino-nano/driver/stdin.cc b/src/arch/arduino-nano/driver/stdin.cc
new file mode 100644
index 0000000..ac58a61
--- /dev/null
+++ b/src/arch/arduino-nano/driver/stdin.cc
@@ -0,0 +1,32 @@
+#include "driver/stdin.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+void StandardInput::setup()
+{
+ UCSR0B |= _BV(RXCIE0);
+}
+
+bool StandardInput::hasKey()
+{
+ if (write_pos != read_pos) {
+ return true;
+ }
+ return false;
+}
+
+char StandardInput::getKey()
+{
+ char ret = buffer[read_pos++];
+ read_pos %= 8;
+ return ret;
+}
+
+StandardInput kin;
+
+ISR(USART_RX_vect)
+{
+ while (UCSR0A & _BV(RXC0)) {
+ kin.addKey(UDR0);
+ }
+}