drivers: sensor: Added timeout for apds9960 sampling
Timeout occurs if status register does not register an interrupt Signed-off-by: Thomas Lang <thomaslang2003@me.com>
This commit is contained in:
parent
f38beeafba
commit
1a8b8f4220
@ -54,6 +54,9 @@ static int apds9960_sample_fetch(const struct device *dev,
|
||||
const struct apds9960_config *config = dev->config;
|
||||
struct apds9960_data *data = dev->data;
|
||||
uint8_t tmp;
|
||||
#ifdef CONFIG_APDS9960_FETCH_MODE_POLL
|
||||
int64_t start_time;
|
||||
#endif
|
||||
|
||||
if (chan != SENSOR_CHAN_ALL) {
|
||||
LOG_ERR("Unsupported sensor channel");
|
||||
@ -84,12 +87,16 @@ static int apds9960_sample_fetch(const struct device *dev,
|
||||
}
|
||||
|
||||
#ifdef CONFIG_APDS9960_FETCH_MODE_POLL
|
||||
start_time = k_uptime_get();
|
||||
#ifdef CONFIG_APDS9960_ENABLE_ALS
|
||||
while (!(tmp & APDS9960_STATUS_AINT)) {
|
||||
k_sleep(K_MSEC(APDS9960_DEFAULT_WAIT_TIME));
|
||||
if (i2c_reg_read_byte_dt(&config->i2c, APDS9960_STATUS_REG, &tmp)) {
|
||||
return -EIO;
|
||||
}
|
||||
if ((k_uptime_get() - start_time) > APDS9960_MAX_WAIT_TIME) {
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
#else
|
||||
while (!(tmp & APDS9960_STATUS_PINT)) {
|
||||
@ -97,6 +104,9 @@ static int apds9960_sample_fetch(const struct device *dev,
|
||||
if (i2c_reg_read_byte_dt(&config->i2c, APDS9960_STATUS_REG, &tmp)) {
|
||||
return -EIO;
|
||||
}
|
||||
if ((k_uptime_get() - start_time) > APDS9960_MAX_WAIT_TIME) {
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -214,6 +214,7 @@
|
||||
|
||||
/* Polling Wait Times (ms) */
|
||||
#define APDS9960_DEFAULT_WAIT_TIME 2.78
|
||||
#define APDS9960_MAX_WAIT_TIME 10000
|
||||
|
||||
struct apds9960_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user