From cd30d638ab60e5d1821e0fff22051f482cf7a5a7 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 1 Nov 2016 14:02:21 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/405854 Reviewed-by: Aseda Aboagye --- driver/accelgyro_bmi160.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'driver') 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: -- cgit v1.2.1