diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2017-03-30 15:14:23 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-09-20 05:50:22 -0700 |
commit | 13fcc5ad84af6a2421e9ee9207b0adcb500e6f37 (patch) | |
tree | 04ffdb1a465a992a209e5ac49e6f7ad425d104ee /driver/accelgyro_lsm6dsm.h | |
parent | 207b3b4e5fb4a1397a15f0b22061ea025e9ff4a1 (diff) | |
download | chrome-ec-13fcc5ad84af6a2421e9ee9207b0adcb500e6f37.tar.gz |
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 <gwendal@chromium.org>
Signed-off-by: Mario Tesi <mario.tesi@st.com>
Reviewed-on: https://chromium-review.googlesource.com/465375
Commit-Ready: mario tesi <mario.tesi@st.com>
Tested-by: mario tesi <mario.tesi@st.com>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/accelgyro_lsm6dsm.h')
-rw-r--r-- | driver/accelgyro_lsm6dsm.h | 12 |
1 files changed, 6 insertions, 6 deletions
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)) |