From 9a59d3051715feb26e0b6868c14e445f117862fb Mon Sep 17 00:00:00 2001 From: Leonard Pollak Date: Tue, 17 Aug 2021 16:24:24 +0200 Subject: [PATCH] drivers: sensor: SHT4X: convert to `i2c_dt_spec` Convert sht4x driver to `struct i2c_dt_spec`. Signed-off-by: Leonard Pollak --- drivers/sensor/sht4x/sht4x.c | 9 ++++----- drivers/sensor/sht4x/sht4x.h | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/sensor/sht4x/sht4x.c b/drivers/sensor/sht4x/sht4x.c index b1de6205697..9b66c8cb12c 100644 --- a/drivers/sensor/sht4x/sht4x.c +++ b/drivers/sensor/sht4x/sht4x.c @@ -34,7 +34,7 @@ static int sht4x_write_command(const struct device *dev, uint8_t cmd) const struct sht4x_config *cfg = dev->config; uint8_t tx_buf[1] = { cmd }; - return i2c_write(cfg->bus, tx_buf, sizeof(tx_buf), cfg->i2c_addr); + return i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf)); } static int sht4x_read_sample(const struct device *dev, @@ -45,7 +45,7 @@ static int sht4x_read_sample(const struct device *dev, uint8_t rx_buf[6]; int rc; - rc = i2c_read(cfg->bus, rx_buf, sizeof(rx_buf), cfg->i2c_addr); + rc = i2c_read_dt(&cfg->bus, rx_buf, sizeof(rx_buf)); if (rc < 0) { LOG_ERR("Failed to read data from device."); return rc; @@ -185,7 +185,7 @@ static int sht4x_init(const struct device *dev) const struct sht4x_config *cfg = dev->config; int rc = 0; - if (!device_is_ready(cfg->bus)) { + if (!device_is_ready(cfg->bus.bus)) { LOG_ERR("Device not ready."); return -ENODEV; } @@ -212,8 +212,7 @@ static const struct sensor_driver_api sht4x_api = { static struct sht4x_data sht4x_data_##n; \ \ static const struct sht4x_config sht4x_config_##n = { \ - .bus = DEVICE_DT_GET(DT_INST_BUS(n)), \ - .i2c_addr = DT_INST_REG_ADDR(n), \ + .bus = I2C_DT_SPEC_INST_GET(n), \ .repeatability = DT_INST_PROP(n, repeatability) \ }; \ \ diff --git a/drivers/sensor/sht4x/sht4x.h b/drivers/sensor/sht4x/sht4x.h index bee3beaf9e4..80dd0c47a1a 100644 --- a/drivers/sensor/sht4x/sht4x.h +++ b/drivers/sensor/sht4x/sht4x.h @@ -25,8 +25,7 @@ #define SHT4X_CRC_INIT 0xFF struct sht4x_config { - const struct device *bus; - uint8_t i2c_addr; + struct i2c_dt_spec bus; uint8_t repeatability; };