diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2016-11-01 14:02:21 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2016-11-02 17:10:01 +0000 |
commit | c2c0437ebab0c2ffd45e8b9680d8d95d962b868c (patch) | |
tree | cfc4d09ca0fbc9a2b1ca886b991afb94b672a9a0 | |
parent | 13c246df6cd8ed7187ca1ec29e6472311726c6af (diff) | |
download | chrome-ec-c2c0437ebab0c2ffd45e8b9680d8d95d962b868c.tar.gz |
driver: bmi160: Autocalibrate Accelerometer properly.
Take into account the rotation matrix to do calibration.
In particular the Z axis: if board is upside down, we need to use
MINUS_1G instead of PLUS_1G when setting online calibration.
BRANCH=kevin
BUG=none
TEST=Before, calibration would not work on the Z axis.
Change-Id: Ifaec331aac40a4be0e34fcab5dd3752d2d59b91f
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/405854
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
(cherry picked from commit cd30d638ab60e5d1821e0fff22051f482cf7a5a7)
Reviewed-on: https://chromium-review.googlesource.com/406573
-rw-r--r-- | driver/accelgyro_bmi160.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index 9be65a4cea..010dbb5d93 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -608,9 +608,14 @@ int perform_calib(const struct motion_sensor_t *s) switch (s->type) { case MOTIONSENSE_TYPE_ACCEL: /* We assume the device is laying flat for calibration */ + if (s->rot_standard_ref == NULL || + (*s->rot_standard_ref)[2][2] > INT_TO_FP(0)) + val = BMI160_FOC_ACC_PLUS_1G; + else + val = BMI160_FOC_ACC_MINUS_1G; val = (BMI160_FOC_ACC_0G << BMI160_FOC_ACC_X_OFFSET) | (BMI160_FOC_ACC_0G << BMI160_FOC_ACC_Y_OFFSET) | - (BMI160_FOC_ACC_PLUS_1G << BMI160_FOC_ACC_Z_OFFSET); + (val << BMI160_FOC_ACC_Z_OFFSET); en_flag = BMI160_OFFSET_ACC_EN; break; case MOTIONSENSE_TYPE_GYRO: |