Added basic layout for new library implementation

This commit is contained in:
BlackMark 2019-07-27 18:55:17 +02:00
parent e07ba7ecd8
commit f9c34b09ba
5 changed files with 304 additions and 0 deletions

30
hardware0.hpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
#include "settings.hpp"
namespace uart {
namespace detail {
template <class settings, const Mode mode>
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<void>(byte);
}
static data_t rxByte() {}
static data_t peek() {}
};
} // namespace detail
} // namespace uart

1
hardware1.hpp Normal file
View File

@ -0,0 +1 @@
#pragma once

43
settings.hpp Normal file
View File

@ -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 <const uint32_t baudRate = 9600, const DataBits dataBits = DataBits::EIGHT, const Parity parity = Parity::NONE,
const StopBits stopBits = StopBits::ONE>
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

1
software.hpp Normal file
View File

@ -0,0 +1 @@
#pragma once

229
uart.hpp Normal file
View 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