summaryrefslogtreecommitdiff
path: root/board/guybrush
diff options
context:
space:
mode:
authorMatt_Wang <Matt_Wang@compal.corp-partner.google.com>2021-03-24 15:04:33 +0800
committerCommit Bot <commit-bot@chromium.org>2021-04-12 14:18:57 +0000
commit617fbe0894d436dc49587a53a5f5e5f808fbc524 (patch)
tree3845262b639f613fc00f5c7165f47ff6449f4c02 /board/guybrush
parent404eb20677dff653e2f5d511b450934441e3c87d (diff)
downloadchrome-ec-617fbe0894d436dc49587a53a5f5e5f808fbc524.tar.gz
Guybrush: initial BMI160 sensor
Initial base BMI160 sensor. BUG=b:178213305 BRANCH=none TEST=make -j BOARD=guybrush TEST=can read the sensor data in ec console by i2cxfer. Signed-off-by: Matt_Wang <Matt_Wang@compal.corp-partner.google.com> Change-Id: Id49ff98dc921ba173b24f3c389fcfbde337ce77c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2783514 Tested-by: Matt Wang <matt_wang@compal.corp-partner.google.com> Reviewed-by: Bhanu Prakash Maiya <bhanumaiya@google.com> Reviewed-by: Rob Barnes <robbarnes@google.com> Commit-Queue: Rob Barnes <robbarnes@google.com>
Diffstat (limited to 'board/guybrush')
-rw-r--r--board/guybrush/board.c76
-rw-r--r--board/guybrush/board.h13
-rw-r--r--board/guybrush/ec.tasklist3
3 files changed, 91 insertions, 1 deletions
diff --git a/board/guybrush/board.c b/board/guybrush/board.c
index dba67d36bd..85861a9995 100644
--- a/board/guybrush/board.c
+++ b/board/guybrush/board.c
@@ -7,6 +7,8 @@
#include "button.h"
#include "common.h"
+#include "driver/accelgyro_bmi_common.h"
+#include "driver/accelgyro_bmi160.h"
#include "driver/retimer/ps8818.h"
#include "extpower.h"
#include "gpio.h"
@@ -20,6 +22,67 @@
#include "gpio_list.h" /* Must come after other header files. */
+/* Lid Sensor mutex */
+static struct mutex g_base_mutex;
+
+/* Lid accel private data */
+static struct bmi_drv_data_t g_bmi160_data;
+
+/* Matrix to rotate accelrator into standard reference frame */
+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[] = {
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI_ACCEL_MIN_FREQ,
+ .max_frequency = BMI_ACCEL_MAX_FREQ,
+ .default_range = 4, /* g, to meet CDD 7.3.1/C-1-4 reqs */
+ .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,
+ .ec_rate = 0,
+ },
+ },
+ },
+ [BASE_GYRO] = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI160,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi160_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi160_data,
+ .port = I2C_PORT_SENSOR,
+ .i2c_spi_addr_flags = BMI160_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
+ },
+};
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
static void board_init(void)
{
/* TODO */
@@ -101,3 +164,16 @@ __override int board_c1_ps8818_mux_set(const struct usb_mux *me,
return rv;
}
+
+void motion_interrupt(enum gpio_signal signal)
+{
+ switch (signal) {
+ case GPIO_3AXIS_INT_L:
+ /* TODO */
+ break;
+ case GPIO_6AXIS_INT_L:
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
+}
diff --git a/board/guybrush/board.h b/board/guybrush/board.h
index 8a4a51e549..93b718e198 100644
--- a/board/guybrush/board.h
+++ b/board/guybrush/board.h
@@ -16,6 +16,16 @@
/* Keyboard features */
/* Sensors */
+#define CONFIG_ACCELGYRO_BMI160
+#define CONFIG_ACCELGYRO_BMI160_INT_EVENT \
+ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL)
+#define CONFIG_ACCEL_INTERRUPTS
+#define I2C_PORT_ACCEL I2C_PORT_SENSOR
+
+/* EC console commands */
+#define CONFIG_CMD_ACCELS
+#define CONFIG_CMD_ACCEL_INFO
+#define CONFIG_CMD_BUTTON
/* USB Type C and USB PD defines */
@@ -32,6 +42,9 @@
#include "gpio_signal.h"
#include "registers.h"
+/* Motion sensor interrupt */
+void motion_interrupt(enum gpio_signal signal);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/guybrush/ec.tasklist b/board/guybrush/ec.tasklist
index 2dc9c26ec2..cb9b34a3cf 100644
--- a/board/guybrush/ec.tasklist
+++ b/board/guybrush/ec.tasklist
@@ -9,4 +9,5 @@
#include "base_ec.tasklist"
-#define CONFIG_TASK_LIST BASEBOARD_CONFIG_TASK_LIST
+#define CONFIG_TASK_LIST BASEBOARD_CONFIG_TASK_LIST \
+ TASK_ALWAYS(MOTIONSENSE, motion_sense_task, NULL, TASK_STACK_SIZE)