Skip to content

Commit

Permalink
sensors: vl53l1: fix compilation without xshut or interrupt pin
Browse files Browse the repository at this point in the history
Fix compilation when CONFIG_VL53L1X_INTERRUPT_MODE=n or
CONFIG_VL53L1X_XSHUT=n

Signed-off-by: Cyril Fougeray <cyril.fougeray@worldcoin.org>
  • Loading branch information
fouge authored and fabiobaltieri committed Oct 11, 2023
1 parent 1d0f287 commit 49126e2
Showing 1 changed file with 37 additions and 39 deletions.
76 changes: 37 additions & 39 deletions drivers/sensor/vl53l1x/vl53l1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand 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) {
Expand Down

0 comments on commit 49126e2

Please sign in to comment.