diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2016-05-30 18:31:33 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-06-17 07:36:34 -0700 |
commit | 1536bd5c62126e3dd67c92e53b239e405eddb860 (patch) | |
tree | 2be80aff6715c4c354775cd621deafc7a98a75a1 /driver | |
parent | d831100df926df2e1d987fc64e6ac6733989ad91 (diff) | |
download | chrome-ec-1536bd5c62126e3dd67c92e53b239e405eddb860.tar.gz |
driver: si114x: Handle overflow properly.
Overflow happens when raw value from ADC is greater than 0x7FFF.
When it happens, skip the result.
BRANCH=ryu,jerry
TEST=Without this code, the proximity sensor would show 22000in
instead of staying close to 0 when thumb is near sensor.
BUG=chrome-os-partner:53851
Change-Id: Id2182acbbf7b00157d9fee5d28bb61df4f166246
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/348300
Diffstat (limited to 'driver')
-rw-r--r-- | driver/als_si114x.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/driver/als_si114x.c b/driver/als_si114x.c index b9c6e5ecc5..9d9b87006c 100644 --- a/driver/als_si114x.c +++ b/driver/als_si114x.c @@ -100,21 +100,25 @@ static int si114x_read_results(struct motion_sensor_t *s, int nb) &val); if (ret) break; - /* Add offset, calibration */ - if (val + type_data->offset <= 0) { + if (val == SI114X_OVERFLOW) { + /* overflowing, try next time. */ + return EC_SUCCESS; + } else if (val + type_data->offset <= 0) { + /* No light */ val = 1; - } else if (val != SI114X_OVERFLOW) { + } else { + /* Add offset, calibration */ val += type_data->offset; - /* - * Proxmitiy sensor data is inverse of the distance. - * Return back something proportional to distance, - * we affine with the scale parmeter. - */ - if (s->type == MOTIONSENSE_TYPE_PROX) - val = SI114X_PS_INVERSION(val); - val = val * type_data->scale + - val * type_data->uscale / 10000; } + /* + * Proximity sensor data is inverse of the distance. + * Return back something proportional to distance, + * we correct later with the scale parameter. + */ + if (s->type == MOTIONSENSE_TYPE_PROX) + val = SI114X_PS_INVERSION(val); + val = val * type_data->scale + + val * type_data->uscale / 10000; s->raw_xyz[i] = val; } |