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 <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
573b322633
commit
cb37ed7830
3 changed files with 21 additions and 8 deletions
|
@ -332,8 +332,9 @@ const struct bmg160_device_config bmg160_config = {
|
||||||
.i2c_addr = DT_INST_0_BOSCH_BMG160_BASE_ADDRESS,
|
.i2c_addr = DT_INST_0_BOSCH_BMG160_BASE_ADDRESS,
|
||||||
.i2c_speed = BMG160_BUS_SPEED,
|
.i2c_speed = BMG160_BUS_SPEED,
|
||||||
#ifdef CONFIG_BMG160_TRIGGER
|
#ifdef CONFIG_BMG160_TRIGGER
|
||||||
.gpio_port = DT_INST_0_BOSCH_BMG160_INT_GPIOS_CONTROLLER,
|
|
||||||
.int_pin = DT_INST_0_BOSCH_BMG160_INT_GPIOS_PIN,
|
.int_pin = DT_INST_0_BOSCH_BMG160_INT_GPIOS_PIN,
|
||||||
|
.int_flags = DT_INST_0_BOSCH_BMG160_INT_GPIOS_FLAGS,
|
||||||
|
.gpio_port = DT_INST_0_BOSCH_BMG160_INT_GPIOS_CONTROLLER,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -179,13 +179,12 @@
|
||||||
|
|
||||||
struct bmg160_device_config {
|
struct bmg160_device_config {
|
||||||
const char *i2c_port;
|
const char *i2c_port;
|
||||||
#ifdef CONFIG_BMG160_TRIGGER
|
|
||||||
const char *gpio_port;
|
|
||||||
#endif
|
|
||||||
u16_t i2c_addr;
|
u16_t i2c_addr;
|
||||||
u8_t i2c_speed;
|
u8_t i2c_speed;
|
||||||
#ifdef CONFIG_BMG160_TRIGGER
|
#ifdef CONFIG_BMG160_TRIGGER
|
||||||
u8_t int_pin;
|
gpio_pin_t int_pin;
|
||||||
|
gpio_devicetree_flags_t int_flags;
|
||||||
|
const char *gpio_port;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,20 @@ extern struct bmg160_device_data bmg160_data;
|
||||||
#include <logging/log.h>
|
#include <logging/log.h>
|
||||||
LOG_MODULE_DECLARE(BMG160, CONFIG_SENSOR_LOG_LEVEL);
|
LOG_MODULE_DECLARE(BMG160, CONFIG_SENSOR_LOG_LEVEL);
|
||||||
|
|
||||||
|
static inline void setup_int(struct device *dev,
|
||||||
|
bool enable)
|
||||||
|
{
|
||||||
|
struct bmg160_device_data *data = dev->driver_data;
|
||||||
|
const struct bmg160_device_config *const cfg =
|
||||||
|
dev->config->config_info;
|
||||||
|
|
||||||
|
gpio_pin_interrupt_configure(data->gpio,
|
||||||
|
cfg->int_pin,
|
||||||
|
enable
|
||||||
|
? GPIO_INT_EDGE_TO_ACTIVE
|
||||||
|
: GPIO_INT_DISABLE);
|
||||||
|
}
|
||||||
|
|
||||||
static void bmg160_gpio_callback(struct device *port, struct gpio_callback *cb,
|
static void bmg160_gpio_callback(struct device *port, struct gpio_callback *cb,
|
||||||
u32_t pin)
|
u32_t pin)
|
||||||
{
|
{
|
||||||
|
@ -244,12 +258,11 @@ int bmg160_trigger_init(struct device *dev)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gpio_pin_configure(bmg160->gpio, cfg->int_pin,
|
gpio_pin_configure(bmg160->gpio, cfg->int_pin,
|
||||||
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
|
cfg->int_flags | GPIO_INT_EDGE_TO_ACTIVE);
|
||||||
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
|
|
||||||
gpio_init_callback(&bmg160->gpio_cb, bmg160_gpio_callback,
|
gpio_init_callback(&bmg160->gpio_cb, bmg160_gpio_callback,
|
||||||
BIT(cfg->int_pin));
|
BIT(cfg->int_pin));
|
||||||
gpio_add_callback(bmg160->gpio, &bmg160->gpio_cb);
|
gpio_add_callback(bmg160->gpio, &bmg160->gpio_cb);
|
||||||
gpio_pin_enable_callback(bmg160->gpio, cfg->int_pin);
|
setup_int(dev, true);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue