diff options
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); + } +} |