Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TOPIC-GPIO] drivers: sensor: bma280: convert to new GPIO API #22104

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/sensor/bma280/bma280.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct bma280_data {
s8_t temp_sample;

#ifdef CONFIG_BMA280_TRIGGER
struct device *dev;
struct device *gpio;
struct gpio_callback gpio_cb;

Expand All @@ -136,7 +137,6 @@ struct bma280_data {
struct k_sem gpio_sem;
#elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD)
struct k_work work;
struct device *dev;
#endif

#endif /* CONFIG_BMA280_TRIGGER */
Expand Down
27 changes: 19 additions & 8 deletions drivers/sensor/bma280/bma280_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
#include <logging/log.h>
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,
enum sensor_channel chan,
enum sensor_attribute attr,
Expand Down Expand Up @@ -61,7 +73,7 @@ static void bma280_gpio_callback(struct device *dev,

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)
k_sem_give(&drv_data->gpio_sem);
Expand Down Expand Up @@ -108,8 +120,7 @@ static void bma280_thread_cb(void *arg)
}
}

gpio_pin_enable_callback(drv_data->gpio,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
setup_int1(dev, true);
}

#ifdef CONFIG_BMA280_TRIGGER_OWN_THREAD
Expand Down Expand Up @@ -220,8 +231,8 @@ int bma280_init_interrupt(struct device *dev)

gpio_pin_configure(drv_data->gpio,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL |
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_FLAGS
| GPIO_INPUT);

gpio_init_callback(&drv_data->gpio_cb,
bma280_gpio_callback,
Expand Down Expand Up @@ -265,6 +276,8 @@ int bma280_init_interrupt(struct device *dev)
return -EIO;
}

drv_data->dev = dev;

#if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);

Expand All @@ -275,11 +288,9 @@ int bma280_init_interrupt(struct device *dev)
0, K_NO_WAIT);
#elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = bma280_work_cb;
drv_data->dev = dev;
#endif

gpio_pin_enable_callback(drv_data->gpio,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
setup_int1(dev, true);

return 0;
}