summaryrefslogtreecommitdiff
path: root/include/accelgyro.h
diff options
context:
space:
mode:
authorNick Vaccaro <nvaccaro@google.com>2019-05-07 15:23:03 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-20 16:31:46 +0000
commit72c142d8a751089baac1f042d6a199e49daa32d0 (patch)
treee5ebf12bb8e3edb4e1b3ecb8352888028e8d9ca8 /include/accelgyro.h
parent6d8a5d3f207af7481e2aa114d306f8448d21b74f (diff)
downloadchrome-ec-72c142d8a751089baac1f042d6a199e49daa32d0.tar.gz
driver/tcs3400: add auto-compensation for saturation
Making settings more sensitive makes the SNR better, so this algorithm strives to keep the output level as close to 90% saturation as possible. Adds calibration mode and lux calculation. Removes unused last_value field from the tcs3400_rgb_drv_data_t structure, we use raw_xyz field in motion_sensor_t struct instead. BUG=b:124512628 BRANCH=master TEST=Flash and boot flapjack, verify that ALS and RGB sensors are still generating data. I used alslog patch and enabled ALS logging in EC console via "alslog 1023". Verify that under a constant light source, the adjustment mechanism correctly drives the ALS values such that they land in the sweet spot between 90 to <100% of saturation. Cq-Depend: chromium:1711958,chromium:1702543 Change-Id: Ibf260a990fe285cb54ee94c1ebe8aa85ea10affc Signed-off-by: Nick Vaccaro <nvaccaro@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1633269 Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Diffstat (limited to 'include/accelgyro.h')
-rw-r--r--include/accelgyro.h41
1 files changed, 36 insertions, 5 deletions
diff --git a/include/accelgyro.h b/include/accelgyro.h
index 65a09b1965..2f1131c9f5 100644
--- a/include/accelgyro.h
+++ b/include/accelgyro.h
@@ -151,6 +151,23 @@ struct accelgyro_drv {
#endif
};
+/* Index values for rgb_calibration_t.coeff array */
+enum xyz_coeff_index {
+ TCS_CLEAR_COEFF_IDX = 0,
+ TCS_RED_COEFF_IDX,
+ TCS_GREEN_COEFF_IDX,
+ TCS_BLUE_COEFF_IDX,
+ COEFF_CHANNEL_COUNT,
+};
+
+/* Index values for rgb_scale array */
+enum rgb_index {
+ RED_RGB_IDX = 0,
+ GREEN_RGB_IDX,
+ BLUE_RGB_IDX,
+ RGB_CHANNEL_COUNT
+};
+
/* Used to save sensor information */
struct accelgyro_saved_data_t {
int odr;
@@ -158,6 +175,14 @@ struct accelgyro_saved_data_t {
uint16_t scale[3];
};
+/* individual channel cover scaling and k factors */
+struct als_channel_scale_t {
+ uint16_t k_channel_scale;
+
+ /* Cover compensation scale factor */
+ uint16_t cover_scale;
+};
+
/* Calibration data */
struct als_calibration_t {
/*
@@ -169,18 +194,21 @@ struct als_calibration_t {
uint16_t scale;
uint16_t uscale;
int16_t offset;
+ struct als_channel_scale_t channel_scale;
};
/* RGB ALS Calibration Data */
struct rgb_calibration_t {
/*
- * Each channel has a scaling factor for normalization, representing
- * a value between 0 and 2 (1 is translated as 1 << 15)
+ * Each channel has scaling factor for normalization & cover
*/
- uint16_t scale;
+ struct als_channel_scale_t scale;
/* Any offset to add to raw channel data */
int16_t offset;
+
+ /* Clear, R, G, and B coefficients for this channel */
+ fp_t coeff[COEFF_CHANNEL_COUNT];
};
/* als driver data */
@@ -190,10 +218,13 @@ struct als_drv_data_t {
struct als_calibration_t als_cal; /* calibration data */
};
+#define SENSOR_APPLY_DIV_SCALE(_input, _scale) \
+ (((_input) * (uint64_t)MOTION_SENSE_DEFAULT_SCALE) / (_scale))
+
#define SENSOR_APPLY_SCALE(_input, _scale) \
- (((_input) * (_scale)) / MOTION_SENSE_DEFAULT_SCALE)
+ (((_input) * (uint64_t)(_scale)) / MOTION_SENSE_DEFAULT_SCALE)
/* Individual channel scale value between 0 and 2 represented in 16 bits */
-#define ALS_CHANNEL_SCALE(_x) ((_x) << 15)
+#define ALS_CHANNEL_SCALE(_x) ((_x) * MOTION_SENSE_DEFAULT_SCALE)
#endif /* __CROS_EC_ACCELGYRO_H */