drivers/sensor: iis2iclx: Use DT helper for gpio_drdy
Use gpio_dt_spec structure and populate it using GPIO_DT_SPEC_GET macro. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
59f3e2c502
commit
6fa0d01c5f
3 changed files with 15 additions and 30 deletions
|
@ -646,10 +646,8 @@ static int iis2iclx_init(const struct device *dev)
|
|||
|
||||
#ifdef CONFIG_IIS2ICLX_TRIGGER
|
||||
#define IIS2ICLX_CFG_IRQ(inst) \
|
||||
.irq_dev_name = DT_INST_GPIO_LABEL(inst, drdy_gpios), \
|
||||
.irq_pin = DT_INST_GPIO_PIN(inst, drdy_gpios), \
|
||||
.irq_flags = DT_INST_GPIO_FLAGS(inst, drdy_gpios), \
|
||||
.int_pin = DT_INST_PROP(inst, int_pin)
|
||||
.gpio_drdy = GPIO_DT_SPEC_GET(DT_DRV_INST(inst), drdy_gpios), \
|
||||
.int_pin = DT_INST_PROP(inst, int_pin)
|
||||
#else
|
||||
#define IIS2ICLX_CFG_IRQ(inst)
|
||||
#endif /* CONFIG_IIS2ICLX_TRIGGER */
|
||||
|
|
|
@ -49,10 +49,8 @@ struct iis2iclx_config {
|
|||
uint8_t odr;
|
||||
uint8_t range;
|
||||
#ifdef CONFIG_IIS2ICLX_TRIGGER
|
||||
const char *irq_dev_name;
|
||||
uint8_t irq_pin;
|
||||
uint8_t irq_flags;
|
||||
uint8_t int_pin;
|
||||
const struct gpio_dt_spec gpio_drdy;
|
||||
#endif /* CONFIG_IIS2ICLX_TRIGGER */
|
||||
};
|
||||
|
||||
|
@ -88,7 +86,6 @@ struct iis2iclx_data {
|
|||
uint8_t accel_fs;
|
||||
|
||||
#ifdef CONFIG_IIS2ICLX_TRIGGER
|
||||
const struct device *gpio;
|
||||
struct gpio_callback gpio_cb;
|
||||
sensor_trigger_handler_t handler_drdy_acc;
|
||||
sensor_trigger_handler_t handler_drdy_temp;
|
||||
|
|
|
@ -72,7 +72,7 @@ static int iis2iclx_enable_xl_int(const struct device *dev, int enable)
|
|||
|
||||
int1_route.int1_ctrl.int1_drdy_xl = enable;
|
||||
return iis2iclx_write_reg(&iis2iclx->ctx, IIS2ICLX_INT1_CTRL,
|
||||
(uint8_t *)&int1_route.int1_ctrl, 1);
|
||||
(uint8_t *)&int1_route.int1_ctrl, 1);
|
||||
} else {
|
||||
iis2iclx_pin_int2_route_t int2_route;
|
||||
|
||||
|
@ -80,7 +80,7 @@ static int iis2iclx_enable_xl_int(const struct device *dev, int enable)
|
|||
(uint8_t *)&int2_route.int2_ctrl, 1);
|
||||
int2_route.int2_ctrl.int2_drdy_xl = enable;
|
||||
return iis2iclx_write_reg(&iis2iclx->ctx, IIS2ICLX_INT2_CTRL,
|
||||
(uint8_t *)&int2_route.int2_ctrl, 1);
|
||||
(uint8_t *)&int2_route.int2_ctrl, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,12 +93,6 @@ int iis2iclx_trigger_set(const struct device *dev,
|
|||
{
|
||||
struct iis2iclx_data *iis2iclx = dev->data;
|
||||
|
||||
/* If drdy_gpio is not configured in DT just return error */
|
||||
if (!iis2iclx->gpio) {
|
||||
LOG_ERR("triggers not supported");
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) {
|
||||
iis2iclx->handler_drdy_acc = handler;
|
||||
if (handler) {
|
||||
|
@ -159,8 +153,8 @@ static void iis2iclx_handle_interrupt(const struct device *dev)
|
|||
#endif
|
||||
}
|
||||
|
||||
gpio_pin_interrupt_configure(iis2iclx->gpio, cfg->irq_pin,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
gpio_pin_interrupt_configure_dt(&cfg->gpio_drdy,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
}
|
||||
|
||||
static void iis2iclx_gpio_callback(const struct device *dev,
|
||||
|
@ -172,8 +166,7 @@ static void iis2iclx_gpio_callback(const struct device *dev,
|
|||
|
||||
ARG_UNUSED(pins);
|
||||
|
||||
gpio_pin_interrupt_configure(iis2iclx->gpio, cfg->irq_pin,
|
||||
GPIO_INT_DISABLE);
|
||||
gpio_pin_interrupt_configure_dt(&cfg->gpio_drdy, GPIO_INT_DISABLE);
|
||||
|
||||
#if defined(CONFIG_IIS2ICLX_TRIGGER_OWN_THREAD)
|
||||
k_sem_give(&iis2iclx->gpio_sem);
|
||||
|
@ -209,10 +202,9 @@ int iis2iclx_init_interrupt(const struct device *dev)
|
|||
int ret;
|
||||
|
||||
/* setup data ready gpio interrupt (INT1 or INT2) */
|
||||
iis2iclx->gpio = device_get_binding(cfg->irq_dev_name);
|
||||
if (iis2iclx->gpio == NULL) {
|
||||
LOG_INF("Cannot get pointer to irq_dev_name");
|
||||
goto end;
|
||||
if (!device_is_ready(cfg->gpio_drdy.port)) {
|
||||
LOG_ERR("Cannot get pointer to drdy_gpio device");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_IIS2ICLX_TRIGGER_OWN_THREAD)
|
||||
|
@ -228,8 +220,7 @@ int iis2iclx_init_interrupt(const struct device *dev)
|
|||
iis2iclx->work.handler = iis2iclx_work_cb;
|
||||
#endif /* CONFIG_IIS2ICLX_TRIGGER_OWN_THREAD */
|
||||
|
||||
ret = gpio_pin_configure(iis2iclx->gpio, cfg->irq_pin,
|
||||
GPIO_INPUT | cfg->irq_flags);
|
||||
ret = gpio_pin_configure_dt(&cfg->gpio_drdy, GPIO_INPUT);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("Could not configure gpio");
|
||||
return ret;
|
||||
|
@ -237,9 +228,9 @@ int iis2iclx_init_interrupt(const struct device *dev)
|
|||
|
||||
gpio_init_callback(&iis2iclx->gpio_cb,
|
||||
iis2iclx_gpio_callback,
|
||||
BIT(cfg->irq_pin));
|
||||
BIT(cfg->gpio_drdy.pin));
|
||||
|
||||
if (gpio_add_callback(iis2iclx->gpio, &iis2iclx->gpio_cb) < 0) {
|
||||
if (gpio_add_callback(cfg->gpio_drdy.port, &iis2iclx->gpio_cb) < 0) {
|
||||
LOG_ERR("Could not set gpio callback");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -251,12 +242,11 @@ int iis2iclx_init_interrupt(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
if (gpio_pin_interrupt_configure(iis2iclx->gpio, cfg->irq_pin,
|
||||
if (gpio_pin_interrupt_configure_dt(&cfg->gpio_drdy,
|
||||
GPIO_INT_EDGE_TO_ACTIVE) < 0) {
|
||||
LOG_ERR("Could not configure interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
end:
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue