diff --git a/settings.hpp b/config.hpp similarity index 86% rename from settings.hpp rename to config.hpp index 33878f4..e7f2179 100644 --- a/settings.hpp +++ b/config.hpp @@ -2,14 +2,6 @@ namespace uart { -enum class Mode { - ASYNCHRONOUS, - ASYNCHRONOUS_2X, - SYNCHRONOUS_MASTER, - SYNCHRONOUS_SLAVE, - SPI, -}; - enum class DataBits { FIVE, SIX, @@ -45,8 +37,7 @@ struct choose_data_type { template -class settings { - public: +struct config { static constexpr auto BAUD_RATE = baudRate; static constexpr auto DATA_BITS = dataBits; static constexpr auto PARITY = parity; diff --git a/hardware0.hpp b/hardware0.hpp index 30f6b07..84ed2b3 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -1,18 +1,22 @@ #pragma once -#include "settings.hpp" +#include "config.hpp" namespace uart { -namespace detail { -template +enum class Mode { + ASYNCHRONOUS, + ASYNCHRONOUS_2X, + SYNCHRONOUS_MASTER, + SYNCHRONOUS_SLAVE, + SPI, +}; + +template class hardware0 { public: - using data_t = typename settings::data_t; - static constexpr auto BAUD_RATE = settings::BAUD_RATE; - static constexpr auto DATA_BITS = settings::DATA_BITS; - static constexpr auto PARITY = settings::PARITY; - static constexpr auto STOP_BITS = settings::STOP_BITS; + using data_t = typename config::data_t; + static constexpr auto DATA_BITS = config::DATA_BITS; static void init() {} @@ -24,7 +28,11 @@ class hardware0 { static data_t rxByte() {} static data_t peek() {} + + private: + static constexpr auto BAUD_RATE = config::BAUD_RATE; + static constexpr auto PARITY = config::PARITY; + static constexpr auto STOP_BITS = config::STOP_BITS; }; -} // namespace detail } // namespace uart diff --git a/software.hpp b/software.hpp index 6f70f09..adef1d5 100644 --- a/software.hpp +++ b/software.hpp @@ -1 +1,16 @@ #pragma once + +#include "../io/io.hpp" + +namespace uart { + +template +class software { + public: + using data_t = typename config::data_t; + static constexpr auto DATA_BITS = config::DATA_BITS; + + static void init() {} +}; + +} // namespace uart diff --git a/uart.hpp b/uart.hpp index 4cdf059..5bc37dc 100644 --- a/uart.hpp +++ b/uart.hpp @@ -1,8 +1,8 @@ #pragma once +#include "config.hpp" #include "hardware0.hpp" #include "hardware1.hpp" -#include "settings.hpp" #include "software.hpp" #include "../flash/flash.hpp" @@ -18,13 +18,13 @@ struct always_false { } // namespace detail -template +template class uart { public: // Initialization is done upon construction uart() { - Impl::init(); + Driver::init(); } // Moving and copying uart objects is not supported @@ -33,24 +33,24 @@ class uart { uart &operator=(const uart &) = delete; uart &operator=(uart &&) = delete; - static void txByte(typename Impl::data_t byte) + static void txByte(typename Driver::data_t byte) { - Impl::txByte(byte); + Driver::txByte(byte); } - static typename Impl::data_t rxByte() + static typename Driver::data_t rxByte() { - return Impl::rxByte(); + return Driver::rxByte(); } - static typename Impl::data_t peek() + static typename Driver::data_t peek() { - return Impl::peek(); + return Driver::peek(); } static void txString(const char *str) { - static_assert(Impl::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); + static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); while (char ch = *str++) txByte(ch); @@ -58,7 +58,7 @@ class uart { static void txString(const ::detail::FlashString *str) { - static_assert(Impl::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); + static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); const char *strIt = reinterpret_cast(str);