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