From 494446eb27f33fd5c4e29ae6e15d0ab1d05f5f74 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Wed, 22 Jan 2020 13:41:28 -0600 Subject: [PATCH] drivers: sensor: lsm9ds0_gyro: convert to new GPIO API Use the new pin and interrupt configuration API. NOTE: Because hardware is not available this has been build-tested only. Signed-off-by: Peter Bigot --- drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.c | 1 + drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h | 3 +- .../lsm9ds0_gyro/lsm9ds0_gyro_trigger.c | 31 +++++++++++-------- tests/drivers/build_all/dts_fixup.h | 1 + 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.c b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.c index 325d9c75be1a2..d65a5c6e86900 100644 --- a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.c +++ b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.c @@ -349,6 +349,7 @@ static const struct lsm9ds0_gyro_config lsm9ds0_gyro_config = { #if defined(CONFIG_LSM9DS0_GYRO_TRIGGER_DRDY) .gpio_drdy_dev_name = DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_CONTROLLER, .gpio_drdy_int_pin = DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_PIN, + .gpio_drdy_int_flags = DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_FLAGS, #endif }; diff --git a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h index 091e9dd461ede..07103ce4c52ef 100644 --- a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h +++ b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h @@ -215,7 +215,8 @@ struct lsm9ds0_gyro_config { #if CONFIG_LSM9DS0_GYRO_TRIGGER_DRDY char *gpio_drdy_dev_name; - u8_t gpio_drdy_int_pin; + gpio_pin_t gpio_drdy_int_pin; + gpio_devicetree_flags_t gpio_drdy_int_flags; #endif }; diff --git a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c index f91c5e43674be..66a9354c121c7 100644 --- a/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c +++ b/drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c @@ -20,6 +20,19 @@ extern struct lsm9ds0_gyro_data lsm9ds0_gyro_data; LOG_MODULE_DECLARE(LSM9DS0_GYRO, CONFIG_SENSOR_LOG_LEVEL); +static inline void setup_drdy(struct device *dev, + bool enable) +{ + struct lsm9ds0_gyro_data *data = dev->driver_data; + const struct lsm9ds0_gyro_config *cfg = dev->config->config_info; + + gpio_pin_interrupt_configure(data->gpio_drdy, + cfg->gpio_drdy_int_pin, + enable + ? GPIO_INT_EDGE_TO_ACTIVE + : GPIO_INT_DISABLE); +} + int lsm9ds0_gyro_trigger_set(struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) @@ -30,8 +43,7 @@ int lsm9ds0_gyro_trigger_set(struct device *dev, u8_t state; if (trig->type == SENSOR_TRIG_DATA_READY) { - gpio_pin_disable_callback(data->gpio_drdy, - config->gpio_drdy_int_pin); + setup_drdy(dev, false); state = 0U; if (handler) { @@ -51,8 +63,7 @@ int lsm9ds0_gyro_trigger_set(struct device *dev, return -EIO; } - gpio_pin_enable_callback(data->gpio_drdy, - config->gpio_drdy_int_pin); + setup_drdy(dev, true); return 0; } @@ -64,10 +75,8 @@ static void lsm9ds0_gyro_gpio_drdy_callback(struct device *dev, { struct lsm9ds0_gyro_data *data = CONTAINER_OF(cb, struct lsm9ds0_gyro_data, gpio_cb); - const struct lsm9ds0_gyro_config * const config = - data->dev->config->config_info; - gpio_pin_disable_callback(dev, config->gpio_drdy_int_pin); + setup_drdy(data->dev, false); k_sem_give(&data->sem); } @@ -76,9 +85,6 @@ static void lsm9ds0_gyro_thread_main(void *arg1, void *arg2, void *arg3) { struct device *dev = (struct device *) arg1; struct lsm9ds0_gyro_data *data = dev->driver_data; - const struct lsm9ds0_gyro_config *config = dev->config->config_info; - - int gpio_pin = config->gpio_drdy_int_pin; while (1) { k_sem_take(&data->sem, K_FOREVER); @@ -87,7 +93,7 @@ static void lsm9ds0_gyro_thread_main(void *arg1, void *arg2, void *arg3) data->handler_drdy(dev, &data->trigger_drdy); } - gpio_pin_enable_callback(data->gpio_drdy, gpio_pin); + setup_drdy(dev, true); } } @@ -112,8 +118,7 @@ int lsm9ds0_gyro_init_interrupt(struct device *dev) } gpio_pin_configure(data->gpio_drdy, config->gpio_drdy_int_pin, - GPIO_DIR_IN | GPIO_INT | - GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE); + GPIO_INPUT | config->gpio_drdy_int_flags); gpio_init_callback(&data->gpio_cb, lsm9ds0_gyro_gpio_drdy_callback, diff --git a/tests/drivers/build_all/dts_fixup.h b/tests/drivers/build_all/dts_fixup.h index 8dcc443168fb9..5d8d700e7ae4b 100644 --- a/tests/drivers/build_all/dts_fixup.h +++ b/tests/drivers/build_all/dts_fixup.h @@ -265,6 +265,7 @@ #define DT_INST_0_ST_LSM9DS0_GYRO_BASE_ADDRESS 0x1d #define DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_CONTROLLER "" #define DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_PIN 1 +#define DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_FLAGS 0 #endif #ifndef DT_INST_0_ST_STTS751_LABEL