Implemented automatic type deducation depending on data bits

This commit is contained in:
BlackMark 2019-07-28 10:49:14 +02:00
parent f08f607265
commit 2364bff11f

View File

@ -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