diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-01-12 15:07:44 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-01-12 15:07:44 +0100 |
commit | 8cdcdcf7572d08d5def7fddc7a9438826eeed22b (patch) | |
tree | 73af74dfcd30d102cea5ceceda71115f88ee26f1 /src/arch/arduino-nano/driver/stdin.cc | |
parent | 3875f37b2ce1d020aaf5174ea2a885bfdb98db98 (diff) |
add arduino nano stdin driver
Diffstat (limited to 'src/arch/arduino-nano/driver/stdin.cc')
-rw-r--r-- | src/arch/arduino-nano/driver/stdin.cc | 32 |
1 files changed, 32 insertions, 0 deletions
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); + } +} |