drivers: sensor: bma280: 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 <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2020-01-22 11:14:42 -06:00 committed by Carles Cufí
commit 9b0859566d
2 changed files with 20 additions and 9 deletions

View file

@ -121,6 +121,7 @@ struct bma280_data {
s8_t temp_sample; s8_t temp_sample;
#ifdef CONFIG_BMA280_TRIGGER #ifdef CONFIG_BMA280_TRIGGER
struct device *dev;
struct device *gpio; struct device *gpio;
struct gpio_callback gpio_cb; struct gpio_callback gpio_cb;
@ -136,7 +137,6 @@ struct bma280_data {
struct k_sem gpio_sem; struct k_sem gpio_sem;
#elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD) #elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD)
struct k_work work; struct k_work work;
struct device *dev;
#endif #endif
#endif /* CONFIG_BMA280_TRIGGER */ #endif /* CONFIG_BMA280_TRIGGER */

View file

@ -15,6 +15,18 @@
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_DECLARE(BMA280, CONFIG_SENSOR_LOG_LEVEL); LOG_MODULE_DECLARE(BMA280, CONFIG_SENSOR_LOG_LEVEL);
static inline void setup_int1(struct device *dev,
bool enable)
{
struct bma280_data *data = dev->driver_data;
gpio_pin_interrupt_configure(data->gpio,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
(enable
? GPIO_INT_EDGE_TO_ACTIVE
: GPIO_INT_DISABLE));
}
int bma280_attr_set(struct device *dev, int bma280_attr_set(struct device *dev,
enum sensor_channel chan, enum sensor_channel chan,
enum sensor_attribute attr, enum sensor_attribute attr,
@ -61,7 +73,7 @@ static void bma280_gpio_callback(struct device *dev,
ARG_UNUSED(pins); ARG_UNUSED(pins);
gpio_pin_disable_callback(dev, DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN); setup_int1(drv_data->dev, false);
#if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD) #if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem); k_sem_give(&drv_data->gpio_sem);
@ -108,8 +120,7 @@ static void bma280_thread_cb(void *arg)
} }
} }
gpio_pin_enable_callback(drv_data->gpio, setup_int1(dev, true);
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
} }
#ifdef CONFIG_BMA280_TRIGGER_OWN_THREAD #ifdef CONFIG_BMA280_TRIGGER_OWN_THREAD
@ -220,8 +231,8 @@ int bma280_init_interrupt(struct device *dev)
gpio_pin_configure(drv_data->gpio, gpio_pin_configure(drv_data->gpio,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN, DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL | DT_INST_0_BOSCH_BMA280_INT1_GPIOS_FLAGS
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE); | GPIO_INPUT);
gpio_init_callback(&drv_data->gpio_cb, gpio_init_callback(&drv_data->gpio_cb,
bma280_gpio_callback, bma280_gpio_callback,
@ -265,6 +276,8 @@ int bma280_init_interrupt(struct device *dev)
return -EIO; return -EIO;
} }
drv_data->dev = dev;
#if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD) #if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX); k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
@ -275,11 +288,9 @@ int bma280_init_interrupt(struct device *dev)
0, K_NO_WAIT); 0, K_NO_WAIT);
#elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD) #elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = bma280_work_cb; drv_data->work.handler = bma280_work_cb;
drv_data->dev = dev;
#endif #endif
gpio_pin_enable_callback(drv_data->gpio, setup_int1(dev, true);
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
return 0; return 0;
} }