drivers: sensor: bmg160: Update driver to use gpio_dt_spec
Simplify driver by using gpio_dt_spec for bus access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
parent
0db8f22892
commit
4974a2d165
3 changed files with 12 additions and 25 deletions
|
@ -335,11 +335,8 @@ int bmg160_init(const struct device *dev)
|
|||
|
||||
static const struct bmg160_device_config bmg160_config = {
|
||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||
#ifdef CONFIG_BMG160_TRIGGER
|
||||
.int_pin = DT_INST_GPIO_PIN(0, int_gpios),
|
||||
.int_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
|
||||
.gpio_port = DT_INST_GPIO_LABEL(0, int_gpios),
|
||||
#endif
|
||||
IF_ENABLED(CONFIG_BMG160_TRIGGER,
|
||||
(.int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios),))
|
||||
};
|
||||
|
||||
DEVICE_DT_INST_DEFINE(0, bmg160_init, NULL,
|
||||
|
|
|
@ -180,16 +180,13 @@
|
|||
struct bmg160_device_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
#ifdef CONFIG_BMG160_TRIGGER
|
||||
gpio_pin_t int_pin;
|
||||
gpio_dt_flags_t int_flags;
|
||||
const char *gpio_port;
|
||||
struct gpio_dt_spec int_gpio;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct bmg160_device_data {
|
||||
#ifdef CONFIG_BMG160_TRIGGER
|
||||
const struct device *dev;
|
||||
const struct device *gpio;
|
||||
struct gpio_callback gpio_cb;
|
||||
#endif
|
||||
#ifdef CONFIG_BMG160_TRIGGER_OWN_THREAD
|
||||
|
|
|
@ -21,15 +21,10 @@ LOG_MODULE_DECLARE(BMG160, CONFIG_SENSOR_LOG_LEVEL);
|
|||
static inline int setup_int(const struct device *dev,
|
||||
bool enable)
|
||||
{
|
||||
struct bmg160_device_data *data = dev->data;
|
||||
const struct bmg160_device_config *const cfg =
|
||||
dev->config;
|
||||
const struct bmg160_device_config *cfg = dev->config;
|
||||
|
||||
return gpio_pin_interrupt_configure(data->gpio,
|
||||
cfg->int_pin,
|
||||
enable
|
||||
? GPIO_INT_EDGE_TO_ACTIVE
|
||||
: GPIO_INT_DISABLE);
|
||||
return gpio_pin_interrupt_configure_dt(&cfg->int_gpio,
|
||||
enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE);
|
||||
}
|
||||
|
||||
static void bmg160_gpio_callback(const struct device *port,
|
||||
|
@ -237,10 +232,9 @@ int bmg160_trigger_init(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
bmg160->gpio = device_get_binding((char *)cfg->gpio_port);
|
||||
if (!bmg160->gpio) {
|
||||
LOG_DBG("Gpio controller %s not found", cfg->gpio_port);
|
||||
return -EINVAL;
|
||||
if (!device_is_ready(cfg->int_gpio.port)) {
|
||||
LOG_ERR("GPIO device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
bmg160->dev = dev;
|
||||
|
@ -258,16 +252,15 @@ int bmg160_trigger_init(const struct device *dev)
|
|||
bmg160->work.handler = bmg160_work_cb;
|
||||
#endif
|
||||
|
||||
ret = gpio_pin_configure(bmg160->gpio, cfg->int_pin,
|
||||
cfg->int_flags | GPIO_INT_EDGE_TO_ACTIVE);
|
||||
ret = gpio_pin_configure_dt(&cfg->int_gpio, GPIO_INT_EDGE_TO_ACTIVE);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
gpio_init_callback(&bmg160->gpio_cb, bmg160_gpio_callback,
|
||||
BIT(cfg->int_pin));
|
||||
BIT(cfg->int_gpio.pin));
|
||||
|
||||
ret = gpio_add_callback(bmg160->gpio, &bmg160->gpio_cb);
|
||||
ret = gpio_add_callback(cfg->int_gpio.port, &bmg160->gpio_cb);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue