54 inline void bitSet(T &value, uint8_t bit)
79 inline void bitFlip(T &value, uint8_t bit)
92 inline bool bitRead(T &value, uint8_t bit)
94 return (value >> bit) & 0x01;
105 template <
typename T>
106 inline void bitWrite(T &value, uint8_t bit,
bool bitValue)
118 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
119 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
120 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
132 x = ((x >> 4) & 0x0F) | ((x << 4) & 0xF0);
162 inline uint16_t
word(uint8_t highByte, uint8_t lowByte)
164 return highByte << 8 | lowByte;
177 return __builtin_parity(x);
190 return a < b ? a : b;
203 return a > b ? a : b;
void bitWrite(T &value, uint8_t bit, bool bitValue)
Writes the bit in the given value.
Definition: utils.h:106
void bitFlip(T &value, uint8_t bit)
Flips the bit in the given value.
Definition: utils.h:79
bool parity(int x)
Returns the even parity for the byte x.
Definition: utils.h:175
uint8_t lowNibble(uint8_t x)
Returns the byte's x low nibble.
Definition: utils.h:151
Namespace containing all symbols of the Sensors library.
Definition: bitdecoder.h:40
uint8_t byteReverse(uint8_t x)
Returns the byte x in reversed bit order.
Definition: utils.h:116
T min(T a, T b)
Returns the minimum of the two values a and b.
Definition: utils.h:188
T max(T a, T b)
Returns the maximum of the two values a and b.
Definition: utils.h:201
uint8_t nibbleReverse(uint8_t x)
Returns the byte x in reversed bit order (nibble wise).
Definition: utils.h:129
bool bitRead(T &value, uint8_t bit)
Returns the bit in the given value.
Definition: utils.h:92
void bitSet(T &value, uint8_t bit)
Sets the bit in the given value to 1.
Definition: utils.h:54
uint8_t highNibble(uint8_t x)
Returns the byte's x high nibble.
Definition: utils.h:141
uint16_t word(uint8_t highByte, uint8_t lowByte)
Converts two bytes to a word.
Definition: utils.h:162
void bitClear(T &value, uint8_t bit)
Sets the bit in the given value to 0.
Definition: utils.h:67