diff --git a/board/oak/board.c b/board/oak/board.c index 33a7bec316..1b08001dd6 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -16,6 +16,8 @@ #include "chipset.h" #include "common.h" #include "console.h" +#include "driver/accel_kionix.h" +#include "driver/accel_kx022.h" #include "driver/als_opt3001.h" #include "driver/temp_sensor/tmp432.h" #include "extpower.h" @@ -25,6 +27,9 @@ #include "i2c.h" #include "keyboard_raw.h" #include "lid_switch.h" +#include "math_util.h" +#include "motion_lid.h" +#include "motion_sense.h" #include "pi3usb9281.h" #include "power.h" #include "power_button.h" @@ -550,3 +555,51 @@ static void board_chipset_suspend(void) #endif } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); + +#ifdef HAS_TASK_MOTIONSENSE +/* Motion sensors */ +/* Mutexes */ +static struct mutex g_lid_mutex; + +/* KX022 private data */ +struct kionix_accel_data g_kx022_data = { + .variant = KX022, +}; + +struct motion_sensor_t motion_sensors[] = { + {.name = "Lid Accel", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_KX022, + .type = MOTIONSENSE_TYPE_ACCEL, + .location = MOTIONSENSE_LOC_LID, + .drv = &kionix_accel_drv, + .mutex = &g_lid_mutex, + .drv_data = &g_kx022_data, + .addr = KX022_ADDR1, + .rot_standard_ref = NULL, /* Identity matrix. */ + .default_range = 2, /* g, enough for laptop. */ + .config = { + /* AP: by default use EC settings */ + [SENSOR_CONFIG_AP] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* EC use accel for angle detection */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 10000 | ROUND_UP_FLAG, + .ec_rate = 100 * MSEC, + }, + /* unused */ + [SENSOR_CONFIG_EC_S3] = { + .odr = 0, + .ec_rate = 0, + }, + [SENSOR_CONFIG_EC_S5] = { + .odr = 0, + .ec_rate = 0, + }, + }, + }, +}; +const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +#endif /* defined(HAS_TASK_MOTIONSENSE) */ diff --git a/board/oak/board.h b/board/oak/board.h index 6336ba16ad..ffa6b53207 100644 --- a/board/oak/board.h +++ b/board/oak/board.h @@ -11,6 +11,7 @@ /* board revision */ #include "board_revs.h" +#define CONFIG_ACCEL_KX022 #define CONFIG_ADC #undef CONFIG_ADC_WATCHDOG @@ -132,15 +133,16 @@ #define KB_OUT_PORT_LIST GPIO_A, GPIO_B, GPIO_C, GPIO_D /* 2 I2C master ports, connect to battery, charger, pd and USB switches */ -#define I2C_PORT_MASTER 0 +#define I2C_PORT_MASTER 0 +#define I2C_PORT_ACCEL 0 +#define I2C_PORT_ALS 0 #define I2C_PORT_BATTERY 0 #define I2C_PORT_CHARGER 0 #define I2C_PORT_PERICOM 0 #define I2C_PORT_THERMAL 0 -#define I2C_PORT_PD_MCU 1 +#define I2C_PORT_PD_MCU 1 #define I2C_PORT_USB_MUX 1 -#define I2C_PORT_TCPC 1 -#define I2C_PORT_ALS I2C_PORT_MASTER +#define I2C_PORT_TCPC 1 /* Ambient Light Sensor address */ #define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 diff --git a/board/oak/ec.tasklist b/board/oak/ec.tasklist index 45cb276099..150ac9b3d4 100644 --- a/board/oak/ec.tasklist +++ b/board/oak/ec.tasklist @@ -27,6 +27,7 @@ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_VBUS(VBUS, vbus_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(ALS, als_task, NULL, TASK_STACK_SIZE) \ + TASK_NOTEST(MOTIONSENSE, motion_sense_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(USB_CHG_P1, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ diff --git a/common/math_util.c b/common/math_util.c index 79b0f47f5e..247bda6dd9 100644 --- a/common/math_util.c +++ b/common/math_util.c @@ -6,7 +6,6 @@ /* Common math functions. */ #include "common.h" -#include "math.h" #include "math_util.h" #include "util.h"