diff options
-rw-r--r-- | board/delbin/board.h | 4 | ||||
-rw-r--r-- | board/delbin/gpio.inc | 2 | ||||
-rw-r--r-- | board/delbin/sensors.c | 73 |
3 files changed, 75 insertions, 4 deletions
diff --git a/board/delbin/board.h b/board/delbin/board.h index e14415bcf5..91f69a2bae 100644 --- a/board/delbin/board.h +++ b/board/delbin/board.h @@ -49,6 +49,9 @@ #define CONFIG_ACCELGYRO_BMI260 #define CONFIG_ACCELGYRO_BMI260_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) +#define CONFIG_ACCELGYRO_ICM426XX +#define CONFIG_ACCELGYRO_ICM426XX_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) @@ -175,6 +178,7 @@ enum usbc_port { }; void board_reset_pd_mcu(void); +void motion_interrupt(enum gpio_signal signal); #endif /* !__ASSEMBLER__ */ diff --git a/board/delbin/gpio.inc b/board/delbin/gpio.inc index 143971ff65..333c638b0a 100644 --- a/board/delbin/gpio.inc +++ b/board/delbin/gpio.inc @@ -25,7 +25,7 @@ GPIO_INT(DSW_PWROK, PIN(C, 7), GPIO_INT_BOTH, power_signal_interrupt) GPIO_INT(PG_EC_ALL_SYS_PWRGD, PIN(F, 4), GPIO_INT_BOTH, power_signal_interrupt) /* Sensor Interrupts */ -GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi260_interrupt) +GPIO_INT(EC_IMU_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, motion_interrupt) GPIO_INT(TABLET_MODE_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr) /* * Lid g-sensor interrupt unused on Delbin, configure as regular input for diff --git a/board/delbin/sensors.c b/board/delbin/sensors.c index fc8e30410b..8000295554 100644 --- a/board/delbin/sensors.c +++ b/board/delbin/sensors.c @@ -12,6 +12,8 @@ #include "driver/accel_kionix.h" #include "driver/accelgyro_bmi_common.h" #include "driver/accelgyro_bmi260.h" +#include "driver/accelgyro_icm_common.h" +#include "driver/accelgyro_icm426xx.h" #include "keyboard_scan.h" #include "hooks.h" #include "i2c.h" @@ -24,12 +26,11 @@ static struct mutex g_lid_accel_mutex; static struct mutex g_base_mutex; -/* BMA253 private data */ +/* sensor private data */ static struct accelgyro_saved_data_t g_bma253_data; static struct kionix_accel_data g_kx022_data; - -/* BMI260 private data */ static struct bmi_drv_data_t g_bmi260_data; +static struct icm_drv_data_t g_icm426xx_data; /* Rotation matrix for the lid accelerometer */ static const mat33_fp_t lid_standard_ref = { @@ -44,6 +45,57 @@ const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(1)} }; +const mat33_fp_t base_standard_ref_icm = { + { 0, FLOAT_TO_FP(-1), 0}, + { FLOAT_TO_FP(1), 0, 0}, + { 0, 0, FLOAT_TO_FP(1)}, +}; + +struct motion_sensor_t icm426xx_base_accel = { + .name = "Base Accel", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_ICM426XX, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_BASE, + .drv = &icm426xx_drv, + .mutex = &g_base_mutex, + .drv_data = &g_icm426xx_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .rot_standard_ref = &base_standard_ref_icm, + .min_frequency = ICM426XX_ACCEL_MIN_FREQ, + .max_frequency = ICM426XX_ACCEL_MAX_FREQ, + .default_range = 4, /* g */ + .config = { + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* Sensor on in S3 */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 10000 | ROUND_UP_FLAG, + }, + }, +}; + +struct motion_sensor_t icm426xx_base_gyro = { + .name = "Base Gyro", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_ICM426XX, + .type = MOTIONSENSE_TYPE_GYRO, + .location = MOTIONSENSE_LOC_BASE, + .drv = &icm426xx_drv, + .mutex = &g_base_mutex, + .drv_data = &g_icm426xx_data, + .port = I2C_PORT_SENSOR, + .i2c_spi_addr_flags = ICM426XX_ADDR0_FLAGS, + .default_range = 1000, /* dps */ + .rot_standard_ref = &base_standard_ref_icm, + .min_frequency = ICM426XX_GYRO_MIN_FREQ, + .max_frequency = ICM426XX_GYRO_MAX_FREQ, +}; + struct motion_sensor_t kx022_lid_accel = { .name = "Lid Accel", .active_mask = SENSOR_ACTIVE_S0_S3, @@ -146,6 +198,14 @@ struct motion_sensor_t motion_sensors[] = { }; unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +void motion_interrupt(enum gpio_signal signal) +{ + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX) + icm426xx_interrupt(signal); + else + bmi260_interrupt(signal); +} + static void baseboard_sensors_init(void) { if (get_cbi_ssfc_lid_sensor() == SSFC_SENSOR_LID_KX022) { @@ -154,6 +214,13 @@ static void baseboard_sensors_init(void) } else ccprints("LID_ACCEL is BMA253"); + if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_BASE_ICM426XX) { + motion_sensors[BASE_ACCEL] = icm426xx_base_accel; + motion_sensors[BASE_GYRO] = icm426xx_base_gyro; + ccprints("BASE ACCEL is ICM426XX"); + } else + ccprints("BASE ACCEL IS BMI260"); + /* Enable interrupt for the accel/gyro sensor */ gpio_enable_interrupt(GPIO_EC_IMU_INT_L); } |