diff options
author | Paul Ma <magf@bitland.corp-partner.google.com> | 2018-06-22 18:11:04 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-27 22:07:33 -0700 |
commit | e013aaa016fd883a6ac545c851ecb1f5b1e60874 (patch) | |
tree | f77fd7dd49db24cc1fa45a2a8cf1c6887aff158f /driver | |
parent | 29bcf334faf89986816127690a9c99459d74a801 (diff) | |
download | chrome-ec-e013aaa016fd883a6ac545c851ecb1f5b1e60874.tar.gz |
phaser: fix lis2de resolution and sensor value output
lis2de only support 8-bit resolution. This is what is different
from lis2dh. This patch add two defines (CONFIG_ACCEL_LIS2DH and
CONFIG_ACCEL_LIS2DE) to defferientiate them.
For calculate_lid_angle() reliable calculation, code asks for
16 bits sensor value output, this patch fix that as well.
Signed-off-by: Paul Ma <magf@bitland.corp-partner.google.com>
BRANCH=none
BUG=b:110604678
TEST=boot phaser360 board, use 'accelinfo on' to watch lid output
and angle output, lid axis value should be 16 bit range and
angle is correct.
Change-Id: If77954ecf477736b9168b3a3b6805396a3201a57
Reviewed-on: https://chromium-review.googlesource.com/1111775
Commit-Ready: Paul Ma <magf@bitland.corp-partner.google.com>
Tested-by: Paul Ma <magf@bitland.corp-partner.google.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/accel_lis2dh.h | 10 | ||||
-rw-r--r-- | driver/build.mk | 2 | ||||
-rw-r--r-- | driver/stm_mems_common.c | 7 |
3 files changed, 13 insertions, 6 deletions
diff --git a/driver/accel_lis2dh.h b/driver/accel_lis2dh.h index 0421f79503..fe8d17641e 100644 --- a/driver/accel_lis2dh.h +++ b/driver/accel_lis2dh.h @@ -102,11 +102,15 @@ enum lis2dh_odr { #define LIS2DH_FS_TO_REG(_fs) (__fls(_fs) - 1) /* Sensor resolution in number of bits - * This sensor has variable precision (8/10/12 bits) depending Power Mode - * selected - * TODO: Only Normal Power mode supported (10 bits) + * lis2dh has variable precision (8/10/12 bits) depending Power Mode + * selected, here Only Normal Power mode supported (10 bits). + * But for lis2de, it has only one 8bit resolution. */ +#ifdef CONFIG_ACCEL_LIS2DE +#define LIS2DH_RESOLUTION 8 +#elif defined(CONFIG_ACCEL_LIS2DH) #define LIS2DH_RESOLUTION 10 +#endif extern const struct accelgyro_drv lis2dh_drv; diff --git a/driver/build.mk b/driver/build.mk index 68b14f836e..6d0990bcec 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -14,7 +14,7 @@ driver-$(CONFIG_ACCELGYRO_LSM6DS0)+=accelgyro_lsm6ds0.o driver-$(CONFIG_ACCELGYRO_BMI160)+=accelgyro_bmi160.o driver-$(CONFIG_MAG_BMI160_BMM150)+=mag_bmm150.o driver-$(CONFIG_ACCELGYRO_LSM6DSM)+=accelgyro_lsm6dsm.o stm_mems_common.o -driver-$(CONFIG_ACCEL_LIS2DH)+=accel_lis2dh.o stm_mems_common.o +driver-$(CONFIG_ACCEL_LIS2D_COMMON)+=accel_lis2dh.o stm_mems_common.o driver-$(CONFIG_SYNC)+=sync.o # BC1.2 Charger Detection Devices diff --git a/driver/stm_mems_common.c b/driver/stm_mems_common.c index c7b84b5b98..427fc8091f 100644 --- a/driver/stm_mems_common.c +++ b/driver/stm_mems_common.c @@ -134,10 +134,13 @@ void st_normalize(const struct motion_sensor_t *s, vector_3_t v, uint8_t *data) { int i, range; struct stprivate_data *drvdata = s->drv_data; + /* data is left-aligned and the bottom bits need to be + * cleared because they may contain trash data. + */ + uint16_t mask = ~((1 << (16 - drvdata->resol)) - 1); for (i = X; i <= Z; i++) { - v[i] = (int16_t)((data[i * 2 + 1] << 8) | - data[i * 2]) >> (16 - drvdata->resol); + v[i] = ((data[i * 2 + 1] << 8) | data[i * 2]) & mask; } rotate(v, *s->rot_standard_ref, v); |