summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-01-26 22:39:37 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-01-26 22:39:54 +0100
commit742ed60b4373bb2c81cd3b4fbc91107ab3c36fca (patch)
treee1251dae9956d242cac21c2da263b032c365ad4a
parent0290ca63a235b98642d54bdd3fc2ec5121b5dd69 (diff)
atmega2560: add stdin driver
-rw-r--r--include/arch/atmega2560/driver/stdin.h30
-rw-r--r--src/arch/atmega2560/Kconfig12
-rw-r--r--src/arch/atmega2560/Makefile.inc4
-rw-r--r--src/arch/atmega2560/driver/stdin.cc35
4 files changed, 81 insertions, 0 deletions
diff --git a/include/arch/atmega2560/driver/stdin.h b/include/arch/atmega2560/driver/stdin.h
new file mode 100644
index 0000000..9a99b00
--- /dev/null
+++ b/include/arch/atmega2560/driver/stdin.h
@@ -0,0 +1,30 @@
+/*
+ * 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
diff --git a/src/arch/atmega2560/Kconfig b/src/arch/atmega2560/Kconfig
index f2d83f8..8c25f97 100644
--- a/src/arch/atmega2560/Kconfig
+++ b/src/arch/atmega2560/Kconfig
@@ -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
diff --git a/src/arch/atmega2560/Makefile.inc b/src/arch/atmega2560/Makefile.inc
index e404331..d00c611 100644
--- a/src/arch/atmega2560/Makefile.inc
+++ b/src/arch/atmega2560/Makefile.inc
@@ -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
diff --git a/src/arch/atmega2560/driver/stdin.cc b/src/arch/atmega2560/driver/stdin.cc
new file mode 100644
index 0000000..213b29e
--- /dev/null
+++ b/src/arch/atmega2560/driver/stdin.cc
@@ -0,0 +1,35 @@
+/*
+ * 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);
+}