diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-01-26 20:38:50 +0100 | 
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-01-26 20:38:50 +0100 | 
| commit | 218166456b68ca2266c8e7c77c1085ad4fc16e86 (patch) | |
| tree | d83ca341c6706dcbac806c960d8f8baaadfc0421 | |
| parent | fc4a1906ff3fa4ce355c3a058b15ed243d8ce7a8 (diff) | |
ATMega2560: Add stdin and stdout on UART1, UART2, UART3
| -rw-r--r-- | include/arch/atmega2560/driver/stdin1.h | 30 | ||||
| -rw-r--r-- | include/arch/atmega2560/driver/stdin2.h | 30 | ||||
| -rw-r--r-- | include/arch/atmega2560/driver/stdin3.h | 30 | ||||
| -rw-r--r-- | include/arch/atmega2560/driver/stdout1.h | 24 | ||||
| -rw-r--r-- | include/arch/atmega2560/driver/stdout2.h | 24 | ||||
| -rw-r--r-- | include/arch/atmega2560/driver/stdout3.h | 24 | ||||
| -rw-r--r-- | src/arch/atmega2560/Kconfig | 79 | ||||
| -rw-r--r-- | src/arch/atmega2560/Makefile.inc | 24 | ||||
| -rw-r--r-- | src/arch/atmega2560/driver/stdin1.cc | 35 | ||||
| -rw-r--r-- | src/arch/atmega2560/driver/stdin2.cc | 35 | ||||
| -rw-r--r-- | src/arch/atmega2560/driver/stdin3.cc | 35 | ||||
| -rw-r--r-- | src/arch/atmega2560/driver/stdout1.cc | 39 | ||||
| -rw-r--r-- | src/arch/atmega2560/driver/stdout2.cc | 39 | ||||
| -rw-r--r-- | src/arch/atmega2560/driver/stdout3.cc | 39 | ||||
| -rw-r--r-- | src/driver/Kconfig | 12 | 
15 files changed, 496 insertions, 3 deletions
| diff --git a/include/arch/atmega2560/driver/stdin1.h b/include/arch/atmega2560/driver/stdin1.h new file mode 100644 index 0000000..c32d1f8 --- /dev/null +++ b/include/arch/atmega2560/driver/stdin1.h @@ -0,0 +1,30 @@ +/* + * Copyright 2021 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef STANDARDINPUT1_H +#define STANDARDINPUT1_H + +class StandardInput1 { +	private: +		StandardInput1(const StandardInput1 ©); +		static unsigned char const bufsize = 16; +		char buffer[bufsize]; +		unsigned char write_pos, read_pos; + +	public: +		StandardInput1() : 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 StandardInput1 kin1; + +#endif diff --git a/include/arch/atmega2560/driver/stdin2.h b/include/arch/atmega2560/driver/stdin2.h new file mode 100644 index 0000000..3d4c1b4 --- /dev/null +++ b/include/arch/atmega2560/driver/stdin2.h @@ -0,0 +1,30 @@ +/* + * Copyright 2021 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef STANDARDINPUT2_H +#define STANDARDINPUT2_H + +class StandardInput2 { +	private: +		StandardInput2(const StandardInput2 ©); +		static unsigned char const bufsize = 16; +		char buffer[bufsize]; +		unsigned char write_pos, read_pos; + +	public: +		StandardInput2() : 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 StandardInput2 kin2; + +#endif diff --git a/include/arch/atmega2560/driver/stdin3.h b/include/arch/atmega2560/driver/stdin3.h new file mode 100644 index 0000000..ec80f43 --- /dev/null +++ b/include/arch/atmega2560/driver/stdin3.h @@ -0,0 +1,30 @@ +/* + * Copyright 2021 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef STANDARDINPUT3_H +#define STANDARDINPUT3_H + +class StandardInput3 { +	private: +		StandardInput3(const StandardInput3 ©); +		static unsigned char const bufsize = 16; +		char buffer[bufsize]; +		unsigned char write_pos, read_pos; + +	public: +		StandardInput3() : 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 StandardInput3 kin3; + +#endif diff --git a/include/arch/atmega2560/driver/stdout1.h b/include/arch/atmega2560/driver/stdout1.h new file mode 100644 index 0000000..5ca03bb --- /dev/null +++ b/include/arch/atmega2560/driver/stdout1.h @@ -0,0 +1,24 @@ +/* + * Copyright 2021 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef STANDARDOUTPUT1_H +#define STANDARDOUTPUT1_H + +#include "object/outputstream.h" + +class StandardOutput1 : public OutputStream { +	private: +		StandardOutput1(const StandardOutput1 ©); + +	public: +		StandardOutput1 () {} +		void setup(); + +		virtual void put(char c) override; +}; + +extern StandardOutput1 kout1; + +#endif diff --git a/include/arch/atmega2560/driver/stdout2.h b/include/arch/atmega2560/driver/stdout2.h new file mode 100644 index 0000000..6930ee5 --- /dev/null +++ b/include/arch/atmega2560/driver/stdout2.h @@ -0,0 +1,24 @@ +/* + * Copyright 2021 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef STANDARDOUTPUT2_H +#define STANDARDOUTPUT2_H + +#include "object/outputstream.h" + +class StandardOutput2 : public OutputStream { +	private: +		StandardOutput2(const StandardOutput2 ©); + +	public: +		StandardOutput2 () {} +		void setup(); + +		virtual void put(char c) override; +}; + +extern StandardOutput2 kout2; + +#endif diff --git a/include/arch/atmega2560/driver/stdout3.h b/include/arch/atmega2560/driver/stdout3.h new file mode 100644 index 0000000..290bded --- /dev/null +++ b/include/arch/atmega2560/driver/stdout3.h @@ -0,0 +1,24 @@ +/* + * Copyright 2021 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#ifndef STANDARDOUTPUT3_H +#define STANDARDOUTPUT3_H + +#include "object/outputstream.h" + +class StandardOutput3 : public OutputStream { +	private: +		StandardOutput3(const StandardOutput3 ©); + +	public: +		StandardOutput3 () {} +		void setup(); + +		virtual void put(char c) override; +}; + +extern StandardOutput3 kout3; + +#endif 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; diff --git a/src/driver/Kconfig b/src/driver/Kconfig index eff39d0..2d9f16b 100644 --- a/src/driver/Kconfig +++ b/src/driver/Kconfig @@ -18,6 +18,18 @@ config meta_driver_spi  bool  config meta_driver_stdin  bool +config meta_driver_stdin1 +bool +config meta_driver_stdin2 +bool +config meta_driver_stdin3 +bool +config meta_driver_stdout1 +bool +config meta_driver_stdout2 +bool +config meta_driver_stdout3 +bool  config meta_driver_timer  bool  config meta_driver_uptime | 
