Skip to content

Commit e8ecc70

Browse files
committed
drivers: sensor: bmg160: 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 1b1f7bc commit e8ecc70

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

drivers/sensor/bmg160/bmg160.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,9 @@ const struct bmg160_device_config bmg160_config = {
332332
.i2c_addr = DT_INST_0_BOSCH_BMG160_BASE_ADDRESS,
333333
.i2c_speed = BMG160_BUS_SPEED,
334334
#ifdef CONFIG_BMG160_TRIGGER
335-
.gpio_port = DT_INST_0_BOSCH_BMG160_INT_GPIOS_CONTROLLER,
336335
.int_pin = DT_INST_0_BOSCH_BMG160_INT_GPIOS_PIN,
336+
.int_flags = DT_INST_0_BOSCH_BMG160_INT_GPIOS_FLAGS,
337+
.gpio_port = DT_INST_0_BOSCH_BMG160_INT_GPIOS_CONTROLLER,
337338
#endif
338339
};
339340

drivers/sensor/bmg160/bmg160.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,12 @@
179179

180180
struct bmg160_device_config {
181181
const char *i2c_port;
182-
#ifdef CONFIG_BMG160_TRIGGER
183-
const char *gpio_port;
184-
#endif
185182
u16_t i2c_addr;
186183
u8_t i2c_speed;
187184
#ifdef CONFIG_BMG160_TRIGGER
188-
u8_t int_pin;
185+
gpio_pin_t int_pin;
186+
gpio_devicetree_flags_t int_flags;
187+
const char *gpio_port;
189188
#endif
190189
};
191190

drivers/sensor/bmg160/bmg160_trigger.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ extern struct bmg160_device_data bmg160_data;
1818
#include <logging/log.h>
1919
LOG_MODULE_DECLARE(BMG160, CONFIG_SENSOR_LOG_LEVEL);
2020

21+
static inline void setup_int(struct device *dev,
22+
bool enable)
23+
{
24+
struct bmg160_device_data *data = dev->driver_data;
25+
const struct bmg160_device_config *const cfg =
26+
dev->config->config_info;
27+
28+
gpio_pin_interrupt_configure(data->gpio,
29+
cfg->int_pin,
30+
enable
31+
? GPIO_INT_EDGE_TO_ACTIVE
32+
: GPIO_INT_DISABLE);
33+
}
34+
2135
static void bmg160_gpio_callback(struct device *port, struct gpio_callback *cb,
2236
u32_t pin)
2337
{
@@ -244,12 +258,11 @@ int bmg160_trigger_init(struct device *dev)
244258
#endif
245259

246260
gpio_pin_configure(bmg160->gpio, cfg->int_pin,
247-
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
248-
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
261+
cfg->int_flags | GPIO_INT_EDGE_TO_ACTIVE);
249262
gpio_init_callback(&bmg160->gpio_cb, bmg160_gpio_callback,
250263
BIT(cfg->int_pin));
251264
gpio_add_callback(bmg160->gpio, &bmg160->gpio_cb);
252-
gpio_pin_enable_callback(bmg160->gpio, cfg->int_pin);
265+
setup_int(dev, true);
253266

254267
return 0;
255268
}

0 commit comments

Comments
 (0)