sensor: bme280: check status before sleeping

Check the status register immediately, instead of waiting 3ms for the
first check.

Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
Jordan Yates 2024-09-05 12:40:08 +10:00 committed by Carles Cufí
parent 22c2fe52dc
commit ecfb4c7628
1 changed files with 8 additions and 5 deletions

View File

@ -118,17 +118,20 @@ static uint32_t bme280_compensate_humidity(struct bme280_data *data,
static int bme280_wait_until_ready(const struct device *dev)
{
uint8_t status = 0;
uint8_t status;
int ret;
/* Wait for NVM to copy and measurement to be completed */
do {
k_sleep(K_MSEC(3));
/* Wait for relevant flags to clear */
while (1) {
ret = bme280_reg_read(dev, BME280_REG_STATUS, &status, 1);
if (ret < 0) {
return ret;
}
} while (status & (BME280_STATUS_MEASURING | BME280_STATUS_IM_UPDATE));
if (!(status & (BME280_STATUS_MEASURING | BME280_STATUS_IM_UPDATE))) {
break;
}
k_sleep(K_MSEC(3));
}
return 0;
}