2019-07-27 18:55:17 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace uart {
|
|
|
|
|
|
|
|
enum class DataBits {
|
|
|
|
FIVE,
|
|
|
|
SIX,
|
|
|
|
SEVEN,
|
|
|
|
EIGHT,
|
|
|
|
NINE,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class StopBits {
|
|
|
|
ONE,
|
|
|
|
TWO,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Parity {
|
|
|
|
NONE,
|
|
|
|
ODD,
|
|
|
|
EVEN,
|
|
|
|
};
|
|
|
|
|
2019-07-28 10:49:14 +02:00
|
|
|
namespace detail {
|
|
|
|
|
2019-07-28 14:00:46 +02:00
|
|
|
template <DataBits dataBits>
|
2019-07-28 10:54:47 +02:00
|
|
|
struct choose_data_type {
|
2019-07-28 10:49:14 +02:00
|
|
|
using type = uint8_t;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2019-07-28 10:54:47 +02:00
|
|
|
struct choose_data_type<DataBits::NINE> {
|
2019-07-28 10:49:14 +02:00
|
|
|
using type = uint16_t;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
2019-07-28 14:00:46 +02:00
|
|
|
template <uint32_t baudRate = 9600, DataBits dataBits = DataBits::EIGHT, Parity parity = Parity::NONE,
|
|
|
|
StopBits stopBits = StopBits::ONE>
|
2019-07-28 12:15:19 +02:00
|
|
|
struct config {
|
2019-07-27 18:55:17 +02:00
|
|
|
static constexpr auto BAUD_RATE = baudRate;
|
|
|
|
static constexpr auto DATA_BITS = dataBits;
|
|
|
|
static constexpr auto PARITY = parity;
|
|
|
|
static constexpr auto STOP_BITS = stopBits;
|
2019-07-28 10:54:47 +02:00
|
|
|
using data_t = typename detail::choose_data_type<DATA_BITS>::type;
|
2019-07-27 18:55:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace uart
|