From d952794c559b2b4876d43b4082dc34f8dba8cc05 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sun, 28 Jul 2019 18:00:15 +0200 Subject: [PATCH] Refactored code to use capital letters for classes and added using namespace inside functions --- uart/main.cpp | 42 +++++++++++++++++++++++++++--------------- uart/uart | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/uart/main.cpp b/uart/main.cpp index af3ad06..92dd7b5 100644 --- a/uart/main.cpp +++ b/uart/main.cpp @@ -18,7 +18,7 @@ enum class Parity { DISABLED = 0, ODD = 1, EVEN = 2 }; enum class StopBit { ONE = 1, TWO = 2 }; template -class hardware0 { +class Hardware0 { static constexpr auto calcBaud() { uint16_t ui16UBRR = ((F_CPU / (16 * baudRate)) - 1); @@ -185,7 +185,7 @@ class uart { void usartTestUsage() { - using uart0 = uart_test::hardware0<9600, 8, uart_test::Parity::DISABLED, uart_test::StopBit::ONE, + using uart0 = uart_test::Hardware0<9600, 8, uart_test::Parity::DISABLED, uart_test::StopBit::ONE, uart_test::Mode::ASYNCHRONOUS>; /*using softuart = uart::Device, 9600, 8, uart::Parity::DISABLED, @@ -207,12 +207,24 @@ void usartTestUsage() void newUartUsage() { - using config = uart::config<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>; - using uart0 = uart::hardware0; - using softuart = uart::software; + using namespace uart; + Uart0> serial; - uart::uart serial; - uart::uart softSerial; + serial << "Hello World from RAM. " << F("Hello World from flash\r\n"); + + _delay_ms(1000); +} + +void newUartUsage2() +{ + using namespace uart; + + using config = Config<9600, DataBits::EIGHT, Parity::NONE, StopBits::ONE>; + using uart0 = Hardware0; + using softuart = Software; + + Uart serial; + Uart softSerial; serial << "Hello World from RAM. " << F("Hello World from flash\r\n"); // softSerial << "Hello World using finalized software interface!" << F("\r\nAlso greetz from progmem\r\n"); @@ -249,7 +261,7 @@ enum class DataOrder { }; template -struct config { +struct Config { static constexpr auto CPOL_MODE = cpol; static constexpr auto CPHA_MODE = cpha; static constexpr auto DATA_ORDER = dataOrder; @@ -267,8 +279,8 @@ struct spi { namespace uart { -template -class hardware0 { +template +class Hardware0 { public: static void init() { @@ -291,17 +303,17 @@ class hardware0 { } 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; } diff --git a/uart/uart b/uart/uart index 8e0ba5a..00cb9ad 160000 --- a/uart/uart +++ b/uart/uart @@ -1 +1 @@ -Subproject commit 8e0ba5a46347beec2ba26e03e2956574577096bf +Subproject commit 00cb9ad13c9f66b3be99689e181cf650cffcd1e9