Skip to content
Snippets Groups Projects
Commit 8cdcdcf7 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add arduino nano stdin driver

parent 3875f37b
No related branches found
No related tags found
No related merge requests found
#ifndef STANDARDINPUT_H
#define STANDARDINPUT_H
class StandardInput {
private:
StandardInput(const StandardInput &copy);
char buffer[8];
unsigned char write_pos, read_pos;
public:
StandardInput() : write_pos(0), read_pos(0) {}
void setup();
bool hasKey();
char getKey();
inline void addKey(char key) {
buffer[write_pos++] = key;
write_pos %= 8;
}
};
extern StandardInput kin;
#endif
......@@ -23,6 +23,10 @@ TARGETS += src/arch/arduino-nano/driver/gpio.cc
TARGETS += src/arch/arduino-nano/driver/stdout.cc
TARGETS += src/arch/arduino-nano/driver/uptime.cc
ifneq ($(findstring stdin,${arch_drivers}), )
TARGETS += src/arch/arduino-nano/driver/stdin.cc
endif
OBJECTS = ${TARGETS:.cc=.o}
.cc.o:
......
......@@ -24,10 +24,14 @@ void Arch::setup(void)
sei();
}
#ifdef WITH_WAKEUP
void wakeup();
#endif
#if defined(WITH_LOOP) || defined(TIMER_S)
#include "driver/uptime.h"
extern void loop();
void loop();
#endif
......@@ -41,6 +45,9 @@ void Arch::idle_loop(void)
#ifdef WITH_LOOP
loop();
#endif
#ifdef WITH_WAKEUP
wakeup();
#endif
#ifdef TIMER_S
uptime.tick_s();
#endif
......
#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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment