diff options
-rw-r--r-- | board/gimble/board.c | 4 | ||||
-rw-r--r-- | board/gimble/board.h | 24 | ||||
-rw-r--r-- | board/gimble/gpio.inc | 4 | ||||
-rw-r--r-- | board/gimble/sensors.c | 86 |
4 files changed, 50 insertions, 68 deletions
diff --git a/board/gimble/board.c b/board/gimble/board.c index 1d53974627..ad70d0f2bf 100644 --- a/board/gimble/board.c +++ b/board/gimble/board.c @@ -10,8 +10,8 @@ #include "charge_ramp.h" #include "charger.h" #include "console.h" -#include "driver/accel_lis2dw12.h" -#include "driver/accelgyro_lsm6dso.h" +#include "driver/accel_bma2x2_public.h" +#include "driver/accelgyro_bmi160.h" #include "fw_config.h" #include "hooks.h" #include "lid_switch.h" diff --git a/board/gimble/board.h b/board/gimble/board.h index 4040e9269a..2965ddc6ae 100644 --- a/board/gimble/board.h +++ b/board/gimble/board.h @@ -37,16 +37,13 @@ #define CONFIG_LED_PWM_LOW_BATT_COLOR EC_LED_COLOR_AMBER /* Sensors */ -#define CONFIG_ACCELGYRO_LSM6DSO /* Base accel */ -#define CONFIG_ACCEL_LSM6DSO_INT_EVENT \ - TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +/* BMA253 accelerometer in lid */ +#define CONFIG_ACCEL_BMA255 -/* Enable sensor fifo, must also define the _SIZE and _THRES */ -#define CONFIG_ACCEL_FIFO -/* FIFO size is in power of 2. */ -#define CONFIG_ACCEL_FIFO_SIZE 256 -/* Depends on how fast the AP boots and typical ODRs */ -#define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO_SIZE / 3) +#define CONFIG_ACCEL_INTERRUPTS +#define CONFIG_ACCELGYRO_BMI160 /* Base accel/gyro */ +#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) /* Sensors without hardware FIFO are in forced mode */ #define CONFIG_ACCEL_FORCE_MODE_MASK BIT(LID_ACCEL) @@ -55,12 +52,6 @@ #define CONFIG_LID_ANGLE #define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL -#define CONFIG_ACCEL_LIS2DWL -#define CONFIG_ACCEL_LIS2DW_AS_BASE -#define CONFIG_ACCEL_LIS2DW12_INT_EVENT \ - TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL) - -#define CONFIG_ACCEL_INTERRUPTS /* Sensor console commands */ #define CONFIG_CMD_ACCELS @@ -152,6 +143,9 @@ #define I2C_PORT_EEPROM NPCX_I2C_PORT7_0 #define I2C_PORT_MP2964 NPCX_I2C_PORT7_0 +/* define this to aviod error on CONFIG_ACCELGYRO_BMI_COMM_I2C */ +#define I2C_PORT_ACCEL I2C_PORT_SENSOR + #define I2C_ADDR_EEPROM_FLAGS 0x50 #define I2C_ADDR_MP2964_FLAGS 0x20 diff --git a/board/gimble/gpio.inc b/board/gimble/gpio.inc index ebedf12d67..dc747e8545 100644 --- a/board/gimble/gpio.inc +++ b/board/gimble/gpio.inc @@ -9,8 +9,7 @@ /* INTERRUPT GPIOs: */ GPIO_INT(ACOK_OD, PIN(0, 0), GPIO_INT_BOTH | GPIO_HIB_WAKE_HIGH, extpower_interrupt) -GPIO_INT(EC_ACCEL_INT_R_L, PIN(8, 1), GPIO_SEL_1P8V | GPIO_INT_FALLING, lis2dw12_interrupt) -GPIO_INT(EC_IMU_INT_R_L, PIN(5, 6), GPIO_SEL_1P8V | GPIO_INT_FALLING, lsm6dso_interrupt) +GPIO_INT(EC_IMU_INT_R_L, PIN(5, 6), GPIO_SEL_1P8V | GPIO_INT_FALLING, bmi160_interrupt) GPIO_INT(EC_PROCHOT_IN_L, PIN(F, 0), GPIO_INT_BOTH, throttle_ap_prochot_input_interrupt) GPIO_INT(EC_VOLDN_BTN_ODL, PIN(9, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) GPIO_INT(EC_VOLUP_BTN_ODL, PIN(9, 7), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) @@ -126,6 +125,7 @@ UNUSED(PIN(4, 1)) /* GPIO41/ADC4 */ UNUSED(PIN(A, 0)) /* F_CS0_L/GPIOA0 */ UNUSED(PIN(9, 6)) /* F_DIO1/GPIO96 */ UNUSED(PIN(7, 0)) /* GPIO70/PS2_DAT0 */ +UNUSED(PIN(8, 1)) /* PECI DATA/GPIO81 */ /* Pre-configured PSL balls: J8 K6 */ diff --git a/board/gimble/sensors.c b/board/gimble/sensors.c index a6e560fa99..47149b05d0 100644 --- a/board/gimble/sensors.c +++ b/board/gimble/sensors.c @@ -6,8 +6,9 @@ #include "common.h" #include "accelgyro.h" #include "adc_chip.h" -#include "driver/accel_lis2dw12.h" -#include "driver/accelgyro_lsm6dso.h" +#include "driver/accel_bma2x2.h" +#include "driver/accel_bma2x2_public.h" +#include "driver/accelgyro_bmi_common.h" #include "hooks.h" #include "motion_sense.h" #include "temp_sensor.h" @@ -35,17 +36,20 @@ BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); K_MUTEX_DEFINE(g_lid_accel_mutex); K_MUTEX_DEFINE(g_base_accel_mutex); -static struct stprivate_data g_lis2dw12_data; -static struct lsm6dso_data lsm6dso_data; +/* BMA253 private data */ +static struct accelgyro_saved_data_t g_bma253_data; -/* TODO(b/184779333): calibrate the orientation matrix on later board stage */ +/* BMI160 private data */ +static struct bmi_drv_data_t g_bmi160_data; + +/* TODO(b/192477578): calibrate the orientation matrix on later board stage */ 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)} }; -/* TODO(b/184779743): verify orientation matrix */ +/* TODO(b/192477578): calibrate the orientation matrix on later board stage */ static const mat33_fp_t base_standard_ref = { { FLOAT_TO_FP(1), 0, 0}, { 0, FLOAT_TO_FP(-1), 0}, @@ -56,26 +60,24 @@ struct motion_sensor_t motion_sensors[] = { [LID_ACCEL] = { .name = "Lid Accel", .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_LIS2DW12, + .chip = MOTIONSENSE_CHIP_BMA255, .type = MOTIONSENSE_TYPE_ACCEL, .location = MOTIONSENSE_LOC_LID, - .drv = &lis2dw12_drv, + .drv = &bma2x2_accel_drv, .mutex = &g_lid_accel_mutex, - .drv_data = &g_lis2dw12_data, - .int_signal = GPIO_EC_ACCEL_INT_R_L, + .drv_data = &g_bma253_data, .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = LIS2DW12_ADDR0, - .flags = MOTIONSENSE_FLAG_INT_SIGNAL, - .rot_standard_ref = &lid_standard_ref, /* identity matrix */ - .default_range = 2, /* g */ - .min_frequency = LIS2DW12_ODR_MIN_VAL, - .max_frequency = LIS2DW12_ODR_MAX_VAL, + .i2c_spi_addr_flags = BMA2x2_I2C_ADDR2_FLAGS, + .rot_standard_ref = &lid_standard_ref, + .min_frequency = BMA255_ACCEL_MIN_FREQ, + .max_frequency = BMA255_ACCEL_MAX_FREQ, + .default_range = 2, /* g, to support tablet mode */ .config = { /* EC use accel for angle detection */ [SENSOR_CONFIG_EC_S0] = { - .odr = 12500 | ROUND_UP_FLAG, + .odr = 10000 | ROUND_UP_FLAG, }, - /* Sensor on for lid angle detection */ + /* Sensor on in S3 */ [SENSOR_CONFIG_EC_S3] = { .odr = 10000 | ROUND_UP_FLAG, }, @@ -85,25 +87,25 @@ struct motion_sensor_t motion_sensors[] = { [BASE_ACCEL] = { .name = "Base Accel", .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_LSM6DSO, + .chip = MOTIONSENSE_CHIP_BMI160, .type = MOTIONSENSE_TYPE_ACCEL, .location = MOTIONSENSE_LOC_BASE, - .drv = &lsm6dso_drv, + .drv = &bmi160_drv, .mutex = &g_base_accel_mutex, - .drv_data = &lsm6dso_data, - .int_signal = GPIO_EC_IMU_INT_R_L, - .flags = MOTIONSENSE_FLAG_INT_SIGNAL, + .drv_data = &g_bmi160_data, .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = LSM6DSO_ADDR0_FLAGS, + .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, .rot_standard_ref = &base_standard_ref, - .default_range = 4, /* g */ - .min_frequency = LSM6DSO_ODR_MIN_VAL, - .max_frequency = LSM6DSO_ODR_MAX_VAL, + .min_frequency = BMI_ACCEL_MIN_FREQ, + .max_frequency = BMI_ACCEL_MAX_FREQ, + .default_range = 4, /* g */ .config = { + /* EC use accel for angle detection */ [SENSOR_CONFIG_EC_S0] = { - .odr = 13000 | ROUND_UP_FLAG, + .odr = 10000 | ROUND_UP_FLAG, .ec_rate = 100 * MSEC, }, + /* Sensor on in S3 */ [SENSOR_CONFIG_EC_S3] = { .odr = 10000 | ROUND_UP_FLAG, .ec_rate = 100 * MSEC, @@ -114,38 +116,24 @@ struct motion_sensor_t motion_sensors[] = { [BASE_GYRO] = { .name = "Base Gyro", .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_LSM6DSO, + .chip = MOTIONSENSE_CHIP_BMI160, .type = MOTIONSENSE_TYPE_GYRO, .location = MOTIONSENSE_LOC_BASE, - .drv = &lsm6dso_drv, + .drv = &bmi160_drv, .mutex = &g_base_accel_mutex, - .drv_data = &lsm6dso_data, - .int_signal = GPIO_EC_IMU_INT_R_L, - .flags = MOTIONSENSE_FLAG_INT_SIGNAL, + .drv_data = &g_bmi160_data, .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = LSM6DSO_ADDR0_FLAGS, - .default_range = 1000 | ROUND_UP_FLAG, /* dps */ + .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS, + .default_range = 1000, /* dps */ .rot_standard_ref = &base_standard_ref, - .min_frequency = LSM6DSO_ODR_MIN_VAL, - .max_frequency = LSM6DSO_ODR_MAX_VAL, - .config = { - [SENSOR_CONFIG_EC_S0] = { - .odr = 13000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, - .ec_rate = 100 * MSEC, - }, - }, + .min_frequency = BMI_GYRO_MIN_FREQ, + .max_frequency = BMI_GYRO_MAX_FREQ, }, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); static void baseboard_sensors_init(void) { - /* Enable gpio interrupt for lid accel sensor */ - gpio_enable_interrupt(GPIO_EC_ACCEL_INT_R_L); /* Enable gpio interrupt for base accelgyro sensor */ gpio_enable_interrupt(GPIO_EC_IMU_INT_R_L); } |