diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2016-11-01 14:02:21 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-11-02 04:23:07 -0700 |
commit | cd30d638ab60e5d1821e0fff22051f482cf7a5a7 (patch) | |
tree | bfa0e281826e44afc0d8079fbe2ff45e667dde8f /driver/accelgyro_bmi160.c | |
parent | 75b1ec6d78c65348f379b9ead6be17a5e18c16b2 (diff) | |
download | chrome-ec-cd30d638ab60e5d1821e0fff22051f482cf7a5a7.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>
Diffstat (limited to 'driver/accelgyro_bmi160.c')
-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 77856e6118..56d484101a 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -616,9 +616,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: |