diff options
Diffstat (limited to 'src/arch/atmega2560/driver/stdin1.cc')
-rw-r--r-- | src/arch/atmega2560/driver/stdin1.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/arch/atmega2560/driver/stdin1.cc b/src/arch/atmega2560/driver/stdin1.cc new file mode 100644 index 0000000..85b825b --- /dev/null +++ b/src/arch/atmega2560/driver/stdin1.cc @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "driver/stdin1.h" +#include <avr/io.h> +#include <avr/interrupt.h> + +void StandardInput1::setup() +{ + UCSR1B |= _BV(RXCIE1); +} + +bool StandardInput1::hasKey() +{ + if (write_pos != read_pos) { + return true; + } + return false; +} + +char StandardInput1::getKey() +{ + char ret = buffer[read_pos++]; + read_pos %= bufsize; + return ret; +} + +StandardInput1 kin1; + +ISR(USART1_RX_vect) +{ + kin1.addKey(UDR1); +} |