This commit is contained in:
Bertrand Songis
2019-02-11 14:51:52 +01:00
parent bf3bba3254
commit 4a6fc430ec
3 changed files with 39 additions and 21 deletions
+29 -6
View File
@@ -23,8 +23,16 @@
#ifndef BITFIELD_H #ifndef BITFIELD_H
#define BITFIELD_H #define BITFIELD_H
#include <inttypes.h>
// A set of bitfield handling macros // A set of bitfield handling macros
#define BF_BIT(n) ( 1<<(n) )
template <typename T>
inline T BF_BIT(uint8_t n)
{
return T(1) << n;
}
#define BF_BIT_GET(y, mask) ( y & (mask) ) #define BF_BIT_GET(y, mask) ( y & (mask) )
#define BF_BIT_SET(y, mask) ( y |= (mask) ) #define BF_BIT_SET(y, mask) ( y |= (mask) )
#define BF_BIT_CLEAR(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)) #define BF_SINGLE_BIT_SET(y, i) BF_BIT_SET(y, BF_BIT(i))
//! Create a bitmask of length 'len'. //! Create a bitmask of length 'len'.
#define BF_BITMASK(len) ( BF_BIT(len)-1 ) template <typename T>
inline T BF_BITMASK(uint8_t len)
{
return BF_BIT<T>(len) - 1;
}
//! Create a bitfield mask of length 'len' starting at bit 'start'. //! Create a bitfield mask of length 'len' starting at bit 'start'.
#define BF_MASK(start, len) ( BF_BITMASK(len)<<(start) ) template <typename T>
inline T BF_MASK(uint8_t start, uint8_t len)
{
return BF_BITMASK<T>(len) << start;
}
//! Prepare a bitmask for insertion or combining. //! Prepare a bitmask for insertion or combining.
#define BF_PREP(x, start, len) ( ((x)&BF_BITMASK(len)) << (start) ) template <typename T>
inline T BF_PREP(T x, uint8_t start, uint8_t len)
{
return (x & BF_BITMASK<T>(len)) << start;
}
//! Extract a bitfield of length 'len' starting at bit 'start' from 'y'. //! Extract a bitfield of length 'len' starting at bit 'start' from 'y'.
#define BF_GET(y, start, len) ( ((y)>>(start)) & BF_BITMASK(len) ) #define BF_GET(y, start, len) ( ((y)>>(start)) & BF_BITMASK(len) )
//! Insert 'len' bits of 'x 'into 'y', starting at bit 'start' from 'y'. //! Insert 'len' bits of 'x 'into 'y', starting at bit 'start' from 'y'.
#define BF_SET(y, x, start, len) \ template <class T>
( y= ((y) &~ BF_MASK(start, len)) | BF_PREP(x, start, len) ) inline T BF_SET(T to, T from, uint8_t start, uint8_t len)
{
return (to & ~BF_MASK<T>(start, len)) | BF_PREP<T>(from, start, len);
}
#endif //BITFIELD_H #endif //BITFIELD_H
+8 -13
View File
@@ -1755,19 +1755,16 @@ void menuModelPinmap(event_t event)
const coord_t x = 1; const coord_t x = 1;
coord_t y = FH + 1; coord_t y = FH + 1;
uint8_t line = (menuVerticalPosition >= sentModuleChannels(g_moduleIdx) ? 2 : 0); uint8_t pin = (menuVerticalPosition >= 8 ? 8 : 0);
uint8_t pin = (menuVerticalPosition >= 8 ? 8 : 0) + line;
for (; line < 8; line++) { for (uint8_t line = 0; line < 8; line++) {
const int32_t channelValue = channelOutputs[getPinOuput(g_receiverIdx, g_moduleIdx, pin)]; const int32_t channelValue = channelOutputs[getPinOuput(g_receiverIdx, g_moduleIdx, pin)];
//Pin // Pin
lcdDrawText(0, y, "Pin", SMLSIZE); lcdDrawText(0, y, "Pin", SMLSIZE);
lcdDrawNumber(lcdLastRightPos+5, y, pin+1, SMLSIZE); lcdDrawNumber(lcdLastRightPos + 1, y, pin+1, SMLSIZE);
lcdDrawText(lcdLastRightPos+5, y, " -> ", SMLSIZE);
// Channel
//Channel
LcdFlags flags = SMLSIZE; LcdFlags flags = SMLSIZE;
if (menuVerticalPosition == pin) { if (menuVerticalPosition == pin) {
flags |= INVERS; flags |= INVERS;
@@ -1778,18 +1775,16 @@ void menuModelPinmap(event_t event)
setPinOuput(g_receiverIdx, g_moduleIdx, pin, channel); 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); // Bargraph
putsChn(lcdLastRightPos+5, y, getPinOuput(g_receiverIdx, g_moduleIdx, pin)+1, flags);
const uint8_t lenChannel = limit<uint8_t>(1, (abs(channelValue) * wbar/2 + lim/2) / lim, wbar/2); const uint8_t lenChannel = limit<uint8_t>(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; 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+1, lenChannel, DOTTED, 0);
lcdDrawHorizontalLine(xChannel, y+2, lenChannel, DOTTED, 0); lcdDrawHorizontalLine(xChannel, y+2, lenChannel, DOTTED, 0);
y += FH-1; y += FH-1;
if (++pin > sentModuleChannels(g_moduleIdx))
if (++pin >sentModuleChannels(g_moduleIdx))
break; break;
} }
} }
+1 -1
View File
@@ -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) 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<uint64_t>(g_model.moduleData[moduleIdx].pxx2.receivers[receiverIdx].channelMapping, chan, (pin + ((pin & 0x01) ? -1 : 1 )) * 4, 4);
} }
inline int8_t maxModuleChannels_M8(uint8_t idx) inline int8_t maxModuleChannels_M8(uint8_t idx)