From 4becd0468c3626e614ef935062445c62e3641754 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Fri, 22 Mar 2019 11:00:39 -0600 Subject: board: arcada_ish: add lis2mdl magnetometer BRANCH=None BUG=b:128619310 TEST=Validated that iio:device4 is present TEST=Validate that cat **/iio:device4/in_magn_*_raw prints correct values TEST=Ran some CTS tests and verified magnetometer tests pass. TEST=Opened an android compass app and raw magnetometer reading app and verified that data is correct. Change-Id: I79ff5ba8de12686d61e7701ac83689924c4de6c4 Signed-off-by: Yuval Peress Reviewed-on: https://chromium-review.googlesource.com/1535428 Commit-Ready: Jack Rosenthal Reviewed-by: Jack Rosenthal Reviewed-by: Mathew King Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1609607 Reviewed-by: Jett Rink Commit-Queue: Jett Rink Tested-by: Jett Rink --- board/arcada_ish/board.c | 21 ++++++++++++++++++++- board/arcada_ish/board.h | 14 ++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/board/arcada_ish/board.c b/board/arcada_ish/board.c index 8b939e9a61..025006b5a0 100644 --- a/board/arcada_ish/board.c +++ b/board/arcada_ish/board.c @@ -8,6 +8,7 @@ #include "console.h" #include "driver/accel_lis2dh.h" #include "driver/accelgyro_lsm6dsm.h" +#include "driver/mag_lis2mdl.h" #include "gpio.h" #include "hooks.h" #include "host_command.h" @@ -32,11 +33,13 @@ const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); /* Sensor config */ static struct mutex g_lid_mutex; +static struct mutex g_lid_mag_mutex; static struct mutex g_base_mutex; /* sensor private data */ static struct lsm6dsm_data lsm6dsm_a_data; static struct stprivate_data g_lis2dh_data; +static struct lis2mdl_private_data lis2mdl_a_data; /* Matrix to rotate lid sensor into standard reference frame */ const mat33_fp_t lid_rot_ref = { @@ -121,8 +124,24 @@ struct motion_sensor_t motion_sensors[] = { }, }, - /* TODO(b/122281217): Add remain sensors */ + [LID_MAG] = { + .name = "Lid Mag", + .active_mask = SENSOR_ACTIVE_S0, + .chip = MOTIONSENSE_CHIP_LIS2MDL, + .type = MOTIONSENSE_TYPE_MAG, + .location = MOTIONSENSE_LOC_LID, + .drv = &lis2mdl_drv, + .mutex = &g_lid_mag_mutex, + .drv_data = &lis2mdl_a_data, + .port = I2C_PORT_SENSOR, + .addr = LIS2MDL_ADDR, + .default_range = 1 << 11, /* 16LSB / uT, fixed */ + .rot_standard_ref = NULL, /* TODO rotate correctly */ + .min_frequency = LIS2MDL_ODR_MIN_VAL, + .max_frequency = LIS2MDL_ODR_MAX_VAL, + }, }; + const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); /* Initialize board. */ diff --git a/board/arcada_ish/board.h b/board/arcada_ish/board.h index 4dc4f89abb..26592923fc 100644 --- a/board/arcada_ish/board.h +++ b/board/arcada_ish/board.h @@ -25,14 +25,20 @@ #define CONFIG_I2C #define CONFIG_I2C_MASTER -#define CONFIG_ACCEL_LNG2DM /* Base sensor: LNG2DM (uses LIS2DH driver) */ -#define CONFIG_ACCELGYRO_LSM6DSM /* Lid sensor: LSM6DS3 (uses LSM6DSM driver) */ +#define CONFIG_ACCEL_LNG2DM /* Base sensor: LNG2DM + * (uses LIS2DH driver) + */ +#define CONFIG_ACCELGYRO_LSM6DSM /* Lid sensor: LSM6DS3 + * (uses LSM6DSM driver) + */ +#define CONFIG_MAG_LIS2MDL /* Lid sensor: LIS2DML */ +#define CONFIG_MAG_CALIBRATE #define CONFIG_ACCEL_INTERRUPTS #define CONFIG_ACCEL_FIFO 256 #define CONFIG_ACCEL_FIFO_THRES (CONFIG_ACCEL_FIFO / 3) /* Sensors without hardware FIFO are in forced mode */ -#define CONFIG_ACCEL_FORCE_MODE_MASK (1 << BASE_ACCEL) +#define CONFIG_ACCEL_FORCE_MODE_MASK (BIT(BASE_ACCEL) | BIT(LID_MAG)) #define CONFIG_ACCEL_LSM6DSM_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL) @@ -106,7 +112,7 @@ enum sensor_id { LID_ACCEL, LID_GYRO, BASE_ACCEL, - /* TODO(b/122281217): Add remain sensors */ + LID_MAG, SENSOR_COUNT }; -- cgit v1.2.1