drivers: sensor: bmc150_magn: 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
c145539b54
commit
8c2a6e34a8
3 changed files with 11 additions and 25 deletions
|
@ -587,11 +587,8 @@ static int bmc150_magn_init(const struct device *dev)
|
|||
|
||||
static const struct bmc150_magn_config bmc150_magn_config = {
|
||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
|
||||
.gpio_drdy_dev_name = DT_INST_GPIO_LABEL(0, drdy_gpios),
|
||||
.gpio_drdy_int_pin = DT_INST_GPIO_PIN(0, drdy_gpios),
|
||||
.gpio_drdy_int_flags = DT_INST_GPIO_FLAGS(0, drdy_gpios),
|
||||
#endif
|
||||
IF_ENABLED(CONFIG_BMC150_MAGN_TRIGGER_DRDY,
|
||||
(.int_gpio = GPIO_DT_SPEC_INST_GET(0, drdy_gpios),))
|
||||
};
|
||||
|
||||
static struct bmc150_magn_data bmc150_magn_data;
|
||||
|
|
|
@ -86,9 +86,7 @@
|
|||
struct bmc150_magn_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
|
||||
char *gpio_drdy_dev_name;
|
||||
gpio_pin_t gpio_drdy_int_pin;
|
||||
gpio_dt_flags_t gpio_drdy_int_flags;
|
||||
struct gpio_dt_spec int_gpio;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -18,15 +18,11 @@ LOG_MODULE_DECLARE(BMC150_MAGN, CONFIG_SENSOR_LOG_LEVEL);
|
|||
static inline void setup_drdy(const struct device *dev,
|
||||
bool enable)
|
||||
{
|
||||
struct bmc150_magn_data *data = dev->data;
|
||||
const struct bmc150_magn_config *const cfg =
|
||||
dev->config;
|
||||
|
||||
gpio_pin_interrupt_configure(data->gpio_drdy,
|
||||
cfg->gpio_drdy_int_pin,
|
||||
enable
|
||||
? GPIO_INT_EDGE_TO_ACTIVE
|
||||
: GPIO_INT_DISABLE);
|
||||
gpio_pin_interrupt_configure_dt(&cfg->int_gpio,
|
||||
enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,7 +101,6 @@ static void bmc150_magn_thread_main(struct bmc150_magn_data *data)
|
|||
|
||||
static int bmc150_magn_set_drdy_polarity(const struct device *dev, int state)
|
||||
{
|
||||
struct bmc150_magn_data *data = dev->data;
|
||||
const struct bmc150_magn_config *config = dev->config;
|
||||
|
||||
if (state) {
|
||||
|
@ -150,22 +145,18 @@ int bmc150_magn_init_interrupt(const struct device *dev)
|
|||
data, NULL, NULL,
|
||||
K_PRIO_COOP(10), 0, K_NO_WAIT);
|
||||
|
||||
data->gpio_drdy = device_get_binding(config->gpio_drdy_dev_name);
|
||||
if (!data->gpio_drdy) {
|
||||
LOG_DBG("gpio controller %s not found",
|
||||
config->gpio_drdy_dev_name);
|
||||
return -EINVAL;
|
||||
if (!device_is_ready(config->int_gpio.port)) {
|
||||
LOG_ERR("GPIO device not ready");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
gpio_pin_configure(data->gpio_drdy, config->gpio_drdy_int_pin,
|
||||
config->gpio_drdy_int_flags
|
||||
| GPIO_INT_EDGE_TO_ACTIVE);
|
||||
gpio_pin_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE);
|
||||
|
||||
gpio_init_callback(&data->gpio_cb,
|
||||
bmc150_magn_gpio_drdy_callback,
|
||||
BIT(config->gpio_drdy_int_pin));
|
||||
BIT(config->int_gpio.pin));
|
||||
|
||||
if (gpio_add_callback(data->gpio_drdy, &data->gpio_cb) < 0) {
|
||||
if (gpio_add_callback(config->int_gpio.port, &data->gpio_cb) < 0) {
|
||||
LOG_DBG("failed to set gpio callback");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue