Implemented automatic type deducation depending on data bits
This commit is contained in:
parent
f08f607265
commit
2364bff11f
16
settings.hpp
16
settings.hpp
@ -29,6 +29,20 @@ enum class Parity {
|
|||||||
EVEN,
|
EVEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template <const DataBits dataBits>
|
||||||
|
struct choose_data_size {
|
||||||
|
using type = uint8_t;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct choose_data_size<DataBits::NINE> {
|
||||||
|
using type = uint16_t;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
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 {
|
class settings {
|
||||||
@ -37,7 +51,7 @@ class settings {
|
|||||||
static constexpr auto DATA_BITS = dataBits;
|
static constexpr auto DATA_BITS = dataBits;
|
||||||
static constexpr auto PARITY = parity;
|
static constexpr auto PARITY = parity;
|
||||||
static constexpr auto STOP_BITS = stopBits;
|
static constexpr auto STOP_BITS = stopBits;
|
||||||
using data_t = uint8_t;
|
using data_t = typename detail::choose_data_size<DATA_BITS>::type;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace uart
|
} // namespace uart
|
||||||
|
Loading…
Reference in New Issue
Block a user