Skip to content

Commit

Permalink
sensor: bme680: only read compensation params once
Browse files Browse the repository at this point in the history
Only read the compensation parameters from the chip on first power up,
as they are static on the device.

Signed-off-by: Jordan Yates <jordan@embeint.com>
  • Loading branch information
JordanYates authored and carlescufi committed Sep 10, 2024
1 parent 5953a26 commit 632d6b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/sensor/bosch/bme680/bme680.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ static int bme680_read_compensation(const struct device *dev)
uint8_t buff[BME680_LEN_COEFF_ALL];
int err = 0;

if (data->has_read_compensation) {
return 0;
}

err = bme680_reg_read(dev, BME680_REG_COEFF1, buff, BME680_LEN_COEFF1);
if (err < 0) {
return err;
Expand Down Expand Up @@ -373,6 +377,7 @@ static int bme680_read_compensation(const struct device *dev)
data->res_heat_range = ((buff[39] & BME680_MSK_RH_RANGE) >> 4);
data->range_sw_err = ((int8_t)(buff[41] & BME680_MSK_RANGE_SW_ERR)) / 16;

data->has_read_compensation = true;
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions drivers/sensor/bosch/bme680/bme680.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct bme680_data {
uint8_t res_heat_range;
int8_t res_heat_val;
int8_t range_sw_err;
bool has_read_compensation;

/* Calculated sensor values. */
int32_t calc_temp;
Expand Down

0 comments on commit 632d6b9

Please sign in to comment.