From 7e5acdd89604319721a3228a3c1dc5570a09223e Mon Sep 17 00:00:00 2001 From: CVR Date: Thu, 9 Sep 2021 12:27:09 +1200 Subject: [PATCH] Add usart lib --- test/rx/main.cpp | 2 +- test/tx/main.cpp | 2 +- test/usart.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ test/usart.h | 14 +++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 test/usart.cpp create mode 100644 test/usart.h diff --git a/test/rx/main.cpp b/test/rx/main.cpp index 8637985..10b8d0c 100644 --- a/test/rx/main.cpp +++ b/test/rx/main.cpp @@ -8,7 +8,7 @@ */ #define F_CPU 8000000UL #include "../../src/mrf24j.h" -#include "../../lib/usart/src/usart.h" +#include "../usart.h" #include #include diff --git a/test/tx/main.cpp b/test/tx/main.cpp index c3cc9f4..56cf8f1 100644 --- a/test/tx/main.cpp +++ b/test/tx/main.cpp @@ -9,7 +9,7 @@ #define F_CPU 8000000UL #include "../../src/mrf24j.h" -#include "../../lib/usart/src/usart.h" +#include "../usart.h" #include "../../src/driver.h" #include #include diff --git a/test/usart.cpp b/test/usart.cpp new file mode 100644 index 0000000..65b6719 --- /dev/null +++ b/test/usart.cpp @@ -0,0 +1,65 @@ +#include +#include +#include "usart.h" + +namespace usart +{ + namespace { + static FILE mystdout; + } + + void init( unsigned long baud) { + fdev_setup_stream(&mystdout, put_printf, NULL, _FDEV_SETUP_WRITE); + stdout = &mystdout; + const unsigned int ubrr = F_CPU/8/baud-1; + + /*Set baud rate */ + + + #if defined __AVR_ATmega328P__ + UBRR0H = (unsigned char)(ubrr>>8); + UBRR0L = (unsigned char)ubrr; + UCSR0A |= (1<>8); + UBRRL = (unsigned char)ubrr; + UCSRA |= (1< + +namespace usart +{ + void init(unsigned long baud); + void put(char data ); + char get(); + int put_printf(char var, FILE *stream); +} // namespace usart + + +