summaryrefslogtreecommitdiff
path: root/src/arch/arduino-nano/driver/stdin.cc
blob: ac58a61833dffa2d33df6e42b7a2c867f5cc9fe7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
	}
}