mirror of https://github.com/ArduPilot/ardupilot
AP_Common: added missing bit set/clear functions
This commit is contained in:
parent
9efc4602af
commit
6a0531c08a
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <type_traits>
|
||||
|
||||
// used to pack structures
|
||||
#define PACKED __attribute__((__packed__))
|
||||
|
@ -143,3 +144,17 @@ bool hex_to_uint8(uint8_t a, uint8_t &res); // return the uint8 value of an asc
|
|||
strncpy without the warning for not leaving room for nul termination
|
||||
*/
|
||||
void strncpy_noterm(char *dest, const char *src, size_t n);
|
||||
|
||||
/*
|
||||
Bit manipulation
|
||||
*/
|
||||
//#define BIT_SET(value, bitnumber) ((value) |= (((typeof(value))1U) << (bitnumber)))
|
||||
template <typename T> void BIT_SET (T& value, uint8_t bitnumber) noexcept {
|
||||
static_assert(std::is_integral<T>::value, "Integral required.");
|
||||
((value) |= ((T)(1U) << (bitnumber)));
|
||||
}
|
||||
//#define BIT_CLEAR(value, bitnumber) ((value) &= ~(((typeof(value))1U) << (bitnumber)))
|
||||
template <typename T> void BIT_CLEAR (T& value, uint8_t bitnumber) noexcept {
|
||||
static_assert(std::is_integral<T>::value, "Integral required.");
|
||||
((value) &= ~((T)(1U) << (bitnumber)));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue