From 218166456b68ca2266c8e7c77c1085ad4fc16e86 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Fri, 26 Jan 2024 20:38:50 +0100 Subject: ATMega2560: Add stdin and stdout on UART1, UART2, UART3 --- include/arch/atmega2560/driver/stdin1.h | 30 ++++++++++++++++++++++++++++++ include/arch/atmega2560/driver/stdin2.h | 30 ++++++++++++++++++++++++++++++ include/arch/atmega2560/driver/stdin3.h | 30 ++++++++++++++++++++++++++++++ include/arch/atmega2560/driver/stdout1.h | 24 ++++++++++++++++++++++++ include/arch/atmega2560/driver/stdout2.h | 24 ++++++++++++++++++++++++ include/arch/atmega2560/driver/stdout3.h | 24 ++++++++++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 include/arch/atmega2560/driver/stdin1.h create mode 100644 include/arch/atmega2560/driver/stdin2.h create mode 100644 include/arch/atmega2560/driver/stdin3.h create mode 100644 include/arch/atmega2560/driver/stdout1.h create mode 100644 include/arch/atmega2560/driver/stdout2.h create mode 100644 include/arch/atmega2560/driver/stdout3.h (limited to 'include/arch/atmega2560/driver') 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 -- cgit v1.2.3