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>
This commit is contained in:
parent
9b92dfeca8
commit
2c103a25cc
4 changed files with 32 additions and 43 deletions
|
@ -63,11 +63,6 @@ struct bme280_config {
|
|||
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_wait_until_ready(const struct device *dev)
|
|||
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 @@ static int bme280_channel_get(const struct device *dev,
|
|||
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 const struct sensor_driver_api bme280_api_funcs = {
|
|||
|
||||
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_read_compensation(const struct device *dev)
|
|||
|
||||
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);
|
||||
|
|
|
@ -30,7 +30,7 @@ LOG_MODULE_REGISTER(BMI160, CONFIG_SENSOR_LOG_LEVEL);
|
|||
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 @@ static int bmi160_transceive(const struct device *dev, uint8_t reg,
|
|||
|
||||
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 @@ static const struct bmi160_bus_io bmi160_bus_io_spi = {
|
|||
|
||||
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_read_i2c(const struct device *dev,
|
|||
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 @@ static const struct bmi160_bus_io bmi160_bus_io_i2c = {
|
|||
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 @@ static int bmi160_word_read(const struct device *dev, uint8_t reg_addr,
|
|||
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_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli)
|
|||
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 @@ static int bmi160_do_calibration(const struct device *dev, uint8_t foc_conf)
|
|||
#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 @@ static int bmi160_acc_calibrate(const struct device *dev,
|
|||
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 @@ static int bmi160_gyr_odr_set(const struct device *dev, uint16_t freq_int,
|
|||
#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_ofs_set(const struct device *dev,
|
|||
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_attr_set(const struct device *dev, enum sensor_channel chan,
|
|||
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 @@ static inline void bmi160_gyr_channel_get(const struct device *dev,
|
|||
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 @@ static inline void bmi160_acc_channel_get(const struct device *dev,
|
|||
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 @@ static int bmi160_temp_channel_get(const struct device *dev,
|
|||
{
|
||||
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 @@ static const struct sensor_driver_api bmi160_api = {
|
|||
|
||||
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;
|
||||
|
||||
|
|
|
@ -509,16 +509,6 @@ struct bmi160_data {
|
|||
#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,
|
||||
|
|
|
@ -16,7 +16,7 @@ LOG_MODULE_DECLARE(BMI160, CONFIG_SENSOR_LOG_LEVEL);
|
|||
|
||||
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_anymotion(const struct device *dev)
|
|||
|
||||
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 @@ static int bmi160_trigger_drdy_set(const struct device *dev,
|
|||
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_drdy_set(const struct device *dev,
|
|||
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_set(const struct device *dev,
|
|||
|
||||
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)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue