Skip to content

Commit

Permalink
hw/drivers/bme280: Fix writes to I2C
Browse files Browse the repository at this point in the history
I2C writes when driver was enabled clear MSB of register
address.

This prevented any write to control registers.

Now registers MSB is cleared on write only for SPI.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
  • Loading branch information
kasjer committed Sep 9, 2024
1 parent 23b6eeb commit 3e665f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions hw/drivers/sensors/bme280/include/bme280/bme280.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct bme280 {
struct bus_i2c_node i2c_node;
struct bus_spi_node spi_node;
};
bool node_is_spi;
#else
struct os_dev dev;
#endif
Expand Down
12 changes: 11 additions & 1 deletion hw/drivers/sensors/bme280/src/bme280.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ static const struct sensor_driver g_bme280_sensor_driver = {
bme280_sensor_get_config
};

#if MYNEWT_VAL(BUS_DRIVER_PRESENT)
static bool
bme280_uses_spi(struct sensor_itf *itf)
{
return ((struct bme280 *)(itf->si_dev))->node_is_spi;
}
#endif

static int
bme280_default_cfg(struct bme280_cfg *cfg)
{
Expand Down Expand Up @@ -901,7 +909,9 @@ bme280_writelen(struct sensor_itf *itf, uint8_t addr, uint8_t *payload,
return SYS_EINVAL;
}

addr &= ~BME280_SPI_READ_CMD_BIT;
if (bme280_uses_spi(itf)) {
addr &= ~BME280_SPI_READ_CMD_BIT;
}

rc = bus_node_write(dev, &addr, 1, OS_TIMEOUT_NEVER, BUS_F_NOSTOP);
if (rc) {
Expand Down

0 comments on commit 3e665f0

Please sign in to comment.