summaryrefslogtreecommitdiff
path: root/src/arch/msp430fr5969lp/driver/stdin.cc
blob: 92b71576c4187d1b0ab54726237a0ca8236324b4 (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
33
34
35
36
37
38
39
40
/*
 * Copyright 2020 Birte Kristina Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "driver/stdin.h"
#include <msp430.h>

void StandardInput::setup()
{
	UCA0CTLW0 |= UCSWRST;
	P2SEL0 &= ~BIT1;
	P2SEL1 |= BIT1;
	UCA0CTLW0 &= ~UCSWRST;
	UCA0IE |= UCRXIE;
}

bool StandardInput::hasKey()
{
	if (write_pos != read_pos) {
		return true;
	}
	return false;
}

char StandardInput::getKey()
{
	char ret = buffer[read_pos++];
	read_pos %= bufsize;
	return ret;
}

StandardInput kin;

__attribute__((interrupt(USCI_A0_VECTOR))) __attribute__((wakeup)) void handle_stdin()
{
	if (UCA0IFG & UCRXIFG) {
		kin.addKey(UCA0RXBUF);
	}
}