This commit is contained in:
2026-04-08 12:49:16 +08:00
parent fda081c1f0
commit ff467d26bc
13 changed files with 781 additions and 727 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -51,11 +51,14 @@ VL53L1_Error VL53L1_platform_init(
VL53L1_Error status = VL53L1_ERROR_NONE;
if (pdev == NULL)
return VL53L1_ERROR_INVALID_PARAMS;
/* remember comms settings */
pdev->i2c_slave_address = i2c_slave_address;
pdev->i2c_slave_address = (i2c_slave_address == 0u) ? VL53L1_DEFAULT_ADDR_8BIT : i2c_slave_address;
pdev->comms_type = comms_type;
pdev->comms_speed_khz = comms_speed_khz;
pdev->comms_speed_khz = (comms_speed_khz == 0u) ? 400u : comms_speed_khz;
if (status == VL53L1_ERROR_NONE) /*lint !e774 always true*/
status =
@@ -64,37 +67,13 @@ VL53L1_Error VL53L1_platform_init(
pdev->comms_type,
pdev->comms_speed_khz);
/* Ensure device is in reset */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_GpioXshutdown(0);
pdev->io_timeout_ms = (pdev->io_timeout_ms == 0u) ? 100u : pdev->io_timeout_ms;
/* disable the platform regulators */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_GpioPowerEnable(0);
/* set the NCS pin for I2C mode */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_GpioCommsSelect(0);
/* 1ms Wait to ensure XSHUTD / NCS are in the right state */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_WaitUs(pdev, 1000);
/* enable the platform regulators */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_GpioPowerEnable(1);
/* 1ms Wait for power regs to settle */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_WaitUs(pdev, 1000);
/* finally, bring the device out of reset */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_GpioXshutdown(1);
/* Wait 100us for device to exit reset */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_WaitUs(pdev, 100);
if ((status == VL53L1_ERROR_NONE) && (pdev->xshut_port != NULL)) {
status = VL53L1_PlatformBootDevice(pdev, 2u, 2u);
} else if (status == VL53L1_ERROR_NONE) {
status = VL53L1_WaitMs(pdev, 2);
}
return status;
}
@@ -110,13 +89,9 @@ VL53L1_Error VL53L1_platform_terminate(
VL53L1_Error status = VL53L1_ERROR_NONE;
/* put device in reset */
if (status == VL53L1_ERROR_NONE) /*lint !e774 always true*/
status = VL53L1_GpioXshutdown(0);
/* disable the platform regulators */
if (status == VL53L1_ERROR_NONE)
status = VL53L1_GpioPowerEnable(0);
/* put device in reset when an XSHUT pin is attached */
if ((status == VL53L1_ERROR_NONE) && (pdev != NULL) && (pdev->xshut_port != NULL))
status = VL53L1_PlatformSetXShut(pdev, GPIO_PIN_RESET);
/* close the comms interfaces */
if (status == VL53L1_ERROR_NONE)

View File

@@ -20,7 +20,7 @@
#include <stdio.h> // sprintf(), vsnprintf(), printf()
#include <string.h>
#include <stdarg.h>
#include <malloc.h>
#include <stdlib.h>
#include "vl53l1_platform_log.h"
#include "vl53l1_platform_user_config.h"