├── README.md └── vl53l1x-st-api ├── vl53l1_api.c ├── vl53l1_api.h ├── vl53l1_api_calibration.c ├── vl53l1_api_calibration.h ├── vl53l1_api_core.c ├── vl53l1_api_core.h ├── vl53l1_api_debug.c ├── vl53l1_api_debug.h ├── vl53l1_api_preset_modes.c ├── vl53l1_api_preset_modes.h ├── vl53l1_api_strings.c ├── vl53l1_api_strings.h ├── vl53l1_core.c ├── vl53l1_core.h ├── vl53l1_core_support.c ├── vl53l1_core_support.h ├── vl53l1_def.h ├── vl53l1_error_codes.h ├── vl53l1_error_exceptions.h ├── vl53l1_error_strings.c ├── vl53l1_error_strings.h ├── vl53l1_ll_def.h ├── vl53l1_ll_device.h ├── vl53l1_nvm_map.h ├── vl53l1_platform.cpp ├── vl53l1_platform.h ├── vl53l1_platform_log.h ├── vl53l1_platform_user_config.h ├── vl53l1_platform_user_data.h ├── vl53l1_platform_user_defines.h ├── vl53l1_preset_setup.h ├── vl53l1_register_funcs.c ├── vl53l1_register_funcs.h ├── vl53l1_register_map.h ├── vl53l1_register_settings.h ├── vl53l1_register_structs.h ├── vl53l1_silicon_core.c ├── vl53l1_silicon_core.h ├── vl53l1_tuning_parm_defaults.h ├── vl53l1_types.h ├── vl53l1_wait.c ├── vl53l1_wait.h └── vl53l1x-st-api.ino /README.md: -------------------------------------------------------------------------------- 1 | # ST VL53L1X API implementation for Arduino 2 | 3 | This is an implementation of ST's [STSW-IMG007][api] VL53L1X API for the Arduino 4 | platform, for use with the [Pololu VL53L1X time-of-flight distance sensor 5 | carrier][product]. It includes an example sketch adapted from ST's 6 | [X-CUBE-53L1A1][exp]. 7 | 8 | To load the sketch, open the file **vl53l1x-st-api.ino** in the vl53l1x-st-api 9 | directory. 10 | 11 | We have also released a more basic [VL53L1X library for Arduino][lib] that is 12 | intended to provide a quicker and easier way to get started using the VL53L1X 13 | with an Arduino-compatible controller, in contrast to using this API from ST. 14 | The library has a more streamlined interface, as well as smaller storage and 15 | memory footprints. However, it does not currently implement some of the more 16 | advanced functionality available in the API (for example, calibrating the 17 | sensor to work well under a cover glass or selecting a smaller region of 18 | interest (ROI)), and it has less robust error checking. 19 | 20 | [product]: https://www.pololu.com/product/3415 21 | [api]: http://www.st.com/content/st_com/en/products/embedded-software/proximity-sensors-software/stsw-img007.html 22 | [exp]: http://www.st.com/content/st_com/en/products/ecosystems/stm32-open-development-environment/stm32cube-expansion-software/stm32-ode-sense-sw/x-cube-53l1a1.html 23 | [lib]: https://github.com/pololu/vl53l1x-arduino 24 | -------------------------------------------------------------------------------- /vl53l1x-st-api/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-st-api/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-st-api/vl53l1_api_preset_modes.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_preset_modes.h 65 | * 66 | * @brief EwokPlus25 API core function definition 67 | */ 68 | 69 | #ifndef _VL53L1_API_PRESET_MODES_H_ 70 | #define _VL53L1_API_PRESET_MODES_H_ 71 | 72 | #include "vl53l1_ll_def.h" 73 | 74 | #ifdef __cplusplus 75 | extern "C" { 76 | #endif 77 | 78 | 79 | /** 80 | * @brief Initializes Ref SPAD Char Configuration Parameters 81 | * 82 | * @param[out] pdata : pointer to VL53L1_refspadchar_config_t data structure 83 | * 84 | * @return VL53L1_ERROR_NONE Success 85 | * @return "Other error code" See ::VL53L1_Error 86 | */ 87 | 88 | #ifndef VL53L1_NOCALIB 89 | VL53L1_Error VL53L1_init_refspadchar_config_struct( 90 | VL53L1_refspadchar_config_t *pdata); 91 | #endif 92 | 93 | 94 | /** 95 | * @brief Initializes SPAD Self Check (SSC) Configuration Parameters 96 | * 97 | * @param[out] pdata : pointer to VL53L1_ssc_config_t data structure 98 | * 99 | * @return VL53L1_ERROR_NONE Success 100 | * @return "Other error code" See ::VL53L1_Error 101 | */ 102 | 103 | VL53L1_Error VL53L1_init_ssc_config_struct( 104 | VL53L1_ssc_config_t *pdata); 105 | 106 | /** 107 | * @brief Initializes Xtalk Configuration Parameters 108 | * 109 | * @param[in] pnvm : pointer to VL53L1_customer_nvm_managed_t data structure 110 | * @param[out] pdata : pointer to VL53L1_xtalk_config_t data structure 111 | * 112 | * @return VL53L1_ERROR_NONE Success 113 | * @return "Other error code" See ::VL53L1_Error 114 | */ 115 | 116 | VL53L1_Error VL53L1_init_xtalk_config_struct( 117 | VL53L1_customer_nvm_managed_t *pnvm, 118 | VL53L1_xtalk_config_t *pdata); 119 | 120 | /** 121 | * @brief Initializes Offset Calibration Configuration Parameters 122 | * 123 | * @param[out] pdata : pointer to VL53L1_offsetcal_config_t data structure 124 | * 125 | * @return VL53L1_ERROR_NONE Success 126 | * @return "Other error code" See ::VL53L1_Error 127 | */ 128 | 129 | #ifndef VL53L1_NOCALIB 130 | VL53L1_Error VL53L1_init_offset_cal_config_struct( 131 | VL53L1_offsetcal_config_t *pdata); 132 | #endif 133 | 134 | 135 | /** 136 | * @brief Initializes Tuning Parameter Storage Values 137 | * 138 | * @param[out] pdata : pointer to VL53L1_tuning_parm_storage_t data structure 139 | * 140 | * @return VL53L1_ERROR_NONE Success 141 | * @return "Other error code" See ::VL53L1_Error 142 | */ 143 | 144 | VL53L1_Error VL53L1_init_tuning_parm_storage_struct( 145 | VL53L1_tuning_parm_storage_t *pdata); 146 | 147 | /** 148 | * @brief Initializes static and dynamic configuration settings for 149 | * preset mode VL53L1_DEVICEPRESETMODE_STANDARD_RANGING 150 | * 151 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 152 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 153 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 154 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 155 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 156 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 157 | * 158 | * @return VL53L1_ERROR_NONE Success 159 | * @return "Other error code" See ::VL53L1_Error 160 | */ 161 | 162 | VL53L1_Error VL53L1_preset_mode_standard_ranging( 163 | VL53L1_static_config_t *pstatic, 164 | VL53L1_general_config_t *pgeneral, 165 | VL53L1_timing_config_t *ptiming, 166 | VL53L1_dynamic_config_t *pdynamic, 167 | VL53L1_system_control_t *psystem, 168 | VL53L1_tuning_parm_storage_t *ptuning_parms); 169 | 170 | /** 171 | * @brief Initializes static and dynamic configuration settings for 172 | * preset mode VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE 173 | * 174 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 175 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 176 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 177 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 178 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 179 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 180 | * 181 | * @return VL53L1_ERROR_NONE Success 182 | * @return "Other error code" See ::VL53L1_Error 183 | */ 184 | 185 | VL53L1_Error VL53L1_preset_mode_standard_ranging_short_range( 186 | VL53L1_static_config_t *pstatic, 187 | VL53L1_general_config_t *pgeneral, 188 | VL53L1_timing_config_t *ptiming, 189 | VL53L1_dynamic_config_t *pdynamic, 190 | VL53L1_system_control_t *psystem, 191 | VL53L1_tuning_parm_storage_t *ptuning_parms); 192 | 193 | 194 | /** 195 | * @brief Initializes static and dynamic configuration settings for 196 | * preset mode VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE 197 | * 198 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 199 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 200 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 201 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 202 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 203 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 204 | * 205 | * @return VL53L1_ERROR_NONE Success 206 | * @return "Other error code" See ::VL53L1_Error 207 | */ 208 | 209 | VL53L1_Error VL53L1_preset_mode_standard_ranging_long_range( 210 | VL53L1_static_config_t *pstatic, 211 | VL53L1_general_config_t *pgeneral, 212 | VL53L1_timing_config_t *ptiming, 213 | VL53L1_dynamic_config_t *pdynamic, 214 | VL53L1_system_control_t *psystem, 215 | VL53L1_tuning_parm_storage_t *ptuning_parms); 216 | 217 | /** 218 | * @brief Initializes static and dynamic configuration settings for 219 | * preset mode VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL 220 | * 221 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 222 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 223 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 224 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 225 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 226 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 227 | * 228 | * @return VL53L1_ERROR_NONE Success 229 | * @return "Other error code" See ::VL53L1_Error 230 | */ 231 | 232 | #ifndef VL53L1_NOCALIB 233 | VL53L1_Error VL53L1_preset_mode_standard_ranging_mm1_cal( 234 | VL53L1_static_config_t *pstatic, 235 | VL53L1_general_config_t *pgeneral, 236 | VL53L1_timing_config_t *ptiming, 237 | VL53L1_dynamic_config_t *pdynamic, 238 | VL53L1_system_control_t *psystem, 239 | VL53L1_tuning_parm_storage_t *ptuning_parms); 240 | #endif 241 | 242 | 243 | /** 244 | * @brief Initializes static and dynamic configuration settings for 245 | * preset mode VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL 246 | * 247 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 248 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 249 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 250 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 251 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 252 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 253 | * 254 | * @return VL53L1_ERROR_NONE Success 255 | * @return "Other error code" See ::VL53L1_Error 256 | */ 257 | 258 | #ifndef VL53L1_NOCALIB 259 | VL53L1_Error VL53L1_preset_mode_standard_ranging_mm2_cal( 260 | VL53L1_static_config_t *pstatic, 261 | VL53L1_general_config_t *pgeneral, 262 | VL53L1_timing_config_t *ptiming, 263 | VL53L1_dynamic_config_t *pdynamic, 264 | VL53L1_system_control_t *psystem, 265 | VL53L1_tuning_parm_storage_t *ptuning_parms); 266 | #endif 267 | 268 | 269 | /** 270 | * @brief Initializes static and dynamic configuration settings for 271 | * preset mode VL53L1_DEVICEPRESETMODE_TIMED_RANGING 272 | * 273 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 274 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 275 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 276 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 277 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 278 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 279 | * 280 | * @return VL53L1_ERROR_NONE Success 281 | * @return "Other error code" See ::VL53L1_Error 282 | */ 283 | 284 | VL53L1_Error VL53L1_preset_mode_timed_ranging( 285 | 286 | VL53L1_static_config_t *pstatic, 287 | VL53L1_general_config_t *pgeneral, 288 | VL53L1_timing_config_t *ptiming, 289 | VL53L1_dynamic_config_t *pdynamic, 290 | VL53L1_system_control_t *psystem, 291 | VL53L1_tuning_parm_storage_t *ptuning_parms); 292 | 293 | /** 294 | * @brief Initializes static and dynamic configuration settings for 295 | * preset mode VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE 296 | * 297 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 298 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 299 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 300 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 301 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 302 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 303 | * 304 | * @return VL53L1_ERROR_NONE Success 305 | * @return "Other error code" See ::VL53L1_Error 306 | */ 307 | 308 | VL53L1_Error VL53L1_preset_mode_timed_ranging_short_range( 309 | 310 | VL53L1_static_config_t *pstatic, 311 | VL53L1_general_config_t *pgeneral, 312 | VL53L1_timing_config_t *ptiming, 313 | VL53L1_dynamic_config_t *pdynamic, 314 | VL53L1_system_control_t *psystem, 315 | VL53L1_tuning_parm_storage_t *ptuning_parms); 316 | 317 | /** 318 | * @brief Initializes static and dynamic configuration settings for 319 | * preset mode VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE 320 | * 321 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 322 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 323 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 324 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 325 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 326 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 327 | * 328 | * @return VL53L1_ERROR_NONE Success 329 | * @return "Other error code" See ::VL53L1_Error 330 | */ 331 | 332 | VL53L1_Error VL53L1_preset_mode_timed_ranging_long_range( 333 | 334 | VL53L1_static_config_t *pstatic, 335 | VL53L1_general_config_t *pgeneral, 336 | VL53L1_timing_config_t *ptiming, 337 | VL53L1_dynamic_config_t *pdynamic, 338 | VL53L1_system_control_t *psystem, 339 | VL53L1_tuning_parm_storage_t *ptuning_parms); 340 | 341 | /** 342 | * @brief Initializes static and dynamic configuration settings for 343 | * preset mode VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_MEDIUM_RANGE 344 | * 345 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 346 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 347 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 348 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 349 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 350 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 351 | * @param[out] plpadata : pointer to VL53L1_low_power_auto_data_t data structure 352 | * 353 | * @return VL53L1_ERROR_NONE Success 354 | * @return "Other error code" See ::VL53L1_Error 355 | */ 356 | 357 | VL53L1_Error VL53L1_preset_mode_low_power_auto_ranging( 358 | 359 | VL53L1_static_config_t *pstatic, 360 | VL53L1_general_config_t *pgeneral, 361 | VL53L1_timing_config_t *ptiming, 362 | VL53L1_dynamic_config_t *pdynamic, 363 | VL53L1_system_control_t *psystem, 364 | VL53L1_tuning_parm_storage_t *ptuning_parms, 365 | VL53L1_low_power_auto_data_t *plpadata); 366 | 367 | /** 368 | * @brief Initializes static and dynamic configuration settings for 369 | * preset mode VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_SHORT_RANGE 370 | * 371 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 372 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 373 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 374 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 375 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 376 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 377 | * @param[out] plpadata : pointer to VL53L1_low_power_auto_data_t data structure 378 | * 379 | * @return VL53L1_ERROR_NONE Success 380 | * @return "Other error code" See ::VL53L1_Error 381 | */ 382 | 383 | VL53L1_Error VL53L1_preset_mode_low_power_auto_short_ranging( 384 | 385 | VL53L1_static_config_t *pstatic, 386 | VL53L1_general_config_t *pgeneral, 387 | VL53L1_timing_config_t *ptiming, 388 | VL53L1_dynamic_config_t *pdynamic, 389 | VL53L1_system_control_t *psystem, 390 | VL53L1_tuning_parm_storage_t *ptuning_parms, 391 | VL53L1_low_power_auto_data_t *plpadata); 392 | 393 | /** 394 | * @brief Initializes static and dynamic configuration settings for 395 | * preset mode VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_LONG_RANGE 396 | * 397 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 398 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 399 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 400 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 401 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 402 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 403 | * @param[out] plpadata : pointer to VL53L1_low_power_auto_data_t data structure 404 | * 405 | * @return VL53L1_ERROR_NONE Success 406 | * @return "Other error code" See ::VL53L1_Error 407 | */ 408 | 409 | VL53L1_Error VL53L1_preset_mode_low_power_auto_long_ranging( 410 | 411 | VL53L1_static_config_t *pstatic, 412 | VL53L1_general_config_t *pgeneral, 413 | VL53L1_timing_config_t *ptiming, 414 | VL53L1_dynamic_config_t *pdynamic, 415 | VL53L1_system_control_t *psystem, 416 | VL53L1_tuning_parm_storage_t *ptuning_parms, 417 | VL53L1_low_power_auto_data_t *plpadata); 418 | 419 | 420 | /** 421 | * @brief Initializes static and dynamic configuration settings for 422 | * preset mode VL53L1_DEVICEPRESETMODE_OLT 423 | * 424 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 425 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 426 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 427 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 428 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 429 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 430 | * 431 | * @return VL53L1_ERROR_NONE Success 432 | * @return "Other error code" See ::VL53L1_Error 433 | */ 434 | 435 | VL53L1_Error VL53L1_preset_mode_olt( 436 | VL53L1_static_config_t *pstatic, 437 | VL53L1_general_config_t *pgeneral, 438 | VL53L1_timing_config_t *ptiming, 439 | VL53L1_dynamic_config_t *pdynamic, 440 | VL53L1_system_control_t *psystem, 441 | VL53L1_tuning_parm_storage_t *ptuning_parms); 442 | 443 | /** 444 | * @brief Initializes static and dynamic configuration settings for 445 | * preset mode VL53L1_DEVICEPRESETMODE_SINGLESHOT_RANGING 446 | * 447 | * @param[out] pstatic : pointer to VL53L1_static_config_t data structure 448 | * @param[out] pgeneral : pointer to VL53L1_general_config_t data structure 449 | * @param[out] ptiming : pointer to VL53L1_timing_config_t data structure 450 | * @param[out] pdynamic : pointer to VL53L1_dynamic_config_t data structure 451 | * @param[out] psystem : pointer to VL53L1_system_control_t data structure 452 | * @param[out] ptuning_parms : pointer to VL53L1_tuning_parms_storage_t structure 453 | * 454 | * @return VL53L1_ERROR_NONE Success 455 | * @return "Other error code" See ::VL53L1_Error 456 | */ 457 | 458 | VL53L1_Error VL53L1_preset_mode_singleshot_ranging( 459 | 460 | VL53L1_static_config_t *pstatic, 461 | VL53L1_general_config_t *pgeneral, 462 | VL53L1_timing_config_t *ptiming, 463 | VL53L1_dynamic_config_t *pdynamic, 464 | VL53L1_system_control_t *psystem, 465 | VL53L1_tuning_parm_storage_t *ptuning_parms); 466 | 467 | #ifdef __cplusplus 468 | } 469 | #endif 470 | 471 | #endif /* _VL53L1_API_CORE_H_ */ 472 | -------------------------------------------------------------------------------- /vl53l1x-st-api/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-st-api/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-st-api/vl53l1_core_support.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 3 | * Modified by Pololu Corporation, 2018 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_core_support.c 66 | * 67 | * @brief EwokPlus25 core function definition 68 | */ 69 | 70 | #include "vl53l1_ll_def.h" 71 | #include "vl53l1_ll_device.h" 72 | #include "vl53l1_platform_log.h" 73 | #include "vl53l1_core_support.h" 74 | #include "vl53l1_platform_user_data.h" 75 | #include "vl53l1_platform_user_defines.h" 76 | 77 | #ifdef VL53L1_LOGGING 78 | #include "vl53l1_debug.h" 79 | #include "vl53l1_register_debug.h" 80 | #endif 81 | 82 | #define LOG_FUNCTION_START(fmt, ...) \ 83 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__) 84 | #define LOG_FUNCTION_END(status, ...) \ 85 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__) 86 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ 87 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \ 88 | status, fmt, ##__VA_ARGS__) 89 | 90 | #define trace_print(level, ...) \ 91 | _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \ 92 | level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) 93 | 94 | 95 | uint32_t VL53L1_calc_pll_period_us( 96 | uint16_t fast_osc_frequency) 97 | { 98 | /* Calculates PLL frequency using NVM fast_osc_frequency 99 | * Fast osc frequency fixed point format = unsigned 4.12 100 | * 101 | * PLL period fixed point format = unsigned 0.24 102 | * Min input fast osc frequency = 1 MHz 103 | * PLL Multiplier = 64 (fixed) 104 | * Min PLL freq = 64.0MHz 105 | * -> max PLL period = 1/ 64 106 | * -> only the 18 LS bits are used 107 | * 108 | * 2^30 = (2^24) (1.0us) * 4096 (2^12) / 64 (PLL Multiplier) 109 | */ 110 | 111 | uint32_t pll_period_us = 0; 112 | 113 | LOG_FUNCTION_START(""); 114 | 115 | pll_period_us = ((uint32_t)0x01 << 30) / fast_osc_frequency; 116 | 117 | #ifdef VL53L1_LOGGING 118 | trace_print(VL53L1_TRACE_LEVEL_DEBUG, 119 | " %-48s : %10u\n", "pll_period_us", 120 | pll_period_us); 121 | #endif 122 | 123 | LOG_FUNCTION_END(0); 124 | 125 | return pll_period_us; 126 | } 127 | 128 | 129 | #ifdef PAL_EXTENDED 130 | uint32_t VL53L1_duration_maths( 131 | uint32_t pll_period_us, 132 | uint32_t vcsel_parm_pclks, 133 | uint32_t window_vclks, 134 | uint32_t elapsed_mclks) 135 | { 136 | /* 137 | * Generates the ranging duration in us 138 | * 139 | * duration_us = elapsed_mclks * vcsel_perm_pclks * 140 | * window_vclks * pll_period_us 141 | * 142 | * returned value in [us] with no fraction bits 143 | */ 144 | 145 | uint64_t tmp_long_int = 0; 146 | uint32_t duration_us = 0; 147 | 148 | /* PLL period us = 0.24 18 LS bits used 149 | * window_vclks = 12.0 (2304 max) 150 | * output 30b (6.24) 151 | */ 152 | duration_us = window_vclks * pll_period_us; 153 | 154 | /* down shift by 12 155 | * output 18b (6.12) 156 | */ 157 | duration_us = duration_us >> 12; 158 | 159 | /* Save first part of the calc (#1) */ 160 | tmp_long_int = (uint64_t)duration_us; 161 | 162 | /* Multiply elapsed macro periods (22-bit) 163 | * by VCSEL parameter 6.4 (max 63.9999) 164 | * output 32b (28.4) 165 | */ 166 | duration_us = elapsed_mclks * vcsel_parm_pclks; 167 | 168 | /* down shift by 4 to remove fractional bits (#2) 169 | * output 28b (28.0) 170 | */ 171 | duration_us = duration_us >> 4; 172 | 173 | /* Multiply #1 18b (6.12) by #2 28b (28.0) 174 | * output 46b (34.12) 175 | */ 176 | tmp_long_int = tmp_long_int * (uint64_t)duration_us; 177 | 178 | /* Remove fractional part 179 | * output 34b (34.0) 180 | */ 181 | tmp_long_int = tmp_long_int >> 12; 182 | 183 | /* Clip to 32-bits */ 184 | if (tmp_long_int > 0xFFFFFFFF) { 185 | tmp_long_int = 0xFFFFFFFF; 186 | } 187 | 188 | duration_us = (uint32_t)tmp_long_int; 189 | 190 | return duration_us; 191 | } 192 | 193 | 194 | uint32_t VL53L1_isqrt(uint32_t num) 195 | { 196 | 197 | /* 198 | * Implements an integer square root 199 | * 200 | * From: http://en.wikipedia.org/wiki/Methods_of_computing_square_roots 201 | */ 202 | 203 | uint32_t res = 0; 204 | uint32_t bit = 1 << 30; /* The second-to-top bit is set: 1 << 14 for 16-bits, 1 << 30 for 32 bits */ 205 | 206 | /* "bit" starts at the highest power of four <= the argument. */ 207 | while (bit > num) { 208 | bit >>= 2; 209 | } 210 | 211 | while (bit != 0) { 212 | if (num >= res + bit) { 213 | num -= res + bit; 214 | res = (res >> 1) + bit; 215 | } else { 216 | res >>= 1; 217 | } 218 | bit >>= 2; 219 | } 220 | 221 | return res; 222 | } 223 | 224 | 225 | uint16_t VL53L1_rate_maths( 226 | int32_t events, 227 | uint32_t time_us) 228 | { 229 | /* 230 | * Converts events into count rate 231 | * 232 | * Max events = 512 Mcps * 1sec 233 | * = 512,000,000 events 234 | * = 29b 235 | * 236 | * If events > 2^24 use 3-bit fractional bits is used internally 237 | * otherwise 7-bit fractional bits are used 238 | */ 239 | 240 | uint32_t tmp_int = 0; 241 | uint32_t frac_bits = 7; 242 | uint16_t rate_mcps = 0; /* 9.7 format */ 243 | 244 | /* 245 | * Clip input event range 246 | */ 247 | 248 | if (events > VL53L1_SPAD_TOTAL_COUNT_MAX) { 249 | tmp_int = VL53L1_SPAD_TOTAL_COUNT_MAX; 250 | } else if (events > 0) { 251 | tmp_int = (uint32_t)events; 252 | } 253 | 254 | /* 255 | * if events > VL53L1_SPAD_TOTAL_COUNT_RES_THRES use 3 rather 256 | * than 7 fractional bits internal to function 257 | */ 258 | 259 | if (events > VL53L1_SPAD_TOTAL_COUNT_RES_THRES) { 260 | frac_bits = 3; 261 | } else { 262 | frac_bits = 7; 263 | } 264 | 265 | /* 266 | * Create 3 or 7 fractional bits 267 | * output 32b (29.3 or 25.7) 268 | * Divide by range duration in [us] - no fractional bits 269 | */ 270 | if (time_us > 0) { 271 | tmp_int = ((tmp_int << frac_bits) + (time_us / 2)) / time_us; 272 | } 273 | 274 | /* 275 | * Re align if reduced resolution 276 | */ 277 | if (events > VL53L1_SPAD_TOTAL_COUNT_RES_THRES) { 278 | tmp_int = tmp_int << 4; 279 | } 280 | 281 | /* 282 | * Firmware internal count is 17.7 (24b) but it this 283 | * case clip to 16-bit value for reporting 284 | */ 285 | 286 | if (tmp_int > 0xFFFF) { 287 | tmp_int = 0xFFFF; 288 | } 289 | 290 | rate_mcps = (uint16_t)tmp_int; 291 | 292 | return rate_mcps; 293 | } 294 | 295 | uint16_t VL53L1_rate_per_spad_maths( 296 | uint32_t frac_bits, 297 | uint32_t peak_count_rate, 298 | uint16_t num_spads, 299 | uint32_t max_output_value) 300 | { 301 | 302 | uint32_t tmp_int = 0; 303 | 304 | /* rate_per_spad Format varies with prog frac_bits */ 305 | uint16_t rate_per_spad = 0; 306 | 307 | /* Calculate rate per spad with variable fractional bits */ 308 | 309 | /* Frac_bits should be programmed as final frac_bits - 7 as 310 | * the pk_rate contains an inherent 7 bit resolution 311 | */ 312 | 313 | if (num_spads > 0) { 314 | tmp_int = (peak_count_rate << 8) << frac_bits; 315 | tmp_int = (tmp_int + ((uint32_t)num_spads / 2)) / (uint32_t)num_spads; 316 | } else { 317 | tmp_int = ((peak_count_rate) << frac_bits); 318 | } 319 | 320 | /* Clip in case of overwrap - special code */ 321 | 322 | if (tmp_int > max_output_value) { 323 | tmp_int = max_output_value; 324 | } 325 | 326 | rate_per_spad = (uint16_t)tmp_int; 327 | 328 | return rate_per_spad; 329 | } 330 | 331 | int32_t VL53L1_range_maths( 332 | uint16_t fast_osc_frequency, 333 | uint16_t phase, 334 | uint16_t zero_distance_phase, 335 | uint8_t fractional_bits, 336 | int32_t gain_factor, 337 | int32_t range_offset_mm) 338 | { 339 | /* 340 | * Converts phase information into distance in [mm] 341 | */ 342 | 343 | uint32_t pll_period_us = 0; /* 0.24 format */ 344 | int64_t tmp_long_int = 0; 345 | int32_t range_mm = 0; 346 | 347 | /* Calculate PLL period in [ps] */ 348 | 349 | pll_period_us = VL53L1_calc_pll_period_us(fast_osc_frequency); 350 | 351 | /* Raw range in [mm] 352 | * 353 | * calculate the phase difference between return and reference phases 354 | * 355 | * phases 16b (5.11) 356 | * output 17b including sign bit 357 | */ 358 | 359 | tmp_long_int = (int64_t)phase - (int64_t)zero_distance_phase; 360 | 361 | /* 362 | * multiply by the PLL period 363 | * 364 | * PLL period 24bit (0.24) but only 18 LS bits used 365 | * 366 | * Output 35b (0.35) (17b + 18b) 367 | */ 368 | 369 | tmp_long_int = tmp_long_int * (int64_t)pll_period_us; 370 | 371 | /* 372 | * Down shift by 9 - Output 26b (0.26) 373 | */ 374 | 375 | tmp_long_int = tmp_long_int / (0x01 << 9); 376 | 377 | /* 378 | * multiply by speed of light in air divided by 8 379 | * Factor of 8 includes 2 for the round trip and 4 scaling 380 | * 381 | * VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8 = 16b (16.2) 382 | * 383 | * Output 42b (18.24) (16b + 26b) 384 | */ 385 | 386 | tmp_long_int = tmp_long_int * VL53L1_SPEED_OF_LIGHT_IN_AIR_DIV_8; 387 | 388 | /* 389 | * Down shift by 22 - Output 20b (18.2) 390 | */ 391 | 392 | tmp_long_int = tmp_long_int / (0x01 << 22); 393 | 394 | /* Add range offset */ 395 | range_mm = (int32_t)tmp_long_int + range_offset_mm; 396 | 397 | /* apply correction gain */ 398 | range_mm *= gain_factor; 399 | range_mm += 0x0400; 400 | range_mm /= 0x0800; 401 | 402 | /* Remove fractional bits */ 403 | if (fractional_bits == 0) 404 | range_mm = range_mm / (0x01 << 2); 405 | else if (fractional_bits == 1) 406 | range_mm = range_mm / (0x01 << 1); 407 | 408 | return range_mm; 409 | } 410 | #endif 411 | 412 | uint8_t VL53L1_decode_vcsel_period(uint8_t vcsel_period_reg) 413 | { 414 | /* 415 | * Converts the encoded VCSEL period register value into 416 | * the real period in PLL clocks 417 | */ 418 | 419 | uint8_t vcsel_period_pclks = 0; 420 | 421 | vcsel_period_pclks = (vcsel_period_reg + 1) << 1; 422 | 423 | return vcsel_period_pclks; 424 | } 425 | 426 | 427 | void VL53L1_decode_row_col( 428 | uint8_t spad_number, 429 | uint8_t *prow, 430 | uint8_t *pcol) 431 | { 432 | 433 | /** 434 | * Decodes the array (row,col) location from 435 | * the input SPAD number 436 | */ 437 | 438 | if (spad_number > 127) { 439 | *prow = 8 + ((255-spad_number) & 0x07); 440 | *pcol = (spad_number-128) >> 3; 441 | } else { 442 | *prow = spad_number & 0x07; 443 | *pcol = (127-spad_number) >> 3; 444 | } 445 | } 446 | 447 | -------------------------------------------------------------------------------- /vl53l1x-st-api/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-st-api/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-st-api/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-st-api/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-st-api/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-st-api/vl53l1_platform.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | This file is derived from vl53l1_platform.c in the STSW-IMG007 VL53L1X API. 4 | 5 | ******************************************************************************** 6 | * 7 | * Copyright (c) 2017, STMicroelectronics - All Rights Reserved 8 | * Copyright (c) 2018 Pololu Corporation 9 | * 10 | * This file is part of VL53L1 Core and is dual licensed, 11 | * either 'STMicroelectronics 12 | * Proprietary license' 13 | * or 'BSD 3-clause "New" or "Revised" License' , at your option. 14 | * 15 | ******************************************************************************** 16 | * 17 | * 'STMicroelectronics Proprietary license' 18 | * 19 | ******************************************************************************** 20 | * 21 | * License terms: STMicroelectronics Proprietary in accordance with licensing 22 | * terms at www.st.com/sla0081 23 | * 24 | * STMicroelectronics confidential 25 | * Reproduction and Communication of this document is strictly prohibited unless 26 | * specifically authorized in writing by STMicroelectronics. 27 | * 28 | * 29 | ******************************************************************************** 30 | * 31 | * Alternatively, VL53L1 Core may be distributed under the terms of 32 | * 'BSD 3-clause "New" or "Revised" License', in which case the following 33 | * provisions apply instead of the ones mentioned above : 34 | * 35 | ******************************************************************************** 36 | * 37 | * License terms: BSD 3-clause "New" or "Revised" License. 38 | * 39 | * Redistribution and use in source and binary forms, with or without 40 | * modification, are permitted provided that the following conditions are met: 41 | * 42 | * 1. Redistributions of source code must retain the above copyright notice, this 43 | * list of conditions and the following disclaimer. 44 | * 45 | * 2. Redistributions in binary form must reproduce the above copyright notice, 46 | * this list of conditions and the following disclaimer in the documentation 47 | * and/or other materials provided with the distribution. 48 | * 49 | * 3. Neither the name of the copyright holder nor the names of its contributors 50 | * may be used to endorse or promote products derived from this software 51 | * without specific prior written permission. 52 | * 53 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 54 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 56 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 59 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 60 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 61 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 63 | * 64 | * 65 | ******************************************************************************** 66 | * 67 | */ 68 | 69 | #include 70 | #include 71 | 72 | #include "vl53l1_platform.h" 73 | // #include "vl53l1_platform_log.h" 74 | #include "vl53l1_api.h" 75 | 76 | // #include "stm32xxx_hal.h" 77 | #include 78 | // #include 79 | // #include 80 | 81 | 82 | // #define I2C_TIME_OUT_BASE 10 83 | // #define I2C_TIME_OUT_BYTE 1 84 | 85 | // #ifdef VL53L1_LOG_ENABLE 86 | // #define trace_print(level, ...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_PLATFORM, level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) 87 | // #define trace_i2c(...) VL53L1_trace_print_module_function(VL53L1_TRACE_MODULE_NONE, VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__) 88 | // #endif 89 | 90 | // #ifndef HAL_I2C_MODULE_ENABLED 91 | // #warning "HAL I2C module must be enable " 92 | // #endif 93 | 94 | //extern I2C_HandleTypeDef hi2c1; 95 | //#define VL53L0X_pI2cHandle (&hi2c1) 96 | 97 | /* when not customized by application define dummy one */ 98 | // #ifndef VL53L1_GetI2cBus 99 | /** This macro can be overloaded by user to enforce i2c sharing in RTOS context 100 | */ 101 | // # define VL53L1_GetI2cBus(...) (void)0 102 | // #endif 103 | 104 | // #ifndef VL53L1_PutI2cBus 105 | /** This macro can be overloaded by user to enforce i2c sharing in RTOS context 106 | */ 107 | // # define VL53L1_PutI2cBus(...) (void)0 108 | // #endif 109 | 110 | // uint8_t _I2CBuffer[256]; 111 | 112 | // int _I2CWrite(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) { 113 | // int status = 0; 114 | // return status; 115 | // } 116 | 117 | // int _I2CRead(VL53L1_DEV Dev, uint8_t *pdata, uint32_t count) { 118 | // int status = 0; 119 | // return Status; 120 | // } 121 | 122 | VL53L1_Error VL53L1_WriteMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) 123 | { 124 | while (count > 0) 125 | { 126 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 127 | Wire.write((index >> 8) & 0xff); 128 | Wire.write(index & 0xff); 129 | 130 | uint8_t writing = 0; 131 | 132 | while (count > 0 && Wire.write(*pdata) != 0) 133 | { 134 | pdata++; 135 | writing++; 136 | count--; 137 | } 138 | 139 | if (writing == 0 || Wire.endTransmission() != 0) { return VL53L1_ERROR_CONTROL_INTERFACE; } 140 | index += writing; 141 | } 142 | 143 | return VL53L1_ERROR_NONE; 144 | } 145 | 146 | VL53L1_Error VL53L1_ReadMulti(VL53L1_DEV Dev, uint16_t index, uint8_t *pdata, uint32_t count) 147 | { 148 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 149 | Wire.write((index >> 8) & 0xff); 150 | Wire.write(index & 0xff); 151 | if (Wire.endTransmission() != 0) { return VL53L1_ERROR_CONTROL_INTERFACE; } 152 | 153 | while (count > 0) 154 | { 155 | uint8_t reading = Wire.requestFrom(Dev->I2cDevAddr >> 1, count); 156 | 157 | if (reading == 0) { return VL53L1_ERROR_CONTROL_INTERFACE; } 158 | count -= reading; 159 | 160 | while (reading-- > 0) 161 | { 162 | *pdata++ = Wire.read(); 163 | } 164 | } 165 | 166 | return VL53L1_ERROR_NONE; 167 | } 168 | 169 | VL53L1_Error VL53L1_WrByte(VL53L1_DEV Dev, uint16_t index, uint8_t data) 170 | { 171 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 172 | Wire.write((index >> 8) & 0xff); 173 | Wire.write(index & 0xff); 174 | Wire.write(data); 175 | return (Wire.endTransmission() == 0 ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE); 176 | } 177 | 178 | VL53L1_Error VL53L1_WrWord(VL53L1_DEV Dev, uint16_t index, uint16_t data) 179 | { 180 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 181 | Wire.write((index >> 8) & 0xff); 182 | Wire.write(index & 0xff); 183 | Wire.write((data >> 8) & 0xff); 184 | Wire.write(data & 0xff); 185 | return (Wire.endTransmission() == 0 ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE); 186 | } 187 | 188 | VL53L1_Error VL53L1_WrDWord(VL53L1_DEV Dev, uint16_t index, uint32_t data) 189 | { 190 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 191 | Wire.write((index >> 8) & 0xff); 192 | Wire.write(index & 0xff); 193 | Wire.write((data >> 24) & 0xff); 194 | Wire.write((data >> 16) & 0xff); 195 | Wire.write((data >> 8) & 0xff); 196 | Wire.write(data & 0xff); 197 | return (Wire.endTransmission() == 0 ? VL53L1_ERROR_NONE : VL53L1_ERROR_CONTROL_INTERFACE); 198 | } 199 | 200 | VL53L1_Error VL53L1_UpdateByte(VL53L1_DEV Dev, uint16_t index, uint8_t AndData, uint8_t OrData) 201 | { 202 | uint8_t data; 203 | VL53L1_Error status = VL53L1_RdByte(Dev, index, &data); 204 | if (status != VL53L1_ERROR_NONE) { return status; } 205 | data &= AndData; 206 | data |= OrData; 207 | return VL53L1_WrByte(Dev, index, data); 208 | } 209 | 210 | VL53L1_Error VL53L1_RdByte(VL53L1_DEV Dev, uint16_t index, uint8_t *data) 211 | { 212 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 213 | Wire.write((index >> 8) & 0xff); 214 | Wire.write(index & 0xff); 215 | if (Wire.endTransmission() != 0) { return VL53L1_ERROR_CONTROL_INTERFACE; } 216 | if (Wire.requestFrom(Dev->I2cDevAddr >> 1, 1) != 1) { return VL53L1_ERROR_CONTROL_INTERFACE; } 217 | *data = Wire.read(); 218 | return VL53L1_ERROR_NONE; 219 | } 220 | 221 | VL53L1_Error VL53L1_RdWord(VL53L1_DEV Dev, uint16_t index, uint16_t *data) 222 | { 223 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 224 | Wire.write((index >> 8) & 0xff); 225 | Wire.write(index & 0xff); 226 | if (Wire.endTransmission() != 0) { return VL53L1_ERROR_CONTROL_INTERFACE; } 227 | if (Wire.requestFrom(Dev->I2cDevAddr >> 1, 2) != 2) { return VL53L1_ERROR_CONTROL_INTERFACE; } 228 | *data = (uint16_t)Wire.read() << 8; 229 | *data |= Wire.read(); 230 | return VL53L1_ERROR_NONE; 231 | } 232 | 233 | VL53L1_Error VL53L1_RdDWord(VL53L1_DEV Dev, uint16_t index, uint32_t *data) 234 | { 235 | Wire.beginTransmission(Dev->I2cDevAddr >> 1); 236 | Wire.write((index >> 8) & 0xff); 237 | Wire.write(index & 0xff); 238 | if (Wire.endTransmission() != 0) { return VL53L1_ERROR_CONTROL_INTERFACE; } 239 | if (Wire.requestFrom(Dev->I2cDevAddr >> 1, 4) != 4) { return VL53L1_ERROR_CONTROL_INTERFACE; } 240 | *data = (uint32_t)Wire.read() << 24; 241 | *data |= (uint32_t)Wire.read() << 16; 242 | *data |= (uint16_t)Wire.read() << 8; 243 | *data |= Wire.read(); 244 | return VL53L1_ERROR_NONE; 245 | } 246 | 247 | VL53L1_Error VL53L1_GetTickCount( 248 | uint32_t *ptick_count_ms) 249 | { 250 | *ptick_count_ms = millis(); 251 | return VL53L1_ERROR_NONE; 252 | } 253 | 254 | //#define trace_print(level, ...) \ 255 | // _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_PLATFORM, \ 256 | // level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) 257 | 258 | //#define trace_i2c(...) \ 259 | // _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_NONE, \ 260 | // VL53L1_TRACE_LEVEL_NONE, VL53L1_TRACE_FUNCTION_I2C, ##__VA_ARGS__) 261 | 262 | VL53L1_Error VL53L1_GetTimerFrequency(int32_t *ptimer_freq_hz) 263 | { 264 | return VL53L1_ERROR_NOT_IMPLEMENTED; 265 | } 266 | 267 | VL53L1_Error VL53L1_WaitMs(VL53L1_Dev_t *pdev, int32_t wait_ms) 268 | { 269 | delay(wait_ms); 270 | return VL53L1_ERROR_NONE; 271 | } 272 | 273 | VL53L1_Error VL53L1_WaitUs(VL53L1_Dev_t *pdev, int32_t wait_us) 274 | { 275 | delayMicroseconds(wait_us); 276 | return VL53L1_ERROR_NONE; 277 | } 278 | 279 | VL53L1_Error VL53L1_WaitValueMaskEx( 280 | VL53L1_Dev_t *pdev, 281 | uint32_t timeout_ms, 282 | uint16_t index, 283 | uint8_t value, 284 | uint8_t mask, 285 | uint32_t poll_delay_ms) 286 | { 287 | uint8_t data; 288 | VL53L1_Error status; 289 | 290 | while (timeout_ms > 0) 291 | { 292 | status = VL53L1_RdByte(pdev, index, &data); 293 | if (status != VL53L1_ERROR_NONE) { return status; } 294 | if ((data & mask) == value) { return VL53L1_ERROR_NONE; } 295 | delay(poll_delay_ms); 296 | timeout_ms -= min(poll_delay_ms, timeout_ms); 297 | } 298 | 299 | return VL53L1_ERROR_TIME_OUT; 300 | } 301 | 302 | 303 | 304 | 305 | -------------------------------------------------------------------------------- /vl53l1x-st-api/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-st-api/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-st-api/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-st-api/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-st-api/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-st-api/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 | -------------------------------------------------------------------------------- /vl53l1x-st-api/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-st-api/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-st-api/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-st-api/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-st-api/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-st-api/vl53l1_wait.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_wait.c 65 | * 66 | * @brief EwokPlus25 low level Driver wait function definition 67 | */ 68 | 69 | 70 | #include "vl53l1_ll_def.h" 71 | #include "vl53l1_ll_device.h" 72 | #include "vl53l1_platform.h" 73 | #include "vl53l1_core.h" 74 | #include "vl53l1_silicon_core.h" 75 | #include "vl53l1_wait.h" 76 | #include "vl53l1_register_settings.h" 77 | 78 | 79 | #define LOG_FUNCTION_START(fmt, ...) \ 80 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__) 81 | #define LOG_FUNCTION_END(status, ...) \ 82 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__) 83 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ 84 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \ 85 | fmt, ##__VA_ARGS__) 86 | 87 | 88 | VL53L1_Error VL53L1_wait_for_boot_completion( 89 | VL53L1_DEV Dev) 90 | { 91 | 92 | /* Waits for firmware boot to finish 93 | */ 94 | 95 | VL53L1_Error status = VL53L1_ERROR_NONE; 96 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 97 | 98 | uint8_t fw_ready = 0; 99 | 100 | LOG_FUNCTION_START(""); 101 | 102 | if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) { 103 | 104 | /* blocking version */ 105 | 106 | status = 107 | VL53L1_poll_for_boot_completion( 108 | Dev, 109 | VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS); 110 | 111 | } else { 112 | 113 | /* implement non blocking version below */ 114 | 115 | fw_ready = 0; 116 | while (fw_ready == 0x00 && status == VL53L1_ERROR_NONE) { 117 | status = VL53L1_is_boot_complete( 118 | Dev, 119 | &fw_ready); 120 | 121 | if (status == VL53L1_ERROR_NONE) { 122 | status = VL53L1_WaitMs( 123 | Dev, 124 | VL53L1_POLLING_DELAY_MS); 125 | } 126 | } 127 | } 128 | 129 | LOG_FUNCTION_END(status); 130 | 131 | return status; 132 | 133 | } 134 | 135 | 136 | VL53L1_Error VL53L1_wait_for_firmware_ready( 137 | VL53L1_DEV Dev) 138 | { 139 | 140 | /* If in timed mode or single shot then check firmware is ready 141 | * before sending handshake 142 | */ 143 | 144 | VL53L1_Error status = VL53L1_ERROR_NONE; 145 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 146 | 147 | uint8_t fw_ready = 0; 148 | uint8_t mode_start = 0; 149 | 150 | LOG_FUNCTION_START(""); 151 | 152 | /* Filter out tje measure mode part of the mode 153 | * start register 154 | */ 155 | mode_start = 156 | pdev->sys_ctrl.system__mode_start & 157 | VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK; 158 | 159 | /* 160 | * conditional wait for firmware ready 161 | * only waits for timed and single shot modes 162 | */ 163 | 164 | if ((mode_start == VL53L1_DEVICEMEASUREMENTMODE_TIMED) || 165 | (mode_start == VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT)) { 166 | 167 | if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) { 168 | 169 | /* blocking version */ 170 | 171 | status = 172 | VL53L1_poll_for_firmware_ready( 173 | Dev, 174 | VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS); 175 | 176 | } else { 177 | 178 | /* implement non blocking version below */ 179 | 180 | fw_ready = 0; 181 | while (fw_ready == 0x00 && status == VL53L1_ERROR_NONE) { 182 | status = VL53L1_is_firmware_ready( 183 | Dev, 184 | &fw_ready); 185 | 186 | if (status == VL53L1_ERROR_NONE) { 187 | status = VL53L1_WaitMs( 188 | Dev, 189 | VL53L1_POLLING_DELAY_MS); 190 | } 191 | } 192 | } 193 | } 194 | 195 | LOG_FUNCTION_END(status); 196 | 197 | return status; 198 | } 199 | 200 | 201 | VL53L1_Error VL53L1_wait_for_range_completion( 202 | VL53L1_DEV Dev) 203 | { 204 | 205 | /* Wrapper function for waiting for range completion 206 | */ 207 | 208 | VL53L1_Error status = VL53L1_ERROR_NONE; 209 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 210 | 211 | uint8_t data_ready = 0; 212 | 213 | LOG_FUNCTION_START(""); 214 | 215 | if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) { 216 | 217 | /* blocking version */ 218 | 219 | status = 220 | VL53L1_poll_for_range_completion( 221 | Dev, 222 | VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS); 223 | 224 | } else { 225 | 226 | /* implement non blocking version below */ 227 | 228 | data_ready = 0; 229 | while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) { 230 | status = VL53L1_is_new_data_ready( 231 | Dev, 232 | &data_ready); 233 | 234 | if (status == VL53L1_ERROR_NONE) { 235 | status = VL53L1_WaitMs( 236 | Dev, 237 | VL53L1_POLLING_DELAY_MS); 238 | } 239 | } 240 | } 241 | 242 | LOG_FUNCTION_END(status); 243 | 244 | return status; 245 | } 246 | 247 | 248 | VL53L1_Error VL53L1_wait_for_test_completion( 249 | VL53L1_DEV Dev) 250 | { 251 | 252 | /* Wrapper function for waiting for test mode completion 253 | */ 254 | 255 | VL53L1_Error status = VL53L1_ERROR_NONE; 256 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 257 | 258 | uint8_t data_ready = 0; 259 | 260 | LOG_FUNCTION_START(""); 261 | 262 | if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) { 263 | 264 | /* blocking version */ 265 | 266 | status = 267 | VL53L1_poll_for_range_completion( 268 | Dev, 269 | VL53L1_TEST_COMPLETION_POLLING_TIMEOUT_MS); 270 | 271 | } else { 272 | 273 | /* implement non blocking version below */ 274 | 275 | data_ready = 0; 276 | while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) { 277 | status = VL53L1_is_new_data_ready( 278 | Dev, 279 | &data_ready); 280 | 281 | if (status == VL53L1_ERROR_NONE) { 282 | status = VL53L1_WaitMs( 283 | Dev, 284 | VL53L1_POLLING_DELAY_MS); 285 | } 286 | } 287 | } 288 | 289 | LOG_FUNCTION_END(status); 290 | 291 | return status; 292 | } 293 | 294 | 295 | 296 | 297 | VL53L1_Error VL53L1_is_boot_complete( 298 | VL53L1_DEV Dev, 299 | uint8_t *pready) 300 | { 301 | /** 302 | * Determines if the firmware finished booting by reading 303 | * bit 0 of firmware__system_status register 304 | */ 305 | 306 | VL53L1_Error status = VL53L1_ERROR_NONE; 307 | uint8_t firmware__system_status = 0; 308 | 309 | LOG_FUNCTION_START(""); 310 | 311 | /* read current range interrupt state */ 312 | 313 | status = 314 | VL53L1_RdByte( 315 | Dev, 316 | VL53L1_FIRMWARE__SYSTEM_STATUS, 317 | &firmware__system_status); 318 | 319 | /* set *pready = 1 if new range data ready complete 320 | * zero otherwise 321 | */ 322 | 323 | if ((firmware__system_status & 0x01) == 0x01) { 324 | *pready = 0x01; 325 | VL53L1_init_ll_driver_state( 326 | Dev, 327 | VL53L1_DEVICESTATE_SW_STANDBY); 328 | } else { 329 | *pready = 0x00; 330 | VL53L1_init_ll_driver_state( 331 | Dev, 332 | VL53L1_DEVICESTATE_FW_COLDBOOT); 333 | } 334 | 335 | LOG_FUNCTION_END(status); 336 | 337 | return status; 338 | } 339 | 340 | 341 | VL53L1_Error VL53L1_is_firmware_ready( 342 | VL53L1_DEV Dev, 343 | uint8_t *pready) 344 | { 345 | /** 346 | * Determines if the firmware is ready to range 347 | */ 348 | 349 | VL53L1_Error status = VL53L1_ERROR_NONE; 350 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 351 | 352 | LOG_FUNCTION_START(""); 353 | 354 | status = VL53L1_is_firmware_ready_silicon( 355 | Dev, 356 | pready); 357 | 358 | pdev->fw_ready = *pready; 359 | 360 | LOG_FUNCTION_END(status); 361 | 362 | return status; 363 | } 364 | 365 | 366 | VL53L1_Error VL53L1_is_new_data_ready( 367 | VL53L1_DEV Dev, 368 | uint8_t *pready) 369 | { 370 | /** 371 | * Determines if new range data is ready by reading bit 0 of 372 | * VL53L1_GPIO__TIO_HV_STATUS to determine the current state 373 | * of output interrupt pin 374 | */ 375 | 376 | VL53L1_Error status = VL53L1_ERROR_NONE; 377 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 378 | 379 | uint8_t gpio__mux_active_high_hv = 0; 380 | uint8_t gpio__tio_hv_status = 0; 381 | uint8_t interrupt_ready = 0; 382 | 383 | LOG_FUNCTION_START(""); 384 | 385 | gpio__mux_active_high_hv = 386 | pdev->stat_cfg.gpio_hv_mux__ctrl & 387 | VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK; 388 | 389 | if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH) 390 | interrupt_ready = 0x01; 391 | else 392 | interrupt_ready = 0x00; 393 | 394 | /* read current range interrupt state */ 395 | 396 | status = VL53L1_RdByte( 397 | Dev, 398 | VL53L1_GPIO__TIO_HV_STATUS, 399 | &gpio__tio_hv_status); 400 | 401 | /* set *pready = 1 if new range data ready complete zero otherwise */ 402 | 403 | if ((gpio__tio_hv_status & 0x01) == interrupt_ready) 404 | *pready = 0x01; 405 | else 406 | *pready = 0x00; 407 | 408 | LOG_FUNCTION_END(status); 409 | 410 | return status; 411 | } 412 | 413 | 414 | 415 | 416 | VL53L1_Error VL53L1_poll_for_boot_completion( 417 | VL53L1_DEV Dev, 418 | uint32_t timeout_ms) 419 | { 420 | /** 421 | * Polls the bit 0 of the FIRMWARE__SYSTEM_STATUS register to see if 422 | * the firmware is ready. 423 | */ 424 | 425 | VL53L1_Error status = VL53L1_ERROR_NONE; 426 | 427 | LOG_FUNCTION_START(""); 428 | 429 | /* after reset for the firmware blocks I2C access while 430 | * it copies the NVM data into the G02 host register banks 431 | * The host must wait the required time to allow the copy 432 | * to complete before attempting to read the firmware status 433 | */ 434 | 435 | status = VL53L1_WaitUs( 436 | Dev, 437 | VL53L1_FIRMWARE_BOOT_TIME_US); 438 | 439 | if (status == VL53L1_ERROR_NONE) 440 | status = 441 | VL53L1_WaitValueMaskEx( 442 | Dev, 443 | timeout_ms, 444 | VL53L1_FIRMWARE__SYSTEM_STATUS, 445 | 0x01, 446 | 0x01, 447 | VL53L1_POLLING_DELAY_MS); 448 | 449 | if (status == VL53L1_ERROR_NONE) 450 | VL53L1_init_ll_driver_state(Dev, VL53L1_DEVICESTATE_SW_STANDBY); 451 | 452 | LOG_FUNCTION_END(status); 453 | 454 | return status; 455 | } 456 | 457 | 458 | VL53L1_Error VL53L1_poll_for_firmware_ready( 459 | VL53L1_DEV Dev, 460 | uint32_t timeout_ms) 461 | { 462 | /** 463 | * Polls the bit 0 of the FIRMWARE__SYSTEM_STATUS register to see if 464 | * the firmware is ready. 465 | */ 466 | 467 | VL53L1_Error status = VL53L1_ERROR_NONE; 468 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 469 | 470 | uint32_t start_time_ms = 0; 471 | uint32_t current_time_ms = 0; 472 | int32_t poll_delay_ms = VL53L1_POLLING_DELAY_MS; 473 | uint8_t fw_ready = 0; 474 | 475 | /* calculate time limit in absolute time */ 476 | 477 | VL53L1_GetTickCount(&start_time_ms); /*lint !e534 ignoring return*/ 478 | pdev->fw_ready_poll_duration_ms = 0; 479 | 480 | /* wait until firmware is ready, timeout reached on error occurred */ 481 | 482 | while ((status == VL53L1_ERROR_NONE) && 483 | (pdev->fw_ready_poll_duration_ms < timeout_ms) && 484 | (fw_ready == 0)) { 485 | 486 | status = VL53L1_is_firmware_ready( 487 | Dev, 488 | &fw_ready); 489 | 490 | if (status == VL53L1_ERROR_NONE && 491 | fw_ready == 0 && 492 | poll_delay_ms > 0) { 493 | status = VL53L1_WaitMs( 494 | Dev, 495 | poll_delay_ms); 496 | } 497 | 498 | /* 499 | * Update polling time (Compare difference rather than 500 | * absolute to negate 32bit wrap around issue) 501 | */ 502 | VL53L1_GetTickCount(¤t_time_ms); /*lint !e534 ignoring return*/ 503 | pdev->fw_ready_poll_duration_ms = 504 | current_time_ms - start_time_ms; 505 | } 506 | 507 | if (fw_ready == 0 && status == VL53L1_ERROR_NONE) 508 | status = VL53L1_ERROR_TIME_OUT; 509 | 510 | LOG_FUNCTION_END(status); 511 | 512 | return status; 513 | } 514 | 515 | 516 | VL53L1_Error VL53L1_poll_for_range_completion( 517 | VL53L1_DEV Dev, 518 | uint32_t timeout_ms) 519 | { 520 | /** 521 | * Polls bit 0 of VL53L1_GPIO__TIO_HV_STATUS to determine 522 | * the state of output interrupt pin 523 | * 524 | * Interrupt may be either active high or active low. Use active_high to 525 | * select the required level check 526 | */ 527 | 528 | VL53L1_Error status = VL53L1_ERROR_NONE; 529 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); 530 | 531 | uint8_t gpio__mux_active_high_hv = 0; 532 | uint8_t interrupt_ready = 0; 533 | 534 | LOG_FUNCTION_START(""); 535 | 536 | gpio__mux_active_high_hv = 537 | pdev->stat_cfg.gpio_hv_mux__ctrl & 538 | VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK; 539 | 540 | if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH) 541 | interrupt_ready = 0x01; 542 | else 543 | interrupt_ready = 0x00; 544 | 545 | status = 546 | VL53L1_WaitValueMaskEx( 547 | Dev, 548 | timeout_ms, 549 | VL53L1_GPIO__TIO_HV_STATUS, 550 | interrupt_ready, 551 | 0x01, 552 | VL53L1_POLLING_DELAY_MS); 553 | 554 | LOG_FUNCTION_END(status); 555 | 556 | return status; 557 | } 558 | 559 | -------------------------------------------------------------------------------- /vl53l1x-st-api/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-st-api/vl53l1x-st-api.ino: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | 3 | This sketch file is derived from an example program 4 | (Projects\Multi\Examples\VL53L1X\SimpleRangingExamples\Src\main.c) in the 5 | X-CUBE-53L1A1 Long Distance Ranging sensor software expansion for STM32Cube 6 | from ST, available here: 7 | 8 | http://www.st.com/content/st_com/en/products/ecosystems/stm32-open-development-environment/stm32cube-expansion-software/stm32-ode-sense-sw/x-cube-53l1a1.html 9 | 10 | The rest of the files in this sketch are from the STSW-IMG007 VL53L1X API from 11 | ST, available here: 12 | 13 | http://www.st.com/content/st_com/en/products/embedded-software/proximity-sensors-software/stsw-img007.html 14 | 15 | ******************************************************************************** 16 | 17 | COPYRIGHT(c) 2017 STMicroelectronics 18 | COPYRIGHT(c) 2018 Pololu Corporation 19 | 20 | Redistribution and use in source and binary forms, with or without modification, 21 | are permitted provided that the following conditions are met: 22 | 1. Redistributions of source code must retain the above copyright notice, 23 | this list of conditions and the following disclaimer. 24 | 2. Redistributions in binary form must reproduce the above copyright notice, 25 | this list of conditions and the following disclaimer in the documentation 26 | and/or other materials provided with the distribution. 27 | 3. Neither the name of STMicroelectronics nor the names of its contributors 28 | may be used to endorse or promote products derived from this software 29 | without specific prior written permission. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 32 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 34 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 35 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 37 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 38 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 39 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 41 | 42 | *******************************************************************************/ 43 | 44 | #include 45 | #include "vl53l1_api.h" 46 | 47 | // By default, this example blocks while waiting for sensor data to be ready. 48 | // Comment out this line to poll for data ready in a non-blocking way instead. 49 | #define USE_BLOCKING_LOOP 50 | 51 | // Timing budget set through VL53L1_SetMeasurementTimingBudgetMicroSeconds(). 52 | #define MEASUREMENT_BUDGET_MS 50 53 | 54 | // Interval between measurements, set through 55 | // VL53L1_SetInterMeasurementPeriodMilliSeconds(). According to the API user 56 | // manual (rev 2), "the minimum inter-measurement period must be longer than the 57 | // timing budget + 4 ms." The STM32Cube example from ST uses 500 ms, but we 58 | // reduce this to 55 ms to allow faster readings. 59 | #define INTER_MEASUREMENT_PERIOD_MS 55 60 | 61 | VL53L1_Dev_t dev; 62 | VL53L1_DEV Dev = &dev; 63 | 64 | int status; 65 | 66 | void setup() 67 | { 68 | uint8_t byteData = 0; 69 | uint16_t wordData = 0; 70 | 71 | Wire.begin(); 72 | Wire.setClock(400000); 73 | Serial.begin(115200); 74 | 75 | // This is the default 8-bit slave address (including R/W as the least 76 | // significant bit) as expected by the API. Note that the Arduino Wire library 77 | // uses a 7-bit address without the R/W bit instead (0x29 or 0b0101001). 78 | Dev->I2cDevAddr = 0x52; 79 | 80 | VL53L1_software_reset(Dev); 81 | 82 | VL53L1_RdByte(Dev, 0x010F, &byteData); 83 | Serial.print(F("VL53L1X Model_ID: ")); 84 | Serial.println(byteData, HEX); 85 | VL53L1_RdByte(Dev, 0x0110, &byteData); 86 | Serial.print(F("VL53L1X Module_Type: ")); 87 | Serial.println(byteData, HEX); 88 | VL53L1_RdWord(Dev, 0x010F, &wordData); 89 | Serial.print(F("VL53L1X: ")); 90 | Serial.println(wordData, HEX); 91 | 92 | Serial.println(F("Autonomous Ranging Test")); 93 | status = VL53L1_WaitDeviceBooted(Dev); 94 | if(!status) status = VL53L1_DataInit(Dev); 95 | if(!status) status = VL53L1_StaticInit(Dev); 96 | if(!status) status = VL53L1_SetDistanceMode(Dev, VL53L1_DISTANCEMODE_LONG); 97 | if(!status) status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, (uint32_t)MEASUREMENT_BUDGET_MS * 1000); 98 | if(!status) status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, INTER_MEASUREMENT_PERIOD_MS); 99 | if(!status) status = VL53L1_StartMeasurement(Dev); 100 | 101 | if(status) 102 | { 103 | Serial.println(F("VL53L1_StartMeasurement failed")); 104 | while(1); 105 | } 106 | } 107 | 108 | void loop() 109 | { 110 | #ifdef USE_BLOCKING_LOOP 111 | 112 | // blocking wait for data ready 113 | status = VL53L1_WaitMeasurementDataReady(Dev); 114 | 115 | if(!status) 116 | { 117 | printRangingData(); 118 | VL53L1_ClearInterruptAndStartMeasurement(Dev); 119 | } 120 | else 121 | { 122 | Serial.print(F("Error waiting for data ready: ")); 123 | Serial.println(status); 124 | } 125 | 126 | #else 127 | 128 | static uint16_t startMs = millis(); 129 | uint8_t isReady; 130 | 131 | // non-blocking check for data ready 132 | status = VL53L1_GetMeasurementDataReady(Dev, &isReady); 133 | 134 | if(!status) 135 | { 136 | if(isReady) 137 | { 138 | printRangingData(); 139 | VL53L1_ClearInterruptAndStartMeasurement(Dev); 140 | startMs = millis(); 141 | } 142 | else if((uint16_t)(millis() - startMs) > VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS) 143 | { 144 | Serial.print(F("Timeout waiting for data ready.")); 145 | VL53L1_ClearInterruptAndStartMeasurement(Dev); 146 | startMs = millis(); 147 | } 148 | } 149 | else 150 | { 151 | Serial.print(F("Error getting data ready: ")); 152 | Serial.println(status); 153 | } 154 | 155 | // Optional polling delay; should be smaller than INTER_MEASUREMENT_PERIOD_MS, 156 | // and MUST be smaller than VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS 157 | delay(10); 158 | 159 | #endif 160 | } 161 | 162 | void printRangingData() 163 | { 164 | static VL53L1_RangingMeasurementData_t RangingData; 165 | 166 | status = VL53L1_GetRangingMeasurementData(Dev, &RangingData); 167 | if(!status) 168 | { 169 | Serial.print(RangingData.RangeStatus); 170 | Serial.print(F(",")); 171 | Serial.print(RangingData.RangeMilliMeter); 172 | Serial.print(F(",")); 173 | Serial.print(RangingData.SignalRateRtnMegaCps/65536.0); 174 | Serial.print(F(",")); 175 | Serial.println(RangingData.AmbientRateRtnMegaCps/65336.0); 176 | } 177 | } 178 | --------------------------------------------------------------------------------