├── raspberry-vl53l1x.png ├── vl53l1x ├── launch │ ├── max_distance.launch │ ├── max_rate.launch │ └── example.launch ├── src │ ├── i2c.h │ ├── i2c.cpp │ └── vl53l1x.cpp ├── CHANGELOG.rst ├── msg │ └── MeasurementData.msg ├── package.xml ├── lib │ ├── platform │ │ ├── vl53l1_platform.c │ │ ├── vl53l1_platform_user_data.h │ │ ├── vl53l1_platform_user_defines.h │ │ ├── vl53l1_platform_user_config.h │ │ ├── vl53l1_platform.h │ │ ├── vl53l1_types.h │ │ ├── vl53l1_platform.c.orig │ │ └── vl53l1_platform_log.h │ └── core │ │ ├── vl53l1_silicon_core.h │ │ ├── vl53l1_error_exceptions.h │ │ ├── vl53l1_preset_setup.h │ │ ├── vl53l1_silicon_core.c │ │ ├── vl53l1_core_support.h │ │ ├── vl53l1_api_strings.h │ │ ├── vl53l1_tuning_parm_defaults.h │ │ ├── vl53l1_error_strings.h │ │ ├── vl53l1_api_strings.c │ │ ├── vl53l1_register_settings.h │ │ ├── vl53l1_wait.h │ │ ├── vl53l1_api_calibration.h │ │ ├── vl53l1_error_strings.c │ │ ├── vl53l1_error_codes.h │ │ ├── vl53l1_api_debug.h │ │ └── vl53l1_core_support.c └── CMakeLists.txt ├── .github └── workflows │ └── main.yml ├── LICENSE └── README.md /raspberry-vl53l1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/okalachev/vl53l1x_ros/HEAD/raspberry-vl53l1x.png -------------------------------------------------------------------------------- /vl53l1x/launch/max_distance.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /vl53l1x/launch/max_rate.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /vl53l1x/launch/example.launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /vl53l1x/src/i2c.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __cplusplus 6 | #define EXTERNC extern "C" 7 | #else 8 | #define EXTERNC 9 | #endif 10 | 11 | void i2c_setup(uint8_t bus, uint8_t addr); 12 | 13 | void i2c_release(); 14 | 15 | EXTERNC bool i2c_readRegisterMulti(uint16_t reg, size_t count, void *pdata); 16 | 17 | EXTERNC bool i2c_readRegisterByte(int reg, uint8_t *pdata); 18 | 19 | EXTERNC bool i2c_readRegisterWord(uint16_t reg, uint16_t *pdata); 20 | 21 | EXTERNC bool i2c_writeRegisterMulti(uint16_t reg, size_t count, void *pdata); 22 | 23 | EXTERNC bool i2c_writeRegisterByte(uint16_t reg, uint8_t value); 24 | 25 | EXTERNC bool i2c_writeRegisterWord(uint16_t reg, uint16_t value); 26 | -------------------------------------------------------------------------------- /vl53l1x/CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2 | Changelog for package vl53l1x 3 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 | 5 | 1.0.0 (2021-01-28) 6 | ------------------ 7 | * Change licence to BSD-3-Clause 8 | 9 | 0.4.1 (2021-01-16) 10 | ------------------ 11 | 12 | 0.4.0 (2019-12-05) 13 | ------------------ 14 | * Publish additional data of the measurements 15 | * Publish measurement data even if range status is not valid 16 | * Add status meanings to measurement data message file 17 | * Implement min_signal and max_sigma parameters 18 | * Add pass_statuses parameter for passing range statuses other than 0 19 | * Print device info on startup 20 | * Contributors: Alexey Rogachevskiy, Arthur Golubtsov, Oleg Kalachev 21 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [ '*' ] 6 | pull_request: 7 | branches: [ master ] 8 | workflow_dispatch: 9 | 10 | jobs: 11 | melodic: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v4 15 | - name: Build for ROS Melodic 16 | env: 17 | NATIVE_DOCKER: ros:melodic-ros-base 18 | run: | 19 | docker run --rm -v $(pwd):/root/catkin_ws/src/vl53l1x_ros ${NATIVE_DOCKER} /bin/bash -c \ 20 | "cd /root/catkin_ws && \ 21 | rosdep install --from-paths src --ignore-src -y && \ 22 | catkin_make && \ 23 | catkin_make run_tests && catkin_test_results && \ 24 | catkin_make install" 25 | noetic: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - uses: actions/checkout@v4 29 | - name: Build for ROS Noetic 30 | env: 31 | NATIVE_DOCKER: ros:noetic-ros-base 32 | run: | 33 | docker run --rm -v $(pwd):/root/catkin_ws/src/vl53l1x_ros ${NATIVE_DOCKER} /bin/bash -c \ 34 | "cd /root/catkin_ws && \ 35 | rosdep install --from-paths src --ignore-src -y && \ 36 | catkin_make && \ 37 | catkin_make run_tests && catkin_test_results && \ 38 | catkin_make install" 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019, Oleg Kalachev 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name of {{ project }} nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 21 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vl53l1x/msg/MeasurementData.msg: -------------------------------------------------------------------------------- 1 | Header header 2 | 3 | # Some of the fields of resulting RangingMeasurementData structure. 4 | 5 | float64 signal # return signal rate in MegaCount per second (MCPS) 6 | float64 ambient # return ambient rate in MegaCount per second (MCPS) 7 | uint8 effective_spad # effective SPAD count for the current ranging 8 | float64 sigma # estimation of the standard deviation of the current ranging, m 9 | uint8 status # status for the current measurement, a value of 0 means the ranging is valid 10 | 11 | # Status field meanings: 12 | 13 | uint8 STATUS_RANGE_VALID = 0 # The Range is valid 14 | uint8 STATUS_SIGMA_FAIL = 1 # Sigma Fail 15 | uint8 STATUS_SIGNAL_FAIL = 2 # Signal fail 16 | uint8 STATUS_RANGE_VALID_MIN_RANGE_CLIPPED = 3 # Target is below minimum detection threshold 17 | uint8 STATUS_OUTOFBOUNDS_FAIL = 4 # Phase out of valid limits - different to a wrap exit 18 | uint8 STATUS_HARDWARE_FAIL = 5 # Hardware fail 19 | uint8 STATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL = 6 # The Range is valid but the wraparound check has not been done 20 | uint8 STATUS_WRAP_TARGET_FAIL = 7 # Wrapped target - no matching phase in other VCSEL period timing 21 | uint8 STATUS_PROCESSING_FAIL = 8 # Internal algo underflow or overflow in lite ranging 22 | uint8 STATUS_XTALK_SIGNAL_FAIL = 9 # Specific to lite ranging 23 | uint8 STATUS_SYNCRONISATION_INT = 10 # 1st interrupt when starting ranging in back to back mode. Ignore data 24 | uint8 STATUS_RANGE_VALID_MERGED_PULSE = 11 # All Range ok but object is result of multiple pulses merging together. Used by RQL for merged pulse detection 25 | uint8 STATUS_TARGET_PRESENT_LACK_OF_SIGNAL = 12 # Used by RQL as different to phase fail 26 | uint8 STATUS_MIN_RANGE_FAIL = 13 # User ROI input is not valid e.g. beyond SPAD Array 27 | uint8 STATUS_RANGE_INVALID = 14 # lld returned valid range but negative value 28 | uint8 STATUS_NONE = 255 # No Update 29 | -------------------------------------------------------------------------------- /vl53l1x/src/i2c.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "i2c.h" 9 | 10 | int fd; 11 | 12 | void i2c_setup(uint8_t bus, uint8_t addr) 13 | { 14 | char filename[50]; 15 | sprintf(filename, "/dev/i2c-%d", bus); 16 | 17 | fd = open(filename, O_RDWR); 18 | 19 | if (fd < 0) { 20 | ROS_FATAL("Failed to open I2C bus %d", bus); 21 | ros::shutdown(); 22 | } 23 | 24 | int rc = ioctl(fd, I2C_SLAVE, addr); 25 | if (rc < 0) { 26 | ROS_FATAL("Failed to select I2C device with address 0x%02x", addr); 27 | ros::shutdown(); 28 | } 29 | } 30 | 31 | void i2c_release() 32 | { 33 | close(fd); 34 | } 35 | 36 | bool i2c_readRegisterMulti(uint16_t reg, size_t count, void *pdata) 37 | { 38 | reg = htons(reg); // little endian to big endian 39 | 40 | // write register number 41 | if (write(fd, ®, sizeof(reg)) < 0) { 42 | return false; 43 | } 44 | 45 | return read(fd, pdata, count); 46 | } 47 | 48 | bool i2c_readRegisterByte(int reg, uint8_t *pdata) 49 | { 50 | return i2c_readRegisterMulti(reg, 1, pdata) > 0; 51 | } 52 | 53 | bool i2c_readRegisterWord(uint16_t reg, uint16_t *pdata) 54 | { 55 | if (i2c_readRegisterMulti(reg, 2, pdata) < 0) { 56 | return false; 57 | } 58 | *pdata = ntohs(*pdata); // big endian to little endian 59 | return true; 60 | } 61 | 62 | bool i2c_writeRegisterMulti(uint16_t reg, size_t count, void *pdata) 63 | { 64 | uint8_t buf[count + sizeof(reg)]; 65 | 66 | reg = htons(reg); // little endian to big endian 67 | 68 | memcpy(buf, ®, sizeof(reg)); 69 | memcpy(buf + sizeof(reg), pdata, count); 70 | 71 | return write(fd, buf, count + sizeof(reg)) > 0; 72 | } 73 | 74 | bool i2c_writeRegisterByte(uint16_t reg, uint8_t value) 75 | { 76 | return i2c_writeRegisterMulti(reg, 1, &value); 77 | } 78 | 79 | 80 | bool i2c_writeRegisterWord(uint16_t reg, uint16_t value) 81 | { 82 | value = htons(value); // little endian to big endian 83 | return i2c_writeRegisterMulti(reg, 2, &value); 84 | } 85 | -------------------------------------------------------------------------------- /vl53l1x/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | vl53l1x 4 | 1.0.0 5 | VL53L1X ToF rangefinder driver 6 | 7 | 8 | 9 | 10 | Oleg Kalachev 11 | 12 | BSD 13 | 14 | 15 | 16 | 17 | https://github.com/okalachev/vl53l1x_ros 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | roscpp 26 | sensor_msgs 27 | message_generation 28 | message_runtime 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | catkin 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_platform.c: -------------------------------------------------------------------------------- 1 | /* Based on: https://github.com/pimoroni/vl53l1x-python */ 2 | 3 | #include "vl53l1_platform.h" 4 | #include "vl53l1_api.h" 5 | #include 6 | #include 7 | #include 8 | 9 | #include "i2c.h" 10 | 11 | VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) { 12 | return i2c_writeRegisterMulti(index, count, pdata) ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE; 13 | } 14 | 15 | // the ranging_sensor_comms.dll will take care of the page selection 16 | VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) { 17 | return i2c_readRegisterMulti(index, count, pdata) ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE; 18 | } 19 | 20 | VL53L1_Error VL53L1_WrByte(VL53L1_DEV Dev, uint16_t index, uint8_t data) { 21 | return i2c_writeRegisterByte(index, data) ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE; 22 | } 23 | 24 | VL53L1_Error VL53L1_WrWord(VL53L1_DEV Dev, uint16_t index, uint16_t data) { 25 | return i2c_writeRegisterWord(index, data) ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE; 26 | } 27 | 28 | VL53L1_Error VL53L1_WrDWord(VL53L1_DEV Dev, uint16_t index, uint32_t data) { 29 | VL53L1_Error Status = VL53L1_ERROR_NONE; 30 | return Status; 31 | } 32 | 33 | VL53L1_Error VL53L1_UpdateByte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData, uint8_t OrData) { 34 | VL53L1_Error Status = VL53L1_ERROR_NONE; 35 | return Status; 36 | } 37 | 38 | VL53L1_Error VL53L1_RdByte(VL53L1_DEV Dev, uint16_t index, uint8_t *data) { 39 | return i2c_readRegisterByte(index, data) ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE; 40 | } 41 | 42 | VL53L1_Error VL53L1_RdWord(VL53L1_DEV Dev, uint16_t index, uint16_t *data) { 43 | return i2c_readRegisterWord(index, data) ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE; 44 | } 45 | 46 | VL53L1_Error VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t *data) { 47 | VL53L1_Error Status = VL53L1_ERROR_NONE; 48 | return Status; 49 | } 50 | 51 | VL53L1_Error VL53L1_GetTickCount( 52 | uint32_t *ptick_count_ms) 53 | { 54 | VL53L1_Error status = VL53L1_ERROR_NONE; 55 | return status; 56 | } 57 | 58 | //#define trace_print(level, ...) \ 59 | // _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_PLATFORM, \ 60 | // level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) 61 | 62 | //#define trace_i2c(...) \ 63 | // _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NONE, \ 64 | // VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__) 65 | 66 | VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz) 67 | { 68 | VL53L1_Error status = VL53L1_ERROR_NONE; 69 | return status; 70 | } 71 | 72 | VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms){ 73 | usleep(wait_ms * 1000); 74 | return VL53L1_ERROR_NONE; 75 | } 76 | 77 | VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us){ 78 | usleep(wait_us); 79 | return VL53L1_ERROR_NONE; 80 | } 81 | 82 | VL53L1_Error VL53L1_WaitValueMaskEx( 83 | VL53L1_Dev_t *pdev, 84 | uint32_t timeout_ms, 85 | uint16_t index, 86 | uint8_t value, 87 | uint8_t mask, 88 | uint32_t poll_delay_ms) 89 | { 90 | uint8_t register_value = 0; 91 | 92 | VL53L1_Error status = VL53L1_ERROR_NONE; 93 | 94 | int32_t attempts = timeout_ms / poll_delay_ms; 95 | 96 | for(int32_t x = 0; x < attempts; x++){ 97 | status = VL53L1_RdByte( 98 | pdev, 99 | index, 100 | ®ister_value); 101 | if (status == VL53L1_ERROR_NONE && (register_value & mask) == value) { 102 | return VL53L1_ERROR_NONE; 103 | } 104 | usleep(poll_delay_ms * 1000); 105 | } 106 | 107 | return VL53L1_ERROR_TIME_OUT; 108 | } 109 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_platform_user_data.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 4 | * 5 | * This file is part of VL53L1 Core and is dual licensed, 6 | * either 'STMicroelectronics 7 | * Proprietary license' 8 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 9 | * 10 | ******************************************************************************** 11 | * 12 | * 'STMicroelectronics Proprietary license' 13 | * 14 | ******************************************************************************** 15 | * 16 | * License terms: STMicroelectronics Proprietary in accordance with licensing 17 | * terms at www.st.com/sla0081 18 | * 19 | * STMicroelectronics confidential 20 | * Reproduction and Communication of this document is strictly prohibited unless 21 | * specifically authorized in writing by STMicroelectronics. 22 | * 23 | * 24 | ******************************************************************************** 25 | * 26 | * Alternatively, VL53L1 Core may be distributed under the terms of 27 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 28 | * provisions apply instead of the ones mentioned above : 29 | * 30 | ******************************************************************************** 31 | * 32 | * License terms: BSD 3-clause "New" or "Revised" License. 33 | * 34 | * Redistribution and use in source and binary forms, with or without 35 | * modification, are permitted provided that the following conditions are met: 36 | * 37 | * 1. Redistributions of source code must retain the above copyright notice, this 38 | * list of conditions and the following disclaimer. 39 | * 40 | * 2. Redistributions in binary form must reproduce the above copyright notice, 41 | * this list of conditions and the following disclaimer in the documentation 42 | * and/or other materials provided with the distribution. 43 | * 44 | * 3. Neither the name of the copyright holder nor the names of its contributors 45 | * may be used to endorse or promote products derived from this software 46 | * without specific prior written permission. 47 | * 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 49 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 51 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 54 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | * 59 | * 60 | ******************************************************************************** 61 | * 62 | */ 63 | 64 | #ifndef _VL53L1_PLATFORM_USER_DATA_H_ 65 | #define _VL53L1_PLATFORM_USER_DATA_H_ 66 | // #include "stm32xxx_hal.h" 67 | #include "vl53l1_def.h" 68 | #ifdef __cplusplus 69 | extern "C" 70 | { 71 | #endif 72 | 73 | 74 | typedef struct { 75 | uint32_t dummy; 76 | } I2C_HandleTypeDef; 77 | 78 | typedef struct { 79 | 80 | VL53L1_DevData_t Data; 81 | 82 | uint8_t I2cDevAddr; 83 | uint8_t comms_type; 84 | uint16_t comms_speed_khz; 85 | uint32_t new_data_ready_poll_duration_ms; 86 | I2C_HandleTypeDef *I2cHandle; 87 | 88 | } VL53L1_Dev_t; 89 | 90 | typedef VL53L1_Dev_t *VL53L1_DEV; 91 | 92 | #define VL53L1DevDataGet(Dev, field) (Dev->Data.field) 93 | #define VL53L1DevDataSet(Dev, field, VL53L1_PRM_00005) ((Dev->Data.field) = (VL53L1_PRM_00005)) 94 | #define VL53L1DevStructGetLLDriverHandle(Dev) (&Dev->Data.LLData) 95 | #define VL53L1DevStructGetLLResultsHandle(Dev) (&Dev->Data.llresults) 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | #endif 100 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_silicon_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_silicon_core.h 65 | * 66 | * @brief EwokPlus25 low level silicon specific API function definitions 67 | */ 68 | 69 | #ifndef _VL53L1_SILICON_CORE_H_ 70 | #define _VL53L1_SILICON_CORE_H_ 71 | 72 | #include "vl53l1_platform.h" 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | 79 | /** 80 | * @brief Checks if the firmware is ready for ranging (Silicon variant) 81 | * 82 | * @param[in] Dev : Device Handle 83 | * @param[out] pready : pointer to data ready flag \n 84 | * 0 = firmware not ready \n 85 | * 1 = firmware ready 86 | * 87 | * @return VL53L1_ERROR_NONE Success 88 | * @return "Other error code" See ::VL53L1_Error 89 | */ 90 | 91 | VL53L1_Error VL53L1_is_firmware_ready_silicon( 92 | VL53L1_DEV Dev, 93 | uint8_t *pready); 94 | 95 | 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif /* _VL53L1_SILICON_CORE_H_ */ 101 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_error_exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_error_exceptions.h 65 | * 66 | * @brief EwokPlus25 LL Driver definitions for control of error handling in LL driver 67 | */ 68 | 69 | #ifndef _VL53L1_ERROR_EXCEPTIONS_H_ 70 | #define _VL53L1_ERROR_EXCEPTIONS_H_ 71 | 72 | #define IGNORE_DIVISION_BY_ZERO 0 73 | 74 | #define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL 0 75 | #define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL 0 76 | #define IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FOR_GRADIENT_WARN 0 77 | #define IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FOR_GRADIENT_WARN 0 78 | #define IGNORE_XTALK_EXTRACTION_MISSING_SAMPLES_WARN 0 79 | 80 | #define IGNORE_REF_SPAD_CHAR_NOT_ENOUGH_SPADS 0 81 | #define IGNORE_REF_SPAD_CHAR_RATE_TOO_HIGH 0 82 | #define IGNORE_REF_SPAD_CHAR_RATE_TOO_LOW 0 83 | 84 | #define IGNORE_OFFSET_CAL_MISSING_SAMPLES 0 85 | #define IGNORE_OFFSET_CAL_SIGMA_TOO_HIGH 0 86 | #define IGNORE_OFFSET_CAL_RATE_TOO_HIGH 0 87 | #define IGNORE_OFFSET_CAL_SPAD_COUNT_TOO_LOW 0 88 | 89 | #define IGNORE_ZONE_CAL_MISSING_SAMPLES 0 90 | #define IGNORE_ZONE_CAL_SIGMA_TOO_HIGH 0 91 | #define IGNORE_ZONE_CAL_RATE_TOO_HIGH 0 92 | 93 | #endif /* _VL53L1_ERROR_EXCEPTIONS_H_ */ 94 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_platform_user_defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | 64 | #ifndef _VL53L1_PLATFORM_USER_DEFINES_H_ 65 | #define _VL53L1_PLATFORM_USER_DEFINES_H_ 66 | 67 | #ifdef __cplusplus 68 | extern "C" 69 | { 70 | #endif 71 | 72 | /** 73 | * @file vl53l1_platform_user_defines.h 74 | * 75 | * @brief All end user OS/platform/application definitions 76 | */ 77 | 78 | 79 | /** 80 | * @def do_division_u 81 | * @brief customer supplied division operation - 64-bit unsigned 82 | * 83 | * @param dividend unsigned 64-bit numerator 84 | * @param divisor unsigned 64-bit denominator 85 | */ 86 | #define do_division_u(dividend, divisor) (dividend / divisor) 87 | 88 | 89 | /** 90 | * @def do_division_s 91 | * @brief customer supplied division operation - 64-bit signed 92 | * 93 | * @param dividend signed 64-bit numerator 94 | * @param divisor signed 64-bit denominator 95 | */ 96 | #define do_division_s(dividend, divisor) (dividend / divisor) 97 | 98 | 99 | /** 100 | * @def WARN_OVERRIDE_STATUS 101 | * @brief customer supplied macro to optionally output info when a specific 102 | error has been overridden with success within the EwokPlus driver 103 | * 104 | * @param __X__ the macro which enabled the suppression 105 | */ 106 | #define WARN_OVERRIDE_STATUS(__X__)\ 107 | trace_print (VL53L1_TRACE_LEVEL_WARNING, #__X__); 108 | 109 | 110 | #ifdef _MSC_VER 111 | #define DISABLE_WARNINGS() { \ 112 | __pragma (warning (push)); \ 113 | __pragma (warning (disable:4127)); \ 114 | } 115 | #define ENABLE_WARNINGS() { \ 116 | __pragma (warning (pop)); \ 117 | } 118 | #else 119 | #define DISABLE_WARNINGS() 120 | #define ENABLE_WARNINGS() 121 | #endif 122 | 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif // _VL53L1_PLATFORM_USER_DEFINES_H_ 129 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_preset_setup.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 4 | * 5 | * This file is part of VL53L1 Core and is dual licensed, 6 | * either 'STMicroelectronics 7 | * Proprietary license' 8 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 9 | * 10 | ******************************************************************************** 11 | * 12 | * 'STMicroelectronics Proprietary license' 13 | * 14 | ******************************************************************************** 15 | * 16 | * License terms: STMicroelectronics Proprietary in accordance with licensing 17 | * terms at www.st.com/sla0081 18 | * 19 | * STMicroelectronics confidential 20 | * Reproduction and Communication of this document is strictly prohibited unless 21 | * specifically authorized in writing by STMicroelectronics. 22 | * 23 | * 24 | ******************************************************************************** 25 | * 26 | * Alternatively, VL53L1 Core may be distributed under the terms of 27 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 28 | * provisions apply instead of the ones mentioned above : 29 | * 30 | ******************************************************************************** 31 | * 32 | * License terms: BSD 3-clause "New" or "Revised" License. 33 | * 34 | * Redistribution and use in source and binary forms, with or without 35 | * modification, are permitted provided that the following conditions are met: 36 | * 37 | * 1. Redistributions of source code must retain the above copyright notice, this 38 | * list of conditions and the following disclaimer. 39 | * 40 | * 2. Redistributions in binary form must reproduce the above copyright notice, 41 | * this list of conditions and the following disclaimer in the documentation 42 | * and/or other materials provided with the distribution. 43 | * 44 | * 3. Neither the name of the copyright holder nor the names of its contributors 45 | * may be used to endorse or promote products derived from this software 46 | * without specific prior written permission. 47 | * 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 49 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 51 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 54 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | * 59 | * 60 | ******************************************************************************** 61 | * 62 | */ 63 | 64 | #ifndef _VL53L1_PRESET_SETUP_H_ 65 | #define _VL53L1_PRESET_SETUP_H_ 66 | 67 | #ifdef __cplusplus 68 | extern "C" 69 | { 70 | #endif 71 | 72 | /* indexes for the bare driver tuning setting API function */ 73 | enum VL53L1_Tuning_t { 74 | VL53L1_TUNING_VERSION = 0, 75 | VL53L1_TUNING_PROXY_MIN, 76 | VL53L1_TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM, 77 | VL53L1_TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER, 78 | VL53L1_TUNING_MIN_AMBIENT_DMAX_VALID, 79 | VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER, 80 | VL53L1_TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM, 81 | VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT, 82 | 83 | VL53L1_TUNING_MAX_TUNABLE_KEY 84 | }; 85 | 86 | /* default values for the tuning settings parameters */ 87 | #define TUNING_VERSION 0x0004 88 | 89 | #define TUNING_PROXY_MIN -30 /* min distance in mm */ 90 | #define TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM 600 91 | /* Target distance in mm for single target Xtalk */ 92 | #define TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER 50 93 | /* Number of sample used for single target Xtalk */ 94 | #define TUNING_MIN_AMBIENT_DMAX_VALID 8 95 | /* Minimum ambient level to state the Dmax returned by the device is valid */ 96 | #define TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER 50 97 | /* Maximum loops to perform simple offset calibration */ 98 | #define TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM 600 99 | /* Target distance in mm for target Xtalk from Bins method*/ 100 | #define TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT 1 101 | /* Number of loops done during the simple offset calibration*/ 102 | 103 | /* the following table should actually be defined as static and shall be part 104 | * of the VL53L1_StaticInit() function code 105 | */ 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* _VL53L1_PRESET_SETUP_H_ */ 112 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vl53l1x_ros 2 | 3 | This is STM [VL53L1X](https://www.st.com/en/imaging-and-photonics-solutions/vl53l1x.html) time-of-flight rangefinder driver for ROS. Tested on a Raspberry Pi 3 and 4 with CJMCU-531 board. 4 | 5 | The code is based on the [STM VL53L1X API library](https://www.st.com/content/st_com/en/products/embedded-software/proximity-sensors-software/stsw-img007.html). 6 | 7 | ## Connecting 8 | 9 | Example of I²C connecting VL53L1X module to Raspberry Pi: 10 | 11 | 12 | 13 | ## Installation 14 | 15 | ### From package 16 | 17 | For Raspberry Pi, there exist prebuilt Debian packages. For installation, get the package ([Noetic](http://packages.coex.tech/packages/buster/ros-noetic-vl53l1x/), [Melodic](http://coex.space/rpi-ros-melodic/pool/main/r/ros-melodic-vl53l1x/), [Kinetic](http://coex.space/rpi-ros-kinetic/pool/main/r/ros-kinetic-vl53l1x/)) to the Raspberry and install it with `dpkg -i .deb`. 18 | 19 | ### Manual 20 | 21 | 1. Clone the repository into your Catkin workspace: 22 | 23 | ```bash 24 | cd ~/catkin_ws/src 25 | git clone https://github.com/okalachev/vl53l1x_ros.git 26 | ``` 27 | 28 | 2. Build the package: 29 | 30 | ```bash 31 | cd ~/catkin_ws 32 | catkin_make -DCATKIN_WHITELIST_PACKAGES="vl53l1x" 33 | ``` 34 | 35 | ## Quick start 36 | 37 | Run with the default settings: 38 | 39 | ```bash 40 | rosrun vl53l1x vl53l1x_node 41 | ``` 42 | 43 | See the ranging results: 44 | 45 | ```bash 46 | rostopic echo /vl53l1x/range 47 | ``` 48 | 49 | See the ranging rate: 50 | 51 | ```bash 52 | rostopic hz /vl53l1x/range 53 | ``` 54 | 55 | ## Parameters 56 | 57 | All parameters are optional. Check the [`launch`](https://github.com/okalachev/vl53l1x_ros/tree/master/vl53l1x/launch) folder for launch-file templates. 58 | 59 | * `~i2c_bus` (*int*) – I2C bus number (default: 1). 60 | * `~i2c_address` (*int*) – I2C address (default: 0x29). 61 | * `~mode` (*int*) – distance mode, 1 = short, 2 = medium, 3 = long (default: 3). 62 | * `~timing_budget` (*double*) – timing budget for measurements, *s* (default: 0.1) 63 | * `~poll_rate` (*double*) – polling data rate, *Hz* (default: 100). 64 | * `~ignore_range_status` (*bool*) – ignore validness of measurements (default: false). 65 | * `~pass_statuses` (*array of int*) – measurement [statuses](vl53l1x/msg/MeasurementData.msg#L13), that considered valid (default: [0, 6, 11]). 66 | * `~min_signal` (*double*) – minimum amplitude of the signal reflected from the target to be considered valid, *MCPS* (default: 1). 67 | * `~max_sigma` (*double*) – maximum standard deviation of the measurement to be considered valid, *m* (default: 0.015). 68 | * `~offset` (*float*) – offset to be automatically added to measurement value, *m* (default: 0.0). 69 | * `~frame_id` (*string*) – frame id for output `Range` messages (default: ""). 70 | * `~field_of_view` (*float*) – field of view for output `Range` messages, *rad* (default: 0.471239). 71 | * `~min_range` (*float*) – minimum range for output `Range` messages, *m* (default: 0.0). 72 | * `~max_range` (*float*) – maximum range for `Range` output messages, *m* (default: 4.0). 73 | 74 | `timing_budget` is the time VL53L1X uses for ranging. The larger this time, the more accurate is measurement and the larger is maximum distance. Timing budget can be set from *0.02 s* up to *1 s*. 75 | 76 | * *0.02 s* is the minimum timing budget and can be used only in *Short* distance mode. 77 | * *0.033 s* is the minimum timing budget which can work for all distance modes. 78 | * *0.14 s* is the timing budget which allows the maximum distance of *4 m* (in *Long* distance mode). 79 | 80 | The resulting measurement rate is *1 / (timing budget + 0.004) Hz*. 81 | 82 | Setting `ignore_range_status` to `true` makes the node to ignore `RangeStatus` field of measurements. This may significantly improve maximum distance and rate but affects quality of measurements. 83 | 84 | `mode` is one of three distance modes, with the timing budget of *0.1 s*, *Short*, *Medium* and *Long* modes have maximum distances of 136, 290, and 360 cm, respectively. 85 | 86 | `~min_range` and `~max_range` don't affect any device settings and only define `min_range` and `max_range` values of the output [`Range`](http://docs.ros.org/melodic/api/sensor_msgs/html/msg/Range.html) messages. 87 | 88 | See the [official documentation](https://www.st.com/resource/en/datasheet/vl53l1x.pdf) for more information on mode and timing budget. 89 | 90 | ## Topics 91 | 92 | ### Published 93 | 94 | * `~range` ([*sensor_msgs/Range*](http://docs.ros.org/kinetic/api/sensor_msgs/html/msg/Range.html)) – resulting measurement. 95 | * `~data` ([*vl53l1x/MeasurementData*](https://github.com/okalachev/vl53l1x_ros/blob/master/vl53l1x/msg/MeasurementData.msg)) – additional data of the measurement. 96 | 97 | ## Copyright 98 | 99 | Copyright © 2019 Oleg Kalachev. 100 | 101 | Distributed under BSD 3-Clause License (https://opensource.org/licenses/BSD-3-Clause). 102 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_platform_user_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_platform_user_config.h 65 | * 66 | * @brief EwokPlus compile time user modifiable configuration 67 | */ 68 | 69 | 70 | #ifndef _VL53L1_PLATFORM_USER_CONFIG_H_ 71 | #define _VL53L1_PLATFORM_USER_CONFIG_H_ 72 | 73 | #define VL53L1_BYTES_PER_WORD 2 74 | #define VL53L1_BYTES_PER_DWORD 4 75 | 76 | /* Define polling delays */ 77 | #define VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS 500 78 | #define VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS 2000 79 | #define VL53L1_TEST_COMPLETION_POLLING_TIMEOUT_MS 60000 80 | 81 | #define VL53L1_POLLING_DELAY_MS 1 82 | 83 | /* Define LLD TuningParms Page Base Address 84 | * - Part of Patch_AddedTuningParms_11761 85 | */ 86 | #define VL53L1_TUNINGPARM_PUBLIC_PAGE_BASE_ADDRESS 0x8000 87 | #define VL53L1_TUNINGPARM_PRIVATE_PAGE_BASE_ADDRESS 0xC000 88 | 89 | #define VL53L1_GAIN_FACTOR__STANDARD_DEFAULT 0x0800 90 | /*!< Default standard ranging gain correction factor 91 | 1.11 format. 1.0 = 0x0800, 0.980 = 0x07D7 */ 92 | 93 | #define VL53L1_OFFSET_CAL_MIN_EFFECTIVE_SPADS 0x0500 94 | /*!< Lower Limit for the MM1 effective SPAD count during offset 95 | calibration Format 8.8 0x0500 -> 5.0 effective SPADs */ 96 | 97 | #define VL53L1_OFFSET_CAL_MAX_PRE_PEAK_RATE_MCPS 0x1900 98 | /*!< Max Limit for the pre range peak rate during offset 99 | calibration Format 9.7 0x1900 -> 50.0 Mcps. 100 | If larger then in pile up */ 101 | 102 | #define VL53L1_OFFSET_CAL_MAX_SIGMA_MM 0x0040 103 | /*!< Max sigma estimate limit during offset calibration 104 | Check applies to pre-range, mm1 and mm2 ranges 105 | Format 14.2 0x0040 -> 16.0mm. */ 106 | 107 | #define VL53L1_MAX_USER_ZONES 169 108 | /*!< Max number of user Zones - maximal limitation from 109 | FW stream divide - value of 254 */ 110 | 111 | #define VL53L1_MAX_RANGE_RESULTS 2 112 | /*!< Allocates storage for return and reference restults */ 113 | 114 | 115 | #define VL53L1_MAX_STRING_LENGTH 512 116 | 117 | #endif /* _VL53L1_PLATFORM_USER_CONFIG_H_ */ 118 | 119 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_silicon_core.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_silicon_core.c 65 | * 66 | * @brief EwokPlus25 low level silicon LL Driver function definition 67 | */ 68 | 69 | 70 | #include "vl53l1_ll_def.h" 71 | #include "vl53l1_platform.h" 72 | #include "vl53l1_register_map.h" 73 | #include "vl53l1_core.h" 74 | #include "vl53l1_silicon_core.h" 75 | 76 | 77 | #define LOG_FUNCTION_START(fmt, ...) \ 78 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__) 79 | #define LOG_FUNCTION_END(status, ...) \ 80 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__) 81 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ 82 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, fmt, ##__VA_ARGS__) 83 | 84 | 85 | VL53L1_Error VL53L1_is_firmware_ready_silicon( 86 | VL53L1_DEV Dev, 87 | uint8_t *pready) 88 | { 89 | /** 90 | * Determines if the firmware is ready to range 91 | * 92 | * There are 2 different behaviors depending on whether 93 | * power force is enabled or not 94 | */ 95 | 96 | VL53L1_Error status = VL53L1_ERROR_NONE; 97 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 98 | 99 | uint8_t comms_buffer[5]; 100 | 101 | LOG_FUNCTION_START(""); 102 | 103 | /* read interrupt and power force reset status */ 104 | 105 | status = VL53L1_ReadMulti( 106 | Dev, 107 | VL53L1_INTERRUPT_MANAGER__ENABLES, 108 | comms_buffer, 109 | 5); 110 | 111 | if (status == VL53L1_ERROR_NONE) { 112 | 113 | pdev->dbg_results.interrupt_manager__enables = 114 | comms_buffer[0]; 115 | pdev->dbg_results.interrupt_manager__clear = 116 | comms_buffer[1]; 117 | pdev->dbg_results.interrupt_manager__status = 118 | comms_buffer[2]; 119 | pdev->dbg_results.mcu_to_host_bank__wr_access_en = 120 | comms_buffer[3]; 121 | pdev->dbg_results.power_management__go1_reset_status = 122 | comms_buffer[4]; 123 | 124 | if ((pdev->sys_ctrl.power_management__go1_power_force & 0x01) == 0x01) { 125 | 126 | if (((pdev->dbg_results.interrupt_manager__enables & 0x1F) == 0x1F) && 127 | ((pdev->dbg_results.interrupt_manager__clear & 0x1F) == 0x1F)) 128 | *pready = 0x01; 129 | else 130 | *pready = 0x00; 131 | 132 | } else { 133 | 134 | /* set ready flag if bit 0 is zero i.g G01 is in reset */ 135 | if ((pdev->dbg_results.power_management__go1_reset_status & 0x01) == 0x00) 136 | *pready = 0x01; 137 | else 138 | *pready = 0x00; 139 | } 140 | 141 | } 142 | 143 | LOG_FUNCTION_END(status); 144 | 145 | return status; 146 | } 147 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_platform.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 4 | * 5 | * This file is part of VL53L1 Core and is dual licensed, 6 | * either 'STMicroelectronics 7 | * Proprietary license' 8 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 9 | * 10 | ******************************************************************************** 11 | * 12 | * 'STMicroelectronics Proprietary license' 13 | * 14 | ******************************************************************************** 15 | * 16 | * License terms: STMicroelectronics Proprietary in accordance with licensing 17 | * terms at www.st.com/sla0081 18 | * 19 | * STMicroelectronics confidential 20 | * Reproduction and Communication of this document is strictly prohibited unless 21 | * specifically authorized in writing by STMicroelectronics. 22 | * 23 | * 24 | ******************************************************************************** 25 | * 26 | * Alternatively, VL53L1 Core may be distributed under the terms of 27 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 28 | * provisions apply instead of the ones mentioned above : 29 | * 30 | ******************************************************************************** 31 | * 32 | * License terms: BSD 3-clause "New" or "Revised" License. 33 | * 34 | * Redistribution and use in source and binary forms, with or without 35 | * modification, are permitted provided that the following conditions are met: 36 | * 37 | * 1. Redistributions of source code must retain the above copyright notice, this 38 | * list of conditions and the following disclaimer. 39 | * 40 | * 2. Redistributions in binary form must reproduce the above copyright notice, 41 | * this list of conditions and the following disclaimer in the documentation 42 | * and/or other materials provided with the distribution. 43 | * 44 | * 3. Neither the name of the copyright holder nor the names of its contributors 45 | * may be used to endorse or promote products derived from this software 46 | * without specific prior written permission. 47 | * 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 49 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 51 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 54 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | * 59 | * 60 | ******************************************************************************** 61 | * 62 | */ 63 | 64 | #ifndef _VL53L1_PLATFORM_H_ 65 | #define _VL53L1_PLATFORM_H_ 66 | 67 | #include "vl53l1_ll_def.h" 68 | #include "vl53l1_platform_log.h" 69 | 70 | #define VL53L1_IPP_API 71 | #include "vl53l1_platform_user_data.h" 72 | 73 | #ifdef __cplusplus 74 | extern "C" 75 | { 76 | #endif 77 | 78 | VL53L1_Error VL53L1_CommsInitialise( 79 | VL53L1_Dev_t *pdev, 80 | uint8_t comms_type, 81 | uint16_t comms_speed_khz); 82 | 83 | VL53L1_Error VL53L1_CommsClose( 84 | VL53L1_Dev_t *pdev); 85 | 86 | VL53L1_Error VL53L1_WriteMulti( 87 | VL53L1_Dev_t *pdev, 88 | uint16_t index, 89 | uint8_t *pdata, 90 | uint32_t count); 91 | 92 | VL53L1_Error VL53L1_ReadMulti( 93 | VL53L1_Dev_t *pdev, 94 | uint16_t index, 95 | uint8_t *pdata, 96 | uint32_t count); 97 | 98 | VL53L1_Error VL53L1_WrByte( 99 | VL53L1_Dev_t *pdev, 100 | uint16_t index, 101 | uint8_t VL53L1_PRM_00005); 102 | 103 | VL53L1_Error VL53L1_WrWord( 104 | VL53L1_Dev_t *pdev, 105 | uint16_t index, 106 | uint16_t VL53L1_PRM_00005); 107 | 108 | VL53L1_Error VL53L1_WrDWord( 109 | VL53L1_Dev_t *pdev, 110 | uint16_t index, 111 | uint32_t VL53L1_PRM_00005); 112 | 113 | VL53L1_Error VL53L1_RdByte( 114 | VL53L1_Dev_t *pdev, 115 | uint16_t index, 116 | uint8_t *pdata); 117 | 118 | VL53L1_Error VL53L1_RdWord( 119 | VL53L1_Dev_t *pdev, 120 | uint16_t index, 121 | uint16_t *pdata); 122 | 123 | VL53L1_Error VL53L1_RdDWord( 124 | VL53L1_Dev_t *pdev, 125 | uint16_t index, 126 | uint32_t *pdata); 127 | 128 | VL53L1_Error VL53L1_WaitUs( 129 | VL53L1_Dev_t *pdev, 130 | int32_t wait_us); 131 | 132 | VL53L1_Error VL53L1_WaitMs( 133 | VL53L1_Dev_t *pdev, 134 | int32_t wait_ms); 135 | 136 | VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz); 137 | 138 | VL53L1_Error VL53L1_GetTimerValue(int32_t *ptimer_count); 139 | 140 | VL53L1_Error VL53L1_GpioSetMode(uint8_t pin, uint8_t mode); 141 | 142 | VL53L1_Error VL53L1_GpioSetValue(uint8_t pin, uint8_t value); 143 | 144 | VL53L1_Error VL53L1_GpioGetValue(uint8_t pin, uint8_t *pvalue); 145 | 146 | VL53L1_Error VL53L1_GpioXshutdown(uint8_t value); 147 | 148 | VL53L1_Error VL53L1_GpioCommsSelect(uint8_t value); 149 | 150 | VL53L1_Error VL53L1_GpioPowerEnable(uint8_t value); 151 | 152 | VL53L1_Error VL53L1_GpioInterruptEnable(void (*function)(void), uint8_t edge_type); 153 | 154 | VL53L1_Error VL53L1_GpioInterruptDisable(void); 155 | 156 | VL53L1_Error VL53L1_GetTickCount( 157 | uint32_t *ptime_ms); 158 | 159 | VL53L1_Error VL53L1_WaitValueMaskEx( 160 | VL53L1_Dev_t *pdev, 161 | uint32_t timeout_ms, 162 | uint16_t index, 163 | uint8_t value, 164 | uint8_t mask, 165 | uint32_t poll_delay_ms); 166 | 167 | #ifdef __cplusplus 168 | } 169 | #endif 170 | 171 | #endif 172 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_types.h 65 | * @brief VL53L1 types definition 66 | */ 67 | 68 | #ifndef _VL53L1_TYPES_H_ 69 | #define _VL53L1_TYPES_H_ 70 | 71 | /** @defgroup porting_type Basic type definition 72 | * @ingroup api_platform 73 | * 74 | * @brief file vl53l1_types.h files hold basic type definition that may requires porting 75 | * 76 | * contains type that must be defined for the platform\n 77 | * when target platform and compiler provide stdint.h and stddef.h it is enough to include it.\n 78 | * If stdint.h is not available review and adapt all signed and unsigned 8/16/32 bits basic types. \n 79 | * If stddef.h is not available review and adapt NULL definition . 80 | */ 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | 87 | #ifndef NULL 88 | #error "Error NULL definition should be done. Please add required include " 89 | #endif 90 | 91 | 92 | #if !defined(STDINT_H) && !defined(_STDINT_H) && !defined(_GCC_STDINT_H) && !defined(__STDINT_DECLS) && !defined(_GCC_WRAP_STDINT_H) && !defined(_STDINT) 93 | 94 | #pragma message("Please review type definition of STDINT define for your platform and add to list above ") 95 | 96 | /* 97 | * target platform do not provide stdint or use a different #define than above 98 | * to avoid seeing the message below addapt the #define list above or implement 99 | * all type and delete these pragma 100 | */ 101 | 102 | /** \ingroup VL53L1_portingType_group 103 | * @{ 104 | */ 105 | 106 | 107 | typedef unsigned long long uint64_t; 108 | 109 | 110 | /** @brief Typedef defining 32 bit unsigned int type.\n 111 | * The developer should modify this to suit the platform being deployed. 112 | */ 113 | typedef unsigned int uint32_t; 114 | 115 | /** @brief Typedef defining 32 bit int type.\n 116 | * The developer should modify this to suit the platform being deployed. 117 | */ 118 | typedef int int32_t; 119 | 120 | /** @brief Typedef defining 16 bit unsigned short type.\n 121 | * The developer should modify this to suit the platform being deployed. 122 | */ 123 | typedef unsigned short uint16_t; 124 | 125 | /** @brief Typedef defining 16 bit short type.\n 126 | * The developer should modify this to suit the platform being deployed. 127 | */ 128 | typedef short int16_t; 129 | 130 | /** @brief Typedef defining 8 bit unsigned char type.\n 131 | * The developer should modify this to suit the platform being deployed. 132 | */ 133 | typedef unsigned char uint8_t; 134 | 135 | /** @brief Typedef defining 8 bit char type.\n 136 | * The developer should modify this to suit the platform being deployed. 137 | */ 138 | typedef signed char int8_t; 139 | 140 | /** @} */ 141 | #endif /* _STDINT_H */ 142 | 143 | 144 | /** use where fractional values are expected 145 | * 146 | * Given a floating point value f it's .16 bit point is (int)(f*(1<<16))*/ 147 | typedef uint32_t FixPoint1616_t; 148 | 149 | #endif /* VL53L1_TYPES_H_ */ 150 | -------------------------------------------------------------------------------- /vl53l1x/src/vl53l1x.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * STM VL53L1X ToF rangefinder driver for ROS 3 | * 4 | * Author: Oleg Kalachev 5 | * 6 | * Distributed under BSD 3-Clause License (available at https://opensource.org/licenses/BSD-3-Clause). 7 | * 8 | * Documentation used: 9 | * VL53L1X datasheet - https://www.st.com/resource/en/datasheet/vl53l1x.pdf 10 | * VL53L1X API user manual - https://www.st.com/content/ccc/resource/technical/document/user_manual/group0/98/0d/38/38/5d/84/49/1f/DM00474730/files/DM00474730.pdf/jcr:content/translations/en.DM00474730.pdf 11 | * 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "vl53l1_api.h" 21 | #include "i2c.h" 22 | 23 | #define xSTR(x) #x 24 | #define STR(x) xSTR(x) 25 | 26 | #define CHECK_STATUS(func) { \ 27 | VL53L1_Error status = func; \ 28 | if (status != VL53L1_ERROR_NONE) { \ 29 | ROS_WARN("VL53L1X: Error %d on %s", status, STR(func)); \ 30 | } \ 31 | } 32 | 33 | int main(int argc, char **argv) 34 | { 35 | ros::init(argc, argv, "vl53l1x"); 36 | ros::NodeHandle nh, nh_priv("~"); 37 | 38 | sensor_msgs::Range range; 39 | vl53l1x::MeasurementData data; 40 | range.radiation_type = sensor_msgs::Range::INFRARED; 41 | ros::Publisher range_pub = nh_priv.advertise("range", 20); 42 | ros::Publisher data_pub = nh_priv.advertise("data", 20); 43 | 44 | // Read parameters 45 | int mode, i2c_bus, i2c_address; 46 | double poll_rate, timing_budget, offset; 47 | bool ignore_range_status; 48 | std::vector pass_statuses { VL53L1_RANGESTATUS_RANGE_VALID, 49 | VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL, 50 | VL53L1_RANGESTATUS_RANGE_VALID_MERGED_PULSE }; 51 | 52 | nh_priv.param("mode", mode, 3); 53 | nh_priv.param("i2c_bus", i2c_bus, 1); 54 | nh_priv.param("i2c_address", i2c_address, 0x29); 55 | nh_priv.param("poll_rate", poll_rate, 100.0); 56 | nh_priv.param("ignore_range_status", ignore_range_status, false); 57 | nh_priv.param("timing_budget", timing_budget, 0.1); 58 | nh_priv.param("offset", offset, 0.0); 59 | nh_priv.param("frame_id", range.header.frame_id, ""); 60 | nh_priv.param("field_of_view", range.field_of_view, 0.471239f); // 27 deg, source: datasheet 61 | nh_priv.param("min_range", range.min_range, 0.0f); 62 | nh_priv.param("max_range", range.max_range, 4.0f); 63 | nh_priv.getParam("pass_statuses", pass_statuses); 64 | 65 | if (timing_budget < 0.02 || timing_budget > 1) { 66 | ROS_FATAL("Error: timing_budget should be within 0.02 and 1 s (%g is set)", timing_budget); 67 | ros::shutdown(); 68 | } 69 | 70 | // The minimum inter-measurement period must be longer than the timing budget + 4 ms (*) 71 | double inter_measurement_period = timing_budget + 0.004; 72 | 73 | // Setup I2C bus 74 | i2c_setup(i2c_bus, i2c_address); 75 | 76 | // Init sensor 77 | VL53L1_Dev_t dev; 78 | VL53L1_Error dev_error; 79 | VL53L1_software_reset(&dev); 80 | VL53L1_WaitDeviceBooted(&dev); 81 | VL53L1_DataInit(&dev); 82 | VL53L1_StaticInit(&dev); 83 | VL53L1_SetPresetMode(&dev, VL53L1_PRESETMODE_AUTONOMOUS); 84 | 85 | // Print device info 86 | VL53L1_DeviceInfo_t device_info; 87 | CHECK_STATUS(VL53L1_GetDeviceInfo(&dev, &device_info)); 88 | ROS_INFO("VL53L1X: Device name: %." STR(VL53L1_DEVINFO_STRLEN) "s", device_info.Name); 89 | ROS_INFO("VL53L1X: Device type: %." STR(VL53L1_DEVINFO_STRLEN) "s", device_info.Type); 90 | ROS_INFO("VL53L1X: Product ID: %." STR(VL53L1_DEVINFO_STRLEN) "s", device_info.ProductId); 91 | ROS_INFO("VL53L1X: Type: %u Version: %u.%u", device_info.ProductType, 92 | device_info.ProductRevisionMajor, device_info.ProductRevisionMinor); 93 | 94 | // Setup sensor 95 | CHECK_STATUS(VL53L1_SetDistanceMode(&dev, mode)); 96 | CHECK_STATUS(VL53L1_SetMeasurementTimingBudgetMicroSeconds(&dev, round(timing_budget * 1e6))); 97 | 98 | double min_signal; 99 | if (nh_priv.getParam("min_signal", min_signal)) { 100 | CHECK_STATUS(VL53L1_SetLimitCheckValue(&dev, VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, min_signal * 65536)); 101 | } 102 | 103 | double max_sigma; 104 | if (nh_priv.getParam("max_sigma", max_sigma)) { 105 | CHECK_STATUS(VL53L1_SetLimitCheckValue(&dev, VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, max_sigma * 1000 * 65536)); 106 | } 107 | 108 | // Start sensor 109 | for (int i = 0; i < 100; i++) { 110 | CHECK_STATUS(VL53L1_SetInterMeasurementPeriodMilliSeconds(&dev, round(inter_measurement_period * 1e3))); 111 | dev_error = VL53L1_StartMeasurement(&dev); 112 | if (dev_error == VL53L1_ERROR_INVALID_PARAMS) { 113 | inter_measurement_period += 0.001; // Increase inter_measurement_period to satisfy condition (*) 114 | } else break; 115 | } 116 | 117 | // Check for errors after start 118 | if (dev_error != VL53L1_ERROR_NONE) { 119 | ROS_FATAL("VL53L1X: Can't start measurement: error %d", dev_error); 120 | ros::shutdown(); 121 | } 122 | 123 | ROS_INFO("VL53L1X: ranging"); 124 | 125 | VL53L1_RangingMeasurementData_t measurement_data; 126 | 127 | // Main loop 128 | ros::Rate r(poll_rate); 129 | while (ros::ok()) { 130 | r.sleep(); 131 | range.header.stamp = ros::Time::now(); 132 | 133 | // Check the data is ready 134 | uint8_t data_ready = 0; 135 | VL53L1_GetMeasurementDataReady(&dev, &data_ready); 136 | if (!data_ready) { 137 | continue; 138 | } 139 | 140 | // Read measurement 141 | VL53L1_GetRangingMeasurementData(&dev, &measurement_data); 142 | VL53L1_ClearInterruptAndStartMeasurement(&dev); 143 | 144 | // Publish measurement data 145 | data.header.stamp = range.header.stamp; 146 | data.signal = measurement_data.SignalRateRtnMegaCps / 65536.0; 147 | data.ambient = measurement_data.AmbientRateRtnMegaCps / 65536.0; 148 | data.effective_spad = measurement_data.EffectiveSpadRtnCount / 256; 149 | data.sigma = measurement_data.SigmaMilliMeter / 65536.0 / 1000.0; 150 | data.status = measurement_data.RangeStatus; 151 | data_pub.publish(data); 152 | 153 | // Check measurement for validness 154 | if (!ignore_range_status && 155 | std::find(pass_statuses.begin(), pass_statuses.end(), measurement_data.RangeStatus) == pass_statuses.end()) { 156 | char range_status[VL53L1_MAX_STRING_LENGTH]; 157 | VL53L1_get_range_status_string(measurement_data.RangeStatus, range_status); 158 | ROS_DEBUG("Range measurement status is not valid: %s", range_status); 159 | ros::spinOnce(); 160 | continue; 161 | } 162 | 163 | // Publish measurement 164 | range.range = measurement_data.RangeMilliMeter / 1000.0 + offset; 165 | range_pub.publish(range); 166 | 167 | ros::spinOnce(); 168 | } 169 | 170 | // Release 171 | ROS_INFO("VL53L1X: stop ranging"); 172 | VL53L1_StopMeasurement(&dev); 173 | i2c_release(); 174 | } 175 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_platform.c.orig: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 4 | * 5 | * This file is part of VL53L1 Core and is dual licensed, 6 | * either 'STMicroelectronics 7 | * Proprietary license' 8 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 9 | * 10 | ******************************************************************************** 11 | * 12 | * 'STMicroelectronics Proprietary license' 13 | * 14 | ******************************************************************************** 15 | * 16 | * License terms: STMicroelectronics Proprietary in accordance with licensing 17 | * terms at www.st.com/sla0081 18 | * 19 | * STMicroelectronics confidential 20 | * Reproduction and Communication of this document is strictly prohibited unless 21 | * specifically authorized in writing by STMicroelectronics. 22 | * 23 | * 24 | ******************************************************************************** 25 | * 26 | * Alternatively, VL53L1 Core may be distributed under the terms of 27 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 28 | * provisions apply instead of the ones mentioned above : 29 | * 30 | ******************************************************************************** 31 | * 32 | * License terms: BSD 3-clause "New" or "Revised" License. 33 | * 34 | * Redistribution and use in source and binary forms, with or without 35 | * modification, are permitted provided that the following conditions are met: 36 | * 37 | * 1. Redistributions of source code must retain the above copyright notice, this 38 | * list of conditions and the following disclaimer. 39 | * 40 | * 2. Redistributions in binary form must reproduce the above copyright notice, 41 | * this list of conditions and the following disclaimer in the documentation 42 | * and/or other materials provided with the distribution. 43 | * 44 | * 3. Neither the name of the copyright holder nor the names of its contributors 45 | * may be used to endorse or promote products derived from this software 46 | * without specific prior written permission. 47 | * 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 49 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 51 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 54 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | * 59 | * 60 | ******************************************************************************** 61 | * 62 | */ 63 | 64 | 65 | #include "vl53l1_platform.h" 66 | // #include "vl53l1_platform_log.h" 67 | #include "vl53l1_api.h" 68 | 69 | // #include "stm32xxx_hal.h" 70 | #include 71 | // #include 72 | // #include 73 | 74 | 75 | // #define I2C_TIME_OUT_BASE 10 76 | // #define I2C_TIME_OUT_BYTE 1 77 | 78 | // #ifdef VL53L1_LOG_ENABLE 79 | // #define trace_print(level, ...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_PLATFORM, level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) 80 | // #define trace_i2c(...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_NONE, VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__) 81 | // #endif 82 | 83 | // #ifndef HAL_I2C_MODULE_ENABLED 84 | // #warning "HAL I2C module must be enable " 85 | // #endif 86 | 87 | //extern I2C_HandleTypeDef hi2c1; 88 | //#define VL53L0X_pI2cHandle (&hi2c1) 89 | 90 | /* when not customized by application define dummy one */ 91 | // #ifndef VL53L1_GetI2cBus 92 | /** This macro can be overloaded by user to enforce i2c sharing in RTOS context 93 | */ 94 | // # define VL53L1_GetI2cBus(...) (void)0 95 | // #endif 96 | 97 | // #ifndef VL53L1_PutI2cBus 98 | /** This macro can be overloaded by user to enforce i2c sharing in RTOS context 99 | */ 100 | // # define VL53L1_PutI2cBus(...) (void)0 101 | // #endif 102 | 103 | // uint8_t _I2CBuffer[256]; 104 | 105 | // int _I2CWrite(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) { 106 | // int status = 0; 107 | // return status; 108 | // } 109 | 110 | // int _I2CRead(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) { 111 | // int status = 0; 112 | // return Status; 113 | // } 114 | 115 | VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) { 116 | VL53L1_Error Status = VL53L1_ERROR_NONE; 117 | return Status; 118 | } 119 | 120 | // the ranging_sensor_comms.dll will take care of the page selection 121 | VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) { 122 | VL53L1_Error Status = VL53L1_ERROR_NONE; 123 | return Status; 124 | } 125 | 126 | VL53L1_Error VL53L1_WrByte(VL53L1_DEV Dev, uint16_t index, uint8_t data) { 127 | VL53L1_Error Status = VL53L1_ERROR_NONE; 128 | return Status; 129 | } 130 | 131 | VL53L1_Error VL53L1_WrWord(VL53L1_DEV Dev, uint16_t index, uint16_t data) { 132 | VL53L1_Error Status = VL53L1_ERROR_NONE; 133 | return Status; 134 | } 135 | 136 | VL53L1_Error VL53L1_WrDWord(VL53L1_DEV Dev, uint16_t index, uint32_t data) { 137 | VL53L1_Error Status = VL53L1_ERROR_NONE; 138 | return Status; 139 | } 140 | 141 | VL53L1_Error VL53L1_UpdateByte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData, uint8_t OrData) { 142 | VL53L1_Error Status = VL53L1_ERROR_NONE; 143 | return Status; 144 | } 145 | 146 | VL53L1_Error VL53L1_RdByte(VL53L1_DEV Dev, uint16_t index, uint8_t *data) { 147 | VL53L1_Error Status = VL53L1_ERROR_NONE; 148 | return Status; 149 | } 150 | 151 | VL53L1_Error VL53L1_RdWord(VL53L1_DEV Dev, uint16_t index, uint16_t *data) { 152 | VL53L1_Error Status = VL53L1_ERROR_NONE; 153 | return Status; 154 | } 155 | 156 | VL53L1_Error VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t *data) { 157 | VL53L1_Error Status = VL53L1_ERROR_NONE; 158 | return Status; 159 | } 160 | 161 | VL53L1_Error VL53L1_GetTickCount( 162 | uint32_t *ptick_count_ms) 163 | { 164 | VL53L1_Error status = VL53L1_ERROR_NONE; 165 | return status; 166 | } 167 | 168 | //#define trace_print(level, ...) \ 169 | // _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_PLATFORM, \ 170 | // level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) 171 | 172 | //#define trace_i2c(...) \ 173 | // _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NONE, \ 174 | // VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__) 175 | 176 | VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz) 177 | { 178 | VL53L1_Error status = VL53L1_ERROR_NONE; 179 | return status; 180 | } 181 | 182 | VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms){ 183 | VL53L1_Error status = VL53L1_ERROR_NONE; 184 | return status; 185 | } 186 | 187 | VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us){ 188 | VL53L1_Error status = VL53L1_ERROR_NONE; 189 | return status; 190 | } 191 | 192 | VL53L1_Error VL53L1_WaitValueMaskEx( 193 | VL53L1_Dev_t *pdev, 194 | uint32_t timeout_ms, 195 | uint16_t index, 196 | uint8_t value, 197 | uint8_t mask, 198 | uint32_t poll_delay_ms) 199 | { 200 | VL53L1_Error status = VL53L1_ERROR_NONE; 201 | return status; 202 | } 203 | 204 | 205 | 206 | 207 | -------------------------------------------------------------------------------- /vl53l1x/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(vl53l1x) 3 | 4 | ## Compile as C++11, supported in ROS Kinetic and newer 5 | add_compile_options($<$:-std=c++11>) 6 | 7 | ## Find catkin macros and libraries 8 | ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) 9 | ## is used, also find other catkin packages 10 | find_package(catkin REQUIRED COMPONENTS 11 | roscpp 12 | sensor_msgs 13 | message_generation 14 | ) 15 | 16 | ## System dependencies are found with CMake's conventions 17 | # find_package(Boost REQUIRED COMPONENTS system) 18 | 19 | 20 | ## Uncomment this if the package has a setup.py. This macro ensures 21 | ## modules and global scripts declared therein get installed 22 | ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html 23 | # catkin_python_setup() 24 | 25 | ################################################ 26 | ## Declare ROS messages, services and actions ## 27 | ################################################ 28 | 29 | ## To declare and build messages, services or actions from within this 30 | ## package, follow these steps: 31 | ## * Let MSG_DEP_SET be the set of packages whose message types you use in 32 | ## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). 33 | ## * In the file package.xml: 34 | ## * add a build_depend tag for "message_generation" 35 | ## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET 36 | ## * If MSG_DEP_SET isn't empty the following dependency has been pulled in 37 | ## but can be declared for certainty nonetheless: 38 | ## * add a run_depend tag for "message_runtime" 39 | ## * In this file (CMakeLists.txt): 40 | ## * add "message_generation" and every package in MSG_DEP_SET to 41 | ## find_package(catkin REQUIRED COMPONENTS ...) 42 | ## * add "message_runtime" and every package in MSG_DEP_SET to 43 | ## catkin_package(CATKIN_DEPENDS ...) 44 | ## * uncomment the add_*_files sections below as needed 45 | ## and list every .msg/.srv/.action file to be processed 46 | ## * uncomment the generate_messages entry below 47 | ## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) 48 | 49 | ## Generate messages in the 'msg' folder 50 | add_message_files( 51 | FILES 52 | MeasurementData.msg 53 | ) 54 | 55 | ## Generate services in the 'srv' folder 56 | # add_service_files( 57 | # FILES 58 | # Service1.srv 59 | # Service2.srv 60 | # ) 61 | 62 | ## Generate actions in the 'action' folder 63 | # add_action_files( 64 | # FILES 65 | # Action1.action 66 | # Action2.action 67 | # ) 68 | 69 | ## Generate added messages and services with any dependencies listed here 70 | generate_messages( 71 | DEPENDENCIES 72 | std_msgs # Or other packages containing msgs 73 | ) 74 | 75 | ################################################ 76 | ## Declare ROS dynamic reconfigure parameters ## 77 | ################################################ 78 | 79 | ## To declare and build dynamic reconfigure parameters within this 80 | ## package, follow these steps: 81 | ## * In the file package.xml: 82 | ## * add a build_depend and a run_depend tag for "dynamic_reconfigure" 83 | ## * In this file (CMakeLists.txt): 84 | ## * add "dynamic_reconfigure" to 85 | ## find_package(catkin REQUIRED COMPONENTS ...) 86 | ## * uncomment the "generate_dynamic_reconfigure_options" section below 87 | ## and list every .cfg file to be processed 88 | 89 | ## Generate dynamic reconfigure parameters in the 'cfg' folder 90 | # generate_dynamic_reconfigure_options( 91 | # cfg/DynReconf1.cfg 92 | # cfg/DynReconf2.cfg 93 | # ) 94 | 95 | ################################### 96 | ## catkin specific configuration ## 97 | ################################### 98 | ## The catkin_package macro generates cmake config files for your package 99 | ## Declare things to be passed to dependent projects 100 | ## INCLUDE_DIRS: uncomment this if your package contains header files 101 | ## LIBRARIES: libraries you create in this project that dependent projects also need 102 | ## CATKIN_DEPENDS: catkin_packages dependent projects also need 103 | ## DEPENDS: system dependencies of this project that dependent projects also need 104 | catkin_package( 105 | # INCLUDE_DIRS include 106 | # LIBRARIES vl53l1x 107 | CATKIN_DEPENDS message_runtime 108 | # DEPENDS system_lib 109 | ) 110 | 111 | ########### 112 | ## Build ## 113 | ########### 114 | 115 | ## Specify additional locations of header files 116 | ## Your package locations should be listed before other locations 117 | include_directories( 118 | src 119 | lib/core 120 | lib/platform 121 | ${catkin_INCLUDE_DIRS} 122 | ) 123 | 124 | ## Declare a C++ library 125 | # add_library(${PROJECT_NAME} 126 | # src/${PROJECT_NAME}/vl53l1x.cpp 127 | # ) 128 | 129 | ## Add cmake target dependencies of the library 130 | ## as an example, code may need to be generated before libraries 131 | ## either from message generation or dynamic reconfigure 132 | # add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) 133 | 134 | ## Declare a C++ executable 135 | ## With catkin_make all packages are built within a single CMake context 136 | ## The recommended prefix ensures that target names across packages don't collide 137 | FILE(GLOB vl53l1x_core lib/core/*.c) 138 | FILE(GLOB vl53l1x_platform lib/platform/*.c) 139 | 140 | add_executable(${PROJECT_NAME}_node 141 | src/vl53l1x.cpp 142 | src/i2c.cpp 143 | ${vl53l1x_core} 144 | ${vl53l1x_platform} 145 | ) 146 | 147 | add_dependencies(${PROJECT_NAME}_node ${PROJECT_NAME}_generate_messages_cpp) 148 | 149 | ## Rename C++ executable without prefix 150 | ## The above recommended prefix causes long target names, the following renames the 151 | ## target back to the shorter version for ease of user use 152 | ## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node" 153 | # set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "") 154 | 155 | ## Add cmake target dependencies of the executable 156 | ## same as for the library above 157 | # add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) 158 | 159 | ## Specify libraries to link a library or executable target against 160 | target_link_libraries(${PROJECT_NAME}_node 161 | ${catkin_LIBRARIES} 162 | ) 163 | 164 | ############# 165 | ## Install ## 166 | ############# 167 | 168 | # all install targets should use catkin DESTINATION variables 169 | # See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html 170 | 171 | ## Mark executable scripts (Python etc.) for installation 172 | ## in contrast to setup.py, you can choose the destination 173 | # install(PROGRAMS 174 | # scripts/my_python_script 175 | # DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} 176 | # ) 177 | 178 | ## Mark executables and/or libraries for installation 179 | install(TARGETS ${PROJECT_NAME}_node 180 | ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} 181 | LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} 182 | RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} 183 | ) 184 | 185 | ## Mark cpp header files for installation 186 | # install(DIRECTORY include/${PROJECT_NAME}/ 187 | # DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} 188 | # FILES_MATCHING PATTERN "*.h" 189 | # PATTERN ".svn" EXCLUDE 190 | # ) 191 | 192 | ## Mark other files for installation (e.g. launch and bag files, etc.) 193 | # install(FILES 194 | # # myfile1 195 | # # myfile2 196 | # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} 197 | # ) 198 | 199 | install(DIRECTORY launch/ 200 | DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch 201 | ) 202 | 203 | ############# 204 | ## Testing ## 205 | ############# 206 | 207 | ## Add gtest based cpp test target and link libraries 208 | # catkin_add_gtest(${PROJECT_NAME}-test test/test_vl53l1x.cpp) 209 | # if(TARGET ${PROJECT_NAME}-test) 210 | # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) 211 | # endif() 212 | 213 | ## Add folders to be run by python nosetests 214 | # catkin_add_nosetests(test) 215 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_core_support.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_core_support.h 65 | * 66 | * @brief EwokPlus25 core function definitions 67 | */ 68 | 69 | #ifndef _VL53L1_CORE_SUPPORT_H_ 70 | #define _VL53L1_CORE_SUPPORT_H_ 71 | 72 | #include "vl53l1_types.h" 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | 79 | /** 80 | * @brief Calculates the PLL period in [us] from the input 81 | * fast_osc_frequency 82 | * 83 | * @param[in] fast_osc_frequency : fast oscillator frequency in 4.12 MHz format 84 | * 85 | * @return pll_period_us : PLL period in [us] 8.24 format 86 | */ 87 | 88 | uint32_t VL53L1_calc_pll_period_us( 89 | uint16_t fast_osc_frequency); 90 | 91 | 92 | 93 | #ifdef PAL_EXTENDED 94 | /** 95 | * @brief Calculates the ranging duration in ns using fixed point maths 96 | * * 97 | * Uses a temporary uint64_t variable internally 98 | * 99 | * @param[in] pll_period_us : PLL Period in [us] 0.25 format 100 | * @param[in] vcsel_parm_pclks : period, width or WOI window in PLL clocks 101 | * in 6.4 format. 102 | * @param[in] window_vclks : ranging or ambient window duration in VCSEL clocks 103 | * @param[in] periods_elapsed_mclks : elapsed time in macro clocks 104 | * 105 | * @return duration_us : uint32_t containing the duration time in us 106 | */ 107 | 108 | uint32_t VL53L1_duration_maths( 109 | uint32_t pll_period_us, 110 | uint32_t vcsel_parm_pclks, 111 | uint32_t window_vclks, 112 | uint32_t periods_elapsed_mclks); 113 | 114 | 115 | /** 116 | * @brief Calculates the square root of the input integer 117 | * 118 | * Reference : http://en.wikipedia.org/wiki/Methods_of_computing_square_roots 119 | * 120 | * @param[in] num : input integer 121 | * 122 | * @return res : square root result 123 | */ 124 | 125 | uint32_t VL53L1_isqrt( 126 | uint32_t num); 127 | 128 | /** 129 | * @brief Calculates the count rate using fixed point maths 130 | * 131 | * Uses a temporary uint64_t variable internally 132 | * Any negative negative rates are clipped to 0. 133 | * 134 | * @param[in] events : accumulated SPAD events 135 | * @param[in] time_us : elapsed time in us 136 | * 137 | * @return rate_mcps : uint16_t count rate in 9.7 format 138 | */ 139 | 140 | uint16_t VL53L1_rate_maths( 141 | int32_t events, 142 | uint32_t time_us); 143 | 144 | /** 145 | * @brief Calculates the Rate per spad 146 | * 147 | * Uses a temporary uint32_t variable internally 148 | * Any output rates larger than 16 bit are clipped to 0xFFFF. 149 | * 150 | * @param[in] frac_bits : required output fractional precision - 7 \ 151 | * due to inherent resolution of pk_rate 152 | * @param[in] peak_count_rate : peak signal count rate in mcps 153 | * @param[in] num_spads : actual effective spads in 8.8 154 | * @param[in] max_output_value : User set value to clip output 155 | * 156 | * @return rate_per_spad : uint16_t count rate in variable fractional format 157 | */ 158 | 159 | uint16_t VL53L1_rate_per_spad_maths( 160 | uint32_t frac_bits, 161 | uint32_t peak_count_rate, 162 | uint16_t num_spads, 163 | uint32_t max_output_value); 164 | 165 | 166 | /** 167 | * @brief Calculates the range from the phase data 168 | * 169 | * Uses a temporary int64_t variable internally 170 | * 171 | * @param[in] fast_osc_frequency : Fast oscillator freq [MHz] 4.12 format 172 | * @param[in] phase : phase in 5.11 format 173 | * @param[in] zero_distance_phase : zero distance phase in 5.11 format 174 | * @param[in] fractional_bits : valid options : 0, 1, 2 175 | * @param[in] gain_factor : gain correction factor 1.11 format 176 | * @param[in] range_offset_mm : range offset [mm] 14.2 format 177 | 178 | * @return range_mm : signed range in [mm] 179 | * format depends on fractional_bits input 180 | */ 181 | 182 | int32_t VL53L1_range_maths( 183 | uint16_t fast_osc_frequency, 184 | uint16_t phase, 185 | uint16_t zero_distance_phase, 186 | uint8_t fractional_bits, 187 | int32_t gain_factor, 188 | int32_t range_offset_mm); 189 | #endif 190 | 191 | 192 | /** 193 | * @brief Decodes VCSEL period register value into the real period in PLL clocks 194 | * 195 | * @param[in] vcsel_period_reg : 8 -bit register value 196 | * 197 | * @return vcsel_period_pclks : 8-bit decoded value 198 | * 199 | */ 200 | 201 | uint8_t VL53L1_decode_vcsel_period( 202 | uint8_t vcsel_period_reg); 203 | 204 | /** 205 | * @brief Decodes the Byte.Bit coord encoding into an (x,y) coord value 206 | * 207 | * @param[in] spad_number : Coord location in Byte.Bit format 208 | * @param[out] prow : Decoded row 209 | * @param[out] pcol : Decoded column 210 | * 211 | */ 212 | 213 | void VL53L1_decode_row_col( 214 | uint8_t spad_number, 215 | uint8_t *prow, 216 | uint8_t *pcol); 217 | 218 | #ifdef __cplusplus 219 | } 220 | #endif 221 | 222 | #endif /* _VL53L1_CORE_SUPPORT_H_ */ 223 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_api_strings.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 4 | * 5 | * This file is part of VL53L1 Core and is dual licensed, 6 | * either 'STMicroelectronics 7 | * Proprietary license' 8 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 9 | * 10 | ******************************************************************************** 11 | * 12 | * 'STMicroelectronics Proprietary license' 13 | * 14 | ******************************************************************************** 15 | * 16 | * License terms: STMicroelectronics Proprietary in accordance with licensing 17 | * terms at www.st.com/sla0081 18 | * 19 | * STMicroelectronics confidential 20 | * Reproduction and Communication of this document is strictly prohibited unless 21 | * specifically authorized in writing by STMicroelectronics. 22 | * 23 | * 24 | ******************************************************************************** 25 | * 26 | * Alternatively, VL53L1 Core may be distributed under the terms of 27 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 28 | * provisions apply instead of the ones mentioned above : 29 | * 30 | ******************************************************************************** 31 | * 32 | * License terms: BSD 3-clause "New" or "Revised" License. 33 | * 34 | * Redistribution and use in source and binary forms, with or without 35 | * modification, are permitted provided that the following conditions are met: 36 | * 37 | * 1. Redistributions of source code must retain the above copyright notice, this 38 | * list of conditions and the following disclaimer. 39 | * 40 | * 2. Redistributions in binary form must reproduce the above copyright notice, 41 | * this list of conditions and the following disclaimer in the documentation 42 | * and/or other materials provided with the distribution. 43 | * 44 | * 3. Neither the name of the copyright holder nor the names of its contributors 45 | * may be used to endorse or promote products derived from this software 46 | * without specific prior written permission. 47 | * 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 49 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 51 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 54 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | * 59 | * 60 | ******************************************************************************** 61 | * 62 | */ 63 | 64 | /** 65 | * @file vl53l1_api_strings.h 66 | * @brief VL53L1 API function declarations for decoding error codes to a 67 | * text strings 68 | */ 69 | 70 | 71 | #ifndef VL53L1_API_STRINGS_H_ 72 | #define VL53L1_API_STRINGS_H_ 73 | 74 | #include "vl53l1_def.h" 75 | 76 | #ifdef __cplusplus 77 | extern "C" { 78 | #endif 79 | 80 | 81 | 82 | /** 83 | * @brief Generates a string for the input device range status code 84 | * 85 | * @param[in] RangeStatus : Device Range AStatus Code 86 | * @param[out] pRangeStatusString : pointer to character buffer 87 | * 88 | * @return VL53L1_ERROR_NONE Success 89 | * @return "Other error code" See ::VL53L1_Error 90 | */ 91 | 92 | VL53L1_Error VL53L1_get_range_status_string( 93 | uint8_t RangeStatus, 94 | char *pRangeStatusString); 95 | 96 | /** 97 | * @brief Generates an error string for the input PAL error code 98 | * 99 | * @param[in] PalErrorCode : PAL Error Code 100 | * @param[out] pPalErrorString : pointer to character buffer 101 | * 102 | * @return VL53L1_ERROR_NONE Success 103 | * @return "Other error code" See ::VL53L1_Error 104 | */ 105 | 106 | VL53L1_Error VL53L1_get_pal_error_string( 107 | VL53L1_Error PalErrorCode, 108 | char *pPalErrorString); 109 | 110 | /** 111 | * @brief Generates a string for the input PAL State code 112 | * 113 | * @param[in] PalStateCode : PAL State Code 114 | * @param[out] pPalStateString : pointer to character buffer 115 | * 116 | * @return VL53L1_ERROR_NONE Success 117 | * @return "Other error code" See ::VL53L1_Error 118 | */ 119 | 120 | VL53L1_Error VL53L1_get_pal_state_string( 121 | VL53L1_State PalStateCode, 122 | char *pPalStateString); 123 | 124 | 125 | /** 126 | * @brief Generates a string for the sequence step Id 127 | * 128 | * @param[in] SequenceStepId : Sequence Step Id 129 | * @param[out] pSequenceStepsString : pointer to character buffer 130 | * 131 | * @return VL53L1_ERROR_NONE Success 132 | * @return "Other error code" See ::VL53L1_Error 133 | */ 134 | VL53L1_Error VL53L1_get_sequence_steps_info( 135 | VL53L1_SequenceStepId SequenceStepId, 136 | char *pSequenceStepsString); 137 | 138 | /** 139 | * @brief Generates a string for the limit check Id 140 | * 141 | * @param[in] LimitCheckId : Limit check Id 142 | * @param[out] pLimitCheckString : pointer to character buffer 143 | * 144 | * @return VL53L1_ERROR_NONE Success 145 | * @return "Other error code" See ::VL53L1_Error 146 | */ 147 | VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId, 148 | char *pLimitCheckString); 149 | 150 | #ifndef VL53L1_USE_EMPTY_STRING 151 | #define VL53L1_STRING_DEVICE_INFO_NAME0 "VL53L1 cut1.0" 152 | #define VL53L1_STRING_DEVICE_INFO_NAME1 "VL53L1 cut1.1" 153 | #define VL53L1_STRING_DEVICE_INFO_TYPE "VL53L1" 154 | 155 | /* Range Status */ 156 | #define VL53L1_STRING_RANGESTATUS_NONE "No Update" 157 | #define VL53L1_STRING_RANGESTATUS_RANGEVALID "Range Valid" 158 | #define VL53L1_STRING_RANGESTATUS_SIGMA "Sigma Fail" 159 | #define VL53L1_STRING_RANGESTATUS_SIGNAL "Signal Fail" 160 | #define VL53L1_STRING_RANGESTATUS_MINRANGE "Min Range Fail" 161 | #define VL53L1_STRING_RANGESTATUS_PHASE "Phase Fail" 162 | #define VL53L1_STRING_RANGESTATUS_HW "Hardware Fail" 163 | 164 | 165 | /* Range Status */ 166 | #define VL53L1_STRING_STATE_POWERDOWN "POWERDOWN State" 167 | #define VL53L1_STRING_STATE_WAIT_STATICINIT \ 168 | "Wait for staticinit State" 169 | #define VL53L1_STRING_STATE_STANDBY "STANDBY State" 170 | #define VL53L1_STRING_STATE_IDLE "IDLE State" 171 | #define VL53L1_STRING_STATE_RUNNING "RUNNING State" 172 | #define VL53L1_STRING_STATE_RESET "RESET State" 173 | #define VL53L1_STRING_STATE_UNKNOWN "UNKNOWN State" 174 | #define VL53L1_STRING_STATE_ERROR "ERROR State" 175 | 176 | 177 | 178 | /* Check Enable */ 179 | #define VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE \ 180 | "SIGMA FINAL RANGE" 181 | #define VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE \ 182 | "SIGNAL RATE FINAL RANGE" 183 | #define VL53L1_STRING_CHECKENABLE_SIGNAL_MIN_CLIP \ 184 | "SIGNAL MIN CLIP" 185 | #define VL53L1_STRING_CHECKENABLE_RANGE_IGNORE_THRESHOLD \ 186 | "RANGE IGNORE THRESHOLD" 187 | #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_HIGH \ 188 | "RANGE PHASE HIGH" 189 | #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_LOW \ 190 | "RANGE PHASE LOW" 191 | #define VL53L1_STRING_CHECKENABLE_RANGE_PHASE_CONSISTENCY \ 192 | "RANGE PHASE CONSISTENCY" 193 | 194 | /* Sequence Step */ 195 | #define VL53L1_STRING_SEQUENCESTEP_VHV "VHV" 196 | #define VL53L1_STRING_SEQUENCESTEP_PHASECAL "PHASE CAL" 197 | #define VL53L1_STRING_SEQUENCESTEP_REFPHASE "REF PHASE" 198 | #define VL53L1_STRING_SEQUENCESTEP_DSS1 "DSS1" 199 | #define VL53L1_STRING_SEQUENCESTEP_DSS2 "DSS2" 200 | #define VL53L1_STRING_SEQUENCESTEP_MM1 "MM1" 201 | #define VL53L1_STRING_SEQUENCESTEP_MM2 "MM2" 202 | #define VL53L1_STRING_SEQUENCESTEP_RANGE "RANGE" 203 | #endif /* VL53L1_USE_EMPTY_STRING */ 204 | 205 | 206 | #ifdef __cplusplus 207 | } 208 | #endif 209 | 210 | #endif 211 | 212 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_tuning_parm_defaults.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_tuning_parm_defaults.h 65 | * 66 | * @brief Define defaults for tuning parm list 67 | * 68 | * - Ensures coherence of internal defaults to tuning table 69 | * - Allows reduction of tuning parm list to only changes from the 70 | * standard settings defined below 71 | * 72 | */ 73 | 74 | 75 | #ifndef _VL53L1_TUNING_PARM_DEFAULTS_H_ 76 | #define _VL53L1_TUNING_PARM_DEFAULTS_H_ 77 | 78 | 79 | #ifdef __cplusplus 80 | extern "C" { 81 | #endif 82 | 83 | /** @defgroup VL53L1_tuningparmdefault_group VL53L1 Defines 84 | * @brief VL53L1 Tuning Parm Default Values 85 | * @{ 86 | */ 87 | 88 | #define VL53L1_TUNINGPARM_VERSION_DEFAULT \ 89 | ((uint16_t) 32771) 90 | #define VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT \ 91 | ((uint16_t) 32769) 92 | #define VL53L1_TUNINGPARM_LLD_VERSION_DEFAULT \ 93 | ((uint16_t) 32833) 94 | #define VL53L1_TUNINGPARM_CONSISTENCY_LITE_PHASE_TOLERANCE_DEFAULT \ 95 | ((uint8_t) 2) 96 | #define VL53L1_TUNINGPARM_PHASECAL_TARGET_DEFAULT \ 97 | ((uint8_t) 33) 98 | #define VL53L1_TUNINGPARM_LITE_CAL_REPEAT_RATE_DEFAULT \ 99 | ((uint16_t) 0) 100 | #define VL53L1_TUNINGPARM_LITE_RANGING_GAIN_FACTOR_DEFAULT \ 101 | ((uint16_t) 2011) 102 | #define VL53L1_TUNINGPARM_LITE_MIN_CLIP_MM_DEFAULT \ 103 | ((uint8_t) 0) 104 | #define VL53L1_TUNINGPARM_LITE_LONG_SIGMA_THRESH_MM_DEFAULT \ 105 | ((uint16_t) 360) 106 | #define VL53L1_TUNINGPARM_LITE_MED_SIGMA_THRESH_MM_DEFAULT \ 107 | ((uint16_t) 360) 108 | #define VL53L1_TUNINGPARM_LITE_SHORT_SIGMA_THRESH_MM_DEFAULT \ 109 | ((uint16_t) 360) 110 | #define VL53L1_TUNINGPARM_LITE_LONG_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \ 111 | ((uint16_t) 192) 112 | #define VL53L1_TUNINGPARM_LITE_MED_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \ 113 | ((uint16_t) 192) 114 | #define VL53L1_TUNINGPARM_LITE_SHORT_MIN_COUNT_RATE_RTN_MCPS_DEFAULT \ 115 | ((uint16_t) 192) 116 | #define VL53L1_TUNINGPARM_LITE_SIGMA_EST_PULSE_WIDTH_DEFAULT \ 117 | ((uint8_t) 8) 118 | #define VL53L1_TUNINGPARM_LITE_SIGMA_EST_AMB_WIDTH_NS_DEFAULT \ 119 | ((uint8_t) 16) 120 | #define VL53L1_TUNINGPARM_LITE_SIGMA_REF_MM_DEFAULT \ 121 | ((uint8_t) 1) 122 | #define VL53L1_TUNINGPARM_LITE_RIT_MULT_DEFAULT \ 123 | ((uint8_t) 64) 124 | #define VL53L1_TUNINGPARM_LITE_SEED_CONFIG_DEFAULT \ 125 | ((uint8_t) 2) 126 | #define VL53L1_TUNINGPARM_LITE_QUANTIFIER_DEFAULT \ 127 | ((uint8_t) 2) 128 | #define VL53L1_TUNINGPARM_LITE_FIRST_ORDER_SELECT_DEFAULT \ 129 | ((uint8_t) 0) 130 | #define VL53L1_TUNINGPARM_LITE_XTALK_MARGIN_KCPS_DEFAULT \ 131 | ((int16_t) 0) 132 | #define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_LONG_RANGE_DEFAULT \ 133 | ((uint8_t) 14) 134 | #define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_MED_RANGE_DEFAULT \ 135 | ((uint8_t) 10) 136 | #define VL53L1_TUNINGPARM_INITIAL_PHASE_RTN_LITE_SHORT_RANGE_DEFAULT \ 137 | ((uint8_t) 6) 138 | #define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_LONG_RANGE_DEFAULT \ 139 | ((uint8_t) 14) 140 | #define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_MED_RANGE_DEFAULT \ 141 | ((uint8_t) 10) 142 | #define VL53L1_TUNINGPARM_INITIAL_PHASE_REF_LITE_SHORT_RANGE_DEFAULT \ 143 | ((uint8_t) 6) 144 | #define VL53L1_TUNINGPARM_TIMED_SEED_CONFIG_DEFAULT \ 145 | ((uint8_t) 1) 146 | #define VL53L1_TUNINGPARM_VHV_LOOPBOUND_DEFAULT \ 147 | ((uint8_t) 32) 148 | #define VL53L1_TUNINGPARM_REFSPADCHAR_DEVICE_TEST_MODE_DEFAULT \ 149 | ((uint8_t) 8) 150 | #define VL53L1_TUNINGPARM_REFSPADCHAR_VCSEL_PERIOD_DEFAULT \ 151 | ((uint8_t) 11) 152 | #define VL53L1_TUNINGPARM_REFSPADCHAR_PHASECAL_TIMEOUT_US_DEFAULT \ 153 | ((uint32_t) 1000) 154 | #define VL53L1_TUNINGPARM_REFSPADCHAR_TARGET_COUNT_RATE_MCPS_DEFAULT \ 155 | ((uint16_t) 2560) 156 | #define VL53L1_TUNINGPARM_REFSPADCHAR_MIN_COUNTRATE_LIMIT_MCPS_DEFAULT \ 157 | ((uint16_t) 1280) 158 | #define VL53L1_TUNINGPARM_REFSPADCHAR_MAX_COUNTRATE_LIMIT_MCPS_DEFAULT \ 159 | ((uint16_t) 5120) 160 | #define VL53L1_TUNINGPARM_OFFSET_CAL_DSS_RATE_MCPS_DEFAULT \ 161 | ((uint16_t) 2560) 162 | #define VL53L1_TUNINGPARM_OFFSET_CAL_PHASECAL_TIMEOUT_US_DEFAULT \ 163 | ((uint32_t) 1000) 164 | #define VL53L1_TUNINGPARM_OFFSET_CAL_MM_TIMEOUT_US_DEFAULT \ 165 | ((uint32_t) 13000) 166 | #define VL53L1_TUNINGPARM_OFFSET_CAL_RANGE_TIMEOUT_US_DEFAULT \ 167 | ((uint32_t) 13000) 168 | #define VL53L1_TUNINGPARM_OFFSET_CAL_PRE_SAMPLES_DEFAULT \ 169 | ((uint8_t) 8) 170 | #define VL53L1_TUNINGPARM_OFFSET_CAL_MM1_SAMPLES_DEFAULT \ 171 | ((uint8_t) 40) 172 | #define VL53L1_TUNINGPARM_OFFSET_CAL_MM2_SAMPLES_DEFAULT \ 173 | ((uint8_t) 9) 174 | #define VL53L1_TUNINGPARM_SPADMAP_VCSEL_PERIOD_DEFAULT \ 175 | ((uint8_t) 18) 176 | #define VL53L1_TUNINGPARM_SPADMAP_VCSEL_START_DEFAULT \ 177 | ((uint8_t) 15) 178 | #define VL53L1_TUNINGPARM_SPADMAP_RATE_LIMIT_MCPS_DEFAULT \ 179 | ((uint16_t) 12) 180 | #define VL53L1_TUNINGPARM_LITE_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \ 181 | ((uint16_t) 2560) 182 | #define VL53L1_TUNINGPARM_TIMED_DSS_CONFIG_TARGET_TOTAL_RATE_MCPS_DEFAULT \ 183 | ((uint16_t) 2560) 184 | #define VL53L1_TUNINGPARM_LITE_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \ 185 | ((uint32_t) 1000) 186 | #define VL53L1_TUNINGPARM_TIMED_PHASECAL_CONFIG_TIMEOUT_US_DEFAULT \ 187 | ((uint32_t) 1000) 188 | #define VL53L1_TUNINGPARM_LITE_MM_CONFIG_TIMEOUT_US_DEFAULT \ 189 | ((uint32_t) 2000) 190 | #define VL53L1_TUNINGPARM_TIMED_MM_CONFIG_TIMEOUT_US_DEFAULT \ 191 | ((uint32_t) 2000) 192 | #define VL53L1_TUNINGPARM_LITE_RANGE_CONFIG_TIMEOUT_US_DEFAULT \ 193 | ((uint32_t) 63000) 194 | #define VL53L1_TUNINGPARM_TIMED_RANGE_CONFIG_TIMEOUT_US_DEFAULT \ 195 | ((uint32_t) 13000) 196 | #define VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND_DEFAULT \ 197 | ((uint8_t) 3) 198 | #define VL53L1_TUNINGPARM_LOWPOWERAUTO_MM_CONFIG_TIMEOUT_US_DEFAULT \ 199 | ((uint32_t) 1) 200 | #define VL53L1_TUNINGPARM_LOWPOWERAUTO_RANGE_CONFIG_TIMEOUT_US_DEFAULT \ 201 | ((uint32_t) 8000) 202 | 203 | 204 | #ifdef __cplusplus 205 | } 206 | #endif 207 | 208 | #endif /* _VL53L1_LL_DEF_H_ */ 209 | 210 | 211 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_error_strings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_error_strings.h 65 | * @brief VL53L1 function declarations for decoding error codes to a 66 | * text strings 67 | */ 68 | 69 | 70 | #ifndef VL53L1_ERROR_STRINGS_H_ 71 | #define VL53L1_ERROR_STRINGS_H_ 72 | 73 | #include "vl53l1_error_codes.h" 74 | 75 | #ifdef __cplusplus 76 | extern "C" { 77 | #endif 78 | 79 | 80 | /** 81 | * @brief Generates an error string for the input PAL error code 82 | * 83 | * @param[in] PalErrorCode : PAL Error Code 84 | * @param[out] pPalErrorString : pointer to character buffer 85 | * 86 | * @return VL53L1_ERROR_NONE Success 87 | * @return "Other error code" See ::VL53L1_Error 88 | */ 89 | 90 | VL53L1_Error VL53L1_get_pal_error_string( 91 | VL53L1_Error PalErrorCode, 92 | char *pPalErrorString); 93 | 94 | 95 | #ifndef VL53L1_USE_EMPTY_STRING 96 | 97 | /* PAL ERROR strings */ 98 | #define VL53L1_STRING_ERROR_NONE \ 99 | "No Error" 100 | #define VL53L1_STRING_ERROR_CALIBRATION_WARNING \ 101 | "Calibration Warning Error" 102 | #define VL53L1_STRING_ERROR_MIN_CLIPPED \ 103 | "Min clipped error" 104 | #define VL53L1_STRING_ERROR_UNDEFINED \ 105 | "Undefined error" 106 | #define VL53L1_STRING_ERROR_INVALID_PARAMS \ 107 | "Invalid parameters error" 108 | #define VL53L1_STRING_ERROR_NOT_SUPPORTED \ 109 | "Not supported error" 110 | #define VL53L1_STRING_ERROR_RANGE_ERROR \ 111 | "Range error" 112 | #define VL53L1_STRING_ERROR_TIME_OUT \ 113 | "Time out error" 114 | #define VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED \ 115 | "Mode not supported error" 116 | #define VL53L1_STRING_ERROR_BUFFER_TOO_SMALL \ 117 | "Buffer too small" 118 | #define VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL \ 119 | "Comms Buffer too small" 120 | #define VL53L1_STRING_ERROR_GPIO_NOT_EXISTING \ 121 | "GPIO not existing" 122 | #define VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED \ 123 | "GPIO funct not supported" 124 | #define VL53L1_STRING_ERROR_CONTROL_INTERFACE \ 125 | "Control Interface Error" 126 | #define VL53L1_STRING_ERROR_INVALID_COMMAND \ 127 | "Invalid Command Error" 128 | #define VL53L1_STRING_ERROR_DIVISION_BY_ZERO \ 129 | "Division by zero Error" 130 | #define VL53L1_STRING_ERROR_REF_SPAD_INIT \ 131 | "Reference Spad Init Error" 132 | #define VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL \ 133 | "GPH Sync Check Fail - API out of sync" 134 | #define VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL \ 135 | "Stream Count Check Fail - API out of sync" 136 | #define VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL \ 137 | "GPH ID Check Fail - API out of sync" 138 | #define VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL \ 139 | "Zone Stream Count Check Fail - API out of sync" 140 | #define VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL \ 141 | "Zone GPH ID Check Fail - API out of sync" 142 | 143 | #define VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL \ 144 | "No Xtalk using full array - Xtalk Extract Fail" 145 | #define VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL \ 146 | "Xtalk does not meet required sigma limit - Xtalk Extract Fail" 147 | 148 | #define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL \ 149 | "Offset Cal - one of more stages with no valid samples - fatal" 150 | #define VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL \ 151 | "Offset Cal - one of more stages with no SPADS enables - fatal" 152 | #define VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL \ 153 | "Zone Cal - one of more zones with no valid samples - fatal" 154 | 155 | #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS \ 156 | "Ref SPAD Char - Not Enough Good SPADs" 157 | #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH \ 158 | "Ref SPAD Char - Final Ref Rate too high" 159 | #define VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW \ 160 | "Ref SPAD Char - Final Ref Rate too low" 161 | 162 | #define VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES \ 163 | "Offset Cal - Less than the requested number of valid samples" 164 | #define VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH \ 165 | "Offset Cal - Sigma estimate value too high - offset not stable" 166 | #define VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH \ 167 | "Offset Cal - Rate too high - in pile up" 168 | #define VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW \ 169 | "Offset Cal - Insufficient SPADs - offset may not be stable" 170 | 171 | #define VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES \ 172 | "Zone Cal - One or more zone with less than requested valid samples" 173 | #define VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH \ 174 | "Zone Cal - One of more zones the sigma estimate too high" 175 | #define VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH \ 176 | "Zone Cal - One of more zones with rate too high - in pile up" 177 | 178 | #define VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT \ 179 | "Xtalk - Gradient sample num = 0" 180 | #define VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT \ 181 | "Xtalk - Gradient Sigma > Limit" 182 | #define VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES \ 183 | "Xtalk - Some missing and invalid samples" 184 | 185 | #define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD \ 186 | "Device Firmware too old" 187 | #define VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW \ 188 | "Device Firmware too new" 189 | #define VL53L1_STRING_ERROR_UNIT_TEST_FAIL \ 190 | "Unit Test Fail" 191 | #define VL53L1_STRING_ERROR_FILE_READ_FAIL \ 192 | "File Read Fail" 193 | #define VL53L1_STRING_ERROR_FILE_WRITE_FAIL \ 194 | "File Write Fail" 195 | 196 | #define VL53L1_STRING_ERROR_NOT_IMPLEMENTED \ 197 | "Not implemented error" 198 | #define VL53L1_STRING_UNKNOW_ERROR_CODE \ 199 | "Unknown Error Code" 200 | 201 | #endif /* VL53L1_USE_EMPTY_STRING */ 202 | 203 | 204 | #ifdef __cplusplus 205 | } 206 | #endif 207 | 208 | #endif 209 | 210 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_api_strings.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 4 | * 5 | * This file is part of VL53L1 Core and is dual licensed, 6 | * either 'STMicroelectronics 7 | * Proprietary license' 8 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 9 | * 10 | ******************************************************************************** 11 | * 12 | * 'STMicroelectronics Proprietary license' 13 | * 14 | ******************************************************************************** 15 | * 16 | * License terms: STMicroelectronics Proprietary in accordance with licensing 17 | * terms at www.st.com/sla0081 18 | * 19 | * STMicroelectronics confidential 20 | * Reproduction and Communication of this document is strictly prohibited unless 21 | * specifically authorized in writing by STMicroelectronics. 22 | * 23 | * 24 | ******************************************************************************** 25 | * 26 | * Alternatively, VL53L1 Core may be distributed under the terms of 27 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 28 | * provisions apply instead of the ones mentioned above : 29 | * 30 | ******************************************************************************** 31 | * 32 | * License terms: BSD 3-clause "New" or "Revised" License. 33 | * 34 | * Redistribution and use in source and binary forms, with or without 35 | * modification, are permitted provided that the following conditions are met: 36 | * 37 | * 1. Redistributions of source code must retain the above copyright notice, this 38 | * list of conditions and the following disclaimer. 39 | * 40 | * 2. Redistributions in binary form must reproduce the above copyright notice, 41 | * this list of conditions and the following disclaimer in the documentation 42 | * and/or other materials provided with the distribution. 43 | * 44 | * 3. Neither the name of the copyright holder nor the names of its contributors 45 | * may be used to endorse or promote products derived from this software 46 | * without specific prior written permission. 47 | * 48 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 49 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 51 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 54 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 57 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 58 | * 59 | * 60 | ******************************************************************************** 61 | * 62 | */ 63 | 64 | /** 65 | * @file vl53l1_api_strings.c 66 | * @brief VL53L1 API functions for decoding error codes to a text string 67 | */ 68 | 69 | #include "vl53l1_api_core.h" 70 | #include "vl53l1_api_strings.h" 71 | #include "vl53l1_error_codes.h" 72 | #include "vl53l1_error_strings.h" 73 | 74 | #define LOG_FUNCTION_START(fmt, ...) \ 75 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__) 76 | #define LOG_FUNCTION_END(status, ...) \ 77 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__) 78 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ 79 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, \ 80 | ##__VA_ARGS__) 81 | 82 | 83 | VL53L1_Error VL53L1_get_range_status_string( 84 | uint8_t RangeStatus, 85 | char *pRangeStatusString) 86 | { 87 | VL53L1_Error status = VL53L1_ERROR_NONE; 88 | 89 | LOG_FUNCTION_START(""); 90 | 91 | #ifdef VL53L1_USE_EMPTY_STRING 92 | VL53L1_COPYSTRING(pRangeStatusString, ""); 93 | #else 94 | switch (RangeStatus) { 95 | case 0: 96 | VL53L1_COPYSTRING(pRangeStatusString, 97 | VL53L1_STRING_RANGESTATUS_RANGEVALID); 98 | break; 99 | case 1: 100 | VL53L1_COPYSTRING(pRangeStatusString, 101 | VL53L1_STRING_RANGESTATUS_SIGMA); 102 | break; 103 | case 2: 104 | VL53L1_COPYSTRING(pRangeStatusString, 105 | VL53L1_STRING_RANGESTATUS_SIGNAL); 106 | break; 107 | case 3: 108 | VL53L1_COPYSTRING(pRangeStatusString, 109 | VL53L1_STRING_RANGESTATUS_MINRANGE); 110 | break; 111 | case 4: 112 | VL53L1_COPYSTRING(pRangeStatusString, 113 | VL53L1_STRING_RANGESTATUS_PHASE); 114 | break; 115 | case 5: 116 | VL53L1_COPYSTRING(pRangeStatusString, 117 | VL53L1_STRING_RANGESTATUS_HW); 118 | break; 119 | 120 | default: /**/ 121 | VL53L1_COPYSTRING(pRangeStatusString, 122 | VL53L1_STRING_RANGESTATUS_NONE); 123 | } 124 | #endif 125 | 126 | LOG_FUNCTION_END(status); 127 | return status; 128 | } 129 | 130 | 131 | VL53L1_Error VL53L1_get_pal_state_string( 132 | VL53L1_State PalStateCode, 133 | char *pPalStateString) 134 | { 135 | VL53L1_Error status = VL53L1_ERROR_NONE; 136 | 137 | LOG_FUNCTION_START(""); 138 | 139 | #ifdef VL53L1_USE_EMPTY_STRING 140 | VL53L1_COPYSTRING(pPalStateString, ""); 141 | #else 142 | switch (PalStateCode) { 143 | case VL53L1_STATE_POWERDOWN: 144 | VL53L1_COPYSTRING(pPalStateString, 145 | VL53L1_STRING_STATE_POWERDOWN); 146 | break; 147 | case VL53L1_STATE_WAIT_STATICINIT: 148 | VL53L1_COPYSTRING(pPalStateString, 149 | VL53L1_STRING_STATE_WAIT_STATICINIT); 150 | break; 151 | case VL53L1_STATE_STANDBY: 152 | VL53L1_COPYSTRING(pPalStateString, 153 | VL53L1_STRING_STATE_STANDBY); 154 | break; 155 | case VL53L1_STATE_IDLE: 156 | VL53L1_COPYSTRING(pPalStateString, 157 | VL53L1_STRING_STATE_IDLE); 158 | break; 159 | case VL53L1_STATE_RUNNING: 160 | VL53L1_COPYSTRING(pPalStateString, 161 | VL53L1_STRING_STATE_RUNNING); 162 | break; 163 | case VL53L1_STATE_RESET: 164 | VL53L1_COPYSTRING(pPalStateString, 165 | VL53L1_STRING_STATE_RESET); 166 | break; 167 | case VL53L1_STATE_UNKNOWN: 168 | VL53L1_COPYSTRING(pPalStateString, 169 | VL53L1_STRING_STATE_UNKNOWN); 170 | break; 171 | case VL53L1_STATE_ERROR: 172 | VL53L1_COPYSTRING(pPalStateString, 173 | VL53L1_STRING_STATE_ERROR); 174 | break; 175 | 176 | default: 177 | VL53L1_COPYSTRING(pPalStateString, 178 | VL53L1_STRING_STATE_UNKNOWN); 179 | } 180 | #endif 181 | 182 | LOG_FUNCTION_END(status); 183 | return status; 184 | } 185 | 186 | VL53L1_Error VL53L1_get_sequence_steps_info( 187 | VL53L1_SequenceStepId SequenceStepId, 188 | char *pSequenceStepsString) 189 | { 190 | VL53L1_Error Status = VL53L1_ERROR_NONE; 191 | 192 | LOG_FUNCTION_START(""); 193 | 194 | #ifdef VL53L1_USE_EMPTY_STRING 195 | VL53L1_COPYSTRING(pSequenceStepsString, ""); 196 | #else 197 | switch (SequenceStepId) { 198 | case VL53L1_SEQUENCESTEP_VHV: 199 | VL53L1_COPYSTRING(pSequenceStepsString, 200 | VL53L1_STRING_SEQUENCESTEP_VHV); 201 | break; 202 | case VL53L1_SEQUENCESTEP_PHASECAL: 203 | VL53L1_COPYSTRING(pSequenceStepsString, 204 | VL53L1_STRING_SEQUENCESTEP_PHASECAL); 205 | break; 206 | case VL53L1_SEQUENCESTEP_REFPHASE: 207 | VL53L1_COPYSTRING(pSequenceStepsString, 208 | VL53L1_STRING_SEQUENCESTEP_DSS1); 209 | break; 210 | case VL53L1_SEQUENCESTEP_DSS1: 211 | VL53L1_COPYSTRING(pSequenceStepsString, 212 | VL53L1_STRING_SEQUENCESTEP_DSS1); 213 | break; 214 | case VL53L1_SEQUENCESTEP_DSS2: 215 | VL53L1_COPYSTRING(pSequenceStepsString, 216 | VL53L1_STRING_SEQUENCESTEP_DSS2); 217 | break; 218 | case VL53L1_SEQUENCESTEP_MM1: 219 | VL53L1_COPYSTRING(pSequenceStepsString, 220 | VL53L1_STRING_SEQUENCESTEP_MM1); 221 | break; 222 | case VL53L1_SEQUENCESTEP_MM2: 223 | VL53L1_COPYSTRING(pSequenceStepsString, 224 | VL53L1_STRING_SEQUENCESTEP_MM2); 225 | break; 226 | case VL53L1_SEQUENCESTEP_RANGE: 227 | VL53L1_COPYSTRING(pSequenceStepsString, 228 | VL53L1_STRING_SEQUENCESTEP_RANGE); 229 | break; 230 | default: 231 | Status = VL53L1_ERROR_INVALID_PARAMS; 232 | } 233 | #endif 234 | 235 | LOG_FUNCTION_END(Status); 236 | 237 | return Status; 238 | } 239 | 240 | VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId, 241 | char *pLimitCheckString) 242 | { 243 | VL53L1_Error Status = VL53L1_ERROR_NONE; 244 | 245 | LOG_FUNCTION_START(""); 246 | 247 | #ifdef VL53L1_USE_EMPTY_STRING 248 | VL53L1_COPYSTRING(pLimitCheckString, ""); 249 | #else 250 | switch (LimitCheckId) { 251 | case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE: 252 | VL53L1_COPYSTRING(pLimitCheckString, 253 | VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE); 254 | break; 255 | case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE: 256 | VL53L1_COPYSTRING(pLimitCheckString, 257 | VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE); 258 | break; 259 | default: 260 | VL53L1_COPYSTRING(pLimitCheckString, 261 | VL53L1_STRING_UNKNOW_ERROR_CODE); 262 | } 263 | #endif 264 | 265 | LOG_FUNCTION_END(Status); 266 | return Status; 267 | } 268 | 269 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_register_settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_register_settings.h 65 | * 66 | * @brief Device register setting defines. 67 | */ 68 | 69 | #ifndef _VL53L1_REGISTER_SETTINGS_H_ 70 | #define _VL53L1_REGISTER_SETTINGS_H_ 71 | 72 | 73 | /** @defgroup VL53L1_RegisterSettings_group Functionality 74 | * @brief Defines the register settings for key device 75 | * configuration registers 76 | * @{ 77 | */ 78 | 79 | /** @defgroup VL53L1_DeviceSchedulerMode_group - Pseudo, Streaming & Hist 80 | * @brief Values below match the bit positions in the SYSTEM__MODE_START 81 | * register do not change 82 | * @{ 83 | */ 84 | 85 | #define VL53L1_DEVICESCHEDULERMODE_PSEUDO_SOLO 0x00 86 | #define VL53L1_DEVICESCHEDULERMODE_STREAMING 0x01 87 | #define VL53L1_DEVICESCHEDULERMODE_HISTOGRAM 0x02 88 | 89 | /** @} end of VL53L1_DeviceReadoutMode_group */ 90 | 91 | /** @defgroup VL53L1_DeviceReadoutMode_group - Single, Dual, Split & Manual 92 | * @brief Values below match the bit positions in the SYSTEM__MODE_START 93 | * register do not change 94 | * @{ 95 | */ 96 | 97 | #define VL53L1_DEVICEREADOUTMODE_SINGLE_SD (0x00 << 2) 98 | #define VL53L1_DEVICEREADOUTMODE_DUAL_SD (0x01 << 2) 99 | #define VL53L1_DEVICEREADOUTMODE_SPLIT_READOUT (0x02 << 2) 100 | #define VL53L1_DEVICEREADOUTMODE_SPLIT_MANUAL (0x03 << 2) 101 | 102 | /** @} end of VL53L1_DeviceReadoutMode_group */ 103 | 104 | /** @defgroup VL53L1_DeviceMeasurementMode_group - SingleShot, BackToBack & timed 105 | * @brief Values below match the bit positions in the SYSTEM__MODE_START 106 | * register do not change 107 | * @{ 108 | */ 109 | 110 | /* 111 | #define VL53L1_DEVICEMEASUREMENTMODE_STOP 0x00 112 | #define VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT 0x10 113 | #define VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK 0x20 114 | #define VL53L1_DEVICEMEASUREMENTMODE_TIMED 0x40 115 | #define VL53L1_DEVICEMEASUREMENTMODE_ABORT 0x80 116 | */ 117 | #define VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK 0xF0 118 | #define VL53L1_DEVICEMEASUREMENTMODE_STOP_MASK 0x0F 119 | 120 | #define VL53L1_GROUPEDPARAMETERHOLD_ID_MASK 0x02 121 | 122 | /** @} end of VL53L1_DeviceMeasurementMode_group */ 123 | 124 | #define VL53L1_EWOK_I2C_DEV_ADDR_DEFAULT 0x29 125 | /*!< Device default 7-bit I2C address */ 126 | #define VL53L1_OSC_FREQUENCY 0x00 127 | #define VL53L1_OSC_TRIM_DEFAULT 0x00 128 | #define VL53L1_OSC_FREQ_SET_DEFAULT 0x00 129 | 130 | #define VL53L1_RANGE_HISTOGRAM_REF 0x08 131 | #define VL53L1_RANGE_HISTOGRAM_RET 0x10 132 | #define VL53L1_RANGE_HISTOGRAM_BOTH 0x18 133 | #define VL53L1_RANGE_HISTOGRAM_INIT 0x20 134 | #define VL53L1_RANGE_VHV_INIT 0x40 135 | 136 | /* Result Status */ 137 | #define VL53L1_RESULT_RANGE_STATUS 0x1F 138 | 139 | /* */ 140 | #define VL53L1_SYSTEM__SEED_CONFIG__MANUAL 0x00 141 | #define VL53L1_SYSTEM__SEED_CONFIG__STANDARD 0x01 142 | #define VL53L1_SYSTEM__SEED_CONFIG__EVEN_UPDATE_ONLY 0x02 143 | 144 | /* Interrupt Config */ 145 | #define VL53L1_INTERRUPT_CONFIG_LEVEL_LOW 0x00 146 | #define VL53L1_INTERRUPT_CONFIG_LEVEL_HIGH 0x01 147 | #define VL53L1_INTERRUPT_CONFIG_OUT_OF_WINDOW 0x02 148 | #define VL53L1_INTERRUPT_CONFIG_IN_WINDOW 0x03 149 | #define VL53L1_INTERRUPT_CONFIG_NEW_SAMPLE_READY 0x20 150 | 151 | /* Interrupt Clear */ 152 | #define VL53L1_CLEAR_RANGE_INT 0x01 153 | #define VL53L1_CLEAR_ERROR_INT 0x02 154 | 155 | /* Sequence Config */ 156 | #define VL53L1_SEQUENCE_VHV_EN 0x01 157 | #define VL53L1_SEQUENCE_PHASECAL_EN 0x02 158 | #define VL53L1_SEQUENCE_REFERENCE_PHASE_EN 0x04 159 | #define VL53L1_SEQUENCE_DSS1_EN 0x08 160 | #define VL53L1_SEQUENCE_DSS2_EN 0x10 161 | #define VL53L1_SEQUENCE_MM1_EN 0x20 162 | #define VL53L1_SEQUENCE_MM2_EN 0x40 163 | #define VL53L1_SEQUENCE_RANGE_EN 0x80 164 | 165 | /* defines for DSS__ROI_CONTROL */ 166 | #define VL53L1_DSS_CONTROL__ROI_SUBTRACT 0x20 167 | #define VL53L1_DSS_CONTROL__ROI_INTERSECT 0x10 168 | 169 | #define VL53L1_DSS_CONTROL__MODE_DISABLED 0x00 170 | #define VL53L1_DSS_CONTROL__MODE_TARGET_RATE 0x01 171 | #define VL53L1_DSS_CONTROL__MODE_EFFSPADS 0x02 172 | #define VL53L1_DSS_CONTROL__MODE_BLOCKSELECT 0x03 173 | 174 | /* SPAD Readout defines 175 | * 176 | * 7:6 - SPAD_IN_SEL_REF 177 | * 5:4 - SPAD_IN_SEL_RTN 178 | * 2 - SPAD_PS_BYPASS 179 | * 0 - SPAD_EN_PULSE_EXTENDER 180 | */ 181 | 182 | #define VL53L1_RANGING_CORE__SPAD_READOUT__STANDARD 0x45 183 | #define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_ARRAY_ONLY 0x05 184 | #define VL53L1_RANGING_CORE__SPAD_READOUT__REFERENCE_ARRAY_ONLY 0x55 185 | #define VL53L1_RANGING_CORE__SPAD_READOUT__RETURN_SPLIT_ARRAY 0x25 186 | #define VL53L1_RANGING_CORE__SPAD_READOUT__CALIB_PULSES 0xF5 187 | 188 | 189 | #define VL53L1_LASER_SAFETY__KEY_VALUE 0x6C 190 | 191 | /* Range Status defines 192 | * 193 | * 7 - GPH ID 194 | * 6 - Min threshold hit 195 | * 5 - Max threshold hit 196 | * 4:0 - Range Status 197 | */ 198 | 199 | #define VL53L1_RANGE_STATUS__RANGE_STATUS_MASK 0x1F 200 | #define VL53L1_RANGE_STATUS__MAX_THRESHOLD_HIT_MASK 0x20 201 | #define VL53L1_RANGE_STATUS__MIN_THRESHOLD_HIT_MASK 0x40 202 | #define VL53L1_RANGE_STATUS__GPH_ID_RANGE_STATUS_MASK 0x80 203 | 204 | /* Interrupt Status defines 205 | * 206 | * 5 - GPH ID 207 | * 4:3 - Interrupt Error Status 208 | * 2:0 - Interrupt Status 209 | */ 210 | 211 | #define VL53L1_INTERRUPT_STATUS__INT_STATUS_MASK 0x07 212 | #define VL53L1_INTERRUPT_STATUS__INT_ERROR_STATUS_MASK 0x18 213 | #define VL53L1_INTERRUPT_STATUS__GPH_ID_INT_STATUS_MASK 0x20 214 | 215 | /** @} end of VL53L1_RegisterSettings_group */ 216 | 217 | 218 | #endif 219 | 220 | /* _VL53L1_REGISTER_SETTINGS_H_ */ 221 | 222 | 223 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_wait.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_wait.h 65 | * 66 | * @brief EwokPlus25 low level Driver wait function definitions 67 | */ 68 | 69 | #ifndef _VL53L1_WAIT_H_ 70 | #define _VL53L1_WAIT_H_ 71 | 72 | #include "vl53l1_platform.h" 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | 79 | /** 80 | * @brief Wait for initial firmware boot to finish 81 | * 82 | * Calls VL53L1_poll_for_boot_completion() 83 | * 84 | * @param[in] Dev : Device handle 85 | * 86 | * @return VL53L1_ERROR_NONE Success 87 | * @return "Other error code" See ::VL53L1_Error 88 | */ 89 | 90 | VL53L1_Error VL53L1_wait_for_boot_completion( 91 | VL53L1_DEV Dev); 92 | 93 | 94 | /** 95 | * @brief Waits for initial firmware ready 96 | * 97 | * Only waits to see if the firmware is ready in timed and 98 | * single shot modes. 99 | * 100 | * Calls VL53L1_poll_for_firmware_ready() 101 | * 102 | * @param[in] Dev : Device handle 103 | * 104 | * @return VL53L1_ERROR_NONE Success 105 | * @return "Other error code" See ::VL53L1_Error 106 | */ 107 | 108 | VL53L1_Error VL53L1_wait_for_firmware_ready( 109 | VL53L1_DEV Dev); 110 | 111 | 112 | /** 113 | * @brief Waits for the next ranging interrupt 114 | * 115 | * Calls VL53L1_poll_for_range_completion() 116 | * 117 | * @param[in] Dev : Device handle 118 | * 119 | * @return VL53L1_ERROR_NONE Success 120 | * @return "Other error code" See ::VL53L1_Error 121 | */ 122 | 123 | VL53L1_Error VL53L1_wait_for_range_completion( 124 | VL53L1_DEV Dev); 125 | 126 | 127 | /** 128 | * @brief Waits for a device test mode to complete. 129 | 130 | * Calls VL53L1_poll_for_test_completion() 131 | * 132 | * @param[in] Dev : Device Handle 133 | * 134 | * @return VL53L1_ERROR_NONE Success 135 | * @return "Other error code" See ::VL53L1_Error 136 | */ 137 | 138 | VL53L1_Error VL53L1_wait_for_test_completion( 139 | VL53L1_DEV Dev); 140 | 141 | 142 | 143 | 144 | /** 145 | * @brief Reads FIRMWARE__SYSTEM_STATUS register to detect if the 146 | * firmware was finished booting 147 | * 148 | * @param[in] Dev : Device handle 149 | * @param[out] pready : pointer to data ready flag \n 150 | * 0 = boot not complete \n 151 | * 1 = boot complete 152 | * 153 | * @return VL53L1_ERROR_NONE Success 154 | * @return "Other error code" See ::VL53L1_Error 155 | */ 156 | 157 | VL53L1_Error VL53L1_is_boot_complete( 158 | VL53L1_DEV Dev, 159 | uint8_t *pready); 160 | 161 | /** 162 | * @brief Reads FIRMWARE__SYSTEM_STATUS register to detect if the 163 | * firmware is ready for ranging. 164 | * 165 | * @param[in] Dev : Device handle 166 | * @param[out] pready : pointer to data ready flag \n 167 | * 0 = firmware not ready \n 168 | * 1 = firmware ready 169 | * 170 | * @return VL53L1_ERROR_NONE Success 171 | * @return "Other error code" See ::VL53L1_Error 172 | */ 173 | 174 | VL53L1_Error VL53L1_is_firmware_ready( 175 | VL53L1_DEV Dev, 176 | uint8_t *pready); 177 | 178 | 179 | /** 180 | * @brief Reads bit 0 of VL53L1_GPIO__TIO_HV_STATUS register to determine 181 | * if new range data is ready (available). 182 | * 183 | * Interrupt may be either active high or active low. The behaviour of bit 0 184 | * of the VL53L1_GPIO__TIO_HV_STATUS register is the same as the interrupt 185 | * signal generated on the GPIO pin. 186 | * 187 | * pdev->stat_cfg.gpio_hv_mux_ctrl bit 4 is used to select required check level 188 | * 189 | * 190 | * @param[in] Dev : Device handle 191 | * @param[out] pready : pointer to data ready flag \n 192 | * 0 = data not ready \n 193 | * 1 = new range data available 194 | * 195 | * @return VL53L1_ERROR_NONE Success 196 | * @return "Other error code" See ::VL53L1_Error 197 | */ 198 | 199 | VL53L1_Error VL53L1_is_new_data_ready( 200 | VL53L1_DEV Dev, 201 | uint8_t *pready); 202 | 203 | 204 | 205 | 206 | /** 207 | * @brief Waits (polls) for initial firmware boot to finish 208 | * 209 | * After power on or a device reset via XSHUTDOWN EwokPlus25 firmware takes 210 | * about 2ms to boot. During this boot sequence elected NVM data is copied 211 | * to the device's Host & MCU G02 registers 212 | * 213 | * This function polls the FIRMWARE__SYSTEM_STATUS register to detect when 214 | * firmware is ready. 215 | * 216 | * Polling is implemented using VL53L1_WaitValueMaskEx() 217 | * 218 | * @param[in] Dev : Device handle 219 | * @param[in] timeout_ms : Wait timeout in [ms] 220 | * 221 | * @return VL53L1_ERROR_NONE Success 222 | * @return "Other error code" See ::VL53L1_Error 223 | */ 224 | 225 | VL53L1_Error VL53L1_poll_for_boot_completion( 226 | VL53L1_DEV Dev, 227 | uint32_t timeout_ms); 228 | 229 | 230 | /** 231 | * @brief Waits (polls) for initial firmware ready 232 | * 233 | * Polling is implemented using VL53L1_WaitValueMaskEx() 234 | * 235 | * @param[in] Dev : Device handle 236 | * @param[in] timeout_ms : Wait timeout in [ms] 237 | * 238 | * @return VL53L1_ERROR_NONE Success 239 | * @return "Other error code" See ::VL53L1_Error 240 | */ 241 | 242 | VL53L1_Error VL53L1_poll_for_firmware_ready( 243 | VL53L1_DEV Dev, 244 | uint32_t timeout_ms); 245 | 246 | 247 | /** 248 | * @brief Polls bit 0 of VL53L1_GPIO__TIO_HV_STATUS register to determine 249 | * the state of the GPIO (Interrupt) pin. 250 | * 251 | * Interrupt may be either active high or active low. The behaviour of bit 0 252 | * of the VL53L1_GPIO__TIO_HV_STATUS register is the same as the interrupt 253 | * signal generated on the GPIO pin. 254 | * 255 | * pdev->stat_cfg.gpio_hv_mux_ctrl bit 4 is used to select required check level 256 | * 257 | * Polling is implemented using VL53L1_WaitValueMaskEx() 258 | * 259 | * @param[in] Dev : Device handle 260 | * @param[in] timeout_ms : Wait timeout in [ms] 261 | * 262 | * @return VL53L1_ERROR_NONE Success 263 | * @return "Other error code" See ::VL53L1_Error 264 | */ 265 | 266 | VL53L1_Error VL53L1_poll_for_range_completion( 267 | VL53L1_DEV Dev, 268 | uint32_t timeout_ms); 269 | 270 | 271 | 272 | #ifdef __cplusplus 273 | } 274 | #endif 275 | 276 | #endif /* _VL53L1_WAIT_H_ */ 277 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_api_calibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_api_core.h 65 | * 66 | * @brief EwokPlus25 low level API function definitions 67 | */ 68 | 69 | #ifndef _VL53L1_API_CALIBRATION_H_ 70 | #define _VL53L1_API_CALIBRATION_H_ 71 | 72 | #include "vl53l1_platform.h" 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | 79 | /** 80 | * @brief Run Reference Array SPAD Characterisation. 81 | * 82 | * This function finds the required number of reference SPAD 83 | * to meet the input required peak reference rate. 84 | * 85 | * The algorithm first tries the non apertured reference SPAD's, 86 | * if the rate is too high for the minimum allowed SPAD count (5) 87 | * then the algo switches to 5x apertured SPAD's and if the rate 88 | * is still to high then the 10x apertured SPAD are selected. 89 | * 90 | * The function reads the following results from the device and 91 | * both caches the values in the pdev->customer structure and 92 | * writes the data into the G02 customer register group. 93 | * 94 | * - num_ref_spads 95 | * - ref_location 96 | * - DCR SPAD enables for selected reference location 97 | * 98 | * Note power force is enabled as the function needs to read 99 | * data from the Patch RAM. 100 | * 101 | * Should only be called once per part with coverglass attached to 102 | * generate the required num of SPAD, Ref location and DCR SPAD enable 103 | * data 104 | * 105 | * @param[in] Dev : Device Handle 106 | * @param[out] pcal_status : Pointer to unfiltered calibration status 107 | * 108 | * @return VL53L1_ERROR_NONE Success 109 | * @return VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS 110 | * Less than 5 Good SPAD available, output not valid 111 | * @return VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH 112 | * At end of search reference rate > 40.0 Mcps 113 | * Offset stability may be degraded. 114 | * @return VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW 115 | * At end of search reference rate < 10.0 Mcps 116 | * Offset stability may be degraded. 117 | * 118 | */ 119 | 120 | #ifndef VL53L1_NOCALIB 121 | VL53L1_Error VL53L1_run_ref_spad_char(VL53L1_DEV Dev, VL53L1_Error *pcal_status); 122 | #endif 123 | 124 | 125 | /** 126 | * @brief Runs the input Device Test 127 | * 128 | * Calls 129 | * 130 | * - VL53L1_enable_powerforce() 131 | * - VL53L1_start_test() 132 | * - VL53L1_poll_for_range_completion() 133 | * 134 | * @param[in] Dev : Device handle 135 | * @param[in] device_test_mode : Device test mode register value 136 | * 137 | * @return VL53L1_ERROR_NONE Success 138 | * @return "Other error code" See ::VL53L1_Error 139 | */ 140 | 141 | #ifndef VL53L1_NOCALIB 142 | VL53L1_Error VL53L1_run_device_test( 143 | VL53L1_DEV Dev, 144 | VL53L1_DeviceTestMode device_test_mode); 145 | #endif 146 | 147 | 148 | /** 149 | * @brief Runs SPAD rate map 150 | * 151 | * Output structure contains SPAD rate data in SPAD number order 152 | * 153 | * @param[in] Dev : Device handle 154 | * @param[in] device_test_mode : Device test mode register value. 155 | * Valid options: \n 156 | * - VL53L1_DEVICETESTMODE_LCR_VCSEL_OFF \n 157 | * - VL53L1_DEVICETESTMODE_LCR_VCSEL_ON 158 | * @param[in] array_select : Device SPAD array select 159 | * Valid options: \n 160 | * - VL53L1_DEVICESSCARRAY_RTN \n 161 | * - VL53L1_DEVICESSCARRAY_REF 162 | * @param[in] ssc_config_timeout_us : SSC timeout in [us] e.g 36000us 163 | * @param[out] pspad_rate_data : pointer to output rates structure 164 | * 1.15 format for LCR_VCSEL_OFF 165 | * 9.7 format for LCR_VCSEL_ON 166 | * 167 | * @return VL53L1_ERROR_NONE Success 168 | * @return "Other error code" See ::VL53L1_Error 169 | */ 170 | 171 | #ifndef VL53L1_NOCALIB 172 | VL53L1_Error VL53L1_run_spad_rate_map( 173 | VL53L1_DEV Dev, 174 | VL53L1_DeviceTestMode device_test_mode, 175 | VL53L1_DeviceSscArray array_select, 176 | uint32_t ssc_config_timeout_us, 177 | VL53L1_spad_rate_data_t *pspad_rate_data); 178 | #endif 179 | 180 | 181 | /** 182 | * @brief Run offset calibration 183 | * 184 | * Runs the standard ranging MM1 and MM2 calibration presets 185 | * to generate the MM1 and MM2 range offset data 186 | * 187 | * The range config timeout is used for both MM1 and MM2 so that 188 | * the sigma delta settling is the same as for the 'real' range 189 | * 190 | * Places results into VL53L1_customer_nvm_managed_t within pdev 191 | * 192 | * Use VL53L1_get_part_to_part_data() to get the offset calibration 193 | * results 194 | * 195 | * Current FMT settings: 196 | * 197 | * - offset_calibration_mode = VL53L1_OFFSETCALIBRATIONMODE__STANDARD_RANGING 198 | * - dss_config__target_total_rate_mcps = 0x0A00 (20.0Mcps) to 0x1400 (40.0Mcps) 199 | * - phasecal_config_timeout_us = 1000 200 | * - range_config_timeout_us = 13000 201 | * - pre_num_of_samples = 32 202 | * - mm1_num_of_samples = 100 203 | * - mm2_range_num_of_samples = 64 204 | * - target_distance_mm = 140 mm 205 | * - target reflectance = 5% 206 | * 207 | * Note: function parms simplified as part of Patch_CalFunctionSimplification_11791 208 | * 209 | * @param[in] Dev : Device handle 210 | * @param[in] cal_distance_mm : Distance to target in [mm] - the ground truth 211 | * @param[out] pcal_status : Pointer to unfiltered calibration status 212 | * 213 | * @return VL53L1_ERROR_NONE Success 214 | * @return VL53L1_WARNING_OFFSET_CAL_INSUFFICIENT_MM1_SPADS 215 | * Effective MM1 SPAD count too low (<5.0). 216 | * Out with recommended calibration condition. 217 | * Accuracy of offset calibration may be degraded. 218 | * @return VL53L1_WARNING_OFFSET_CAL_PRE_RANGE_RATE_TOO_HIGH 219 | * Pre range too high (>40.0) in pile up region. 220 | * Out with recommended calibration condition. 221 | * Accuracy of offset calibration may be degraded. 222 | */ 223 | 224 | #ifndef VL53L1_NOCALIB 225 | VL53L1_Error VL53L1_run_offset_calibration( 226 | VL53L1_DEV Dev, 227 | int16_t cal_distance_mm, 228 | VL53L1_Error *pcal_status); 229 | #endif 230 | 231 | 232 | #ifdef __cplusplus 233 | } 234 | #endif 235 | 236 | #endif /* _VL53L1_API_CALIBRATION_H_ */ 237 | -------------------------------------------------------------------------------- /vl53l1x/lib/platform/vl53l1_platform_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_platform_log.h 65 | * 66 | * @brief EwokPlus25 platform logging function definition 67 | */ 68 | 69 | 70 | #ifndef _VL53L1_PLATFORM_LOG_H_ 71 | #define _VL53L1_PLATFORM_LOG_H_ 72 | 73 | 74 | #ifdef VL53L1_LOG_ENABLE 75 | #include "vl53l1_platform_user_config.h" 76 | 77 | #ifdef _MSC_VER 78 | # define EWOKPLUS_EXPORTS __declspec(dllexport) 79 | #else 80 | # define EWOKPLUS_EXPORTS 81 | #endif 82 | 83 | #include "vl53l1_types.h" 84 | 85 | #ifdef __cplusplus 86 | extern "C" { 87 | #endif 88 | 89 | #include 90 | 91 | /** 92 | * @brief Set the level, output and specific functions for module logging. 93 | * 94 | * 95 | * @param filename - full path of output log file, NULL for print to stdout 96 | * 97 | * @param modules - Module or None or All to trace 98 | * VL53L1_TRACE_MODULE_NONE 99 | * VL53L1_TRACE_MODULE_API 100 | * VL53L1_TRACE_MODULE_CORE 101 | * VL53L1_TRACE_MODULE_TUNING 102 | * VL53L1_TRACE_MODULE_CHARACTERISATION 103 | * VL53L1_TRACE_MODULE_PLATFORM 104 | * VL53L1_TRACE_MODULE_ALL 105 | * 106 | * @param level - trace level 107 | * VL53L1_TRACE_LEVEL_NONE 108 | * VL53L1_TRACE_LEVEL_ERRORS 109 | * VL53L1_TRACE_LEVEL_WARNING 110 | * VL53L1_TRACE_LEVEL_INFO 111 | * VL53L1_TRACE_LEVEL_DEBUG 112 | * VL53L1_TRACE_LEVEL_ALL 113 | * VL53L1_TRACE_LEVEL_IGNORE 114 | * 115 | * @param functions - function level to trace; 116 | * VL53L1_TRACE_FUNCTION_NONE 117 | * VL53L1_TRACE_FUNCTION_I2C 118 | * VL53L1_TRACE_FUNCTION_ALL 119 | * 120 | * @return status - always VL53L1_ERROR_NONE 121 | * 122 | */ 123 | 124 | #define VL53L1_TRACE_LEVEL_NONE 0x00000000 125 | #define VL53L1_TRACE_LEVEL_ERRORS 0x00000001 126 | #define VL53L1_TRACE_LEVEL_WARNING 0x00000002 127 | #define VL53L1_TRACE_LEVEL_INFO 0x00000004 128 | #define VL53L1_TRACE_LEVEL_DEBUG 0x00000008 129 | #define VL53L1_TRACE_LEVEL_ALL 0x00000010 130 | #define VL53L1_TRACE_LEVEL_IGNORE 0x00000020 131 | 132 | #define VL53L1_TRACE_FUNCTION_NONE 0x00000000 133 | #define VL53L1_TRACE_FUNCTION_I2C 0x00000001 134 | #define VL53L1_TRACE_FUNCTION_ALL 0x7fffffff 135 | 136 | #define VL53L1_TRACE_MODULE_NONE 0x00000000 137 | #define VL53L1_TRACE_MODULE_API 0x00000001 138 | #define VL53L1_TRACE_MODULE_CORE 0x00000002 139 | #define VL53L1_TRACE_MODULE_PROTECTED 0x00000004 140 | #define VL53L1_TRACE_MODULE_HISTOGRAM 0x00000008 141 | #define VL53L1_TRACE_MODULE_REGISTERS 0x00000010 142 | #define VL53L1_TRACE_MODULE_PLATFORM 0x00000020 143 | #define VL53L1_TRACE_MODULE_NVM 0x00000040 144 | #define VL53L1_TRACE_MODULE_CALIBRATION_DATA 0x00000080 145 | #define VL53L1_TRACE_MODULE_NVM_DATA 0x00000100 146 | #define VL53L1_TRACE_MODULE_HISTOGRAM_DATA 0x00000200 147 | #define VL53L1_TRACE_MODULE_RANGE_RESULTS_DATA 0x00000400 148 | #define VL53L1_TRACE_MODULE_XTALK_DATA 0x00000800 149 | #define VL53L1_TRACE_MODULE_OFFSET_DATA 0x00001000 150 | #define VL53L1_TRACE_MODULE_DATA_INIT 0x00002000 151 | #define VL53L1_TRACE_MODULE_REF_SPAD_CHAR 0x00004000 152 | #define VL53L1_TRACE_MODULE_SPAD_RATE_MAP 0x00008000 153 | #ifdef PAL_EXTENDED 154 | #define VL53L1_TRACE_MODULE_SPAD 0x01000000 155 | #define VL53L1_TRACE_MODULE_FMT 0x02000000 156 | #define VL53L1_TRACE_MODULE_UTILS 0x04000000 157 | #define VL53L1_TRACE_MODULE_BENCH_FUNCS 0x08000000 158 | #endif 159 | #define VL53L1_TRACE_MODULE_CUSTOMER_API 0x40000000 160 | #define VL53L1_TRACE_MODULE_ALL 0x7fffffff 161 | 162 | 163 | extern uint32_t _trace_level; 164 | 165 | /* 166 | * NOTE: dynamically exported if we enable logging. 167 | * this way, Python interfaces can access this function, but we don't 168 | * need to include it in the .def files. 169 | */ 170 | EWOKPLUS_EXPORTS int8_t VL53L1_trace_config( 171 | char *filename, 172 | uint32_t modules, 173 | uint32_t level, 174 | uint32_t functions); 175 | 176 | /** 177 | * @brief Print trace module function. 178 | * 179 | * @param module - ?? 180 | * @param level - ?? 181 | * @param function - ?? 182 | * @param format - ?? 183 | * 184 | */ 185 | 186 | EWOKPLUS_EXPORTS void VL53L1_trace_print_module_function( 187 | uint32_t module, 188 | uint32_t level, 189 | uint32_t function, 190 | const char *format, ...); 191 | 192 | /** 193 | * @brief Get global _trace_functions parameter 194 | * 195 | * @return _trace_functions 196 | */ 197 | 198 | uint32_t VL53L1_get_trace_functions(void); 199 | 200 | /** 201 | * @brief Set global _trace_functions parameter 202 | * 203 | * @param[in] function : new function code 204 | */ 205 | 206 | void VL53L1_set_trace_functions(uint32_t function); 207 | 208 | 209 | /* 210 | * @brief Returns the current system tick count in [ms] 211 | * 212 | * @return time_ms : current time in [ms] 213 | * 214 | */ 215 | 216 | uint32_t VL53L1_clock(void); 217 | 218 | #define LOG_GET_TIME() \ 219 | ((int)VL53L1_clock()) 220 | 221 | #define _LOG_TRACE_PRINT(module, level, function, ...) \ 222 | VL53L1_trace_print_module_function(module, level, function, ##__VA_ARGS__); 223 | 224 | #define _LOG_FUNCTION_START(module, fmt, ...) \ 225 | VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld %s "fmt"\n", LOG_GET_TIME(), __FUNCTION__, ##__VA_ARGS__); 226 | 227 | #define _LOG_FUNCTION_END(module, status, ...)\ 228 | VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld %s %d\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__) 229 | 230 | #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...)\ 231 | VL53L1_trace_print_module_function(module, _trace_level, VL53L1_TRACE_FUNCTION_ALL, "%6ld %s %d "fmt"\n", LOG_GET_TIME(), __FUNCTION__, (int)status, ##__VA_ARGS__) 232 | 233 | #define _LOG_GET_TRACE_FUNCTIONS()\ 234 | VL53L1_get_trace_functions() 235 | 236 | #define _LOG_SET_TRACE_FUNCTIONS(functions)\ 237 | VL53L1_set_trace_functions(functions) 238 | 239 | #define _LOG_STRING_BUFFER(x) char x[VL53L1_MAX_STRING_LENGTH] 240 | 241 | #ifdef __cplusplus 242 | } 243 | #endif 244 | 245 | #else /* VL53L1_LOG_ENABLE - no logging */ 246 | 247 | #define _LOG_TRACE_PRINT(module, level, function, ...) 248 | #define _LOG_FUNCTION_START(module, fmt, ...) 249 | #define _LOG_FUNCTION_END(module, status, ...) 250 | #define _LOG_FUNCTION_END_FMT(module, status, fmt, ...) 251 | #define _LOG_GET_TRACE_FUNCTIONS() 0 252 | #define _LOG_SET_TRACE_FUNCTIONS(functions) 253 | #define _LOG_STRING_BUFFER(x) 254 | 255 | #endif /* VL53L1_LOG_ENABLE */ 256 | 257 | #endif /* _VL53L1_PLATFORM_LOG_H_ */ 258 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_error_strings.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_error_strings.c 65 | * @brief VL53L1 API functions for decoding error codes to a text string 66 | */ 67 | 68 | #include "vl53l1_error_codes.h" 69 | #include "vl53l1_error_strings.h" 70 | #include "vl53l1_platform_log.h" 71 | #include "vl53l1_ll_def.h" 72 | 73 | #define LOG_FUNCTION_START(fmt, ...) \ 74 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__) 75 | #define LOG_FUNCTION_END(status, ...) \ 76 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__) 77 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ 78 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, \ 79 | status, fmt, ##__VA_ARGS__) 80 | 81 | 82 | #ifndef VL53L1_DEBUG 83 | #define VL53L1_USE_EMPTY_STRING 84 | #endif 85 | 86 | VL53L1_Error VL53L1_get_pal_error_string( 87 | VL53L1_Error PalErrorCode, 88 | char *pPalErrorString) 89 | { 90 | VL53L1_Error Status = VL53L1_ERROR_NONE; 91 | 92 | #ifdef VL53L1_USE_EMPTY_STRING 93 | SUPPRESS_UNUSED_WARNING(PalErrorCode); 94 | #endif 95 | 96 | LOG_FUNCTION_START(""); 97 | 98 | #ifdef VL53L1_USE_EMPTY_STRING 99 | VL53L1_COPYSTRING(pPalErrorString, ""); 100 | #else 101 | 102 | switch (PalErrorCode) { 103 | case VL53L1_ERROR_NONE: 104 | VL53L1_COPYSTRING(pPalErrorString, 105 | VL53L1_STRING_ERROR_NONE); 106 | break; 107 | case VL53L1_ERROR_CALIBRATION_WARNING: 108 | VL53L1_COPYSTRING(pPalErrorString, 109 | VL53L1_STRING_ERROR_CALIBRATION_WARNING); 110 | break; 111 | case VL53L1_ERROR_MIN_CLIPPED: 112 | VL53L1_COPYSTRING(pPalErrorString, 113 | VL53L1_STRING_ERROR_MIN_CLIPPED); 114 | break; 115 | case VL53L1_ERROR_UNDEFINED: 116 | VL53L1_COPYSTRING(pPalErrorString, 117 | VL53L1_STRING_ERROR_UNDEFINED); 118 | break; 119 | case VL53L1_ERROR_INVALID_PARAMS: 120 | VL53L1_COPYSTRING(pPalErrorString, 121 | VL53L1_STRING_ERROR_INVALID_PARAMS); 122 | break; 123 | case VL53L1_ERROR_NOT_SUPPORTED: 124 | VL53L1_COPYSTRING(pPalErrorString, 125 | VL53L1_STRING_ERROR_NOT_SUPPORTED); 126 | break; 127 | case VL53L1_ERROR_RANGE_ERROR: 128 | VL53L1_COPYSTRING(pPalErrorString, 129 | VL53L1_STRING_ERROR_RANGE_ERROR); 130 | break; 131 | case VL53L1_ERROR_TIME_OUT: 132 | VL53L1_COPYSTRING(pPalErrorString, 133 | VL53L1_STRING_ERROR_TIME_OUT); 134 | break; 135 | case VL53L1_ERROR_MODE_NOT_SUPPORTED: 136 | VL53L1_COPYSTRING(pPalErrorString, 137 | VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED); 138 | break; 139 | case VL53L1_ERROR_BUFFER_TOO_SMALL: 140 | VL53L1_COPYSTRING(pPalErrorString, 141 | VL53L1_STRING_ERROR_BUFFER_TOO_SMALL); 142 | break; 143 | case VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL: 144 | VL53L1_COPYSTRING(pPalErrorString, 145 | VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL); 146 | break; 147 | case VL53L1_ERROR_GPIO_NOT_EXISTING: 148 | VL53L1_COPYSTRING(pPalErrorString, 149 | VL53L1_STRING_ERROR_GPIO_NOT_EXISTING); 150 | break; 151 | case VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED: 152 | VL53L1_COPYSTRING(pPalErrorString, 153 | VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED); 154 | break; 155 | case VL53L1_ERROR_CONTROL_INTERFACE: 156 | VL53L1_COPYSTRING(pPalErrorString, 157 | VL53L1_STRING_ERROR_CONTROL_INTERFACE); 158 | break; 159 | case VL53L1_ERROR_INVALID_COMMAND: 160 | VL53L1_COPYSTRING(pPalErrorString, 161 | VL53L1_STRING_ERROR_INVALID_COMMAND); 162 | break; 163 | case VL53L1_ERROR_DIVISION_BY_ZERO: 164 | VL53L1_COPYSTRING(pPalErrorString, 165 | VL53L1_STRING_ERROR_DIVISION_BY_ZERO); 166 | break; 167 | case VL53L1_ERROR_REF_SPAD_INIT: 168 | VL53L1_COPYSTRING(pPalErrorString, 169 | VL53L1_STRING_ERROR_REF_SPAD_INIT); 170 | break; 171 | case VL53L1_ERROR_GPH_SYNC_CHECK_FAIL: 172 | VL53L1_COPYSTRING(pPalErrorString, 173 | VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL); 174 | break; 175 | case VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL: 176 | VL53L1_COPYSTRING(pPalErrorString, 177 | VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL); 178 | break; 179 | case VL53L1_ERROR_GPH_ID_CHECK_FAIL: 180 | VL53L1_COPYSTRING(pPalErrorString, 181 | VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL); 182 | break; 183 | case VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL: 184 | VL53L1_COPYSTRING(pPalErrorString, 185 | VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL); 186 | break; 187 | case VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL: 188 | VL53L1_COPYSTRING(pPalErrorString, 189 | VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL); 190 | break; 191 | 192 | case VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL: 193 | VL53L1_COPYSTRING(pPalErrorString, 194 | VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL); 195 | break; 196 | case VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL: 197 | VL53L1_COPYSTRING(pPalErrorString, 198 | VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL); 199 | break; 200 | 201 | case VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL: 202 | VL53L1_COPYSTRING(pPalErrorString, 203 | VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL); 204 | break; 205 | case VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL: 206 | VL53L1_COPYSTRING(pPalErrorString, 207 | VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL); 208 | break; 209 | case VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL: 210 | VL53L1_COPYSTRING(pPalErrorString, 211 | VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL); 212 | break; 213 | 214 | case VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES: 215 | VL53L1_COPYSTRING(pPalErrorString, 216 | VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES); 217 | break; 218 | case VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH: 219 | VL53L1_COPYSTRING(pPalErrorString, 220 | VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH); 221 | break; 222 | case VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH: 223 | VL53L1_COPYSTRING(pPalErrorString, 224 | VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH); 225 | break; 226 | case VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW: 227 | VL53L1_COPYSTRING(pPalErrorString, 228 | VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW); 229 | break; 230 | 231 | case VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES: 232 | VL53L1_COPYSTRING(pPalErrorString, 233 | VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES); 234 | break; 235 | case VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH: 236 | VL53L1_COPYSTRING(pPalErrorString, 237 | VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH); 238 | break; 239 | case VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH: 240 | VL53L1_COPYSTRING(pPalErrorString, 241 | VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH); 242 | break; 243 | 244 | case VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS: 245 | VL53L1_COPYSTRING(pPalErrorString, 246 | VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS); 247 | break; 248 | case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH: 249 | VL53L1_COPYSTRING(pPalErrorString, 250 | VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH); 251 | break; 252 | case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW: 253 | VL53L1_COPYSTRING(pPalErrorString, 254 | VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW); 255 | break; 256 | 257 | case VL53L1_WARNING_XTALK_MISSING_SAMPLES: 258 | VL53L1_COPYSTRING(pPalErrorString, 259 | VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES); 260 | break; 261 | case VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT: 262 | VL53L1_COPYSTRING(pPalErrorString, 263 | VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT); 264 | break; 265 | case VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT: 266 | VL53L1_COPYSTRING(pPalErrorString, 267 | VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT); 268 | break; 269 | 270 | case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD: 271 | VL53L1_COPYSTRING(pPalErrorString, 272 | VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD); 273 | break; 274 | case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW: 275 | VL53L1_COPYSTRING(pPalErrorString, 276 | VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW); 277 | break; 278 | case VL53L1_ERROR_UNIT_TEST_FAIL: 279 | VL53L1_COPYSTRING(pPalErrorString, 280 | VL53L1_STRING_ERROR_UNIT_TEST_FAIL); 281 | break; 282 | case VL53L1_ERROR_FILE_READ_FAIL: 283 | VL53L1_COPYSTRING(pPalErrorString, 284 | VL53L1_STRING_ERROR_FILE_READ_FAIL); 285 | break; 286 | case VL53L1_ERROR_FILE_WRITE_FAIL: 287 | VL53L1_COPYSTRING(pPalErrorString, 288 | VL53L1_STRING_ERROR_FILE_WRITE_FAIL); 289 | break; 290 | case VL53L1_ERROR_NOT_IMPLEMENTED: 291 | VL53L1_COPYSTRING(pPalErrorString, 292 | VL53L1_STRING_ERROR_NOT_IMPLEMENTED); 293 | break; 294 | default: 295 | VL53L1_COPYSTRING(pPalErrorString, 296 | VL53L1_STRING_UNKNOW_ERROR_CODE); 297 | } 298 | 299 | #endif 300 | 301 | LOG_FUNCTION_END(Status); 302 | 303 | return Status; 304 | } 305 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_error_codes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_error_codes.h 65 | * 66 | * @brief Error Code definitions for VL53L1 API. 67 | * 68 | */ 69 | 70 | #ifndef _VL53L1_ERROR_CODES_H_ 71 | #define _VL53L1_ERROR_CODES_H_ 72 | 73 | #include "vl53l1_types.h" 74 | 75 | #ifdef __cplusplus 76 | extern "C" { 77 | #endif 78 | 79 | 80 | /**************************************** 81 | * PRIVATE define do not edit 82 | ****************************************/ 83 | 84 | /** @defgroup VL53L1_define_Error_group Error and Warning code returned by API 85 | * The following DEFINE are used to identify the PAL ERROR 86 | * @{ 87 | */ 88 | 89 | typedef int8_t VL53L1_Error; 90 | 91 | #define VL53L1_ERROR_NONE ((VL53L1_Error) 0) 92 | #define VL53L1_ERROR_CALIBRATION_WARNING ((VL53L1_Error) - 1) 93 | /*!< Warning invalid calibration data may be in used 94 | \a VL53L1_InitData() 95 | \a VL53L1_GetOffsetCalibrationData 96 | \a VL53L1_SetOffsetCalibrationData */ 97 | #define VL53L1_ERROR_MIN_CLIPPED ((VL53L1_Error) - 2) 98 | /*!< Warning parameter passed was clipped to min before to be applied */ 99 | 100 | #define VL53L1_ERROR_UNDEFINED ((VL53L1_Error) - 3) 101 | /*!< Unqualified error */ 102 | #define VL53L1_ERROR_INVALID_PARAMS ((VL53L1_Error) - 4) 103 | /*!< Parameter passed is invalid or out of range */ 104 | #define VL53L1_ERROR_NOT_SUPPORTED ((VL53L1_Error) - 5) 105 | /*!< Function is not supported in current mode or configuration */ 106 | #define VL53L1_ERROR_RANGE_ERROR ((VL53L1_Error) - 6) 107 | /*!< Device report a ranging error interrupt status */ 108 | #define VL53L1_ERROR_TIME_OUT ((VL53L1_Error) - 7) 109 | /*!< Aborted due to time out */ 110 | #define VL53L1_ERROR_MODE_NOT_SUPPORTED ((VL53L1_Error) - 8) 111 | /*!< Asked mode is not supported by the device */ 112 | #define VL53L1_ERROR_BUFFER_TOO_SMALL ((VL53L1_Error) - 9) 113 | /*!< ... */ 114 | #define VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL ((VL53L1_Error) - 10) 115 | /*!< Supplied buffer is larger than I2C supports */ 116 | #define VL53L1_ERROR_GPIO_NOT_EXISTING ((VL53L1_Error) - 11) 117 | /*!< User tried to setup a non-existing GPIO pin */ 118 | #define VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED ((VL53L1_Error) - 12) 119 | /*!< unsupported GPIO functionality */ 120 | #define VL53L1_ERROR_CONTROL_INTERFACE ((VL53L1_Error) - 13) 121 | /*!< error reported from IO functions */ 122 | #define VL53L1_ERROR_INVALID_COMMAND ((VL53L1_Error) - 14) 123 | /*!< The command is not allowed in the current device state 124 | * (power down) */ 125 | #define VL53L1_ERROR_DIVISION_BY_ZERO ((VL53L1_Error) - 15) 126 | /*!< In the function a division by zero occurs */ 127 | #define VL53L1_ERROR_REF_SPAD_INIT ((VL53L1_Error) - 16) 128 | /*!< Error during reference SPAD initialization */ 129 | #define VL53L1_ERROR_GPH_SYNC_CHECK_FAIL ((VL53L1_Error) - 17) 130 | /*!< GPH sync interrupt check fail - API out of sync with device*/ 131 | #define VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 18) 132 | /*!< Stream count check fail - API out of sync with device */ 133 | #define VL53L1_ERROR_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 19) 134 | /*!< GPH ID check fail - API out of sync with device */ 135 | #define VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL ((VL53L1_Error) - 20) 136 | /*!< Zone dynamic config stream count check failed - API out of sync */ 137 | #define VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL ((VL53L1_Error) - 21) 138 | /*!< Zone dynamic config GPH ID check failed - API out of sync */ 139 | 140 | #define VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL ((VL53L1_Error) - 22) 141 | /*!< Thrown when run_xtalk_extraction fn has 0 succesful samples 142 | * when using the full array to sample the xtalk. In this case there is 143 | * not enough information to generate new Xtalk parm info. The function 144 | * will exit and leave the current xtalk parameters unaltered */ 145 | #define VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL ((VL53L1_Error) - 23) 146 | /*!< Thrown when run_xtalk_extraction fn has found that the 147 | * avg sigma estimate of the full array xtalk sample is > than the 148 | * maximal limit allowed. In this case the xtalk sample is too noisy for 149 | * measurement. The function will exit and leave the current xtalk parameters 150 | * unaltered. */ 151 | 152 | 153 | #define VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 24) 154 | /*!< Thrown if there one of stages has no valid offset calibration 155 | * samples. A fatal error calibration not valid */ 156 | #define VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL ((VL53L1_Error) - 25) 157 | /*!< Thrown if there one of stages has zero effective SPADS 158 | * Traps the case when MM1 SPADs is zero. 159 | * A fatal error calibration not valid */ 160 | #define VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL ((VL53L1_Error) - 26) 161 | /*!< Thrown if then some of the zones have no valid samples 162 | * A fatal error calibration not valid */ 163 | 164 | #define VL53L1_ERROR_TUNING_PARM_KEY_MISMATCH ((VL53L1_Error) - 27) 165 | /*!< Thrown if the tuning file key table version does not match with 166 | * expected value. The driver expects the key table version to match 167 | * the compiled default version number in the define 168 | * #VL53L1_TUNINGPARM_KEY_TABLE_VERSION_DEFAULT 169 | * */ 170 | 171 | #define VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS ((VL53L1_Error) - 28) 172 | /*!< Thrown if there are less than 5 good SPADs are available. */ 173 | #define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH ((VL53L1_Error) - 29) 174 | /*!< Thrown if the final reference rate is greater than 175 | the upper reference rate limit - default is 40 Mcps. 176 | Implies a minimum Q3 (x10) SPAD (5) selected */ 177 | #define VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW ((VL53L1_Error) - 30) 178 | /*!< Thrown if the final reference rate is less than 179 | the lower reference rate limit - default is 10 Mcps. 180 | Implies maximum Q1 (x1) SPADs selected */ 181 | 182 | 183 | #define VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES ((VL53L1_Error) - 31) 184 | /*!< Thrown if there is less than the requested number of 185 | * valid samples. */ 186 | #define VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 32) 187 | /*!< Thrown if the offset calibration range sigma estimate is greater 188 | * than 8.0 mm. This is the recommended min value to yield a stable 189 | * offset measurement */ 190 | #define VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 33) 191 | /*!< Thrown when VL53L1_run_offset_calibration() peak rate is greater 192 | than that 50.0Mcps. This is the recommended max rate to avoid 193 | pile-up influencing the offset measurement */ 194 | #define VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW ((VL53L1_Error) - 34) 195 | /*!< Thrown when VL53L1_run_offset_calibration() when one of stages 196 | range has less that 5.0 effective SPADS. This is the recommended 197 | min value to yield a stable offset */ 198 | 199 | 200 | #define VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES ((VL53L1_Error) - 35) 201 | /*!< Thrown if one of more of the zones have less than 202 | the requested number of valid samples */ 203 | #define VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH ((VL53L1_Error) - 36) 204 | /*!< Thrown if one or more zones have sigma estimate value greater 205 | * than 8.0 mm. This is the recommended min value to yield a stable 206 | * offset measurement */ 207 | #define VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH ((VL53L1_Error) - 37) 208 | /*!< Thrown if one of more zones have peak rate higher than 209 | that 50.0Mcps. This is the recommended max rate to avoid 210 | pile-up influencing the offset measurement */ 211 | 212 | 213 | #define VL53L1_WARNING_XTALK_MISSING_SAMPLES ((VL53L1_Error) - 38) 214 | /*!< Thrown to notify that some of the xtalk samples did not yield 215 | * valid ranging pulse data while attempting to measure 216 | * the xtalk signal in vl53l1_run_xtalk_extract(). This can signify any of 217 | * the zones are missing samples, for further debug information the 218 | * xtalk_results struct should be referred to. This warning is for 219 | * notification only, the xtalk pulse and shape have still been generated 220 | */ 221 | #define VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT ((VL53L1_Error) - 39) 222 | /*!< Thrown to notify that some of teh xtalk samples used for gradient 223 | * generation did not yield valid ranging pulse data while attempting to 224 | * measure the xtalk signal in vl53l1_run_xtalk_extract(). This can signify 225 | * that any one of the zones 0-3 yielded no successful samples. The 226 | * xtalk_results struct should be referred to for further debug info. 227 | * This warning is for notification only, the xtalk pulse and shape 228 | * have still been generated. 229 | */ 230 | #define VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT ((VL53L1_Error) - 40) 231 | /*!< Thrown to notify that some of the xtalk samples used for gradient 232 | * generation did not pass the sigma limit check while attempting to 233 | * measure the xtalk signal in vl53l1_run_xtalk_extract(). This can signify 234 | * that any one of the zones 0-3 yielded an avg sigma_mm value > the limit. 235 | * The xtalk_results struct should be referred to for further debug info. 236 | * This warning is for notification only, the xtalk pulse and shape 237 | * have still been generated. 238 | */ 239 | 240 | #define VL53L1_ERROR_NOT_IMPLEMENTED ((VL53L1_Error) - 41) 241 | /*!< Tells requested functionality has not been implemented yet or 242 | * not compatible with the device */ 243 | #define VL53L1_ERROR_PLATFORM_SPECIFIC_START ((VL53L1_Error) - 60) 244 | /*!< Tells the starting code for platform */ 245 | /** @} VL53L1_define_Error_group */ 246 | 247 | 248 | #ifdef __cplusplus 249 | } 250 | #endif 251 | 252 | 253 | #endif /* _VL53L1_ERROR_CODES_H_ */ 254 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_api_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_api_debug.h 65 | * 66 | * @brief EwokPlus25 low level API function definitions 67 | */ 68 | 69 | #ifndef _VL53L1_API_DEBUG_H_ 70 | #define _VL53L1_API_DEBUG_H_ 71 | 72 | #include "vl53l1_platform.h" 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | 79 | 80 | /* Start Patch_AdditionalDebugData_11823 */ 81 | 82 | /** 83 | * @brief Gets the current LL Driver configuration parameters and the last 84 | * set of histogram data for debug 85 | * 86 | * @param[in] Dev : Device Handle 87 | * @param[out] pdata : pointer to VL53L1_additional_data_t data structure 88 | * 89 | * @return VL53L1_ERROR_NONE Success 90 | * @return "Other error code" See ::VL53L1_Error 91 | */ 92 | 93 | VL53L1_Error VL53L1_get_additional_data( 94 | VL53L1_DEV Dev, 95 | VL53L1_additional_data_t *pdata); 96 | 97 | /* End Patch_AdditionalDebugData_11823 */ 98 | 99 | 100 | #ifdef VL53L1_LOG_ENABLE 101 | 102 | /** 103 | * @brief Implements an sprintf function for signed fixed point numbers 104 | * 105 | * @param[in] fp_value : input signed fixed point number 106 | * @param[in] frac_bits : number of fixed point fractional bits 107 | * @param[in] buf_size : size of supplied text buffer 108 | * @param[out] pbuffer : pointer to text buffer 109 | * 110 | */ 111 | 112 | void VL53L1_signed_fixed_point_sprintf( 113 | int32_t fp_value, 114 | uint8_t frac_bits, 115 | uint16_t buf_size, 116 | char *pbuffer); 117 | 118 | 119 | /** 120 | * @brief Convenience function to print out VL53L1_static_nvm_managed_t for debug 121 | * 122 | * @param[in] pdata : pointer to VL53L1_static_nvm_managed_t 123 | * @param[in] pprefix : pointer to name prefix string 124 | * @param[in] trace_flags : logging module enable bit flags 125 | */ 126 | 127 | void VL53L1_print_static_nvm_managed( 128 | VL53L1_static_nvm_managed_t *pdata, 129 | char *pprefix, 130 | uint32_t trace_flags); 131 | 132 | 133 | /** 134 | * @brief Convenience function to print out VL53L1_customer_nvm_managed_t for debug 135 | * 136 | * @param[in] pdata : pointer to VL53L1_customer_nvm_managed_t 137 | * @param[in] pprefix : pointer to name prefix string 138 | * @param[in] trace_flags : logging module enable bit flags 139 | */ 140 | 141 | void VL53L1_print_customer_nvm_managed( 142 | VL53L1_customer_nvm_managed_t *pdata, 143 | char *pprefix, 144 | uint32_t trace_flags); 145 | 146 | 147 | /** 148 | * @brief Convenience function to print out VL53L1_nvm_copy_data_t for debug 149 | * 150 | * @param[in] pdata : pointer to VL53L1_nvm_copy_data_t 151 | * @param[in] pprefix : pointer to name prefix string 152 | * @param[in] trace_flags : logging module enable bit flags 153 | */ 154 | 155 | void VL53L1_print_nvm_copy_data( 156 | VL53L1_nvm_copy_data_t *pdata, 157 | char *pprefix, 158 | uint32_t trace_flags); 159 | 160 | 161 | /** 162 | * @brief Convenience function to print out the contents of 163 | * the Range Results structure for debug 164 | * 165 | * @param[in] pdata : pointer to a VL53L1_range_results_t structure 166 | * @param[in] pprefix : pointer to name prefix string 167 | * @param[in] trace_flags : logging module enable bit flags 168 | */ 169 | 170 | void VL53L1_print_range_results( 171 | VL53L1_range_results_t *pdata, 172 | char *pprefix, 173 | uint32_t trace_flags); 174 | 175 | /** 176 | * @brief Convenience function to print out the contents of 177 | * the Range Data structure for debug 178 | * 179 | * @param[in] pdata : pointer to a VL53L1_range_data_t structure 180 | * @param[in] pprefix : pointer to name prefix string 181 | * @param[in] trace_flags : logging module enable bit flags 182 | */ 183 | 184 | void VL53L1_print_range_data( 185 | VL53L1_range_data_t *pdata, 186 | char *pprefix, 187 | uint32_t trace_flags); 188 | 189 | /** 190 | * @brief Convenience function to print out the contents of 191 | * the offset range results structure for debug 192 | * 193 | * @param[in] pdata : pointer to a VL53L1_offset_range_results_t structure 194 | * @param[in] pprefix : pointer to name prefix string 195 | * @param[in] trace_flags : logging module enable bit flags 196 | */ 197 | 198 | void VL53L1_print_offset_range_results( 199 | VL53L1_offset_range_results_t *pdata, 200 | char *pprefix, 201 | uint32_t trace_flags); 202 | 203 | /** 204 | * @brief Convenience function to print out the contents of 205 | * the offset range data structure for debug 206 | * 207 | * @param[in] pdata : pointer to a VL53L1_offset_range_data_t structure 208 | * @param[in] pprefix : pointer to name prefix string 209 | * @param[in] trace_flags : logging module enable bit flags 210 | */ 211 | 212 | void VL53L1_print_offset_range_data( 213 | VL53L1_offset_range_data_t *pdata, 214 | char *pprefix, 215 | uint32_t trace_flags); 216 | 217 | 218 | /** 219 | * @brief Convenience function to print out the contents of 220 | * the peak rate map calibration data structure 221 | * 222 | * @param[in] pdata : pointer to a VL53L1_cal_peak_rate_map_t structure 223 | * @param[in] pprefix : pointer to name prefix string 224 | * @param[in] trace_flags : logging module enable bit flags 225 | */ 226 | 227 | void VL53L1_print_cal_peak_rate_map( 228 | VL53L1_cal_peak_rate_map_t *pdata, 229 | char *pprefix, 230 | uint32_t trace_flags); 231 | 232 | 233 | /** 234 | * @brief Convenience function to print out the contents of 235 | * the additional offset calibration data structure 236 | * 237 | * @param[in] pdata : pointer to a VL53L1_additional_offset_cal_data_t structure 238 | * @param[in] pprefix : pointer to name prefix string 239 | * @param[in] trace_flags : logging module enable bit flags 240 | */ 241 | 242 | void VL53L1_print_additional_offset_cal_data( 243 | VL53L1_additional_offset_cal_data_t *pdata, 244 | char *pprefix, 245 | uint32_t trace_flags); 246 | 247 | /** 248 | * @brief Convenience function to print out the contents of 249 | * the additional data structure 250 | * 251 | * @param[in] pdata : pointer to a VL53L1_additional_data_t structure 252 | * @param[in] pprefix : pointer to name prefix string 253 | * @param[in] trace_flags : logging module enable bit flags 254 | */ 255 | 256 | void VL53L1_print_additional_data( 257 | VL53L1_additional_data_t *pdata, 258 | char *pprefix, 259 | uint32_t trace_flags); 260 | 261 | 262 | /** 263 | * @brief Convenience function to print out the contents of 264 | * the LL driver gain calibration data structure 265 | * 266 | * @param[in] pdata : pointer to a VL53L1_gain_calibration_data_t structure 267 | * @param[in] pprefix : pointer to name prefix string 268 | * @param[in] trace_flags : logging module enable bit flags 269 | */ 270 | 271 | void VL53L1_print_gain_calibration_data( 272 | VL53L1_gain_calibration_data_t *pdata, 273 | char *pprefix, 274 | uint32_t trace_flags); 275 | 276 | 277 | /** 278 | * @brief Convenience function to print out the contents of 279 | * the xtalk configuration data for debug 280 | * 281 | * @param[in] pdata : pointer to a VL53L1_xtalk_config_t Structure 282 | * @param[in] pprefix : pointer to name prefix string 283 | * @param[in] trace_flags : logging module enable bit flags 284 | */ 285 | 286 | void VL53L1_print_xtalk_config( 287 | VL53L1_xtalk_config_t *pdata, 288 | char *pprefix, 289 | uint32_t trace_flags); 290 | 291 | /** 292 | * @brief Convenience function to print out the contents of 293 | * the Optical Centre structure for debug 294 | * 295 | * @param[in] pdata : pointer to a VL53L1_optical_centre_t structure 296 | * @param[in] pprefix : pointer to name prefix string 297 | * @param[in] trace_flags : logging module enable bit flags 298 | */ 299 | 300 | void VL53L1_print_optical_centre( 301 | VL53L1_optical_centre_t *pdata, 302 | char *pprefix, 303 | uint32_t trace_flags); 304 | 305 | 306 | /** 307 | * @brief Convenience function to print out the contents of 308 | * the User Zone (ROI) structure for debug 309 | * 310 | * @param[in] pdata : pointer to a VL53L1_user_zone_t structure 311 | * @param[in] pprefix : pointer to name prefix string 312 | * @param[in] trace_flags : logging module enable bit flags 313 | */ 314 | 315 | void VL53L1_print_user_zone( 316 | VL53L1_user_zone_t *pdata, 317 | char *pprefix, 318 | uint32_t trace_flags); 319 | 320 | /** 321 | * @brief Convenience function for printing out VL53L1_spad_rate_data_t 322 | * 323 | * @param[in] pspad_rates : pointer to VL53L1_spad_rate_data_t 324 | * @param[in] pprefix : pointer to name prefix string 325 | * @param[in] trace_flags : logging module enable bit flags 326 | */ 327 | 328 | void VL53L1_print_spad_rate_data( 329 | VL53L1_spad_rate_data_t *pspad_rates, 330 | char *pprefix, 331 | uint32_t trace_flags); 332 | 333 | 334 | /** 335 | * @brief Convenience function for printing out VL53L1_spad_rate_map_t 336 | * 337 | * @param[in] pspad_rates : pointer to VL53L1_spad_rate_map_t 338 | * @param[in] pprefix : pointer to name prefix string 339 | * @param[in] trace_flags : logging module enable bit flags 340 | */ 341 | 342 | void VL53L1_print_spad_rate_map( 343 | VL53L1_spad_rate_data_t *pspad_rates, 344 | char *pprefix, 345 | uint32_t trace_flags); 346 | 347 | 348 | #endif /* VL53L1_LOG_ENABLE */ 349 | 350 | #ifdef __cplusplus 351 | } 352 | #endif 353 | 354 | #endif /* _VL53L1_API_DEBUG_H_ */ 355 | -------------------------------------------------------------------------------- /vl53l1x/lib/core/vl53l1_core_support.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * 4 | * This file is part of VL53L1 Core and is dual licensed, 5 | * either 'STMicroelectronics 6 | * Proprietary license' 7 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 8 | * 9 | ******************************************************************************** 10 | * 11 | * 'STMicroelectronics Proprietary license' 12 | * 13 | ******************************************************************************** 14 | * 15 | * License terms: STMicroelectronics Proprietary in accordance with licensing 16 | * terms at www.st.com/sla0081 17 | * 18 | * STMicroelectronics confidential 19 | * Reproduction and Communication of this document is strictly prohibited unless 20 | * specifically authorized in writing by STMicroelectronics. 21 | * 22 | * 23 | ******************************************************************************** 24 | * 25 | * Alternatively, VL53L1 Core may be distributed under the terms of 26 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 27 | * provisions apply instead of the ones mentioned above : 28 | * 29 | ******************************************************************************** 30 | * 31 | * License terms: BSD 3-clause "New" or "Revised" License. 32 | * 33 | * Redistribution and use in source and binary forms, with or without 34 | * modification, are permitted provided that the following conditions are met: 35 | * 36 | * 1. Redistributions of source code must retain the above copyright notice, this 37 | * list of conditions and the following disclaimer. 38 | * 39 | * 2. Redistributions in binary form must reproduce the above copyright notice, 40 | * this list of conditions and the following disclaimer in the documentation 41 | * and/or other materials provided with the distribution. 42 | * 43 | * 3. Neither the name of the copyright holder nor the names of its contributors 44 | * may be used to endorse or promote products derived from this software 45 | * without specific prior written permission. 46 | * 47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 48 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 50 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 53 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 54 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 55 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 56 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 | * 58 | * 59 | ******************************************************************************** 60 | * 61 | */ 62 | 63 | /** 64 | * @file vl53l1_core_support.c 65 | * 66 | * @brief EwokPlus25 core function definition 67 | */ 68 | 69 | #include "vl53l1_ll_def.h" 70 | #include "vl53l1_ll_device.h" 71 | #include "vl53l1_platform_log.h" 72 | #include "vl53l1_core_support.h" 73 | #include "vl53l1_platform_user_data.h" 74 | #include "vl53l1_platform_user_defines.h" 75 | 76 | #ifdef VL53L1_LOGGING 77 | #include "vl53l1_debug.h" 78 | #include "vl53l1_register_debug.h" 79 | #endif 80 | 81 | #define LOG_FUNCTION_START(fmt, ...) \ 82 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__) 83 | #define LOG_FUNCTION_END(status, ...) \ 84 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__) 85 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ 86 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \ 87 | status, fmt, ##__VA_ARGS__) 88 | 89 | #define trace_print(level, ...) \ 90 | _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \ 91 | level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) 92 | 93 | 94 | uint32_t VL53L1_calc_pll_period_us( 95 | uint16_t fast_osc_frequency) 96 | { 97 | /* Calculates PLL frequency using NVM fast_osc_frequency 98 | * Fast osc frequency fixed point format = unsigned 4.12 99 | * 100 | * PLL period fixed point format = unsigned 0.24 101 | * Min input fast osc frequency = 1 MHz 102 | * PLL Multiplier = 64 (fixed) 103 | * Min PLL freq = 64.0MHz 104 | * -> max PLL period = 1/ 64 105 | * -> only the 18 LS bits are used 106 | * 107 | * 2^30 = (2^24) (1.0us) * 4096 (2^12) / 64 (PLL Multiplier) 108 | */ 109 | 110 | uint32_t pll_period_us = 0; 111 | 112 | LOG_FUNCTION_START(""); 113 | 114 | pll_period_us = (0x01 << 30) / fast_osc_frequency; 115 | 116 | #ifdef VL53L1_LOGGING 117 | trace_print(VL53L1_TRACE_LEVEL_DEBUG, 118 | " %-48s : %10u\n", "pll_period_us", 119 | pll_period_us); 120 | #endif 121 | 122 | LOG_FUNCTION_END(0); 123 | 124 | return pll_period_us; 125 | } 126 | 127 | 128 | #ifdef PAL_EXTENDED 129 | uint32_t VL53L1_duration_maths( 130 | uint32_t pll_period_us, 131 | uint32_t vcsel_parm_pclks, 132 | uint32_t window_vclks, 133 | uint32_t elapsed_mclks) 134 | { 135 | /* 136 | * Generates the ranging duration in us 137 | * 138 | * duration_us = elapsed_mclks * vcsel_perm_pclks * 139 | * window_vclks * pll_period_us 140 | * 141 | * returned value in [us] with no fraction bits 142 | */ 143 | 144 | uint64_t tmp_long_int = 0; 145 | uint32_t duration_us = 0; 146 | 147 | /* PLL period us = 0.24 18 LS bits used 148 | * window_vclks = 12.0 (2304 max) 149 | * output 30b (6.24) 150 | */ 151 | duration_us = window_vclks * pll_period_us; 152 | 153 | /* down shift by 12 154 | * output 18b (6.12) 155 | */ 156 | duration_us = duration_us >> 12; 157 | 158 | /* Save first part of the calc (#1) */ 159 | tmp_long_int = (uint64_t)duration_us; 160 | 161 | /* Multiply elapsed macro periods (22-bit) 162 | * by VCSEL parameter 6.4 (max 63.9999) 163 | * output 32b (28.4) 164 | */ 165 | duration_us = elapsed_mclks * vcsel_parm_pclks; 166 | 167 | /* down shift by 4 to remove fractional bits (#2) 168 | * output 28b (28.0) 169 | */ 170 | duration_us = duration_us >> 4; 171 | 172 | /* Multiply #1 18b (6.12) by #2 28b (28.0) 173 | * output 46b (34.12) 174 | */ 175 | tmp_long_int = tmp_long_int * (uint64_t)duration_us; 176 | 177 | /* Remove fractional part 178 | * output 34b (34.0) 179 | */ 180 | tmp_long_int = tmp_long_int >> 12; 181 | 182 | /* Clip to 32-bits */ 183 | if (tmp_long_int > 0xFFFFFFFF) { 184 | tmp_long_int = 0xFFFFFFFF; 185 | } 186 | 187 | duration_us = (uint32_t)tmp_long_int; 188 | 189 | return duration_us; 190 | } 191 | 192 | 193 | uint32_t VL53L1_isqrt(uint32_t num) 194 | { 195 | 196 | /* 197 | * Implements an integer square root 198 | * 199 | * From: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots 200 | */ 201 | 202 | uint32_t res = 0; 203 | uint32_t bit = 1 << 30; /* The second-to-top bit is set: 1 << 14 for 16-bits, 1 << 30 for 32 bits */ 204 | 205 | /* "bit" starts at the highest power of four <= the argument. */ 206 | while (bit > num) { 207 | bit >>= 2; 208 | } 209 | 210 | while (bit != 0) { 211 | if (num >= res + bit) { 212 | num -= res + bit; 213 | res = (res >> 1) + bit; 214 | } else { 215 | res >>= 1; 216 | } 217 | bit >>= 2; 218 | } 219 | 220 | return res; 221 | } 222 | 223 | 224 | uint16_t VL53L1_rate_maths( 225 | int32_t events, 226 | uint32_t time_us) 227 | { 228 | /* 229 | * Converts events into count rate 230 | * 231 | * Max events = 512 Mcps * 1sec 232 | * = 512,000,000 events 233 | * = 29b 234 | * 235 | * If events > 2^24 use 3-bit fractional bits is used internally 236 | * otherwise 7-bit fractional bits are used 237 | */ 238 | 239 | uint32_t tmp_int = 0; 240 | uint32_t frac_bits = 7; 241 | uint16_t rate_mcps = 0; /* 9.7 format */ 242 | 243 | /* 244 | * Clip input event range 245 | */ 246 | 247 | if (events > VL53L1_SPAD_TOTAL_COUNT_MAX) { 248 | tmp_int = VL53L1_SPAD_TOTAL_COUNT_MAX; 249 | } else if (events > 0) { 250 | tmp_int = (uint32_t)events; 251 | } 252 | 253 | /* 254 | * if events > VL53L1_SPAD_TOTAL_COUNT_RES_THRES use 3 rather 255 | * than 7 fractional bits internal to function 256 | */ 257 | 258 | if (events > VL53L1_SPAD_TOTAL_COUNT_RES_THRES) { 259 | frac_bits = 3; 260 | } else { 261 | frac_bits = 7; 262 | } 263 | 264 | /* 265 | * Create 3 or 7 fractional bits 266 | * output 32b (29.3 or 25.7) 267 | * Divide by range duration in [us] - no fractional bits 268 | */ 269 | if (time_us > 0) { 270 | tmp_int = ((tmp_int << frac_bits) + (time_us / 2)) / time_us; 271 | } 272 | 273 | /* 274 | * Re align if reduced resolution 275 | */ 276 | if (events > VL53L1_SPAD_TOTAL_COUNT_RES_THRES) { 277 | tmp_int = tmp_int << 4; 278 | } 279 | 280 | /* 281 | * Firmware internal count is 17.7 (24b) but it this 282 | * case clip to 16-bit value for reporting 283 | */ 284 | 285 | if (tmp_int > 0xFFFF) { 286 | tmp_int = 0xFFFF; 287 | } 288 | 289 | rate_mcps = (uint16_t)tmp_int; 290 | 291 | return rate_mcps; 292 | } 293 | 294 | uint16_t VL53L1_rate_per_spad_maths( 295 | uint32_t frac_bits, 296 | uint32_t peak_count_rate, 297 | uint16_t num_spads, 298 | uint32_t max_output_value) 299 | { 300 | 301 | uint32_t tmp_int = 0; 302 | 303 | /* rate_per_spad Format varies with prog frac_bits */ 304 | uint16_t rate_per_spad = 0; 305 | 306 | /* Calculate rate per spad with variable fractional bits */ 307 | 308 | /* Frac_bits should be programmed as final frac_bits - 7 as 309 | * the pk_rate contains an inherent 7 bit resolution 310 | */ 311 | 312 | if (num_spads > 0) { 313 | tmp_int = (peak_count_rate << 8) << frac_bits; 314 | tmp_int = (tmp_int + ((uint32_t)num_spads / 2)) / (uint32_t)num_spads; 315 | } else { 316 | tmp_int = ((peak_count_rate) << frac_bits); 317 | } 318 | 319 | /* Clip in case of overwrap - special code */ 320 | 321 | if (tmp_int > max_output_value) { 322 | tmp_int = max_output_value; 323 | } 324 | 325 | rate_per_spad = (uint16_t)tmp_int; 326 | 327 | return rate_per_spad; 328 | } 329 | 330 | int32_t VL53L1_range_maths( 331 | uint16_t fast_osc_frequency, 332 | uint16_t phase, 333 | uint16_t zero_distance_phase, 334 | uint8_t fractional_bits, 335 | int32_t gain_factor, 336 | int32_t range_offset_mm) 337 | { 338 | /* 339 | * Converts phase information into distance in [mm] 340 | */ 341 | 342 | uint32_t pll_period_us = 0; /* 0.24 format */ 343 | int64_t tmp_long_int = 0; 344 | int32_t range_mm = 0; 345 | 346 | /* Calculate PLL period in [ps] */ 347 | 348 | pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency); 349 | 350 | /* Raw range in [mm] 351 | * 352 | * calculate the phase difference between return and reference phases 353 | * 354 | * phases 16b (5.11) 355 | * output 17b including sign bit 356 | */ 357 | 358 | tmp_long_int = (int64_t)phase - (int64_t)zero_distance_phase; 359 | 360 | /* 361 | * multiply by the PLL period 362 | * 363 | * PLL period 24bit (0.24) but only 18 LS bits used 364 | * 365 | * Output 35b (0.35) (17b + 18b) 366 | */ 367 | 368 | tmp_long_int = tmp_long_int * (int64_t)pll_period_us; 369 | 370 | /* 371 | * Down shift by 9 - Output 26b (0.26) 372 | */ 373 | 374 | tmp_long_int = tmp_long_int / (0x01 << 9); 375 | 376 | /* 377 | * multiply by speed of light in air divided by 8 378 | * Factor of 8 includes 2 for the round trip and 4 scaling 379 | * 380 | * VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8 = 16b (16.2) 381 | * 382 | * Output 42b (18.24) (16b + 26b) 383 | */ 384 | 385 | tmp_long_int = tmp_long_int * VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8; 386 | 387 | /* 388 | * Down shift by 22 - Output 20b (18.2) 389 | */ 390 | 391 | tmp_long_int = tmp_long_int / (0x01 << 22); 392 | 393 | /* Add range offset */ 394 | range_mm = (int32_t)tmp_long_int + range_offset_mm; 395 | 396 | /* apply correction gain */ 397 | range_mm *= gain_factor; 398 | range_mm += 0x0400; 399 | range_mm /= 0x0800; 400 | 401 | /* Remove fractional bits */ 402 | if (fractional_bits == 0) 403 | range_mm = range_mm / (0x01 << 2); 404 | else if (fractional_bits == 1) 405 | range_mm = range_mm / (0x01 << 1); 406 | 407 | return range_mm; 408 | } 409 | #endif 410 | 411 | uint8_t VL53L1_decode_vcsel_period(uint8_t vcsel_period_reg) 412 | { 413 | /* 414 | * Converts the encoded VCSEL period register value into 415 | * the real period in PLL clocks 416 | */ 417 | 418 | uint8_t vcsel_period_pclks = 0; 419 | 420 | vcsel_period_pclks = (vcsel_period_reg + 1) << 1; 421 | 422 | return vcsel_period_pclks; 423 | } 424 | 425 | 426 | void VL53L1_decode_row_col( 427 | uint8_t spad_number, 428 | uint8_t *prow, 429 | uint8_t *pcol) 430 | { 431 | 432 | /** 433 | * Decodes the array (row,col) location from 434 | * the input SPAD number 435 | */ 436 | 437 | if (spad_number > 127) { 438 | *prow = 8 + ((255-spad_number) & 0x07); 439 | *pcol = (spad_number-128) >> 3; 440 | } else { 441 | *prow = spad_number & 0x07; 442 | *pcol = (127-spad_number) >> 3; 443 | } 444 | } 445 | 446 | --------------------------------------------------------------------------------