drivers: sensor: icm42605: convert to usinggpio_dt_spec

for the interrupt gpio, now use gpio_dt_spec instead of raw gpio.

Signed-off-by: Mikkel Jakobsen <mikkel.aunsbjerg@escolifesciences.com>
This commit is contained in:
Mikkel Jakobsen 2022-03-16 08:31:14 +01:00 committed by Maureen Helm
commit f502d21634
3 changed files with 12 additions and 32 deletions

View file

@ -434,9 +434,7 @@ static const struct sensor_driver_api icm42605_driver_api = {
SPI_WORD_SET(8) | \
SPI_TRANSFER_MSB, \
0U), \
.int_label = DT_INST_GPIO_LABEL(index, int_gpios), \
.int_pin = DT_INST_GPIO_PIN(index, int_gpios), \
.int_flags = DT_INST_GPIO_FLAGS(index, int_gpios), \
.gpio_int = GPIO_DT_SPEC_INST_GET(index, int_gpios), \
.accel_hz = DT_INST_PROP(index, accel_hz), \
.gyro_hz = DT_INST_PROP(index, gyro_hz), \
.accel_fs = DT_INST_ENUM_IDX(index, accel_fs), \

View file

@ -44,7 +44,6 @@ struct icm42605_data {
bool sensor_started;
const struct device *dev;
const struct device *gpio;
struct gpio_callback gpio_cb;
struct sensor_trigger data_ready_trigger;
@ -65,12 +64,7 @@ struct icm42605_data {
struct icm42605_config {
struct spi_dt_spec spi;
uint8_t int_pin;
uint8_t int_flags;
const char *int_label;
const char *gpio_label;
gpio_pin_t gpio_pin;
gpio_dt_flags_t gpio_dt_flags;
struct gpio_dt_spec gpio_int;
uint16_t accel_hz;
uint16_t gyro_hz;
uint16_t accel_fs;

View file

@ -28,8 +28,7 @@ int icm42605_trigger_set(const struct device *dev,
return -ENOTSUP;
}
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_pin,
GPIO_INT_DISABLE);
gpio_pin_interrupt_configure_dt(&cfg->gpio_int, GPIO_INT_DISABLE);
if (handler == NULL) {
icm42605_turn_off_sensor(dev);
@ -51,8 +50,7 @@ int icm42605_trigger_set(const struct device *dev,
return -ENOTSUP;
}
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_pin,
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_interrupt_configure_dt(&cfg->gpio_int, GPIO_INT_EDGE_TO_ACTIVE);
icm42605_turn_on_sensor(dev);
@ -68,8 +66,7 @@ static void icm42605_gpio_callback(const struct device *dev,
ARG_UNUSED(pins);
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_pin,
GPIO_INT_DISABLE);
gpio_pin_interrupt_configure_dt(&cfg->gpio_int, GPIO_INT_DISABLE);
k_sem_give(&drv_data->gpio_sem);
}
@ -89,8 +86,7 @@ static void icm42605_thread_cb(const struct device *dev)
icm42605_tap_fetch(dev);
}
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_pin,
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_interrupt_configure_dt(&cfg->gpio_int, GPIO_INT_EDGE_TO_ACTIVE);
}
static void icm42605_thread(int dev_ptr, int unused)
@ -112,24 +108,17 @@ int icm42605_init_interrupt(const struct device *dev)
const struct icm42605_config *cfg = dev->config;
int result = 0;
/* setup data ready gpio interrupt */
drv_data->gpio = device_get_binding(cfg->int_label);
if (drv_data->gpio == NULL) {
LOG_ERR("Failed to get pointer to %s device",
cfg->int_label);
if (!device_is_ready(cfg->gpio_int.port)) {
LOG_ERR("gpio_int gpio not ready");
return -ENODEV;
}
drv_data->dev = dev;
gpio_pin_configure(drv_data->gpio, cfg->int_pin,
GPIO_INPUT | cfg->int_flags);
gpio_pin_configure_dt(&cfg->gpio_int, GPIO_INPUT);
gpio_init_callback(&drv_data->gpio_cb, icm42605_gpio_callback, BIT(cfg->gpio_int.pin));
result = gpio_add_callback(cfg->gpio_int.port, &drv_data->gpio_cb);
gpio_init_callback(&drv_data->gpio_cb,
icm42605_gpio_callback,
BIT(cfg->int_pin));
result = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
if (result < 0) {
LOG_ERR("Failed to set gpio callback");
return result;
@ -143,8 +132,7 @@ int icm42605_init_interrupt(const struct device *dev)
0, NULL, K_PRIO_COOP(CONFIG_ICM42605_THREAD_PRIORITY),
0, K_NO_WAIT);
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_pin,
GPIO_INT_EDGE_TO_INACTIVE);
gpio_pin_interrupt_configure_dt(&cfg->gpio_int, GPIO_INT_EDGE_TO_INACTIVE);
return 0;
}