summaryrefslogtreecommitdiff
path: root/src/arch/arduino-nano
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 /src/arch/arduino-nano
parent3875f37b2ce1d020aaf5174ea2a885bfdb98db98 (diff)
add arduino nano stdin driver
Diffstat (limited to 'src/arch/arduino-nano')
-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
3 files changed, 44 insertions, 1 deletions
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);
+ }
+}