drivers: sensor: ms5607: Update driver to use i2c_dt_spec
Simplify driver by using i2c_dt_spec for bus access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
parent
df75bfd8f6
commit
e6f9ef4cc7
3 changed files with 7 additions and 9 deletions
|
@ -333,9 +333,8 @@ static const struct sensor_driver_api ms5607_api_funcs = {
|
|||
/* Initializes a struct ms5607_config for an instance on a I2C bus. */
|
||||
#define MS5607_CONFIG_I2C(inst) \
|
||||
{ \
|
||||
.bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \
|
||||
.tf = &ms5607_i2c_transfer_function, \
|
||||
.bus_cfg.i2c_addr = DT_INST_REG_ADDR(inst) \
|
||||
.bus_cfg.i2c = I2C_DT_SPEC_INST_GET(inst), \
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -92,7 +92,7 @@ struct ms5607_config {
|
|||
const struct ms5607_transfer_function *tf;
|
||||
union {
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
||||
uint16_t i2c_addr;
|
||||
struct i2c_dt_spec i2c;
|
||||
#endif
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
struct spi_dt_spec spi_bus;
|
||||
|
|
|
@ -19,7 +19,7 @@ LOG_MODULE_DECLARE(ms5607);
|
|||
|
||||
static int ms5607_i2c_raw_cmd(const struct ms5607_config *config, uint8_t cmd)
|
||||
{
|
||||
return i2c_write(config->bus, &cmd, 1, config->bus_cfg.i2c_addr);
|
||||
return i2c_write_dt(&config->bus_cfg.i2c, &cmd, 1);
|
||||
}
|
||||
|
||||
static int ms5607_i2c_reset(const struct ms5607_config *config)
|
||||
|
@ -39,7 +39,7 @@ static int ms5607_i2c_read_prom(const struct ms5607_config *config, uint8_t cmd,
|
|||
uint8_t valb[2];
|
||||
int err;
|
||||
|
||||
err = i2c_burst_read(config->bus, config->bus_cfg.i2c_addr, cmd, valb, sizeof(valb));
|
||||
err = i2c_burst_read_dt(&config->bus_cfg.i2c, cmd, valb, sizeof(valb));
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
@ -60,8 +60,7 @@ static int ms5607_i2c_read_adc(const struct ms5607_config *config, uint32_t *val
|
|||
int err;
|
||||
uint8_t valb[3];
|
||||
|
||||
err = i2c_burst_read(config->bus, config->bus_cfg.i2c_addr,
|
||||
MS5607_CMD_CONV_READ_ADC, valb, sizeof(valb));
|
||||
err = i2c_burst_read_dt(&config->bus_cfg.i2c, MS5607_CMD_CONV_READ_ADC, valb, sizeof(valb));
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
@ -74,8 +73,8 @@ static int ms5607_i2c_read_adc(const struct ms5607_config *config, uint32_t *val
|
|||
|
||||
static int ms5607_i2c_check(const struct ms5607_config *config)
|
||||
{
|
||||
if (!device_is_ready(config->bus)) {
|
||||
LOG_DBG("I2C bus %s not ready", config->bus->name);
|
||||
if (!device_is_ready(config->bus_cfg.i2c.bus)) {
|
||||
LOG_DBG("I2C bus device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue