diff --git a/drivers/sensor/vl53l1x/vl53l1.c b/drivers/sensor/vl53l1x/vl53l1.c index 714007a1a71fa3..351874233428eb 100644 --- a/drivers/sensor/vl53l1x/vl53l1.c +++ b/drivers/sensor/vl53l1x/vl53l1.c @@ -65,59 +65,56 @@ static VL53L1_Error vl53l1x_read_sensor(struct vl53l1x_data *drv_data) return VL53L1_ERROR_NONE; } +#ifdef CONFIG_VL53L1X_INTERRUPT_MODE static void vl53l1x_worker(struct k_work *work) { - if (IS_ENABLED(CONFIG_VL53L1X_INTERRUPT_MODE)) { - struct vl53l1x_data *drv_data = CONTAINER_OF(work, struct vl53l1x_data, work); + struct vl53l1x_data *drv_data = CONTAINER_OF(work, struct vl53l1x_data, work); - vl53l1x_read_sensor(drv_data); - } + vl53l1x_read_sensor(drv_data); } static void vl53l1x_gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { - if (IS_ENABLED(CONFIG_VL53L1X_INTERRUPT_MODE)) { - struct vl53l1x_data *drv_data = CONTAINER_OF(cb, struct vl53l1x_data, gpio_cb); + struct vl53l1x_data *drv_data = CONTAINER_OF(cb, struct vl53l1x_data, gpio_cb); - k_work_submit(&drv_data->work); - } + k_work_submit(&drv_data->work); } static int vl53l1x_init_interrupt(const struct device *dev) { - if (IS_ENABLED(CONFIG_VL53L1X_INTERRUPT_MODE)) { - struct vl53l1x_data *drv_data = dev->data; - const struct vl53l1x_config *config = dev->config; - int ret; - - drv_data->dev = dev; + struct vl53l1x_data *drv_data = dev->data; + const struct vl53l1x_config *config = dev->config; + int ret; - if (!gpio_is_ready_dt(&config->gpio1)) { - LOG_ERR("%s: device %s is not ready", dev->name, config->gpio1.port->name); - return -ENODEV; - } + drv_data->dev = dev; - ret = gpio_pin_configure_dt(&config->gpio1, GPIO_INPUT | GPIO_PULL_UP); - if (ret < 0) { - LOG_ERR("[%s] Unable to configure GPIO interrupt", dev->name); - return -EIO; - } + if (!gpio_is_ready_dt(&config->gpio1)) { + LOG_ERR("%s: device %s is not ready", dev->name, config->gpio1.port->name); + return -ENODEV; + } - gpio_init_callback(&drv_data->gpio_cb, - vl53l1x_gpio_callback, - BIT(config->gpio1.pin)); + ret = gpio_pin_configure_dt(&config->gpio1, GPIO_INPUT | GPIO_PULL_UP); + if (ret < 0) { + LOG_ERR("[%s] Unable to configure GPIO interrupt", dev->name); + return -EIO; + } - ret = gpio_add_callback(config->gpio1.port, &drv_data->gpio_cb); - if (ret < 0) { - LOG_ERR("Failed to set gpio callback!"); - return -EIO; - } + gpio_init_callback(&drv_data->gpio_cb, + vl53l1x_gpio_callback, + BIT(config->gpio1.pin)); - drv_data->work.handler = vl53l1x_worker; + ret = gpio_add_callback(config->gpio1.port, &drv_data->gpio_cb); + if (ret < 0) { + LOG_ERR("Failed to set gpio callback!"); + return -EIO; } + + drv_data->work.handler = vl53l1x_worker; + return 0; } +#endif static int vl53l1x_initialize(const struct device *dev) { @@ -304,7 +301,6 @@ static int vl53l1x_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct vl53l1x_data *drv_data = dev->data; - const struct vl53l1x_config *config = dev->config; VL53L1_Error ret; __ASSERT_NO_MSG((chan == SENSOR_CHAN_ALL) @@ -317,13 +313,15 @@ static int vl53l1x_sample_fetch(const struct device *dev, return -EBUSY; } - if (IS_ENABLED(CONFIG_VL53L1X_INTERRUPT_MODE)) { - ret = gpio_pin_interrupt_configure_dt(&config->gpio1, GPIO_INT_EDGE_TO_INACTIVE); - if (ret < 0) { - LOG_ERR("[%s] Unable to config interrupt", dev->name); - return -EIO; - } +#ifdef CONFIG_VL53L1X_INTERRUPT_MODE + const struct vl53l1x_config *config = dev->config; + + ret = gpio_pin_interrupt_configure_dt(&config->gpio1, GPIO_INT_EDGE_TO_INACTIVE); + if (ret < 0) { + LOG_ERR("[%s] Unable to config interrupt", dev->name); + return -EIO; } +#endif ret = VL53L1_StartMeasurement(&drv_data->vl53l1x); if (ret != VL53L1_ERROR_NONE) {