Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
vl53l1_register_funcs.c
00001 00002 /******************************************************************************* 00003 * Copyright (c) 2020, STMicroelectronics - All Rights Reserved 00004 00005 This file is part of VL53L1 Core and is dual licensed, 00006 either 'STMicroelectronics 00007 Proprietary license' 00008 or 'BSD 3-clause "New" or "Revised" License' , at your option. 00009 00010 ******************************************************************************** 00011 00012 'STMicroelectronics Proprietary license' 00013 00014 ******************************************************************************** 00015 00016 License terms: STMicroelectronics Proprietary in accordance with licensing 00017 terms at www.st.com/sla0081 00018 00019 STMicroelectronics confidential 00020 Reproduction and Communication of this document is strictly prohibited unless 00021 specifically authorized in writing by STMicroelectronics. 00022 00023 00024 ******************************************************************************** 00025 00026 Alternatively, VL53L1 Core may be distributed under the terms of 00027 'BSD 3-clause "New" or "Revised" License', in which case the following 00028 provisions apply instead of the ones 00029 mentioned above : 00030 00031 ******************************************************************************** 00032 00033 License terms: BSD 3-clause "New" or "Revised" License. 00034 00035 Redistribution and use in source and binary forms, with or without 00036 modification, are permitted provided that the following conditions are met: 00037 00038 1. Redistributions of source code must retain the above copyright notice, this 00039 list of conditions and the following disclaimer. 00040 00041 2. Redistributions in binary form must reproduce the above copyright notice, 00042 this list of conditions and the following disclaimer in the documentation 00043 and/or other materials provided with the distribution. 00044 00045 3. Neither the name of the copyright holder nor the names of its contributors 00046 may be used to endorse or promote products derived from this software 00047 without specific prior written permission. 00048 00049 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00050 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00051 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00052 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00053 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00054 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00055 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00056 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00057 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00058 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00059 00060 00061 ******************************************************************************** 00062 00063 */ 00064 00065 00066 00067 00068 #include "vl53l1_ll_def.h" 00069 #include "vl53l1_platform.h" 00070 #include "vl53l1_platform_log.h" 00071 #include "vl53l1_core.h" 00072 #include "vl53l1_register_map.h" 00073 #include "vl53l1_register_structs.h" 00074 #include "vl53l1_register_funcs.h" 00075 00076 #define LOG_FUNCTION_START(fmt, ...) \ 00077 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_REGISTERS, fmt, ##__VA_ARGS__) 00078 #define LOG_FUNCTION_END(status, ...) \ 00079 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_REGISTERS, status, ##__VA_ARGS__) 00080 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ 00081 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_REGISTERS,\ 00082 status, fmt, ##__VA_ARGS__) 00083 00084 00085 VL53L1_Error VL53L1_i2c_encode_static_nvm_managed( 00086 VL53L1_static_nvm_managed_t *pdata, 00087 uint16_t buf_size, 00088 uint8_t *pbuffer) 00089 { 00090 00091 00092 VL53L1_Error status = VL53L1_ERROR_NONE; 00093 00094 LOG_FUNCTION_START(""); 00095 00096 if (buf_size < VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES) 00097 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00098 00099 *(pbuffer + 0) = 00100 pdata->i2c_slave__device_address & 0x7F; 00101 *(pbuffer + 1) = 00102 pdata->ana_config__vhv_ref_sel_vddpix & 0xF; 00103 *(pbuffer + 2) = 00104 pdata->ana_config__vhv_ref_sel_vquench & 0x7F; 00105 *(pbuffer + 3) = 00106 pdata->ana_config__reg_avdd1v2_sel & 0x3; 00107 *(pbuffer + 4) = 00108 pdata->ana_config__fast_osc__trim & 0x7F; 00109 VL53L1_i2c_encode_uint16_t( 00110 pdata->osc_measured__fast_osc__frequency, 00111 2, 00112 pbuffer + 5); 00113 *(pbuffer + 7) = 00114 pdata->vhv_config__timeout_macrop_loop_bound; 00115 *(pbuffer + 8) = 00116 pdata->vhv_config__count_thresh; 00117 *(pbuffer + 9) = 00118 pdata->vhv_config__offset & 0x3F; 00119 *(pbuffer + 10) = 00120 pdata->vhv_config__init; 00121 LOG_FUNCTION_END(status); 00122 00123 00124 return status; 00125 } 00126 00127 00128 VL53L1_Error VL53L1_i2c_decode_static_nvm_managed( 00129 uint16_t buf_size, 00130 uint8_t *pbuffer, 00131 VL53L1_static_nvm_managed_t *pdata) 00132 { 00133 00134 00135 VL53L1_Error status = VL53L1_ERROR_NONE; 00136 00137 LOG_FUNCTION_START(""); 00138 00139 if (buf_size < VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES) 00140 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00141 00142 pdata->i2c_slave__device_address = 00143 (*(pbuffer + 0)) & 0x7F; 00144 pdata->ana_config__vhv_ref_sel_vddpix = 00145 (*(pbuffer + 1)) & 0xF; 00146 pdata->ana_config__vhv_ref_sel_vquench = 00147 (*(pbuffer + 2)) & 0x7F; 00148 pdata->ana_config__reg_avdd1v2_sel = 00149 (*(pbuffer + 3)) & 0x3; 00150 pdata->ana_config__fast_osc__trim = 00151 (*(pbuffer + 4)) & 0x7F; 00152 pdata->osc_measured__fast_osc__frequency = 00153 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 5)); 00154 pdata->vhv_config__timeout_macrop_loop_bound = 00155 (*(pbuffer + 7)); 00156 pdata->vhv_config__count_thresh = 00157 (*(pbuffer + 8)); 00158 pdata->vhv_config__offset = 00159 (*(pbuffer + 9)) & 0x3F; 00160 pdata->vhv_config__init = 00161 (*(pbuffer + 10)); 00162 00163 LOG_FUNCTION_END(status); 00164 00165 return status; 00166 } 00167 00168 00169 VL53L1_Error VL53L1_set_static_nvm_managed( 00170 VL53L1_DEV Dev, 00171 VL53L1_static_nvm_managed_t *pdata) 00172 { 00173 00174 00175 VL53L1_Error status = VL53L1_ERROR_NONE; 00176 uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES]; 00177 00178 LOG_FUNCTION_START(""); 00179 00180 if (status == VL53L1_ERROR_NONE) 00181 status = VL53L1_i2c_encode_static_nvm_managed( 00182 pdata, 00183 VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES, 00184 comms_buffer); 00185 00186 if (status == VL53L1_ERROR_NONE) 00187 status = VL53L1_WriteMulti( 00188 Dev, 00189 VL53L1_I2C_SLAVE__DEVICE_ADDRESS, 00190 comms_buffer, 00191 VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES); 00192 00193 LOG_FUNCTION_END(status); 00194 00195 return status; 00196 } 00197 00198 00199 VL53L1_Error VL53L1_get_static_nvm_managed( 00200 VL53L1_DEV Dev, 00201 VL53L1_static_nvm_managed_t *pdata) 00202 { 00203 00204 00205 VL53L1_Error status = VL53L1_ERROR_NONE; 00206 uint8_t comms_buffer[VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES]; 00207 00208 LOG_FUNCTION_START(""); 00209 00210 if (status == VL53L1_ERROR_NONE) 00211 status = VL53L1_ReadMulti( 00212 Dev, 00213 VL53L1_I2C_SLAVE__DEVICE_ADDRESS, 00214 comms_buffer, 00215 VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES); 00216 00217 if (status == VL53L1_ERROR_NONE) 00218 status = VL53L1_i2c_decode_static_nvm_managed( 00219 VL53L1_STATIC_NVM_MANAGED_I2C_SIZE_BYTES, 00220 comms_buffer, 00221 pdata); 00222 00223 LOG_FUNCTION_END(status); 00224 00225 return status; 00226 } 00227 00228 00229 VL53L1_Error VL53L1_i2c_encode_customer_nvm_managed( 00230 VL53L1_customer_nvm_managed_t *pdata, 00231 uint16_t buf_size, 00232 uint8_t *pbuffer) 00233 { 00234 00235 00236 VL53L1_Error status = VL53L1_ERROR_NONE; 00237 00238 LOG_FUNCTION_START(""); 00239 00240 if (buf_size < VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES) 00241 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00242 00243 *(pbuffer + 0) = 00244 pdata->global_config__spad_enables_ref_0; 00245 *(pbuffer + 1) = 00246 pdata->global_config__spad_enables_ref_1; 00247 *(pbuffer + 2) = 00248 pdata->global_config__spad_enables_ref_2; 00249 *(pbuffer + 3) = 00250 pdata->global_config__spad_enables_ref_3; 00251 *(pbuffer + 4) = 00252 pdata->global_config__spad_enables_ref_4; 00253 *(pbuffer + 5) = 00254 pdata->global_config__spad_enables_ref_5 & 0xF; 00255 *(pbuffer + 6) = 00256 pdata->global_config__ref_en_start_select; 00257 *(pbuffer + 7) = 00258 pdata->ref_spad_man__num_requested_ref_spads & 0x3F; 00259 *(pbuffer + 8) = 00260 pdata->ref_spad_man__ref_location & 0x3; 00261 VL53L1_i2c_encode_uint16_t( 00262 pdata->algo__crosstalk_compensation_plane_offset_kcps, 00263 2, 00264 pbuffer + 9); 00265 VL53L1_i2c_encode_int16_t( 00266 pdata->algo__crosstalk_compensation_x_plane_gradient_kcps, 00267 2, 00268 pbuffer + 11); 00269 VL53L1_i2c_encode_int16_t( 00270 pdata->algo__crosstalk_compensation_y_plane_gradient_kcps, 00271 2, 00272 pbuffer + 13); 00273 VL53L1_i2c_encode_uint16_t( 00274 pdata->ref_spad_char__total_rate_target_mcps, 00275 2, 00276 pbuffer + 15); 00277 VL53L1_i2c_encode_int16_t( 00278 pdata->algo__part_to_part_range_offset_mm & 0x1FFF, 00279 2, 00280 pbuffer + 17); 00281 VL53L1_i2c_encode_int16_t( 00282 pdata->mm_config__inner_offset_mm, 00283 2, 00284 pbuffer + 19); 00285 VL53L1_i2c_encode_int16_t( 00286 pdata->mm_config__outer_offset_mm, 00287 2, 00288 pbuffer + 21); 00289 LOG_FUNCTION_END(status); 00290 00291 00292 return status; 00293 } 00294 00295 00296 VL53L1_Error VL53L1_i2c_decode_customer_nvm_managed( 00297 uint16_t buf_size, 00298 uint8_t *pbuffer, 00299 VL53L1_customer_nvm_managed_t *pdata) 00300 { 00301 00302 00303 VL53L1_Error status = VL53L1_ERROR_NONE; 00304 00305 LOG_FUNCTION_START(""); 00306 00307 if (buf_size < VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES) 00308 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00309 00310 pdata->global_config__spad_enables_ref_0 = 00311 (*(pbuffer + 0)); 00312 pdata->global_config__spad_enables_ref_1 = 00313 (*(pbuffer + 1)); 00314 pdata->global_config__spad_enables_ref_2 = 00315 (*(pbuffer + 2)); 00316 pdata->global_config__spad_enables_ref_3 = 00317 (*(pbuffer + 3)); 00318 pdata->global_config__spad_enables_ref_4 = 00319 (*(pbuffer + 4)); 00320 pdata->global_config__spad_enables_ref_5 = 00321 (*(pbuffer + 5)) & 0xF; 00322 pdata->global_config__ref_en_start_select = 00323 (*(pbuffer + 6)); 00324 pdata->ref_spad_man__num_requested_ref_spads = 00325 (*(pbuffer + 7)) & 0x3F; 00326 pdata->ref_spad_man__ref_location = 00327 (*(pbuffer + 8)) & 0x3; 00328 pdata->algo__crosstalk_compensation_plane_offset_kcps = 00329 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 9)); 00330 pdata->algo__crosstalk_compensation_x_plane_gradient_kcps = 00331 (VL53L1_i2c_decode_int16_t(2, pbuffer + 11)); 00332 pdata->algo__crosstalk_compensation_y_plane_gradient_kcps = 00333 (VL53L1_i2c_decode_int16_t(2, pbuffer + 13)); 00334 pdata->ref_spad_char__total_rate_target_mcps = 00335 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 15)); 00336 pdata->algo__part_to_part_range_offset_mm = 00337 (VL53L1_i2c_decode_int16_t(2, pbuffer + 17)) & 0x1FFF; 00338 pdata->mm_config__inner_offset_mm = 00339 (VL53L1_i2c_decode_int16_t(2, pbuffer + 19)); 00340 pdata->mm_config__outer_offset_mm = 00341 (VL53L1_i2c_decode_int16_t(2, pbuffer + 21)); 00342 00343 LOG_FUNCTION_END(status); 00344 00345 return status; 00346 } 00347 00348 00349 VL53L1_Error VL53L1_set_customer_nvm_managed( 00350 VL53L1_DEV Dev, 00351 VL53L1_customer_nvm_managed_t *pdata) 00352 { 00353 00354 00355 VL53L1_Error status = VL53L1_ERROR_NONE; 00356 uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES]; 00357 00358 LOG_FUNCTION_START(""); 00359 00360 if (status == VL53L1_ERROR_NONE) 00361 status = VL53L1_i2c_encode_customer_nvm_managed( 00362 pdata, 00363 VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES, 00364 comms_buffer); 00365 00366 if (status == VL53L1_ERROR_NONE) 00367 status = VL53L1_WriteMulti( 00368 Dev, 00369 VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0, 00370 comms_buffer, 00371 VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES); 00372 00373 LOG_FUNCTION_END(status); 00374 00375 return status; 00376 } 00377 00378 00379 VL53L1_Error VL53L1_get_customer_nvm_managed( 00380 VL53L1_DEV Dev, 00381 VL53L1_customer_nvm_managed_t *pdata) 00382 { 00383 00384 00385 VL53L1_Error status = VL53L1_ERROR_NONE; 00386 uint8_t comms_buffer[VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES]; 00387 00388 LOG_FUNCTION_START(""); 00389 00390 if (status == VL53L1_ERROR_NONE) 00391 status = VL53L1_ReadMulti( 00392 Dev, 00393 VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0, 00394 comms_buffer, 00395 VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES); 00396 00397 if (status == VL53L1_ERROR_NONE) 00398 status = VL53L1_i2c_decode_customer_nvm_managed( 00399 VL53L1_CUSTOMER_NVM_MANAGED_I2C_SIZE_BYTES, 00400 comms_buffer, 00401 pdata); 00402 00403 LOG_FUNCTION_END(status); 00404 00405 return status; 00406 } 00407 00408 00409 VL53L1_Error VL53L1_i2c_encode_static_config( 00410 VL53L1_static_config_t *pdata, 00411 uint16_t buf_size, 00412 uint8_t *pbuffer) 00413 { 00414 00415 00416 VL53L1_Error status = VL53L1_ERROR_NONE; 00417 00418 LOG_FUNCTION_START(""); 00419 00420 if (buf_size < VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES) 00421 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00422 00423 VL53L1_i2c_encode_uint16_t( 00424 pdata->dss_config__target_total_rate_mcps, 00425 2, 00426 pbuffer + 0); 00427 *(pbuffer + 2) = 00428 pdata->debug__ctrl & 0x1; 00429 *(pbuffer + 3) = 00430 pdata->test_mode__ctrl & 0xF; 00431 *(pbuffer + 4) = 00432 pdata->clk_gating__ctrl & 0xF; 00433 *(pbuffer + 5) = 00434 pdata->nvm_bist__ctrl & 0x1F; 00435 *(pbuffer + 6) = 00436 pdata->nvm_bist__num_nvm_words & 0x7F; 00437 *(pbuffer + 7) = 00438 pdata->nvm_bist__start_address & 0x7F; 00439 *(pbuffer + 8) = 00440 pdata->host_if__status & 0x1; 00441 *(pbuffer + 9) = 00442 pdata->pad_i2c_hv__config; 00443 *(pbuffer + 10) = 00444 pdata->pad_i2c_hv__extsup_config & 0x1; 00445 *(pbuffer + 11) = 00446 pdata->gpio_hv_pad__ctrl & 0x3; 00447 *(pbuffer + 12) = 00448 pdata->gpio_hv_mux__ctrl & 0x1F; 00449 *(pbuffer + 13) = 00450 pdata->gpio__tio_hv_status & 0x3; 00451 *(pbuffer + 14) = 00452 pdata->gpio__fio_hv_status & 0x3; 00453 *(pbuffer + 15) = 00454 pdata->ana_config__spad_sel_pswidth & 0x7; 00455 *(pbuffer + 16) = 00456 pdata->ana_config__vcsel_pulse_width_offset & 0x1F; 00457 *(pbuffer + 17) = 00458 pdata->ana_config__fast_osc__config_ctrl & 0x1; 00459 *(pbuffer + 18) = 00460 pdata->sigma_estimator__effective_pulse_width_ns; 00461 *(pbuffer + 19) = 00462 pdata->sigma_estimator__effective_ambient_width_ns; 00463 *(pbuffer + 20) = 00464 pdata->sigma_estimator__sigma_ref_mm; 00465 *(pbuffer + 21) = 00466 pdata->algo__crosstalk_compensation_valid_height_mm; 00467 *(pbuffer + 22) = 00468 pdata->spare_host_config__static_config_spare_0; 00469 *(pbuffer + 23) = 00470 pdata->spare_host_config__static_config_spare_1; 00471 VL53L1_i2c_encode_uint16_t( 00472 pdata->algo__range_ignore_threshold_mcps, 00473 2, 00474 pbuffer + 24); 00475 *(pbuffer + 26) = 00476 pdata->algo__range_ignore_valid_height_mm; 00477 *(pbuffer + 27) = 00478 pdata->algo__range_min_clip; 00479 *(pbuffer + 28) = 00480 pdata->algo__consistency_check__tolerance & 0xF; 00481 *(pbuffer + 29) = 00482 pdata->spare_host_config__static_config_spare_2; 00483 *(pbuffer + 30) = 00484 pdata->sd_config__reset_stages_msb & 0xF; 00485 *(pbuffer + 31) = 00486 pdata->sd_config__reset_stages_lsb; 00487 LOG_FUNCTION_END(status); 00488 00489 00490 return status; 00491 } 00492 00493 00494 VL53L1_Error VL53L1_i2c_decode_static_config( 00495 uint16_t buf_size, 00496 uint8_t *pbuffer, 00497 VL53L1_static_config_t *pdata) 00498 { 00499 00500 00501 VL53L1_Error status = VL53L1_ERROR_NONE; 00502 00503 LOG_FUNCTION_START(""); 00504 00505 if (buf_size < VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES) 00506 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00507 00508 pdata->dss_config__target_total_rate_mcps = 00509 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0)); 00510 pdata->debug__ctrl = 00511 (*(pbuffer + 2)) & 0x1; 00512 pdata->test_mode__ctrl = 00513 (*(pbuffer + 3)) & 0xF; 00514 pdata->clk_gating__ctrl = 00515 (*(pbuffer + 4)) & 0xF; 00516 pdata->nvm_bist__ctrl = 00517 (*(pbuffer + 5)) & 0x1F; 00518 pdata->nvm_bist__num_nvm_words = 00519 (*(pbuffer + 6)) & 0x7F; 00520 pdata->nvm_bist__start_address = 00521 (*(pbuffer + 7)) & 0x7F; 00522 pdata->host_if__status = 00523 (*(pbuffer + 8)) & 0x1; 00524 pdata->pad_i2c_hv__config = 00525 (*(pbuffer + 9)); 00526 pdata->pad_i2c_hv__extsup_config = 00527 (*(pbuffer + 10)) & 0x1; 00528 pdata->gpio_hv_pad__ctrl = 00529 (*(pbuffer + 11)) & 0x3; 00530 pdata->gpio_hv_mux__ctrl = 00531 (*(pbuffer + 12)) & 0x1F; 00532 pdata->gpio__tio_hv_status = 00533 (*(pbuffer + 13)) & 0x3; 00534 pdata->gpio__fio_hv_status = 00535 (*(pbuffer + 14)) & 0x3; 00536 pdata->ana_config__spad_sel_pswidth = 00537 (*(pbuffer + 15)) & 0x7; 00538 pdata->ana_config__vcsel_pulse_width_offset = 00539 (*(pbuffer + 16)) & 0x1F; 00540 pdata->ana_config__fast_osc__config_ctrl = 00541 (*(pbuffer + 17)) & 0x1; 00542 pdata->sigma_estimator__effective_pulse_width_ns = 00543 (*(pbuffer + 18)); 00544 pdata->sigma_estimator__effective_ambient_width_ns = 00545 (*(pbuffer + 19)); 00546 pdata->sigma_estimator__sigma_ref_mm = 00547 (*(pbuffer + 20)); 00548 pdata->algo__crosstalk_compensation_valid_height_mm = 00549 (*(pbuffer + 21)); 00550 pdata->spare_host_config__static_config_spare_0 = 00551 (*(pbuffer + 22)); 00552 pdata->spare_host_config__static_config_spare_1 = 00553 (*(pbuffer + 23)); 00554 pdata->algo__range_ignore_threshold_mcps = 00555 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); 00556 pdata->algo__range_ignore_valid_height_mm = 00557 (*(pbuffer + 26)); 00558 pdata->algo__range_min_clip = 00559 (*(pbuffer + 27)); 00560 pdata->algo__consistency_check__tolerance = 00561 (*(pbuffer + 28)) & 0xF; 00562 pdata->spare_host_config__static_config_spare_2 = 00563 (*(pbuffer + 29)); 00564 pdata->sd_config__reset_stages_msb = 00565 (*(pbuffer + 30)) & 0xF; 00566 pdata->sd_config__reset_stages_lsb = 00567 (*(pbuffer + 31)); 00568 00569 LOG_FUNCTION_END(status); 00570 00571 return status; 00572 } 00573 00574 00575 VL53L1_Error VL53L1_set_static_config( 00576 VL53L1_DEV Dev, 00577 VL53L1_static_config_t *pdata) 00578 { 00579 00580 00581 VL53L1_Error status = VL53L1_ERROR_NONE; 00582 uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES]; 00583 00584 LOG_FUNCTION_START(""); 00585 00586 if (status == VL53L1_ERROR_NONE) 00587 status = VL53L1_i2c_encode_static_config( 00588 pdata, 00589 VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES, 00590 comms_buffer); 00591 00592 if (status == VL53L1_ERROR_NONE) 00593 status = VL53L1_WriteMulti( 00594 Dev, 00595 VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS, 00596 comms_buffer, 00597 VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES); 00598 00599 LOG_FUNCTION_END(status); 00600 00601 return status; 00602 } 00603 00604 00605 VL53L1_Error VL53L1_get_static_config( 00606 VL53L1_DEV Dev, 00607 VL53L1_static_config_t *pdata) 00608 { 00609 00610 00611 VL53L1_Error status = VL53L1_ERROR_NONE; 00612 uint8_t comms_buffer[VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES]; 00613 00614 LOG_FUNCTION_START(""); 00615 00616 if (status == VL53L1_ERROR_NONE) 00617 status = VL53L1_ReadMulti( 00618 Dev, 00619 VL53L1_DSS_CONFIG__TARGET_TOTAL_RATE_MCPS, 00620 comms_buffer, 00621 VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES); 00622 00623 if (status == VL53L1_ERROR_NONE) 00624 status = VL53L1_i2c_decode_static_config( 00625 VL53L1_STATIC_CONFIG_I2C_SIZE_BYTES, 00626 comms_buffer, 00627 pdata); 00628 00629 LOG_FUNCTION_END(status); 00630 00631 return status; 00632 } 00633 00634 00635 VL53L1_Error VL53L1_i2c_encode_general_config( 00636 VL53L1_general_config_t *pdata, 00637 uint16_t buf_size, 00638 uint8_t *pbuffer) 00639 { 00640 00641 00642 VL53L1_Error status = VL53L1_ERROR_NONE; 00643 00644 LOG_FUNCTION_START(""); 00645 00646 if (buf_size < VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES) 00647 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00648 00649 *(pbuffer + 0) = 00650 pdata->gph_config__stream_count_update_value; 00651 *(pbuffer + 1) = 00652 pdata->global_config__stream_divider; 00653 *(pbuffer + 2) = 00654 pdata->system__interrupt_config_gpio; 00655 *(pbuffer + 3) = 00656 pdata->cal_config__vcsel_start & 0x7F; 00657 VL53L1_i2c_encode_uint16_t( 00658 pdata->cal_config__repeat_rate & 0xFFF, 00659 2, 00660 pbuffer + 4); 00661 *(pbuffer + 6) = 00662 pdata->global_config__vcsel_width & 0x7F; 00663 *(pbuffer + 7) = 00664 pdata->phasecal_config__timeout_macrop; 00665 *(pbuffer + 8) = 00666 pdata->phasecal_config__target; 00667 *(pbuffer + 9) = 00668 pdata->phasecal_config__override & 0x1; 00669 *(pbuffer + 11) = 00670 pdata->dss_config__roi_mode_control & 0x7; 00671 VL53L1_i2c_encode_uint16_t( 00672 pdata->system__thresh_rate_high, 00673 2, 00674 pbuffer + 12); 00675 VL53L1_i2c_encode_uint16_t( 00676 pdata->system__thresh_rate_low, 00677 2, 00678 pbuffer + 14); 00679 VL53L1_i2c_encode_uint16_t( 00680 pdata->dss_config__manual_effective_spads_select, 00681 2, 00682 pbuffer + 16); 00683 *(pbuffer + 18) = 00684 pdata->dss_config__manual_block_select; 00685 *(pbuffer + 19) = 00686 pdata->dss_config__aperture_attenuation; 00687 *(pbuffer + 20) = 00688 pdata->dss_config__max_spads_limit; 00689 *(pbuffer + 21) = 00690 pdata->dss_config__min_spads_limit; 00691 LOG_FUNCTION_END(status); 00692 00693 00694 return status; 00695 } 00696 00697 00698 VL53L1_Error VL53L1_i2c_decode_general_config( 00699 uint16_t buf_size, 00700 uint8_t *pbuffer, 00701 VL53L1_general_config_t *pdata) 00702 { 00703 00704 00705 VL53L1_Error status = VL53L1_ERROR_NONE; 00706 00707 LOG_FUNCTION_START(""); 00708 00709 if (buf_size < VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES) 00710 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00711 00712 pdata->gph_config__stream_count_update_value = 00713 (*(pbuffer + 0)); 00714 pdata->global_config__stream_divider = 00715 (*(pbuffer + 1)); 00716 pdata->system__interrupt_config_gpio = 00717 (*(pbuffer + 2)); 00718 pdata->cal_config__vcsel_start = 00719 (*(pbuffer + 3)) & 0x7F; 00720 pdata->cal_config__repeat_rate = 00721 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)) & 0xFFF; 00722 pdata->global_config__vcsel_width = 00723 (*(pbuffer + 6)) & 0x7F; 00724 pdata->phasecal_config__timeout_macrop = 00725 (*(pbuffer + 7)); 00726 pdata->phasecal_config__target = 00727 (*(pbuffer + 8)); 00728 pdata->phasecal_config__override = 00729 (*(pbuffer + 9)) & 0x1; 00730 pdata->dss_config__roi_mode_control = 00731 (*(pbuffer + 11)) & 0x7; 00732 pdata->system__thresh_rate_high = 00733 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); 00734 pdata->system__thresh_rate_low = 00735 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); 00736 pdata->dss_config__manual_effective_spads_select = 00737 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); 00738 pdata->dss_config__manual_block_select = 00739 (*(pbuffer + 18)); 00740 pdata->dss_config__aperture_attenuation = 00741 (*(pbuffer + 19)); 00742 pdata->dss_config__max_spads_limit = 00743 (*(pbuffer + 20)); 00744 pdata->dss_config__min_spads_limit = 00745 (*(pbuffer + 21)); 00746 00747 LOG_FUNCTION_END(status); 00748 00749 return status; 00750 } 00751 00752 00753 VL53L1_Error VL53L1_set_general_config( 00754 VL53L1_DEV Dev, 00755 VL53L1_general_config_t *pdata) 00756 { 00757 00758 00759 VL53L1_Error status = VL53L1_ERROR_NONE; 00760 uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES]; 00761 00762 LOG_FUNCTION_START(""); 00763 00764 if (status == VL53L1_ERROR_NONE) 00765 status = VL53L1_i2c_encode_general_config( 00766 pdata, 00767 VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES, 00768 comms_buffer); 00769 00770 if (status == VL53L1_ERROR_NONE) 00771 status = VL53L1_WriteMulti( 00772 Dev, 00773 VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE, 00774 comms_buffer, 00775 VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES); 00776 00777 LOG_FUNCTION_END(status); 00778 00779 return status; 00780 } 00781 00782 00783 VL53L1_Error VL53L1_get_general_config( 00784 VL53L1_DEV Dev, 00785 VL53L1_general_config_t *pdata) 00786 { 00787 00788 00789 VL53L1_Error status = VL53L1_ERROR_NONE; 00790 uint8_t comms_buffer[VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES]; 00791 00792 LOG_FUNCTION_START(""); 00793 00794 if (status == VL53L1_ERROR_NONE) 00795 status = VL53L1_ReadMulti( 00796 Dev, 00797 VL53L1_GPH_CONFIG__STREAM_COUNT_UPDATE_VALUE, 00798 comms_buffer, 00799 VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES); 00800 00801 if (status == VL53L1_ERROR_NONE) 00802 status = VL53L1_i2c_decode_general_config( 00803 VL53L1_GENERAL_CONFIG_I2C_SIZE_BYTES, 00804 comms_buffer, 00805 pdata); 00806 00807 LOG_FUNCTION_END(status); 00808 00809 return status; 00810 } 00811 00812 00813 VL53L1_Error VL53L1_i2c_encode_timing_config( 00814 VL53L1_timing_config_t *pdata, 00815 uint16_t buf_size, 00816 uint8_t *pbuffer) 00817 { 00818 00819 00820 VL53L1_Error status = VL53L1_ERROR_NONE; 00821 00822 LOG_FUNCTION_START(""); 00823 00824 if (buf_size < VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES) 00825 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00826 00827 *(pbuffer + 0) = 00828 pdata->mm_config__timeout_macrop_a_hi & 0xF; 00829 *(pbuffer + 1) = 00830 pdata->mm_config__timeout_macrop_a_lo; 00831 *(pbuffer + 2) = 00832 pdata->mm_config__timeout_macrop_b_hi & 0xF; 00833 *(pbuffer + 3) = 00834 pdata->mm_config__timeout_macrop_b_lo; 00835 *(pbuffer + 4) = 00836 pdata->range_config__timeout_macrop_a_hi & 0xF; 00837 *(pbuffer + 5) = 00838 pdata->range_config__timeout_macrop_a_lo; 00839 *(pbuffer + 6) = 00840 pdata->range_config__vcsel_period_a & 0x3F; 00841 *(pbuffer + 7) = 00842 pdata->range_config__timeout_macrop_b_hi & 0xF; 00843 *(pbuffer + 8) = 00844 pdata->range_config__timeout_macrop_b_lo; 00845 *(pbuffer + 9) = 00846 pdata->range_config__vcsel_period_b & 0x3F; 00847 VL53L1_i2c_encode_uint16_t( 00848 pdata->range_config__sigma_thresh, 00849 2, 00850 pbuffer + 10); 00851 VL53L1_i2c_encode_uint16_t( 00852 pdata->range_config__min_count_rate_rtn_limit_mcps, 00853 2, 00854 pbuffer + 12); 00855 *(pbuffer + 14) = 00856 pdata->range_config__valid_phase_low; 00857 *(pbuffer + 15) = 00858 pdata->range_config__valid_phase_high; 00859 VL53L1_i2c_encode_uint32_t( 00860 pdata->system__intermeasurement_period, 00861 4, 00862 pbuffer + 18); 00863 *(pbuffer + 22) = 00864 pdata->system__fractional_enable & 0x1; 00865 LOG_FUNCTION_END(status); 00866 00867 00868 return status; 00869 } 00870 00871 00872 VL53L1_Error VL53L1_i2c_decode_timing_config( 00873 uint16_t buf_size, 00874 uint8_t *pbuffer, 00875 VL53L1_timing_config_t *pdata) 00876 { 00877 00878 00879 VL53L1_Error status = VL53L1_ERROR_NONE; 00880 00881 LOG_FUNCTION_START(""); 00882 00883 if (buf_size < VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES) 00884 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00885 00886 pdata->mm_config__timeout_macrop_a_hi = 00887 (*(pbuffer + 0)) & 0xF; 00888 pdata->mm_config__timeout_macrop_a_lo = 00889 (*(pbuffer + 1)); 00890 pdata->mm_config__timeout_macrop_b_hi = 00891 (*(pbuffer + 2)) & 0xF; 00892 pdata->mm_config__timeout_macrop_b_lo = 00893 (*(pbuffer + 3)); 00894 pdata->range_config__timeout_macrop_a_hi = 00895 (*(pbuffer + 4)) & 0xF; 00896 pdata->range_config__timeout_macrop_a_lo = 00897 (*(pbuffer + 5)); 00898 pdata->range_config__vcsel_period_a = 00899 (*(pbuffer + 6)) & 0x3F; 00900 pdata->range_config__timeout_macrop_b_hi = 00901 (*(pbuffer + 7)) & 0xF; 00902 pdata->range_config__timeout_macrop_b_lo = 00903 (*(pbuffer + 8)); 00904 pdata->range_config__vcsel_period_b = 00905 (*(pbuffer + 9)) & 0x3F; 00906 pdata->range_config__sigma_thresh = 00907 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); 00908 pdata->range_config__min_count_rate_rtn_limit_mcps = 00909 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); 00910 pdata->range_config__valid_phase_low = 00911 (*(pbuffer + 14)); 00912 pdata->range_config__valid_phase_high = 00913 (*(pbuffer + 15)); 00914 pdata->system__intermeasurement_period = 00915 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 18)); 00916 pdata->system__fractional_enable = 00917 (*(pbuffer + 22)) & 0x1; 00918 00919 LOG_FUNCTION_END(status); 00920 00921 return status; 00922 } 00923 00924 00925 VL53L1_Error VL53L1_set_timing_config( 00926 VL53L1_DEV Dev, 00927 VL53L1_timing_config_t *pdata) 00928 { 00929 00930 00931 VL53L1_Error status = VL53L1_ERROR_NONE; 00932 uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES]; 00933 00934 LOG_FUNCTION_START(""); 00935 00936 if (status == VL53L1_ERROR_NONE) 00937 status = VL53L1_i2c_encode_timing_config( 00938 pdata, 00939 VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES, 00940 comms_buffer); 00941 00942 if (status == VL53L1_ERROR_NONE) 00943 status = VL53L1_WriteMulti( 00944 Dev, 00945 VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI, 00946 comms_buffer, 00947 VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES); 00948 00949 LOG_FUNCTION_END(status); 00950 00951 return status; 00952 } 00953 00954 00955 VL53L1_Error VL53L1_get_timing_config( 00956 VL53L1_DEV Dev, 00957 VL53L1_timing_config_t *pdata) 00958 { 00959 00960 00961 VL53L1_Error status = VL53L1_ERROR_NONE; 00962 uint8_t comms_buffer[VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES]; 00963 00964 LOG_FUNCTION_START(""); 00965 00966 if (status == VL53L1_ERROR_NONE) 00967 status = VL53L1_ReadMulti( 00968 Dev, 00969 VL53L1_MM_CONFIG__TIMEOUT_MACROP_A_HI, 00970 comms_buffer, 00971 VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES); 00972 00973 if (status == VL53L1_ERROR_NONE) 00974 status = VL53L1_i2c_decode_timing_config( 00975 VL53L1_TIMING_CONFIG_I2C_SIZE_BYTES, 00976 comms_buffer, 00977 pdata); 00978 00979 LOG_FUNCTION_END(status); 00980 00981 return status; 00982 } 00983 00984 00985 VL53L1_Error VL53L1_i2c_encode_dynamic_config( 00986 VL53L1_dynamic_config_t *pdata, 00987 uint16_t buf_size, 00988 uint8_t *pbuffer) 00989 { 00990 00991 00992 VL53L1_Error status = VL53L1_ERROR_NONE; 00993 00994 LOG_FUNCTION_START(""); 00995 00996 if (buf_size < VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES) 00997 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 00998 00999 *(pbuffer + 0) = 01000 pdata->system__grouped_parameter_hold_0 & 0x3; 01001 VL53L1_i2c_encode_uint16_t( 01002 pdata->system__thresh_high, 01003 2, 01004 pbuffer + 1); 01005 VL53L1_i2c_encode_uint16_t( 01006 pdata->system__thresh_low, 01007 2, 01008 pbuffer + 3); 01009 *(pbuffer + 5) = 01010 pdata->system__enable_xtalk_per_quadrant & 0x1; 01011 *(pbuffer + 6) = 01012 pdata->system__seed_config & 0x7; 01013 *(pbuffer + 7) = 01014 pdata->sd_config__woi_sd0; 01015 *(pbuffer + 8) = 01016 pdata->sd_config__woi_sd1; 01017 *(pbuffer + 9) = 01018 pdata->sd_config__initial_phase_sd0 & 0x7F; 01019 *(pbuffer + 10) = 01020 pdata->sd_config__initial_phase_sd1 & 0x7F; 01021 *(pbuffer + 11) = 01022 pdata->system__grouped_parameter_hold_1 & 0x3; 01023 *(pbuffer + 12) = 01024 pdata->sd_config__first_order_select & 0x3; 01025 *(pbuffer + 13) = 01026 pdata->sd_config__quantifier & 0xF; 01027 *(pbuffer + 14) = 01028 pdata->roi_config__user_roi_centre_spad; 01029 *(pbuffer + 15) = 01030 pdata->roi_config__user_roi_requested_global_xy_size; 01031 *(pbuffer + 16) = 01032 pdata->system__sequence_config; 01033 *(pbuffer + 17) = 01034 pdata->system__grouped_parameter_hold & 0x3; 01035 LOG_FUNCTION_END(status); 01036 01037 01038 return status; 01039 } 01040 01041 01042 VL53L1_Error VL53L1_i2c_decode_dynamic_config( 01043 uint16_t buf_size, 01044 uint8_t *pbuffer, 01045 VL53L1_dynamic_config_t *pdata) 01046 { 01047 01048 01049 VL53L1_Error status = VL53L1_ERROR_NONE; 01050 01051 LOG_FUNCTION_START(""); 01052 01053 if (buf_size < VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES) 01054 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01055 01056 pdata->system__grouped_parameter_hold_0 = 01057 (*(pbuffer + 0)) & 0x3; 01058 pdata->system__thresh_high = 01059 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1)); 01060 pdata->system__thresh_low = 01061 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3)); 01062 pdata->system__enable_xtalk_per_quadrant = 01063 (*(pbuffer + 5)) & 0x1; 01064 pdata->system__seed_config = 01065 (*(pbuffer + 6)) & 0x7; 01066 pdata->sd_config__woi_sd0 = 01067 (*(pbuffer + 7)); 01068 pdata->sd_config__woi_sd1 = 01069 (*(pbuffer + 8)); 01070 pdata->sd_config__initial_phase_sd0 = 01071 (*(pbuffer + 9)) & 0x7F; 01072 pdata->sd_config__initial_phase_sd1 = 01073 (*(pbuffer + 10)) & 0x7F; 01074 pdata->system__grouped_parameter_hold_1 = 01075 (*(pbuffer + 11)) & 0x3; 01076 pdata->sd_config__first_order_select = 01077 (*(pbuffer + 12)) & 0x3; 01078 pdata->sd_config__quantifier = 01079 (*(pbuffer + 13)) & 0xF; 01080 pdata->roi_config__user_roi_centre_spad = 01081 (*(pbuffer + 14)); 01082 pdata->roi_config__user_roi_requested_global_xy_size = 01083 (*(pbuffer + 15)); 01084 pdata->system__sequence_config = 01085 (*(pbuffer + 16)); 01086 pdata->system__grouped_parameter_hold = 01087 (*(pbuffer + 17)) & 0x3; 01088 01089 LOG_FUNCTION_END(status); 01090 01091 return status; 01092 } 01093 01094 01095 VL53L1_Error VL53L1_set_dynamic_config( 01096 VL53L1_DEV Dev, 01097 VL53L1_dynamic_config_t *pdata) 01098 { 01099 01100 01101 VL53L1_Error status = VL53L1_ERROR_NONE; 01102 uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES]; 01103 01104 LOG_FUNCTION_START(""); 01105 01106 if (status == VL53L1_ERROR_NONE) 01107 status = VL53L1_i2c_encode_dynamic_config( 01108 pdata, 01109 VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES, 01110 comms_buffer); 01111 01112 if (status == VL53L1_ERROR_NONE) 01113 status = VL53L1_WriteMulti( 01114 Dev, 01115 VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0, 01116 comms_buffer, 01117 VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES); 01118 01119 LOG_FUNCTION_END(status); 01120 01121 return status; 01122 } 01123 01124 01125 VL53L1_Error VL53L1_get_dynamic_config( 01126 VL53L1_DEV Dev, 01127 VL53L1_dynamic_config_t *pdata) 01128 { 01129 01130 01131 VL53L1_Error status = VL53L1_ERROR_NONE; 01132 uint8_t comms_buffer[VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES]; 01133 01134 LOG_FUNCTION_START(""); 01135 01136 if (status == VL53L1_ERROR_NONE) 01137 status = VL53L1_ReadMulti( 01138 Dev, 01139 VL53L1_SYSTEM__GROUPED_PARAMETER_HOLD_0, 01140 comms_buffer, 01141 VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES); 01142 01143 if (status == VL53L1_ERROR_NONE) 01144 status = VL53L1_i2c_decode_dynamic_config( 01145 VL53L1_DYNAMIC_CONFIG_I2C_SIZE_BYTES, 01146 comms_buffer, 01147 pdata); 01148 01149 LOG_FUNCTION_END(status); 01150 01151 return status; 01152 } 01153 01154 01155 VL53L1_Error VL53L1_i2c_encode_system_control( 01156 VL53L1_system_control_t *pdata, 01157 uint16_t buf_size, 01158 uint8_t *pbuffer) 01159 { 01160 01161 01162 VL53L1_Error status = VL53L1_ERROR_NONE; 01163 01164 LOG_FUNCTION_START(""); 01165 01166 if (buf_size < VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES) 01167 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01168 01169 *(pbuffer + 0) = 01170 pdata->power_management__go1_power_force & 0x1; 01171 *(pbuffer + 1) = 01172 pdata->system__stream_count_ctrl & 0x1; 01173 *(pbuffer + 2) = 01174 pdata->firmware__enable & 0x1; 01175 *(pbuffer + 3) = 01176 pdata->system__interrupt_clear & 0x3; 01177 *(pbuffer + 4) = 01178 pdata->system__mode_start; 01179 LOG_FUNCTION_END(status); 01180 01181 01182 return status; 01183 } 01184 01185 01186 VL53L1_Error VL53L1_i2c_decode_system_control( 01187 uint16_t buf_size, 01188 uint8_t *pbuffer, 01189 VL53L1_system_control_t *pdata) 01190 { 01191 01192 01193 VL53L1_Error status = VL53L1_ERROR_NONE; 01194 01195 LOG_FUNCTION_START(""); 01196 01197 if (buf_size < VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES) 01198 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01199 01200 pdata->power_management__go1_power_force = 01201 (*(pbuffer + 0)) & 0x1; 01202 pdata->system__stream_count_ctrl = 01203 (*(pbuffer + 1)) & 0x1; 01204 pdata->firmware__enable = 01205 (*(pbuffer + 2)) & 0x1; 01206 pdata->system__interrupt_clear = 01207 (*(pbuffer + 3)) & 0x3; 01208 pdata->system__mode_start = 01209 (*(pbuffer + 4)); 01210 01211 LOG_FUNCTION_END(status); 01212 01213 return status; 01214 } 01215 01216 01217 VL53L1_Error VL53L1_set_system_control( 01218 VL53L1_DEV Dev, 01219 VL53L1_system_control_t *pdata) 01220 { 01221 01222 01223 VL53L1_Error status = VL53L1_ERROR_NONE; 01224 uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES]; 01225 01226 LOG_FUNCTION_START(""); 01227 01228 if (status == VL53L1_ERROR_NONE) 01229 status = VL53L1_i2c_encode_system_control( 01230 pdata, 01231 VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES, 01232 comms_buffer); 01233 01234 if (status == VL53L1_ERROR_NONE) 01235 status = VL53L1_WriteMulti( 01236 Dev, 01237 VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE, 01238 comms_buffer, 01239 VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES); 01240 01241 LOG_FUNCTION_END(status); 01242 01243 return status; 01244 } 01245 01246 01247 VL53L1_Error VL53L1_get_system_control( 01248 VL53L1_DEV Dev, 01249 VL53L1_system_control_t *pdata) 01250 { 01251 01252 01253 VL53L1_Error status = VL53L1_ERROR_NONE; 01254 uint8_t comms_buffer[VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES]; 01255 01256 LOG_FUNCTION_START(""); 01257 01258 if (status == VL53L1_ERROR_NONE) 01259 status = VL53L1_ReadMulti( 01260 Dev, 01261 VL53L1_POWER_MANAGEMENT__GO1_POWER_FORCE, 01262 comms_buffer, 01263 VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES); 01264 01265 if (status == VL53L1_ERROR_NONE) 01266 status = VL53L1_i2c_decode_system_control( 01267 VL53L1_SYSTEM_CONTROL_I2C_SIZE_BYTES, 01268 comms_buffer, 01269 pdata); 01270 01271 LOG_FUNCTION_END(status); 01272 01273 return status; 01274 } 01275 01276 01277 VL53L1_Error VL53L1_i2c_encode_system_results( 01278 VL53L1_system_results_t *pdata, 01279 uint16_t buf_size, 01280 uint8_t *pbuffer) 01281 { 01282 01283 01284 VL53L1_Error status = VL53L1_ERROR_NONE; 01285 01286 LOG_FUNCTION_START(""); 01287 01288 if (buf_size < VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES) 01289 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01290 01291 *(pbuffer + 0) = 01292 pdata->result__interrupt_status & 0x3F; 01293 *(pbuffer + 1) = 01294 pdata->result__range_status; 01295 *(pbuffer + 2) = 01296 pdata->result__report_status & 0xF; 01297 *(pbuffer + 3) = 01298 pdata->result__stream_count; 01299 VL53L1_i2c_encode_uint16_t( 01300 pdata->result__dss_actual_effective_spads_sd0, 01301 2, 01302 pbuffer + 4); 01303 VL53L1_i2c_encode_uint16_t( 01304 pdata->result__peak_signal_count_rate_mcps_sd0, 01305 2, 01306 pbuffer + 6); 01307 VL53L1_i2c_encode_uint16_t( 01308 pdata->result__ambient_count_rate_mcps_sd0, 01309 2, 01310 pbuffer + 8); 01311 VL53L1_i2c_encode_uint16_t( 01312 pdata->result__sigma_sd0, 01313 2, 01314 pbuffer + 10); 01315 VL53L1_i2c_encode_uint16_t( 01316 pdata->result__phase_sd0, 01317 2, 01318 pbuffer + 12); 01319 VL53L1_i2c_encode_uint16_t( 01320 pdata->result__final_crosstalk_corrected_range_mm_sd0, 01321 2, 01322 pbuffer + 14); 01323 VL53L1_i2c_encode_uint16_t( 01324 pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0, 01325 2, 01326 pbuffer + 16); 01327 VL53L1_i2c_encode_uint16_t( 01328 pdata->result__mm_inner_actual_effective_spads_sd0, 01329 2, 01330 pbuffer + 18); 01331 VL53L1_i2c_encode_uint16_t( 01332 pdata->result__mm_outer_actual_effective_spads_sd0, 01333 2, 01334 pbuffer + 20); 01335 VL53L1_i2c_encode_uint16_t( 01336 pdata->result__avg_signal_count_rate_mcps_sd0, 01337 2, 01338 pbuffer + 22); 01339 VL53L1_i2c_encode_uint16_t( 01340 pdata->result__dss_actual_effective_spads_sd1, 01341 2, 01342 pbuffer + 24); 01343 VL53L1_i2c_encode_uint16_t( 01344 pdata->result__peak_signal_count_rate_mcps_sd1, 01345 2, 01346 pbuffer + 26); 01347 VL53L1_i2c_encode_uint16_t( 01348 pdata->result__ambient_count_rate_mcps_sd1, 01349 2, 01350 pbuffer + 28); 01351 VL53L1_i2c_encode_uint16_t( 01352 pdata->result__sigma_sd1, 01353 2, 01354 pbuffer + 30); 01355 VL53L1_i2c_encode_uint16_t( 01356 pdata->result__phase_sd1, 01357 2, 01358 pbuffer + 32); 01359 VL53L1_i2c_encode_uint16_t( 01360 pdata->result__final_crosstalk_corrected_range_mm_sd1, 01361 2, 01362 pbuffer + 34); 01363 VL53L1_i2c_encode_uint16_t( 01364 pdata->result__spare_0_sd1, 01365 2, 01366 pbuffer + 36); 01367 VL53L1_i2c_encode_uint16_t( 01368 pdata->result__spare_1_sd1, 01369 2, 01370 pbuffer + 38); 01371 VL53L1_i2c_encode_uint16_t( 01372 pdata->result__spare_2_sd1, 01373 2, 01374 pbuffer + 40); 01375 *(pbuffer + 42) = 01376 pdata->result__spare_3_sd1; 01377 *(pbuffer + 43) = 01378 pdata->result__thresh_info; 01379 LOG_FUNCTION_END(status); 01380 01381 01382 return status; 01383 } 01384 01385 01386 VL53L1_Error VL53L1_i2c_decode_system_results( 01387 uint16_t buf_size, 01388 uint8_t *pbuffer, 01389 VL53L1_system_results_t *pdata) 01390 { 01391 01392 01393 VL53L1_Error status = VL53L1_ERROR_NONE; 01394 01395 LOG_FUNCTION_START(""); 01396 01397 if (buf_size < VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES) 01398 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01399 01400 pdata->result__interrupt_status = 01401 (*(pbuffer + 0)) & 0x3F; 01402 pdata->result__range_status = 01403 (*(pbuffer + 1)); 01404 pdata->result__report_status = 01405 (*(pbuffer + 2)) & 0xF; 01406 pdata->result__stream_count = 01407 (*(pbuffer + 3)); 01408 pdata->result__dss_actual_effective_spads_sd0 = 01409 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)); 01410 pdata->result__peak_signal_count_rate_mcps_sd0 = 01411 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6)); 01412 pdata->result__ambient_count_rate_mcps_sd0 = 01413 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)); 01414 pdata->result__sigma_sd0 = 01415 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); 01416 pdata->result__phase_sd0 = 01417 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); 01418 pdata->result__final_crosstalk_corrected_range_mm_sd0 = 01419 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); 01420 pdata->result__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 = 01421 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); 01422 pdata->result__mm_inner_actual_effective_spads_sd0 = 01423 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)); 01424 pdata->result__mm_outer_actual_effective_spads_sd0 = 01425 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20)); 01426 pdata->result__avg_signal_count_rate_mcps_sd0 = 01427 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); 01428 pdata->result__dss_actual_effective_spads_sd1 = 01429 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); 01430 pdata->result__peak_signal_count_rate_mcps_sd1 = 01431 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26)); 01432 pdata->result__ambient_count_rate_mcps_sd1 = 01433 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28)); 01434 pdata->result__sigma_sd1 = 01435 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30)); 01436 pdata->result__phase_sd1 = 01437 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32)); 01438 pdata->result__final_crosstalk_corrected_range_mm_sd1 = 01439 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34)); 01440 pdata->result__spare_0_sd1 = 01441 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36)); 01442 pdata->result__spare_1_sd1 = 01443 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38)); 01444 pdata->result__spare_2_sd1 = 01445 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40)); 01446 pdata->result__spare_3_sd1 = 01447 (*(pbuffer + 42)); 01448 pdata->result__thresh_info = 01449 (*(pbuffer + 43)); 01450 01451 LOG_FUNCTION_END(status); 01452 01453 return status; 01454 } 01455 01456 01457 VL53L1_Error VL53L1_set_system_results( 01458 VL53L1_DEV Dev, 01459 VL53L1_system_results_t *pdata) 01460 { 01461 01462 01463 VL53L1_Error status = VL53L1_ERROR_NONE; 01464 uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES]; 01465 01466 LOG_FUNCTION_START(""); 01467 01468 if (status == VL53L1_ERROR_NONE) 01469 status = VL53L1_i2c_encode_system_results( 01470 pdata, 01471 VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES, 01472 comms_buffer); 01473 01474 if (status == VL53L1_ERROR_NONE) 01475 status = VL53L1_WriteMulti( 01476 Dev, 01477 VL53L1_RESULT__INTERRUPT_STATUS, 01478 comms_buffer, 01479 VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES); 01480 01481 LOG_FUNCTION_END(status); 01482 01483 return status; 01484 } 01485 01486 01487 VL53L1_Error VL53L1_get_system_results( 01488 VL53L1_DEV Dev, 01489 VL53L1_system_results_t *pdata) 01490 { 01491 01492 01493 VL53L1_Error status = VL53L1_ERROR_NONE; 01494 uint8_t comms_buffer[VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES]; 01495 01496 LOG_FUNCTION_START(""); 01497 01498 if (status == VL53L1_ERROR_NONE) 01499 status = VL53L1_ReadMulti( 01500 Dev, 01501 VL53L1_RESULT__INTERRUPT_STATUS, 01502 comms_buffer, 01503 VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES); 01504 01505 if (status == VL53L1_ERROR_NONE) 01506 status = VL53L1_i2c_decode_system_results( 01507 VL53L1_SYSTEM_RESULTS_I2C_SIZE_BYTES, 01508 comms_buffer, 01509 pdata); 01510 01511 LOG_FUNCTION_END(status); 01512 01513 return status; 01514 } 01515 01516 01517 VL53L1_Error VL53L1_i2c_encode_core_results( 01518 VL53L1_core_results_t *pdata, 01519 uint16_t buf_size, 01520 uint8_t *pbuffer) 01521 { 01522 01523 01524 VL53L1_Error status = VL53L1_ERROR_NONE; 01525 01526 LOG_FUNCTION_START(""); 01527 01528 if (buf_size < VL53L1_CORE_RESULTS_I2C_SIZE_BYTES) 01529 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01530 01531 VL53L1_i2c_encode_uint32_t( 01532 pdata->result_core__ambient_window_events_sd0, 01533 4, 01534 pbuffer + 0); 01535 VL53L1_i2c_encode_uint32_t( 01536 pdata->result_core__ranging_total_events_sd0, 01537 4, 01538 pbuffer + 4); 01539 VL53L1_i2c_encode_int32_t( 01540 pdata->result_core__signal_total_events_sd0, 01541 4, 01542 pbuffer + 8); 01543 VL53L1_i2c_encode_uint32_t( 01544 pdata->result_core__total_periods_elapsed_sd0, 01545 4, 01546 pbuffer + 12); 01547 VL53L1_i2c_encode_uint32_t( 01548 pdata->result_core__ambient_window_events_sd1, 01549 4, 01550 pbuffer + 16); 01551 VL53L1_i2c_encode_uint32_t( 01552 pdata->result_core__ranging_total_events_sd1, 01553 4, 01554 pbuffer + 20); 01555 VL53L1_i2c_encode_int32_t( 01556 pdata->result_core__signal_total_events_sd1, 01557 4, 01558 pbuffer + 24); 01559 VL53L1_i2c_encode_uint32_t( 01560 pdata->result_core__total_periods_elapsed_sd1, 01561 4, 01562 pbuffer + 28); 01563 *(pbuffer + 32) = 01564 pdata->result_core__spare_0; 01565 LOG_FUNCTION_END(status); 01566 01567 01568 return status; 01569 } 01570 01571 01572 VL53L1_Error VL53L1_i2c_decode_core_results( 01573 uint16_t buf_size, 01574 uint8_t *pbuffer, 01575 VL53L1_core_results_t *pdata) 01576 { 01577 01578 01579 VL53L1_Error status = VL53L1_ERROR_NONE; 01580 01581 LOG_FUNCTION_START(""); 01582 01583 if (buf_size < VL53L1_CORE_RESULTS_I2C_SIZE_BYTES) 01584 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01585 01586 pdata->result_core__ambient_window_events_sd0 = 01587 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0)); 01588 pdata->result_core__ranging_total_events_sd0 = 01589 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4)); 01590 pdata->result_core__signal_total_events_sd0 = 01591 (VL53L1_i2c_decode_int32_t(4, pbuffer + 8)); 01592 pdata->result_core__total_periods_elapsed_sd0 = 01593 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12)); 01594 pdata->result_core__ambient_window_events_sd1 = 01595 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16)); 01596 pdata->result_core__ranging_total_events_sd1 = 01597 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20)); 01598 pdata->result_core__signal_total_events_sd1 = 01599 (VL53L1_i2c_decode_int32_t(4, pbuffer + 24)); 01600 pdata->result_core__total_periods_elapsed_sd1 = 01601 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28)); 01602 pdata->result_core__spare_0 = 01603 (*(pbuffer + 32)); 01604 01605 LOG_FUNCTION_END(status); 01606 01607 return status; 01608 } 01609 01610 01611 VL53L1_Error VL53L1_set_core_results( 01612 VL53L1_DEV Dev, 01613 VL53L1_core_results_t *pdata) 01614 { 01615 01616 01617 VL53L1_Error status = VL53L1_ERROR_NONE; 01618 uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES]; 01619 01620 LOG_FUNCTION_START(""); 01621 01622 if (status == VL53L1_ERROR_NONE) 01623 status = VL53L1_i2c_encode_core_results( 01624 pdata, 01625 VL53L1_CORE_RESULTS_I2C_SIZE_BYTES, 01626 comms_buffer); 01627 01628 if (status == VL53L1_ERROR_NONE) 01629 status = VL53L1_disable_firmware(Dev); 01630 01631 if (status == VL53L1_ERROR_NONE) 01632 status = VL53L1_WriteMulti( 01633 Dev, 01634 VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, 01635 comms_buffer, 01636 VL53L1_CORE_RESULTS_I2C_SIZE_BYTES); 01637 01638 if (status == VL53L1_ERROR_NONE) 01639 status = VL53L1_enable_firmware(Dev); 01640 01641 LOG_FUNCTION_END(status); 01642 01643 return status; 01644 } 01645 01646 01647 VL53L1_Error VL53L1_get_core_results( 01648 VL53L1_DEV Dev, 01649 VL53L1_core_results_t *pdata) 01650 { 01651 01652 01653 VL53L1_Error status = VL53L1_ERROR_NONE; 01654 uint8_t comms_buffer[VL53L1_CORE_RESULTS_I2C_SIZE_BYTES]; 01655 01656 LOG_FUNCTION_START(""); 01657 01658 if (status == VL53L1_ERROR_NONE) 01659 status = VL53L1_ReadMulti( 01660 Dev, 01661 VL53L1_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, 01662 comms_buffer, 01663 VL53L1_CORE_RESULTS_I2C_SIZE_BYTES); 01664 01665 if (status == VL53L1_ERROR_NONE) 01666 status = VL53L1_i2c_decode_core_results( 01667 VL53L1_CORE_RESULTS_I2C_SIZE_BYTES, 01668 comms_buffer, 01669 pdata); 01670 01671 LOG_FUNCTION_END(status); 01672 01673 return status; 01674 } 01675 01676 01677 VL53L1_Error VL53L1_i2c_encode_debug_results( 01678 VL53L1_debug_results_t *pdata, 01679 uint16_t buf_size, 01680 uint8_t *pbuffer) 01681 { 01682 01683 01684 VL53L1_Error status = VL53L1_ERROR_NONE; 01685 01686 LOG_FUNCTION_START(""); 01687 01688 if (buf_size < VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES) 01689 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01690 01691 VL53L1_i2c_encode_uint16_t( 01692 pdata->phasecal_result__reference_phase, 01693 2, 01694 pbuffer + 0); 01695 *(pbuffer + 2) = 01696 pdata->phasecal_result__vcsel_start & 0x7F; 01697 *(pbuffer + 3) = 01698 pdata->ref_spad_char_result__num_actual_ref_spads & 0x3F; 01699 *(pbuffer + 4) = 01700 pdata->ref_spad_char_result__ref_location & 0x3; 01701 *(pbuffer + 5) = 01702 pdata->vhv_result__coldboot_status & 0x1; 01703 *(pbuffer + 6) = 01704 pdata->vhv_result__search_result & 0x3F; 01705 *(pbuffer + 7) = 01706 pdata->vhv_result__latest_setting & 0x3F; 01707 VL53L1_i2c_encode_uint16_t( 01708 pdata->result__osc_calibrate_val & 0x3FF, 01709 2, 01710 pbuffer + 8); 01711 *(pbuffer + 10) = 01712 pdata->ana_config__powerdown_go1 & 0x3; 01713 *(pbuffer + 11) = 01714 pdata->ana_config__ref_bg_ctrl & 0x3; 01715 *(pbuffer + 12) = 01716 pdata->ana_config__regdvdd1v2_ctrl & 0xF; 01717 *(pbuffer + 13) = 01718 pdata->ana_config__osc_slow_ctrl & 0x7; 01719 *(pbuffer + 14) = 01720 pdata->test_mode__status & 0x1; 01721 *(pbuffer + 15) = 01722 pdata->firmware__system_status & 0x3; 01723 *(pbuffer + 16) = 01724 pdata->firmware__mode_status; 01725 *(pbuffer + 17) = 01726 pdata->firmware__secondary_mode_status; 01727 VL53L1_i2c_encode_uint16_t( 01728 pdata->firmware__cal_repeat_rate_counter & 0xFFF, 01729 2, 01730 pbuffer + 18); 01731 VL53L1_i2c_encode_uint16_t( 01732 pdata->gph__system__thresh_high, 01733 2, 01734 pbuffer + 22); 01735 VL53L1_i2c_encode_uint16_t( 01736 pdata->gph__system__thresh_low, 01737 2, 01738 pbuffer + 24); 01739 *(pbuffer + 26) = 01740 pdata->gph__system__enable_xtalk_per_quadrant & 0x1; 01741 *(pbuffer + 27) = 01742 pdata->gph__spare_0 & 0x7; 01743 *(pbuffer + 28) = 01744 pdata->gph__sd_config__woi_sd0; 01745 *(pbuffer + 29) = 01746 pdata->gph__sd_config__woi_sd1; 01747 *(pbuffer + 30) = 01748 pdata->gph__sd_config__initial_phase_sd0 & 0x7F; 01749 *(pbuffer + 31) = 01750 pdata->gph__sd_config__initial_phase_sd1 & 0x7F; 01751 *(pbuffer + 32) = 01752 pdata->gph__sd_config__first_order_select & 0x3; 01753 *(pbuffer + 33) = 01754 pdata->gph__sd_config__quantifier & 0xF; 01755 *(pbuffer + 34) = 01756 pdata->gph__roi_config__user_roi_centre_spad; 01757 *(pbuffer + 35) = 01758 pdata->gph__roi_config__user_roi_requested_global_xy_size; 01759 *(pbuffer + 36) = 01760 pdata->gph__system__sequence_config; 01761 *(pbuffer + 37) = 01762 pdata->gph__gph_id & 0x1; 01763 *(pbuffer + 38) = 01764 pdata->system__interrupt_set & 0x3; 01765 *(pbuffer + 39) = 01766 pdata->interrupt_manager__enables & 0x1F; 01767 *(pbuffer + 40) = 01768 pdata->interrupt_manager__clear & 0x1F; 01769 *(pbuffer + 41) = 01770 pdata->interrupt_manager__status & 0x1F; 01771 *(pbuffer + 42) = 01772 pdata->mcu_to_host_bank__wr_access_en & 0x1; 01773 *(pbuffer + 43) = 01774 pdata->power_management__go1_reset_status & 0x1; 01775 *(pbuffer + 44) = 01776 pdata->pad_startup_mode__value_ro & 0x3; 01777 *(pbuffer + 45) = 01778 pdata->pad_startup_mode__value_ctrl & 0x3F; 01779 VL53L1_i2c_encode_uint32_t( 01780 pdata->pll_period_us & 0x3FFFF, 01781 4, 01782 pbuffer + 46); 01783 VL53L1_i2c_encode_uint32_t( 01784 pdata->interrupt_scheduler__data_out, 01785 4, 01786 pbuffer + 50); 01787 *(pbuffer + 54) = 01788 pdata->nvm_bist__complete & 0x1; 01789 *(pbuffer + 55) = 01790 pdata->nvm_bist__status & 0x1; 01791 LOG_FUNCTION_END(status); 01792 01793 01794 return status; 01795 } 01796 01797 01798 VL53L1_Error VL53L1_i2c_decode_debug_results( 01799 uint16_t buf_size, 01800 uint8_t *pbuffer, 01801 VL53L1_debug_results_t *pdata) 01802 { 01803 01804 01805 VL53L1_Error status = VL53L1_ERROR_NONE; 01806 01807 LOG_FUNCTION_START(""); 01808 01809 if (buf_size < VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES) 01810 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01811 01812 pdata->phasecal_result__reference_phase = 01813 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0)); 01814 pdata->phasecal_result__vcsel_start = 01815 (*(pbuffer + 2)) & 0x7F; 01816 pdata->ref_spad_char_result__num_actual_ref_spads = 01817 (*(pbuffer + 3)) & 0x3F; 01818 pdata->ref_spad_char_result__ref_location = 01819 (*(pbuffer + 4)) & 0x3; 01820 pdata->vhv_result__coldboot_status = 01821 (*(pbuffer + 5)) & 0x1; 01822 pdata->vhv_result__search_result = 01823 (*(pbuffer + 6)) & 0x3F; 01824 pdata->vhv_result__latest_setting = 01825 (*(pbuffer + 7)) & 0x3F; 01826 pdata->result__osc_calibrate_val = 01827 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)) & 0x3FF; 01828 pdata->ana_config__powerdown_go1 = 01829 (*(pbuffer + 10)) & 0x3; 01830 pdata->ana_config__ref_bg_ctrl = 01831 (*(pbuffer + 11)) & 0x3; 01832 pdata->ana_config__regdvdd1v2_ctrl = 01833 (*(pbuffer + 12)) & 0xF; 01834 pdata->ana_config__osc_slow_ctrl = 01835 (*(pbuffer + 13)) & 0x7; 01836 pdata->test_mode__status = 01837 (*(pbuffer + 14)) & 0x1; 01838 pdata->firmware__system_status = 01839 (*(pbuffer + 15)) & 0x3; 01840 pdata->firmware__mode_status = 01841 (*(pbuffer + 16)); 01842 pdata->firmware__secondary_mode_status = 01843 (*(pbuffer + 17)); 01844 pdata->firmware__cal_repeat_rate_counter = 01845 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)) & 0xFFF; 01846 pdata->gph__system__thresh_high = 01847 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); 01848 pdata->gph__system__thresh_low = 01849 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); 01850 pdata->gph__system__enable_xtalk_per_quadrant = 01851 (*(pbuffer + 26)) & 0x1; 01852 pdata->gph__spare_0 = 01853 (*(pbuffer + 27)) & 0x7; 01854 pdata->gph__sd_config__woi_sd0 = 01855 (*(pbuffer + 28)); 01856 pdata->gph__sd_config__woi_sd1 = 01857 (*(pbuffer + 29)); 01858 pdata->gph__sd_config__initial_phase_sd0 = 01859 (*(pbuffer + 30)) & 0x7F; 01860 pdata->gph__sd_config__initial_phase_sd1 = 01861 (*(pbuffer + 31)) & 0x7F; 01862 pdata->gph__sd_config__first_order_select = 01863 (*(pbuffer + 32)) & 0x3; 01864 pdata->gph__sd_config__quantifier = 01865 (*(pbuffer + 33)) & 0xF; 01866 pdata->gph__roi_config__user_roi_centre_spad = 01867 (*(pbuffer + 34)); 01868 pdata->gph__roi_config__user_roi_requested_global_xy_size = 01869 (*(pbuffer + 35)); 01870 pdata->gph__system__sequence_config = 01871 (*(pbuffer + 36)); 01872 pdata->gph__gph_id = 01873 (*(pbuffer + 37)) & 0x1; 01874 pdata->system__interrupt_set = 01875 (*(pbuffer + 38)) & 0x3; 01876 pdata->interrupt_manager__enables = 01877 (*(pbuffer + 39)) & 0x1F; 01878 pdata->interrupt_manager__clear = 01879 (*(pbuffer + 40)) & 0x1F; 01880 pdata->interrupt_manager__status = 01881 (*(pbuffer + 41)) & 0x1F; 01882 pdata->mcu_to_host_bank__wr_access_en = 01883 (*(pbuffer + 42)) & 0x1; 01884 pdata->power_management__go1_reset_status = 01885 (*(pbuffer + 43)) & 0x1; 01886 pdata->pad_startup_mode__value_ro = 01887 (*(pbuffer + 44)) & 0x3; 01888 pdata->pad_startup_mode__value_ctrl = 01889 (*(pbuffer + 45)) & 0x3F; 01890 pdata->pll_period_us = 01891 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 46)) & 0x3FFFF; 01892 pdata->interrupt_scheduler__data_out = 01893 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 50)); 01894 pdata->nvm_bist__complete = 01895 (*(pbuffer + 54)) & 0x1; 01896 pdata->nvm_bist__status = 01897 (*(pbuffer + 55)) & 0x1; 01898 01899 LOG_FUNCTION_END(status); 01900 01901 return status; 01902 } 01903 01904 01905 VL53L1_Error VL53L1_set_debug_results( 01906 VL53L1_DEV Dev, 01907 VL53L1_debug_results_t *pdata) 01908 { 01909 01910 01911 VL53L1_Error status = VL53L1_ERROR_NONE; 01912 uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES]; 01913 01914 LOG_FUNCTION_START(""); 01915 01916 if (status == VL53L1_ERROR_NONE) 01917 status = VL53L1_i2c_encode_debug_results( 01918 pdata, 01919 VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES, 01920 comms_buffer); 01921 01922 if (status == VL53L1_ERROR_NONE) 01923 status = VL53L1_disable_firmware(Dev); 01924 01925 if (status == VL53L1_ERROR_NONE) 01926 status = VL53L1_WriteMulti( 01927 Dev, 01928 VL53L1_PHASECAL_RESULT__REFERENCE_PHASE, 01929 comms_buffer, 01930 VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES); 01931 01932 if (status == VL53L1_ERROR_NONE) 01933 status = VL53L1_enable_firmware(Dev); 01934 01935 LOG_FUNCTION_END(status); 01936 01937 return status; 01938 } 01939 01940 01941 VL53L1_Error VL53L1_get_debug_results( 01942 VL53L1_DEV Dev, 01943 VL53L1_debug_results_t *pdata) 01944 { 01945 01946 01947 VL53L1_Error status = VL53L1_ERROR_NONE; 01948 uint8_t comms_buffer[VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES]; 01949 01950 LOG_FUNCTION_START(""); 01951 01952 if (status == VL53L1_ERROR_NONE) 01953 status = VL53L1_ReadMulti( 01954 Dev, 01955 VL53L1_PHASECAL_RESULT__REFERENCE_PHASE, 01956 comms_buffer, 01957 VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES); 01958 01959 if (status == VL53L1_ERROR_NONE) 01960 status = VL53L1_i2c_decode_debug_results( 01961 VL53L1_DEBUG_RESULTS_I2C_SIZE_BYTES, 01962 comms_buffer, 01963 pdata); 01964 01965 LOG_FUNCTION_END(status); 01966 01967 return status; 01968 } 01969 01970 01971 VL53L1_Error VL53L1_i2c_encode_nvm_copy_data( 01972 VL53L1_nvm_copy_data_t *pdata, 01973 uint16_t buf_size, 01974 uint8_t *pbuffer) 01975 { 01976 01977 01978 VL53L1_Error status = VL53L1_ERROR_NONE; 01979 01980 LOG_FUNCTION_START(""); 01981 01982 if (buf_size < VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES) 01983 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 01984 01985 *(pbuffer + 0) = 01986 pdata->identification__model_id; 01987 *(pbuffer + 1) = 01988 pdata->identification__module_type; 01989 *(pbuffer + 2) = 01990 pdata->identification__revision_id; 01991 VL53L1_i2c_encode_uint16_t( 01992 pdata->identification__module_id, 01993 2, 01994 pbuffer + 3); 01995 *(pbuffer + 5) = 01996 pdata->ana_config__fast_osc__trim_max & 0x7F; 01997 *(pbuffer + 6) = 01998 pdata->ana_config__fast_osc__freq_set & 0x7; 01999 *(pbuffer + 7) = 02000 pdata->ana_config__vcsel_trim & 0x7; 02001 *(pbuffer + 8) = 02002 pdata->ana_config__vcsel_selion & 0x3F; 02003 *(pbuffer + 9) = 02004 pdata->ana_config__vcsel_selion_max & 0x3F; 02005 *(pbuffer + 10) = 02006 pdata->protected_laser_safety__lock_bit & 0x1; 02007 *(pbuffer + 11) = 02008 pdata->laser_safety__key & 0x7F; 02009 *(pbuffer + 12) = 02010 pdata->laser_safety__key_ro & 0x1; 02011 *(pbuffer + 13) = 02012 pdata->laser_safety__clip & 0x3F; 02013 *(pbuffer + 14) = 02014 pdata->laser_safety__mult & 0x3F; 02015 *(pbuffer + 15) = 02016 pdata->global_config__spad_enables_rtn_0; 02017 *(pbuffer + 16) = 02018 pdata->global_config__spad_enables_rtn_1; 02019 *(pbuffer + 17) = 02020 pdata->global_config__spad_enables_rtn_2; 02021 *(pbuffer + 18) = 02022 pdata->global_config__spad_enables_rtn_3; 02023 *(pbuffer + 19) = 02024 pdata->global_config__spad_enables_rtn_4; 02025 *(pbuffer + 20) = 02026 pdata->global_config__spad_enables_rtn_5; 02027 *(pbuffer + 21) = 02028 pdata->global_config__spad_enables_rtn_6; 02029 *(pbuffer + 22) = 02030 pdata->global_config__spad_enables_rtn_7; 02031 *(pbuffer + 23) = 02032 pdata->global_config__spad_enables_rtn_8; 02033 *(pbuffer + 24) = 02034 pdata->global_config__spad_enables_rtn_9; 02035 *(pbuffer + 25) = 02036 pdata->global_config__spad_enables_rtn_10; 02037 *(pbuffer + 26) = 02038 pdata->global_config__spad_enables_rtn_11; 02039 *(pbuffer + 27) = 02040 pdata->global_config__spad_enables_rtn_12; 02041 *(pbuffer + 28) = 02042 pdata->global_config__spad_enables_rtn_13; 02043 *(pbuffer + 29) = 02044 pdata->global_config__spad_enables_rtn_14; 02045 *(pbuffer + 30) = 02046 pdata->global_config__spad_enables_rtn_15; 02047 *(pbuffer + 31) = 02048 pdata->global_config__spad_enables_rtn_16; 02049 *(pbuffer + 32) = 02050 pdata->global_config__spad_enables_rtn_17; 02051 *(pbuffer + 33) = 02052 pdata->global_config__spad_enables_rtn_18; 02053 *(pbuffer + 34) = 02054 pdata->global_config__spad_enables_rtn_19; 02055 *(pbuffer + 35) = 02056 pdata->global_config__spad_enables_rtn_20; 02057 *(pbuffer + 36) = 02058 pdata->global_config__spad_enables_rtn_21; 02059 *(pbuffer + 37) = 02060 pdata->global_config__spad_enables_rtn_22; 02061 *(pbuffer + 38) = 02062 pdata->global_config__spad_enables_rtn_23; 02063 *(pbuffer + 39) = 02064 pdata->global_config__spad_enables_rtn_24; 02065 *(pbuffer + 40) = 02066 pdata->global_config__spad_enables_rtn_25; 02067 *(pbuffer + 41) = 02068 pdata->global_config__spad_enables_rtn_26; 02069 *(pbuffer + 42) = 02070 pdata->global_config__spad_enables_rtn_27; 02071 *(pbuffer + 43) = 02072 pdata->global_config__spad_enables_rtn_28; 02073 *(pbuffer + 44) = 02074 pdata->global_config__spad_enables_rtn_29; 02075 *(pbuffer + 45) = 02076 pdata->global_config__spad_enables_rtn_30; 02077 *(pbuffer + 46) = 02078 pdata->global_config__spad_enables_rtn_31; 02079 *(pbuffer + 47) = 02080 pdata->roi_config__mode_roi_centre_spad; 02081 *(pbuffer + 48) = 02082 pdata->roi_config__mode_roi_xy_size; 02083 LOG_FUNCTION_END(status); 02084 02085 02086 return status; 02087 } 02088 02089 02090 VL53L1_Error VL53L1_i2c_decode_nvm_copy_data( 02091 uint16_t buf_size, 02092 uint8_t *pbuffer, 02093 VL53L1_nvm_copy_data_t *pdata) 02094 { 02095 02096 02097 VL53L1_Error status = VL53L1_ERROR_NONE; 02098 02099 LOG_FUNCTION_START(""); 02100 02101 if (buf_size < VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES) 02102 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02103 02104 pdata->identification__model_id = 02105 (*(pbuffer + 0)); 02106 pdata->identification__module_type = 02107 (*(pbuffer + 1)); 02108 pdata->identification__revision_id = 02109 (*(pbuffer + 2)); 02110 pdata->identification__module_id = 02111 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 3)); 02112 pdata->ana_config__fast_osc__trim_max = 02113 (*(pbuffer + 5)) & 0x7F; 02114 pdata->ana_config__fast_osc__freq_set = 02115 (*(pbuffer + 6)) & 0x7; 02116 pdata->ana_config__vcsel_trim = 02117 (*(pbuffer + 7)) & 0x7; 02118 pdata->ana_config__vcsel_selion = 02119 (*(pbuffer + 8)) & 0x3F; 02120 pdata->ana_config__vcsel_selion_max = 02121 (*(pbuffer + 9)) & 0x3F; 02122 pdata->protected_laser_safety__lock_bit = 02123 (*(pbuffer + 10)) & 0x1; 02124 pdata->laser_safety__key = 02125 (*(pbuffer + 11)) & 0x7F; 02126 pdata->laser_safety__key_ro = 02127 (*(pbuffer + 12)) & 0x1; 02128 pdata->laser_safety__clip = 02129 (*(pbuffer + 13)) & 0x3F; 02130 pdata->laser_safety__mult = 02131 (*(pbuffer + 14)) & 0x3F; 02132 pdata->global_config__spad_enables_rtn_0 = 02133 (*(pbuffer + 15)); 02134 pdata->global_config__spad_enables_rtn_1 = 02135 (*(pbuffer + 16)); 02136 pdata->global_config__spad_enables_rtn_2 = 02137 (*(pbuffer + 17)); 02138 pdata->global_config__spad_enables_rtn_3 = 02139 (*(pbuffer + 18)); 02140 pdata->global_config__spad_enables_rtn_4 = 02141 (*(pbuffer + 19)); 02142 pdata->global_config__spad_enables_rtn_5 = 02143 (*(pbuffer + 20)); 02144 pdata->global_config__spad_enables_rtn_6 = 02145 (*(pbuffer + 21)); 02146 pdata->global_config__spad_enables_rtn_7 = 02147 (*(pbuffer + 22)); 02148 pdata->global_config__spad_enables_rtn_8 = 02149 (*(pbuffer + 23)); 02150 pdata->global_config__spad_enables_rtn_9 = 02151 (*(pbuffer + 24)); 02152 pdata->global_config__spad_enables_rtn_10 = 02153 (*(pbuffer + 25)); 02154 pdata->global_config__spad_enables_rtn_11 = 02155 (*(pbuffer + 26)); 02156 pdata->global_config__spad_enables_rtn_12 = 02157 (*(pbuffer + 27)); 02158 pdata->global_config__spad_enables_rtn_13 = 02159 (*(pbuffer + 28)); 02160 pdata->global_config__spad_enables_rtn_14 = 02161 (*(pbuffer + 29)); 02162 pdata->global_config__spad_enables_rtn_15 = 02163 (*(pbuffer + 30)); 02164 pdata->global_config__spad_enables_rtn_16 = 02165 (*(pbuffer + 31)); 02166 pdata->global_config__spad_enables_rtn_17 = 02167 (*(pbuffer + 32)); 02168 pdata->global_config__spad_enables_rtn_18 = 02169 (*(pbuffer + 33)); 02170 pdata->global_config__spad_enables_rtn_19 = 02171 (*(pbuffer + 34)); 02172 pdata->global_config__spad_enables_rtn_20 = 02173 (*(pbuffer + 35)); 02174 pdata->global_config__spad_enables_rtn_21 = 02175 (*(pbuffer + 36)); 02176 pdata->global_config__spad_enables_rtn_22 = 02177 (*(pbuffer + 37)); 02178 pdata->global_config__spad_enables_rtn_23 = 02179 (*(pbuffer + 38)); 02180 pdata->global_config__spad_enables_rtn_24 = 02181 (*(pbuffer + 39)); 02182 pdata->global_config__spad_enables_rtn_25 = 02183 (*(pbuffer + 40)); 02184 pdata->global_config__spad_enables_rtn_26 = 02185 (*(pbuffer + 41)); 02186 pdata->global_config__spad_enables_rtn_27 = 02187 (*(pbuffer + 42)); 02188 pdata->global_config__spad_enables_rtn_28 = 02189 (*(pbuffer + 43)); 02190 pdata->global_config__spad_enables_rtn_29 = 02191 (*(pbuffer + 44)); 02192 pdata->global_config__spad_enables_rtn_30 = 02193 (*(pbuffer + 45)); 02194 pdata->global_config__spad_enables_rtn_31 = 02195 (*(pbuffer + 46)); 02196 pdata->roi_config__mode_roi_centre_spad = 02197 (*(pbuffer + 47)); 02198 pdata->roi_config__mode_roi_xy_size = 02199 (*(pbuffer + 48)); 02200 02201 LOG_FUNCTION_END(status); 02202 02203 return status; 02204 } 02205 02206 02207 VL53L1_Error VL53L1_set_nvm_copy_data( 02208 VL53L1_DEV Dev, 02209 VL53L1_nvm_copy_data_t *pdata) 02210 { 02211 02212 02213 VL53L1_Error status = VL53L1_ERROR_NONE; 02214 uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES]; 02215 02216 LOG_FUNCTION_START(""); 02217 02218 if (status == VL53L1_ERROR_NONE) 02219 status = VL53L1_i2c_encode_nvm_copy_data( 02220 pdata, 02221 VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES, 02222 comms_buffer); 02223 02224 if (status == VL53L1_ERROR_NONE) 02225 status = VL53L1_disable_firmware(Dev); 02226 02227 if (status == VL53L1_ERROR_NONE) 02228 status = VL53L1_WriteMulti( 02229 Dev, 02230 VL53L1_IDENTIFICATION__MODEL_ID, 02231 comms_buffer, 02232 VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES); 02233 02234 if (status == VL53L1_ERROR_NONE) 02235 status = VL53L1_enable_firmware(Dev); 02236 02237 LOG_FUNCTION_END(status); 02238 02239 return status; 02240 } 02241 02242 02243 VL53L1_Error VL53L1_get_nvm_copy_data( 02244 VL53L1_DEV Dev, 02245 VL53L1_nvm_copy_data_t *pdata) 02246 { 02247 02248 02249 VL53L1_Error status = VL53L1_ERROR_NONE; 02250 uint8_t comms_buffer[VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES]; 02251 02252 LOG_FUNCTION_START(""); 02253 02254 if (status == VL53L1_ERROR_NONE) 02255 status = VL53L1_ReadMulti( 02256 Dev, 02257 VL53L1_IDENTIFICATION__MODEL_ID, 02258 comms_buffer, 02259 VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES); 02260 02261 if (status == VL53L1_ERROR_NONE) 02262 status = VL53L1_i2c_decode_nvm_copy_data( 02263 VL53L1_NVM_COPY_DATA_I2C_SIZE_BYTES, 02264 comms_buffer, 02265 pdata); 02266 02267 LOG_FUNCTION_END(status); 02268 02269 return status; 02270 } 02271 02272 02273 VL53L1_Error VL53L1_i2c_encode_prev_shadow_system_results( 02274 VL53L1_prev_shadow_system_results_t *pdata, 02275 uint16_t buf_size, 02276 uint8_t *pbuffer) 02277 { 02278 02279 02280 VL53L1_Error status = VL53L1_ERROR_NONE; 02281 02282 LOG_FUNCTION_START(""); 02283 02284 if (buf_size < VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) 02285 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02286 02287 *(pbuffer + 0) = 02288 pdata->prev_shadow_result__interrupt_status & 0x3F; 02289 *(pbuffer + 1) = 02290 pdata->prev_shadow_result__range_status; 02291 *(pbuffer + 2) = 02292 pdata->prev_shadow_result__report_status & 0xF; 02293 *(pbuffer + 3) = 02294 pdata->prev_shadow_result__stream_count; 02295 VL53L1_i2c_encode_uint16_t( 02296 pdata->prev_shadow_result__dss_actual_effective_spads_sd0, 02297 2, 02298 pbuffer + 4); 02299 VL53L1_i2c_encode_uint16_t( 02300 pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0, 02301 2, 02302 pbuffer + 6); 02303 VL53L1_i2c_encode_uint16_t( 02304 pdata->prev_shadow_result__ambient_count_rate_mcps_sd0, 02305 2, 02306 pbuffer + 8); 02307 VL53L1_i2c_encode_uint16_t( 02308 pdata->prev_shadow_result__sigma_sd0, 02309 2, 02310 pbuffer + 10); 02311 VL53L1_i2c_encode_uint16_t( 02312 pdata->prev_shadow_result__phase_sd0, 02313 2, 02314 pbuffer + 12); 02315 VL53L1_i2c_encode_uint16_t( 02316 pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0, 02317 2, 02318 pbuffer + 14); 02319 VL53L1_i2c_encode_uint16_t( 02320 pdata->psr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0, 02321 2, 02322 pbuffer + 16); 02323 VL53L1_i2c_encode_uint16_t( 02324 pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0, 02325 2, 02326 pbuffer + 18); 02327 VL53L1_i2c_encode_uint16_t( 02328 pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0, 02329 2, 02330 pbuffer + 20); 02331 VL53L1_i2c_encode_uint16_t( 02332 pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0, 02333 2, 02334 pbuffer + 22); 02335 VL53L1_i2c_encode_uint16_t( 02336 pdata->prev_shadow_result__dss_actual_effective_spads_sd1, 02337 2, 02338 pbuffer + 24); 02339 VL53L1_i2c_encode_uint16_t( 02340 pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1, 02341 2, 02342 pbuffer + 26); 02343 VL53L1_i2c_encode_uint16_t( 02344 pdata->prev_shadow_result__ambient_count_rate_mcps_sd1, 02345 2, 02346 pbuffer + 28); 02347 VL53L1_i2c_encode_uint16_t( 02348 pdata->prev_shadow_result__sigma_sd1, 02349 2, 02350 pbuffer + 30); 02351 VL53L1_i2c_encode_uint16_t( 02352 pdata->prev_shadow_result__phase_sd1, 02353 2, 02354 pbuffer + 32); 02355 VL53L1_i2c_encode_uint16_t( 02356 pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1, 02357 2, 02358 pbuffer + 34); 02359 VL53L1_i2c_encode_uint16_t( 02360 pdata->prev_shadow_result__spare_0_sd1, 02361 2, 02362 pbuffer + 36); 02363 VL53L1_i2c_encode_uint16_t( 02364 pdata->prev_shadow_result__spare_1_sd1, 02365 2, 02366 pbuffer + 38); 02367 VL53L1_i2c_encode_uint16_t( 02368 pdata->prev_shadow_result__spare_2_sd1, 02369 2, 02370 pbuffer + 40); 02371 VL53L1_i2c_encode_uint16_t( 02372 pdata->prev_shadow_result__spare_3_sd1, 02373 2, 02374 pbuffer + 42); 02375 LOG_FUNCTION_END(status); 02376 02377 02378 return status; 02379 } 02380 02381 02382 VL53L1_Error VL53L1_i2c_decode_prev_shadow_system_results( 02383 uint16_t buf_size, 02384 uint8_t *pbuffer, 02385 VL53L1_prev_shadow_system_results_t *pdata) 02386 { 02387 02388 02389 VL53L1_Error status = VL53L1_ERROR_NONE; 02390 02391 LOG_FUNCTION_START(""); 02392 02393 if (buf_size < VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) 02394 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02395 02396 pdata->prev_shadow_result__interrupt_status = 02397 (*(pbuffer + 0)) & 0x3F; 02398 pdata->prev_shadow_result__range_status = 02399 (*(pbuffer + 1)); 02400 pdata->prev_shadow_result__report_status = 02401 (*(pbuffer + 2)) & 0xF; 02402 pdata->prev_shadow_result__stream_count = 02403 (*(pbuffer + 3)); 02404 pdata->prev_shadow_result__dss_actual_effective_spads_sd0 = 02405 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 4)); 02406 pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd0 = 02407 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6)); 02408 pdata->prev_shadow_result__ambient_count_rate_mcps_sd0 = 02409 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)); 02410 pdata->prev_shadow_result__sigma_sd0 = 02411 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); 02412 pdata->prev_shadow_result__phase_sd0 = 02413 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); 02414 pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd0 = 02415 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); 02416 pdata->psr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 = 02417 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); 02418 pdata->prev_shadow_result__mm_inner_actual_effective_spads_sd0 = 02419 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)); 02420 pdata->prev_shadow_result__mm_outer_actual_effective_spads_sd0 = 02421 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20)); 02422 pdata->prev_shadow_result__avg_signal_count_rate_mcps_sd0 = 02423 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); 02424 pdata->prev_shadow_result__dss_actual_effective_spads_sd1 = 02425 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); 02426 pdata->prev_shadow_result__peak_signal_count_rate_mcps_sd1 = 02427 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26)); 02428 pdata->prev_shadow_result__ambient_count_rate_mcps_sd1 = 02429 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28)); 02430 pdata->prev_shadow_result__sigma_sd1 = 02431 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30)); 02432 pdata->prev_shadow_result__phase_sd1 = 02433 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32)); 02434 pdata->prev_shadow_result__final_crosstalk_corrected_range_mm_sd1 = 02435 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34)); 02436 pdata->prev_shadow_result__spare_0_sd1 = 02437 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36)); 02438 pdata->prev_shadow_result__spare_1_sd1 = 02439 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38)); 02440 pdata->prev_shadow_result__spare_2_sd1 = 02441 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40)); 02442 pdata->prev_shadow_result__spare_3_sd1 = 02443 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42)); 02444 02445 LOG_FUNCTION_END(status); 02446 02447 return status; 02448 } 02449 02450 02451 VL53L1_Error VL53L1_set_prev_shadow_system_results( 02452 VL53L1_DEV Dev, 02453 VL53L1_prev_shadow_system_results_t *pdata) 02454 { 02455 02456 02457 VL53L1_Error status = VL53L1_ERROR_NONE; 02458 uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; 02459 02460 LOG_FUNCTION_START(""); 02461 02462 if (status == VL53L1_ERROR_NONE) 02463 status = VL53L1_i2c_encode_prev_shadow_system_results( 02464 pdata, 02465 VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, 02466 comms_buffer); 02467 02468 if (status == VL53L1_ERROR_NONE) 02469 status = VL53L1_disable_firmware(Dev); 02470 02471 if (status == VL53L1_ERROR_NONE) 02472 status = VL53L1_WriteMulti( 02473 Dev, 02474 VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS, 02475 comms_buffer, 02476 VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); 02477 02478 if (status == VL53L1_ERROR_NONE) 02479 status = VL53L1_enable_firmware(Dev); 02480 02481 LOG_FUNCTION_END(status); 02482 02483 return status; 02484 } 02485 02486 02487 VL53L1_Error VL53L1_get_prev_shadow_system_results( 02488 VL53L1_DEV Dev, 02489 VL53L1_prev_shadow_system_results_t *pdata) 02490 { 02491 02492 02493 VL53L1_Error status = VL53L1_ERROR_NONE; 02494 uint8_t comms_buffer[VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; 02495 02496 LOG_FUNCTION_START(""); 02497 02498 if (status == VL53L1_ERROR_NONE) 02499 status = VL53L1_disable_firmware(Dev); 02500 02501 if (status == VL53L1_ERROR_NONE) 02502 status = VL53L1_ReadMulti( 02503 Dev, 02504 VL53L1_PREV_SHADOW_RESULT__INTERRUPT_STATUS, 02505 comms_buffer, 02506 VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); 02507 02508 if (status == VL53L1_ERROR_NONE) 02509 status = VL53L1_enable_firmware(Dev); 02510 02511 if (status == VL53L1_ERROR_NONE) 02512 status = VL53L1_i2c_decode_prev_shadow_system_results( 02513 VL53L1_PREV_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, 02514 comms_buffer, 02515 pdata); 02516 02517 LOG_FUNCTION_END(status); 02518 02519 return status; 02520 } 02521 02522 02523 VL53L1_Error VL53L1_i2c_encode_prev_shadow_core_results( 02524 VL53L1_prev_shadow_core_results_t *pdata, 02525 uint16_t buf_size, 02526 uint8_t *pbuffer) 02527 { 02528 02529 02530 VL53L1_Error status = VL53L1_ERROR_NONE; 02531 02532 LOG_FUNCTION_START(""); 02533 02534 if (buf_size < VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) 02535 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02536 02537 VL53L1_i2c_encode_uint32_t( 02538 pdata->prev_shadow_result_core__ambient_window_events_sd0, 02539 4, 02540 pbuffer + 0); 02541 VL53L1_i2c_encode_uint32_t( 02542 pdata->prev_shadow_result_core__ranging_total_events_sd0, 02543 4, 02544 pbuffer + 4); 02545 VL53L1_i2c_encode_int32_t( 02546 pdata->prev_shadow_result_core__signal_total_events_sd0, 02547 4, 02548 pbuffer + 8); 02549 VL53L1_i2c_encode_uint32_t( 02550 pdata->prev_shadow_result_core__total_periods_elapsed_sd0, 02551 4, 02552 pbuffer + 12); 02553 VL53L1_i2c_encode_uint32_t( 02554 pdata->prev_shadow_result_core__ambient_window_events_sd1, 02555 4, 02556 pbuffer + 16); 02557 VL53L1_i2c_encode_uint32_t( 02558 pdata->prev_shadow_result_core__ranging_total_events_sd1, 02559 4, 02560 pbuffer + 20); 02561 VL53L1_i2c_encode_int32_t( 02562 pdata->prev_shadow_result_core__signal_total_events_sd1, 02563 4, 02564 pbuffer + 24); 02565 VL53L1_i2c_encode_uint32_t( 02566 pdata->prev_shadow_result_core__total_periods_elapsed_sd1, 02567 4, 02568 pbuffer + 28); 02569 *(pbuffer + 32) = 02570 pdata->prev_shadow_result_core__spare_0; 02571 LOG_FUNCTION_END(status); 02572 02573 02574 return status; 02575 } 02576 02577 02578 VL53L1_Error VL53L1_i2c_decode_prev_shadow_core_results( 02579 uint16_t buf_size, 02580 uint8_t *pbuffer, 02581 VL53L1_prev_shadow_core_results_t *pdata) 02582 { 02583 02584 02585 VL53L1_Error status = VL53L1_ERROR_NONE; 02586 02587 LOG_FUNCTION_START(""); 02588 02589 if (buf_size < VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) 02590 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02591 02592 pdata->prev_shadow_result_core__ambient_window_events_sd0 = 02593 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0)); 02594 pdata->prev_shadow_result_core__ranging_total_events_sd0 = 02595 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4)); 02596 pdata->prev_shadow_result_core__signal_total_events_sd0 = 02597 (VL53L1_i2c_decode_int32_t(4, pbuffer + 8)); 02598 pdata->prev_shadow_result_core__total_periods_elapsed_sd0 = 02599 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12)); 02600 pdata->prev_shadow_result_core__ambient_window_events_sd1 = 02601 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16)); 02602 pdata->prev_shadow_result_core__ranging_total_events_sd1 = 02603 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20)); 02604 pdata->prev_shadow_result_core__signal_total_events_sd1 = 02605 (VL53L1_i2c_decode_int32_t(4, pbuffer + 24)); 02606 pdata->prev_shadow_result_core__total_periods_elapsed_sd1 = 02607 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28)); 02608 pdata->prev_shadow_result_core__spare_0 = 02609 (*(pbuffer + 32)); 02610 02611 LOG_FUNCTION_END(status); 02612 02613 return status; 02614 } 02615 02616 02617 VL53L1_Error VL53L1_set_prev_shadow_core_results( 02618 VL53L1_DEV Dev, 02619 VL53L1_prev_shadow_core_results_t *pdata) 02620 { 02621 02622 02623 VL53L1_Error status = VL53L1_ERROR_NONE; 02624 uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; 02625 02626 LOG_FUNCTION_START(""); 02627 02628 if (status == VL53L1_ERROR_NONE) 02629 status = VL53L1_i2c_encode_prev_shadow_core_results( 02630 pdata, 02631 VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, 02632 comms_buffer); 02633 02634 if (status == VL53L1_ERROR_NONE) 02635 status = VL53L1_disable_firmware(Dev); 02636 02637 if (status == VL53L1_ERROR_NONE) 02638 status = VL53L1_WriteMulti( 02639 Dev, 02640 VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, 02641 comms_buffer, 02642 VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); 02643 02644 if (status == VL53L1_ERROR_NONE) 02645 status = VL53L1_enable_firmware(Dev); 02646 02647 LOG_FUNCTION_END(status); 02648 02649 return status; 02650 } 02651 02652 02653 VL53L1_Error VL53L1_get_prev_shadow_core_results( 02654 VL53L1_DEV Dev, 02655 VL53L1_prev_shadow_core_results_t *pdata) 02656 { 02657 02658 02659 VL53L1_Error status = VL53L1_ERROR_NONE; 02660 uint8_t comms_buffer[VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; 02661 02662 LOG_FUNCTION_START(""); 02663 02664 if (status == VL53L1_ERROR_NONE) 02665 status = VL53L1_disable_firmware(Dev); 02666 02667 if (status == VL53L1_ERROR_NONE) 02668 status = VL53L1_ReadMulti( 02669 Dev, 02670 VL53L1_PREV_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, 02671 comms_buffer, 02672 VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); 02673 02674 if (status == VL53L1_ERROR_NONE) 02675 status = VL53L1_enable_firmware(Dev); 02676 02677 if (status == VL53L1_ERROR_NONE) 02678 status = VL53L1_i2c_decode_prev_shadow_core_results( 02679 VL53L1_PREV_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, 02680 comms_buffer, 02681 pdata); 02682 02683 LOG_FUNCTION_END(status); 02684 02685 return status; 02686 } 02687 02688 02689 VL53L1_Error VL53L1_i2c_encode_patch_debug( 02690 VL53L1_patch_debug_t *pdata, 02691 uint16_t buf_size, 02692 uint8_t *pbuffer) 02693 { 02694 02695 02696 VL53L1_Error status = VL53L1_ERROR_NONE; 02697 02698 LOG_FUNCTION_START(""); 02699 02700 if (buf_size < VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES) 02701 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02702 02703 *(pbuffer + 0) = 02704 pdata->result__debug_status; 02705 *(pbuffer + 1) = 02706 pdata->result__debug_stage; 02707 LOG_FUNCTION_END(status); 02708 02709 02710 return status; 02711 } 02712 02713 02714 VL53L1_Error VL53L1_i2c_decode_patch_debug( 02715 uint16_t buf_size, 02716 uint8_t *pbuffer, 02717 VL53L1_patch_debug_t *pdata) 02718 { 02719 02720 02721 VL53L1_Error status = VL53L1_ERROR_NONE; 02722 02723 LOG_FUNCTION_START(""); 02724 02725 if (buf_size < VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES) 02726 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02727 02728 pdata->result__debug_status = 02729 (*(pbuffer + 0)); 02730 pdata->result__debug_stage = 02731 (*(pbuffer + 1)); 02732 02733 LOG_FUNCTION_END(status); 02734 02735 return status; 02736 } 02737 02738 02739 VL53L1_Error VL53L1_set_patch_debug( 02740 VL53L1_DEV Dev, 02741 VL53L1_patch_debug_t *pdata) 02742 { 02743 02744 02745 VL53L1_Error status = VL53L1_ERROR_NONE; 02746 uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES]; 02747 02748 LOG_FUNCTION_START(""); 02749 02750 if (status == VL53L1_ERROR_NONE) 02751 status = VL53L1_i2c_encode_patch_debug( 02752 pdata, 02753 VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES, 02754 comms_buffer); 02755 02756 if (status == VL53L1_ERROR_NONE) 02757 status = VL53L1_disable_firmware(Dev); 02758 02759 if (status == VL53L1_ERROR_NONE) 02760 status = VL53L1_WriteMulti( 02761 Dev, 02762 VL53L1_RESULT__DEBUG_STATUS, 02763 comms_buffer, 02764 VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES); 02765 02766 if (status == VL53L1_ERROR_NONE) 02767 status = VL53L1_enable_firmware(Dev); 02768 02769 LOG_FUNCTION_END(status); 02770 02771 return status; 02772 } 02773 02774 02775 VL53L1_Error VL53L1_get_patch_debug( 02776 VL53L1_DEV Dev, 02777 VL53L1_patch_debug_t *pdata) 02778 { 02779 02780 02781 VL53L1_Error status = VL53L1_ERROR_NONE; 02782 uint8_t comms_buffer[VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES]; 02783 02784 LOG_FUNCTION_START(""); 02785 02786 if (status == VL53L1_ERROR_NONE) 02787 status = VL53L1_disable_firmware(Dev); 02788 02789 if (status == VL53L1_ERROR_NONE) 02790 status = VL53L1_ReadMulti( 02791 Dev, 02792 VL53L1_RESULT__DEBUG_STATUS, 02793 comms_buffer, 02794 VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES); 02795 02796 if (status == VL53L1_ERROR_NONE) 02797 status = VL53L1_enable_firmware(Dev); 02798 02799 if (status == VL53L1_ERROR_NONE) 02800 status = VL53L1_i2c_decode_patch_debug( 02801 VL53L1_PATCH_DEBUG_I2C_SIZE_BYTES, 02802 comms_buffer, 02803 pdata); 02804 02805 LOG_FUNCTION_END(status); 02806 02807 return status; 02808 } 02809 02810 02811 VL53L1_Error VL53L1_i2c_encode_gph_general_config( 02812 VL53L1_gph_general_config_t *pdata, 02813 uint16_t buf_size, 02814 uint8_t *pbuffer) 02815 { 02816 02817 02818 VL53L1_Error status = VL53L1_ERROR_NONE; 02819 02820 LOG_FUNCTION_START(""); 02821 02822 if (buf_size < VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES) 02823 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02824 02825 VL53L1_i2c_encode_uint16_t( 02826 pdata->gph__system__thresh_rate_high, 02827 2, 02828 pbuffer + 0); 02829 VL53L1_i2c_encode_uint16_t( 02830 pdata->gph__system__thresh_rate_low, 02831 2, 02832 pbuffer + 2); 02833 *(pbuffer + 4) = 02834 pdata->gph__system__interrupt_config_gpio; 02835 LOG_FUNCTION_END(status); 02836 02837 02838 return status; 02839 } 02840 02841 02842 VL53L1_Error VL53L1_i2c_decode_gph_general_config( 02843 uint16_t buf_size, 02844 uint8_t *pbuffer, 02845 VL53L1_gph_general_config_t *pdata) 02846 { 02847 02848 02849 VL53L1_Error status = VL53L1_ERROR_NONE; 02850 02851 LOG_FUNCTION_START(""); 02852 02853 if (buf_size < VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES) 02854 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02855 02856 pdata->gph__system__thresh_rate_high = 02857 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 0)); 02858 pdata->gph__system__thresh_rate_low = 02859 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 2)); 02860 pdata->gph__system__interrupt_config_gpio = 02861 (*(pbuffer + 4)); 02862 02863 LOG_FUNCTION_END(status); 02864 02865 return status; 02866 } 02867 02868 02869 VL53L1_Error VL53L1_set_gph_general_config( 02870 VL53L1_DEV Dev, 02871 VL53L1_gph_general_config_t *pdata) 02872 { 02873 02874 02875 VL53L1_Error status = VL53L1_ERROR_NONE; 02876 uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES]; 02877 02878 LOG_FUNCTION_START(""); 02879 02880 if (status == VL53L1_ERROR_NONE) 02881 status = VL53L1_i2c_encode_gph_general_config( 02882 pdata, 02883 VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES, 02884 comms_buffer); 02885 02886 if (status == VL53L1_ERROR_NONE) 02887 status = VL53L1_disable_firmware(Dev); 02888 02889 if (status == VL53L1_ERROR_NONE) 02890 status = VL53L1_WriteMulti( 02891 Dev, 02892 VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH, 02893 comms_buffer, 02894 VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES); 02895 02896 if (status == VL53L1_ERROR_NONE) 02897 status = VL53L1_enable_firmware(Dev); 02898 02899 LOG_FUNCTION_END(status); 02900 02901 return status; 02902 } 02903 02904 02905 VL53L1_Error VL53L1_get_gph_general_config( 02906 VL53L1_DEV Dev, 02907 VL53L1_gph_general_config_t *pdata) 02908 { 02909 02910 02911 VL53L1_Error status = VL53L1_ERROR_NONE; 02912 uint8_t comms_buffer[VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES]; 02913 02914 LOG_FUNCTION_START(""); 02915 02916 if (status == VL53L1_ERROR_NONE) 02917 status = VL53L1_disable_firmware(Dev); 02918 02919 if (status == VL53L1_ERROR_NONE) 02920 status = VL53L1_ReadMulti( 02921 Dev, 02922 VL53L1_GPH__SYSTEM__THRESH_RATE_HIGH, 02923 comms_buffer, 02924 VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES); 02925 02926 if (status == VL53L1_ERROR_NONE) 02927 status = VL53L1_enable_firmware(Dev); 02928 02929 if (status == VL53L1_ERROR_NONE) 02930 status = VL53L1_i2c_decode_gph_general_config( 02931 VL53L1_GPH_GENERAL_CONFIG_I2C_SIZE_BYTES, 02932 comms_buffer, 02933 pdata); 02934 02935 LOG_FUNCTION_END(status); 02936 02937 return status; 02938 } 02939 02940 02941 VL53L1_Error VL53L1_i2c_encode_gph_static_config( 02942 VL53L1_gph_static_config_t *pdata, 02943 uint16_t buf_size, 02944 uint8_t *pbuffer) 02945 { 02946 02947 02948 VL53L1_Error status = VL53L1_ERROR_NONE; 02949 02950 LOG_FUNCTION_START(""); 02951 02952 if (buf_size < VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES) 02953 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02954 02955 *(pbuffer + 0) = 02956 pdata->gph__dss_config__roi_mode_control & 0x7; 02957 VL53L1_i2c_encode_uint16_t( 02958 pdata->gph__dss_config__manual_effective_spads_select, 02959 2, 02960 pbuffer + 1); 02961 *(pbuffer + 3) = 02962 pdata->gph__dss_config__manual_block_select; 02963 *(pbuffer + 4) = 02964 pdata->gph__dss_config__max_spads_limit; 02965 *(pbuffer + 5) = 02966 pdata->gph__dss_config__min_spads_limit; 02967 LOG_FUNCTION_END(status); 02968 02969 02970 return status; 02971 } 02972 02973 02974 VL53L1_Error VL53L1_i2c_decode_gph_static_config( 02975 uint16_t buf_size, 02976 uint8_t *pbuffer, 02977 VL53L1_gph_static_config_t *pdata) 02978 { 02979 02980 02981 VL53L1_Error status = VL53L1_ERROR_NONE; 02982 02983 LOG_FUNCTION_START(""); 02984 02985 if (buf_size < VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES) 02986 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 02987 02988 pdata->gph__dss_config__roi_mode_control = 02989 (*(pbuffer + 0)) & 0x7; 02990 pdata->gph__dss_config__manual_effective_spads_select = 02991 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 1)); 02992 pdata->gph__dss_config__manual_block_select = 02993 (*(pbuffer + 3)); 02994 pdata->gph__dss_config__max_spads_limit = 02995 (*(pbuffer + 4)); 02996 pdata->gph__dss_config__min_spads_limit = 02997 (*(pbuffer + 5)); 02998 02999 LOG_FUNCTION_END(status); 03000 03001 return status; 03002 } 03003 03004 03005 VL53L1_Error VL53L1_set_gph_static_config( 03006 VL53L1_DEV Dev, 03007 VL53L1_gph_static_config_t *pdata) 03008 { 03009 03010 03011 VL53L1_Error status = VL53L1_ERROR_NONE; 03012 uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES]; 03013 03014 LOG_FUNCTION_START(""); 03015 03016 if (status == VL53L1_ERROR_NONE) 03017 status = VL53L1_i2c_encode_gph_static_config( 03018 pdata, 03019 VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES, 03020 comms_buffer); 03021 03022 if (status == VL53L1_ERROR_NONE) 03023 status = VL53L1_disable_firmware(Dev); 03024 03025 if (status == VL53L1_ERROR_NONE) 03026 status = VL53L1_WriteMulti( 03027 Dev, 03028 VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL, 03029 comms_buffer, 03030 VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES); 03031 03032 if (status == VL53L1_ERROR_NONE) 03033 status = VL53L1_enable_firmware(Dev); 03034 03035 LOG_FUNCTION_END(status); 03036 03037 return status; 03038 } 03039 03040 03041 VL53L1_Error VL53L1_get_gph_static_config( 03042 VL53L1_DEV Dev, 03043 VL53L1_gph_static_config_t *pdata) 03044 { 03045 03046 03047 VL53L1_Error status = VL53L1_ERROR_NONE; 03048 uint8_t comms_buffer[VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES]; 03049 03050 LOG_FUNCTION_START(""); 03051 03052 if (status == VL53L1_ERROR_NONE) 03053 status = VL53L1_disable_firmware(Dev); 03054 03055 if (status == VL53L1_ERROR_NONE) 03056 status = VL53L1_ReadMulti( 03057 Dev, 03058 VL53L1_GPH__DSS_CONFIG__ROI_MODE_CONTROL, 03059 comms_buffer, 03060 VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES); 03061 03062 if (status == VL53L1_ERROR_NONE) 03063 status = VL53L1_enable_firmware(Dev); 03064 03065 if (status == VL53L1_ERROR_NONE) 03066 status = VL53L1_i2c_decode_gph_static_config( 03067 VL53L1_GPH_STATIC_CONFIG_I2C_SIZE_BYTES, 03068 comms_buffer, 03069 pdata); 03070 03071 LOG_FUNCTION_END(status); 03072 03073 return status; 03074 } 03075 03076 03077 VL53L1_Error VL53L1_i2c_encode_gph_timing_config( 03078 VL53L1_gph_timing_config_t *pdata, 03079 uint16_t buf_size, 03080 uint8_t *pbuffer) 03081 { 03082 03083 03084 VL53L1_Error status = VL53L1_ERROR_NONE; 03085 03086 LOG_FUNCTION_START(""); 03087 03088 if (buf_size < VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES) 03089 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03090 03091 *(pbuffer + 0) = 03092 pdata->gph__mm_config__timeout_macrop_a_hi & 0xF; 03093 *(pbuffer + 1) = 03094 pdata->gph__mm_config__timeout_macrop_a_lo; 03095 *(pbuffer + 2) = 03096 pdata->gph__mm_config__timeout_macrop_b_hi & 0xF; 03097 *(pbuffer + 3) = 03098 pdata->gph__mm_config__timeout_macrop_b_lo; 03099 *(pbuffer + 4) = 03100 pdata->gph__range_config__timeout_macrop_a_hi & 0xF; 03101 *(pbuffer + 5) = 03102 pdata->gph__range_config__timeout_macrop_a_lo; 03103 *(pbuffer + 6) = 03104 pdata->gph__range_config__vcsel_period_a & 0x3F; 03105 *(pbuffer + 7) = 03106 pdata->gph__range_config__vcsel_period_b & 0x3F; 03107 *(pbuffer + 8) = 03108 pdata->gph__range_config__timeout_macrop_b_hi & 0xF; 03109 *(pbuffer + 9) = 03110 pdata->gph__range_config__timeout_macrop_b_lo; 03111 VL53L1_i2c_encode_uint16_t( 03112 pdata->gph__range_config__sigma_thresh, 03113 2, 03114 pbuffer + 10); 03115 VL53L1_i2c_encode_uint16_t( 03116 pdata->gph__range_config__min_count_rate_rtn_limit_mcps, 03117 2, 03118 pbuffer + 12); 03119 *(pbuffer + 14) = 03120 pdata->gph__range_config__valid_phase_low; 03121 *(pbuffer + 15) = 03122 pdata->gph__range_config__valid_phase_high; 03123 LOG_FUNCTION_END(status); 03124 03125 03126 return status; 03127 } 03128 03129 03130 VL53L1_Error VL53L1_i2c_decode_gph_timing_config( 03131 uint16_t buf_size, 03132 uint8_t *pbuffer, 03133 VL53L1_gph_timing_config_t *pdata) 03134 { 03135 03136 03137 VL53L1_Error status = VL53L1_ERROR_NONE; 03138 03139 LOG_FUNCTION_START(""); 03140 03141 if (buf_size < VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES) 03142 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03143 03144 pdata->gph__mm_config__timeout_macrop_a_hi = 03145 (*(pbuffer + 0)) & 0xF; 03146 pdata->gph__mm_config__timeout_macrop_a_lo = 03147 (*(pbuffer + 1)); 03148 pdata->gph__mm_config__timeout_macrop_b_hi = 03149 (*(pbuffer + 2)) & 0xF; 03150 pdata->gph__mm_config__timeout_macrop_b_lo = 03151 (*(pbuffer + 3)); 03152 pdata->gph__range_config__timeout_macrop_a_hi = 03153 (*(pbuffer + 4)) & 0xF; 03154 pdata->gph__range_config__timeout_macrop_a_lo = 03155 (*(pbuffer + 5)); 03156 pdata->gph__range_config__vcsel_period_a = 03157 (*(pbuffer + 6)) & 0x3F; 03158 pdata->gph__range_config__vcsel_period_b = 03159 (*(pbuffer + 7)) & 0x3F; 03160 pdata->gph__range_config__timeout_macrop_b_hi = 03161 (*(pbuffer + 8)) & 0xF; 03162 pdata->gph__range_config__timeout_macrop_b_lo = 03163 (*(pbuffer + 9)); 03164 pdata->gph__range_config__sigma_thresh = 03165 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); 03166 pdata->gph__range_config__min_count_rate_rtn_limit_mcps = 03167 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); 03168 pdata->gph__range_config__valid_phase_low = 03169 (*(pbuffer + 14)); 03170 pdata->gph__range_config__valid_phase_high = 03171 (*(pbuffer + 15)); 03172 03173 LOG_FUNCTION_END(status); 03174 03175 return status; 03176 } 03177 03178 03179 VL53L1_Error VL53L1_set_gph_timing_config( 03180 VL53L1_DEV Dev, 03181 VL53L1_gph_timing_config_t *pdata) 03182 { 03183 03184 03185 VL53L1_Error status = VL53L1_ERROR_NONE; 03186 uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES]; 03187 03188 LOG_FUNCTION_START(""); 03189 03190 if (status == VL53L1_ERROR_NONE) 03191 status = VL53L1_i2c_encode_gph_timing_config( 03192 pdata, 03193 VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES, 03194 comms_buffer); 03195 03196 if (status == VL53L1_ERROR_NONE) 03197 status = VL53L1_disable_firmware(Dev); 03198 03199 if (status == VL53L1_ERROR_NONE) 03200 status = VL53L1_WriteMulti( 03201 Dev, 03202 VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI, 03203 comms_buffer, 03204 VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES); 03205 03206 if (status == VL53L1_ERROR_NONE) 03207 status = VL53L1_enable_firmware(Dev); 03208 03209 LOG_FUNCTION_END(status); 03210 03211 return status; 03212 } 03213 03214 03215 VL53L1_Error VL53L1_get_gph_timing_config( 03216 VL53L1_DEV Dev, 03217 VL53L1_gph_timing_config_t *pdata) 03218 { 03219 03220 03221 VL53L1_Error status = VL53L1_ERROR_NONE; 03222 uint8_t comms_buffer[VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES]; 03223 03224 LOG_FUNCTION_START(""); 03225 03226 if (status == VL53L1_ERROR_NONE) 03227 status = VL53L1_disable_firmware(Dev); 03228 03229 if (status == VL53L1_ERROR_NONE) 03230 status = VL53L1_ReadMulti( 03231 Dev, 03232 VL53L1_GPH__MM_CONFIG__TIMEOUT_MACROP_A_HI, 03233 comms_buffer, 03234 VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES); 03235 03236 if (status == VL53L1_ERROR_NONE) 03237 status = VL53L1_enable_firmware(Dev); 03238 03239 if (status == VL53L1_ERROR_NONE) 03240 status = VL53L1_i2c_decode_gph_timing_config( 03241 VL53L1_GPH_TIMING_CONFIG_I2C_SIZE_BYTES, 03242 comms_buffer, 03243 pdata); 03244 03245 LOG_FUNCTION_END(status); 03246 03247 return status; 03248 } 03249 03250 03251 VL53L1_Error VL53L1_i2c_encode_fw_internal( 03252 VL53L1_fw_internal_t *pdata, 03253 uint16_t buf_size, 03254 uint8_t *pbuffer) 03255 { 03256 03257 03258 VL53L1_Error status = VL53L1_ERROR_NONE; 03259 03260 LOG_FUNCTION_START(""); 03261 03262 if (buf_size < VL53L1_FW_INTERNAL_I2C_SIZE_BYTES) 03263 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03264 03265 *(pbuffer + 0) = 03266 pdata->firmware__internal_stream_count_div; 03267 *(pbuffer + 1) = 03268 pdata->firmware__internal_stream_counter_val; 03269 LOG_FUNCTION_END(status); 03270 03271 03272 return status; 03273 } 03274 03275 03276 VL53L1_Error VL53L1_i2c_decode_fw_internal( 03277 uint16_t buf_size, 03278 uint8_t *pbuffer, 03279 VL53L1_fw_internal_t *pdata) 03280 { 03281 03282 03283 VL53L1_Error status = VL53L1_ERROR_NONE; 03284 03285 LOG_FUNCTION_START(""); 03286 03287 if (buf_size < VL53L1_FW_INTERNAL_I2C_SIZE_BYTES) 03288 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03289 03290 pdata->firmware__internal_stream_count_div = 03291 (*(pbuffer + 0)); 03292 pdata->firmware__internal_stream_counter_val = 03293 (*(pbuffer + 1)); 03294 03295 LOG_FUNCTION_END(status); 03296 03297 return status; 03298 } 03299 03300 03301 VL53L1_Error VL53L1_set_fw_internal( 03302 VL53L1_DEV Dev, 03303 VL53L1_fw_internal_t *pdata) 03304 { 03305 03306 03307 VL53L1_Error status = VL53L1_ERROR_NONE; 03308 uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES]; 03309 03310 LOG_FUNCTION_START(""); 03311 03312 if (status == VL53L1_ERROR_NONE) 03313 status = VL53L1_i2c_encode_fw_internal( 03314 pdata, 03315 VL53L1_FW_INTERNAL_I2C_SIZE_BYTES, 03316 comms_buffer); 03317 03318 if (status == VL53L1_ERROR_NONE) 03319 status = VL53L1_disable_firmware(Dev); 03320 03321 if (status == VL53L1_ERROR_NONE) 03322 status = VL53L1_WriteMulti( 03323 Dev, 03324 VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV, 03325 comms_buffer, 03326 VL53L1_FW_INTERNAL_I2C_SIZE_BYTES); 03327 03328 if (status == VL53L1_ERROR_NONE) 03329 status = VL53L1_enable_firmware(Dev); 03330 03331 LOG_FUNCTION_END(status); 03332 03333 return status; 03334 } 03335 03336 03337 VL53L1_Error VL53L1_get_fw_internal( 03338 VL53L1_DEV Dev, 03339 VL53L1_fw_internal_t *pdata) 03340 { 03341 03342 03343 VL53L1_Error status = VL53L1_ERROR_NONE; 03344 uint8_t comms_buffer[VL53L1_FW_INTERNAL_I2C_SIZE_BYTES]; 03345 03346 LOG_FUNCTION_START(""); 03347 03348 if (status == VL53L1_ERROR_NONE) 03349 status = VL53L1_disable_firmware(Dev); 03350 03351 if (status == VL53L1_ERROR_NONE) 03352 status = VL53L1_ReadMulti( 03353 Dev, 03354 VL53L1_FIRMWARE__INTERNAL_STREAM_COUNT_DIV, 03355 comms_buffer, 03356 VL53L1_FW_INTERNAL_I2C_SIZE_BYTES); 03357 03358 if (status == VL53L1_ERROR_NONE) 03359 status = VL53L1_enable_firmware(Dev); 03360 03361 if (status == VL53L1_ERROR_NONE) 03362 status = VL53L1_i2c_decode_fw_internal( 03363 VL53L1_FW_INTERNAL_I2C_SIZE_BYTES, 03364 comms_buffer, 03365 pdata); 03366 03367 LOG_FUNCTION_END(status); 03368 03369 return status; 03370 } 03371 03372 03373 VL53L1_Error VL53L1_i2c_encode_patch_results( 03374 VL53L1_patch_results_t *pdata, 03375 uint16_t buf_size, 03376 uint8_t *pbuffer) 03377 { 03378 03379 03380 VL53L1_Error status = VL53L1_ERROR_NONE; 03381 03382 LOG_FUNCTION_START(""); 03383 03384 if (buf_size < VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES) 03385 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03386 03387 *(pbuffer + 0) = 03388 pdata->dss_calc__roi_ctrl & 0x3; 03389 *(pbuffer + 1) = 03390 pdata->dss_calc__spare_1; 03391 *(pbuffer + 2) = 03392 pdata->dss_calc__spare_2; 03393 *(pbuffer + 3) = 03394 pdata->dss_calc__spare_3; 03395 *(pbuffer + 4) = 03396 pdata->dss_calc__spare_4; 03397 *(pbuffer + 5) = 03398 pdata->dss_calc__spare_5; 03399 *(pbuffer + 6) = 03400 pdata->dss_calc__spare_6; 03401 *(pbuffer + 7) = 03402 pdata->dss_calc__spare_7; 03403 *(pbuffer + 8) = 03404 pdata->dss_calc__user_roi_spad_en_0; 03405 *(pbuffer + 9) = 03406 pdata->dss_calc__user_roi_spad_en_1; 03407 *(pbuffer + 10) = 03408 pdata->dss_calc__user_roi_spad_en_2; 03409 *(pbuffer + 11) = 03410 pdata->dss_calc__user_roi_spad_en_3; 03411 *(pbuffer + 12) = 03412 pdata->dss_calc__user_roi_spad_en_4; 03413 *(pbuffer + 13) = 03414 pdata->dss_calc__user_roi_spad_en_5; 03415 *(pbuffer + 14) = 03416 pdata->dss_calc__user_roi_spad_en_6; 03417 *(pbuffer + 15) = 03418 pdata->dss_calc__user_roi_spad_en_7; 03419 *(pbuffer + 16) = 03420 pdata->dss_calc__user_roi_spad_en_8; 03421 *(pbuffer + 17) = 03422 pdata->dss_calc__user_roi_spad_en_9; 03423 *(pbuffer + 18) = 03424 pdata->dss_calc__user_roi_spad_en_10; 03425 *(pbuffer + 19) = 03426 pdata->dss_calc__user_roi_spad_en_11; 03427 *(pbuffer + 20) = 03428 pdata->dss_calc__user_roi_spad_en_12; 03429 *(pbuffer + 21) = 03430 pdata->dss_calc__user_roi_spad_en_13; 03431 *(pbuffer + 22) = 03432 pdata->dss_calc__user_roi_spad_en_14; 03433 *(pbuffer + 23) = 03434 pdata->dss_calc__user_roi_spad_en_15; 03435 *(pbuffer + 24) = 03436 pdata->dss_calc__user_roi_spad_en_16; 03437 *(pbuffer + 25) = 03438 pdata->dss_calc__user_roi_spad_en_17; 03439 *(pbuffer + 26) = 03440 pdata->dss_calc__user_roi_spad_en_18; 03441 *(pbuffer + 27) = 03442 pdata->dss_calc__user_roi_spad_en_19; 03443 *(pbuffer + 28) = 03444 pdata->dss_calc__user_roi_spad_en_20; 03445 *(pbuffer + 29) = 03446 pdata->dss_calc__user_roi_spad_en_21; 03447 *(pbuffer + 30) = 03448 pdata->dss_calc__user_roi_spad_en_22; 03449 *(pbuffer + 31) = 03450 pdata->dss_calc__user_roi_spad_en_23; 03451 *(pbuffer + 32) = 03452 pdata->dss_calc__user_roi_spad_en_24; 03453 *(pbuffer + 33) = 03454 pdata->dss_calc__user_roi_spad_en_25; 03455 *(pbuffer + 34) = 03456 pdata->dss_calc__user_roi_spad_en_26; 03457 *(pbuffer + 35) = 03458 pdata->dss_calc__user_roi_spad_en_27; 03459 *(pbuffer + 36) = 03460 pdata->dss_calc__user_roi_spad_en_28; 03461 *(pbuffer + 37) = 03462 pdata->dss_calc__user_roi_spad_en_29; 03463 *(pbuffer + 38) = 03464 pdata->dss_calc__user_roi_spad_en_30; 03465 *(pbuffer + 39) = 03466 pdata->dss_calc__user_roi_spad_en_31; 03467 *(pbuffer + 40) = 03468 pdata->dss_calc__user_roi_0; 03469 *(pbuffer + 41) = 03470 pdata->dss_calc__user_roi_1; 03471 *(pbuffer + 42) = 03472 pdata->dss_calc__mode_roi_0; 03473 *(pbuffer + 43) = 03474 pdata->dss_calc__mode_roi_1; 03475 *(pbuffer + 44) = 03476 pdata->sigma_estimator_calc__spare_0; 03477 VL53L1_i2c_encode_uint16_t( 03478 pdata->vhv_result__peak_signal_rate_mcps, 03479 2, 03480 pbuffer + 46); 03481 VL53L1_i2c_encode_uint32_t( 03482 pdata->vhv_result__signal_total_events_ref, 03483 4, 03484 pbuffer + 48); 03485 VL53L1_i2c_encode_uint16_t( 03486 pdata->phasecal_result__phase_output_ref, 03487 2, 03488 pbuffer + 52); 03489 VL53L1_i2c_encode_uint16_t( 03490 pdata->dss_result__total_rate_per_spad, 03491 2, 03492 pbuffer + 54); 03493 *(pbuffer + 56) = 03494 pdata->dss_result__enabled_blocks; 03495 VL53L1_i2c_encode_uint16_t( 03496 pdata->dss_result__num_requested_spads, 03497 2, 03498 pbuffer + 58); 03499 VL53L1_i2c_encode_uint16_t( 03500 pdata->mm_result__inner_intersection_rate, 03501 2, 03502 pbuffer + 62); 03503 VL53L1_i2c_encode_uint16_t( 03504 pdata->mm_result__outer_complement_rate, 03505 2, 03506 pbuffer + 64); 03507 VL53L1_i2c_encode_uint16_t( 03508 pdata->mm_result__total_offset, 03509 2, 03510 pbuffer + 66); 03511 VL53L1_i2c_encode_uint32_t( 03512 pdata->xtalk_calc__xtalk_for_enabled_spads & 0xFFFFFF, 03513 4, 03514 pbuffer + 68); 03515 VL53L1_i2c_encode_uint32_t( 03516 pdata->xtalk_result__avg_xtalk_user_roi_kcps & 0xFFFFFF, 03517 4, 03518 pbuffer + 72); 03519 VL53L1_i2c_encode_uint32_t( 03520 pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps & 0xFFFFFF, 03521 4, 03522 pbuffer + 76); 03523 VL53L1_i2c_encode_uint32_t( 03524 pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps & 0xFFFFFF, 03525 4, 03526 pbuffer + 80); 03527 VL53L1_i2c_encode_uint32_t( 03528 pdata->range_result__accum_phase, 03529 4, 03530 pbuffer + 84); 03531 VL53L1_i2c_encode_uint16_t( 03532 pdata->range_result__offset_corrected_range, 03533 2, 03534 pbuffer + 88); 03535 LOG_FUNCTION_END(status); 03536 03537 03538 return status; 03539 } 03540 03541 03542 VL53L1_Error VL53L1_i2c_decode_patch_results( 03543 uint16_t buf_size, 03544 uint8_t *pbuffer, 03545 VL53L1_patch_results_t *pdata) 03546 { 03547 03548 03549 VL53L1_Error status = VL53L1_ERROR_NONE; 03550 03551 LOG_FUNCTION_START(""); 03552 03553 if (buf_size < VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES) 03554 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03555 03556 pdata->dss_calc__roi_ctrl = 03557 (*(pbuffer + 0)) & 0x3; 03558 pdata->dss_calc__spare_1 = 03559 (*(pbuffer + 1)); 03560 pdata->dss_calc__spare_2 = 03561 (*(pbuffer + 2)); 03562 pdata->dss_calc__spare_3 = 03563 (*(pbuffer + 3)); 03564 pdata->dss_calc__spare_4 = 03565 (*(pbuffer + 4)); 03566 pdata->dss_calc__spare_5 = 03567 (*(pbuffer + 5)); 03568 pdata->dss_calc__spare_6 = 03569 (*(pbuffer + 6)); 03570 pdata->dss_calc__spare_7 = 03571 (*(pbuffer + 7)); 03572 pdata->dss_calc__user_roi_spad_en_0 = 03573 (*(pbuffer + 8)); 03574 pdata->dss_calc__user_roi_spad_en_1 = 03575 (*(pbuffer + 9)); 03576 pdata->dss_calc__user_roi_spad_en_2 = 03577 (*(pbuffer + 10)); 03578 pdata->dss_calc__user_roi_spad_en_3 = 03579 (*(pbuffer + 11)); 03580 pdata->dss_calc__user_roi_spad_en_4 = 03581 (*(pbuffer + 12)); 03582 pdata->dss_calc__user_roi_spad_en_5 = 03583 (*(pbuffer + 13)); 03584 pdata->dss_calc__user_roi_spad_en_6 = 03585 (*(pbuffer + 14)); 03586 pdata->dss_calc__user_roi_spad_en_7 = 03587 (*(pbuffer + 15)); 03588 pdata->dss_calc__user_roi_spad_en_8 = 03589 (*(pbuffer + 16)); 03590 pdata->dss_calc__user_roi_spad_en_9 = 03591 (*(pbuffer + 17)); 03592 pdata->dss_calc__user_roi_spad_en_10 = 03593 (*(pbuffer + 18)); 03594 pdata->dss_calc__user_roi_spad_en_11 = 03595 (*(pbuffer + 19)); 03596 pdata->dss_calc__user_roi_spad_en_12 = 03597 (*(pbuffer + 20)); 03598 pdata->dss_calc__user_roi_spad_en_13 = 03599 (*(pbuffer + 21)); 03600 pdata->dss_calc__user_roi_spad_en_14 = 03601 (*(pbuffer + 22)); 03602 pdata->dss_calc__user_roi_spad_en_15 = 03603 (*(pbuffer + 23)); 03604 pdata->dss_calc__user_roi_spad_en_16 = 03605 (*(pbuffer + 24)); 03606 pdata->dss_calc__user_roi_spad_en_17 = 03607 (*(pbuffer + 25)); 03608 pdata->dss_calc__user_roi_spad_en_18 = 03609 (*(pbuffer + 26)); 03610 pdata->dss_calc__user_roi_spad_en_19 = 03611 (*(pbuffer + 27)); 03612 pdata->dss_calc__user_roi_spad_en_20 = 03613 (*(pbuffer + 28)); 03614 pdata->dss_calc__user_roi_spad_en_21 = 03615 (*(pbuffer + 29)); 03616 pdata->dss_calc__user_roi_spad_en_22 = 03617 (*(pbuffer + 30)); 03618 pdata->dss_calc__user_roi_spad_en_23 = 03619 (*(pbuffer + 31)); 03620 pdata->dss_calc__user_roi_spad_en_24 = 03621 (*(pbuffer + 32)); 03622 pdata->dss_calc__user_roi_spad_en_25 = 03623 (*(pbuffer + 33)); 03624 pdata->dss_calc__user_roi_spad_en_26 = 03625 (*(pbuffer + 34)); 03626 pdata->dss_calc__user_roi_spad_en_27 = 03627 (*(pbuffer + 35)); 03628 pdata->dss_calc__user_roi_spad_en_28 = 03629 (*(pbuffer + 36)); 03630 pdata->dss_calc__user_roi_spad_en_29 = 03631 (*(pbuffer + 37)); 03632 pdata->dss_calc__user_roi_spad_en_30 = 03633 (*(pbuffer + 38)); 03634 pdata->dss_calc__user_roi_spad_en_31 = 03635 (*(pbuffer + 39)); 03636 pdata->dss_calc__user_roi_0 = 03637 (*(pbuffer + 40)); 03638 pdata->dss_calc__user_roi_1 = 03639 (*(pbuffer + 41)); 03640 pdata->dss_calc__mode_roi_0 = 03641 (*(pbuffer + 42)); 03642 pdata->dss_calc__mode_roi_1 = 03643 (*(pbuffer + 43)); 03644 pdata->sigma_estimator_calc__spare_0 = 03645 (*(pbuffer + 44)); 03646 pdata->vhv_result__peak_signal_rate_mcps = 03647 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 46)); 03648 pdata->vhv_result__signal_total_events_ref = 03649 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 48)); 03650 pdata->phasecal_result__phase_output_ref = 03651 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 52)); 03652 pdata->dss_result__total_rate_per_spad = 03653 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 54)); 03654 pdata->dss_result__enabled_blocks = 03655 (*(pbuffer + 56)); 03656 pdata->dss_result__num_requested_spads = 03657 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 58)); 03658 pdata->mm_result__inner_intersection_rate = 03659 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 62)); 03660 pdata->mm_result__outer_complement_rate = 03661 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 64)); 03662 pdata->mm_result__total_offset = 03663 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 66)); 03664 pdata->xtalk_calc__xtalk_for_enabled_spads = 03665 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 68)) & 0xFFFFFF; 03666 pdata->xtalk_result__avg_xtalk_user_roi_kcps = 03667 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 72)) & 0xFFFFFF; 03668 pdata->xtalk_result__avg_xtalk_mm_inner_roi_kcps = 03669 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 76)) & 0xFFFFFF; 03670 pdata->xtalk_result__avg_xtalk_mm_outer_roi_kcps = 03671 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 80)) & 0xFFFFFF; 03672 pdata->range_result__accum_phase = 03673 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 84)); 03674 pdata->range_result__offset_corrected_range = 03675 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 88)); 03676 03677 LOG_FUNCTION_END(status); 03678 03679 return status; 03680 } 03681 03682 03683 VL53L1_Error VL53L1_set_patch_results( 03684 VL53L1_DEV Dev, 03685 VL53L1_patch_results_t *pdata) 03686 { 03687 03688 03689 VL53L1_Error status = VL53L1_ERROR_NONE; 03690 uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES]; 03691 03692 LOG_FUNCTION_START(""); 03693 03694 if (status == VL53L1_ERROR_NONE) 03695 status = VL53L1_i2c_encode_patch_results( 03696 pdata, 03697 VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES, 03698 comms_buffer); 03699 03700 if (status == VL53L1_ERROR_NONE) 03701 status = VL53L1_disable_firmware(Dev); 03702 03703 if (status == VL53L1_ERROR_NONE) 03704 status = VL53L1_WriteMulti( 03705 Dev, 03706 VL53L1_DSS_CALC__ROI_CTRL, 03707 comms_buffer, 03708 VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES); 03709 03710 if (status == VL53L1_ERROR_NONE) 03711 status = VL53L1_enable_firmware(Dev); 03712 03713 LOG_FUNCTION_END(status); 03714 03715 return status; 03716 } 03717 03718 03719 VL53L1_Error VL53L1_get_patch_results( 03720 VL53L1_DEV Dev, 03721 VL53L1_patch_results_t *pdata) 03722 { 03723 03724 03725 VL53L1_Error status = VL53L1_ERROR_NONE; 03726 uint8_t comms_buffer[VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES]; 03727 03728 LOG_FUNCTION_START(""); 03729 03730 if (status == VL53L1_ERROR_NONE) 03731 status = VL53L1_disable_firmware(Dev); 03732 03733 if (status == VL53L1_ERROR_NONE) 03734 status = VL53L1_ReadMulti( 03735 Dev, 03736 VL53L1_DSS_CALC__ROI_CTRL, 03737 comms_buffer, 03738 VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES); 03739 03740 if (status == VL53L1_ERROR_NONE) 03741 status = VL53L1_enable_firmware(Dev); 03742 03743 if (status == VL53L1_ERROR_NONE) 03744 status = VL53L1_i2c_decode_patch_results( 03745 VL53L1_PATCH_RESULTS_I2C_SIZE_BYTES, 03746 comms_buffer, 03747 pdata); 03748 03749 LOG_FUNCTION_END(status); 03750 03751 return status; 03752 } 03753 03754 03755 VL53L1_Error VL53L1_i2c_encode_shadow_system_results( 03756 VL53L1_shadow_system_results_t *pdata, 03757 uint16_t buf_size, 03758 uint8_t *pbuffer) 03759 { 03760 03761 03762 VL53L1_Error status = VL53L1_ERROR_NONE; 03763 03764 LOG_FUNCTION_START(""); 03765 03766 if (buf_size < VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) 03767 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03768 03769 *(pbuffer + 0) = 03770 pdata->shadow_phasecal_result__vcsel_start; 03771 *(pbuffer + 2) = 03772 pdata->shadow_result__interrupt_status & 0x3F; 03773 *(pbuffer + 3) = 03774 pdata->shadow_result__range_status; 03775 *(pbuffer + 4) = 03776 pdata->shadow_result__report_status & 0xF; 03777 *(pbuffer + 5) = 03778 pdata->shadow_result__stream_count; 03779 VL53L1_i2c_encode_uint16_t( 03780 pdata->shadow_result__dss_actual_effective_spads_sd0, 03781 2, 03782 pbuffer + 6); 03783 VL53L1_i2c_encode_uint16_t( 03784 pdata->shadow_result__peak_signal_count_rate_mcps_sd0, 03785 2, 03786 pbuffer + 8); 03787 VL53L1_i2c_encode_uint16_t( 03788 pdata->shadow_result__ambient_count_rate_mcps_sd0, 03789 2, 03790 pbuffer + 10); 03791 VL53L1_i2c_encode_uint16_t( 03792 pdata->shadow_result__sigma_sd0, 03793 2, 03794 pbuffer + 12); 03795 VL53L1_i2c_encode_uint16_t( 03796 pdata->shadow_result__phase_sd0, 03797 2, 03798 pbuffer + 14); 03799 VL53L1_i2c_encode_uint16_t( 03800 pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0, 03801 2, 03802 pbuffer + 16); 03803 VL53L1_i2c_encode_uint16_t( 03804 pdata->shr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0, 03805 2, 03806 pbuffer + 18); 03807 VL53L1_i2c_encode_uint16_t( 03808 pdata->shadow_result__mm_inner_actual_effective_spads_sd0, 03809 2, 03810 pbuffer + 20); 03811 VL53L1_i2c_encode_uint16_t( 03812 pdata->shadow_result__mm_outer_actual_effective_spads_sd0, 03813 2, 03814 pbuffer + 22); 03815 VL53L1_i2c_encode_uint16_t( 03816 pdata->shadow_result__avg_signal_count_rate_mcps_sd0, 03817 2, 03818 pbuffer + 24); 03819 VL53L1_i2c_encode_uint16_t( 03820 pdata->shadow_result__dss_actual_effective_spads_sd1, 03821 2, 03822 pbuffer + 26); 03823 VL53L1_i2c_encode_uint16_t( 03824 pdata->shadow_result__peak_signal_count_rate_mcps_sd1, 03825 2, 03826 pbuffer + 28); 03827 VL53L1_i2c_encode_uint16_t( 03828 pdata->shadow_result__ambient_count_rate_mcps_sd1, 03829 2, 03830 pbuffer + 30); 03831 VL53L1_i2c_encode_uint16_t( 03832 pdata->shadow_result__sigma_sd1, 03833 2, 03834 pbuffer + 32); 03835 VL53L1_i2c_encode_uint16_t( 03836 pdata->shadow_result__phase_sd1, 03837 2, 03838 pbuffer + 34); 03839 VL53L1_i2c_encode_uint16_t( 03840 pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1, 03841 2, 03842 pbuffer + 36); 03843 VL53L1_i2c_encode_uint16_t( 03844 pdata->shadow_result__spare_0_sd1, 03845 2, 03846 pbuffer + 38); 03847 VL53L1_i2c_encode_uint16_t( 03848 pdata->shadow_result__spare_1_sd1, 03849 2, 03850 pbuffer + 40); 03851 VL53L1_i2c_encode_uint16_t( 03852 pdata->shadow_result__spare_2_sd1, 03853 2, 03854 pbuffer + 42); 03855 *(pbuffer + 44) = 03856 pdata->shadow_result__spare_3_sd1; 03857 *(pbuffer + 45) = 03858 pdata->shadow_result__thresh_info; 03859 *(pbuffer + 80) = 03860 pdata->shadow_phasecal_result__reference_phase_hi; 03861 *(pbuffer + 81) = 03862 pdata->shadow_phasecal_result__reference_phase_lo; 03863 LOG_FUNCTION_END(status); 03864 03865 03866 return status; 03867 } 03868 03869 03870 VL53L1_Error VL53L1_i2c_decode_shadow_system_results( 03871 uint16_t buf_size, 03872 uint8_t *pbuffer, 03873 VL53L1_shadow_system_results_t *pdata) 03874 { 03875 03876 03877 VL53L1_Error status = VL53L1_ERROR_NONE; 03878 03879 LOG_FUNCTION_START(""); 03880 03881 if (buf_size < VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES) 03882 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 03883 03884 pdata->shadow_phasecal_result__vcsel_start = 03885 (*(pbuffer + 0)); 03886 pdata->shadow_result__interrupt_status = 03887 (*(pbuffer + 2)) & 0x3F; 03888 pdata->shadow_result__range_status = 03889 (*(pbuffer + 3)); 03890 pdata->shadow_result__report_status = 03891 (*(pbuffer + 4)) & 0xF; 03892 pdata->shadow_result__stream_count = 03893 (*(pbuffer + 5)); 03894 pdata->shadow_result__dss_actual_effective_spads_sd0 = 03895 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 6)); 03896 pdata->shadow_result__peak_signal_count_rate_mcps_sd0 = 03897 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 8)); 03898 pdata->shadow_result__ambient_count_rate_mcps_sd0 = 03899 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 10)); 03900 pdata->shadow_result__sigma_sd0 = 03901 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 12)); 03902 pdata->shadow_result__phase_sd0 = 03903 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 14)); 03904 pdata->shadow_result__final_crosstalk_corrected_range_mm_sd0 = 03905 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 16)); 03906 pdata->shr__peak_signal_count_rate_crosstalk_corrected_mcps_sd0 = 03907 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 18)); 03908 pdata->shadow_result__mm_inner_actual_effective_spads_sd0 = 03909 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 20)); 03910 pdata->shadow_result__mm_outer_actual_effective_spads_sd0 = 03911 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 22)); 03912 pdata->shadow_result__avg_signal_count_rate_mcps_sd0 = 03913 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 24)); 03914 pdata->shadow_result__dss_actual_effective_spads_sd1 = 03915 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 26)); 03916 pdata->shadow_result__peak_signal_count_rate_mcps_sd1 = 03917 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 28)); 03918 pdata->shadow_result__ambient_count_rate_mcps_sd1 = 03919 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 30)); 03920 pdata->shadow_result__sigma_sd1 = 03921 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 32)); 03922 pdata->shadow_result__phase_sd1 = 03923 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 34)); 03924 pdata->shadow_result__final_crosstalk_corrected_range_mm_sd1 = 03925 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 36)); 03926 pdata->shadow_result__spare_0_sd1 = 03927 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 38)); 03928 pdata->shadow_result__spare_1_sd1 = 03929 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 40)); 03930 pdata->shadow_result__spare_2_sd1 = 03931 (VL53L1_i2c_decode_uint16_t(2, pbuffer + 42)); 03932 pdata->shadow_result__spare_3_sd1 = 03933 (*(pbuffer + 44)); 03934 pdata->shadow_result__thresh_info = 03935 (*(pbuffer + 45)); 03936 pdata->shadow_phasecal_result__reference_phase_hi = 03937 (*(pbuffer + 80)); 03938 pdata->shadow_phasecal_result__reference_phase_lo = 03939 (*(pbuffer + 81)); 03940 03941 LOG_FUNCTION_END(status); 03942 03943 return status; 03944 } 03945 03946 03947 VL53L1_Error VL53L1_set_shadow_system_results( 03948 VL53L1_DEV Dev, 03949 VL53L1_shadow_system_results_t *pdata) 03950 { 03951 03952 03953 VL53L1_Error status = VL53L1_ERROR_NONE; 03954 uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; 03955 03956 LOG_FUNCTION_START(""); 03957 03958 if (status == VL53L1_ERROR_NONE) 03959 status = VL53L1_i2c_encode_shadow_system_results( 03960 pdata, 03961 VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, 03962 comms_buffer); 03963 03964 if (status == VL53L1_ERROR_NONE) 03965 status = VL53L1_disable_firmware(Dev); 03966 03967 if (status == VL53L1_ERROR_NONE) 03968 status = VL53L1_WriteMulti( 03969 Dev, 03970 VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START, 03971 comms_buffer, 03972 VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); 03973 03974 if (status == VL53L1_ERROR_NONE) 03975 status = VL53L1_enable_firmware(Dev); 03976 03977 LOG_FUNCTION_END(status); 03978 03979 return status; 03980 } 03981 03982 03983 VL53L1_Error VL53L1_get_shadow_system_results( 03984 VL53L1_DEV Dev, 03985 VL53L1_shadow_system_results_t *pdata) 03986 { 03987 03988 03989 VL53L1_Error status = VL53L1_ERROR_NONE; 03990 uint8_t comms_buffer[VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES]; 03991 03992 LOG_FUNCTION_START(""); 03993 03994 if (status == VL53L1_ERROR_NONE) 03995 status = VL53L1_disable_firmware(Dev); 03996 03997 if (status == VL53L1_ERROR_NONE) 03998 status = VL53L1_ReadMulti( 03999 Dev, 04000 VL53L1_SHADOW_PHASECAL_RESULT__VCSEL_START, 04001 comms_buffer, 04002 VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES); 04003 04004 if (status == VL53L1_ERROR_NONE) 04005 status = VL53L1_enable_firmware(Dev); 04006 04007 if (status == VL53L1_ERROR_NONE) 04008 status = VL53L1_i2c_decode_shadow_system_results( 04009 VL53L1_SHADOW_SYSTEM_RESULTS_I2C_SIZE_BYTES, 04010 comms_buffer, 04011 pdata); 04012 04013 LOG_FUNCTION_END(status); 04014 04015 return status; 04016 } 04017 04018 04019 VL53L1_Error VL53L1_i2c_encode_shadow_core_results( 04020 VL53L1_shadow_core_results_t *pdata, 04021 uint16_t buf_size, 04022 uint8_t *pbuffer) 04023 { 04024 04025 04026 VL53L1_Error status = VL53L1_ERROR_NONE; 04027 04028 LOG_FUNCTION_START(""); 04029 04030 if (buf_size < VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) 04031 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 04032 04033 VL53L1_i2c_encode_uint32_t( 04034 pdata->shadow_result_core__ambient_window_events_sd0, 04035 4, 04036 pbuffer + 0); 04037 VL53L1_i2c_encode_uint32_t( 04038 pdata->shadow_result_core__ranging_total_events_sd0, 04039 4, 04040 pbuffer + 4); 04041 VL53L1_i2c_encode_int32_t( 04042 pdata->shadow_result_core__signal_total_events_sd0, 04043 4, 04044 pbuffer + 8); 04045 VL53L1_i2c_encode_uint32_t( 04046 pdata->shadow_result_core__total_periods_elapsed_sd0, 04047 4, 04048 pbuffer + 12); 04049 VL53L1_i2c_encode_uint32_t( 04050 pdata->shadow_result_core__ambient_window_events_sd1, 04051 4, 04052 pbuffer + 16); 04053 VL53L1_i2c_encode_uint32_t( 04054 pdata->shadow_result_core__ranging_total_events_sd1, 04055 4, 04056 pbuffer + 20); 04057 VL53L1_i2c_encode_int32_t( 04058 pdata->shadow_result_core__signal_total_events_sd1, 04059 4, 04060 pbuffer + 24); 04061 VL53L1_i2c_encode_uint32_t( 04062 pdata->shadow_result_core__total_periods_elapsed_sd1, 04063 4, 04064 pbuffer + 28); 04065 *(pbuffer + 32) = 04066 pdata->shadow_result_core__spare_0; 04067 LOG_FUNCTION_END(status); 04068 04069 04070 return status; 04071 } 04072 04073 04074 VL53L1_Error VL53L1_i2c_decode_shadow_core_results( 04075 uint16_t buf_size, 04076 uint8_t *pbuffer, 04077 VL53L1_shadow_core_results_t *pdata) 04078 { 04079 04080 04081 VL53L1_Error status = VL53L1_ERROR_NONE; 04082 04083 LOG_FUNCTION_START(""); 04084 04085 if (buf_size < VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES) 04086 return VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL; 04087 04088 pdata->shadow_result_core__ambient_window_events_sd0 = 04089 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 0)); 04090 pdata->shadow_result_core__ranging_total_events_sd0 = 04091 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 4)); 04092 pdata->shadow_result_core__signal_total_events_sd0 = 04093 (VL53L1_i2c_decode_int32_t(4, pbuffer + 8)); 04094 pdata->shadow_result_core__total_periods_elapsed_sd0 = 04095 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 12)); 04096 pdata->shadow_result_core__ambient_window_events_sd1 = 04097 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 16)); 04098 pdata->shadow_result_core__ranging_total_events_sd1 = 04099 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 20)); 04100 pdata->shadow_result_core__signal_total_events_sd1 = 04101 (VL53L1_i2c_decode_int32_t(4, pbuffer + 24)); 04102 pdata->shadow_result_core__total_periods_elapsed_sd1 = 04103 (VL53L1_i2c_decode_uint32_t(4, pbuffer + 28)); 04104 pdata->shadow_result_core__spare_0 = 04105 (*(pbuffer + 32)); 04106 04107 LOG_FUNCTION_END(status); 04108 04109 return status; 04110 } 04111 04112 04113 VL53L1_Error VL53L1_set_shadow_core_results( 04114 VL53L1_DEV Dev, 04115 VL53L1_shadow_core_results_t *pdata) 04116 { 04117 04118 04119 VL53L1_Error status = VL53L1_ERROR_NONE; 04120 uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; 04121 04122 LOG_FUNCTION_START(""); 04123 04124 if (status == VL53L1_ERROR_NONE) 04125 status = VL53L1_i2c_encode_shadow_core_results( 04126 pdata, 04127 VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, 04128 comms_buffer); 04129 04130 if (status == VL53L1_ERROR_NONE) 04131 status = VL53L1_disable_firmware(Dev); 04132 04133 if (status == VL53L1_ERROR_NONE) 04134 status = VL53L1_WriteMulti( 04135 Dev, 04136 VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, 04137 comms_buffer, 04138 VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); 04139 04140 if (status == VL53L1_ERROR_NONE) 04141 status = VL53L1_enable_firmware(Dev); 04142 04143 LOG_FUNCTION_END(status); 04144 04145 return status; 04146 } 04147 04148 04149 VL53L1_Error VL53L1_get_shadow_core_results( 04150 VL53L1_DEV Dev, 04151 VL53L1_shadow_core_results_t *pdata) 04152 { 04153 04154 04155 VL53L1_Error status = VL53L1_ERROR_NONE; 04156 uint8_t comms_buffer[VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES]; 04157 04158 LOG_FUNCTION_START(""); 04159 04160 if (status == VL53L1_ERROR_NONE) 04161 status = VL53L1_disable_firmware(Dev); 04162 04163 if (status == VL53L1_ERROR_NONE) 04164 status = VL53L1_ReadMulti( 04165 Dev, 04166 VL53L1_SHADOW_RESULT_CORE__AMBIENT_WINDOW_EVENTS_SD0, 04167 comms_buffer, 04168 VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES); 04169 04170 if (status == VL53L1_ERROR_NONE) 04171 status = VL53L1_enable_firmware(Dev); 04172 04173 if (status == VL53L1_ERROR_NONE) 04174 status = VL53L1_i2c_decode_shadow_core_results( 04175 VL53L1_SHADOW_CORE_RESULTS_I2C_SIZE_BYTES, 04176 comms_buffer, 04177 pdata); 04178 04179 LOG_FUNCTION_END(status); 04180 04181 return status; 04182 } 04183 04184 04185
Generated on Tue Jul 12 2022 20:07:15 by
 1.7.2
 1.7.2