Lecture des données en 4x4

This commit is contained in:
Samuel 2023-10-21 09:48:27 +02:00
commit 19d50b56fa
30 changed files with 28570 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/

39
CMakeLists.txt Normal file
View File

@ -0,0 +1,39 @@
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(VL53L8CX C CXX ASM)
set(CMAKE_C_STNDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(PICO_EXAMPLES_PATH ${PROJECT_SOURCE_DIR})
pico_sdk_init()
add_executable(VL53L8CX
main.c
VL53L8CX_ULD_API/src/vl53l8cx_api.c
VL53L8CX_ULD_API/src/vl53l8cx_plugin_detection_thresholds.c
VL53L8CX_ULD_API/src/vl53l8cx_plugin_motion_indicator.c
VL53L8CX_ULD_API/src/vl53l8cx_plugin_xtalk.c
Platform/platform.c
)
target_include_directories(VL53L8CX PRIVATE VL53L8CX_ULD_API/inc/)
target_link_libraries(VL53L8CX
hardware_i2c
hardware_uart
pico_stdlib
pico_multicore
)
pico_enable_stdio_usb(VL53L8CX 1)
pico_enable_stdio_uart(VL53L8CX 1)
pico_add_extra_outputs(VL53L8CX)
add_custom_target(Flash
DEPENDS VL53L8CX
COMMAND sudo picotool load -f ${PROJECT_BINARY_DIR}/VL53L8CX.uf2
)

Binary file not shown.

View File

@ -0,0 +1,204 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD motion indicator */
/***********************************/
/*
* This example shows the VL53L8CX motion indicator capabilities.
* To use this example, user needs to be sure that macro
* VL53L8CX_DISABLE_MOTION_INDICATOR is NOT enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
#include "vl53l8cx_plugin_motion_indicator.h"
int example10(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Program motion indicator */
/*********************************/
/* Create motion indicator with resolution 4x4 */
status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_4X4);
if(status)
{
printf("Motion indicator init failed with status : %u\n", status);
return status;
}
/* (Optional) Change the min and max distance used to detect motions. The
* difference between min and max must never be >1500mm, and minimum never be <400mm,
* otherwise the function below returns error 127 */
status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000);
if(status)
{
printf("Motion indicator set distance motion failed with status : %u\n", status);
return status;
}
/* If user want to change the resolution, he also needs to update the motion indicator resolution */
//status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_4X4);
//status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_4X4);
/* Increase ranging frequency for the example */
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 2);
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Motion power : %3lu\n",
i,
Results.motion_indicator.motion[motion_config.map_id[i]]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,257 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/************************************************************/
/* VL53L8CX ULD motion indicator with detection thresholds */
/************************************************************/
/*
* This example shows how to use the motion indicator with detection threshold.
* This kind of configuration might be used for user detection applications.
* To use this example, user needs to be sure that macro
* VL53L8CX_DISABLE_MOTION_INDICATOR is NOT enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
#include "vl53l8cx_plugin_motion_indicator.h"
#include "vl53l8cx_plugin_detection_thresholds.h"
#define UNUSED(x) (void)(x)
/* This function needs to be filled by the customer. It allows knowing when
* the VL53L8CX interrupt is raised on GPIO1. This is the only way to use detection thresholds.
*/
int WaitForL8CXInterrupt(VL53L8CX_Configuration * pDev) {
//Add your implementation here ...
UNUSED(pDev);
return 0;
}
int example11(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_Motion_Configuration motion_config; /* Motion configuration*/
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Program motion indicator */
/*********************************/
/* Create motion indicator with resolution 8x8 */
status = vl53l8cx_motion_indicator_init(&Dev, &motion_config, VL53L8CX_RESOLUTION_8X8);
if(status)
{
printf("Motion indicator init failed with status : %u\n", status);
return status;
}
/* (Optional) Change the min and max distance used to detect motions. The
* difference between min and max must never be >1500mm, and minimum never be <400mm,
* otherwise the function below returns error 127 */
status = vl53l8cx_motion_indicator_set_distance_motion(&Dev, &motion_config, 1000, 2000);
if(status)
{
printf("Motion indicator set distance motion failed with status : %u\n", status);
return status;
}
/* If user want to change the resolution, he also needs to update the motion indicator resolution */
//status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_4X4);
//status = vl53l8cx_motion_indicator_set_resolution(&Dev, &motion_config, VL53L8CX_RESOLUTION_4X4);
/* Set the device in AUTONOMOUS and set a small integration time to reduce power consumption */
status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8);
status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS);
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 2);
status = vl53l8cx_set_integration_time_ms(&Dev, 10);
/*********************************/
/* Program detection thresholds */
/*********************************/
/* In this example, we want 1 thresholds per zone for a 8x8 resolution */
/* Create array of thresholds (size cannot be changed) */
VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS];
/* Set all values to 0 */
memset(&thresholds, 0, sizeof(thresholds));
/* Add thresholds for all zones (64 zones in resolution 4x4, or 64 in 8x8) */
for(i = 0; i < 64; i++){
thresholds[i].zone_num = i;
thresholds[i].measurement = VL53L8CX_MOTION_INDICATOR;
thresholds[i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER;
thresholds[i].mathematic_operation = VL53L8CX_OPERATION_NONE;
/* The value 44 is given as example. All motion above 44 will be considered as a movement */
thresholds[i].param_low_thresh = 44;
thresholds[i].param_high_thresh = 44;
}
/* The last thresholds must be clearly indicated. As we have 64
* checkers, the last one is the 63 */
thresholds[63].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[63].zone_num;
/* Send array of thresholds to the sensor */
vl53l8cx_set_detection_thresholds(&Dev, thresholds);
/* Enable detection thresholds */
vl53l8cx_set_detection_thresholds_enable(&Dev, 1);
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
printf("Waiting for a movement into the FOV between 1m and 2m...\n");
loop = 0;
while(loop < 10)
{
/* Function WaitForL8CXInterrupt() does not exists, and must be
* implemented by user. It allows catching the interrupt raised on
* pin A1 (INT), when the checkers detect the programmed
* conditions.
*/
isReady = WaitForL8CXInterrupt(&Dev);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 8x8 mode by default, we have a total
* of 64 zones to print. For this example, only the data of first zone are
* print */
for(i = 0; i < 64; i++)
{
if(Results.motion_indicator.motion[motion_config.map_id[i]] >= 44)
{
printf(" Movement detected in this zone : %3d !\n", i);
}
}
printf("\n");
loop++;
}
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,179 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD basic example */
/***********************************/
/*
* This example is the most basic. It initializes the VL53L8CX ULD, and starts
* a ranging to capture 10 frames.
*
* By default, ULD is configured to have the following settings :
* - Resolution 4x4
* - Ranging period 1Hz
*
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
int example1(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,220 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD get/set params */
/***********************************/
/*
* This example shows the possibility of VL53L8CX to get/set params. It
* initializes the VL53L8CX ULD, set a configuration, and starts
* a ranging to capture 10 frames.
*
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
int example2(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
uint32_t integration_time_ms;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Set some params */
/*********************************/
/* Set resolution in 8x8. WARNING : As others settings depend to this
* one, it must be the first to use.
*/
status = vl53l8cx_set_resolution(&Dev, VL53L8CX_RESOLUTION_8X8);
if(status)
{
printf("vl53l8cx_set_resolution failed, status %u\n", status);
return status;
}
/* Set ranging frequency to 10Hz.
* Using 4x4, min frequency is 1Hz and max is 60Hz
* Using 8x8, min frequency is 1Hz and max is 15Hz
*/
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10);
if(status)
{
printf("vl53l8cx_set_ranging_frequency_hz failed, status %u\n", status);
return status;
}
/* Set target order to closest */
status = vl53l8cx_set_target_order(&Dev, VL53L8CX_TARGET_ORDER_CLOSEST);
if(status)
{
printf("vl53l8cx_set_target_order failed, status %u\n", status);
return status;
}
/* Get current integration time */
status = vl53l8cx_get_integration_time_ms(&Dev, &integration_time_ms);
if(status)
{
printf("vl53l8cx_get_integration_time_ms failed, status %u\n", status);
return status;
}
printf("Current integration time is : %d ms\n", (int)integration_time_ms);
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 8x8 mode, we have a total
* of 64 zones to print. For this example, only the data of
* first zone are print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 64; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,239 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD ranging mode */
/***********************************/
/*
* This example shows the differences between ranging modes of VL53L8CX
* (mode continuous and autonomous). For both modes, it initializes the VL53L8CX
* ULD, set the mode, and starts a ranging to capture 10 frames.
*
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
int example3(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Set ranging mode autonomous */
/*********************************/
status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_AUTONOMOUS);
if(status)
{
printf("vl53l8cx_set_ranging_mode failed, status %u\n", status);
return status;
}
/* Using autonomous mode, the integration time can be updated (not possible
* using continuous) */
status = vl53l8cx_set_integration_time_ms(&Dev, 20);
/* Start a ranging session */
status = vl53l8cx_start_ranging(&Dev);
printf("Start ranging autonomous\n");
loop = 0;
while(loop < 10)
{
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("Stop ranging autonomous\n");
WaitMs(&(Dev.platform), 1);
/*********************************/
/* Set ranging mode continuous */
/*********************************/
/* In continuous mode, the integration time cannot be programmed
* (automatically set to maximum value) */
status = vl53l8cx_set_ranging_mode(&Dev, VL53L8CX_RANGING_MODE_CONTINUOUS);
if(status)
{
printf("vl53l8cx_set_ranging_mode failed, status %u\n", status);
return status;
}
/* Trying to update value below will have no impact on integration time */
//status = vl53l8cx_set_integration_time_ms(&Dev, 20);
/* Start a ranging session */
status = vl53l8cx_start_ranging(&Dev);
printf("Start ranging continuous\n");
loop = 0;
while(loop < 10)
{
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("Stop ranging continuous\n");
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,203 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD power mode */
/***********************************/
/*
* This example shows the possibility of VL53L8CX to change power mode. It
* initializes the VL53L8CX ULD, set a configuration, change the power mode, and
* starts a ranging to capture 10 frames.
*
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
int example4(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Change the power mode */
/*********************************/
/* For the example, we don't want to use the sensor during 10 seconds. In order to reduce
* the power consumption, the sensor is set to low power mode.
*/
status = vl53l8cx_set_power_mode(&Dev, VL53L8CX_POWER_MODE_SLEEP);
if(status)
{
printf("vl53l8cx_set_power_mode failed, status %u\n", status);
return status;
}
printf("VL53L8CX is now sleeping\n");
/* We wait 5 seconds, only for the example */
printf("Waiting 5 seconds for the example...\n");
WaitMs(&(Dev.platform), 5000);
/* After 5 seconds, the sensor needs to be restarted */
status = vl53l8cx_set_power_mode(&Dev, VL53L8CX_POWER_MODE_WAKEUP);
if(status)
{
printf("vl53l8cx_set_power_mode failed, status %u\n", status);
return status;
}
printf("VL53L8CX is now waking up\n");
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,195 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD multiple targets */
/***********************************/
/*
* This example shows the possibility of VL53L8CX to get/set params. It
* initializes the VL53L8CX ULD, set a configuration, and starts
* a ranging to capture 10 frames.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
int example5(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i, j;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Set nb target per zone */
/*********************************/
/* Each zone can output between 1 and 4 targets. By default the output
* is set to 1 targets, but user can change it using macro
* VL53L8CX_NB_TARGET_PER_ZONE located in file 'platform.h'.
*/
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
/* Print per zone results. These results are the same for all targets */
printf("Zone %3u : %2u, %6lu, %6lu, ",
i,
Results.nb_target_detected[i],
Results.ambient_per_spad[i],
Results.nb_spads_enabled[i]);
for(j = 0; j < VL53L8CX_NB_TARGET_PER_ZONE; j++)
{
/* Print per target results. These results depends of the target nb */
uint16_t idx = VL53L8CX_NB_TARGET_PER_ZONE * i + j;
printf("Target[%1u] : %2u, %4d, %6lu, %3u, ",
j,
Results.target_status[idx],
Results.distance_mm[idx],
Results.signal_per_spad[idx],
Results.range_sigma_mm[idx]);
}
printf("\n");
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,195 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/**************************************/
/* VL53L8CX ULD I2C/RAM optimization */
/**************************************/
/*
* This example shows the possibility of VL53L8CX to reduce I2C transactions
* and RAM footprint. It initializes the VL53L8CX ULD, and starts
* a ranging to capture 10 frames.
*
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
int example6(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Reduce RAM & I2C access */
/*********************************/
/* Results can be tuned in order to reduce I2C access and RAM footprints.
* The 'platform.h' file contains macros used to disable output. If user declare
* one of these macros, the results will not be sent through I2C, and the array will not
* be created into the VL53L8CX_ResultsData structure.
* For the minimum size, ST recommends 1 targets per zone, and only keep distance_mm,
* target_status, and nb_target_detected. The following macros can be defined into file 'platform.h':
*
* #define VL53L8CX_DISABLE_AMBIENT_PER_SPAD
* #define VL53L8CX_DISABLE_NB_SPADS_ENABLED
* #define VL53L8CX_DISABLE_SIGNAL_PER_SPAD
* #define VL53L8CX_DISABLE_RANGE_SIGMA_MM
* #define VL53L8CX_DISABLE_REFLECTANCE_PERCENT
* #define VL53L8CX_DISABLE_MOTION_INDICATOR
*/
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,205 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD calibrate Xtalk */
/***********************************/
/*
* This example shows the possibility of VL53L8CX to calibrate Xtalk. It
* initializes the VL53L8CX ULD, perform a Xtalk calibration, and starts
* a ranging to capture 10 frames.
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
#include "vl53l8cx_plugin_xtalk.h"
int example7(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/* Buffer containing Xtalk data */
uint8_t xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE];
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Start Xtalk calibration */
/*********************************/
/* Start Xtalk calibration with a 3% reflective target at 600mm for the
* sensor, using 4 samples.
*/
printf("Running Xtalk calibration...\n");
status = vl53l8cx_calibrate_xtalk(&Dev, 3, 4, 600);
if(status)
{
printf("vl53l8cx_calibrate_xtalk failed, status %u\n", status);
return status;
}else
{
printf("Xtalk calibration done\n");
/* Get Xtalk calibration data, in order to use them later */
status = vl53l8cx_get_caldata_xtalk(&Dev, xtalk_data);
/* Set Xtalk calibration data */
status = vl53l8cx_set_caldata_xtalk(&Dev, xtalk_data);
}
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,240 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD visualize Xtalk */
/***********************************/
/*
* This example shows the possibility of VL53L8CX to visualize Xtalk data. It
* initializes the VL53L8CX ULD, perform a Xtalk calibration, and starts
* a ranging to capture 10 frames.
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
#include "vl53l8cx_plugin_xtalk.h"
int example8(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/* Buffer containing Xtalk data */
uint8_t xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE];
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Start Xtalk calibration */
/*********************************/
/* Start Xtalk calibration with a 3% reflective target at 600mm for the
* sensor, using 4 samples.
*/
printf("Running Xtalk calibration...\n");
status = vl53l8cx_calibrate_xtalk(&Dev, 3, 4, 600);
if(status)
{
printf("vl53l8cx_calibrate_xtalk failed, status %u\n", status);
return status;
}else
{
printf("Xtalk calibration done\n");
/* Get Xtalk calibration data, in order to use them later */
status = vl53l8cx_get_caldata_xtalk(&Dev, xtalk_data);
/* Set Xtalk calibration data */
status = vl53l8cx_set_caldata_xtalk(&Dev, xtalk_data);
}
/* (Optional) Visualize Xtalk grid and Xtalk shape */
uint32_t i, j;
union Block_header *bh_ptr;
uint32_t xtalk_signal_kcps_grid[VL53L8CX_RESOLUTION_8X8];
uint16_t xtalk_shape_bins[144];
/* Swap buffer */
SwapBuffer(xtalk_data, VL53L8CX_XTALK_BUFFER_SIZE);
/* Get data */
for(i = 0; i < VL53L8CX_XTALK_BUFFER_SIZE; i = i + 4)
{
bh_ptr = (union Block_header *)&(xtalk_data[i]);
if (bh_ptr->idx == 0xA128){
printf("Xtalk shape bins located at position %#06x\n", (int)i);
for (j = 0; j < 144; j++){
memcpy(&(xtalk_shape_bins[j]), &(xtalk_data[i + 4 + j * 2]), 2);
printf("xtalk_shape_bins[%d] = %d\n", (int)j, (int)xtalk_shape_bins[j]);
}
}
if (bh_ptr->idx == 0x9FFC){
printf("Xtalk signal kcps located at position %#06x\n", (int)i);
for (j = 0; j < VL53L8CX_RESOLUTION_8X8; j++){
memcpy(&(xtalk_signal_kcps_grid[j]), &(xtalk_data[i + 4 + j * 4]), 4);
xtalk_signal_kcps_grid[j] /= 2048;
printf("xtalk_signal_kcps_grid[%d] = %d\n", (int)j, (int)xtalk_signal_kcps_grid[j]);
}
}
}
/* Re-Swap buffer (in case of re-using data later) */
SwapBuffer(xtalk_data, VL53L8CX_XTALK_BUFFER_SIZE);
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(loop < 10)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
(int)i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

