summaryrefslogtreecommitdiff
path: root/driver/als_tcs3400.c
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@google.com>2019-12-10 22:39:02 -0800
committerCommit Bot <commit-bot@chromium.org>2019-12-12 20:01:50 +0000
commit18cb44fec23ed2c90d9f3b6e147ffbc326ffedca (patch)
treec851257a62efac18953ef7cafb342a427f2f7906 /driver/als_tcs3400.c
parentcced767b5ff670340197efef203a1369f94b2e96 (diff)
downloadchrome-ec-18cb44fec23ed2c90d9f3b6e147ffbc326ffedca.tar.gz
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 <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1959458 Tested-by: Mengqi Guo <mqg@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'driver/als_tcs3400.c')
-rw-r--r--driver/als_tcs3400.c25
1 files changed, 23 insertions, 2 deletions
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;