diff options
author | Jian-Jia Su <jjsu@chromium.org> | 2020-07-28 12:24:17 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-04 05:10:56 +0000 |
commit | 3e8d31a1e10fc80852a6bdc02ebbe4fc54a6a948 (patch) | |
tree | 4a76b05831a00908efe4993c6bc6accb69af8868 /driver/accel_bma2x2.c | |
parent | 1ae42ef81eb9c81b90c2eb5cd9f58825e08174b6 (diff) | |
download | chrome-ec-3e8d31a1e10fc80852a6bdc02ebbe4fc54a6a948.tar.gz |
driver: bma253: use rotation matrix to handle offsets
Store offsets using sensor axis, not the device axis.
Therefore apply rot_standard_ref to the offset vector before
get and rot_standard_ref^-1 before set.
BUG=b:160842447
TEST=check the offset follow device axis
BRANCH=none
Signed-off-by: Jian-Jia Su <jjsu@chromium.org>
Change-Id: I3a4f5caabd9fdfdc3825cccc622a854a3521bed4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2325525
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'driver/accel_bma2x2.c')
-rw-r--r-- | driver/accel_bma2x2.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/driver/accel_bma2x2.c b/driver/accel_bma2x2.c index a4f66036ce..92e273cf9a 100644 --- a/driver/accel_bma2x2.c +++ b/driver/accel_bma2x2.c @@ -128,12 +128,15 @@ static int set_offset(const struct motion_sensor_t *s, const int16_t *offset, int16_t temp) { int i, ret; + intv3_t v = { offset[X], offset[Y], offset[Z] }; + + rotate_inv(v, *s->rot_standard_ref, v); /* temperature is ignored */ /* Offset from host is in 1/1024g, 1/128g internally. */ for (i = X; i <= Z; i++) { ret = raw_write8(s->port, s->i2c_spi_addr_flags, - BMA2x2_OFFSET_X_AXIS_ADDR + i, offset[i] / 8); + BMA2x2_OFFSET_X_AXIS_ADDR + i, v[i] / 8); if (ret) return ret; } @@ -144,14 +147,20 @@ static int get_offset(const struct motion_sensor_t *s, int16_t *offset, int16_t *temp) { int i, val, ret; + intv3_t v; for (i = X; i <= Z; i++) { ret = raw_read8(s->port, s->i2c_spi_addr_flags, BMA2x2_OFFSET_X_AXIS_ADDR + i, &val); if (ret) return ret; - offset[i] = (int8_t)val * 8; + v[i] = (int8_t)val * 8; } + rotate(v, *s->rot_standard_ref, v); + offset[X] = v[X]; + offset[Y] = v[Y]; + offset[Z] = v[Z]; + *temp = EC_MOTION_SENSE_INVALID_CALIB_TEMP; return EC_SUCCESS; } |