Skip to content

Commit 2d8d27c

Browse files
committed
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 <[email protected]>
1 parent 73d24e3 commit 2d8d27c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

drivers/sensor/bma280/bma280.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct bma280_data {
121121
s8_t temp_sample;
122122

123123
#ifdef CONFIG_BMA280_TRIGGER
124+
struct device *dev;
124125
struct device *gpio;
125126
struct gpio_callback gpio_cb;
126127

@@ -136,7 +137,6 @@ struct bma280_data {
136137
struct k_sem gpio_sem;
137138
#elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD)
138139
struct k_work work;
139-
struct device *dev;
140140
#endif
141141

142142
#endif /* CONFIG_BMA280_TRIGGER */

drivers/sensor/bma280/bma280_trigger.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
#include <logging/log.h>
1616
LOG_MODULE_DECLARE(BMA280, CONFIG_SENSOR_LOG_LEVEL);
1717

18+
static inline void setup_int1(struct device *dev,
19+
bool enable)
20+
{
21+
struct bma280_data *data = dev->driver_data;
22+
23+
gpio_pin_interrupt_configure(data->gpio,
24+
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
25+
(enable
26+
? GPIO_INT_EDGE_TO_ACTIVE
27+
: GPIO_INT_DISABLE));
28+
}
29+
1830
int bma280_attr_set(struct device *dev,
1931
enum sensor_channel chan,
2032
enum sensor_attribute attr,
@@ -61,7 +73,7 @@ static void bma280_gpio_callback(struct device *dev,
6173

6274
ARG_UNUSED(pins);
6375

64-
gpio_pin_disable_callback(dev, DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
76+
setup_int1(drv_data->dev, false);
6577

6678
#if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD)
6779
k_sem_give(&drv_data->gpio_sem);
@@ -108,8 +120,7 @@ static void bma280_thread_cb(void *arg)
108120
}
109121
}
110122

111-
gpio_pin_enable_callback(drv_data->gpio,
112-
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
123+
setup_int1(dev, true);
113124
}
114125

115126
#ifdef CONFIG_BMA280_TRIGGER_OWN_THREAD
@@ -220,8 +231,8 @@ int bma280_init_interrupt(struct device *dev)
220231

221232
gpio_pin_configure(drv_data->gpio,
222233
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
223-
GPIO_DIR_IN | GPIO_INT | GPIO_INT_LEVEL |
224-
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
234+
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_FLAGS
235+
| GPIO_INPUT);
225236

226237
gpio_init_callback(&drv_data->gpio_cb,
227238
bma280_gpio_callback,
@@ -265,6 +276,8 @@ int bma280_init_interrupt(struct device *dev)
265276
return -EIO;
266277
}
267278

279+
drv_data->dev = dev;
280+
268281
#if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD)
269282
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
270283

@@ -275,11 +288,9 @@ int bma280_init_interrupt(struct device *dev)
275288
0, K_NO_WAIT);
276289
#elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD)
277290
drv_data->work.handler = bma280_work_cb;
278-
drv_data->dev = dev;
279291
#endif
280292

281-
gpio_pin_enable_callback(drv_data->gpio,
282-
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN);
293+
setup_int1(dev, true);
283294

284295
return 0;
285296
}

0 commit comments

Comments
 (0)