drivers: sensors: npcx_tach: Clear stale data

The tachometer collects the data continuously setting a "data ready" bit
when it's ready. The availability bit has to be cleared before the
register is updated.
The driver also supports underflow detection, when the bit indicating it
is set the reading of "0" is returned.
The problem here is that there is that once the underflow bit is cleared
we might end up reading stale data.
To prevent that clear the "data ready" bit when underflow is detected

Signed-off-by: Kornel Dulęba <mindal@semihalf.com>
This commit is contained in:
Kornel Dulęba 2023-05-29 09:48:29 +00:00 committed by Anas Nashif
commit 057888836e

View file

@ -259,6 +259,8 @@ int tach_npcx_sample_fetch(const struct device *dev, enum sensor_channel chan)
if (tach_npcx_is_underflow(dev)) {
/* Clear pending flags */
tach_npcx_clear_underflow_flag(dev);
/* Clear stale captured data */
tach_npcx_clear_captured_flag(dev);
data->capture = 0;
return 0;