From 18cb44fec23ed2c90d9f3b6e147ffbc326ffedca Mon Sep 17 00:00:00 2001 From: Nick Vaccaro Date: Tue, 10 Dec 2019 22:39:02 -0800 Subject: drivers/tcs3400: don't add offset for LUX When translating RGB to XYZ, don't add in the offset value for LUX. BUG=b:144319657 BRANCH=NONE TEST="make -j BOARD=kohaku", flash EC on kohaku, place kohaku in a dark location and verify it reads 0. Change-Id: I4c6dcc01999ca5e4390f97c31e50b27075ed9ce4 Signed-off-by: Nick Vaccaro Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1959458 Tested-by: Mengqi Guo Reviewed-by: Gwendal Grignou --- driver/als_tcs3400.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'driver/als_tcs3400.c') diff --git a/driver/als_tcs3400.c b/driver/als_tcs3400.c index 651f319589..6deb584976 100644 --- a/driver/als_tcs3400.c +++ b/driver/als_tcs3400.c @@ -362,6 +362,20 @@ static void tcs3400_process_raw_data(struct motion_sensor_t *s, } } +static int32_t get_lux_from_xyz(struct motion_sensor_t *s, int32_t *xyz_data) +{ + int32_t lux = xyz_data[Y]; + const int32_t offset = + TCS3400_RGB_DRV_DATA(s+1)->calibration.rgb_cal[Y].offset; + + /* + * Do not include the offset when determining LUX from XYZ. + */ + lux = MAX(0, lux - offset); + + return lux; +} + static int tcs3400_post_events(struct motion_sensor_t *s, uint32_t last_ts) { /* @@ -378,6 +392,7 @@ static int tcs3400_post_events(struct motion_sensor_t *s, uint32_t last_ts) int retries = 20; /* 400 ms max */ int *last_v = s->raw_xyz; int32_t data = 0; + int32_t lux; int i, ret = EC_SUCCESS; /* Make sure data is valid */ @@ -405,13 +420,19 @@ static int tcs3400_post_events(struct motion_sensor_t *s, uint32_t last_ts) /* Process the raw light data, adjusting for scale and calibration */ tcs3400_process_raw_data(s, buf, raw_data, xyz_data); + /* get lux value */ + if (calibration_mode) + lux = xyz_data[Y]; + else + lux = get_lux_from_xyz(s, xyz_data); + /* if clear channel data changed, send illuminance upstream */ if ((raw_data[CLEAR_CRGB_IDX] != TCS_SATURATION_LEVEL) && - (last_v[X] != xyz_data[Y])) { + (last_v[X] != lux)) { if (calibration_mode) last_v[X] = raw_data[CLEAR_CRGB_IDX]; else - last_v[X] = xyz_data[Y]; + last_v[X] = lux; vector.flags = 0; vector.data[X] = last_v[X]; vector.data[Y] = 0; -- cgit v1.2.1