summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZick Wei <zick.wei@quanta.corp-partner.google.com>2021-04-08 10:44:00 +0800
committerCommit Bot <commit-bot@chromium.org>2021-04-13 00:24:46 +0000
commit4d6a1750c679e15214f4938fb7de7cfbdde6103d (patch)
tree8d33169dbbd71cb215a3efe1147d4ab69201edff
parent163b7cb43d612663ad2365d19e1832a47ff6b0a0 (diff)
downloadchrome-ec-4d6a1750c679e15214f4938fb7de7cfbdde6103d.tar.gz
dooly: update ALS lux equation
The previous equation in CL:2771482, would cause lux = 0 on some ALS board in specific ambient light , we worked with vendor and update the lux equation: Lux = LuxScalar * (DGFn * ((C * Ccoefn) + (R * Rcoefn) + (G * Gcoefn) + (B * Bcoefn)) / (Atime*Again)) Lux = MAX(0, Lux) If (G+B)/C < 0.692 n=1 If (G+B)/C >= 0.692 and < 1.012 n=2 else n=3 LuxScalar = 1.00 Coeffs n=1(Lo) n=2(Med) n=3(Hi) Ccoef 0.009 0.202 -0.661 Rcoef 0.056 - 1.1 1.334 GCoef 2.735 8.692 1.095 BCoef -1.903 -7.068 -1.821 DGF 799.797 801.347 795.574 BUG=b:184238881 BRANCH=puff TEST=verify equation works as intended. Signed-off-by: Zick Wei <zick.wei@quanta.corp-partner.google.com> Change-Id: Ic9e41579c37544496f54a4faeb1a0d0aeea8f7c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2822388 Reviewed-by: Andrew McRae <amcrae@chromium.org> Commit-Queue: Andrew McRae <amcrae@chromium.org>
-rw-r--r--board/dooly/board.c68
1 files changed, 29 insertions, 39 deletions
diff --git a/board/dooly/board.c b/board/dooly/board.c
index 0cbf2938c0..241fa67a2a 100644
--- a/board/dooly/board.c
+++ b/board/dooly/board.c
@@ -187,65 +187,55 @@ DECLARE_DEFERRED(power_monitor);
__override void tcs3400_translate_to_xyz(struct motion_sensor_t *s,
int32_t *crgb_data, int32_t *xyz_data)
{
- int n, cur_gain, dgf;
+ int n, cur_gain;
fp_t n_interval;
- fp_t integration_time_us;
+ int integration_time_us;
struct tcs_saturation_t *sat_p =
&(TCS3400_RGB_DRV_DATA(s+1)->saturation);
cur_gain = (1 << (2 * sat_p->again));
integration_time_us =
- (tcs3400_get_integration_time(sat_p->atime));
+ tcs3400_get_integration_time(sat_p->atime);
/* n_interval = (G+B)/C, to use different coefficient*/
- n_interval = INT_TO_FP(crgb_data[2]+crgb_data[3])/crgb_data[0];
-
- dgf = 993; /* Device and Glass Factor */
+ if (crgb_data[0] != 0)
+ n_interval = INT_TO_FP(crgb_data[2]+crgb_data[3])/crgb_data[0];
+ else
+ n_interval = FLOAT_TO_FP(0.692); /* set default n = 2 */
- if (n_interval < FLOAT_TO_FP(0.514))
+ if (n_interval < FLOAT_TO_FP(0.692))
n = 1;
- else if (n_interval >= FLOAT_TO_FP(0.514) &&
- n_interval < FLOAT_TO_FP(0.66))
+ else if (n_interval >= FLOAT_TO_FP(0.692) &&
+ n_interval < FLOAT_TO_FP(1.012))
n = 2;
- else if (n_interval >= FLOAT_TO_FP(0.66) &&
- n_interval < FLOAT_TO_FP(1.012))
- n = 3;
else
- n = 4;
+ n = 3;
switch (n) {
case 1:
- xyz_data[1] = (fp_inter_t)(FP_TO_INT(dgf *
- (crgb_data[0]*(fp_inter_t)FLOAT_TO_FP(3.8) +
- crgb_data[1]*(fp_inter_t)FLOAT_TO_FP(3.956) +
- crgb_data[2]*(fp_inter_t)FLOAT_TO_FP(-20.915) +
- crgb_data[3]*(fp_inter_t)FLOAT_TO_FP(3.281))))*1000 /
- (integration_time_us*cur_gain);
+ xyz_data[1] = FP_TO_INT(fp_mul(FLOAT_TO_FP(799.797),
+ (fp_mul(INT_TO_FP(crgb_data[0]), FLOAT_TO_FP(0.009)) +
+ fp_mul(INT_TO_FP(crgb_data[1]), FLOAT_TO_FP(0.056)) +
+ fp_mul(INT_TO_FP(crgb_data[2]), FLOAT_TO_FP(2.735)) +
+ fp_mul(INT_TO_FP(crgb_data[3]), FLOAT_TO_FP(-1.903))) /
+ (integration_time_us * cur_gain / 1000ULL)));
break;
case 2:
- xyz_data[1] = (fp_inter_t)(FP_TO_INT(dgf *
- (crgb_data[0]*(fp_inter_t)FLOAT_TO_FP(-17.436) +
- crgb_data[1]*(fp_inter_t)FLOAT_TO_FP(14.535) +
- crgb_data[2]*(fp_inter_t)FLOAT_TO_FP(32.07) +
- crgb_data[3]*(fp_inter_t)FLOAT_TO_FP(2.43))))*1000 /
- (integration_time_us*cur_gain);
+ xyz_data[1] = FP_TO_INT(fp_mul(FLOAT_TO_FP(801.347),
+ (fp_mul(INT_TO_FP(crgb_data[0]), FLOAT_TO_FP(0.202)) +
+ fp_mul(INT_TO_FP(crgb_data[1]), FLOAT_TO_FP(-1.1)) +
+ fp_mul(INT_TO_FP(crgb_data[2]), FLOAT_TO_FP(8.692)) +
+ fp_mul(INT_TO_FP(crgb_data[3]), FLOAT_TO_FP(-7.068))) /
+ (integration_time_us * cur_gain / 1000ULL)));
break;
case 3:
- xyz_data[1] = (fp_inter_t)(FP_TO_INT(dgf *
- (crgb_data[0]*(fp_inter_t)FLOAT_TO_FP(0.08) +
- crgb_data[1]*(fp_inter_t)FLOAT_TO_FP(-0.89) +
- crgb_data[2]*(fp_inter_t)FLOAT_TO_FP(7.096) +
- crgb_data[3]*(fp_inter_t)FLOAT_TO_FP(-5.603))))*1000 /
- (integration_time_us*cur_gain);
- break;
- case 4:
- xyz_data[1] = (fp_inter_t)(FP_TO_INT(dgf *
- (crgb_data[0]*(fp_inter_t)FLOAT_TO_FP(-0.686) +
- crgb_data[1]*(fp_inter_t)FLOAT_TO_FP(1.224) +
- crgb_data[2]*(fp_inter_t)FLOAT_TO_FP(4.043) +
- crgb_data[3]*(fp_inter_t)FLOAT_TO_FP(-4.584))))*1000 /
- (integration_time_us*cur_gain);
+ xyz_data[1] = FP_TO_INT(fp_mul(FLOAT_TO_FP(795.574),
+ (fp_mul(INT_TO_FP(crgb_data[0]), FLOAT_TO_FP(-0.661)) +
+ fp_mul(INT_TO_FP(crgb_data[1]), FLOAT_TO_FP(1.334)) +
+ fp_mul(INT_TO_FP(crgb_data[2]), FLOAT_TO_FP(1.095)) +
+ fp_mul(INT_TO_FP(crgb_data[3]), FLOAT_TO_FP(-1.821))) /
+ (integration_time_us * cur_gain / 1000ULL)));
break;
default:
break;