diff --git a/src/main/common/utils.h b/src/main/common/utils.h index 1c773034b5..5764c5a85a 100644 --- a/src/main/common/utils.h +++ b/src/main/common/utils.h @@ -100,6 +100,8 @@ http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html static inline int16_t cmp16(uint16_t a, uint16_t b) { return (int16_t)(a-b); } static inline int32_t cmp32(uint32_t a, uint32_t b) { return (int32_t)(a-b); } +static inline uint32_t llog2(uint32_t n) { return 31 - __builtin_clz(n | 1); } + // using memcpy_fn will force memcpy function call, instead of inlining it. In most cases function call takes fewer instructions // than inlined version (inlining is cheaper for very small moves < 8 bytes / 2 store instructions) #if defined(UNIT_TEST) || defined(SIMULATOR_BUILD) diff --git a/src/main/drivers/accgyro/accgyro_spi_icm426xx.c b/src/main/drivers/accgyro/accgyro_spi_icm426xx.c index 4da8b8dcee..54d3f8e478 100644 --- a/src/main/drivers/accgyro/accgyro_spi_icm426xx.c +++ b/src/main/drivers/accgyro/accgyro_spi_icm426xx.c @@ -31,7 +31,7 @@ #if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P) #include "common/axis.h" -#include "common/maths.h" +#include "common/utils.h" #include "build/debug.h" #include "drivers/accgyro/accgyro.h" @@ -208,7 +208,7 @@ void icm426xxGyroInit(gyroDev_t *gyro) // Get desired output data rate uint8_t odrConfig; - const uint8_t decim = LOG2_8BIT(gyro->mpuDividerDrops + 1); + const unsigned decim = llog2(gyro->mpuDividerDrops + 1); if (gyro->gyroRateKHz && decim < ODR_CONFIG_COUNT) { odrConfig = odrLUT[decim]; } else {