uart/config.hpp

51 lines
849 B
C++
Raw Normal View History

#pragma once
2022-05-29 16:15:11 +02:00
#include <cstdint>
2019-08-02 20:23:54 +02:00
namespace uart {
enum class DataBits {
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
};
enum class StopBits {
ONE,
TWO,
};
enum class Parity {
NONE,
ODD,
EVEN,
};
namespace detail {
template <DataBits dataBits>
2019-07-28 10:54:47 +02:00
struct choose_data_type {
2022-05-29 16:15:11 +02:00
using type = std::uint8_t;
};
template <>
2019-07-28 10:54:47 +02:00
struct choose_data_type<DataBits::NINE> {
2022-05-29 16:15:11 +02:00
using type = std::uint16_t;
};
} // namespace detail
2022-05-29 16:15:11 +02:00
template <std::uint32_t baudRate = 9600, DataBits dataBits = DataBits::EIGHT, Parity parity = Parity::NONE,
StopBits stopBits = StopBits::ONE>
struct Config {
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;
};
} // namespace uart