#pragma once #include "config.hpp" #include "hardware0.hpp" #include "hardware1.hpp" #include "software.hpp" #include "../flash/flash.hpp" #define FORCE_INLINE __attribute__((always_inline)) namespace uart { namespace detail { template struct always_false { static constexpr auto value = false; }; } // namespace detail template class uart { public: // Initialization is done upon construction uart() { Driver::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 Driver::data_t byte) FORCE_INLINE { Driver::txByte(byte); } static typename Driver::data_t rxByte() { return Driver::rxByte(); } static typename Driver::data_t peek() { return Driver::peek(); } static void txString(const char *str) FORCE_INLINE { static_assert(Driver::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) FORCE_INLINE { static_assert(Driver::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) FORCE_INLINE { txString(str); return *this; } uart &operator<<(const ::detail::FlashString *str) FORCE_INLINE { txString(str); return *this; } template uart &operator<<(char) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(unsigned char) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(short) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(unsigned short) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(int) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(unsigned int) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(long) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(unsigned long) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(long long) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(unsigned long long) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(float) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(double) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(long double) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(bool) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator<<(const void *) { static_assert(detail::always_false::value, "Not implemented"); } ////////////////////////////////////////////////////////////////////////// // Input stream overloads template uart &operator>>(char &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(unsigned char &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(short &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(unsigned short &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(int &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(unsigned int &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(long &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(unsigned long &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(long long &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(unsigned long long &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(float &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(double &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(long double &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(bool &) { static_assert(detail::always_false::value, "Not implemented"); } template uart &operator>>(const void *&) { static_assert(detail::always_false::value, "Not implemented"); } }; } // namespace uart #undef FORCE_INLINE