Renamed settings to config

This commit is contained in:
BlackMark 2019-07-28 12:15:19 +02:00
parent ae90fdae3f
commit 29b4d85ce3
4 changed files with 44 additions and 30 deletions

View File

@ -2,14 +2,6 @@
namespace uart { namespace uart {
enum class Mode {
ASYNCHRONOUS,
ASYNCHRONOUS_2X,
SYNCHRONOUS_MASTER,
SYNCHRONOUS_SLAVE,
SPI,
};
enum class DataBits { enum class DataBits {
FIVE, FIVE,
SIX, SIX,
@ -45,8 +37,7 @@ struct choose_data_type<DataBits::NINE> {
template <const uint32_t baudRate = 9600, const DataBits dataBits = DataBits::EIGHT, const Parity parity = Parity::NONE, template <const uint32_t baudRate = 9600, const DataBits dataBits = DataBits::EIGHT, const Parity parity = Parity::NONE,
const StopBits stopBits = StopBits::ONE> const StopBits stopBits = StopBits::ONE>
class settings { struct config {
public:
static constexpr auto BAUD_RATE = baudRate; static constexpr auto BAUD_RATE = baudRate;
static constexpr auto DATA_BITS = dataBits; static constexpr auto DATA_BITS = dataBits;
static constexpr auto PARITY = parity; static constexpr auto PARITY = parity;

View File

@ -1,18 +1,22 @@
#pragma once #pragma once
#include "settings.hpp" #include "config.hpp"
namespace uart { namespace uart {
namespace detail {
template <class settings, const Mode mode> enum class Mode {
ASYNCHRONOUS,
ASYNCHRONOUS_2X,
SYNCHRONOUS_MASTER,
SYNCHRONOUS_SLAVE,
SPI,
};
template <const Mode mode, class config>
class hardware0 { class hardware0 {
public: public:
using data_t = typename settings::data_t; using data_t = typename config::data_t;
static constexpr auto BAUD_RATE = settings::BAUD_RATE; static constexpr auto DATA_BITS = config::DATA_BITS;
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 init() {}
@ -24,7 +28,11 @@ class hardware0 {
static data_t rxByte() {} static data_t rxByte() {}
static data_t peek() {} static data_t peek() {}
private:
static constexpr auto BAUD_RATE = config::BAUD_RATE;
static constexpr auto PARITY = config::PARITY;
static constexpr auto STOP_BITS = config::STOP_BITS;
}; };
} // namespace detail
} // namespace uart } // namespace uart

View File

@ -1 +1,16 @@
#pragma once #pragma once
#include "../io/io.hpp"
namespace uart {
template <const io::P rxPin, const io::P txPin, class config>
class software {
public:
using data_t = typename config::data_t;
static constexpr auto DATA_BITS = config::DATA_BITS;
static void init() {}
};
} // namespace uart

View File

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "config.hpp"
#include "hardware0.hpp" #include "hardware0.hpp"
#include "hardware1.hpp" #include "hardware1.hpp"
#include "settings.hpp"
#include "software.hpp" #include "software.hpp"
#include "../flash/flash.hpp" #include "../flash/flash.hpp"
@ -18,13 +18,13 @@ struct always_false {
} // namespace detail } // namespace detail
template <class Impl> template <class Driver>
class uart { class uart {
public: public:
// Initialization is done upon construction // Initialization is done upon construction
uart() uart()
{ {
Impl::init(); Driver::init();
} }
// Moving and copying uart objects is not supported // Moving and copying uart objects is not supported
@ -33,24 +33,24 @@ class uart {
uart &operator=(const uart &) = delete; uart &operator=(const uart &) = delete;
uart &operator=(uart &&) = delete; uart &operator=(uart &&) = delete;
static void txByte(typename Impl::data_t byte) static void txByte(typename Driver::data_t byte)
{ {
Impl::txByte(byte); Driver::txByte(byte);
} }
static typename Impl::data_t rxByte() static typename Driver::data_t rxByte()
{ {
return Impl::rxByte(); return Driver::rxByte();
} }
static typename Impl::data_t peek() static typename Driver::data_t peek()
{ {
return Impl::peek(); return Driver::peek();
} }
static void txString(const char *str) static void txString(const char *str)
{ {
static_assert(Impl::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits");
while (char ch = *str++) while (char ch = *str++)
txByte(ch); txByte(ch);
@ -58,7 +58,7 @@ class uart {
static void txString(const ::detail::FlashString *str) static void txString(const ::detail::FlashString *str)
{ {
static_assert(Impl::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits"); static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits");
const char *strIt = reinterpret_cast<const char *>(str); const char *strIt = reinterpret_cast<const char *>(str);