Capitalized local constexpr variables to be more consistent
This commit is contained in:
parent
0e128bcb7d
commit
fa0a65a94c
40
hardware.hpp
40
hardware.hpp
@ -46,24 +46,24 @@ class Hardware {
|
|||||||
public:
|
public:
|
||||||
static void init() FORCE_INLINE
|
static void init() FORCE_INLINE
|
||||||
{
|
{
|
||||||
constexpr auto baudVal = calcBaud();
|
constexpr auto BaudVal = calcBaud();
|
||||||
|
|
||||||
*getRegPtr<Registers::BAUD_REG_H_ADDR>() = static_cast<uint8_t>(baudVal >> 8);
|
*getRegPtr<Registers::BAUD_REG_H_ADDR>() = static_cast<uint8_t>(BaudVal >> 8);
|
||||||
*getRegPtr<Registers::BAUD_REG_L_ADDR>() = static_cast<uint8_t>(baudVal);
|
*getRegPtr<Registers::BAUD_REG_L_ADDR>() = static_cast<uint8_t>(BaudVal);
|
||||||
|
|
||||||
constexpr auto dataBitsVal = calcDataBits();
|
constexpr auto DataBitsValues = calcDataBits();
|
||||||
constexpr auto parityVal = calcParity();
|
constexpr auto ParityVal = calcParity();
|
||||||
constexpr auto stopBitsVal = calcStopBits();
|
constexpr auto StopBitsVal = calcStopBits();
|
||||||
constexpr auto modeVal = calcMode();
|
constexpr auto ModeVal = calcMode();
|
||||||
constexpr auto enableRx = calcRxState<true>();
|
constexpr auto EnableRx = calcRxState<true>();
|
||||||
constexpr auto enableTx = calcTxState<true>();
|
constexpr auto EnableTx = calcTxState<true>();
|
||||||
constexpr auto interruptVal = calcInterrupt();
|
constexpr auto InterruptVal = calcInterrupt();
|
||||||
|
|
||||||
constexpr uint8_t controlRegB = dataBitsVal.regBVal | enableRx | enableTx | interruptVal;
|
constexpr uint8_t ControlRegB = DataBitsValues.regBVal | EnableRx | EnableTx | InterruptVal;
|
||||||
constexpr uint8_t controlRegC = dataBitsVal.regCVal | parityVal | stopBitsVal | modeVal;
|
constexpr uint8_t ControlRegC = DataBitsValues.regCVal | ParityVal | StopBitsVal | ModeVal;
|
||||||
|
|
||||||
*getRegPtr<Registers::CTRL_STAT_REG_B_ADDR>() = controlRegB;
|
*getRegPtr<Registers::CTRL_STAT_REG_B_ADDR>() = ControlRegB;
|
||||||
*getRegPtr<Registers::CTRL_STAT_REG_C_ADDR>() = controlRegC;
|
*getRegPtr<Registers::CTRL_STAT_REG_C_ADDR>() = ControlRegC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool rxByteBlocking(typename cfg::data_t &byte) FORCE_INLINE
|
static bool rxByteBlocking(typename cfg::data_t &byte) FORCE_INLINE
|
||||||
@ -137,8 +137,8 @@ class Hardware {
|
|||||||
static constexpr auto calcBaud()
|
static constexpr auto calcBaud()
|
||||||
{
|
{
|
||||||
// The actual formula is (F_CPU / (16 * baudRate)) - 1, but this one has the advantage of rounding correctly
|
// The actual formula is (F_CPU / (16 * baudRate)) - 1, but this one has the advantage of rounding correctly
|
||||||
constexpr auto baudVal = (F_CPU + 8 * cfg::BAUD_RATE) / (16 * cfg::BAUD_RATE) - 1;
|
constexpr auto BaudVal = (F_CPU + 8 * cfg::BAUD_RATE) / (16 * cfg::BAUD_RATE) - 1;
|
||||||
return baudVal;
|
return BaudVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr auto calcDataBits()
|
static constexpr auto calcDataBits()
|
||||||
@ -202,23 +202,23 @@ class Hardware {
|
|||||||
return modeVal;
|
return modeVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool enable>
|
template <bool Enable>
|
||||||
static constexpr auto calcRxState()
|
static constexpr auto calcRxState()
|
||||||
{
|
{
|
||||||
uint8_t enableVal = 0;
|
uint8_t enableVal = 0;
|
||||||
|
|
||||||
if (enable)
|
if (Enable)
|
||||||
enableVal = (1 << CtrlFlagsB::RX_ENABLE);
|
enableVal = (1 << CtrlFlagsB::RX_ENABLE);
|
||||||
|
|
||||||
return enableVal;
|
return enableVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool enable>
|
template <bool Enable>
|
||||||
static constexpr auto calcTxState()
|
static constexpr auto calcTxState()
|
||||||
{
|
{
|
||||||
uint8_t enableVal = 0;
|
uint8_t enableVal = 0;
|
||||||
|
|
||||||
if (enable)
|
if (Enable)
|
||||||
enableVal = (1 << CtrlFlagsB::TX_ENABLE);
|
enableVal = (1 << CtrlFlagsB::TX_ENABLE);
|
||||||
|
|
||||||
return enableVal;
|
return enableVal;
|
||||||
|
24
uart.hpp
24
uart.hpp
@ -36,13 +36,13 @@ static constexpr size_t cntDigits()
|
|||||||
template <typename T, size_t Base>
|
template <typename T, size_t Base>
|
||||||
static constexpr size_t maxNumDigits()
|
static constexpr size_t maxNumDigits()
|
||||||
{
|
{
|
||||||
constexpr T minVal = util::NumericLimits<T>::min();
|
constexpr T MinVal = util::NumericLimits<T>::min();
|
||||||
constexpr T maxVal = util::NumericLimits<T>::max();
|
constexpr T MaxVal = util::NumericLimits<T>::max();
|
||||||
|
|
||||||
constexpr T minDigits = cntDigits<T, MinVal, Base>();
|
constexpr T MinDigits = cntDigits<T, MinVal, Base>();
|
||||||
constexpr T maxDigits = cntDigits<T, MaxVal, Base>();
|
constexpr T MaxDigits = cntDigits<T, MaxVal, Base>();
|
||||||
|
|
||||||
return (minDigits < maxDigits) ? maxDigits : minDigits;
|
return (MinDigits < MaxDigits) ? MaxDigits : MinDigits;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
@ -120,8 +120,8 @@ class Uart {
|
|||||||
static_assert(Base <= 16, "Numbers with base higher than 16 are not supported");
|
static_assert(Base <= 16, "Numbers with base higher than 16 are not supported");
|
||||||
static_assert(Padding <= detail::maxNumDigits<T, Base>(), "Cannot pad more than maximum length of number");
|
static_assert(Padding <= detail::maxNumDigits<T, Base>(), "Cannot pad more than maximum length of number");
|
||||||
|
|
||||||
constexpr char alphaChar = (LowerCase) ? 'a' : 'A';
|
constexpr char AlphaChar = (LowerCase) ? 'a' : 'A';
|
||||||
constexpr size_t numDigits = detail::maxNumDigits<T, Base>();
|
constexpr size_t NumDigits = detail::maxNumDigits<T, Base>();
|
||||||
|
|
||||||
T digits = val;
|
T digits = val;
|
||||||
|
|
||||||
@ -130,17 +130,17 @@ class Uart {
|
|||||||
txByte('-');
|
txByte('-');
|
||||||
}
|
}
|
||||||
|
|
||||||
data_t buffer[numDigits];
|
data_t buffer[NumDigits];
|
||||||
data_t *bufEnd = buffer + numDigits - 1;
|
data_t *bufEnd = buffer + NumDigits - 1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
const data_t lastDigit = digits % Base;
|
const data_t lastDigit = digits % Base;
|
||||||
*bufEnd-- = (lastDigit < 10) ? ('0' + lastDigit) : (alphaChar + lastDigit - 10);
|
*bufEnd-- = (lastDigit < 10) ? ('0' + lastDigit) : (AlphaChar + lastDigit - 10);
|
||||||
digits /= Base;
|
digits /= Base;
|
||||||
} while (digits > 0);
|
} while (digits > 0);
|
||||||
|
|
||||||
if (Padding > 0) {
|
if (Padding > 0) {
|
||||||
size_t strLen = buffer + numDigits - (bufEnd + 1);
|
size_t strLen = buffer + NumDigits - (bufEnd + 1);
|
||||||
|
|
||||||
if (Padding > strLen) {
|
if (Padding > strLen) {
|
||||||
for (size_t i = Padding; i > strLen && bufEnd >= buffer; --i) {
|
for (size_t i = Padding; i > strLen && bufEnd >= buffer; --i) {
|
||||||
@ -149,7 +149,7 @@ class Uart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (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