Commit 742ed60b authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

atmega2560: add stdin driver

parent 0290ca63
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
/*
 * 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
+12 −0
Original line number Diff line number Diff line
@@ -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
+4 −0
Original line number Diff line number Diff line
@@ -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
+35 −0
Original line number Diff line number Diff line
/*
 * 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);
}