From e013aaa016fd883a6ac545c851ecb1f5b1e60874 Mon Sep 17 00:00:00 2001 From: Paul Ma Date: Fri, 22 Jun 2018 18:11:04 +0800 Subject: 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 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 Tested-by: Paul Ma Reviewed-by: Jett Rink --- driver/stm_mems_common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'driver/stm_mems_common.c') 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); -- cgit v1.2.1