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

atmega2560: add stdin driver

parent 0290ca63
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2021 Daniel Friesel
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#ifndef STANDARDINPUT_H
#define STANDARDINPUT_H
class StandardInput {
private:
StandardInput(const StandardInput &copy);
static unsigned char const bufsize = 16;
char buffer[bufsize];
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 = (write_pos + 1) % bufsize;
}
};
extern StandardInput kin;
#endif
......@@ -2,7 +2,19 @@
#
# SPDX-License-Identifier: CC0-1.0
config arch_atmega2560_driver_dmx
bool "DMX"
select meta_driver_dmx
config arch_atmega2560_driver_i2c
bool "I2C"
select meta_driver_hardware_i2c
select meta_driver_i2c
config arch_atmega2560_driver_stdin
bool "UART Input"
select meta_driver_stdin
config arch_atmega2560_driver_timer
bool "Timer with Interrupts"
select meta_driver_timer
......@@ -83,6 +83,10 @@ ifdef CONFIG_arch_atmega2560_driver_adc
CXX_TARGETS += src/arch/atmega2560/driver/adc.cc
endif
ifdef CONFIG_arch_atmega2560_driver_dmx
CXX_TARGETS += src/arch/atmega2560/driver/dmx.cc
endif
ifdef CONFIG_arch_atmega2560_driver_spi
CXX_TARGETS += src/arch/atmega2560/driver/spi.cc
endif
......
/*
* Copyright 2020 Daniel Friesel
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#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 %= bufsize;
return ret;
}
StandardInput kin;
ISR(USART0_RX_vect)
{
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