diff options
author | Scott Collyer <scollyer@google.com> | 2019-02-22 11:23:52 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-27 13:43:44 -0800 |
commit | 9ae31246174f914a22b2200595c1457c9c382f05 (patch) | |
tree | eb96f21e767edf6e30c83be3ac3d8646aca12199 | |
parent | a9ec276b2d3417518a46db8f703b6e0a2756a9f9 (diff) | |
download | chrome-ec-9ae31246174f914a22b2200595c1457c9c382f05.tar.gz |
hatch: Add support for OPT3001 ALS
This CL adds support for the OPT3001 to hatch.
BUG=b:124337208
BRANCH=none
TEST=Verfied that when shining phone light on sensor the numbers went
very high (~30k) and when covering sensor values dropped in low 100s.
Change-Id: I43842050273eb5c3e4e13d04a7ca679e5a875d91
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1483894
Commit-Ready: Scott Collyer <scollyer@chromium.org>
Tested-by: Scott Collyer <scollyer@chromium.org>
Tested-by: Zack Yang <zack_yang@compal.corp-partner.google.com>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
-rw-r--r-- | board/hatch/board.c | 35 | ||||
-rw-r--r-- | board/hatch/board.h | 10 |
2 files changed, 44 insertions, 1 deletions
diff --git a/board/hatch/board.c b/board/hatch/board.c index e936bb5cbf..cae726e504 100644 --- a/board/hatch/board.c +++ b/board/hatch/board.c @@ -10,6 +10,7 @@ #include "common.h" #include "driver/accel_bma2x2.h" #include "driver/accelgyro_bmi160.h" +#include "driver/als_opt3001.h" #include "driver/ppc/sn5s330.h" #include "ec_commands.h" #include "extpower.h" @@ -123,6 +124,12 @@ static struct bmi160_drv_data_t g_bmi160_data; /* BMA255 private data */ static struct accelgyro_saved_data_t g_bma255_data; +static struct opt3001_drv_data_t g_opt3001_data = { + .scale = 1, + .uscale = 0, + .offset = 0, +}; + /* Matrix to rotate accelrator into standard reference frame */ static const mat33_fp_t base_standard_ref = { { 0, FLOAT_TO_FP(1), 0}, @@ -211,9 +218,37 @@ struct motion_sensor_t motion_sensors[] = { .min_frequency = BMI160_GYRO_MIN_FREQ, .max_frequency = BMI160_GYRO_MAX_FREQ, }, + + [LID_ALS] = { + .name = "Light", + .active_mask = SENSOR_ACTIVE_S0_S3, + .chip = MOTIONSENSE_CHIP_OPT3001, + .type = MOTIONSENSE_TYPE_LIGHT, + .location = MOTIONSENSE_LOC_LID, + .drv = &opt3001_drv, + .drv_data = &g_opt3001_data, + .port = I2C_PORT_ACCEL, + .addr = OPT3001_I2C_ADDR, + .rot_standard_ref = NULL, + .default_range = 0x2b11a1, + .min_frequency = OPT3001_LIGHT_MIN_FREQ, + .max_frequency = OPT3001_LIGHT_MAX_FREQ, + .config = { + /* Run ALS sensor in S0 */ + [SENSOR_CONFIG_EC_S0] = { + .odr = 1000, + }, + }, + }, }; unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); +/* ALS instances when LPC mapping is needed. Each entry directs to a sensor. */ +const struct motion_sensor_t *motion_als_sensors[] = { + &motion_sensors[LID_ALS], +}; +BUILD_ASSERT(ARRAY_SIZE(motion_als_sensors) == ALS_COUNT); + /******************************************************************************/ /* Physical fans. These are logically separate from pwm_channels. */ diff --git a/board/hatch/board.h b/board/hatch/board.h index 3f5ac8322a..f5730cccec 100644 --- a/board/hatch/board.h +++ b/board/hatch/board.h @@ -30,16 +30,23 @@ #define CONFIG_PWM_KBLIGHT /* Sensors */ +/* BMI160 Base accel/gyro */ #define CONFIG_ACCEL_INTERRUPTS #define CONFIG_ACCELGYRO_BMI160 #define CONFIG_ACCELGYRO_BMI160_INT_EVENT TASK_EVENT_CUSTOM(4) #define CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT +/* BMA253 Lid accel */ #define CONFIG_ACCEL_BMA255 -#define CONFIG_ACCEL_FORCE_MODE_MASK (1 << LID_ACCEL) +#define CONFIG_ACCEL_FORCE_MODE_MASK ((1 << LID_ACCEL) | (1 << LID_ALS)) #define CONFIG_LID_ANGLE #define CONFIG_LID_ANGLE_SENSOR_BASE BASE_ACCEL #define CONFIG_LID_ANGLE_SENSOR_LID LID_ACCEL #define CONFIG_LID_ANGLE_UPDATE +/* OPT3001 ALS */ +#define CONFIG_ALS +#define ALS_COUNT 1 +#define CONFIG_ALS_OPT3001 +#define OPT3001_I2C_ADDR OPT3001_I2C_ADDR1 /* Fan features */ #define CONFIG_FANS 1 @@ -87,6 +94,7 @@ enum sensor_id { LID_ACCEL = 0, BASE_ACCEL, BASE_GYRO, + LID_ALS, SENSOR_COUNT, }; |