diff --git a/radio/src/bitfield.h b/radio/src/bitfield.h index 84b3632b5..379d4280f 100644 --- a/radio/src/bitfield.h +++ b/radio/src/bitfield.h @@ -23,8 +23,16 @@ #ifndef BITFIELD_H #define BITFIELD_H +#include + // A set of bitfield handling macros -#define BF_BIT(n) ( 1<<(n) ) + +template +inline T BF_BIT(uint8_t n) +{ + return T(1) << n; +} + #define BF_BIT_GET(y, mask) ( y & (mask) ) #define BF_BIT_SET(y, mask) ( y |= (mask) ) #define BF_BIT_CLEAR(y, mask) ( y &= ~(mask) ) @@ -33,19 +41,34 @@ #define BF_SINGLE_BIT_SET(y, i) BF_BIT_SET(y, BF_BIT(i)) //! Create a bitmask of length 'len'. -#define BF_BITMASK(len) ( BF_BIT(len)-1 ) +template +inline T BF_BITMASK(uint8_t len) +{ + return BF_BIT(len) - 1; +} //! Create a bitfield mask of length 'len' starting at bit 'start'. -#define BF_MASK(start, len) ( BF_BITMASK(len)<<(start) ) +template +inline T BF_MASK(uint8_t start, uint8_t len) +{ + return BF_BITMASK(len) << start; +} //! Prepare a bitmask for insertion or combining. -#define BF_PREP(x, start, len) ( ((x)&BF_BITMASK(len)) << (start) ) +template +inline T BF_PREP(T x, uint8_t start, uint8_t len) +{ + return (x & BF_BITMASK(len)) << start; +} //! Extract a bitfield of length 'len' starting at bit 'start' from 'y'. #define BF_GET(y, start, len) ( ((y)>>(start)) & BF_BITMASK(len) ) //! Insert 'len' bits of 'x 'into 'y', starting at bit 'start' from 'y'. -#define BF_SET(y, x, start, len) \ - ( y= ((y) &~ BF_MASK(start, len)) | BF_PREP(x, start, len) ) +template +inline T BF_SET(T to, T from, uint8_t start, uint8_t len) +{ + return (to & ~BF_MASK(start, len)) | BF_PREP(from, start, len); +} -#endif //BITFIELD_H \ No newline at end of file +#endif //BITFIELD_H diff --git a/radio/src/gui/128x64/model_setup.cpp b/radio/src/gui/128x64/model_setup.cpp index 5a59cde20..5bfbb5ef0 100644 --- a/radio/src/gui/128x64/model_setup.cpp +++ b/radio/src/gui/128x64/model_setup.cpp @@ -1755,19 +1755,16 @@ void menuModelPinmap(event_t event) const coord_t x = 1; coord_t y = FH + 1; - uint8_t line = (menuVerticalPosition >= sentModuleChannels(g_moduleIdx) ? 2 : 0); - uint8_t pin = (menuVerticalPosition >= 8 ? 8 : 0) + line; + uint8_t pin = (menuVerticalPosition >= 8 ? 8 : 0); - for (; line < 8; line++) { + for (uint8_t line = 0; line < 8; line++) { const int32_t channelValue = channelOutputs[getPinOuput(g_receiverIdx, g_moduleIdx, pin)]; - //Pin + // Pin lcdDrawText(0, y, "Pin", SMLSIZE); - lcdDrawNumber(lcdLastRightPos+5, y, pin+1, SMLSIZE); - lcdDrawText(lcdLastRightPos+5, y, " -> ", SMLSIZE); + lcdDrawNumber(lcdLastRightPos + 1, y, pin+1, SMLSIZE); - - //Channel + // Channel LcdFlags flags = SMLSIZE; if (menuVerticalPosition == pin) { flags |= INVERS; @@ -1778,18 +1775,16 @@ void menuModelPinmap(event_t event) setPinOuput(g_receiverIdx, g_moduleIdx, pin, channel); } } + putsChn(8*FW, y, getPinOuput(g_receiverIdx, g_moduleIdx, pin)+1, flags); - //lcdDrawNumber(lcdLastRightPos+5, y, getPinOuput(g_receiverIdx, g_moduleIdx, pin)+1, flags); - putsChn(lcdLastRightPos+5, y, getPinOuput(g_receiverIdx, g_moduleIdx, pin)+1, flags); - + // Bargraph const uint8_t lenChannel = limit(1, (abs(channelValue) * wbar/2 + lim/2) / lim, wbar/2); const coord_t xChannel = (channelValue>0) ? x+LCD_W-3-wbar/2 : x+LCD_W-2-wbar/2-lenChannel; lcdDrawHorizontalLine(xChannel, y+1, lenChannel, DOTTED, 0); lcdDrawHorizontalLine(xChannel, y+2, lenChannel, DOTTED, 0); y += FH-1; - - if (++pin >sentModuleChannels(g_moduleIdx)) + if (++pin > sentModuleChannels(g_moduleIdx)) break; } } \ No newline at end of file diff --git a/radio/src/pulses/modules.h b/radio/src/pulses/modules.h index d516578c5..8cb6e09fd 100644 --- a/radio/src/pulses/modules.h +++ b/radio/src/pulses/modules.h @@ -208,7 +208,7 @@ inline uint8_t getPinOuput(uint8_t receiverIdx, uint8_t moduleIdx, uint8_t pin) inline void setPinOuput(uint8_t receiverIdx, uint8_t moduleIdx, uint8_t pin, uint8_t chan) { - BF_SET(g_model.moduleData[moduleIdx].pxx2.receivers[receiverIdx].channelMapping, chan, (pin + ((pin & 0x01) ? -1 : 1 )) * 4, 4); + g_model.moduleData[moduleIdx].pxx2.receivers[receiverIdx].channelMapping = BF_SET(g_model.moduleData[moduleIdx].pxx2.receivers[receiverIdx].channelMapping, chan, (pin + ((pin & 0x01) ? -1 : 1 )) * 4, 4); } inline int8_t maxModuleChannels_M8(uint8_t idx)