Added basic layout for new library implementation
This commit is contained in:
229
uart.hpp
Normal file
229
uart.hpp
Normal file
@@ -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 Impl>
|
||||
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<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;
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user