From 13fcc5ad84af6a2421e9ee9207b0adcb500e6f37 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Thu, 30 Mar 2017 15:14:23 -0700 Subject: driver: lsm6dsm/lsm6dsl: Fix LSM6DSM_ODR_TO_NORMALIZE macro Using builtin function in macro. Compact macros. BUG=none BRANCH=master TEST=Tested on discovery BOARD with LSM6DSM sensor connected to I2C master interface of target board. Using accelrate motion sense console command is possible to test with different data rate: all supported ODR has been tested for acc and gyro Change-Id: Icb11f90254521715dfb2abb5bac6eb87ce45b92d Signed-off-by: Gwendal Grignou Signed-off-by: Mario Tesi Reviewed-on: https://chromium-review.googlesource.com/465375 Commit-Ready: mario tesi Tested-by: mario tesi Reviewed-by: Aseda Aboagye --- driver/accelgyro_lsm6dsm.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'driver') diff --git a/driver/accelgyro_lsm6dsm.h b/driver/accelgyro_lsm6dsm.h index ba1bf51510..bf40741140 100644 --- a/driver/accelgyro_lsm6dsm.h +++ b/driver/accelgyro_lsm6dsm.h @@ -77,11 +77,11 @@ enum lsm6dsm_odr { /* ODR reg value from selected data rate in mHz */ #define LSM6DSM_ODR_TO_REG(_odr) \ - (31 - __builtin_clz(_odr / LSM6DSM_ODR_MIN_VAL)) + __fls(_odr / LSM6DSM_ODR_MIN_VAL) /* normalized ODR value from selected data rate in mHz */ #define LSM6DSM_ODR_TO_NORMALIZE(_odr) \ - (LSM6DSM_ODR_MIN_VAL * (_odr / LSM6DSM_ODR_MIN_VAL)) + (LSM6DSM_ODR_MIN_VAL << __fls(_odr/LSM6DSM_ODR_MIN_VAL)) /* Full Scale range value for Accel */ #define LSM6DSM_FS_LIST_NUM 4 @@ -104,7 +104,7 @@ enum lsm6dsm_odr { /* Accel Gain value from selected Full Scale */ #define LSM6DSM_ACCEL_FS_GAIN(_fs) \ (_fs == 16 ? LSM6DSM_ACCEL_FS_16G_GAIN : \ - LSM6DSM_ACCEL_FS_2G_GAIN << (31 - __builtin_clz(_fs / 2))) + LSM6DSM_ACCEL_FS_2G_GAIN << __fls(_fs / 2)) /* Accel FS Full Scale value from Gain */ #define LSM6DSM_ACCEL_GAIN_FS(_gain) \ @@ -138,7 +138,7 @@ enum lsm6dsm_odr { /* Gyro FS Gain value from selected Full Scale */ #define LSM6DSM_GYRO_FS_GAIN(_fs) \ - (LSM6DSM_GYRO_FS_245_GAIN << (31 - __builtin_clz(_fs / 245))) + (LSM6DSM_GYRO_FS_245_GAIN << __fls(_fs / 245)) /* Gyro FS Full Scale value from Gain */ #define LSM6DSM_GYRO_GAIN_FS(_gain) \ @@ -147,11 +147,11 @@ enum lsm6dsm_odr { /* Gyro Reg value from Full Scale */ #define LSM6DSM_GYRO_FS_REG(_fs) \ - ((31 - __builtin_clz(_fs / 245))) + __fls(_fs / 245) /* Gyro normalized FS value from Full Scale: for Gyro Gains are not multiple */ #define LSM6DSM_GYRO_NORMALIZE_FS(_fs) \ - (_fs == 245 ? 245 : 500 << (31 - __builtin_clz(_fs / 500))) + (_fs == 245 ? 245 : 500 << __fls(_fs / 500)) /* FS register address/mask for Acc/Gyro sensors */ #define LSM6DSM_RANGE_REG(_sensor) (LSM6DSM_ACCEL_FS_ADDR + (_sensor)) -- cgit v1.2.1