summaryrefslogtreecommitdiff
path: root/src/arch/atmega2560
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-01-26 20:38:50 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2024-01-26 20:38:50 +0100
commit218166456b68ca2266c8e7c77c1085ad4fc16e86 (patch)
treed83ca341c6706dcbac806c960d8f8baaadfc0421 /src/arch/atmega2560
parentfc4a1906ff3fa4ce355c3a058b15ed243d8ce7a8 (diff)
ATMega2560: Add stdin and stdout on UART1, UART2, UART3
Diffstat (limited to 'src/arch/atmega2560')
-rw-r--r--src/arch/atmega2560/Kconfig79
-rw-r--r--src/arch/atmega2560/Makefile.inc24
-rw-r--r--src/arch/atmega2560/driver/stdin1.cc35
-rw-r--r--src/arch/atmega2560/driver/stdin2.cc35
-rw-r--r--src/arch/atmega2560/driver/stdin3.cc35
-rw-r--r--src/arch/atmega2560/driver/stdout1.cc39
-rw-r--r--src/arch/atmega2560/driver/stdout2.cc39
-rw-r--r--src/arch/atmega2560/driver/stdout3.cc39
8 files changed, 322 insertions, 3 deletions
diff --git a/src/arch/atmega2560/Kconfig b/src/arch/atmega2560/Kconfig
index 31ad215..d93a808 100644
--- a/src/arch/atmega2560/Kconfig
+++ b/src/arch/atmega2560/Kconfig
@@ -2,8 +2,22 @@
#
# SPDX-License-Identifier: CC0-1.0
-config arch_atmega2560_driver_dmx
-bool "DMX"
+config arch_atmega2560_driver_dmx1
+bool "DMX1 Output on PD3 (D18)"
+help
+ TX: PD3 (UART1) (D18)
+select meta_driver_dmx
+
+config arch_atmega2560_driver_dmx2
+bool "DMX2 Output on PH1 (D16)"
+help
+ TX: PH1 (UART2) (D16)
+select meta_driver_dmx
+
+config arch_atmega2560_driver_dmx3
+bool "DMX3 Output on PJ1 (D14)"
+help
+ TX: PJ1 (UART3) (D14)
select meta_driver_dmx
config arch_atmega2560_driver_i2c
@@ -11,10 +25,69 @@ bool "I2C"
select meta_driver_hardware_i2c
select meta_driver_i2c
+config arch_atmega2560_driver_stdout1
+bool "UART1 Output on PD3 (D18)"
+help
+ TX: PD3 (UART1) (D18)
+select meta_driver_stdout1
+
+config arch_atmega2560_uart1_baud
+int "UART1 Baud Rate"
+range 9600 249600
+default 57600
+depends on arch_atmega2560_driver_stdout1
+
+config arch_atmega2560_driver_stdout2
+bool "UART2 Output on PH1 (D16)"
+help
+ TX: PH1 (UART2) (D16)
+select meta_driver_stdout2
+
+config arch_atmega2560_uart2_baud
+int "UART2 Baud Rate"
+range 9600 249600
+default 57600
+depends on arch_atmega2560_driver_stdout2
+
+config arch_atmega2560_driver_stdout3
+bool "UART3 Output on PJ1 (D14)"
+help
+ TX: PJ1 (UART3) (D14)
+select meta_driver_stdout3
+
+config arch_atmega2560_uart3_baud
+int "UART3 Baud Rate"
+range 9600 249600
+default 57600
+depends on arch_atmega2560_driver_stdout3
+
config arch_atmega2560_driver_stdin
-bool "UART Input"
+bool "UART0 Input on PE0 (RX)"
+help
+ RX: PE0 (UART0) (RX)
select meta_driver_stdin
+config arch_atmega2560_driver_stdin1
+bool "UART1 Input on PD2 (D19)"
+help
+ RX: PD2 (UART1) (D19)
+depends on arch_atmega2560_driver_stdout1
+select meta_driver_stdin1
+
+config arch_atmega2560_driver_stdin2
+bool "UART2 Input on PH0 (D17)"
+help
+ RX: PH0 (UART2) (D17)
+depends on arch_atmega2560_driver_stdout2
+select meta_driver_stdin2
+
+config arch_atmega2560_driver_stdin3
+bool "UART3 Input on PE0 (RX)"
+help
+ RX: PE0 (UART0) (RX)
+depends on arch_atmega2560_driver_stdout3
+select meta_driver_stdin3
+
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 d7a6b05..39821da 100644
--- a/src/arch/atmega2560/Makefile.inc
+++ b/src/arch/atmega2560/Makefile.inc
@@ -91,10 +91,34 @@ ifdef CONFIG_arch_atmega2560_driver_spi
CXX_TARGETS += src/arch/atmega2560/driver/spi.cc
endif
+ifdef CONFIG_arch_atmega2560_driver_stdout1
+ CXX_TARGETS += src/arch/atmega2560/driver/stdout1.cc
+endif
+
+ifdef CONFIG_arch_atmega2560_driver_stdout2
+ CXX_TARGETS += src/arch/atmega2560/driver/stdout2.cc
+endif
+
+ifdef CONFIG_arch_atmega2560_driver_stdout3
+ CXX_TARGETS += src/arch/atmega2560/driver/stdout3.cc
+endif
+
ifdef CONFIG_arch_atmega2560_driver_stdin
CXX_TARGETS += src/arch/atmega2560/driver/stdin.cc
endif
+ifdef CONFIG_arch_atmega2560_driver_stdin1
+ CXX_TARGETS += src/arch/atmega2560/driver/stdin1.cc
+endif
+
+ifdef CONFIG_arch_atmega2560_driver_stdin2
+ CXX_TARGETS += src/arch/atmega2560/driver/stdin2.cc
+endif
+
+ifdef CONFIG_arch_atmega2560_driver_stdin3
+ CXX_TARGETS += src/arch/atmega2560/driver/stdin3.cc
+endif
+
ifdef CONFIG_arch_atmega2560_driver_timer
CXX_TARGETS += src/arch/atmega2560/driver/timer.cc
endif
diff --git a/src/arch/atmega2560/driver/stdin1.cc b/src/arch/atmega2560/driver/stdin1.cc
new file mode 100644
index 0000000..85b825b
--- /dev/null
+++ b/src/arch/atmega2560/driver/stdin1.cc
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2020 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/stdin1.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+void StandardInput1::setup()
+{
+ UCSR1B |= _BV(RXCIE1);
+}
+
+bool StandardInput1::hasKey()
+{
+ if (write_pos != read_pos) {
+ return true;
+ }
+ return false;
+}
+
+char StandardInput1::getKey()
+{
+ char ret = buffer[read_pos++];
+ read_pos %= bufsize;
+ return ret;
+}
+
+StandardInput1 kin1;
+
+ISR(USART1_RX_vect)
+{
+ kin1.addKey(UDR1);
+}
diff --git a/src/arch/atmega2560/driver/stdin2.cc b/src/arch/atmega2560/driver/stdin2.cc
new file mode 100644
index 0000000..f807e26
--- /dev/null
+++ b/src/arch/atmega2560/driver/stdin2.cc
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2020 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/stdin2.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+void StandardInput2::setup()
+{
+ UCSR2B |= _BV(RXCIE2);
+}
+
+bool StandardInput2::hasKey()
+{
+ if (write_pos != read_pos) {
+ return true;
+ }
+ return false;
+}
+
+char StandardInput2::getKey()
+{
+ char ret = buffer[read_pos++];
+ read_pos %= bufsize;
+ return ret;
+}
+
+StandardInput2 kin2;
+
+ISR(USART2_RX_vect)
+{
+ kin2.addKey(UDR2);
+}
diff --git a/src/arch/atmega2560/driver/stdin3.cc b/src/arch/atmega2560/driver/stdin3.cc
new file mode 100644
index 0000000..7b32fe6
--- /dev/null
+++ b/src/arch/atmega2560/driver/stdin3.cc
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2020 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/stdin3.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+void StandardInput3::setup()
+{
+ UCSR3B |= _BV(RXCIE3);
+}
+
+bool StandardInput3::hasKey()
+{
+ if (write_pos != read_pos) {
+ return true;
+ }
+ return false;
+}
+
+char StandardInput3::getKey()
+{
+ char ret = buffer[read_pos++];
+ read_pos %= bufsize;
+ return ret;
+}
+
+StandardInput3 kin3;
+
+ISR(USART3_RX_vect)
+{
+ kin3.addKey(UDR3);
+}
diff --git a/src/arch/atmega2560/driver/stdout1.cc b/src/arch/atmega2560/driver/stdout1.cc
new file mode 100644
index 0000000..e686237
--- /dev/null
+++ b/src/arch/atmega2560/driver/stdout1.cc
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2024 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/stdout1.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#undef BAUD
+#define BAUD CONFIG_arch_atmega2560_uart1_baud
+
+#include <util/setbaud.h>
+
+void StandardOutput1::setup()
+{
+ UBRR1H = UBRRH_VALUE;
+ UBRR1L = UBRRL_VALUE;
+
+#if USE_2X
+ UCSR1A |= _BV(U2X1);
+#else
+ UCSR1A &= ~_BV(U2X1);
+#endif
+
+ UCSR1B |= _BV(RXEN1) | _BV(TXEN1);
+ UCSR1C = _BV(UCSZ11) | _BV(UCSZ10);
+}
+
+void StandardOutput1::put(char c)
+{
+ while (!(UCSR1A & _BV(UDRE1)));
+ UDR1 = c;
+ if (c == '\n') {
+ put('\r');
+ }
+}
+
+StandardOutput1 kout1;
diff --git a/src/arch/atmega2560/driver/stdout2.cc b/src/arch/atmega2560/driver/stdout2.cc
new file mode 100644
index 0000000..254226e
--- /dev/null
+++ b/src/arch/atmega2560/driver/stdout2.cc
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2024 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/stdout2.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#undef BAUD
+#define BAUD CONFIG_arch_atmega2560_uart2_baud
+
+#include <util/setbaud.h>
+
+void StandardOutput2::setup()
+{
+ UBRR2H = UBRRH_VALUE;
+ UBRR2L = UBRRL_VALUE;
+
+#if USE_2X
+ UCSR2A |= _BV(U2X2);
+#else
+ UCSR2A &= ~_BV(U2X2);
+#endif
+
+ UCSR2B |= _BV(RXEN2) | _BV(TXEN2);
+ UCSR2C = _BV(UCSZ21) | _BV(UCSZ20);
+}
+
+void StandardOutput2::put(char c)
+{
+ while (!(UCSR2A & _BV(UDRE2)));
+ UDR2 = c;
+ if (c == '\n') {
+ put('\r');
+ }
+}
+
+StandardOutput2 kout2;
diff --git a/src/arch/atmega2560/driver/stdout3.cc b/src/arch/atmega2560/driver/stdout3.cc
new file mode 100644
index 0000000..451a043
--- /dev/null
+++ b/src/arch/atmega2560/driver/stdout3.cc
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2024 Birte Kristina Friesel
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include "driver/stdout3.h"
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#undef BAUD
+#define BAUD CONFIG_arch_atmega2560_uart3_baud
+
+#include <util/setbaud.h>
+
+void StandardOutput3::setup()
+{
+ UBRR3H = UBRRH_VALUE;
+ UBRR3L = UBRRL_VALUE;
+
+#if USE_2X
+ UCSR3A |= _BV(U2X3);
+#else
+ UCSR3A &= ~_BV(U2X3);
+#endif
+
+ UCSR3B |= _BV(RXEN3) | _BV(TXEN3);
+ UCSR3C = _BV(UCSZ31) | _BV(UCSZ30);
+}
+
+void StandardOutput3::put(char c)
+{
+ while (!(UCSR3A & _BV(UDRE3)));
+ UDR3 = c;
+ if (c == '\n') {
+ put('\r');
+ }
+}
+
+StandardOutput3 kout3;