drivers: sensor: ms5607: Update driver to use spi_dt_spec
Simplify driver by using spi_dt_spec for bus access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
parent
e6f9ef4cc7
commit
6098e1894b
3 changed files with 9 additions and 16 deletions
|
@ -322,12 +322,10 @@ static const struct sensor_driver_api ms5607_api_funcs = {
|
|||
/* Initializes a struct ms5607_config for an instance on a SPI bus. */
|
||||
#define MS5607_CONFIG_SPI(inst) \
|
||||
{ \
|
||||
.bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \
|
||||
.tf = &ms5607_spi_transfer_function, \
|
||||
.bus_cfg.spi_bus = \
|
||||
SPI_DT_SPEC_INST_GET(inst, \
|
||||
MS5607_SPI_OPERATION, \
|
||||
0), \
|
||||
.bus_cfg.spi = SPI_DT_SPEC_INST_GET(inst, \
|
||||
MS5607_SPI_OPERATION, \
|
||||
0), \
|
||||
}
|
||||
|
||||
/* Initializes a struct ms5607_config for an instance on a I2C bus. */
|
||||
|
|
|
@ -88,14 +88,13 @@ extern const struct ms5607_transfer_function ms5607_spi_transfer_function;
|
|||
#endif
|
||||
|
||||
struct ms5607_config {
|
||||
const struct device *bus;
|
||||
const struct ms5607_transfer_function *tf;
|
||||
union {
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
||||
struct i2c_dt_spec i2c;
|
||||
#endif
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
struct spi_dt_spec spi_bus;
|
||||
struct spi_dt_spec spi;
|
||||
#endif
|
||||
} bus_cfg;
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ static int ms5607_spi_raw_cmd(const struct ms5607_config *config, uint8_t cmd)
|
|||
.count = 1,
|
||||
};
|
||||
|
||||
return spi_write_dt(&config->bus_cfg.spi_bus, &buf_set);
|
||||
return spi_write_dt(&config->bus_cfg.spi, &buf_set);
|
||||
}
|
||||
|
||||
static int ms5607_spi_reset(const struct ms5607_config *config)
|
||||
|
@ -79,9 +79,7 @@ static int ms5607_spi_read_prom(const struct ms5607_config *config, uint8_t cmd,
|
|||
.count = 1,
|
||||
};
|
||||
|
||||
err = spi_transceive_dt(&config->bus_cfg.spi_bus,
|
||||
&tx_buf_set,
|
||||
&rx_buf_set);
|
||||
err = spi_transceive_dt(&config->bus_cfg.spi, &tx_buf_set, &rx_buf_set);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
@ -129,9 +127,7 @@ static int ms5607_spi_read_adc(const struct ms5607_config *config, uint32_t *val
|
|||
.count = 1,
|
||||
};
|
||||
|
||||
err = spi_transceive_dt(&config->bus_cfg.spi_bus,
|
||||
&tx_buf_set,
|
||||
&rx_buf_set);
|
||||
err = spi_transceive_dt(&config->bus_cfg.spi, &tx_buf_set, &rx_buf_set);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
|
@ -143,8 +139,8 @@ static int ms5607_spi_read_adc(const struct ms5607_config *config, uint32_t *val
|
|||
|
||||
static int ms5607_spi_check(const struct ms5607_config *config)
|
||||
{
|
||||
if (!spi_is_ready(&config->bus_cfg.spi_bus)) {
|
||||
LOG_DBG("SPI bus %s not ready", config->bus->name);
|
||||
if (!spi_is_ready(&config->bus_cfg.spi)) {
|
||||
LOG_DBG("SPI bus not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue