Skip to content

Commit

Permalink
drivers: sensor: vl53l0x: fix XSHUT pin as active low
Browse files Browse the repository at this point in the history
Also utilises gpio_pin_configure_dt() API to configure and set pin
state at the same time.

Signed-off-by: Nick Ward <[email protected]>
  • Loading branch information
nixward authored and nashif committed May 27, 2023
1 parent 658ed40 commit c5f725e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion boards/arm/b_l4s5i_iot01a/b_l4s5i_iot01a.dts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
vl53l0x@29 {
compatible = "st,vl53l0x";
reg = <0x29>;
xshut-gpios = <&gpioc 6 GPIO_ACTIVE_HIGH>;
xshut-gpios = <&gpioc 6 GPIO_ACTIVE_LOW>;
};
};

Expand Down
2 changes: 1 addition & 1 deletion boards/arm/disco_l475_iot1/disco_l475_iot1.dts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
vl53l0x@29 {
compatible = "st,vl53l0x";
reg = <0x29>;
xshut-gpios = <&gpioc 6 GPIO_ACTIVE_HIGH>;
xshut-gpios = <&gpioc 6 GPIO_ACTIVE_LOW>;
};
};

Expand Down
6 changes: 3 additions & 3 deletions boards/shields/x_nucleo_53l0a1/x_nucleo_53l0a1.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
vl53l0x_c_x_nucleo_53l0a1: vl53l0x@30 {
compatible = "st,vl53l0x";
reg = <0x30>;
xshut-gpios = <&expander1_x_nucleo_53l0a1 15 0>;
xshut-gpios = <&expander1_x_nucleo_53l0a1 15 GPIO_ACTIVE_LOW>;
};

/* Satellites optional sensors */
vl53l0x_l_x_nucleo_53l0a1: vl53l0x@31 {
compatible = "st,vl53l0x";
reg = <0x31>;
xshut-gpios = <&expander2_x_nucleo_53l0a1 14 0>;
xshut-gpios = <&expander2_x_nucleo_53l0a1 14 GPIO_ACTIVE_LOW>;
};
vl53l0x_r_x_nucleo_53l0a1: vl53l0x@32 {
compatible = "st,vl53l0x";
reg = <0x32>;
xshut-gpios = <&expander2_x_nucleo_53l0a1 15 0>;
xshut-gpios = <&expander2_x_nucleo_53l0a1 15 GPIO_ACTIVE_LOW>;
};
};
20 changes: 7 additions & 13 deletions drivers/sensor/vl53l0x/vl53l0x.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,10 @@ static int vl53l0x_start(const struct device *dev)

LOG_DBG("[%s] Starting", dev->name);

/* Pull XSHUT high to start the sensor */
if (config->xshut.port) {
r = gpio_pin_set_dt(&config->xshut, 1);
r = gpio_pin_configure_dt(&config->xshut, GPIO_OUTPUT_INACTIVE);
if (r < 0) {
LOG_ERR("[%s] Unable to set XSHUT gpio (error %d)",
LOG_ERR("[%s] Unable to inactivate XSHUT: %d",
dev->name, r);
return -EIO;
}
Expand Down Expand Up @@ -326,17 +325,12 @@ static int vl53l0x_init(const struct device *dev)
}
#endif

if (config->xshut.port) {
r = gpio_pin_configure_dt(&config->xshut, GPIO_OUTPUT);
if (r < 0) {
LOG_ERR("[%s] Unable to configure GPIO as output",
dev->name);
}
}

#ifdef CONFIG_VL53L0X_RECONFIGURE_ADDRESS
/* Pull XSHUT low to shut down the sensor for now */
r = gpio_pin_set_dt(&config->xshut, 0);
/*
* Shutdown all vl53l0x sensors so at each sensor's 1st fetch call
* they can be enabled one at a time and programmed with their address.
*/
r = gpio_pin_configure_dt(&config->xshut, GPIO_OUTPUT_ACTIVE);
if (r < 0) {
LOG_ERR("[%s] Unable to shutdown sensor", dev->name);
return -EIO;
Expand Down
2 changes: 2 additions & 0 deletions dts/bindings/sensor/st,vl53l0x.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ include: [sensor-device.yaml, i2c-device.yaml]
properties:
xshut-gpios:
type: phandle-array
description: |
Xshutdown pin, Active LOW.

0 comments on commit c5f725e

Please sign in to comment.