summaryrefslogtreecommitdiff
path: root/src/arch/atmega2560/driver/stdout3.cc
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/driver/stdout3.cc
parentfc4a1906ff3fa4ce355c3a058b15ed243d8ce7a8 (diff)
ATMega2560: Add stdin and stdout on UART1, UART2, UART3
Diffstat (limited to 'src/arch/atmega2560/driver/stdout3.cc')
-rw-r--r--src/arch/atmega2560/driver/stdout3.cc39
1 files changed, 39 insertions, 0 deletions
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;