From 8cdcdcf7572d08d5def7fddc7a9438826eeed22b Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 12 Jan 2018 15:07:44 +0100 Subject: add arduino nano stdin driver --- src/arch/arduino-nano/driver/stdin.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/arch/arduino-nano/driver/stdin.cc (limited to 'src/arch/arduino-nano/driver') 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 +#include + +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); + } +} -- cgit v1.2.3