diff options
author | Philip Chen <philipchen@google.com> | 2018-06-07 02:51:55 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-15 10:57:42 -0700 |
commit | b0d725bf21e230e1b04afa689e0e13e181e4c423 (patch) | |
tree | a47f6b13a4ad5c7aacbf331ac1f8dba6e30d1b73 /board | |
parent | db1f369e08cdf839bce6525bc20a5488a5b14ad0 (diff) | |
download | chrome-ec-b0d725bf21e230e1b04afa689e0e13e181e4c423.tar.gz |
cheza: Support accel/gyro
BUG=b:110006188
BRANCH=none
TEST=Move/rotate cheza rev1 board, and
'accelread' shows different readings
Change-Id: Iec89e800df9722f5bb53d91c3178dd99d30e5d4c
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1090693
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Alexandru M Stan <amstan@chromium.org>
Diffstat (limited to 'board')
-rw-r--r-- | board/cheza/board.c | 61 | ||||
-rw-r--r-- | board/cheza/board.h | 16 | ||||
-rw-r--r-- | board/cheza/ec.tasklist | 1 | ||||
-rw-r--r-- | board/cheza/gpio.inc | 2 |
4 files changed, 79 insertions, 1 deletions
diff --git a/board/cheza/board.c b/board/cheza/board.c index 0409fb3885..c608ab583f 100644 --- a/board/cheza/board.c +++ b/board/cheza/board.c @@ -11,6 +11,7 @@ #include "charge_state.h" #include "chipset.h" #include "extpower.h" +#include "driver/accelgyro_bmi160.h" #include "driver/ppc/sn5s330.h" #include "driver/tcpm/anx74xx.h" #include "driver/tcpm/ps8xxx.h" @@ -236,6 +237,9 @@ static void board_init(void) /* Enable BC1.2 interrupts */ gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_L); gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_L); + + /* Enable interrupt for BMI160 sensor */ + gpio_enable_interrupt(GPIO_ACCEL_GYRO_INT_L); } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); @@ -424,3 +428,60 @@ uint16_t tcpc_get_alert_status(void) return status; } +/* Mutexes */ +static struct mutex g_lid_mutex; + +static struct bmi160_drv_data_t g_bmi160_data; + +/* Matrix to rotate accelerometer into standard reference frame */ +const matrix_3x3_t base_standard_ref = { + { FLOAT_TO_FP(-1), 0, 0}, + { 0, FLOAT_TO_FP(-1), 0}, + { 0, 0, FLOAT_TO_FP(1)} +}; + +struct motion_sensor_t motion_sensors[] = { + /* + * Note: bmi160: supports accelerometer and gyro sensor + * Requirement: accelerometer sensor must init before gyro sensor + * DO NOT change the order of the following table. + */ + [LID_ACCEL] = { + .name = "Accel", + .active_mask = SENSOR_ACTIVE_S0_S3_S5, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &bmi160_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_SENSOR, + .addr = BMI160_ADDR0, + .rot_standard_ref = &base_standard_ref, + .default_range = 4, /* g */ + .min_frequency = BMI160_ACCEL_MIN_FREQ, + .max_frequency = BMI160_ACCEL_MAX_FREQ, + .config = { + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, + }, + [LID_GYRO] = { + .name = "Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3_S5, + .chip = MOTIONSENSE_CHIP_BMI160, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_LID, + .drv = &bmi160_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_bmi160_data, + .port = I2C_PORT_SENSOR, + .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, + }, +}; +const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); diff --git a/board/cheza/board.h b/board/cheza/board.h index e91a4829fd..55e80c56aa 100644 --- a/board/cheza/board.h +++ b/board/cheza/board.h @@ -90,6 +90,15 @@ #define CONFIG_USBC_VCONN #define CONFIG_USBC_VCONN_SWAP +/* Sensors */ +#define CONFIG_ACCELGYRO_BMI160 +#define CONFIG_ACCEL_INTERRUPTS +#define CONFIG_ACCELGYRO_BMI160_INT_EVENT TASK_EVENT_CUSTOM(4) +#define CONFIG_ACCEL_FIFO 512 +#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3) +#define CONFIG_CMD_ACCELS +#define CONFIG_CMD_ACCEL_INFO + /* TODO(b/79163120): Use correct PD delay values, copied from Lux for rev-0 */ #define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */ #define PD_POWER_SUPPLY_TURN_OFF_DELAY 250000 /* us */ @@ -112,6 +121,7 @@ /* I2C Ports */ #define I2C_PORT_BATTERY I2C_PORT_POWER #define I2C_PORT_CHARGER I2C_PORT_POWER +#define I2C_PORT_ACCEL I2C_PORT_SENSOR #define I2C_PORT_POWER NPCX_I2C_PORT0_0 #define I2C_PORT_TCPC0 NPCX_I2C_PORT1_0 #define I2C_PORT_TCPC1 NPCX_I2C_PORT2_0 @@ -134,6 +144,12 @@ enum adc_channel { ADC_CH_COUNT }; +/* Motion sensors */ +enum sensor_id { + LID_ACCEL = 0, + LID_GYRO, +}; + void board_set_switchcap(int asserted); /* Custom function to indicate if sourcing VBUS */ diff --git a/board/cheza/ec.tasklist b/board/cheza/ec.tasklist index 06acec6971..970f1df3f0 100644 --- a/board/cheza/ec.tasklist +++ b/board/cheza/ec.tasklist @@ -26,6 +26,7 @@ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \ TASK_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_ALWAYS(CONSOLE, console_task, NULL, LARGER_TASK_STACK_SIZE) \ diff --git a/board/cheza/gpio.inc b/board/cheza/gpio.inc index a2820713a6..6dae084476 100644 --- a/board/cheza/gpio.inc +++ b/board/cheza/gpio.inc @@ -17,6 +17,7 @@ GPIO_INT(USB_C1_BC12_INT_L, PIN(8, 2), GPIO_INT_FALLING, usb1_evt) /* Interr GPIO_INT(USB_C0_VBUS_DET_L, PIN(6, 2), GPIO_INT_BOTH | GPIO_PULL_UP, vbus0_evt) /* BC1.2 VBUS detection on port-0 */ GPIO_INT(USB_C1_VBUS_DET_L, PIN(8, 3), GPIO_INT_BOTH | GPIO_PULL_UP, vbus1_evt) /* BC1.2 VBUS detection on port-1 */ GPIO_INT(USB_C0_CABLE_DET, PIN(3, 7), GPIO_INT_RISING, anx74xx_cable_det_interrupt) /* Cable detection from port-0 TCPC */ +GPIO_INT(ACCEL_GYRO_INT_L, PIN(D, 3), GPIO_INT_RISING | GPIO_SEL_1P8V, bmi160_interrupt) /* Accelerometer/gyro interrupt */ /* System interrupts */ /* @@ -55,7 +56,6 @@ GPIO(BL_DISABLE_L, PIN(2, 6), GPIO_OUT_HIGH) /* EC_BL_DISABLE_L: Backl /* Sensors */ GPIO(ALS_INT_L, PIN(5, 0), GPIO_INPUT) /* ALS sensor interrupt */ GPIO(P_SENSOR_INT_L, PIN(1, 4), GPIO_INPUT) /* P-sensor interrupt */ -GPIO(ACCEL_GYRO_INT_L, PIN(D, 3), GPIO_INPUT) /* Accelerometer/gyro interrupt */ GPIO(RCAM_VSYNC, PIN(4, 0), GPIO_INPUT) /* VSYNC from rear camera */ /* Base */ |