drivers: sensor: drop get_dev_data/get_dev_config usage
Replace all get_dev_data()/get_dev_config() accessor utilities with
dev->data and dev->config.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
diff --git a/drivers/sensor/bme280/bme280.c b/drivers/sensor/bme280/bme280.c
index 585544e..1a33c54 100644
--- a/drivers/sensor/bme280/bme280.c
+++ b/drivers/sensor/bme280/bme280.c
@@ -63,11 +63,6 @@
const struct bme280_bus_io *bus_io;
};
-static inline struct bme280_data *to_data(const struct device *dev)
-{
- return dev->data;
-}
-
static inline int bme280_bus_check(const struct device *dev)
{
const struct bme280_config *cfg = dev->config;
@@ -174,7 +169,7 @@
static int bme280_sample_fetch(const struct device *dev,
enum sensor_channel chan)
{
- struct bme280_data *data = to_data(dev);
+ struct bme280_data *data = dev->data;
uint8_t buf[8];
int32_t adc_press, adc_temp, adc_humidity;
int size = 6;
@@ -228,7 +223,7 @@
enum sensor_channel chan,
struct sensor_value *val)
{
- struct bme280_data *data = to_data(dev);
+ struct bme280_data *data = dev->data;
switch (chan) {
case SENSOR_CHAN_AMBIENT_TEMP:
@@ -272,7 +267,7 @@
static int bme280_read_compensation(const struct device *dev)
{
- struct bme280_data *data = to_data(dev);
+ struct bme280_data *data = dev->data;
uint16_t buf[12];
uint8_t hbuf[7];
int err = 0;
@@ -325,7 +320,7 @@
static int bme280_chip_init(const struct device *dev)
{
- struct bme280_data *data = to_data(dev);
+ struct bme280_data *data = dev->data;
int err;
err = bme280_bus_check(dev);
diff --git a/drivers/sensor/bmi160/bmi160.c b/drivers/sensor/bmi160/bmi160.c
index dcd509d..8eb03ba 100644
--- a/drivers/sensor/bmi160/bmi160.c
+++ b/drivers/sensor/bmi160/bmi160.c
@@ -30,7 +30,7 @@
static int bmi160_transceive(const struct device *dev, uint8_t reg,
bool write, void *buf, size_t length)
{
- const struct bmi160_cfg *cfg = to_config(dev);
+ const struct bmi160_cfg *cfg = dev->config;
const struct spi_buf tx_buf[2] = {
{
.buf = ®,
@@ -60,7 +60,9 @@
bool bmi160_bus_ready_spi(const struct device *dev)
{
- return spi_is_ready(&to_config(dev)->bus.spi);
+ const struct bmi160_cfg *cfg = dev->config;
+
+ return spi_is_ready(&cfg->bus.spi);
}
int bmi160_read_spi(const struct device *dev,
@@ -88,13 +90,15 @@
bool bmi160_bus_ready_i2c(const struct device *dev)
{
- return device_is_ready(to_config(dev)->bus.i2c.bus);
+ const struct bmi160_cfg *cfg = dev->config;
+
+ return device_is_ready(cfg->bus.i2c.bus);
}
int bmi160_read_i2c(const struct device *dev,
uint8_t reg_addr, void *buf, uint8_t len)
{
- const struct bmi160_cfg *cfg = to_config(dev);
+ const struct bmi160_cfg *cfg = dev->config;
return i2c_burst_read_dt(&cfg->bus.i2c, reg_addr, buf, len);
}
@@ -102,7 +106,7 @@
int bmi160_write_i2c(const struct device *dev,
uint8_t reg_addr, void *buf, uint8_t len)
{
- const struct bmi160_cfg *cfg = to_config(dev);
+ const struct bmi160_cfg *cfg = dev->config;
return i2c_burst_write_dt(&cfg->bus.i2c, reg_addr, buf, len);
}
@@ -117,7 +121,7 @@
int bmi160_read(const struct device *dev, uint8_t reg_addr, void *buf,
uint8_t len)
{
- const struct bmi160_cfg *cfg = to_config(dev);
+ const struct bmi160_cfg *cfg = dev->config;
return cfg->bus_io->read(dev, reg_addr, buf, len);
}
@@ -145,7 +149,7 @@
int bmi160_write(const struct device *dev, uint8_t reg_addr, void *buf,
uint8_t len)
{
- const struct bmi160_cfg *cfg = to_config(dev);
+ const struct bmi160_cfg *cfg = dev->config;
return cfg->bus_io->write(dev, reg_addr, buf, len);
}
@@ -276,7 +280,7 @@
static int bmi160_acc_odr_set(const struct device *dev, uint16_t freq_int,
uint16_t freq_milli)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
int odr = bmi160_freq_to_odr_val(freq_int, freq_milli);
if (odr < 0) {
@@ -378,7 +382,7 @@
#if defined(CONFIG_BMI160_ACCEL_RANGE_RUNTIME)
static int bmi160_acc_range_set(const struct device *dev, int32_t range)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
int32_t reg_val = bmi160_range_to_reg_val(range,
bmi160_acc_range_map,
BMI160_ACC_RANGE_MAP_SIZE);
@@ -441,7 +445,7 @@
enum sensor_channel chan,
const struct sensor_value *xyz_calib_value)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
uint8_t foc_pos[] = {
BMI160_FOC_ACC_X_POS,
BMI160_FOC_ACC_Y_POS,
@@ -545,7 +549,7 @@
#if defined(CONFIG_BMI160_GYRO_RANGE_RUNTIME)
static int bmi160_gyr_range_set(const struct device *dev, uint16_t range)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
int32_t reg_val = bmi160_range_to_reg_val(range,
bmi160_gyr_range_map,
BMI160_GYR_RANGE_MAP_SIZE);
@@ -629,7 +633,7 @@
static int bmi160_gyr_calibrate(const struct device *dev,
enum sensor_channel chan)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
ARG_UNUSED(chan);
@@ -707,7 +711,7 @@
static int bmi160_sample_fetch(const struct device *dev,
enum sensor_channel chan)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
uint8_t status;
size_t i;
@@ -789,7 +793,7 @@
enum sensor_channel chan,
struct sensor_value *val)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
bmi160_channel_convert(chan, data->scale.gyr, data->sample.gyr, val);
}
@@ -800,7 +804,7 @@
enum sensor_channel chan,
struct sensor_value *val)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
bmi160_channel_convert(chan, data->scale.acc, data->sample.acc, val);
}
@@ -811,7 +815,7 @@
{
uint16_t temp_raw = 0U;
int32_t temp_micro = 0;
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
if (data->pmu_sts.raw == 0U) {
return -EINVAL;
@@ -872,8 +876,8 @@
int bmi160_init(const struct device *dev)
{
- const struct bmi160_cfg *cfg = to_config(dev);
- struct bmi160_data *data = to_data(dev);
+ const struct bmi160_cfg *cfg = dev->config;
+ struct bmi160_data *data = dev->data;
uint8_t val = 0U;
int32_t acc_range, gyr_range;
diff --git a/drivers/sensor/bmi160/bmi160.h b/drivers/sensor/bmi160/bmi160.h
index 1c92fc8..cfa5ade 100644
--- a/drivers/sensor/bmi160/bmi160.h
+++ b/drivers/sensor/bmi160/bmi160.h
@@ -509,16 +509,6 @@
#endif /* CONFIG_BMI160_TRIGGER */
};
-static inline struct bmi160_data *to_data(const struct device *dev)
-{
- return dev->data;
-}
-
-static inline const struct bmi160_cfg *to_config(const struct device *dev)
-{
- return dev->config;
-}
-
int bmi160_read(const struct device *dev, uint8_t reg_addr,
void *data, uint8_t len);
int bmi160_byte_read(const struct device *dev, uint8_t reg_addr,
diff --git a/drivers/sensor/bmi160/bmi160_trigger.c b/drivers/sensor/bmi160/bmi160_trigger.c
index 5075061..4405185 100644
--- a/drivers/sensor/bmi160/bmi160_trigger.c
+++ b/drivers/sensor/bmi160/bmi160_trigger.c
@@ -16,7 +16,7 @@
static void bmi160_handle_anymotion(const struct device *dev)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
struct sensor_trigger anym_trigger = {
.type = SENSOR_TRIG_DELTA,
.chan = SENSOR_CHAN_ACCEL_XYZ,
@@ -29,7 +29,7 @@
static void bmi160_handle_drdy(const struct device *dev, uint8_t status)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
struct sensor_trigger drdy_trigger = {
.type = SENSOR_TRIG_DATA_READY,
};
@@ -121,7 +121,7 @@
enum sensor_channel chan,
sensor_trigger_handler_t handler)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
uint8_t drdy_en = 0U;
#if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND)
@@ -156,7 +156,7 @@
static int bmi160_trigger_anym_set(const struct device *dev,
sensor_trigger_handler_t handler)
{
- struct bmi160_data *data = to_data(dev);
+ struct bmi160_data *data = dev->data;
uint8_t anym_en = 0U;
data->handler_anymotion = handler;
@@ -265,8 +265,8 @@
int bmi160_trigger_mode_init(const struct device *dev)
{
- struct bmi160_data *data = to_data(dev);
- const struct bmi160_cfg *cfg = to_config(dev);
+ struct bmi160_data *data = dev->data;
+ const struct bmi160_cfg *cfg = dev->config;
int ret;
if (!device_is_ready(cfg->interrupt.port)) {