From f9c34b09bad1c65d2dfaf5a9ae7e128b3719b321 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 27 Jul 2019 18:55:17 +0200 Subject: [PATCH] Added basic layout for new library implementation --- hardware0.hpp | 30 +++++++ hardware1.hpp | 1 + settings.hpp | 43 ++++++++++ software.hpp | 1 + uart.hpp | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 304 insertions(+) create mode 100644 hardware0.hpp create mode 100644 hardware1.hpp create mode 100644 settings.hpp create mode 100644 software.hpp create mode 100644 uart.hpp diff --git a/hardware0.hpp b/hardware0.hpp new file mode 100644 index 0000000..30f6b07 --- /dev/null +++ b/hardware0.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include "settings.hpp" + +namespace uart { +namespace detail { + +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; + + static void init() {} + + static void txByte(data_t byte) + { + static_cast(byte); + } + + static data_t rxByte() {} + + static data_t peek() {} +}; + +} // namespace detail +} // namespace uart diff --git a/hardware1.hpp b/hardware1.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/hardware1.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/settings.hpp b/settings.hpp new file mode 100644 index 0000000..d646e57 --- /dev/null +++ b/settings.hpp @@ -0,0 +1,43 @@ +#pragma once + +namespace uart { + +enum class Mode { + ASYNCHRONOUS, + ASYNCHRONOUS_2X, + SYNCHRONOUS_MASTER, + SYNCHRONOUS_SLAVE, + SPI, +}; + +enum class DataBits { + FIVE, + SIX, + SEVEN, + EIGHT, + NINE, +}; + +enum class StopBits { + ONE, + TWO, +}; + +enum class Parity { + NONE, + ODD, + EVEN, +}; + +template +class settings { + public: + static constexpr auto BAUD_RATE = baudRate; + static constexpr auto DATA_BITS = dataBits; + static constexpr auto PARITY = parity; + static constexpr auto STOP_BITS = stopBits; + using data_t = uint8_t; +}; + +} // namespace uart diff --git a/software.hpp b/software.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/software.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/uart.hpp b/uart.hpp new file mode 100644 index 0000000..6107f5d --- /dev/null +++ b/uart.hpp @@ -0,0 +1,229 @@ +#pragma once + +#include "hardware0.hpp" +#include "hardware1.hpp" +#include "settings.hpp" +#include "software.hpp" + +#include "../flash/flash.hpp" + +namespace uart { + +template +class uart { + public: + // Initialization is done upon construction + uart() + { + Impl::init(); + } + + // Moving and copying uart objects is not supported + uart(const uart &) = delete; + uart(uart &&) = delete; + uart &operator=(const uart &) = delete; + uart &operator=(uart &&) = delete; + + static void txByte(typename Impl::data_t byte) + { + Impl::txByte(byte); + } + + static typename Impl::data_t rxByte() + { + return Impl::rxByte(); + } + + static typename Impl::data_t peek() + { + return Impl::peek(); + } + + static void txString(const char *str) + { + static_assert(Impl::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); + + while (char ch = *str++) + txByte(ch); + } + + static void txString(const ::detail::FlashString *str) + { + static_assert(Impl::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); + + const char *strIt = reinterpret_cast(str); + + while (char ch = pgm_read_byte(strIt++)) + txByte(ch); + } + + ////////////////////////////////////////////////////////////////////////// + // Output stream overloads + + uart &operator<<(const char *str) + { + txString(str); + return *this; + } + + uart &operator<<(const ::detail::FlashString *str) + { + txString(str); + return *this; + } + + uart &operator<<(char) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(unsigned char) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(short) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(unsigned short) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(int) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(unsigned int) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(long) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(unsigned long) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(long long) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(unsigned long long) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(float) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(double) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(long double) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(bool) + { + static_assert(true, "Not implemented"); + } + + uart &operator<<(const void *) + { + static_assert(true, "Not implemented"); + } + + ////////////////////////////////////////////////////////////////////////// + // Input stream overloads + + uart &operator>>(char &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(unsigned char &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(short &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(unsigned short &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(int &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(unsigned int &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(long &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(unsigned long &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(long long &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(unsigned long long &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(float &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(double &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(long double &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(bool &) + { + static_assert(true, "Not implemented"); + } + + uart &operator>>(const void *&) + { + static_assert(true, "Not implemented"); + } +}; + +} // namespace uart