drivers: sensor: lsm6dsl: Update driver to use gpio_dt_spec
Simplify driver by using gpio_dt_spec for bus access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
parent
07587e7826
commit
1a0159518b
3 changed files with 11 additions and 20 deletions
|
@ -839,9 +839,7 @@ static int lsm6dsl_init(const struct device *dev)
|
|||
|
||||
#ifdef CONFIG_LSM6DSL_TRIGGER
|
||||
#define LSM6DSL_CFG_IRQ(inst) \
|
||||
.irq_dev_name = DT_INST_GPIO_LABEL(inst, irq_gpios), \
|
||||
.irq_pin = DT_INST_GPIO_PIN(inst, irq_gpios), \
|
||||
.irq_flags = DT_INST_GPIO_FLAGS(inst, irq_gpios),
|
||||
.int_gpio = GPIO_DT_SPEC_INST_GET(inst, irq_gpios),
|
||||
#else
|
||||
#define LSM6DSL_CFG_IRQ(inst)
|
||||
#endif /* CONFIG_LSM6DSL_TRIGGER */
|
||||
|
|
|
@ -625,9 +625,7 @@ struct lsm6dsl_config {
|
|||
int (*bus_init)(const struct device *dev);
|
||||
const union lsm6dsl_bus_cfg bus_cfg;
|
||||
#ifdef CONFIG_LSM6DSL_TRIGGER
|
||||
char *irq_dev_name;
|
||||
uint32_t irq_pin;
|
||||
int irq_flags;
|
||||
struct gpio_dt_spec int_gpio;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -674,7 +672,6 @@ struct lsm6dsl_data {
|
|||
|
||||
#ifdef CONFIG_LSM6DSL_TRIGGER
|
||||
const struct device *dev;
|
||||
const struct device *gpio;
|
||||
struct gpio_callback gpio_cb;
|
||||
|
||||
struct sensor_trigger data_ready_trigger;
|
||||
|
|
|
@ -19,14 +19,13 @@ LOG_MODULE_DECLARE(LSM6DSL, CONFIG_SENSOR_LOG_LEVEL);
|
|||
|
||||
static inline void setup_irq(const struct device *dev, bool enable)
|
||||
{
|
||||
struct lsm6dsl_data *drv_data = dev->data;
|
||||
const struct lsm6dsl_config *config = dev->config;
|
||||
|
||||
unsigned int flags = enable
|
||||
? GPIO_INT_EDGE_TO_ACTIVE
|
||||
: GPIO_INT_DISABLE;
|
||||
|
||||
gpio_pin_interrupt_configure(drv_data->gpio, config->irq_pin, flags);
|
||||
gpio_pin_interrupt_configure_dt(&config->int_gpio, flags);
|
||||
}
|
||||
|
||||
static inline void handle_irq(const struct device *dev)
|
||||
|
@ -52,7 +51,7 @@ int lsm6dsl_trigger_set(const struct device *dev,
|
|||
__ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY);
|
||||
|
||||
/* If irq_gpio is not configured in DT just return error */
|
||||
if (!drv_data->gpio) {
|
||||
if (!config->int_gpio.port) {
|
||||
LOG_ERR("triggers not supported");
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
@ -67,7 +66,7 @@ int lsm6dsl_trigger_set(const struct device *dev,
|
|||
drv_data->data_ready_trigger = *trig;
|
||||
|
||||
setup_irq(dev, true);
|
||||
if (gpio_pin_get(drv_data->gpio, config->irq_pin) > 0) {
|
||||
if (gpio_pin_get_dt(&config->int_gpio) > 0) {
|
||||
handle_irq(dev);
|
||||
}
|
||||
|
||||
|
@ -124,20 +123,17 @@ int lsm6dsl_init_interrupt(const struct device *dev)
|
|||
const struct lsm6dsl_config *config = dev->config;
|
||||
struct lsm6dsl_data *drv_data = dev->data;
|
||||
|
||||
/* setup data ready gpio interrupt */
|
||||
drv_data->gpio = device_get_binding(config->irq_dev_name);
|
||||
if (drv_data->gpio == NULL) {
|
||||
LOG_INF("Cannot get pointer for irq_dev_name");
|
||||
goto end;
|
||||
if (!device_is_ready(config->int_gpio.port)) {
|
||||
LOG_ERR("GPIO device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
gpio_pin_configure(drv_data->gpio, config->irq_pin,
|
||||
GPIO_INPUT | config->irq_flags);
|
||||
gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT);
|
||||
|
||||
gpio_init_callback(&drv_data->gpio_cb,
|
||||
lsm6dsl_gpio_callback, BIT(config->irq_pin));
|
||||
lsm6dsl_gpio_callback, BIT(config->int_gpio.pin));
|
||||
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
if (gpio_add_callback(config->int_gpio.port, &drv_data->gpio_cb) < 0) {
|
||||
LOG_ERR("Could not set gpio callback.");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue