From 408ab83afbe20b4cb4f6ca5869a22e8198ecebbf Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 2 Aug 2019 17:42:12 +0200 Subject: [PATCH] Changed example to use rx as well --- uart/main.cpp | 94 ++++++++++++++++++++++------------------- uart/uart | 2 +- uart/uart.cppproj | 104 +++++++++++++++++++++++----------------------- 3 files changed, 104 insertions(+), 96 deletions(-) diff --git a/uart/main.cpp b/uart/main.cpp index cea9758..2d09849 100644 --- a/uart/main.cpp +++ b/uart/main.cpp @@ -13,9 +13,17 @@ void newUartUsage() { using namespace uart; - Uart1<> serial1; + Uart, Driven::INTERRUPT>> serial1; + sei(); - serial1 << "Hello World from RAM. " << F("Hello World from flash\r\n"); + serial1 << F("Hello World from RAM. ") << F("Hello World from flash\r\n"); + + while (true) { + uint8_t received = 0; + + if (serial1.rxByte(received)) + serial1.txByte(received); + } _delay_ms(1000); } @@ -25,7 +33,7 @@ void newUartUsage2() using namespace uart; using config = Config<9600, DataBits::EIGHT, Parity::NONE, StopBits::ONE>; - using uart0 = Hardware0; + using uart0 = Hardware0; using softuart = Software; Uart serial; @@ -47,37 +55,37 @@ void oldUsartUsage() _delay_ms(1000); } - +/* namespace spi { enum class Cpol { - MODE_0, - MODE_1, + MODE_0, + MODE_1, }; enum class Cpha { - MODE_0, - MODE_1, + MODE_0, + MODE_1, }; enum class DataOrder { - MSB, - LSB, + MSB, + LSB, }; template struct Config { - static constexpr auto CPOL_MODE = cpol; - static constexpr auto CPHA_MODE = cpha; - static constexpr auto DATA_ORDER = dataOrder; + static constexpr auto CPOL_MODE = cpol; + static constexpr auto CPHA_MODE = cpha; + static constexpr auto DATA_ORDER = dataOrder; }; template struct spi { - spi() - { - Driver::init(); - } + spi() + { + Driver::init(); + } }; } // namespace spi @@ -87,42 +95,42 @@ namespace uart { template class Hardware0 { public: - static void init() - { - UCSR0C |= (1 << UMSEL01) | (1 << UMSEL00); + static void init() + { + UCSR0C |= (1 << UMSEL01) | (1 << UMSEL00); - if (DATA_ORDER == spi::DataOrder::MSB) - UCSR0C &= ~(1 << UCSZ01); - else - UCSR0C |= (1 << UCSZ01); + if (DATA_ORDER == spi::DataOrder::MSB) + UCSR0C &= ~(1 << UCSZ01); + else + UCSR0C |= (1 << UCSZ01); - if (CPOL_MODE == spi::Cpol::MODE_0) - UCSR0C &= ~(1 << UCPOL0); - else - UCSR0C |= (1 << UCPOL0); + if (CPOL_MODE == spi::Cpol::MODE_0) + UCSR0C &= ~(1 << UCPOL0); + else + UCSR0C |= (1 << UCPOL0); - if (CPHA_MODE == spi::Cpha::MODE_0) - UCSR0C &= ~(1 << UCSZ00); - else - UCSR0C |= (1 << UCSZ00); - } + if (CPHA_MODE == spi::Cpha::MODE_0) + UCSR0C &= ~(1 << UCSZ00); + else + UCSR0C |= (1 << UCSZ00); + } private: - static constexpr auto CPOL_MODE = Config::CPOL_MODE; - static constexpr auto CPHA_MODE = Config::CPHA_MODE; - static constexpr auto DATA_ORDER = Config::DATA_ORDER; + static constexpr auto CPOL_MODE = Config::CPOL_MODE; + static constexpr auto CPHA_MODE = Config::CPHA_MODE; + static constexpr auto DATA_ORDER = Config::DATA_ORDER; }; } // namespace uart void spiTest() { - using config = spi::Config; - using uartspi = uart::Hardware0; + using config = spi::Config; + using uartspi = uart::Hardware0; - spi::spi uartSpi; + spi::spi uartSpi; } - +*/ static inline void initUart(const uint32_t baudRate) { UBRR0 = static_cast((F_CPU / (16 * baudRate)) - 1); @@ -170,11 +178,11 @@ void cUartLibTest() auto ramString = "Hello World from RAM. "; auto flashString = F("Hello World from flash\r\n"); - uart_init(UART_BAUD_SELECT(9600, F_CPU)); + uart1_init(UART_BAUD_SELECT(9600, F_CPU)); sei(); - uart_puts(ramString); - uart_puts_p(reinterpret_cast(flashString)); + uart1_puts(ramString); + uart1_puts_p(reinterpret_cast(flashString)); _delay_ms(1000); } diff --git a/uart/uart b/uart/uart index 92c96bb..0bfd303 160000 --- a/uart/uart +++ b/uart/uart @@ -1 +1 @@ -Subproject commit 92c96bbc72e8784f10d38e85073c5bd010ab877e +Subproject commit 0bfd303a26a8aad77607e9cefb1039997952af09 diff --git a/uart/uart.cppproj b/uart/uart.cppproj index 8efb015..fb99325 100644 --- a/uart/uart.cppproj +++ b/uart/uart.cppproj @@ -86,58 +86,58 @@ - -mmcu=atmega1284p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega1284p" - True - True - True - True - True - False - True - True - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - - - True - True - True - True - True - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - - - True - True - True - True - -Wextra -std=c++17 - - - libm - - - - - %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include - - - - - NDEBUG - - - Optimize for size (-Os) - - - NDEBUG - - - Optimize for size (-Os) - + -mmcu=atmega1284p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega1284p" + True + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + Optimize for size (-Os) + True + True + True + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + + Optimize for size (-Os) + True + True + True + True + -Wextra -std=c++17 + + + libm + + + + + %24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include + + +