269 lines
5.6 KiB
C++
269 lines
5.6 KiB
C++
#pragma once
|
|
|
|
#include "config.hpp"
|
|
#include "hardware0.hpp"
|
|
#include "hardware1.hpp"
|
|
#include "software.hpp"
|
|
|
|
#include "../flash/flash.hpp"
|
|
|
|
namespace uart {
|
|
|
|
namespace detail {
|
|
|
|
template <typename...>
|
|
struct always_false {
|
|
static constexpr auto value = false;
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
template <class Driver>
|
|
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)
|
|
{
|
|
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)
|
|
{
|
|
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)
|
|
{
|
|
static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits");
|
|
|
|
const char *strIt = reinterpret_cast<const char *>(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;
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(char)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(unsigned char)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(short)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(unsigned short)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(int)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(unsigned int)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(long)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(unsigned long)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(long long)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(unsigned long long)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(float)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(double)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(long double)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(bool)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator<<(const void *)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// Input stream overloads
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(char &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(unsigned char &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(short &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(unsigned short &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(int &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(unsigned int &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(long &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(unsigned long &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(long long &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(unsigned long long &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(float &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(double &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(long double &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(bool &)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
|
|
template <typename... Ts>
|
|
uart &operator>>(const void *&)
|
|
{
|
|
static_assert(detail::always_false<Ts...>::value, "Not implemented");
|
|
}
|
|
};
|
|
|
|
} // namespace uart
|