diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2018-03-09 14:43:47 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-16 13:29:58 -0700 |
commit | cf30d5c29dae458f1f616351b48f8d04aa4a777a (patch) | |
tree | 1fe94ec0472bb1b2856cc4707e4cae42b6d209ae /driver/accelgyro_bmi160.c | |
parent | 09292f6a89b113775ac951afed022138b6b20026 (diff) | |
download | chrome-ec-cf30d5c29dae458f1f616351b48f8d04aa4a777a.tar.gz |
driver: bma2x2: Add perform_calib
Add fast compensation automatic calibration, like bmi160.
Use timestamp_expired for timeout measurement for both perform_calib
functions.
Remove driver offset field, remove private bma2x2 structure.
BUG=b:73205042
BRANCH=master
TEST=echo 1 > calibrate perform calibration.
Reading in_accel_*_calibbias is within range.
Check on Lami for both bma2x2 and bmi160.
Change-Id: I3472865287fa4769a05e6f872b92d7c3f933cb4e
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/957872
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'driver/accelgyro_bmi160.c')
-rw-r--r-- | driver/accelgyro_bmi160.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c index 20a6a65a79..74689b6ae9 100644 --- a/driver/accelgyro_bmi160.c +++ b/driver/accelgyro_bmi160.c @@ -599,9 +599,10 @@ static int set_offset(const struct motion_sensor_t *s, return ret; } -int perform_calib(const struct motion_sensor_t *s) +static int perform_calib(const struct motion_sensor_t *s) { - int ret, val, en_flag, status, timeout = 0, rate; + int ret, val, en_flag, status, rate; + timestamp_t deadline; rate = get_data_rate(s); /* @@ -635,8 +636,9 @@ int perform_calib(const struct motion_sensor_t *s) ret = raw_write8(s->port, s->addr, BMI160_FOC_CONF, val); ret = raw_write8(s->port, s->addr, BMI160_CMD_REG, BMI160_CMD_START_FOC); + deadline.val = get_time().val + 400; do { - if (timeout > 400) { + if (timestamp_expired(deadline, NULL)) { ret = EC_RES_TIMEOUT; goto end_perform_calib; } @@ -644,7 +646,6 @@ int perform_calib(const struct motion_sensor_t *s) ret = raw_read8(s->port, s->addr, BMI160_STATUS, &status); if (ret != EC_SUCCESS) goto end_perform_calib; - timeout += 50; } while ((status & BMI160_FOC_RDY) == 0); /* Calibration is successful, and loaded, use the result */ |