drivers: sensor: bma280: Update driver to use gpio_dt_spec
Simplify driver by using gpio_dt_spec for gpio access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
This commit is contained in:
parent
3be45afe79
commit
67d53d9232
3 changed files with 14 additions and 19 deletions
|
@ -164,6 +164,8 @@ static struct bma280_data bma280_inst_data;
|
|||
|
||||
static const struct bma280_config bma280_inst_config = {
|
||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||
IF_ENABLED(CONFIG_BMA280_TRIGGER,
|
||||
(.int1_gpio = GPIO_DT_SPEC_INST_GET(0, int1_gpios),))
|
||||
};
|
||||
|
||||
DEVICE_DT_INST_DEFINE(0, bma280_init, NULL, &bma280_inst_data,
|
||||
|
|
|
@ -120,7 +120,6 @@ struct bma280_data {
|
|||
|
||||
#ifdef CONFIG_BMA280_TRIGGER
|
||||
const struct device *dev;
|
||||
const struct device *gpio;
|
||||
struct gpio_callback gpio_cb;
|
||||
|
||||
struct sensor_trigger data_ready_trigger;
|
||||
|
@ -142,6 +141,9 @@ struct bma280_data {
|
|||
|
||||
struct bma280_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
#ifdef CONFIG_BMA280_TRIGGER
|
||||
struct gpio_dt_spec int1_gpio;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_BMA280_TRIGGER
|
||||
|
|
|
@ -20,13 +20,10 @@ LOG_MODULE_DECLARE(BMA280, CONFIG_SENSOR_LOG_LEVEL);
|
|||
static inline void setup_int1(const struct device *dev,
|
||||
bool enable)
|
||||
{
|
||||
struct bma280_data *data = dev->data;
|
||||
const struct bma280_config *config = dev->config;
|
||||
|
||||
gpio_pin_interrupt_configure(data->gpio,
|
||||
DT_INST_GPIO_PIN(0, int1_gpios),
|
||||
(enable
|
||||
? GPIO_INT_EDGE_TO_ACTIVE
|
||||
: GPIO_INT_DISABLE));
|
||||
gpio_pin_interrupt_configure_dt(&config->int1_gpio,
|
||||
(enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE));
|
||||
}
|
||||
|
||||
int bma280_attr_set(const struct device *dev,
|
||||
|
@ -220,24 +217,18 @@ int bma280_init_interrupt(const struct device *dev)
|
|||
}
|
||||
|
||||
/* setup data ready gpio interrupt */
|
||||
drv_data->gpio =
|
||||
device_get_binding(DT_INST_GPIO_LABEL(0, int1_gpios));
|
||||
if (drv_data->gpio == NULL) {
|
||||
LOG_DBG("Cannot get pointer to %s device",
|
||||
DT_INST_GPIO_LABEL(0, int1_gpios));
|
||||
return -EINVAL;
|
||||
if (!device_is_ready(config->int1_gpio.port)) {
|
||||
LOG_ERR("GPIO device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
gpio_pin_configure(drv_data->gpio,
|
||||
DT_INST_GPIO_PIN(0, int1_gpios),
|
||||
DT_INST_GPIO_FLAGS(0, int1_gpios)
|
||||
| GPIO_INPUT);
|
||||
gpio_pin_configure_dt(&config->int1_gpio, GPIO_INPUT);
|
||||
|
||||
gpio_init_callback(&drv_data->gpio_cb,
|
||||
bma280_gpio_callback,
|
||||
BIT(DT_INST_GPIO_PIN(0, int1_gpios)));
|
||||
BIT(config->int1_gpio.pin));
|
||||
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
if (gpio_add_callback(config->int1_gpio.port, &drv_data->gpio_cb) < 0) {
|
||||
LOG_DBG("Could not set gpio callback");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue