summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Mittelberg <bmbm@google.com>2021-04-01 03:45:51 +0000
committerCommit Bot <commit-bot@chromium.org>2021-04-08 18:30:23 +0000
commited9b4784c53ca03de59d410341d477b43a78537a (patch)
tree084b5a7fe81c67fa6a64bbca10989a0d37c7d955
parent104abee3dd48ac133e16e9691efa8ad6883d92fb (diff)
downloadchrome-ec-ed9b4784c53ca03de59d410341d477b43a78537a.tar.gz
brya: add motionsense task and IMU sensors
Add motionsense task with following sensors: lid accel, base accel, base gyro. BRANCH=none BUG=b:179648721 TEST=manual tests were performed Base accel/gyro test on EC console: > accelread 1 Current data 1: -65461 65488 8163 > accelread 2 Current data 2: -2 2 65518 Lid accel test from AP console: $ ectool motionsense Sensor 0: 392 10548 12708 All the values above changed when I moved the boards Signed-off-by: Boris Mittelberg <bmbm@google.com> Change-Id: I03cddcf74611da6d2b5557a3998db6f0314a015a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2798977 Reviewed-by: caveh jalali <caveh@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--board/brya/board.c2
-rw-r--r--board/brya/board.h35
-rw-r--r--board/brya/ec.tasklist1
-rw-r--r--board/brya/generated-gpio.inc3
-rw-r--r--board/brya/sensors.c124
5 files changed, 163 insertions, 2 deletions
diff --git a/board/brya/board.c b/board/brya/board.c
index 1cd9836be2..beb327739f 100644
--- a/board/brya/board.c
+++ b/board/brya/board.c
@@ -10,6 +10,8 @@
#include "charge_ramp.h"
#include "charger.h"
#include "console.h"
+#include "driver/accel_lis2dw12.h"
+#include "driver/accelgyro_lsm6dso.h"
#include "power_button.h"
#include "power.h"
#include "switch.h"
diff --git a/board/brya/board.h b/board/brya/board.h
index 80c3fc04a3..7bbd19a6f5 100644
--- a/board/brya/board.h
+++ b/board/brya/board.h
@@ -33,6 +33,34 @@
#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_WHITE
#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)
+
+/* 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)
+
+/* Sensors without hardware FIFO are in forced mode */
+#define CONFIG_ACCEL_FORCE_MODE_MASK \
+ (BIT(LID_ACCEL))
+
+/* 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
+#define CONFIG_CMD_ACCEL_INFO
+
/* USB Type A Features */
#define USB_PORT_COUNT 1
#define CONFIG_USB_PORT_POWER_DUMB
@@ -174,6 +202,13 @@ enum temp_sensor_id {
TEMP_SENSOR_COUNT
};
+enum sensor_id {
+ LID_ACCEL = 0,
+ BASE_ACCEL,
+ BASE_GYRO,
+ SENSOR_COUNT
+};
+
enum ioex_port {
IOEX_C0_NCT38XX = 0,
IOEX_C2_NCT38XX,
diff --git a/board/brya/ec.tasklist b/board/brya/ec.tasklist
index dd4f31ffed..470a1fcdde 100644
--- a/board/brya/ec.tasklist
+++ b/board/brya/ec.tasklist
@@ -17,6 +17,7 @@
TASK_ALWAYS(USB_CHG_P1, usb_charger_task, 0, TASK_STACK_SIZE) \
TASK_ALWAYS(USB_CHG_P2, usb_charger_task, 0, TASK_STACK_SIZE) \
TASK_ALWAYS(CHARGER, charger_task, NULL, VENTI_TASK_STACK_SIZE) \
+ TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, VENTI_TASK_STACK_SIZE) \
TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \
TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, LARGER_TASK_STACK_SIZE) \
diff --git a/board/brya/generated-gpio.inc b/board/brya/generated-gpio.inc
index 7b03ee89e0..67afb0bb09 100644
--- a/board/brya/generated-gpio.inc
+++ b/board/brya/generated-gpio.inc
@@ -4,6 +4,8 @@
/* INTERRUPT GPIOs: */
GPIO_INT(ACOK_OD, PIN(0, 0), GPIO_INT_BOTH, 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_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)
@@ -32,7 +34,6 @@ GPIO_INT(USB_C2_RT_INT_ODL, PIN(4, 1), GPIO_INT_BOTH, retimer_inter
GPIO(CCD_MODE_ODL, PIN(E, 5), GPIO_INPUT)
GPIO(CHARGER_VAP_OTG_EN, PIN(7, 3), GPIO_OUT_LOW)
GPIO(CPU_C10_GATE_L, PIN(6, 7), GPIO_INPUT)
-GPIO(EC_ACCEL_INT_R_L, PIN(8, 1), GPIO_INPUT | GPIO_SEL_1P8V)
GPIO(EC_ALS_RGB_INT_R_L, PIN(D, 4), GPIO_INPUT)
GPIO(EC_BATT_PRES_ODL, PIN(E, 1), GPIO_INPUT)
GPIO(EC_ENTERING_RW, PIN(0, 3), GPIO_OUT_LOW)
diff --git a/board/brya/sensors.c b/board/brya/sensors.c
index 4dffe00d7c..0478b308a2 100644
--- a/board/brya/sensors.c
+++ b/board/brya/sensors.c
@@ -4,8 +4,12 @@
*/
#include "common.h"
-
+#include "accelgyro.h"
#include "adc_chip.h"
+#include "driver/accel_lis2dw12.h"
+#include "driver/accelgyro_lsm6dso.h"
+#include "hooks.h"
+#include "motion_sense.h"
#include "temp_sensor.h"
#include "thermal.h"
#include "thermistor.h"
@@ -29,6 +33,124 @@ const struct adc_t adc_channels[] = {
};
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;
+
+/* TODO(b/184779333): 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 */
+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[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LIS2DW12,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &lis2dw12_drv,
+ .mutex = &g_lid_accel_mutex,
+ .drv_data = &g_lis2dw12_data,
+ .int_signal = GPIO_EC_ACCEL_INT_R_L,
+ .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,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 12500 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LSM6DSO,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &lsm6dso_drv,
+ .mutex = &g_base_accel_mutex,
+ .drv_data = &lsm6dso_data,
+ .int_signal = GPIO_EC_IMU_INT_R_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = LSM6DSO_ADDR0_FLAGS,
+ .rot_standard_ref = &base_standard_ref,
+ .default_range = 4, /* g */
+ .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,
+ },
+ },
+ },
+
+ [BASE_GYRO] = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_LSM6DSO,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &lsm6dso_drv,
+ .mutex = &g_base_accel_mutex,
+ .drv_data = &lsm6dso_data,
+ .int_signal = GPIO_EC_IMU_INT_R_L,
+ .flags = MOTIONSENSE_FLAG_INT_SIGNAL,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = LSM6DSO_ADDR0_FLAGS,
+ .default_range = 1000 | ROUND_UP_FLAG, /* 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,
+ },
+ },
+ },
+};
+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);
+}
+DECLARE_HOOK(HOOK_INIT, baseboard_sensors_init, HOOK_PRIO_INIT_I2C + 1);
+
/* Temperature sensor configuration */
const struct temp_sensor_t temp_sensors[] = {
[TEMP_SENSOR_1_DDR_SOC] = {