Added alias for driver dependent data size
This commit is contained in:
parent
2a07744575
commit
9f7dc0da55
16
uart.hpp
16
uart.hpp
@ -49,6 +49,8 @@ static constexpr size_t maxNumDigits()
|
|||||||
template <class Driver>
|
template <class Driver>
|
||||||
class Uart {
|
class Uart {
|
||||||
public:
|
public:
|
||||||
|
using data_t = typename Driver::data_t;
|
||||||
|
|
||||||
// Constructing a uart object does not initialize the driver to allow different specializations with the same
|
// Constructing a uart object does not initialize the driver to allow different specializations with the same
|
||||||
// back-end to exists at the same time
|
// back-end to exists at the same time
|
||||||
// Note that init must be called every time when switching specializations with the same back-end
|
// Note that init must be called every time when switching specializations with the same back-end
|
||||||
@ -66,17 +68,17 @@ class Uart {
|
|||||||
Driver::init();
|
Driver::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void txByte(const typename Driver::data_t &byte)
|
static void txByte(const data_t &byte)
|
||||||
{
|
{
|
||||||
Driver::txByte(byte);
|
Driver::txByte(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rxByte(typename Driver::data_t &byte)
|
static bool rxByte(data_t &byte)
|
||||||
{
|
{
|
||||||
return Driver::rxByte(byte);
|
return Driver::rxByte(byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool peek(typename Driver::data_t &byte)
|
static bool peek(data_t &byte)
|
||||||
{
|
{
|
||||||
return Driver::peek(byte);
|
return Driver::peek(byte);
|
||||||
}
|
}
|
||||||
@ -110,8 +112,8 @@ class Uart {
|
|||||||
static_assert(util::is_integral_v<T>, "Only supported on integral types");
|
static_assert(util::is_integral_v<T>, "Only supported on integral types");
|
||||||
|
|
||||||
constexpr size_t numDigits = detail::maxNumDigits<T, Base>();
|
constexpr size_t numDigits = detail::maxNumDigits<T, Base>();
|
||||||
typename Driver::data_t buffer[numDigits];
|
data_t buffer[numDigits];
|
||||||
typename Driver::data_t *bufEnd = buffer + numDigits - 1;
|
data_t *bufEnd = buffer + numDigits - 1;
|
||||||
|
|
||||||
T digits = val;
|
T digits = val;
|
||||||
|
|
||||||
@ -121,12 +123,12 @@ class Uart {
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
typename Driver::data_t lastDigit = digits % Base;
|
data_t lastDigit = digits % Base;
|
||||||
*bufEnd-- = '0' + lastDigit;
|
*bufEnd-- = '0' + lastDigit;
|
||||||
digits /= Base;
|
digits /= Base;
|
||||||
} while (digits > 0);
|
} while (digits > 0);
|
||||||
|
|
||||||
for (typename Driver::data_t *buf = bufEnd + 1; buf < buffer + numDigits; ++buf)
|
for (data_t *buf = bufEnd + 1; buf < buffer + numDigits; ++buf)
|
||||||
txByte(*buf);
|
txByte(*buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user