View File

@ -0,0 +1,245 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD interrupt checkers */
/***********************************/
/*
* This example shows the possibility of VL53L8CX to program detection thresholds. It
* initializes the VL53L8CX ULD, create 2 thresholds per zone for a 4x4 resolution,
* and starts a ranging to capture 10 frames.
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
#include "vl53l8cx_plugin_detection_thresholds.h"
#define UNUSED(x) (void)(x)
/* This function needs to be filled by the customer. It allows knowing when
* the VL53L8CX interrupt is raised on GPIO1. This is the only way to use detection thresholds.
*/
int WaitForL8CXInterrupt(VL53L8CX_Configuration * pDev) {
//Add your implementation here ...
UNUSED(pDev);
return 0;
}
int example9(void)
{
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
return status;
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
printf("VL53L8CX ULD Loading failed\n");
return status;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Program detection thresholds */
/*********************************/
/* In this example, we want 2 thresholds per zone for a 4x4 resolution */
/* Create array of thresholds (size cannot be changed) */
VL53L8CX_DetectionThresholds thresholds[VL53L8CX_NB_THRESHOLDS];
/* Set all values to 0 */
memset(&thresholds, 0, sizeof(thresholds));
/* Add thresholds for all zones (16 zones in resolution 4x4, or 64 in 8x8) */
for(i = 0; i < 16; i++){
/* The first wanted thresholds is GREATER_THAN mode. Please note that the
* first one must always be set with a mathematic_operation
* VL53L8CX_OPERATION_NONE.
* For this example, the signal thresholds is set to 150 kcps/spads
* (the format is automatically updated inside driver)
*/
thresholds[2*i].zone_num = i;
thresholds[2*i].measurement = VL53L8CX_SIGNAL_PER_SPAD_KCPS;
thresholds[2*i].type = VL53L8CX_GREATER_THAN_MAX_CHECKER;
thresholds[2*i].mathematic_operation = VL53L8CX_OPERATION_NONE;
thresholds[2*i].param_low_thresh = 150;
thresholds[2*i].param_high_thresh = 150;
/* The second wanted checker is IN_WINDOW mode. We will set a
* mathematical thresholds VL53L8CX_OPERATION_OR, to add the previous
* checker to this one.
* For this example, distance thresholds are set between 200mm and
* 400mm (the format is automatically updated inside driver).
*/
thresholds[2*i+1].zone_num = i;
thresholds[2*i+1].measurement = VL53L8CX_DISTANCE_MM;
thresholds[2*i+1].type = VL53L8CX_IN_WINDOW;
thresholds[2*i+1].mathematic_operation = VL53L8CX_OPERATION_OR;
thresholds[2*i+1].param_low_thresh = 200;
thresholds[2*i+1].param_high_thresh = 400;
}
/* The last thresholds must be clearly indicated. As we have 32
* checkers (16 zones x 2), the last one is the 31 */
thresholds[31].zone_num = VL53L8CX_LAST_THRESHOLD | thresholds[31].zone_num;
/* Send array of thresholds to the sensor */
vl53l8cx_set_detection_thresholds(&Dev, thresholds);
/* Enable detection thresholds */
vl53l8cx_set_detection_thresholds_enable(&Dev, 1);
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_set_ranging_frequency_hz(&Dev, 10);
IntCount = 0;
status = vl53l8cx_start_ranging(&Dev);
printf("Put an object between 200mm and 400mm to catch an interrupt\n");
loop = 0;
while(loop < 100)
{
/* Function WaitForL8CXInterrupt() does not exists, and must be
* implemented by user. It allows catching the interrupt raised on
* pin A1 (INT), when the checkers detect the programmed
* conditions.
*/
isReady = WaitForL8CXInterrupt(&Dev);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of
* first zone are print */
printf("Print data no : %3u\n", Dev.streamcount);
for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm, Signal : %5lu kcps/SPADs\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.signal_per_spad[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return status;
}

6
Platform/LICENSE.txt Normal file
View File

@ -0,0 +1,6 @@
This software component is provided to you as part of a software package and
applicable license terms are in the Package_license file. If you received this
software component outside of a package or without applicable license terms,
the terms of the BSD-3-Clause license shall apply.
You may obtain a copy of the BSD-3-Clause at:
https://opensource.org/licenses/BSD-3-Clause

196
Platform/platform.c Normal file
View File

@ -0,0 +1,196 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include "platform.h"
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "hardware/gpio.h"
#include <stdio.h>
#define I2C_SUCCESS 0
#define I2C_FAILED -1
#define I2C_BUFFER_EXCEEDED -2
#define MAX_I2C_BUFFER 0x8100
/// @brief Blocking function allowing to write a register on an I2C device
/// @param address_7_bits
/// @param index : register to write
/// @param values : values to write
/// @param count : number of byte to send
/// @return 0: Success, -1 or -2: Failed
int8_t i2c_write_register(char adresse_7_bits, uint16_t index, uint8_t * values, uint32_t count){
int statu;
uint8_t buffer[MAX_I2C_BUFFER];
uint8_t index_to_unint8[2];
absolute_time_t timeout_time;
if(count > MAX_I2C_BUFFER - 2){
return I2C_BUFFER_EXCEEDED;
}
index_to_unint8[0] = (index >> 8) & 0xFF;
index_to_unint8[1] = index & 0xFF;
buffer[0] = index_to_unint8[0];
buffer[1] = index_to_unint8[1];
for(uint32_t i=0; i<count; i++){
buffer[2+i] = values[i];
}
// Define timeout - now + 1s.
timeout_time = time_us_64() + 5000000;
statu = i2c_write_blocking_until (i2c0, adresse_7_bits, buffer, count + 2, 0, timeout_time);
//statu = i2c_write_blocking (i2c0, adresse_7_bits, buffer, count + 2, 0);
if(statu == PICO_ERROR_GENERIC){
printf("I2C - Write - Envoi registre Echec\n");
return I2C_FAILED;
}else if(statu == PICO_ERROR_TIMEOUT){
printf("Erreur ecrire registre: timeout\n");
printf("Adresse : %x\n",adresse_7_bits << 1 );
return I2C_FAILED;
}
return I2C_SUCCESS;
}
/// @brief Blocking function allowing to write a register on an I2C device
/// @param address_7_bits
/// @param index : register to write
/// @param values : values to write
/// @param count : number of byte to send
/// @return 0: Success, -1 or -2: Failed
int8_t i2c_read_register(char adresse_7_bits, uint16_t index, uint8_t *pdata, uint32_t count){
int statu;
uint8_t buffer[MAX_I2C_BUFFER];
uint8_t index_to_unint8[2];
index_to_unint8[0] = (index >> 8) & 0xFF;
index_to_unint8[1] = index & 0xFF;
statu = i2c_write_blocking (i2c0, adresse_7_bits, index_to_unint8, 2, 0);
if(statu == PICO_ERROR_GENERIC){
printf("I2C - Read - Envoi registre Echec\n");
return I2C_FAILED;
}
statu = i2c_read_blocking (i2c0, adresse_7_bits, pdata, count, 0);
if(statu == PICO_ERROR_GENERIC){
printf("I2C - Lecture registre Echec\n");
return I2C_FAILED;
}
return I2C_SUCCESS;
}
uint8_t RdByte(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_value)
{
uint8_t status = 255;
/* Need to be implemented by customer. This function returns 0 if OK */
return i2c_read_register(p_platform->address >> 1, RegisterAdress, p_value, 1);
}
uint8_t WrByte(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t value)
{
uint8_t status = 255;
/* Need to be implemented by customer. This function returns 0 if OK */
return i2c_write_register(p_platform->address >> 1, RegisterAdress, &value, 1);
}
uint8_t WrMulti(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size)
{
uint8_t status = 255;
return i2c_write_register(p_platform->address >> 1, RegisterAdress, p_values, size);
}
uint8_t RdMulti(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size)
{
uint8_t status = 255;
return i2c_read_register(p_platform->address >> 1, RegisterAdress, p_values, size);
}
uint8_t Reset_Sensor(
VL53L8CX_Platform *p_platform)
{
uint8_t status = 0;
/* (Optional) Need to be implemented by customer. This function returns 0 if OK */
/* Set pin LPN to LOW */
/* Set pin AVDD to LOW */
/* Set pin VDDIO to LOW */
/* Set pin CORE_1V8 to LOW */
WaitMs(p_platform, 100);
/* Set pin LPN to HIGH */
/* Set pin AVDD to HIGH */
/* Set pin VDDIO to HIGH */
/* Set pin CORE_1V8 to HIGH */
WaitMs(p_platform, 100);
return status;
}
void SwapBuffer(
uint8_t *buffer,
uint16_t size)
{
uint32_t i, tmp;
/* Example of possible implementation using <string.h> */
for(i = 0; i < size; i = i + 4)
{
tmp = (
buffer[i]<<24)
|(buffer[i+1]<<16)
|(buffer[i+2]<<8)
|(buffer[i+3]);
memcpy(&(buffer[i]), &tmp, 4);
}
}
uint8_t WaitMs(
VL53L8CX_Platform *p_platform,
uint32_t TimeMs)
{
/* Need to be implemented by customer. This function returns 0 if OK */
sleep_ms(TimeMs);
return 0;
}

166
Platform/platform.h Normal file
View File

@ -0,0 +1,166 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef _PLATFORM_H_
#define _PLATFORM_H_
#pragma once
#include <stdint.h>
#include <string.h>
/**
* @brief Structure VL53L8CX_Platform needs to be filled by the customer,
* depending on his platform. At least, it contains the VL53L8CX I2C address.
* Some additional fields can be added, as descriptors, or platform
* dependencies. Anything added into this structure is visible into the platform
* layer.
*/
typedef struct
{
/* To be filled with customer's platform. At least an I2C address/descriptor
* needs to be added */
/* Example for most standard platform : I2C address of sensor */
uint16_t address;
} VL53L8CX_Platform;
/*
* @brief The macro below is used to define the number of target per zone sent
* through I2C. This value can be changed by user, in order to tune I2C
* transaction, and also the total memory size (a lower number of target per
* zone means a lower RAM). The value must be between 1 and 4.
*/
#define VL53L8CX_NB_TARGET_PER_ZONE 1U
/*
* @brief The macro below can be used to avoid data conversion into the driver.
* By default there is a conversion between firmware and user data. Using this macro
* allows to use the firmware format instead of user format. The firmware format allows
* an increased precision.
*/
// #define VL53L8CX_USE_RAW_FORMAT
/*
* @brief All macro below are used to configure the sensor output. User can
* define some macros if he wants to disable selected output, in order to reduce
* I2C access.
*/
// #define VL53L8CX_DISABLE_AMBIENT_PER_SPAD
// #define VL53L8CX_DISABLE_NB_SPADS_ENABLED
// #define VL53L8CX_DISABLE_NB_TARGET_DETECTED
// #define VL53L8CX_DISABLE_SIGNAL_PER_SPAD
// #define VL53L8CX_DISABLE_RANGE_SIGMA_MM
// #define VL53L8CX_DISABLE_DISTANCE_MM
// #define VL53L8CX_DISABLE_REFLECTANCE_PERCENT
// #define VL53L8CX_DISABLE_TARGET_STATUS
// #define VL53L8CX_DISABLE_MOTION_INDICATOR
/**
* @param (VL53L8CX_Platform*) p_platform : Pointer of VL53L8CX platform
* structure.
* @param (uint16_t) Address : I2C location of value to read.
* @param (uint8_t) *p_values : Pointer of value to read.
* @return (uint8_t) status : 0 if OK
*/
uint8_t RdByte(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_value);
/**
* @brief Mandatory function used to write one single byte.
* @param (VL53L8CX_Platform*) p_platform : Pointer of VL53L8CX platform
* structure.
* @param (uint16_t) Address : I2C location of value to read.
* @param (uint8_t) value : Pointer of value to write.
* @return (uint8_t) status : 0 if OK
*/
uint8_t WrByte(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t value);
/**
* @brief Mandatory function used to read multiples bytes.
* @param (VL53L8CX_Platform*) p_platform : Pointer of VL53L8CX platform
* structure.
* @param (uint16_t) Address : I2C location of values to read.
* @param (uint8_t) *p_values : Buffer of bytes to read.
* @param (uint32_t) size : Size of *p_values buffer.
* @return (uint8_t) status : 0 if OK
*/
uint8_t RdMulti(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size);
/**
* @brief Mandatory function used to write multiples bytes.
* @param (VL53L8CX_Platform*) p_platform : Pointer of VL53L8CX platform
* structure.
* @param (uint16_t) Address : I2C location of values to write.
* @param (uint8_t) *p_values : Buffer of bytes to write.
* @param (uint32_t) size : Size of *p_values buffer.
* @return (uint8_t) status : 0 if OK
*/
uint8_t WrMulti(
VL53L8CX_Platform *p_platform,
uint16_t RegisterAdress,
uint8_t *p_values,
uint32_t size);
/**
* @brief Optional function, only used to perform an hardware reset of the
* sensor. This function is not used in the API, but it can be used by the host.
* This function is not mandatory to fill if user don't want to reset the
* sensor.
* @param (VL53L8CX_Platform*) p_platform : Pointer of VL53L8CX platform
* structure.
* @return (uint8_t) status : 0 if OK
*/
uint8_t Reset_Sensor(
VL53L8CX_Platform *p_platform);
/**
* @brief Mandatory function, used to swap a buffer. The buffer size is always a
* multiple of 4 (4, 8, 12, 16, ...).
* @param (uint8_t*) buffer : Buffer to swap, generally uint32_t
* @param (uint16_t) size : Buffer size to swap
*/
void SwapBuffer(
uint8_t *buffer,
uint16_t size);
/**
* @brief Mandatory function, used to wait during an amount of time. It must be
* filled as it's used into the API.
* @param (VL53L8CX_Platform*) p_platform : Pointer of VL53L8CX platform
* structure.
* @param (uint32_t) TimeMs : Time to wait in ms.
* @return (uint8_t) status : 0 if wait is finished.
*/
uint8_t WaitMs(
VL53L8CX_Platform *p_platform,
uint32_t TimeMs);
#endif // _PLATFORM_H_

47
Readme.md Normal file
View File

@ -0,0 +1,47 @@
Détection de l'adversaire - 2023
================================
Le code présenté ici sert à la détection de l'adversaire pour les robots de l'équipe [Poivron Robotique](http://poivron-robotique.fr) qui participe à la coupe de France de Robotique. Ce code tourne sur un Raspberry Pi Pico et une carte personnalisé sur laquelle sont banchés 12 capteurs VL53L1X.
Principe de fonctionnement
--------------------------
Les capteurs VL53L1X sont des capteurs I2C dont l'adresse est configurable. Cependant, le capteur revient à son adresse par défaut dès qu'il est éteint ou désactivé par la broche `XSHUT`. Le Raspberry Pi Pico est relié à un 74HC4067, qui lui permet de désactiver un capteur à la fois.
Le code utilisé ici repose sur [VL53L1X_Raspberry_Pi_Pico](https://git.poivron-robotique.fr/Keuronde/Raspberry_Pi_Pico_VL53L1X) et l'exemple pour piloter les LED RGB ws2812 fourni avec le SDK du Raspberry Pi Pico.
Initialisation
--------------
La première étape de l'initialisation consiste à changer tous les capteurs d'adresses en une seule commande I2C.
La seconde étape consiste, pour chaque capteur, à le désactiver puis à le réactiver à l'aide du 74HC4067 et de la boche `XSHUT` du composant. Ce faisant, il reprend son adresse par défaut et il est le seul à cette adresse. Ainsi il est possible, via le bus I2C de lui attribuer une adresse unique.
Communication I2C
-----------------
Avec le reste du robot, la carte communique en I2C sur le bus i2c1, se comportant comme une EPROM en utilisant le code de Valentin Milea <valentin.milea@gmail.com>, [Pico_i2c_slave](https://github.com/vmilea/pico_i2c_slave).
Description de la mémoire d'échange:
------------------------------------
Les adresses 0 à 11 (0x0B) contiennent les distances des capteurs en centimètre. Cette distance est saturée à 200 cm.
Les adresses 16 (0x10) à 18 (0x12) contiennent les consignes d'éclairage des LEDs:
* 0x10 : Couleur sur 8 bits.
* 0x11 : octet de poids fort pour le masque sélectionnant les LEDs à commander.
* 0x12 : octet de poids faible pour le masque sélectionnant les LEDs à commander.
Couleur sur 8 bits structurée ainsi : 3-3-2 (Rouge - vert - bleu).
Le masque sur 16 bits, 1 : la led doit être piloter de la couleur indiquée, 0 la led affiche la distance.
Valeur spéciale pour le masque : 0x00. Dans ce cas, toutes les LEDs reprennent leur fonction par défaut (affichage de la distance).
Démo - Ne fonctionne plus
----
La démo ne fonctionne plus, la carte initialise automatiquement les capteurs et lit leurs valeurs en continu. Le code esclave I2C envoi ces valeurs qui sont stockée de l'adresse 0x0 à 0x0B de la "mémoire" I2C.
Le code I2C pour la partie esclave est repris de [pico_i2c_slave](https://github.com/vmilea/pico_i2c_slave).
Une fois branchée à un ordinateur, le Raspberry Pi Pico propose un menu par la liaison USB/série.
- La commande "i" initialise les capteurs et change d'état les LEDs en fonction du succès de l'initialisation.
- La commande "j" démarre une lecture continue et renvoie les données des capteurs dans un format compatible avec [Teleplot](https://github.com/nesnes/teleplot/).

View File

@ -0,0 +1,6 @@
This software component is provided to you as part of a software package and
applicable license terms are in the Package_license file. If you received this
software component outside of a package or without applicable license terms,
the terms of the BSD-3-Clause license shall apply.
You may obtain a copy of the BSD-3-Clause at:
https://opensource.org/licenses/BSD-3-Clause

View File

@ -0,0 +1,730 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef VL53L8CX_API_H_
#define VL53L8CX_API_H_
#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION < 6010050)
#pragma anon_unions
#endif
#include "../../Platform/platform.h"
/**
* @brief Current driver version.
*/
#define VL53L8CX_API_REVISION "VL53L8CX_1.1.0"
/**
* @brief Default I2C address of VL53L8CX sensor. Can be changed using function
* vl53l8cx_set_i2c_address() function is called.
*/
#define VL53L8CX_DEFAULT_I2C_ADDRESS ((uint16_t)0x52)
/**
* @brief Macro VL53L8CX_RESOLUTION_4X4 or VL53L8CX_RESOLUTION_8X8 allows
* setting sensor in 4x4 mode or 8x8 mode, using function
* vl53l8cx_set_resolution().
*/
#define VL53L8CX_RESOLUTION_4X4 ((uint8_t) 16U)
#define VL53L8CX_RESOLUTION_8X8 ((uint8_t) 64U)
/**
* @brief Macro VL53L8CX_TARGET_ORDER_STRONGEST or VL53L8CX_TARGET_ORDER_CLOSEST
* are used to select the target order for data output.
*/
#define VL53L8CX_TARGET_ORDER_CLOSEST ((uint8_t) 1U)
#define VL53L8CX_TARGET_ORDER_STRONGEST ((uint8_t) 2U)
/**
* @brief Macro VL53L8CX_RANGING_MODE_CONTINUOUS and
* VL53L8CX_RANGING_MODE_AUTONOMOUS are used to change the ranging mode.
* Autonomous mode can be used to set a precise integration time, whereas
* continuous is always maximum.
*/
#define VL53L8CX_RANGING_MODE_CONTINUOUS ((uint8_t) 1U)
#define VL53L8CX_RANGING_MODE_AUTONOMOUS ((uint8_t) 3U)
/**
* @brief The default power mode is VL53L8CX_POWER_MODE_WAKEUP. User can choose
* the mode VL53L8CX_POWER_MODE_SLEEP to save power consumption is the device
* is not used. The low power mode retains the firmware and the configuration.
* Both modes can be changed using function vl53l8cx_set_power_mode().
*/
#define VL53L8CX_POWER_MODE_SLEEP ((uint8_t) 0U)
#define VL53L8CX_POWER_MODE_WAKEUP ((uint8_t) 1U)
/**
* @brief Macro VL53L8CX_STATUS_OK indicates that VL53L5 sensor has no error.
* Macro VL53L8CX_STATUS_ERROR indicates that something is wrong (value,
* I2C access, ...). Macro VL53L8CX_MCU_ERROR is used to indicate a MCU issue.
*/
#define VL53L8CX_STATUS_OK ((uint8_t) 0U)
#define VL53L8CX_STATUS_TIMEOUT_ERROR ((uint8_t) 1U)
#define VL53L8CX_STATUS_CORRUPTED_FRAME ((uint8_t) 2U)
#define VL53L8CX_STATUS_LASER_SAFETY ((uint8_t) 3U)
#define VL53L8CX_STATUS_XTALK_FAILED ((uint8_t) 4U)
#define VL53L8CX_STATUS_FW_CHECKSUM_FAIL ((uint8_t) 5U)
#define VL53L8CX_MCU_ERROR ((uint8_t) 66U)
#define VL53L8CX_STATUS_INVALID_PARAM ((uint8_t) 127U)
#define VL53L8CX_STATUS_ERROR ((uint8_t) 255U)
/**
* @brief Definitions for Range results block headers
*/
#if VL53L8CX_NB_TARGET_PER_ZONE == 1
#define VL53L8CX_START_BH ((uint32_t)0x0000000DU)
#define VL53L8CX_METADATA_BH ((uint32_t)0x54B400C0U)
#define VL53L8CX_COMMONDATA_BH ((uint32_t)0x54C00040U)
#define VL53L8CX_AMBIENT_RATE_BH ((uint32_t)0x54D00104U)
#define VL53L8CX_SPAD_COUNT_BH ((uint32_t)0x55D00404U)
#define VL53L8CX_NB_TARGET_DETECTED_BH ((uint32_t)0xDB840401U)
#define VL53L8CX_SIGNAL_RATE_BH ((uint32_t)0xDBC40404U)
#define VL53L8CX_RANGE_SIGMA_MM_BH ((uint32_t)0xDEC40402U)
#define VL53L8CX_DISTANCE_BH ((uint32_t)0xDF440402U)
#define VL53L8CX_REFLECTANCE_BH ((uint32_t)0xE0440401U)
#define VL53L8CX_TARGET_STATUS_BH ((uint32_t)0xE0840401U)
#define VL53L8CX_MOTION_DETECT_BH ((uint32_t)0xD85808C0U)
#define VL53L8CX_METADATA_IDX ((uint16_t)0x54B4U)
#define VL53L8CX_SPAD_COUNT_IDX ((uint16_t)0x55D0U)
#define VL53L8CX_AMBIENT_RATE_IDX ((uint16_t)0x54D0U)
#define VL53L8CX_NB_TARGET_DETECTED_IDX ((uint16_t)0xDB84U)
#define VL53L8CX_SIGNAL_RATE_IDX ((uint16_t)0xDBC4U)
#define VL53L8CX_RANGE_SIGMA_MM_IDX ((uint16_t)0xDEC4U)
#define VL53L8CX_DISTANCE_IDX ((uint16_t)0xDF44U)
#define VL53L8CX_REFLECTANCE_EST_PC_IDX ((uint16_t)0xE044U)
#define VL53L8CX_TARGET_STATUS_IDX ((uint16_t)0xE084U)
#define VL53L8CX_MOTION_DETEC_IDX ((uint16_t)0xD858U)
#else
#define VL53L8CX_START_BH ((uint32_t)0x0000000DU)
#define VL53L8CX_METADATA_BH ((uint32_t)0x54B400C0U)
#define VL53L8CX_COMMONDATA_BH ((uint32_t)0x54C00040U)
#define VL53L8CX_AMBIENT_RATE_BH ((uint32_t)0x54D00104U)
#define VL53L8CX_NB_TARGET_DETECTED_BH ((uint32_t)0x57D00401U)
#define VL53L8CX_SPAD_COUNT_BH ((uint32_t)0x55D00404U)
#define VL53L8CX_SIGNAL_RATE_BH ((uint32_t)0x58900404U)
#define VL53L8CX_RANGE_SIGMA_MM_BH ((uint32_t)0x64900402U)
#define VL53L8CX_DISTANCE_BH ((uint32_t)0x66900402U)
#define VL53L8CX_REFLECTANCE_BH ((uint32_t)0x6A900401U)
#define VL53L8CX_TARGET_STATUS_BH ((uint32_t)0x6B900401U)
#define VL53L8CX_MOTION_DETECT_BH ((uint32_t)0xCC5008C0U)
#define VL53L8CX_METADATA_IDX ((uint16_t)0x54B4U)
#define VL53L8CX_SPAD_COUNT_IDX ((uint16_t)0x55D0U)
#define VL53L8CX_AMBIENT_RATE_IDX ((uint16_t)0x54D0U)
#define VL53L8CX_NB_TARGET_DETECTED_IDX ((uint16_t)0x57D0U)
#define VL53L8CX_SIGNAL_RATE_IDX ((uint16_t)0x5890U)
#define VL53L8CX_RANGE_SIGMA_MM_IDX ((uint16_t)0x6490U)
#define VL53L8CX_DISTANCE_IDX ((uint16_t)0x6690U)
#define VL53L8CX_REFLECTANCE_EST_PC_IDX ((uint16_t)0x6A90U)
#define VL53L8CX_TARGET_STATUS_IDX ((uint16_t)0x6B90U)
#define VL53L8CX_MOTION_DETEC_IDX ((uint16_t)0xCC50U)
#endif
/**
* @brief Inner Macro for API. Not for user, only for development.
*/
#define VL53L8CX_NVM_DATA_SIZE ((uint16_t)492U)
#define VL53L8CX_CONFIGURATION_SIZE ((uint16_t)972U)
#define VL53L8CX_OFFSET_BUFFER_SIZE ((uint16_t)488U)
#define VL53L8CX_XTALK_BUFFER_SIZE ((uint16_t)776U)
#define VL53L8CX_DCI_ZONE_CONFIG ((uint16_t)0x5450U)
#define VL53L8CX_DCI_FREQ_HZ ((uint16_t)0x5458U)
#define VL53L8CX_DCI_INT_TIME ((uint16_t)0x545CU)
#define VL53L8CX_DCI_FW_NB_TARGET ((uint16_t)0x5478)
#define VL53L8CX_DCI_RANGING_MODE ((uint16_t)0xAD30U)
#define VL53L8CX_DCI_DSS_CONFIG ((uint16_t)0xAD38U)
#define VL53L8CX_DCI_TARGET_ORDER ((uint16_t)0xAE64U)
#define VL53L8CX_DCI_SHARPENER ((uint16_t)0xAED8U)
#define VL53L8CX_DCI_INTERNAL_CP ((uint16_t)0xB39CU)
#define VL53L8CX_DCI_SYNC_PIN ((uint16_t)0xB5F0U)
#define VL53L8CX_DCI_MOTION_DETECTOR_CFG ((uint16_t)0xBFACU)
#define VL53L8CX_DCI_SINGLE_RANGE ((uint16_t)0xD964U)
#define VL53L8CX_DCI_OUTPUT_CONFIG ((uint16_t)0xD968U)
#define VL53L8CX_DCI_OUTPUT_ENABLES ((uint16_t)0xD970U)
#define VL53L8CX_DCI_OUTPUT_LIST ((uint16_t)0xD980U)
#define VL53L8CX_DCI_PIPE_CONTROL ((uint16_t)0xDB80U)
#define VL53L8CX_UI_CMD_STATUS ((uint16_t)0x2C00U)
#define VL53L8CX_UI_CMD_START ((uint16_t)0x2C04U)
#define VL53L8CX_UI_CMD_END ((uint16_t)0x2FFFU)
/**
* @brief Inner values for API. Max buffer size depends of the selected output.
*/
#ifndef VL53L8CX_DISABLE_AMBIENT_PER_SPAD
#define L5CX_AMB_SIZE 260U
#else
#define L5CX_AMB_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_NB_SPADS_ENABLED
#define L5CX_SPAD_SIZE 260U
#else
#define L5CX_SPAD_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_NB_TARGET_DETECTED
#define L5CX_NTAR_SIZE 68U
#else
#define L5CX_NTAR_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_SIGNAL_PER_SPAD
#define L5CX_SPS_SIZE ((256U * VL53L8CX_NB_TARGET_PER_ZONE) + 4U)
#else
#define L5CX_SPS_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_RANGE_SIGMA_MM
#define L5CX_SIGR_SIZE ((128U * VL53L8CX_NB_TARGET_PER_ZONE) + 4U)
#else
#define L5CX_SIGR_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_DISTANCE_MM
#define L5CX_DIST_SIZE ((128U * VL53L8CX_NB_TARGET_PER_ZONE) + 4U)
#else
#define L5CX_DIST_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_REFLECTANCE_PERCENT
#define L5CX_RFLEST_SIZE ((64U *VL53L8CX_NB_TARGET_PER_ZONE) + 4U)
#else
#define L5CX_RFLEST_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_TARGET_STATUS
#define L5CX_STA_SIZE ((64U *VL53L8CX_NB_TARGET_PER_ZONE) + 4U)
#else
#define L5CX_STA_SIZE 0U
#endif
#ifndef VL53L8CX_DISABLE_MOTION_INDICATOR
#define L5CX_MOT_SIZE 144U
#else
#define L5CX_MOT_SIZE 0U
#endif
/**
* @brief Macro VL53L8CX_MAX_RESULTS_SIZE indicates the maximum size used by
* output through I2C. Value 40 corresponds to headers + meta-data + common-data
* and 20 corresponds to the footer.
*/
#define VL53L8CX_MAX_RESULTS_SIZE ( 40U \
+ L5CX_AMB_SIZE + L5CX_SPAD_SIZE + L5CX_NTAR_SIZE + L5CX_SPS_SIZE \
+ L5CX_SIGR_SIZE + L5CX_DIST_SIZE + L5CX_RFLEST_SIZE + L5CX_STA_SIZE \
+ L5CX_MOT_SIZE + 20U)
/**
* @brief Macro VL53L8CX_TEMPORARY_BUFFER_SIZE can be used to know the size of
* the temporary buffer. The minimum size is 1024, and the maximum depends of
* the output configuration.
*/
#if VL53L8CX_MAX_RESULTS_SIZE < 1024U
#define VL53L8CX_TEMPORARY_BUFFER_SIZE ((uint32_t) 1024U)
#else
#define VL53L8CX_TEMPORARY_BUFFER_SIZE ((uint32_t) VL53L8CX_MAX_RESULTS_SIZE)
#endif
/**
* @brief Structure VL53L8CX_Configuration contains the sensor configuration.
* User MUST not manually change these field, except for the sensor address.
*/
typedef struct
{
/* Platform, filled by customer into the 'platform.h' file */
VL53L8CX_Platform platform;
/* Results streamcount, value auto-incremented at each range */
uint8_t streamcount;
/* Size of data read though I2C */
uint32_t data_read_size;
/* Address of default configuration buffer */
uint8_t *default_configuration;
/* Address of default Xtalk buffer */
uint8_t *default_xtalk;
/* Offset buffer */
uint8_t offset_data[VL53L8CX_OFFSET_BUFFER_SIZE];
/* Xtalk buffer */
uint8_t xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE];
/* Temporary buffer used for internal driver processing */
uint8_t temp_buffer[VL53L8CX_TEMPORARY_BUFFER_SIZE];
/* Auto-stop flag for stopping the sensor */
uint8_t is_auto_stop_enabled;
} VL53L8CX_Configuration;
/**
* @brief Structure VL53L8CX_ResultsData contains the ranging results of
* VL53L8CX. If user wants more than 1 target per zone, the results can be split
* into 2 sub-groups :
* - Per zone results. These results are common to all targets (ambient_per_spad
* , nb_target_detected and nb_spads_enabled).
* - Per target results : These results are different relative to the detected
* target (signal_per_spad, range_sigma_mm, distance_mm, reflectance,
* target_status).
*/
typedef struct
{
/* Internal sensor silicon temperature */
int8_t silicon_temp_degc;
/* Ambient noise in kcps/spads */
#ifndef VL53L8CX_DISABLE_AMBIENT_PER_SPAD
uint32_t ambient_per_spad[VL53L8CX_RESOLUTION_8X8];
#endif
/* Number of valid target detected for 1 zone */
#ifndef VL53L8CX_DISABLE_NB_TARGET_DETECTED
uint8_t nb_target_detected[VL53L8CX_RESOLUTION_8X8];
#endif
/* Number of spads enabled for this ranging */
#ifndef VL53L8CX_DISABLE_NB_SPADS_ENABLED
uint32_t nb_spads_enabled[VL53L8CX_RESOLUTION_8X8];
#endif
/* Signal returned to the sensor in kcps/spads */
#ifndef VL53L8CX_DISABLE_SIGNAL_PER_SPAD
uint32_t signal_per_spad[(VL53L8CX_RESOLUTION_8X8
*VL53L8CX_NB_TARGET_PER_ZONE)];
#endif
/* Sigma of the current distance in mm */
#ifndef VL53L8CX_DISABLE_RANGE_SIGMA_MM
uint16_t range_sigma_mm[(VL53L8CX_RESOLUTION_8X8
*VL53L8CX_NB_TARGET_PER_ZONE)];
#endif
/* Measured distance in mm */
#ifndef VL53L8CX_DISABLE_DISTANCE_MM
int16_t distance_mm[(VL53L8CX_RESOLUTION_8X8
*VL53L8CX_NB_TARGET_PER_ZONE)];
#endif
/* Estimated reflectance in percent */
#ifndef VL53L8CX_DISABLE_REFLECTANCE_PERCENT
uint8_t reflectance[(VL53L8CX_RESOLUTION_8X8
*VL53L8CX_NB_TARGET_PER_ZONE)];
#endif
/* Status indicating the measurement validity (5 & 9 means ranging OK)*/
#ifndef VL53L8CX_DISABLE_TARGET_STATUS
uint8_t target_status[(VL53L8CX_RESOLUTION_8X8
*VL53L8CX_NB_TARGET_PER_ZONE)];
#endif
/* Motion detector results */
#ifndef VL53L8CX_DISABLE_MOTION_INDICATOR
struct
{
uint32_t global_indicator_1;
uint32_t global_indicator_2;
uint8_t status;
uint8_t nb_of_detected_aggregates;
uint8_t nb_of_aggregates;
uint8_t spare;
uint32_t motion[32];
} motion_indicator;
#endif
} VL53L8CX_ResultsData;
union Block_header {
uint32_t bytes;
struct {
uint32_t type : 4;
uint32_t size : 12;
uint32_t idx : 16;
};
};
uint8_t vl53l8cx_is_alive(
VL53L8CX_Configuration *p_dev,
uint8_t *p_is_alive);
/**
* @brief Mandatory function used to initialize the sensor. This function must
* be called after a power on, to load the firmware into the VL53L8CX. It takes
* a few hundred milliseconds.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @return (uint8_t) status : 0 if initialization is OK.
*/
uint8_t vl53l8cx_init(
VL53L8CX_Configuration *p_dev);
/**
* @brief This function is used to change the I2C address of the sensor. If
* multiple VL53L5 sensors are connected to the same I2C line, all other LPn
* pins needs to be set to Low. The default sensor address is 0x52.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint16_t) i2c_address : New I2C address.
* @return (uint8_t) status : 0 if new address is OK
*/
uint8_t vl53l8cx_set_i2c_address(
VL53L8CX_Configuration *p_dev,
uint16_t i2c_address);
/**
* @brief This function is used to get the current sensor power mode.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_power_mode : Current power mode. The value of this
* pointer is equal to 0 if the sensor is in low power,
* (VL53L8CX_POWER_MODE_SLEEP), or 1 if sensor is in standard mode
* (VL53L8CX_POWER_MODE_WAKEUP).
* @return (uint8_t) status : 0 if power mode is OK
*/
uint8_t vl53l8cx_get_power_mode(
VL53L8CX_Configuration *p_dev,
uint8_t *p_power_mode);
/**
* @brief This function is used to set the sensor in Low Power mode, for
* example if the sensor is not used during a long time. The macro
* VL53L8CX_POWER_MODE_SLEEP can be used to enable the low power mode. When user
* want to restart the sensor, he can use macro VL53L8CX_POWER_MODE_WAKEUP.
* Please ensure that the device is not streaming before calling the function.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) power_mode : Selected power mode (VL53L8CX_POWER_MODE_SLEEP
* or VL53L8CX_POWER_MODE_WAKEUP)
* @return (uint8_t) status : 0 if power mode is OK, or 127 if power mode
* requested by user is not valid.
*/
uint8_t vl53l8cx_set_power_mode(
VL53L8CX_Configuration *p_dev,
uint8_t power_mode);
/**
* @brief This function starts a ranging session. When the sensor streams, host
* cannot change settings 'on-the-fly'.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @return (uint8_t) status : 0 if start is OK.
*/
uint8_t vl53l8cx_start_ranging(
VL53L8CX_Configuration *p_dev);
/**
* @brief This function stops the ranging session. It must be used when the
* sensor streams, after calling vl53l8cx_start_ranging().
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @return (uint8_t) status : 0 if stop is OK
*/
uint8_t vl53l8cx_stop_ranging(
VL53L8CX_Configuration *p_dev);
/**
* @brief This function checks if a new data is ready by polling I2C. If a new
* data is ready, a flag will be raised.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_isReady : Value of this pointer be updated to 0 if data
* is not ready, or 1 if a new data is ready.
* @return (uint8_t) status : 0 if I2C reading is OK
*/
uint8_t vl53l8cx_check_data_ready(
VL53L8CX_Configuration *p_dev,
uint8_t *p_isReady);
/**
* @brief This function gets the ranging data, using the selected output and the
* resolution.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (VL53L8CX_ResultsData) *p_results : VL53L5 results structure.
* @return (uint8_t) status : 0 data are successfully get.
*/
uint8_t vl53l8cx_get_ranging_data(
VL53L8CX_Configuration *p_dev,
VL53L8CX_ResultsData *p_results);
/**
* @brief This function gets the current resolution (4x4 or 8x8).
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_resolution : Value of this pointer will be equal to 16
* for 4x4 mode, and 64 for 8x8 mode.
* @return (uint8_t) status : 0 if resolution is OK.
*/
uint8_t vl53l8cx_get_resolution(
VL53L8CX_Configuration *p_dev,
uint8_t *p_resolution);
/**
* @brief This function sets a new resolution (4x4 or 8x8).
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) resolution : Use macro VL53L8CX_RESOLUTION_4X4 or
* VL53L8CX_RESOLUTION_8X8 to set the resolution.
* @return (uint8_t) status : 0 if set resolution is OK.
*/
uint8_t vl53l8cx_set_resolution(
VL53L8CX_Configuration *p_dev,
uint8_t resolution);
/**
* @brief This function gets the current ranging frequency in Hz. Ranging
* frequency corresponds to the time between each measurement.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_frequency_hz: Contains the ranging frequency in Hz.
* @return (uint8_t) status : 0 if ranging frequency is OK.
*/
uint8_t vl53l8cx_get_ranging_frequency_hz(
VL53L8CX_Configuration *p_dev,
uint8_t *p_frequency_hz);
/**
* @brief This function sets a new ranging frequency in Hz. Ranging frequency
* corresponds to the measurements frequency. This setting depends of
* the resolution, so please select your resolution before using this function.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) frequency_hz : Contains the ranging frequency in Hz.
* - For 4x4, min and max allowed values are : [1;60]
* - For 8x8, min and max allowed values are : [1;15]
* @return (uint8_t) status : 0 if ranging frequency is OK, or 127 if the value
* is not correct.
*/
uint8_t vl53l8cx_set_ranging_frequency_hz(
VL53L8CX_Configuration *p_dev,
uint8_t frequency_hz);
/**
* @brief This function gets the current integration time in ms.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint32_t) *p_time_ms: Contains integration time in ms.
* @return (uint8_t) status : 0 if integration time is OK.
*/
uint8_t vl53l8cx_get_integration_time_ms(
VL53L8CX_Configuration *p_dev,
uint32_t *p_time_ms);
/**
* @brief This function sets a new integration time in ms. Integration time must
* be computed to be lower than the ranging period, for a selected resolution.
* Please note that this function has no impact on ranging mode continous.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint32_t) time_ms : Contains the integration time in ms. For all
* resolutions and frequency, the minimum value is 2ms, and the maximum is
* 1000ms.
* @return (uint8_t) status : 0 if set integration time is OK.
*/
uint8_t vl53l8cx_set_integration_time_ms(
VL53L8CX_Configuration *p_dev,
uint32_t integration_time_ms);
/**
* @brief This function gets the current sharpener in percent. Sharpener can be
* changed to blur more or less zones depending of the application.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint32_t) *p_sharpener_percent: Contains the sharpener in percent.
* @return (uint8_t) status : 0 if get sharpener is OK.
*/
uint8_t vl53l8cx_get_sharpener_percent(
VL53L8CX_Configuration *p_dev,
uint8_t *p_sharpener_percent);
/**
* @brief This function sets a new sharpener value in percent. Sharpener can be
* changed to blur more or less zones depending of the application. Min value is
* 0 (disabled), and max is 99.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint32_t) sharpener_percent : Value between 0 (disabled) and 99%.
* @return (uint8_t) status : 0 if set sharpener is OK.
*/
uint8_t vl53l8cx_set_sharpener_percent(
VL53L8CX_Configuration *p_dev,
uint8_t sharpener_percent);
/**
* @brief This function gets the current target order (closest or strongest).
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_target_order: Contains the target order.
* @return (uint8_t) status : 0 if get target order is OK.
*/
uint8_t vl53l8cx_get_target_order(
VL53L8CX_Configuration *p_dev,
uint8_t *p_target_order);
/**
* @brief This function sets a new target order. Please use macros
* VL53L8CX_TARGET_ORDER_STRONGEST and VL53L8CX_TARGET_ORDER_CLOSEST to define
* the new output order. By default, the sensor is configured with the strongest
* output.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) target_order : Required target order.
* @return (uint8_t) status : 0 if set target order is OK, or 127 if target
* order is unknown.
*/
uint8_t vl53l8cx_set_target_order(
VL53L8CX_Configuration *p_dev,
uint8_t target_order);
/**
* @brief This function is used to get the ranging mode. Two modes are
* available using ULD : Continuous and autonomous. The default
* mode is Autonomous.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_ranging_mode : current ranging mode
* @return (uint8_t) status : 0 if get ranging mode is OK.
*/
uint8_t vl53l8cx_get_ranging_mode(
VL53L8CX_Configuration *p_dev,
uint8_t *p_ranging_mode);
/**
* @brief This function is used to set the ranging mode. Two modes are
* available using ULD : Continuous and autonomous. The default
* mode is Autonomous.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) ranging_mode : Use macros VL53L8CX_RANGING_MODE_CONTINUOUS,
* VL53L8CX_RANGING_MODE_CONTINUOUS.
* @return (uint8_t) status : 0 if set ranging mode is OK.
*/
uint8_t vl53l8cx_set_ranging_mode(
VL53L8CX_Configuration *p_dev,
uint8_t ranging_mode);
/**
* @brief This function is used to check if the synchronization pin is enabled
* or disabled. When it is enabled, the sensor waits an interrupt on B1 pin
* to start the next measurement. It is useful for multi-devices
* synchronization. By default the sync pin is disabled.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t*) p_is_sync_pin_enabled : Pointer of sync pin status. Value
* overridden to 0 if the pin is disabled, or 1 if the pin is enabled.
* @return (uint8_t) status : 0 if get sync pin OK.
*/
uint8_t vl53l8cx_get_external_sync_pin_enable(
VL53L8CX_Configuration *p_dev,
uint8_t *p_is_sync_pin_enabled);
/**
* @brief This function is used to enable or disable the synchronization pin. When
* it is enabled, the sensor waits an interrupt on B1 pin to start the next
* measurement. It is useful for multi-devices synchronization. By default the sync
* pin is disabled.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) enable_sync_pin : Ste the value to 1 to enable the sync
* pin, or 0 to disable it.
* @return (uint8_t) status : 0 if set sync pin OK.
*/
uint8_t vl53l8cx_set_external_sync_pin_enable(
VL53L8CX_Configuration *p_dev,
uint8_t enable_sync_pin);
/**
* @brief This function can be used to read 'extra data' from DCI. Using a known
* index, the function fills the casted structure passed in argument.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *data : This field can be a casted structure, or a simple
* array. Please note that the FW only accept data of 32 bits. So field data can
* only have a size of 32, 64, 96, 128, bits ....
* @param (uint32_t) index : Index of required value.
* @param (uint16_t)*data_size : This field must be the structure or array size
* (using sizeof() function).
* @return (uint8_t) status : 0 if OK
*/
uint8_t vl53l8cx_dci_read_data(
VL53L8CX_Configuration *p_dev,
uint8_t *data,
uint32_t index,
uint16_t data_size);
/**
* @brief This function can be used to write 'extra data' to DCI. The data can
* be simple data, or casted structure.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *data : This field can be a casted structure, or a simple
* array. Please note that the FW only accept data of 32 bits. So field data can
* only have a size of 32, 64, 96, 128, bits ..
* @param (uint32_t) index : Index of required value.
* @param (uint16_t)*data_size : This field must be the structure or array size
* (using sizeof() function).
* @return (uint8_t) status : 0 if OK
*/
uint8_t vl53l8cx_dci_write_data(
VL53L8CX_Configuration *p_dev,
uint8_t *data,
uint32_t index,
uint16_t data_size);
/**
* @brief This function can be used to replace 'extra data' in DCI. The data can
* be simple data, or casted structure.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *data : This field can be a casted structure, or a simple
* array. Please note that the FW only accept data of 32 bits. So field data can
* only have a size of 32, 64, 96, 128, bits ..
* @param (uint32_t) index : Index of required value.
* @param (uint16_t)*data_size : This field must be the structure or array size
* (using sizeof() function).
* @param (uint8_t) *new_data : Contains the new fields.
* @param (uint16_t) new_data_size : New data size.
* @param (uint16_t) new_data_pos : New data position into the buffer.
* @return (uint8_t) status : 0 if OK
*/
uint8_t vl53l8cx_dci_replace_data(
VL53L8CX_Configuration *p_dev,
uint8_t *data,
uint32_t index,
uint16_t data_size,
uint8_t *new_data,
uint16_t new_data_size,
uint16_t new_data_pos);
#endif //VL53L8CX_API_H_

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,186 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef VL53L8CX_PLUGIN_DETECTION_THRESHOLDS_H_
#define VL53L8CX_PLUGIN_DETECTION_THRESHOLDS_H_
#include "vl53l8cx_api.h"
/**
* @brief Macro VL53L8CX_NB_THRESHOLDS indicates the number of checkers. This
* value cannot be changed.
*/
#define VL53L8CX_NB_THRESHOLDS ((uint8_t)64U)
/**
* @brief Inner Macro for API. Not for user, only for development.
*/
#define VL53L8CX_DCI_DET_THRESH_CONFIG ((uint16_t)0x5488U)
#define VL53L8CX_DCI_DET_THRESH_GLOBAL_CONFIG ((uint16_t)0xB6E0U)
#define VL53L8CX_DCI_DET_THRESH_START ((uint16_t)0xB6E8U)
#define VL53L8CX_DCI_DET_THRESH_VALID_STATUS ((uint16_t)0xB9F0U)
/**
* @brief Macro VL53L8CX_LAST_THRESHOLD is used to indicate the end of checkers
* programming.
*/
#define VL53L8CX_LAST_THRESHOLD ((uint8_t)128U)
/**
* @brief The following macro are used to define the 'param_type' of a checker.
* They indicate what is the measurement to catch.
*/
#define VL53L8CX_DISTANCE_MM ((uint8_t)1U)
#define VL53L8CX_SIGNAL_PER_SPAD_KCPS ((uint8_t)2U)
#define VL53L8CX_RANGE_SIGMA_MM ((uint8_t)4U)
#define VL53L8CX_AMBIENT_PER_SPAD_KCPS ((uint8_t)8U)
#define VL53L8CX_NB_TARGET_DETECTED ((uint8_t)9U)
#define VL53L8CX_TARGET_STATUS ((uint8_t)12U)
#define VL53L8CX_NB_SPADS_ENABLED ((uint8_t)13U)
#define VL53L8CX_MOTION_INDICATOR ((uint8_t)19U)
/**
* @brief The following macro are used to define the 'type' of a checker.
* They indicate the window of measurements, defined by low and a high
* thresholds.
*/
#define VL53L8CX_IN_WINDOW ((uint8_t)0U)
#define VL53L8CX_OUT_OF_WINDOW ((uint8_t)1U)
#define VL53L8CX_LESS_THAN_EQUAL_MIN_CHECKER ((uint8_t)2U)
#define VL53L8CX_GREATER_THAN_MAX_CHECKER ((uint8_t)3U)
#define VL53L8CX_EQUAL_MIN_CHECKER ((uint8_t)4U)
#define VL53L8CX_NOT_EQUAL_MIN_CHECKER ((uint8_t)5U)
/**
* @brief The following macro are used to define multiple checkers in the same
* zone, using operators. Please note that the first checker MUST always be a OR
* operation.
*/
#define VL53L8CX_OPERATION_NONE ((uint8_t)0U)
#define VL53L8CX_OPERATION_OR ((uint8_t)0U)
#define VL53L8CX_OPERATION_AND ((uint8_t)2U)
/**
* @brief Structure VL53L8CX_DetectionThresholds contains a single threshold.
* This structure is never used alone, it must be used as an array of 64
* thresholds (defined by macro VL53L8CX_NB_THRESHOLDS).
*/
typedef struct {
/* Low threshold */
int32_t param_low_thresh;
/* High threshold */
int32_t param_high_thresh;
/* Measurement to catch (VL53L8CX_MEDIAN_RANGE_MM,...)*/
uint8_t measurement;
/* Windows type (VL53L8CX_IN_WINDOW, VL53L8CX_OUT_WINDOW, ...) */
uint8_t type;
/* Zone id. Please read VL53L5 user manual to find the zone id.Set macro
* VL53L8CX_LAST_THRESHOLD to indicates the end of checkers */
uint8_t zone_num;
/* Mathematics operation (AND/OR). The first threshold is always OR.*/
uint8_t mathematic_operation;
}VL53L8CX_DetectionThresholds;
/**
* @brief This function allows indicating if the detection thresholds are
* enabled.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_enabled : Set to 1 if enabled, or 0 if disable.
* @return (uint8_t) status : 0 if OK
*/
uint8_t vl53l8cx_get_detection_thresholds_enable(
VL53L8CX_Configuration *p_dev,
uint8_t *p_enabled);
/**
* @brief This function allows enable the detection thresholds.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) enabled : Set to 1 to enable, or 0 to disable thresholds.
* @return (uint8_t) status : 0 if programming is OK
*/
uint8_t vl53l8cx_set_detection_thresholds_enable(
VL53L8CX_Configuration *p_dev,
uint8_t enabled);
/**
* @brief This function allows getting the detection thresholds.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (VL53L8CX_DetectionThresholds) *p_thresholds : Array of 64 thresholds.
* @return (uint8_t) status : 0 if programming is OK
*/
uint8_t vl53l8cx_get_detection_thresholds(
VL53L8CX_Configuration *p_dev,
VL53L8CX_DetectionThresholds *p_thresholds);
/**
* @brief This function allows programming the detection thresholds.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (VL53L8CX_DetectionThresholds) *p_thresholds : Array of 64 thresholds.
* @return (uint8_t) status : 0 if programming is OK
*/
uint8_t vl53l8cx_set_detection_thresholds(
VL53L8CX_Configuration *p_dev,
VL53L8CX_DetectionThresholds *p_thresholds);
/**
* @brief This function is used to enable or disable the auto-stop feature.
* When ToF runs in autonomous mode with detection threshold, the sensor
* only emits an interrupt (INT pin) when a threshold is reached. Interrupt
* is raised when the measurement is completed. It is possible to abort the ranging
* without waiting for end of measurement completed by enabling the auto-stop. The
* sensor emits an interrupt and quickly aborts the measurements in progress. Please
* note that vl53l8cx_stop_ranging() function needs to be used after interrupt raised
* for a clean stop.
* This function is used to get the auto_stop flag.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_auto_stop : Pointer of auto-stop feature, 0 disabled
* (default) or 1 enabled.
* @return (uint8_t) status : 0 if programming is OK
*/
uint8_t vl53l8cx_get_detection_thresholds_auto_stop(
VL53L8CX_Configuration *p_dev,
uint8_t *p_auto_stop);
/**
* @brief This function is used to enable or disable the auto-stop feature.
* When ToF runs in autonomous mode with detection threshold, the sensor
* only emits an interrupt (INT pin) when a threshold is reached. Interrupt
* is raised when the measurement is completed. It is possible to abort the ranging
* without waiting for end of measurement completed by enabling the auto-stop. The
* sensor emits an interrupt and quickly aborts the measurements in progress. Please
* note that vl53l8cx_stop_ranging() function needs to be used after interrupt raised
* for a clean stop.
* This function is used to set the auto_stop flag.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint8_t) *p_auto_stop : Pointer of auto-stop feature, 0 disabled
* (default) or 1 enabled.
* @return (uint8_t) status : 0 if programming is OK
*/
uint8_t vl53l8cx_set_detection_thresholds_auto_stop(
VL53L8CX_Configuration *p_dev,
uint8_t auto_stop);
#endif /* VL53L8CX_PLUGIN_DETECTION_THRESHOLDS_H_ */

View File

@ -0,0 +1,96 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef VL53L8CX_PLUGIN_MOTION_INDICATOR_H_
#define VL53L8CX_PLUGIN_MOTION_INDICATOR_H_
#include "vl53l8cx_api.h"
/**
* @brief Motion indicator internal configuration structure.
*/
typedef struct {
int32_t ref_bin_offset;
uint32_t detection_threshold;
uint32_t extra_noise_sigma;
uint32_t null_den_clip_value;
uint8_t mem_update_mode;
uint8_t mem_update_choice;
uint8_t sum_span;
uint8_t feature_length;
uint8_t nb_of_aggregates;
uint8_t nb_of_temporal_accumulations;
uint8_t min_nb_for_global_detection;
uint8_t global_indicator_format_1;
uint8_t global_indicator_format_2;
uint8_t spare_1;
uint8_t spare_2;
uint8_t spare_3;
int8_t map_id[64];
uint8_t indicator_format_1[32];
uint8_t indicator_format_2[32];
}VL53L8CX_Motion_Configuration;
/**
* @brief This function is used to initialized the motion indicator. By default,
* indicator is programmed to monitor movements between 400mm and 1500mm.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (VL53L8CX_Motion_Configuration) *p_motion_config : Structure
* containing the initialized motion configuration.
* @param (uint8_t) resolution : Wanted resolution, defined by macros
* VL53L8CX_RESOLUTION_4X4 or VL53L8CX_RESOLUTION_8X8.
* @return (uint8_t) status : 0 if OK, or 127 is the resolution is unknown.
*/
uint8_t vl53l8cx_motion_indicator_init(
VL53L8CX_Configuration *p_dev,
VL53L8CX_Motion_Configuration *p_motion_config,
uint8_t resolution);
/**
* @brief This function can be used to change the working distance of motion
* indicator. By default, indicator is programmed to monitor movements between
* 400mm and 1500mm.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (VL53L8CX_Motion_Configuration) *p_motion_config : Structure
* containing the initialized motion configuration.
* @param (uint16_t) distance_min_mm : Minimum distance for indicator (min value
* 400mm, max 4000mm).
* @param (uint16_t) distance_max_mm : Maximum distance for indicator (min value
* 400mm, max 4000mm).
* VL53L8CX_RESOLUTION_4X4 or VL53L8CX_RESOLUTION_8X8.
* @return (uint8_t) status : 0 if OK, or 127 if an argument is invalid.
*/
uint8_t vl53l8cx_motion_indicator_set_distance_motion(
VL53L8CX_Configuration *p_dev,
VL53L8CX_Motion_Configuration *p_motion_config,
uint16_t distance_min_mm,
uint16_t distance_max_mm);
/**
* @brief This function is used to update the internal motion indicator map.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (VL53L8CX_Motion_Configuration) *p_motion_config : Structure
* containing the initialized motion configuration.
* @param (uint8_t) resolution : Wanted SCI resolution, defined by macros
* VL53L8CX_RESOLUTION_4X4 or VL53L8CX_RESOLUTION_8X8.
* @return (uint8_t) status : 0 if OK, or 127 is the resolution is unknown.
*/
uint8_t vl53l8cx_motion_indicator_set_resolution(
VL53L8CX_Configuration *p_dev,
VL53L8CX_Motion_Configuration *p_motion_config,
uint8_t resolution);
#endif /* VL53L8CX_PLUGIN_MOTION_INDICATOR_H_ */

View File

@ -0,0 +1,391 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#ifndef VL53L8CX_PLUGIN_XTALK_H_
#define VL53L8CX_PLUGIN_XTALK_H_
#include "vl53l8cx_api.h"
/**
* @brief Inner internal number of targets.
*/
#if VL53L8CX_NB_TARGET_PER_ZONE == 1
#define VL53L8CX_FW_NBTAR_XTALK 2
#else
#define VL53L8CX_FW_NBTAR_XTALK VL53L8CX_NB_TARGET_PER_ZONE
#endif
/**
* @brief Inner Macro for plugin. Not for user, only for development.
*/
#define VL53L8CX_DCI_CAL_CFG ((uint16_t)0x5470U)
#define VL53L8CX_DCI_XTALK_CFG ((uint16_t)0xAD94U)
/**
* @brief This function starts the VL53L8CX sensor in order to calibrate Xtalk.
* This calibration is recommended is user wants to use a coverglass.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint16_t) reflectance_percent : Target reflectance in percent. This
* value is include between 1 and 99%. For a better efficiency, ST recommends a
* 3% target reflectance.
* @param (uint8_t) nb_samples : Nb of samples used for calibration. A higher
* number of samples means a higher accuracy, but it increases the calibration
* time. Minimum is 1 and maximum is 16.
* @param (uint16_t) distance_mm : Target distance in mm. The minimum allowed
* distance is 600mm, and maximum is 3000mm. The target must stay in Full FOV,
* so short distance are easier for calibration.
* @return (uint8_t) status : 0 if calibration OK, 127 if an argument has an
* incorrect value, or 255 is something failed.
*/
uint8_t vl53l8cx_calibrate_xtalk(
VL53L8CX_Configuration *p_dev,
uint16_t reflectance_percent,
uint8_t nb_samples,
uint16_t distance_mm);
/**
* @brief This function gets the Xtalk buffer. The buffer is available after
* using the function vl53l8cx_calibrate_xtalk().
* @param (VL53L8CX_Configuration) *p_dev : VL53L5 configuration structure.
* @param (uint8_t) *p_xtalk_data : Buffer with a size defined by
* macro VL53L8CX_XTALK_SIZE.
* @return (uint8_t) status : 0 if buffer reading OK
*/
uint8_t vl53l8cx_get_caldata_xtalk(
VL53L8CX_Configuration *p_dev,
uint8_t *p_xtalk_data);
/**
* @brief This function sets the Xtalk buffer. This function can be used to
* override default Xtalk buffer.
* @param (VL53L8CX_Configuration) *p_dev : VL53L5 configuration structure.
* @param (uint8_t) *p_xtalk_data : Buffer with a size defined by
* macro VL53L8CX_XTALK_SIZE.
* @return (uint8_t) status : 0 if buffer OK
*/
uint8_t vl53l8cx_set_caldata_xtalk(
VL53L8CX_Configuration *p_dev,
uint8_t *p_xtalk_data);
/**
* @brief This function gets the Xtalk margin. This margin is used to increase
* the Xtalk threshold. It can also be used to avoid false positives after the
* Xtalk calibration. The default value is 50 kcps/spads.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint32_t) *p_xtalk_margin : Xtalk margin in kcps/spads.
* @return (uint8_t) status : 0 if reading OK
*/
uint8_t vl53l8cx_get_xtalk_margin(
VL53L8CX_Configuration *p_dev,
uint32_t *p_xtalk_margin);
/**
* @brief This function sets the Xtalk margin. This margin is used to increase
* the Xtalk threshold. It can also be used to avoid false positives after the
* Xtalk calibration. The default value is 50 kcps/spads.
* @param (VL53L8CX_Configuration) *p_dev : VL53L8CX configuration structure.
* @param (uint32_t) xtalk_margin : New Xtalk margin in kcps/spads. Min value is
* 0 kcps/spads, and max is 10.000 kcps/spads
* @return (uint8_t) status : 0 if set margin is OK, or 127 is the margin is
* invalid.
*/
uint8_t vl53l8cx_set_xtalk_margin(
VL53L8CX_Configuration *p_dev,
uint32_t xtalk_margin);
/**
* @brief Command used to get Xtalk calibration data
*/
static const uint8_t VL53L8CX_GET_XTALK_CMD[] = {
0x54, 0x00, 0x00, 0x40,
0x9F, 0xD8, 0x00, 0xC0,
0x9F, 0xE4, 0x01, 0x40,
0x9F, 0xF8, 0x00, 0x40,
0x9F, 0xFC, 0x04, 0x04,
0xA0, 0xFC, 0x01, 0x00,
0xA1, 0x0C, 0x01, 0x00,
0xA1, 0x1C, 0x00, 0xC0,
0xA1, 0x28, 0x09, 0x02,
0xA2, 0x48, 0x00, 0x40,
0xA2, 0x4C, 0x00, 0x81,
0xA2, 0x54, 0x00, 0x81,
0xA2, 0x5C, 0x00, 0x81,
0xA2, 0x64, 0x00, 0x81,
0xA2, 0x6C, 0x00, 0x84,
0xA2, 0x8C, 0x00, 0x82,
0x00, 0x00, 0x00, 0x0F,
0x07, 0x02, 0x00, 0x44
};
/**
* @brief Command used to get run Xtalk calibration
*/
static const uint8_t VL53L8CX_CALIBRATE_XTALK[] = {
0x54, 0x50, 0x00, 0x80,
0x00, 0x04, 0x08, 0x08,
0x00, 0x00, 0x04, 0x04,
0xAD, 0x30, 0x00, 0x80,
0x03, 0x01, 0x06, 0x03,
0x00, 0x00, 0x01, 0x00,
0xAD, 0x38, 0x01, 0x00,
0x01, 0xE0, 0x01, 0x40,
0x00, 0x10, 0x00, 0x10,
0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x01,
0x54, 0x58, 0x00, 0x40,
0x04, 0x1A, 0x02, 0x00,
0x54, 0x5C, 0x01, 0x40,
0x00, 0x01, 0x00, 0x51,
0x00, 0x00, 0x0F, 0xA0,
0x0F, 0xA0, 0x03, 0xE8,
0x02, 0x80, 0x1F, 0x40,
0x00, 0x00, 0x05, 0x00,
0x54, 0x70, 0x00, 0x80,
0x03, 0x20, 0x03, 0x20,
0x00, 0x00, 0x00, 0x08,
0x54, 0x78, 0x01, 0x00,
0x01, 0x1B, 0x00, 0x21,
0x00, 0x33, 0x00, 0x00,
0x02, 0x00, 0x00, 0x01,
0x04, 0x01, 0x08, VL53L8CX_FW_NBTAR_XTALK,
0x54, 0x88, 0x01, 0x40,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x00,
0xAD, 0x48, 0x01, 0x00,
0x01, 0xF4, 0x00, 0x00,
0x03, 0x06, 0x00, 0x10,
0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x00, 0x08,
0xAD, 0x60, 0x01, 0x00,
0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00,
0x20, 0x1F, 0x01, 0xF4,
0x00, 0x00, 0x1D, 0x0A,
0xAD, 0x70, 0x00, 0x80,
0x08, 0x00, 0x1F, 0x40,
0x00, 0x00, 0x00, 0x01,
0xAD, 0x78, 0x00, 0x80,
0x00, 0xA0, 0x03, 0x20,
0x00, 0x01, 0x01, 0x90,
0xAD, 0x80, 0x00, 0x40,
0x00, 0x00, 0x28, 0x00,
0xAD, 0x84, 0x00, 0x80,
0x00, 0x00, 0x32, 0x00,
0x03, 0x20, 0x00, 0x00,
0xAD, 0x8C, 0x00, 0x80,
0x02, 0x58, 0xFF, 0x38,
0x00, 0x00, 0x00, 0x0C,
0xAD, 0x94, 0x01, 0x00,
0x00, 0x01, 0x90, 0x00,
0xFF, 0xFF, 0xFC, 0x00,
0x00, 0x00, 0x04, 0x00,
0x00, 0x00, 0x01, 0x00,
0xAD, 0xA4, 0x00, 0xC0,
0x04, 0x80, 0x06, 0x1A,
0x00, 0x80, 0x05, 0x80,
0x00, 0x00, 0x01, 0x06,
0xAD, 0xB0, 0x00, 0xC0,
0x04, 0x80, 0x06, 0x1A,
0x19, 0x00, 0x05, 0x80,
0x00, 0x00, 0x01, 0x90,
0xAD, 0xBC, 0x04, 0x40,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x12, 0x00, 0x25,
0x00, 0x00, 0x00, 0x06,
0x00, 0x00, 0x00, 0x05,
0x00, 0x00, 0x00, 0x05,
0x00, 0x00, 0x00, 0x06,
0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x0F,
0x00, 0x00, 0x00, 0x5A,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x09,
0x0B, 0x0C, 0x0B, 0x0B,
0x03, 0x03, 0x11, 0x05,
0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x0D, 0x00, 0x00,
0xAE, 0x00, 0x01, 0x04,
0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x0A,
0x00, 0x00, 0x00, 0x0C,
0x00, 0x00, 0x00, 0x0D,
0x00, 0x00, 0x00, 0x0E,
0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x10,
0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x20,
0x00, 0x00, 0x00, 0x06,
0x00, 0x00, 0x05, 0x0A,
0x02, 0x00, 0x0C, 0x08,
0x00, 0x00, 0x00, 0x00,
0xAE, 0x40, 0x00, 0x40,
0x00, 0x00, 0x00, 0xFF,
0xAE, 0x44, 0x00, 0x40,
0x00, 0x10, 0x04, 0x01,
0xAE, 0x48, 0x00, 0x40,
0x00, 0x00, 0x10, 0x00,
0xAE, 0x4C, 0x00, 0x40,
0x00, 0x00, 0x00, 0x01,
0xAE, 0x50, 0x01, 0x40,
0x00, 0x00, 0x00, 0x14,
0x04, 0x00, 0x28, 0x00,
0x03, 0x20, 0x6C, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xAE, 0x64, 0x00, 0x40,
0x00, 0x00, 0x00, 0x01,
0xAE, 0xD8, 0x01, 0x00,
0x00, 0xC8, 0x05, 0xDC,
0x00, 0x00, 0x0C, 0xCD,
0x01, 0x04, 0x00, 0x00,
0x00, 0x01, 0x26, 0x01,
0xB5, 0x50, 0x02, 0x82,
0xA3, 0xE8, 0xA3, 0xB8,
0xA4, 0x38, 0xA4, 0x28,
0xA6, 0x48, 0xA4, 0x48,
0xA7, 0x88, 0xA7, 0x48,
0xAC, 0x10, 0xA7, 0x90,
0x99, 0xBC, 0x99, 0xB4,
0x9A, 0xFC, 0x9A, 0xBC,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB5, 0xA0, 0x02, 0x82,
0x00, 0x88, 0x03, 0x00,
0x00, 0x82, 0x00, 0x82,
0x04, 0x04, 0x04, 0x08,
0x00, 0x80, 0x04, 0x01,
0x09, 0x02, 0x09, 0x08,
0x04, 0x04, 0x00, 0x80,
0x04, 0x01, 0x04, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB5, 0xF0, 0x00, 0x40,
0x00, 0x04, 0x00, 0x00,
0xB3, 0x9C, 0x01, 0x00,
0x40, 0x00, 0x05, 0x1E,
0x02, 0x1B, 0x08, 0x7C,
0x80, 0x00, 0x12, 0x01,
0x00, 0x01, 0x08, 0x00,
0xB6, 0xC0, 0x00, 0xC0,
0x00, 0x00, 0x60, 0x00,
0x00, 0x00, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00,
0xAE, 0xA8, 0x00, 0x40,
0x00, 0x00, 0x04, 0x05,
0xAE, 0xAC, 0x00, 0x80,
0x01, 0x00, 0x01, 0x00,
0x00, 0x02, 0x00, 0x00,
0xAE, 0xB4, 0x00, 0x40,
0x00, 0x00, 0x00, 0x00,
0xAE, 0xB8, 0x00, 0x81,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xAE, 0xC0, 0x00, 0x81,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xAE, 0xC8, 0x00, 0x81,
0x08, 0x01, 0x01, 0x08,
0x00, 0x00, 0x00, 0x08,
0xAE, 0xD0, 0x00, 0x81,
0x01, 0x08, 0x08, 0x08,
0x00, 0x00, 0x00, 0x01,
0xB5, 0xF4, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB5, 0xFC, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x04, 0x00, 0x40,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x08, 0x00, 0x44,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x18, 0x00, 0x44,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x28, 0x00, 0x44,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x38, 0x00, 0x44,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x48, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x58, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xB6, 0x68, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x54, 0x70, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x0F,
0x00, 0x01, 0x03, 0xD4
};
#endif /* VL53L8CX_PLUGIN_XTALK_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,187 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include "vl53l8cx_plugin_detection_thresholds.h"
uint8_t vl53l8cx_get_detection_thresholds_enable(
VL53L8CX_Configuration *p_dev,
uint8_t *p_enabled)
{
uint8_t status = VL53L8CX_STATUS_OK;
status |= vl53l8cx_dci_read_data(p_dev, (uint8_t*)p_dev->temp_buffer,
VL53L8CX_DCI_DET_THRESH_GLOBAL_CONFIG, 8);
*p_enabled = p_dev->temp_buffer[0x1];
return status;
}
uint8_t vl53l8cx_set_detection_thresholds_enable(
VL53L8CX_Configuration *p_dev,
uint8_t enabled)
{
uint8_t tmp, status = VL53L8CX_STATUS_OK;
uint8_t grp_global_config[] = {0x01, 0x00, 0x01, 0x00};
if(enabled == (uint8_t)1)
{
grp_global_config[0x01] = 0x01;
tmp = 0x04;
}
else
{
grp_global_config[0x01] = 0x00;
tmp = 0x0C;
}
/* Set global interrupt config */
status |= vl53l8cx_dci_replace_data(p_dev, p_dev->temp_buffer,
VL53L8CX_DCI_DET_THRESH_GLOBAL_CONFIG, 8,
(uint8_t*)&grp_global_config, 4, 0x00);
/* Update interrupt config */
status |= vl53l8cx_dci_replace_data(p_dev, p_dev->temp_buffer,
VL53L8CX_DCI_DET_THRESH_CONFIG, 20,
(uint8_t*)&tmp, 1, 0x11);
return status;
}
uint8_t vl53l8cx_get_detection_thresholds(
VL53L8CX_Configuration *p_dev,
VL53L8CX_DetectionThresholds *p_thresholds)
{
uint8_t i, status = VL53L8CX_STATUS_OK;
/* Get thresholds configuration */
status |= vl53l8cx_dci_read_data(p_dev, (uint8_t*)p_thresholds,
VL53L8CX_DCI_DET_THRESH_START,
(uint16_t)VL53L8CX_NB_THRESHOLDS
*(uint16_t)sizeof(VL53L8CX_DetectionThresholds));
for(i = 0; i < (uint8_t)VL53L8CX_NB_THRESHOLDS; i++)
{
switch(p_thresholds[i].measurement)
{
case VL53L8CX_DISTANCE_MM:
p_thresholds[i].param_low_thresh /= 4;
p_thresholds[i].param_high_thresh /= 4;
break;
case VL53L8CX_SIGNAL_PER_SPAD_KCPS:
p_thresholds[i].param_low_thresh /= 2048;
p_thresholds[i].param_high_thresh /= 2048;
break;
case VL53L8CX_RANGE_SIGMA_MM:
p_thresholds[i].param_low_thresh /= 128;
p_thresholds[i].param_high_thresh /= 128;
break;
case VL53L8CX_AMBIENT_PER_SPAD_KCPS:
p_thresholds[i].param_low_thresh /= 2048;
p_thresholds[i].param_high_thresh /= 2048;
break;
case VL53L8CX_NB_SPADS_ENABLED:
p_thresholds[i].param_low_thresh /= 256;
p_thresholds[i].param_high_thresh /= 256;
break;
case VL53L8CX_MOTION_INDICATOR:
p_thresholds[i].param_low_thresh /= 65535;
p_thresholds[i].param_high_thresh /= 65535;
break;
default:
break;
}
}
return status;
}
uint8_t vl53l8cx_set_detection_thresholds(
VL53L8CX_Configuration *p_dev,
VL53L8CX_DetectionThresholds *p_thresholds)
{
uint8_t i, status = VL53L8CX_STATUS_OK;
uint8_t grp_valid_target_cfg[] = {0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05};
for(i = 0; i < (uint8_t) VL53L8CX_NB_THRESHOLDS; i++)
{
switch(p_thresholds->measurement)
{
case VL53L8CX_DISTANCE_MM:
p_thresholds[i].param_low_thresh *= 4;
p_thresholds[i].param_high_thresh *= 4;
break;
case VL53L8CX_SIGNAL_PER_SPAD_KCPS:
p_thresholds[i].param_low_thresh *= 2048;
p_thresholds[i].param_high_thresh *= 2048;
break;
case VL53L8CX_RANGE_SIGMA_MM:
p_thresholds[i].param_low_thresh *= 128;
p_thresholds[i].param_high_thresh *= 128;
break;
case VL53L8CX_AMBIENT_PER_SPAD_KCPS:
p_thresholds[i].param_low_thresh *= 2048;
p_thresholds[i].param_high_thresh *= 2048;
break;
case VL53L8CX_NB_SPADS_ENABLED:
p_thresholds[i].param_low_thresh *= 256;
p_thresholds[i].param_high_thresh *= 256;
break;
case VL53L8CX_MOTION_INDICATOR:
p_thresholds[i].param_low_thresh *= 65535;
p_thresholds[i].param_high_thresh *= 65535;
break;
default:
break;
}
}
/* Set valid target list */
status |= vl53l8cx_dci_write_data(p_dev, (uint8_t*)grp_valid_target_cfg,
VL53L8CX_DCI_DET_THRESH_VALID_STATUS,
(uint16_t)sizeof(grp_valid_target_cfg));
/* Set thresholds configuration */
status |= vl53l8cx_dci_write_data(p_dev, (uint8_t*)p_thresholds,
VL53L8CX_DCI_DET_THRESH_START,
(uint16_t)(VL53L8CX_NB_THRESHOLDS
*sizeof(VL53L8CX_DetectionThresholds)));
return status;
}
uint8_t vl53l8cx_get_detection_thresholds_auto_stop(
VL53L8CX_Configuration *p_dev,
uint8_t *p_auto_stop)
{
uint8_t status = VL53L8CX_STATUS_OK;
status |= vl53l8cx_dci_read_data(p_dev, (uint8_t*)p_dev->temp_buffer,
VL53L8CX_DCI_PIPE_CONTROL, 4);
*p_auto_stop = p_dev->temp_buffer[0x3];
return status;
}
uint8_t vl53l8cx_set_detection_thresholds_auto_stop(
VL53L8CX_Configuration *p_dev,
uint8_t auto_stop)
{
uint8_t status = VL53L8CX_STATUS_OK;
status |= vl53l8cx_dci_replace_data(p_dev, p_dev->temp_buffer,
VL53L8CX_DCI_PIPE_CONTROL, 4,
(uint8_t*)&auto_stop, 1, 0x03);
p_dev->is_auto_stop_enabled = (uint8_t)auto_stop;
return status;
}

View File

@ -0,0 +1,122 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include <math.h>
#include "vl53l8cx_plugin_motion_indicator.h"
uint8_t vl53l8cx_motion_indicator_init(
VL53L8CX_Configuration *p_dev,
VL53L8CX_Motion_Configuration *p_motion_config,
uint8_t resolution)
{
uint8_t status = VL53L8CX_STATUS_OK;
(void)memset(p_motion_config, 0, sizeof(VL53L8CX_Motion_Configuration));
p_motion_config->ref_bin_offset = 13633;
p_motion_config->detection_threshold = 2883584;
p_motion_config->extra_noise_sigma = 0;
p_motion_config->null_den_clip_value = 0;
p_motion_config->mem_update_mode = 6;
p_motion_config->mem_update_choice = 2;
p_motion_config->sum_span = 4;
p_motion_config->feature_length = 9;
p_motion_config->nb_of_aggregates = 16;
p_motion_config->nb_of_temporal_accumulations = 16;
p_motion_config->min_nb_for_global_detection = 1;
p_motion_config->global_indicator_format_1 = 8;
p_motion_config->global_indicator_format_2 = 0;
p_motion_config->spare_1 = 0;
p_motion_config->spare_2 = 0;
p_motion_config->spare_3 = 0;
status |= vl53l8cx_motion_indicator_set_resolution(p_dev,
p_motion_config, resolution);
return status;
}
uint8_t vl53l8cx_motion_indicator_set_distance_motion(
VL53L8CX_Configuration *p_dev,
VL53L8CX_Motion_Configuration *p_motion_config,
uint16_t distance_min_mm,
uint16_t distance_max_mm)
{
uint8_t status = VL53L8CX_STATUS_OK;
float_t tmp;
if(((distance_max_mm - distance_min_mm) > (uint16_t)1500)
|| (distance_min_mm < (uint16_t)400)
|| (distance_max_mm > (uint16_t)4000))
{
status |= VL53L8CX_STATUS_INVALID_PARAM;
}
else
{
tmp = (float_t)((((float_t)distance_min_mm/(float_t)37.5348)
-(float_t)4.0)*(float_t)2048.5);
p_motion_config->ref_bin_offset = (int32_t)tmp;
tmp = (float_t)((((((float_t)distance_max_mm-
(float_t)distance_min_mm)/(float_t)10.0)+(float_t)30.02784)
/((float_t)15.01392))+(float_t)0.5);
p_motion_config->feature_length = (uint8_t)tmp;
status |= vl53l8cx_dci_write_data(p_dev,
(uint8_t*)(p_motion_config),
VL53L8CX_DCI_MOTION_DETECTOR_CFG,
(uint16_t)sizeof(*p_motion_config));
}
return status;
}
uint8_t vl53l8cx_motion_indicator_set_resolution(
VL53L8CX_Configuration *p_dev,
VL53L8CX_Motion_Configuration *p_motion_config,
uint8_t resolution)
{
uint8_t i, status = VL53L8CX_STATUS_OK;
switch(resolution)
{
case VL53L8CX_RESOLUTION_4X4:
for(i = 0; i < (uint8_t)VL53L8CX_RESOLUTION_4X4; i++)
{
p_motion_config->map_id[i] = (int8_t)i;
}
(void)memset(p_motion_config->map_id + 16, -1, 48);
break;
case VL53L8CX_RESOLUTION_8X8:
for(i = 0; i < (uint8_t)VL53L8CX_RESOLUTION_8X8; i++)
{
p_motion_config->map_id[i] = (int8_t)((((int8_t)
i % 8)/2) + (4*((int8_t)i/16)));
}
break;
default:
status |= VL53L8CX_STATUS_ERROR;
break;
}
if(status == VL53L8CX_STATUS_OK)
{
status |= vl53l8cx_dci_write_data(p_dev,
(uint8_t*)(p_motion_config),
VL53L8CX_DCI_MOTION_DETECTOR_CFG,
(uint16_t)sizeof(*p_motion_config));
}
return status;
}

View File

@ -0,0 +1,366 @@
/**
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
#include "vl53l8cx_plugin_xtalk.h"
/*
* Inner function, not available outside this file. This function is used to
* wait for an answer from VL53L5 sensor.
*/
static uint8_t _vl53l8cx_poll_for_answer(
VL53L8CX_Configuration *p_dev,
uint16_t address,
uint8_t expected_value)
{
uint8_t status = VL53L8CX_STATUS_OK;
uint8_t timeout = 0;
do {
status |= RdMulti(&(p_dev->platform),
address, p_dev->temp_buffer, 4);
status |= WaitMs(&(p_dev->platform), 10);
/* 2s timeout or FW error*/
if((timeout >= (uint8_t)200)
|| (p_dev->temp_buffer[2] >= (uint8_t) 0x7f))
{
status |= VL53L8CX_MCU_ERROR;
break;
}
else
{
timeout++;
}
}while ((p_dev->temp_buffer[0x1]) != expected_value);
return status;
}
/*
* Inner function, not available outside this file. This function is used to
* program the output using the macro defined into the 'platform.h' file.
*/
static uint8_t _vl53l8cx_program_output_config(
VL53L8CX_Configuration *p_dev)
{
uint8_t resolution, status = VL53L8CX_STATUS_OK;
uint32_t i;
uint32_t header_config[2] = {0, 0};
union Block_header *bh_ptr;
status |= vl53l8cx_get_resolution(p_dev, &resolution);
p_dev->data_read_size = 0;
/* Enable mandatory output (meta and common data) */
uint32_t output_bh_enable[] = {
0x0001FFFFU,
0x00000000U,
0x00000000U,
0xC0000000U};
/* Send addresses of possible output */
uint32_t output[] ={
0x0000000DU,
0x54000040U,
0x9FD800C0U,
0x9FE40140U,
0x9FF80040U,
0x9FFC0404U,
0xA0FC0100U,
0xA10C0100U,
0xA11C00C0U,
0xA1280902U,
0xA2480040U,
0xA24C0081U,
0xA2540081U,
0xA25C0081U,
0xA2640081U,
0xA26C0084U,
0xA28C0082U};
/* Update data size */
for (i = 0; i < (uint32_t)(sizeof(output)/sizeof(uint32_t)); i++)
{
if ((output[i] == (uint8_t)0)
|| ((output_bh_enable[i/(uint32_t)32]
&((uint32_t)1 << (i%(uint32_t)32))) == (uint32_t)0))
{
continue;
}
bh_ptr = (union Block_header *)&(output[i]);
if (((uint8_t)bh_ptr->type >= (uint8_t)0x1)
&& ((uint8_t)bh_ptr->type < (uint8_t)0x0d))
{
if ((bh_ptr->idx >= (uint16_t)0x54d0)
&& (bh_ptr->idx < (uint16_t)(0x54d0 + 960)))
{
bh_ptr->size = resolution;
}
else
{
bh_ptr->size = (uint8_t)(resolution
* (uint8_t)VL53L8CX_NB_TARGET_PER_ZONE);
}
p_dev->data_read_size += bh_ptr->type * bh_ptr->size;
}
else
{
p_dev->data_read_size += bh_ptr->size;
}
p_dev->data_read_size += (uint32_t)4;
}
p_dev->data_read_size += (uint32_t)24;
status |= vl53l8cx_dci_write_data(p_dev,
(uint8_t*)&(output),
VL53L8CX_DCI_OUTPUT_LIST, (uint16_t)sizeof(output));
header_config[0] = p_dev->data_read_size;
header_config[1] = i + (uint32_t)1;
status |= vl53l8cx_dci_write_data(p_dev, (uint8_t*)&(header_config),
VL53L8CX_DCI_OUTPUT_CONFIG,
(uint16_t)sizeof(header_config));
status |= vl53l8cx_dci_write_data(p_dev, (uint8_t*)&(output_bh_enable),
VL53L8CX_DCI_OUTPUT_ENABLES,
(uint16_t)sizeof(output_bh_enable));
return status;
}
uint8_t vl53l8cx_calibrate_xtalk(
VL53L8CX_Configuration *p_dev,
uint16_t reflectance_percent,
uint8_t nb_samples,
uint16_t distance_mm)
{
uint16_t timeout = 0;
uint8_t cmd[] = {0x00, 0x03, 0x00, 0x00};
uint8_t footer[] = {0x00, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x03, 0x04};
uint8_t continue_loop = 1, status = VL53L8CX_STATUS_OK;
uint8_t resolution, frequency, target_order, sharp_prct, ranging_mode;
uint32_t integration_time_ms, xtalk_margin;
uint16_t reflectance = reflectance_percent;
uint8_t samples = nb_samples;
uint16_t distance = distance_mm;
uint8_t *default_xtalk_ptr;
/* Get initial configuration */
status |= vl53l8cx_get_resolution(p_dev, &resolution);
status |= vl53l8cx_get_ranging_frequency_hz(p_dev, &frequency);
status |= vl53l8cx_get_integration_time_ms(p_dev, &integration_time_ms);
status |= vl53l8cx_get_sharpener_percent(p_dev, &sharp_prct);
status |= vl53l8cx_get_target_order(p_dev, &target_order);
status |= vl53l8cx_get_xtalk_margin(p_dev, &xtalk_margin);
status |= vl53l8cx_get_ranging_mode(p_dev, &ranging_mode);
/* Check input arguments validity */
if(((reflectance < (uint16_t)1) || (reflectance > (uint16_t)99))
|| ((distance < (uint16_t)600) || (distance > (uint16_t)3000))
|| ((samples < (uint8_t)1) || (samples > (uint8_t)16)))
{
status |= VL53L8CX_STATUS_INVALID_PARAM;
}
else
{
status |= vl53l8cx_set_resolution(p_dev,
VL53L8CX_RESOLUTION_8X8);
/* Send Xtalk calibration buffer */
(void)memcpy(p_dev->temp_buffer, VL53L8CX_CALIBRATE_XTALK,
sizeof(VL53L8CX_CALIBRATE_XTALK));
status |= WrMulti(&(p_dev->platform), 0x2c28,
p_dev->temp_buffer,
(uint16_t)sizeof(VL53L8CX_CALIBRATE_XTALK));
status |= _vl53l8cx_poll_for_answer(p_dev,
VL53L8CX_UI_CMD_STATUS, 0x3);
/* Format input argument */
reflectance = reflectance * (uint16_t)16;
distance = distance * (uint16_t)4;
/* Update required fields */
status |= vl53l8cx_dci_replace_data(p_dev, p_dev->temp_buffer,
VL53L8CX_DCI_CAL_CFG, 8,
(uint8_t*)&distance, 2, 0x00);
status |= vl53l8cx_dci_replace_data(p_dev, p_dev->temp_buffer,
VL53L8CX_DCI_CAL_CFG, 8,
(uint8_t*)&reflectance, 2,0x02);
status |= vl53l8cx_dci_replace_data(p_dev, p_dev->temp_buffer,
VL53L8CX_DCI_CAL_CFG, 8,
(uint8_t*)&samples, 1, 0x04);
/* Program output for Xtalk calibration */
status |= _vl53l8cx_program_output_config(p_dev);
/* Start ranging session */
status |= WrMulti(&(p_dev->platform),
VL53L8CX_UI_CMD_END - (uint16_t)(4 - 1),
(uint8_t*)cmd, sizeof(cmd));
status |= _vl53l8cx_poll_for_answer(p_dev,
VL53L8CX_UI_CMD_STATUS, 0x3);
/* Wait for end of calibration */
do {
status |= RdMulti(&(p_dev->platform),
0x0, p_dev->temp_buffer, 4);
if(p_dev->temp_buffer[0] != VL53L8CX_STATUS_ERROR)
{
/* Coverglass too good for Xtalk calibration */
if((p_dev->temp_buffer[2] >= (uint8_t)0x7f) &&
(((uint16_t)(p_dev->temp_buffer[3] &
(uint16_t)0x80) >> 7) == (uint16_t)1))
{
default_xtalk_ptr = p_dev->default_xtalk;
(void)memcpy(p_dev->xtalk_data,
default_xtalk_ptr,
sizeof(p_dev->xtalk_data));
status |= VL53L8CX_STATUS_XTALK_FAILED;
}
continue_loop = (uint8_t)0;
}
else if(timeout >= (uint16_t)400)
{
status |= VL53L8CX_STATUS_ERROR;
continue_loop = (uint8_t)0;
}
else
{
timeout++;
status |= WaitMs(&(p_dev->platform), 50);
}
}while (continue_loop == (uint8_t)1);
}
/* Save Xtalk data into the Xtalk buffer */
(void)memcpy(p_dev->temp_buffer, VL53L8CX_GET_XTALK_CMD,
sizeof(VL53L8CX_GET_XTALK_CMD));
status |= WrMulti(&(p_dev->platform), 0x2fb8,
p_dev->temp_buffer,
(uint16_t)sizeof(VL53L8CX_GET_XTALK_CMD));
status |= _vl53l8cx_poll_for_answer(p_dev,VL53L8CX_UI_CMD_STATUS, 0x03);
status |= RdMulti(&(p_dev->platform), VL53L8CX_UI_CMD_START,
p_dev->temp_buffer,
VL53L8CX_XTALK_BUFFER_SIZE + (uint16_t)4);
(void)memcpy(&(p_dev->xtalk_data[0]), &(p_dev->temp_buffer[8]),
VL53L8CX_XTALK_BUFFER_SIZE - (uint16_t)8);
(void)memcpy(&(p_dev->xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE
- (uint16_t)8]), footer, sizeof(footer));
/* Reset default buffer */
status |= WrMulti(&(p_dev->platform), 0x2c34,
p_dev->default_configuration,
VL53L8CX_CONFIGURATION_SIZE);
status |= _vl53l8cx_poll_for_answer(p_dev,VL53L8CX_UI_CMD_STATUS, 0x03);
/* Reset initial configuration */
status |= vl53l8cx_set_resolution(p_dev, resolution);
status |= vl53l8cx_set_ranging_frequency_hz(p_dev, frequency);
status |= vl53l8cx_set_integration_time_ms(p_dev, integration_time_ms);
status |= vl53l8cx_set_sharpener_percent(p_dev, sharp_prct);
status |= vl53l8cx_set_target_order(p_dev, target_order);
status |= vl53l8cx_set_xtalk_margin(p_dev, xtalk_margin);
status |= vl53l8cx_set_ranging_mode(p_dev, ranging_mode);
return status;
}
uint8_t vl53l8cx_get_caldata_xtalk(
VL53L8CX_Configuration *p_dev,
uint8_t *p_xtalk_data)
{
uint8_t status = VL53L8CX_STATUS_OK, resolution;
uint8_t footer[] = {0x00, 0x00, 0x00, 0x0F, 0x00, 0x01, 0x03, 0x04};
status |= vl53l8cx_get_resolution(p_dev, &resolution);
status |= vl53l8cx_set_resolution(p_dev, VL53L8CX_RESOLUTION_8X8);
(void)memcpy(p_dev->temp_buffer, VL53L8CX_GET_XTALK_CMD,
sizeof(VL53L8CX_GET_XTALK_CMD));
status |= WrMulti(&(p_dev->platform), 0x2fb8,
p_dev->temp_buffer, sizeof(VL53L8CX_GET_XTALK_CMD));
status |= _vl53l8cx_poll_for_answer(p_dev,VL53L8CX_UI_CMD_STATUS, 0x03);
status |= RdMulti(&(p_dev->platform), VL53L8CX_UI_CMD_START,
p_dev->temp_buffer,
VL53L8CX_XTALK_BUFFER_SIZE + (uint16_t)4);
(void)memcpy(&(p_xtalk_data[0]), &(p_dev->temp_buffer[8]),
VL53L8CX_XTALK_BUFFER_SIZE-(uint16_t)8);
(void)memcpy(&(p_xtalk_data[VL53L8CX_XTALK_BUFFER_SIZE - (uint16_t)8]),
footer, sizeof(footer));
status |= vl53l8cx_set_resolution(p_dev, resolution);
return status;
}
uint8_t vl53l8cx_set_caldata_xtalk(
VL53L8CX_Configuration *p_dev,
uint8_t *p_xtalk_data)
{
uint8_t resolution, status = VL53L8CX_STATUS_OK;
status |= vl53l8cx_get_resolution(p_dev, &resolution);
(void)memcpy(p_dev->xtalk_data, p_xtalk_data, VL53L8CX_XTALK_BUFFER_SIZE);
status |= vl53l8cx_set_resolution(p_dev, resolution);
return status;
}
uint8_t vl53l8cx_get_xtalk_margin(
VL53L8CX_Configuration *p_dev,
uint32_t *p_xtalk_margin)
{
uint8_t status = VL53L8CX_STATUS_OK;
status |= vl53l8cx_dci_read_data(p_dev, (uint8_t*)p_dev->temp_buffer,
VL53L8CX_DCI_XTALK_CFG, 16);
(void)memcpy(p_xtalk_margin, p_dev->temp_buffer, 4);
*p_xtalk_margin = *p_xtalk_margin/(uint32_t)2048;
return status;
}
uint8_t vl53l8cx_set_xtalk_margin(
VL53L8CX_Configuration *p_dev,
uint32_t xtalk_margin)
{
uint8_t status = VL53L8CX_STATUS_OK;
uint32_t margin_kcps = xtalk_margin;
if(margin_kcps > (uint32_t)10000)
{
status |= VL53L8CX_STATUS_INVALID_PARAM;
}
else
{
margin_kcps = margin_kcps*(uint32_t)2048;
status |= vl53l8cx_dci_replace_data(p_dev, p_dev->temp_buffer,
VL53L8CX_DCI_XTALK_CFG, 16,
(uint8_t*)&margin_kcps, 4, 0x00);
}
return status;
}

207
main.c Normal file
View File

@ -0,0 +1,207 @@
/*******************************************************************************
* Copyright (c) 2020, STMicroelectronics - All Rights Reserved
*
* This file is part of the VL53L8CX Ultra Lite Driver and is dual licensed,
* either 'STMicroelectronics Proprietary license'
* or 'BSD 3-clause "New" or "Revised" License' , at your option.
*
********************************************************************************
*
* 'STMicroelectronics Proprietary license'
*
********************************************************************************
*
* License terms: STMicroelectronics Proprietary in accordance with licensing
* terms at www.st.com/sla0081
*
* STMicroelectronics confidential
* Reproduction and Communication of this document is strictly prohibited unless
* specifically authorized in writing by STMicroelectronics.
*
*
********************************************************************************
*
* Alternatively, the VL53L8CX Ultra Lite Driver may be distributed under the
* terms of 'BSD 3-clause "New" or "Revised" License', in which case the
* following provisions apply instead of the ones mentioned above :
*
********************************************************************************
*
* License terms: BSD 3-clause "New" or "Revised" License.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
*******************************************************************************/
/***********************************/
/* VL53L8CX ULD basic example */
/***********************************/
/*
* This example is the most basic. It initializes the VL53L8CX ULD, and starts
* a ranging to capture 10 frames.
*
* By default, ULD is configured to have the following settings :
* - Resolution 4x4
* - Ranging period 1Hz
*
* In this example, we also suppose that the number of target per zone is
* set to 1 , and all output are enabled (see file platform.h).
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vl53l8cx_api.h"
#include "pico/stdlib.h"
#include "hardware/i2c.h"
void main(void)
{
stdio_init_all();
gpio_set_function(0, GPIO_FUNC_I2C);
gpio_set_function(1, GPIO_FUNC_I2C);
i2c_init(i2c0, 100 * 1000);
printf("3\n");
WaitMs(0, 1000);
printf("2\n");
WaitMs(0, 1000);
printf("1\n");
WaitMs(0, 1000);
printf("0\n");
WaitMs(0, 1000);
/*********************************/
/* VL53L8CX ranging variables */
/*********************************/
uint8_t status, loop, isAlive, isReady, i;
VL53L8CX_Configuration Dev; /* Sensor configuration */
VL53L8CX_ResultsData Results; /* Results data from VL53L8CX */
/*********************************/
/* Customer platform */
/*********************************/
/* Fill the platform structure with customer's implementation. For this
* example, only the I2C address is used.
*/
Dev.platform.address = VL53L8CX_DEFAULT_I2C_ADDRESS;
/* (Optional) Reset sensor toggling PINs (see platform, not in API) */
//Reset_Sensor(&(Dev.platform));
/* (Optional) Set a new I2C address if the wanted address is different
* from the default one (filled with 0x20 for this example).
*/
//status = vl53l8cx_set_i2c_address(&Dev, 0x20);
/*********************************/
/* Power on sensor and init */
/*********************************/
/* (Optional) Check if there is a VL53L8CX sensor connected */
status = vl53l8cx_is_alive(&Dev, &isAlive);
if(!isAlive || status)
{
printf("VL53L8CX not detected at requested address\n");
while(1);
}else{printf("VL53L8CX detected !\n");
}
/* (Mandatory) Init VL53L8CX sensor */
status = vl53l8cx_init(&Dev);
if(status)
{
while(1){
printf("VL53L8CX ULD Loading failed :%d\n", status);
WaitMs(&(Dev.platform), 1000);
}
return;
}
printf("VL53L8CX ULD ready ! (Version : %s)\n",
VL53L8CX_API_REVISION);
/*********************************/
/* Ranging loop */
/*********************************/
status = vl53l8cx_start_ranging(&Dev);
loop = 0;
while(1)
{
/* Use polling function to know when a new measurement is ready.
* Another way can be to wait for HW interrupt raised on PIN A1
* (INT) when a new measurement is ready */
status = vl53l8cx_check_data_ready(&Dev, &isReady);
if(isReady)
{
vl53l8cx_get_ranging_data(&Dev, &Results);
/* As the sensor is set in 4x4 mode by default, we have a total
* of 16 zones to print. For this example, only the data of first zone are
* print */
printf("Print data no : %3u\n", Dev.streamcount);
/*for(i = 0; i < 16; i++)
{
printf("Zone : %3d, Status : %3u, Distance : %4d mm\n",
i,
Results.target_status[VL53L8CX_NB_TARGET_PER_ZONE*i],
Results.distance_mm[VL53L8CX_NB_TARGET_PER_ZONE*i]);
}*/
printf("%4d,%4d,%4d,%4d\n%4d,%4d,%4d,%4d\n%4d,%4d,%4d,%4d\n%4d,%4d,%4d,%4d\n",
Results.distance_mm[0],Results.distance_mm[1],Results.distance_mm[2],Results.distance_mm[3],
Results.distance_mm[4],Results.distance_mm[5],Results.distance_mm[6],Results.distance_mm[7],
Results.distance_mm[8],Results.distance_mm[9],Results.distance_mm[10],Results.distance_mm[11],
Results.distance_mm[12],Results.distance_mm[13],Results.distance_mm[14],Results.distance_mm[15]
);
printf("\n");
loop++;
}
/* Wait a few ms to avoid too high polling (function in platform
* file, not in API) */
WaitMs(&(Dev.platform), 5);
}
status = vl53l8cx_stop_ranging(&Dev);
printf("End of ULD demo\n");
return;
}

62
pico_sdk_import.cmake Normal file
View File

@ -0,0 +1,62 @@
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
# This can be dropped into an external project to help locate this SDK
# It should be include()ed prior to project()
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
endif ()
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
endif ()
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
if (NOT PICO_SDK_PATH)
if (PICO_SDK_FETCH_FROM_GIT)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
if (PICO_SDK_FETCH_FROM_GIT_PATH)
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
endif ()
FetchContent_Declare(
pico_sdk
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
GIT_TAG master
)
if (NOT pico_sdk)
message("Downloading Raspberry Pi Pico SDK")
FetchContent_Populate(pico_sdk)
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
endif ()
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
else ()
message(FATAL_ERROR
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
)
endif ()
endif ()
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
if (NOT EXISTS ${PICO_SDK_PATH})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
endif ()
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
endif ()
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
include(${PICO_SDK_INIT_CMAKE_FILE})