diff options
author | Scott Collyer <scollyer@google.com> | 2019-02-11 17:50:35 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-27 13:43:43 -0800 |
commit | 62e6e0ac57958e976fd7575febe0c8d2926a39bf (patch) | |
tree | 5d26410a88228a2b9ebed15aacbae4d044ae4dd8 /board/hatch/board.c | |
parent | a3c27b39fa69f280a3728a5cf24de57a5d3ccb0d (diff) | |
download | chrome-ec-62e6e0ac57958e976fd7575febe0c8d2926a39bf.tar.gz |
hatch: Add support for base accelgyro bmi160 sensor
This CL adds the motion_sensor_t table, config options, gpio interrupt
signal, and rotation matrix required for the bmi160 base accel/gyro
sensor.
BUG=b:124337208
BRANCH=none
TEST=Verfied with 'ectool motionsense' that sensor readings are
present and that values move in the expected direction as I rotated
the unit along it's X and Y axis. Also verified the gyro sensor
returns non-zero values when moving the system.
Change-Id: I57c323916662a4ee0b9aa3fc00c3a4bf18aaef40
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1464393
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Tested-by: Zack Yang <zack_yang@compal.corp-partner.google.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Diffstat (limited to 'board/hatch/board.c')
-rw-r--r-- | board/hatch/board.c | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/board/hatch/board.c b/board/hatch/board.c index 9bac034d31..5648dc016e 100644 --- a/board/hatch/board.c +++ b/board/hatch/board.c @@ -8,6 +8,7 @@ #include "adc.h" #include "adc_chip.h" #include "common.h" +#include "driver/accelgyro_bmi160.h" #include "driver/ppc/sn5s330.h" #include "ec_commands.h" #include "extpower.h" @@ -110,6 +111,66 @@ const struct pwm_t pwm_channels[] = { BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); /******************************************************************************/ +/* Sensors */ +/* Base Sensor mutex */ +static struct mutex g_base_mutex; + +/* Base accel private data */ +static struct bmi160_drv_data_t g_bmi160_data; + +/* Matrix to rotate accelrator into standard reference frame */ +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)} +}; + +struct motion_sensor_t motion_sensors[] = { + [BASE_ACCEL] = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, + .addr = BMI160_ADDR0, + .rot_standard_ref = &base_standard_ref, + .min_frequency = BMI160_ACCEL_MIN_FREQ, + .max_frequency = BMI160_ACCEL_MAX_FREQ, + .default_range = 2, /* g, to support tablet mode */ + .config = { + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + /* Sensor on in S3 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, + }, + [BASE_GYRO] = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &bmi160_drv, + .mutex = &g_base_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_ACCEL, + .addr = BMI160_ADDR0, + .default_range = 1000, /* dps */ + .rot_standard_ref = &base_standard_ref, + .min_frequency = BMI160_GYRO_MIN_FREQ, + .max_frequency = BMI160_GYRO_MAX_FREQ, + }, +}; +unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); + +/******************************************************************************/ /* Physical fans. These are logically separate from pwm_channels. */ const struct fan_conf fan_conf_0 = { @@ -189,7 +250,15 @@ static void setup_fans(void) thermal_params[TEMP_SENSOR_1] = thermal_a; thermal_params[TEMP_SENSOR_2] = thermal_a; } -DECLARE_HOOK(HOOK_INIT, setup_fans, HOOK_PRIO_DEFAULT); + +static void board_init(void) +{ + /* Initialize Fans */ + setup_fans(); + /* Enable gpio interrupt for base accelgyro sensor */ + gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L); +} +DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); void board_overcurrent_event(int port, int is_overcurrented) { |