diff --git a/uart/main.cpp b/uart/main.cpp index 09cd3df..0608edb 100644 --- a/uart/main.cpp +++ b/uart/main.cpp @@ -207,12 +207,15 @@ void usartTestUsage() void newUartUsage() { - using settings = uart::settings<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>; - using uart0 = uart::detail::hardware0; + using config = uart::config<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>; + using uart0 = uart::hardware0; + using softuart = uart::software; uart::uart serial; + uart::uart softSerial; serial << "Hello World using finalized interface!" << F("\r\nAlso works from progmem\r\n"); + // softSerial << "Hello World using finalized software interface!" << F("\r\nAlso greetz from progmem\r\n"); } void oldUsartUsage() @@ -226,11 +229,88 @@ void oldUsartUsage() _delay_ms(1000); } +namespace spi { + +enum class Cpol { + MODE_0, + MODE_1, +}; + +enum class Cpha { + MODE_0, + MODE_1, +}; + +enum class DataOrder { + MSB, + LSB, +}; + +template +struct config { + static constexpr auto CPOL_MODE = cpol; + static constexpr auto CPHA_MODE = cpha; + static constexpr auto DATA_ORDER = dataOrder; +}; + +template +struct spi { + spi() + { + Driver::init(); + } +}; + +} // namespace spi + +namespace uart { + +template +class hardware0 { + public: + static void init() + { + UCSR0C |= (1 << UMSEL01) | (1 << UMSEL00); + + 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 (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; +}; + +} // namespace uart + +void spiTest() +{ + using config = spi::config; + using uartspi = uart::hardware0; + + spi::spi uartSpi; +} + int main() { usartTestUsage(); newUartUsage(); oldUsartUsage(); + spiTest(); + return 0; } diff --git a/uart/uart b/uart/uart index f08f607..29b4d85 160000 --- a/uart/uart +++ b/uart/uart @@ -1 +1 @@ -Subproject commit f08f607265cd316714d0db6fde5807e1c6320a72 +Subproject commit 29b4d85ce3e2a5467dc378f029b94fa35cb6c793 diff --git a/uart/uart.cppproj b/uart/uart.cppproj index b61b2d5..31aafa1 100644 --- a/uart/uart.cppproj +++ b/uart/uart.cppproj @@ -61,15 +61,15 @@ - - - - - - - - - + + + + + + + + + @@ -211,7 +211,7 @@ compile - + compile