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
This commit is contained in:
Gwendal Grignou
2016-05-30 18:31:33 -07:00
committed by chrome-bot
parent d831100df9
commit 1536bd5c62

View File

@@ -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;
}