drivers: sensor: SGP40: convert to i2c_dt_spec
Convert sgp40 driver to `struct i2c_dt_spec`. Signed-off-by: Leonard Pollak <leonardp@tr-host.de>
This commit is contained in:
parent
13d9b5c2ed
commit
adc5604c5c
2 changed files with 7 additions and 11 deletions
|
@ -36,8 +36,7 @@ static int sgp40_write_command(const struct device *dev, uint16_t cmd)
|
||||||
|
|
||||||
sys_put_be16(cmd, tx_buf);
|
sys_put_be16(cmd, tx_buf);
|
||||||
|
|
||||||
return i2c_write(cfg->bus, tx_buf, sizeof(tx_buf),
|
return i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf));
|
||||||
cfg->i2c_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sgp40_start_measurement(const struct device *dev)
|
static int sgp40_start_measurement(const struct device *dev)
|
||||||
|
@ -50,8 +49,7 @@ static int sgp40_start_measurement(const struct device *dev)
|
||||||
sys_put_be24(sys_get_be24(data->rh_param), &tx_buf[2]);
|
sys_put_be24(sys_get_be24(data->rh_param), &tx_buf[2]);
|
||||||
sys_put_be24(sys_get_be24(data->t_param), &tx_buf[5]);
|
sys_put_be24(sys_get_be24(data->t_param), &tx_buf[5]);
|
||||||
|
|
||||||
return i2c_write(cfg->bus, tx_buf, sizeof(tx_buf),
|
return i2c_write_dt(&cfg->bus, tx_buf, sizeof(tx_buf));
|
||||||
cfg->i2c_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sgp40_attr_set(const struct device *dev,
|
static int sgp40_attr_set(const struct device *dev,
|
||||||
|
@ -110,7 +108,7 @@ static int sgp40_selftest(const struct device *dev)
|
||||||
|
|
||||||
k_sleep(K_MSEC(SGP40_TEST_WAIT_MS));
|
k_sleep(K_MSEC(SGP40_TEST_WAIT_MS));
|
||||||
|
|
||||||
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) {
|
if (rc < 0) {
|
||||||
LOG_ERR("Failed to read data sample.");
|
LOG_ERR("Failed to read data sample.");
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -151,7 +149,7 @@ static int sgp40_sample_fetch(const struct device *dev,
|
||||||
|
|
||||||
k_sleep(K_MSEC(SGP40_MEASURE_WAIT_MS));
|
k_sleep(K_MSEC(SGP40_MEASURE_WAIT_MS));
|
||||||
|
|
||||||
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) {
|
if (rc < 0) {
|
||||||
LOG_ERR("Failed to read data sample.");
|
LOG_ERR("Failed to read data sample.");
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -211,7 +209,7 @@ static int sgp40_init(const struct device *dev)
|
||||||
const struct sgp40_config *cfg = dev->config;
|
const struct sgp40_config *cfg = dev->config;
|
||||||
struct sensor_value comp_data;
|
struct sensor_value comp_data;
|
||||||
|
|
||||||
if (!device_is_ready(cfg->bus)) {
|
if (!device_is_ready(cfg->bus.bus)) {
|
||||||
LOG_ERR("Device not ready.");
|
LOG_ERR("Device not ready.");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
@ -250,8 +248,7 @@ static const struct sensor_driver_api sgp40_api = {
|
||||||
static struct sgp40_data sgp40_data_##n; \
|
static struct sgp40_data sgp40_data_##n; \
|
||||||
\
|
\
|
||||||
static const struct sgp40_config sgp40_config_##n = { \
|
static const struct sgp40_config sgp40_config_##n = { \
|
||||||
.bus = DEVICE_DT_GET(DT_INST_BUS(n)), \
|
.bus = I2C_DT_SPEC_INST_GET(n), \
|
||||||
.i2c_addr = DT_INST_REG_ADDR(n), \
|
|
||||||
.selftest = DT_INST_PROP(n, enable_selftest), \
|
.selftest = DT_INST_PROP(n, enable_selftest), \
|
||||||
}; \
|
}; \
|
||||||
\
|
\
|
||||||
|
|
|
@ -38,8 +38,7 @@
|
||||||
#define SGP40_COMP_DEFAULT_RH 50
|
#define SGP40_COMP_DEFAULT_RH 50
|
||||||
|
|
||||||
struct sgp40_config {
|
struct sgp40_config {
|
||||||
const struct device *bus;
|
struct i2c_dt_spec bus;
|
||||||
uint8_t i2c_addr;
|
|
||||||
bool selftest;
|
bool selftest;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue