From f957f7fef2ae683d90840ccb89a922a5fd587082 Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Wed, 20 May 2020 13:48:33 -0700 Subject: waddledoo: Add rotation matrices for sensors This commit adds the needed rotation matrices for the sensors to place the measurements into the standard reference frame. BUG=b:155253629 BRANCH=None TEST=Build and flash waddledoo. Compare accel readings against released chromebooks and verify that they match in orientation and sign. Signed-off-by: Aseda Aboagye Change-Id: I6d1cb3ed674d71b083eef5e44e972794108701a1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2210826 Tested-by: Aseda Aboagye Reviewed-by: Diana Z Commit-Queue: Diana Z Auto-Submit: Aseda Aboagye --- board/waddledoo/board.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'board/waddledoo/board.c') diff --git a/board/waddledoo/board.c b/board/waddledoo/board.c index 2d8a4c4f47..cd0a2cfccc 100644 --- a/board/waddledoo/board.c +++ b/board/waddledoo/board.c @@ -242,6 +242,19 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, static struct mutex g_lid_mutex; static struct mutex g_base_mutex; +/* Matrices to rotate accelerometers into the standard reference. */ +static const mat33_fp_t lid_standard_ref = { + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(-1), 0, 0}, + { 0, 0, FLOAT_TO_FP(1)} +}; + +static const mat33_fp_t base_standard_ref = { + { 0, FLOAT_TO_FP(1), 0}, + { FLOAT_TO_FP(-1), 0, 0}, + { 0, 0, FLOAT_TO_FP(1)} +}; + static struct accelgyro_saved_data_t g_bma253_data; static struct bmi_drv_data_t g_bmi160_data; @@ -257,7 +270,7 @@ struct motion_sensor_t motion_sensors[] = { .drv_data = &g_bma253_data, .port = I2C_PORT_SENSOR, .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS, - .rot_standard_ref = NULL, + .rot_standard_ref = &lid_standard_ref, .default_range = 2, .min_frequency = BMA255_ACCEL_MIN_FREQ, .max_frequency = BMA255_ACCEL_MAX_FREQ, @@ -281,7 +294,7 @@ struct motion_sensor_t motion_sensors[] = { .drv_data = &g_bmi160_data, .port = I2C_PORT_SENSOR, .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, - .rot_standard_ref = NULL, + .rot_standard_ref = &base_standard_ref, .default_range = 4, .min_frequency = BMI_ACCEL_MIN_FREQ, .max_frequency = BMI_ACCEL_MAX_FREQ, @@ -308,7 +321,7 @@ struct motion_sensor_t motion_sensors[] = { .port = I2C_PORT_SENSOR, .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, .default_range = 1000, /* dps */ - .rot_standard_ref = NULL, + .rot_standard_ref = &base_standard_ref, .min_frequency = BMI_GYRO_MIN_FREQ, .max_frequency = BMI_GYRO_MAX_FREQ, }, -- cgit v1.2.1