drivers: sensor: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and dev->config instead. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
1de05e6095
commit
e8c15f68b2
4 changed files with 28 additions and 35 deletions
|
@ -49,7 +49,7 @@ static const struct {
|
|||
static int bmp388_transceive(const struct device *dev,
|
||||
void *data, size_t length)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
const struct spi_buf buf = { .buf = data, .len = length };
|
||||
const struct spi_buf_set s = { .buffers = &buf, .count = 1 };
|
||||
|
||||
|
@ -61,7 +61,7 @@ static int bmp388_read_spi(const struct device *dev,
|
|||
void *data,
|
||||
size_t length)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
/* Reads must clock out a dummy byte after sending the address. */
|
||||
uint8_t reg_buf[2] = { reg | BIT(7), 0 };
|
||||
|
@ -127,7 +127,7 @@ static int bmp388_read_i2c(const struct device *dev,
|
|||
void *data,
|
||||
size_t length)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return i2c_burst_read(cfg->bus, cfg->bus_addr, reg, data, length);
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ static int bmp388_byte_read_i2c(const struct device *dev,
|
|||
uint8_t reg,
|
||||
uint8_t *byte)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return i2c_reg_read_byte(cfg->bus, cfg->bus_addr, reg, byte);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ static int bmp388_byte_write_i2c(const struct device *dev,
|
|||
uint8_t reg,
|
||||
uint8_t byte)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return i2c_reg_write_byte(cfg->bus, cfg->bus_addr, reg, byte);
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ int bmp388_reg_field_update_i2c(const struct device *dev,
|
|||
uint8_t mask,
|
||||
uint8_t val)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return i2c_reg_update_byte(cfg->bus, cfg->bus_addr, reg, mask, val);
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ static int bmp388_read(const struct device *dev,
|
|||
void *data,
|
||||
size_t length)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return cfg->ops->read(dev, reg, data, length);
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ static int bmp388_byte_read(const struct device *dev,
|
|||
uint8_t reg,
|
||||
uint8_t *byte)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return cfg->ops->byte_read(dev, reg, byte);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ static int bmp388_byte_write(const struct device *dev,
|
|||
uint8_t reg,
|
||||
uint8_t byte)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return cfg->ops->byte_write(dev, reg, byte);
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ int bmp388_reg_field_update(const struct device *dev,
|
|||
uint8_t mask,
|
||||
uint8_t val)
|
||||
{
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
|
||||
return cfg->ops->reg_field_update(dev, reg, mask, val);
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ static int bmp388_attr_set_odr(const struct device *dev,
|
|||
uint16_t freq_milli)
|
||||
{
|
||||
int err;
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
int odr = bmp388_freq_to_odr_val(freq_int, freq_milli);
|
||||
|
||||
if (odr < 0) {
|
||||
|
@ -261,7 +261,7 @@ static int bmp388_attr_set_oversampling(const struct device *dev,
|
|||
uint32_t pos, mask;
|
||||
int err;
|
||||
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
|
||||
/* Value must be a positive power of 2 <= 32. */
|
||||
if ((val <= 0) || (val > 32) || ((val & (val - 1)) != 0)) {
|
||||
|
@ -343,7 +343,7 @@ static int bmp388_attr_set(const struct device *dev,
|
|||
static int bmp388_sample_fetch(const struct device *dev,
|
||||
enum sensor_channel chan)
|
||||
{
|
||||
struct bmp388_data *bmp388 = DEV_DATA(dev);
|
||||
struct bmp388_data *bmp388 = dev->data;
|
||||
uint8_t raw[BMP388_SAMPLE_BUFFER_SIZE];
|
||||
int ret = 0;
|
||||
|
||||
|
@ -418,7 +418,7 @@ static void bmp388_compensate_temp(struct bmp388_data *data)
|
|||
static int bmp388_temp_channel_get(const struct device *dev,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
|
||||
if (data->sample.comp_temp == 0) {
|
||||
bmp388_compensate_temp(data);
|
||||
|
@ -490,7 +490,7 @@ static uint64_t bmp388_compensate_press(struct bmp388_data *data)
|
|||
static int bmp388_press_channel_get(const struct device *dev,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
|
||||
if (data->sample.comp_temp == 0) {
|
||||
bmp388_compensate_temp(data);
|
||||
|
@ -531,7 +531,7 @@ static int bmp388_channel_get(const struct device *dev,
|
|||
|
||||
static int bmp388_get_calibration_data(const struct device *dev)
|
||||
{
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
struct bmp388_cal_data *cal = &data->cal;
|
||||
|
||||
if (bmp388_read(dev, BMP388_REG_CALIB0, cal, sizeof(*cal)) < 0) {
|
||||
|
@ -589,8 +589,8 @@ static const struct sensor_driver_api bmp388_api = {
|
|||
|
||||
static int bmp388_init(const struct device *dev)
|
||||
{
|
||||
struct bmp388_data *bmp388 = DEV_DATA(dev);
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
struct bmp388_data *bmp388 = dev->data;
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
uint8_t val = 0U;
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
|
|
|
@ -187,9 +187,6 @@ struct bmp388_data {
|
|||
#endif /* CONFIG_BMP388_TRIGGER */
|
||||
};
|
||||
|
||||
#define DEV_DATA(dev) ((struct bmp388_data *)dev->data)
|
||||
#define DEV_CFG(dev) ((const struct bmp388_config *)dev->config)
|
||||
|
||||
int bmp388_trigger_mode_init(const struct device *dev);
|
||||
int bmp388_trigger_set(const struct device *dev,
|
||||
const struct sensor_trigger *trig,
|
||||
|
|
|
@ -23,7 +23,7 @@ LOG_MODULE_DECLARE(BMP388, CONFIG_SENSOR_LOG_LEVEL);
|
|||
static void bmp388_handle_interrupts(const void *arg)
|
||||
{
|
||||
const struct device *dev = (const struct device *)arg;
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
|
||||
struct sensor_trigger drdy_trigger = {
|
||||
.type = SENSOR_TRIG_DATA_READY,
|
||||
|
@ -45,7 +45,7 @@ static void bmp388_thread_main(void *arg1, void *unused1, void *unused2)
|
|||
ARG_UNUSED(unused1);
|
||||
ARG_UNUSED(unused2);
|
||||
const struct device *dev = (const struct device *)arg1;
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
|
||||
while (1) {
|
||||
k_sem_take(&data->sem, K_FOREVER);
|
||||
|
@ -90,7 +90,7 @@ int bmp388_trigger_set(
|
|||
const struct sensor_trigger *trig,
|
||||
sensor_trigger_handler_t handler)
|
||||
{
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
enum pm_device_state state;
|
||||
|
@ -121,8 +121,8 @@ int bmp388_trigger_set(
|
|||
|
||||
int bmp388_trigger_mode_init(const struct device *dev)
|
||||
{
|
||||
struct bmp388_data *data = DEV_DATA(dev);
|
||||
const struct bmp388_config *cfg = DEV_CFG(dev);
|
||||
struct bmp388_data *data = dev->data;
|
||||
const struct bmp388_config *cfg = dev->config;
|
||||
int ret;
|
||||
|
||||
if (!device_is_ready(cfg->gpio_int.port)) {
|
||||
|
|
|
@ -35,15 +35,11 @@ struct qdec_sam_dev_data {
|
|||
};
|
||||
|
||||
#define DEV_NAME(dev) ((dev)->name)
|
||||
#define DEV_CFG(dev) \
|
||||
((const struct qdec_sam_dev_cfg *const)(dev)->config)
|
||||
#define DEV_DATA(dev) \
|
||||
((struct qdec_sam_dev_data *const)(dev)->data)
|
||||
|
||||
static int qdec_sam_fetch(const struct device *dev, enum sensor_channel chan)
|
||||
{
|
||||
const struct qdec_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
|
||||
struct qdec_sam_dev_data *const dev_data = DEV_DATA(dev);
|
||||
const struct qdec_sam_dev_cfg *const dev_cfg = dev->config;
|
||||
struct qdec_sam_dev_data *const dev_data = dev->data;
|
||||
Tc *const tc = dev_cfg->regs;
|
||||
TcChannel *tc_ch0 = &tc->TcChannel[0];
|
||||
|
||||
|
@ -56,7 +52,7 @@ static int qdec_sam_fetch(const struct device *dev, enum sensor_channel chan)
|
|||
static int qdec_sam_get(const struct device *dev, enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct qdec_sam_dev_data *const dev_data = DEV_DATA(dev);
|
||||
struct qdec_sam_dev_data *const dev_data = dev->data;
|
||||
|
||||
if (chan == SENSOR_CHAN_ROTATION) {
|
||||
val->val1 = dev_data->position;
|
||||
|
@ -79,7 +75,7 @@ static void qdec_sam_start(Tc *const tc)
|
|||
|
||||
static void qdec_sam_configure(const struct device *dev)
|
||||
{
|
||||
const struct qdec_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
|
||||
const struct qdec_sam_dev_cfg *const dev_cfg = dev->config;
|
||||
Tc *const tc = dev_cfg->regs;
|
||||
TcChannel *tc_ch0 = &tc->TcChannel[0];
|
||||
|
||||
|
@ -100,7 +96,7 @@ static void qdec_sam_configure(const struct device *dev)
|
|||
static int qdec_sam_initialize(const struct device *dev)
|
||||
{
|
||||
__ASSERT_NO_MSG(dev != NULL);
|
||||
const struct qdec_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
|
||||
const struct qdec_sam_dev_cfg *const dev_cfg = dev->config;
|
||||
|
||||
/* Connect pins to the peripheral */
|
||||
soc_gpio_list_configure(dev_cfg->pin_list, dev_cfg->pin_list_size);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue