summaryrefslogtreecommitdiff
path: root/src/arch/atmega2560/driver
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/atmega2560/driver')
-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
6 files changed, 222 insertions, 0 deletions
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;