The VL53L1CB proximity sensor, based on ST’s FlightSense™, Time-of-Flight technology.
Dependencies: X_NUCLEO_COMMON ST_INTERFACES
Dependents: VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2
Based on VL53L1 library, this is a library for the VL53L1CB ToF chip.
src/vl53l1_api_calibration.c@7:1add29d51e72, 2021-06-08 (annotated)
- Committer:
- Charles MacNeill
- Date:
- Tue Jun 08 10:34:47 2021 +0100
- Revision:
- 7:1add29d51e72
- Parent:
- 0:3ac96e360672
- Child:
- 18:0696efe39d08
Update to v6.6.5 of bare_driver
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:3ac96e360672 | 1 | |
Charles MacNeill |
7:1add29d51e72 | 2 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Charles MacNeill |
7:1add29d51e72 | 3 | /****************************************************************************** |
charlesmn | 0:3ac96e360672 | 4 | * Copyright (c) 2020, STMicroelectronics - All Rights Reserved |
charlesmn | 0:3ac96e360672 | 5 | |
Charles MacNeill |
7:1add29d51e72 | 6 | This file is part of VL53L1 and is dual licensed, |
Charles MacNeill |
7:1add29d51e72 | 7 | either GPL-2.0+ |
charlesmn | 0:3ac96e360672 | 8 | or 'BSD 3-clause "New" or "Revised" License' , at your option. |
Charles MacNeill |
7:1add29d51e72 | 9 | ****************************************************************************** |
Charles MacNeill |
7:1add29d51e72 | 10 | */ |
charlesmn | 0:3ac96e360672 | 11 | |
charlesmn | 0:3ac96e360672 | 12 | |
charlesmn | 0:3ac96e360672 | 13 | |
charlesmn | 0:3ac96e360672 | 14 | |
charlesmn | 0:3ac96e360672 | 15 | |
charlesmn | 0:3ac96e360672 | 16 | #include "vl53l1_ll_def.h" |
charlesmn | 0:3ac96e360672 | 17 | #include "vl53l1_ll_device.h" |
charlesmn | 0:3ac96e360672 | 18 | #include "vl53l1_platform.h" |
charlesmn | 0:3ac96e360672 | 19 | #include "vl53l1_platform_ipp.h" |
charlesmn | 0:3ac96e360672 | 20 | #include "vl53l1_register_map.h" |
charlesmn | 0:3ac96e360672 | 21 | #include "vl53l1_register_funcs.h" |
charlesmn | 0:3ac96e360672 | 22 | #include "vl53l1_register_settings.h" |
charlesmn | 0:3ac96e360672 | 23 | #include "vl53l1_hist_map.h" |
charlesmn | 0:3ac96e360672 | 24 | #include "vl53l1_hist_structs.h" |
charlesmn | 0:3ac96e360672 | 25 | #include "vl53l1_core.h" |
charlesmn | 0:3ac96e360672 | 26 | #include "vl53l1_wait.h" |
charlesmn | 0:3ac96e360672 | 27 | #include "vl53l1_api_preset_modes.h" |
charlesmn | 0:3ac96e360672 | 28 | #include "vl53l1_silicon_core.h" |
charlesmn | 0:3ac96e360672 | 29 | #include "vl53l1_api_core.h" |
charlesmn | 0:3ac96e360672 | 30 | #include "vl53l1_api_calibration.h" |
charlesmn | 0:3ac96e360672 | 31 | |
charlesmn | 0:3ac96e360672 | 32 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 33 | #include "vl53l1_api_debug.h" |
charlesmn | 0:3ac96e360672 | 34 | #endif |
charlesmn | 0:3ac96e360672 | 35 | |
charlesmn | 0:3ac96e360672 | 36 | |
charlesmn | 0:3ac96e360672 | 37 | #define LOG_FUNCTION_START(fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 38 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 39 | #define LOG_FUNCTION_END(status, ...) \ |
charlesmn | 0:3ac96e360672 | 40 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 41 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 42 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \ |
charlesmn | 0:3ac96e360672 | 43 | fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 44 | |
charlesmn | 0:3ac96e360672 | 45 | #define trace_print(level, ...) \ |
charlesmn | 0:3ac96e360672 | 46 | _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \ |
charlesmn | 0:3ac96e360672 | 47 | level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 48 | |
charlesmn | 0:3ac96e360672 | 49 | |
charlesmn | 0:3ac96e360672 | 50 | VL53L1_Error VL53L1_run_ref_spad_char( |
charlesmn | 0:3ac96e360672 | 51 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 52 | VL53L1_Error *pcal_status) |
charlesmn | 0:3ac96e360672 | 53 | { |
charlesmn | 0:3ac96e360672 | 54 | |
charlesmn | 0:3ac96e360672 | 55 | |
charlesmn | 0:3ac96e360672 | 56 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 57 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 58 | |
charlesmn | 0:3ac96e360672 | 59 | uint8_t comms_buffer[6]; |
charlesmn | 0:3ac96e360672 | 60 | |
charlesmn | 0:3ac96e360672 | 61 | VL53L1_refspadchar_config_t *prefspadchar = &(pdev->refspadchar); |
charlesmn | 0:3ac96e360672 | 62 | |
charlesmn | 0:3ac96e360672 | 63 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 64 | |
charlesmn | 0:3ac96e360672 | 65 | |
charlesmn | 0:3ac96e360672 | 66 | |
charlesmn | 0:3ac96e360672 | 67 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 68 | status = VL53L1_enable_powerforce(Dev); |
charlesmn | 0:3ac96e360672 | 69 | |
charlesmn | 0:3ac96e360672 | 70 | |
charlesmn | 0:3ac96e360672 | 71 | |
charlesmn | 0:3ac96e360672 | 72 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 73 | status = |
charlesmn | 0:3ac96e360672 | 74 | VL53L1_set_ref_spad_char_config( |
charlesmn | 0:3ac96e360672 | 75 | Dev, |
charlesmn | 0:3ac96e360672 | 76 | prefspadchar->VL53L1_p_009, |
charlesmn | 0:3ac96e360672 | 77 | prefspadchar->timeout_us, |
charlesmn | 0:3ac96e360672 | 78 | prefspadchar->target_count_rate_mcps, |
charlesmn | 0:3ac96e360672 | 79 | prefspadchar->max_count_rate_limit_mcps, |
charlesmn | 0:3ac96e360672 | 80 | prefspadchar->min_count_rate_limit_mcps, |
charlesmn | 0:3ac96e360672 | 81 | pdev->stat_nvm.osc_measured__fast_osc__frequency); |
charlesmn | 0:3ac96e360672 | 82 | |
charlesmn | 0:3ac96e360672 | 83 | |
charlesmn | 0:3ac96e360672 | 84 | |
charlesmn | 0:3ac96e360672 | 85 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 86 | status = VL53L1_run_device_test( |
charlesmn | 0:3ac96e360672 | 87 | Dev, |
charlesmn | 0:3ac96e360672 | 88 | prefspadchar->device_test_mode); |
charlesmn | 0:3ac96e360672 | 89 | |
charlesmn | 0:3ac96e360672 | 90 | |
charlesmn | 0:3ac96e360672 | 91 | |
charlesmn | 0:3ac96e360672 | 92 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 93 | status = |
charlesmn | 0:3ac96e360672 | 94 | VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 95 | Dev, |
charlesmn | 0:3ac96e360672 | 96 | VL53L1_REF_SPAD_CHAR_RESULT__NUM_ACTUAL_REF_SPADS, |
charlesmn | 0:3ac96e360672 | 97 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 98 | 2); |
charlesmn | 0:3ac96e360672 | 99 | |
charlesmn | 0:3ac96e360672 | 100 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 101 | pdev->dbg_results.ref_spad_char_result__num_actual_ref_spads = |
charlesmn | 0:3ac96e360672 | 102 | comms_buffer[0]; |
charlesmn | 0:3ac96e360672 | 103 | pdev->dbg_results.ref_spad_char_result__ref_location = |
charlesmn | 0:3ac96e360672 | 104 | comms_buffer[1]; |
charlesmn | 0:3ac96e360672 | 105 | } |
charlesmn | 0:3ac96e360672 | 106 | |
charlesmn | 0:3ac96e360672 | 107 | |
charlesmn | 0:3ac96e360672 | 108 | |
charlesmn | 0:3ac96e360672 | 109 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 110 | status = |
charlesmn | 0:3ac96e360672 | 111 | VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 112 | Dev, |
charlesmn | 0:3ac96e360672 | 113 | VL53L1_REF_SPAD_MAN__NUM_REQUESTED_REF_SPADS, |
charlesmn | 0:3ac96e360672 | 114 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 115 | 2); |
charlesmn | 0:3ac96e360672 | 116 | |
charlesmn | 0:3ac96e360672 | 117 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 118 | pdev->customer.ref_spad_man__num_requested_ref_spads = |
charlesmn | 0:3ac96e360672 | 119 | comms_buffer[0]; |
charlesmn | 0:3ac96e360672 | 120 | pdev->customer.ref_spad_man__ref_location = |
charlesmn | 0:3ac96e360672 | 121 | comms_buffer[1]; |
charlesmn | 0:3ac96e360672 | 122 | } |
charlesmn | 0:3ac96e360672 | 123 | |
charlesmn | 0:3ac96e360672 | 124 | |
charlesmn | 0:3ac96e360672 | 125 | |
charlesmn | 0:3ac96e360672 | 126 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 127 | status = |
charlesmn | 0:3ac96e360672 | 128 | VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 129 | Dev, |
charlesmn | 0:3ac96e360672 | 130 | VL53L1_RESULT__SPARE_0_SD1, |
charlesmn | 0:3ac96e360672 | 131 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 132 | 6); |
charlesmn | 0:3ac96e360672 | 133 | |
charlesmn | 0:3ac96e360672 | 134 | |
charlesmn | 0:3ac96e360672 | 135 | |
charlesmn | 0:3ac96e360672 | 136 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 137 | status = |
charlesmn | 0:3ac96e360672 | 138 | VL53L1_WriteMulti( |
charlesmn | 0:3ac96e360672 | 139 | Dev, |
charlesmn | 0:3ac96e360672 | 140 | VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0, |
charlesmn | 0:3ac96e360672 | 141 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 142 | 6); |
charlesmn | 0:3ac96e360672 | 143 | |
charlesmn | 0:3ac96e360672 | 144 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 145 | pdev->customer.global_config__spad_enables_ref_0 = |
charlesmn | 0:3ac96e360672 | 146 | comms_buffer[0]; |
charlesmn | 0:3ac96e360672 | 147 | pdev->customer.global_config__spad_enables_ref_1 = |
charlesmn | 0:3ac96e360672 | 148 | comms_buffer[1]; |
charlesmn | 0:3ac96e360672 | 149 | pdev->customer.global_config__spad_enables_ref_2 = |
charlesmn | 0:3ac96e360672 | 150 | comms_buffer[2]; |
charlesmn | 0:3ac96e360672 | 151 | pdev->customer.global_config__spad_enables_ref_3 = |
charlesmn | 0:3ac96e360672 | 152 | comms_buffer[3]; |
charlesmn | 0:3ac96e360672 | 153 | pdev->customer.global_config__spad_enables_ref_4 = |
charlesmn | 0:3ac96e360672 | 154 | comms_buffer[4]; |
charlesmn | 0:3ac96e360672 | 155 | pdev->customer.global_config__spad_enables_ref_5 = |
charlesmn | 0:3ac96e360672 | 156 | comms_buffer[5]; |
charlesmn | 0:3ac96e360672 | 157 | } |
charlesmn | 0:3ac96e360672 | 158 | |
charlesmn | 0:3ac96e360672 | 159 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 160 | |
charlesmn | 0:3ac96e360672 | 161 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 162 | VL53L1_print_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 163 | &(pdev->customer), |
charlesmn | 0:3ac96e360672 | 164 | "run_ref_spad_char():pdev->lldata.customer.", |
charlesmn | 0:3ac96e360672 | 165 | VL53L1_TRACE_MODULE_REF_SPAD_CHAR); |
charlesmn | 0:3ac96e360672 | 166 | #endif |
charlesmn | 0:3ac96e360672 | 167 | |
charlesmn | 0:3ac96e360672 | 168 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 169 | |
charlesmn | 0:3ac96e360672 | 170 | switch (pdev->sys_results.result__range_status) { |
charlesmn | 0:3ac96e360672 | 171 | |
charlesmn | 0:3ac96e360672 | 172 | case VL53L1_DEVICEERROR_REFSPADCHARNOTENOUGHDPADS: |
charlesmn | 0:3ac96e360672 | 173 | status = VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS; |
charlesmn | 0:3ac96e360672 | 174 | break; |
charlesmn | 0:3ac96e360672 | 175 | |
charlesmn | 0:3ac96e360672 | 176 | case VL53L1_DEVICEERROR_REFSPADCHARMORETHANTARGET: |
charlesmn | 0:3ac96e360672 | 177 | status = VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 178 | break; |
charlesmn | 0:3ac96e360672 | 179 | |
charlesmn | 0:3ac96e360672 | 180 | case VL53L1_DEVICEERROR_REFSPADCHARLESSTHANTARGET: |
charlesmn | 0:3ac96e360672 | 181 | status = VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW; |
charlesmn | 0:3ac96e360672 | 182 | break; |
charlesmn | 0:3ac96e360672 | 183 | } |
charlesmn | 0:3ac96e360672 | 184 | } |
charlesmn | 0:3ac96e360672 | 185 | |
charlesmn | 0:3ac96e360672 | 186 | |
charlesmn | 0:3ac96e360672 | 187 | |
charlesmn | 0:3ac96e360672 | 188 | *pcal_status = status; |
charlesmn | 0:3ac96e360672 | 189 | |
charlesmn | 0:3ac96e360672 | 190 | |
charlesmn | 0:3ac96e360672 | 191 | |
charlesmn | 0:3ac96e360672 | 192 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 193 | IGNORE_REF_SPAD_CHAR_NOT_ENOUGH_SPADS, |
charlesmn | 0:3ac96e360672 | 194 | VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS, |
charlesmn | 0:3ac96e360672 | 195 | status); |
charlesmn | 0:3ac96e360672 | 196 | |
charlesmn | 0:3ac96e360672 | 197 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 198 | IGNORE_REF_SPAD_CHAR_RATE_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 199 | VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 200 | status); |
charlesmn | 0:3ac96e360672 | 201 | |
charlesmn | 0:3ac96e360672 | 202 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 203 | IGNORE_REF_SPAD_CHAR_RATE_TOO_LOW, |
charlesmn | 0:3ac96e360672 | 204 | VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW, |
charlesmn | 0:3ac96e360672 | 205 | status); |
charlesmn | 0:3ac96e360672 | 206 | |
charlesmn | 0:3ac96e360672 | 207 | |
charlesmn | 0:3ac96e360672 | 208 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 209 | |
charlesmn | 0:3ac96e360672 | 210 | return status; |
charlesmn | 0:3ac96e360672 | 211 | } |
charlesmn | 0:3ac96e360672 | 212 | |
charlesmn | 0:3ac96e360672 | 213 | |
charlesmn | 0:3ac96e360672 | 214 | VL53L1_Error VL53L1_run_xtalk_extraction( |
charlesmn | 0:3ac96e360672 | 215 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 216 | VL53L1_Error *pcal_status) |
charlesmn | 0:3ac96e360672 | 217 | { |
charlesmn | 0:3ac96e360672 | 218 | |
charlesmn | 0:3ac96e360672 | 219 | |
charlesmn | 0:3ac96e360672 | 220 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 221 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 222 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 223 | |
charlesmn | 0:3ac96e360672 | 224 | |
charlesmn | 0:3ac96e360672 | 225 | |
charlesmn | 0:3ac96e360672 | 226 | VL53L1_xtalkextract_config_t *pX = &(pdev->xtalk_extract_cfg); |
charlesmn | 0:3ac96e360672 | 227 | VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg); |
charlesmn | 0:3ac96e360672 | 228 | VL53L1_xtalk_calibration_results_t *pXC = &(pdev->xtalk_cal); |
charlesmn | 0:3ac96e360672 | 229 | |
charlesmn | 0:3ac96e360672 | 230 | uint8_t results_invalid = 0; |
charlesmn | 0:3ac96e360672 | 231 | |
charlesmn | 0:3ac96e360672 | 232 | uint8_t i = 0; |
charlesmn | 0:3ac96e360672 | 233 | uint16_t tmp16 = 0; |
charlesmn | 0:3ac96e360672 | 234 | |
charlesmn | 0:3ac96e360672 | 235 | uint8_t measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK; |
charlesmn | 0:3ac96e360672 | 236 | |
charlesmn | 0:3ac96e360672 | 237 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 238 | |
charlesmn | 0:3ac96e360672 | 239 | |
charlesmn | 0:3ac96e360672 | 240 | |
charlesmn | 0:3ac96e360672 | 241 | |
charlesmn | 0:3ac96e360672 | 242 | |
charlesmn | 0:3ac96e360672 | 243 | VL53L1_init_histogram_bin_data_struct( |
charlesmn | 0:3ac96e360672 | 244 | 0, |
charlesmn | 0:3ac96e360672 | 245 | (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE, |
charlesmn | 0:3ac96e360672 | 246 | &(pdev->xtalk_results.central_histogram_avg)); |
charlesmn | 0:3ac96e360672 | 247 | |
charlesmn | 0:3ac96e360672 | 248 | VL53L1_init_histogram_bin_data_struct( |
charlesmn | 0:3ac96e360672 | 249 | 0, |
charlesmn | 0:3ac96e360672 | 250 | (uint16_t)VL53L1_HISTOGRAM_BUFFER_SIZE, |
charlesmn | 0:3ac96e360672 | 251 | &(pdev->xtalk_results.central_histogram_sum)); |
charlesmn | 0:3ac96e360672 | 252 | |
charlesmn | 0:3ac96e360672 | 253 | |
charlesmn | 0:3ac96e360672 | 254 | |
charlesmn | 0:3ac96e360672 | 255 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 256 | status = |
charlesmn | 0:3ac96e360672 | 257 | VL53L1_set_preset_mode( |
charlesmn | 0:3ac96e360672 | 258 | Dev, |
charlesmn | 0:3ac96e360672 | 259 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_XTALK_PLANAR, |
charlesmn | 0:3ac96e360672 | 260 | |
charlesmn | 0:3ac96e360672 | 261 | pX->dss_config__target_total_rate_mcps, |
charlesmn | 0:3ac96e360672 | 262 | pX->phasecal_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 263 | pX->mm_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 264 | pX->range_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 265 | |
charlesmn | 0:3ac96e360672 | 266 | 100); |
charlesmn | 0:3ac96e360672 | 267 | |
charlesmn | 0:3ac96e360672 | 268 | |
charlesmn | 0:3ac96e360672 | 269 | |
charlesmn | 0:3ac96e360672 | 270 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 271 | status = VL53L1_disable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 272 | |
charlesmn | 0:3ac96e360672 | 273 | |
charlesmn | 0:3ac96e360672 | 274 | |
charlesmn | 0:3ac96e360672 | 275 | pdev->xtalk_results.max_results = VL53L1_MAX_XTALK_RANGE_RESULTS; |
charlesmn | 0:3ac96e360672 | 276 | pdev->xtalk_results.active_results = pdev->zone_cfg.active_zones+1; |
charlesmn | 0:3ac96e360672 | 277 | |
charlesmn | 0:3ac96e360672 | 278 | |
charlesmn | 0:3ac96e360672 | 279 | |
charlesmn | 0:3ac96e360672 | 280 | pdev->xtalk_results.central_histogram__window_start = 0xFF; |
charlesmn | 0:3ac96e360672 | 281 | pdev->xtalk_results.central_histogram__window_end = 0x00; |
charlesmn | 0:3ac96e360672 | 282 | |
charlesmn | 0:3ac96e360672 | 283 | pdev->xtalk_results.num_of_samples_status = 0x00; |
charlesmn | 0:3ac96e360672 | 284 | pdev->xtalk_results.zero_samples_status = 0x00; |
charlesmn | 0:3ac96e360672 | 285 | pdev->xtalk_results.max_sigma_status = 0x00; |
charlesmn | 0:3ac96e360672 | 286 | |
charlesmn | 0:3ac96e360672 | 287 | for (i = 0; i < pdev->xtalk_results.max_results; i++) { |
charlesmn | 0:3ac96e360672 | 288 | pdev->xtalk_results.VL53L1_p_002[i].no_of_samples = 0; |
charlesmn | 0:3ac96e360672 | 289 | pdev->xtalk_results.VL53L1_p_002[i].signal_total_events_avg = 0; |
charlesmn | 0:3ac96e360672 | 290 | pdev->xtalk_results.VL53L1_p_002[i].signal_total_events_sum = 0; |
charlesmn | 0:3ac96e360672 | 291 | pdev->xtalk_results.VL53L1_p_002[i].rate_per_spad_kcps_sum = 0; |
charlesmn | 0:3ac96e360672 | 292 | pdev->xtalk_results.VL53L1_p_002[i].rate_per_spad_kcps_avg = 0; |
charlesmn | 0:3ac96e360672 | 293 | pdev->xtalk_results.VL53L1_p_002[i].sigma_mm_sum = 0; |
charlesmn | 0:3ac96e360672 | 294 | pdev->xtalk_results.VL53L1_p_002[i].sigma_mm_avg = 0; |
charlesmn | 0:3ac96e360672 | 295 | |
charlesmn | 0:3ac96e360672 | 296 | pdev->xtalk_results.VL53L1_p_002[i].median_phase_sum = 0; |
charlesmn | 0:3ac96e360672 | 297 | pdev->xtalk_results.VL53L1_p_002[i].median_phase_avg = 0; |
charlesmn | 0:3ac96e360672 | 298 | |
charlesmn | 0:3ac96e360672 | 299 | } |
charlesmn | 0:3ac96e360672 | 300 | |
charlesmn | 0:3ac96e360672 | 301 | |
charlesmn | 0:3ac96e360672 | 302 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 303 | |
charlesmn | 0:3ac96e360672 | 304 | status = |
charlesmn | 0:3ac96e360672 | 305 | VL53L1_get_and_avg_xtalk_samples( |
charlesmn | 0:3ac96e360672 | 306 | Dev, |
charlesmn | 0:3ac96e360672 | 307 | |
charlesmn | 0:3ac96e360672 | 308 | pX->num_of_samples, |
charlesmn | 0:3ac96e360672 | 309 | |
charlesmn | 0:3ac96e360672 | 310 | measurement_mode, |
charlesmn | 0:3ac96e360672 | 311 | |
charlesmn | 0:3ac96e360672 | 312 | pX->algo__crosstalk_extract_max_valid_range_mm, |
charlesmn | 0:3ac96e360672 | 313 | pX->algo__crosstalk_extract_min_valid_range_mm, |
charlesmn | 0:3ac96e360672 | 314 | pX->algo__crosstalk_extract_max_valid_rate_kcps, |
charlesmn | 0:3ac96e360672 | 315 | |
charlesmn | 0:3ac96e360672 | 316 | 0x0, |
charlesmn | 0:3ac96e360672 | 317 | 0x4, |
charlesmn | 0:3ac96e360672 | 318 | &(pdev->xtalk_results), |
charlesmn | 0:3ac96e360672 | 319 | &(pdev->xtalk_results.central_histogram_sum), |
charlesmn | 0:3ac96e360672 | 320 | &(pdev->xtalk_results.central_histogram_avg)); |
charlesmn | 0:3ac96e360672 | 321 | } |
charlesmn | 0:3ac96e360672 | 322 | |
charlesmn | 0:3ac96e360672 | 323 | |
charlesmn | 0:3ac96e360672 | 324 | |
charlesmn | 0:3ac96e360672 | 325 | |
charlesmn | 0:3ac96e360672 | 326 | |
charlesmn | 0:3ac96e360672 | 327 | |
charlesmn | 0:3ac96e360672 | 328 | |
charlesmn | 0:3ac96e360672 | 329 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 330 | if ((pdev->xtalk_results.VL53L1_p_002[4].no_of_samples == 0) || |
charlesmn | 0:3ac96e360672 | 331 | (pdev->xtalk_results.VL53L1_p_002[4].sigma_mm_avg > |
charlesmn | 0:3ac96e360672 | 332 | ((uint32_t)pX->algo__crosstalk_extract_max_sigma_mm |
charlesmn | 0:3ac96e360672 | 333 | << 5))) |
charlesmn | 0:3ac96e360672 | 334 | results_invalid = 0x01; |
charlesmn | 0:3ac96e360672 | 335 | |
charlesmn | 0:3ac96e360672 | 336 | |
charlesmn | 0:3ac96e360672 | 337 | |
charlesmn | 0:3ac96e360672 | 338 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 339 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 340 | VL53L1_print_xtalk_range_results( |
charlesmn | 0:3ac96e360672 | 341 | &(pdev->xtalk_results), |
charlesmn | 0:3ac96e360672 | 342 | "pdev->xtalk_results", |
charlesmn | 0:3ac96e360672 | 343 | VL53L1_TRACE_MODULE_CORE); |
charlesmn | 0:3ac96e360672 | 344 | #endif |
charlesmn | 0:3ac96e360672 | 345 | |
charlesmn | 0:3ac96e360672 | 346 | if ((status == VL53L1_ERROR_NONE) && (results_invalid == 0)) { |
charlesmn | 0:3ac96e360672 | 347 | |
charlesmn | 0:3ac96e360672 | 348 | status = |
charlesmn | 0:3ac96e360672 | 349 | VL53L1_ipp_xtalk_calibration_process_data( |
charlesmn | 0:3ac96e360672 | 350 | Dev, |
charlesmn | 0:3ac96e360672 | 351 | &(pdev->xtalk_results), |
charlesmn | 0:3ac96e360672 | 352 | &(pdev->xtalk_shapes), |
charlesmn | 0:3ac96e360672 | 353 | &(pdev->xtalk_cal)); |
charlesmn | 0:3ac96e360672 | 354 | |
charlesmn | 0:3ac96e360672 | 355 | } |
charlesmn | 0:3ac96e360672 | 356 | if ((status == VL53L1_ERROR_NONE) && (results_invalid == 0)) { |
charlesmn | 0:3ac96e360672 | 357 | for (i = 0; i < VL53L1_BIN_REC_SIZE; i++) |
charlesmn | 0:3ac96e360672 | 358 | pXC->algo__xtalk_cpo_HistoMerge_kcps[i] = |
charlesmn | 0:3ac96e360672 | 359 | pXC->algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 360 | pC->algo__crosstalk_compensation_x_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 361 | pXC->algo__crosstalk_compensation_x_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 362 | pC->algo__crosstalk_compensation_y_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 363 | pXC->algo__crosstalk_compensation_y_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 364 | pC->algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 365 | pXC->algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 366 | } |
charlesmn | 0:3ac96e360672 | 367 | |
charlesmn | 0:3ac96e360672 | 368 | |
charlesmn | 0:3ac96e360672 | 369 | |
charlesmn | 0:3ac96e360672 | 370 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 371 | status = VL53L1_enable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 372 | |
charlesmn | 0:3ac96e360672 | 373 | |
charlesmn | 0:3ac96e360672 | 374 | |
charlesmn | 0:3ac96e360672 | 375 | |
charlesmn | 0:3ac96e360672 | 376 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 377 | |
charlesmn | 0:3ac96e360672 | 378 | for (i = 0; i < pdev->xtalk_results.max_results; i++) { |
charlesmn | 0:3ac96e360672 | 379 | |
charlesmn | 0:3ac96e360672 | 380 | if (pdev->xtalk_results.VL53L1_p_002[i].no_of_samples != |
charlesmn | 0:3ac96e360672 | 381 | |
charlesmn | 0:3ac96e360672 | 382 | pX->num_of_samples) { |
charlesmn | 0:3ac96e360672 | 383 | |
charlesmn | 0:3ac96e360672 | 384 | pdev->xtalk_results.num_of_samples_status = |
charlesmn | 0:3ac96e360672 | 385 | pdev->xtalk_results.num_of_samples_status | |
charlesmn | 0:3ac96e360672 | 386 | (1 << i); |
charlesmn | 0:3ac96e360672 | 387 | } |
charlesmn | 0:3ac96e360672 | 388 | |
charlesmn | 0:3ac96e360672 | 389 | if (pdev->xtalk_results.VL53L1_p_002[i].no_of_samples == |
charlesmn | 0:3ac96e360672 | 390 | 0x00) { |
charlesmn | 0:3ac96e360672 | 391 | pdev->xtalk_results.zero_samples_status = |
charlesmn | 0:3ac96e360672 | 392 | pdev->xtalk_results.zero_samples_status | |
charlesmn | 0:3ac96e360672 | 393 | (1 << i); |
charlesmn | 0:3ac96e360672 | 394 | } |
charlesmn | 0:3ac96e360672 | 395 | |
charlesmn | 0:3ac96e360672 | 396 | |
charlesmn | 0:3ac96e360672 | 397 | |
charlesmn | 0:3ac96e360672 | 398 | |
charlesmn | 0:3ac96e360672 | 399 | tmp16 = pX->algo__crosstalk_extract_max_sigma_mm; |
charlesmn | 0:3ac96e360672 | 400 | if (pdev->xtalk_results.VL53L1_p_002[i].sigma_mm_avg > |
charlesmn | 0:3ac96e360672 | 401 | ((uint32_t)tmp16 << 5)) { |
charlesmn | 0:3ac96e360672 | 402 | pdev->xtalk_results.max_sigma_status = |
charlesmn | 0:3ac96e360672 | 403 | pdev->xtalk_results.max_sigma_status | |
charlesmn | 0:3ac96e360672 | 404 | (1 << i); |
charlesmn | 0:3ac96e360672 | 405 | } |
charlesmn | 0:3ac96e360672 | 406 | |
charlesmn | 0:3ac96e360672 | 407 | } |
charlesmn | 0:3ac96e360672 | 408 | } |
charlesmn | 0:3ac96e360672 | 409 | |
charlesmn | 0:3ac96e360672 | 410 | |
charlesmn | 0:3ac96e360672 | 411 | if (results_invalid > 0) { |
charlesmn | 0:3ac96e360672 | 412 | |
charlesmn | 0:3ac96e360672 | 413 | if (pdev->xtalk_results.VL53L1_p_002[4].no_of_samples == 0) { |
charlesmn | 0:3ac96e360672 | 414 | status = VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL; |
charlesmn | 0:3ac96e360672 | 415 | } else { |
charlesmn | 0:3ac96e360672 | 416 | |
charlesmn | 0:3ac96e360672 | 417 | |
charlesmn | 0:3ac96e360672 | 418 | if (pdev->xtalk_results.VL53L1_p_002[4].sigma_mm_avg > |
charlesmn | 0:3ac96e360672 | 419 | (((uint32_t)pX->algo__crosstalk_extract_max_sigma_mm) |
charlesmn | 0:3ac96e360672 | 420 | << 5)) { |
charlesmn | 0:3ac96e360672 | 421 | status = |
charlesmn | 0:3ac96e360672 | 422 | VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL; |
charlesmn | 0:3ac96e360672 | 423 | } |
charlesmn | 0:3ac96e360672 | 424 | |
charlesmn | 0:3ac96e360672 | 425 | } |
charlesmn | 0:3ac96e360672 | 426 | } else { |
charlesmn | 0:3ac96e360672 | 427 | |
charlesmn | 0:3ac96e360672 | 428 | if (pdev->xtalk_results.zero_samples_status != 0x00) { |
charlesmn | 0:3ac96e360672 | 429 | status = VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT; |
charlesmn | 0:3ac96e360672 | 430 | } else { |
charlesmn | 0:3ac96e360672 | 431 | if (pdev->xtalk_results.max_sigma_status != 0x00) { |
charlesmn | 0:3ac96e360672 | 432 | status = |
charlesmn | 0:3ac96e360672 | 433 | VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT; |
charlesmn | 0:3ac96e360672 | 434 | } else { |
charlesmn | 0:3ac96e360672 | 435 | if (pdev->xtalk_results.num_of_samples_status != |
charlesmn | 0:3ac96e360672 | 436 | 0x00) |
charlesmn | 0:3ac96e360672 | 437 | status = |
charlesmn | 0:3ac96e360672 | 438 | VL53L1_WARNING_XTALK_MISSING_SAMPLES; |
charlesmn | 0:3ac96e360672 | 439 | } |
charlesmn | 0:3ac96e360672 | 440 | } |
charlesmn | 0:3ac96e360672 | 441 | } |
charlesmn | 0:3ac96e360672 | 442 | |
charlesmn | 0:3ac96e360672 | 443 | |
charlesmn | 0:3ac96e360672 | 444 | |
charlesmn | 0:3ac96e360672 | 445 | pdev->xtalk_results.cal_status = status; |
charlesmn | 0:3ac96e360672 | 446 | *pcal_status = pdev->xtalk_results.cal_status; |
charlesmn | 0:3ac96e360672 | 447 | |
charlesmn | 0:3ac96e360672 | 448 | |
charlesmn | 0:3ac96e360672 | 449 | |
charlesmn | 0:3ac96e360672 | 450 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 451 | IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FAIL, |
charlesmn | 0:3ac96e360672 | 452 | VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL, |
charlesmn | 0:3ac96e360672 | 453 | status); |
charlesmn | 0:3ac96e360672 | 454 | |
charlesmn | 0:3ac96e360672 | 455 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 456 | IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL, |
charlesmn | 0:3ac96e360672 | 457 | VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL, |
charlesmn | 0:3ac96e360672 | 458 | status); |
charlesmn | 0:3ac96e360672 | 459 | |
charlesmn | 0:3ac96e360672 | 460 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 461 | IGNORE_XTALK_EXTRACTION_NO_SAMPLE_FOR_GRADIENT_WARN, |
charlesmn | 0:3ac96e360672 | 462 | VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT, |
charlesmn | 0:3ac96e360672 | 463 | status); |
charlesmn | 0:3ac96e360672 | 464 | |
charlesmn | 0:3ac96e360672 | 465 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 466 | IGNORE_XTALK_EXTRACTION_SIGMA_LIMIT_FOR_GRADIENT_WARN, |
charlesmn | 0:3ac96e360672 | 467 | VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT, |
charlesmn | 0:3ac96e360672 | 468 | status); |
charlesmn | 0:3ac96e360672 | 469 | |
charlesmn | 0:3ac96e360672 | 470 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 471 | IGNORE_XTALK_EXTRACTION_MISSING_SAMPLES_WARN, |
charlesmn | 0:3ac96e360672 | 472 | VL53L1_WARNING_XTALK_MISSING_SAMPLES, |
charlesmn | 0:3ac96e360672 | 473 | status); |
charlesmn | 0:3ac96e360672 | 474 | |
charlesmn | 0:3ac96e360672 | 475 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 476 | |
charlesmn | 0:3ac96e360672 | 477 | |
charlesmn | 0:3ac96e360672 | 478 | |
charlesmn | 0:3ac96e360672 | 479 | VL53L1_print_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 480 | &(pdev->customer), |
charlesmn | 0:3ac96e360672 | 481 | "run_xtalk_extraction():pdev->lldata.customer.", |
charlesmn | 0:3ac96e360672 | 482 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 483 | |
charlesmn | 0:3ac96e360672 | 484 | VL53L1_print_xtalk_config( |
charlesmn | 0:3ac96e360672 | 485 | &(pdev->xtalk_cfg), |
charlesmn | 0:3ac96e360672 | 486 | "run_xtalk_extraction():pdev->lldata.xtalk_cfg.", |
charlesmn | 0:3ac96e360672 | 487 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 488 | |
charlesmn | 0:3ac96e360672 | 489 | VL53L1_print_xtalk_extract_config( |
charlesmn | 0:3ac96e360672 | 490 | &(pdev->xtalk_extract_cfg), |
charlesmn | 0:3ac96e360672 | 491 | "run_xtalk_extraction():pdev->lldata.xtalk_extract_cfg.", |
charlesmn | 0:3ac96e360672 | 492 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 493 | |
charlesmn | 0:3ac96e360672 | 494 | VL53L1_print_histogram_bin_data( |
charlesmn | 0:3ac96e360672 | 495 | &(pdev->hist_data), |
charlesmn | 0:3ac96e360672 | 496 | "run_xtalk_extraction():pdev->lldata.hist_data.", |
charlesmn | 0:3ac96e360672 | 497 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 498 | |
charlesmn | 0:3ac96e360672 | 499 | VL53L1_print_xtalk_histogram_data( |
charlesmn | 0:3ac96e360672 | 500 | &(pdev->xtalk_shapes), |
charlesmn | 0:3ac96e360672 | 501 | "pdev->lldata.xtalk_shapes.", |
charlesmn | 0:3ac96e360672 | 502 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 503 | |
charlesmn | 0:3ac96e360672 | 504 | VL53L1_print_xtalk_range_results( |
charlesmn | 0:3ac96e360672 | 505 | &(pdev->xtalk_results), |
charlesmn | 0:3ac96e360672 | 506 | "run_xtalk_extraction():pdev->lldata.xtalk_results.", |
charlesmn | 0:3ac96e360672 | 507 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 508 | |
charlesmn | 0:3ac96e360672 | 509 | #endif |
charlesmn | 0:3ac96e360672 | 510 | |
charlesmn | 0:3ac96e360672 | 511 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 512 | |
charlesmn | 0:3ac96e360672 | 513 | return status; |
charlesmn | 0:3ac96e360672 | 514 | |
charlesmn | 0:3ac96e360672 | 515 | } |
charlesmn | 0:3ac96e360672 | 516 | |
charlesmn | 0:3ac96e360672 | 517 | |
charlesmn | 0:3ac96e360672 | 518 | |
charlesmn | 0:3ac96e360672 | 519 | VL53L1_Error VL53L1_get_and_avg_xtalk_samples( |
charlesmn | 0:3ac96e360672 | 520 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 521 | uint8_t num_of_samples, |
charlesmn | 0:3ac96e360672 | 522 | uint8_t measurement_mode, |
charlesmn | 0:3ac96e360672 | 523 | int16_t xtalk_filter_thresh_max_mm, |
charlesmn | 0:3ac96e360672 | 524 | int16_t xtalk_filter_thresh_min_mm, |
charlesmn | 0:3ac96e360672 | 525 | uint16_t xtalk_max_valid_rate_kcps, |
charlesmn | 0:3ac96e360672 | 526 | uint8_t xtalk_result_id, |
charlesmn | 0:3ac96e360672 | 527 | uint8_t xtalk_histo_id, |
charlesmn | 0:3ac96e360672 | 528 | VL53L1_xtalk_range_results_t *pXR, |
charlesmn | 0:3ac96e360672 | 529 | VL53L1_histogram_bin_data_t *psum_histo, |
charlesmn | 0:3ac96e360672 | 530 | VL53L1_histogram_bin_data_t *pavg_histo) |
charlesmn | 0:3ac96e360672 | 531 | { |
charlesmn | 0:3ac96e360672 | 532 | |
charlesmn | 0:3ac96e360672 | 533 | |
charlesmn | 0:3ac96e360672 | 534 | |
charlesmn | 0:3ac96e360672 | 535 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 536 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 537 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 538 | |
charlesmn | 0:3ac96e360672 | 539 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 540 | VL53L1_LLDriverResults_t *pres = |
charlesmn | 0:3ac96e360672 | 541 | VL53L1DevStructGetLLResultsHandle(Dev); |
charlesmn | 0:3ac96e360672 | 542 | #endif |
charlesmn | 0:3ac96e360672 | 543 | |
charlesmn | 0:3ac96e360672 | 544 | VL53L1_range_results_t *prs = |
charlesmn | 0:3ac96e360672 | 545 | (VL53L1_range_results_t *) pdev->wArea1; |
charlesmn | 0:3ac96e360672 | 546 | |
charlesmn | 0:3ac96e360672 | 547 | VL53L1_range_data_t *prange_data; |
charlesmn | 0:3ac96e360672 | 548 | VL53L1_xtalk_range_data_t *pxtalk_range_data; |
charlesmn | 0:3ac96e360672 | 549 | |
charlesmn | 0:3ac96e360672 | 550 | uint8_t i = 0; |
charlesmn | 0:3ac96e360672 | 551 | uint8_t j = 0; |
charlesmn | 0:3ac96e360672 | 552 | uint8_t zone_id = 0; |
charlesmn | 0:3ac96e360672 | 553 | uint8_t final_zone = pdev->zone_cfg.active_zones+1; |
charlesmn | 0:3ac96e360672 | 554 | uint8_t valid_result; |
charlesmn | 0:3ac96e360672 | 555 | |
charlesmn | 0:3ac96e360672 | 556 | uint8_t smudge_corr_en = 0; |
charlesmn | 0:3ac96e360672 | 557 | |
charlesmn | 0:3ac96e360672 | 558 | |
charlesmn | 0:3ac96e360672 | 559 | |
charlesmn | 0:3ac96e360672 | 560 | |
charlesmn | 0:3ac96e360672 | 561 | smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled; |
charlesmn | 0:3ac96e360672 | 562 | |
charlesmn | 0:3ac96e360672 | 563 | status = VL53L1_dynamic_xtalk_correction_disable(Dev); |
charlesmn | 0:3ac96e360672 | 564 | |
charlesmn | 0:3ac96e360672 | 565 | |
charlesmn | 0:3ac96e360672 | 566 | VL53L1_load_patch(Dev); |
charlesmn | 0:3ac96e360672 | 567 | |
charlesmn | 0:3ac96e360672 | 568 | |
charlesmn | 0:3ac96e360672 | 569 | |
charlesmn | 0:3ac96e360672 | 570 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 571 | status = |
charlesmn | 0:3ac96e360672 | 572 | VL53L1_init_and_start_range( |
charlesmn | 0:3ac96e360672 | 573 | Dev, |
charlesmn | 0:3ac96e360672 | 574 | measurement_mode, |
charlesmn | 0:3ac96e360672 | 575 | VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS); |
charlesmn | 0:3ac96e360672 | 576 | |
charlesmn | 0:3ac96e360672 | 577 | |
charlesmn | 0:3ac96e360672 | 578 | for (i = 0; i <= (final_zone*num_of_samples); i++) { |
charlesmn | 0:3ac96e360672 | 579 | |
charlesmn | 0:3ac96e360672 | 580 | |
charlesmn | 0:3ac96e360672 | 581 | |
charlesmn | 0:3ac96e360672 | 582 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 583 | status = VL53L1_wait_for_range_completion(Dev); |
charlesmn | 0:3ac96e360672 | 584 | |
charlesmn | 0:3ac96e360672 | 585 | |
charlesmn | 0:3ac96e360672 | 586 | |
charlesmn | 0:3ac96e360672 | 587 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 588 | status = |
charlesmn | 0:3ac96e360672 | 589 | VL53L1_get_device_results( |
charlesmn | 0:3ac96e360672 | 590 | Dev, |
charlesmn | 0:3ac96e360672 | 591 | VL53L1_DEVICERESULTSLEVEL_FULL, |
charlesmn | 0:3ac96e360672 | 592 | prs); |
charlesmn | 0:3ac96e360672 | 593 | |
charlesmn | 0:3ac96e360672 | 594 | |
charlesmn | 0:3ac96e360672 | 595 | |
charlesmn | 0:3ac96e360672 | 596 | if (status == VL53L1_ERROR_NONE && |
charlesmn | 0:3ac96e360672 | 597 | pdev->ll_state.rd_device_state != |
charlesmn | 0:3ac96e360672 | 598 | VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC) { |
charlesmn | 0:3ac96e360672 | 599 | |
charlesmn | 0:3ac96e360672 | 600 | zone_id = pdev->ll_state.rd_zone_id + xtalk_result_id; |
charlesmn | 0:3ac96e360672 | 601 | prange_data = &(prs->VL53L1_p_002[0]); |
charlesmn | 0:3ac96e360672 | 602 | |
charlesmn | 0:3ac96e360672 | 603 | |
charlesmn | 0:3ac96e360672 | 604 | if (prs->active_results > 1) { |
charlesmn | 0:3ac96e360672 | 605 | for (j = 1; |
charlesmn | 0:3ac96e360672 | 606 | j < prs->active_results; j++) { |
charlesmn | 0:3ac96e360672 | 607 | if (prs->VL53L1_p_002[j].median_range_mm |
charlesmn | 0:3ac96e360672 | 608 | < |
charlesmn | 0:3ac96e360672 | 609 | prange_data->median_range_mm) |
charlesmn | 0:3ac96e360672 | 610 | prange_data = |
charlesmn | 0:3ac96e360672 | 611 | &(prs->VL53L1_p_002[j]); |
charlesmn | 0:3ac96e360672 | 612 | |
charlesmn | 0:3ac96e360672 | 613 | } |
charlesmn | 0:3ac96e360672 | 614 | } |
charlesmn | 0:3ac96e360672 | 615 | |
charlesmn | 0:3ac96e360672 | 616 | pxtalk_range_data = &(pXR->VL53L1_p_002[zone_id]); |
charlesmn | 0:3ac96e360672 | 617 | |
charlesmn | 0:3ac96e360672 | 618 | |
charlesmn | 0:3ac96e360672 | 619 | |
charlesmn | 0:3ac96e360672 | 620 | if ((prs->active_results > 0) && |
charlesmn | 0:3ac96e360672 | 621 | (prange_data->median_range_mm < |
charlesmn | 0:3ac96e360672 | 622 | xtalk_filter_thresh_max_mm) && |
charlesmn | 0:3ac96e360672 | 623 | (prange_data->median_range_mm > |
charlesmn | 0:3ac96e360672 | 624 | xtalk_filter_thresh_min_mm) && |
charlesmn | 0:3ac96e360672 | 625 | (prange_data->VL53L1_p_012 < |
charlesmn | 0:3ac96e360672 | 626 | (uint32_t)(xtalk_max_valid_rate_kcps * 16))) |
charlesmn | 0:3ac96e360672 | 627 | valid_result = 1; |
charlesmn | 0:3ac96e360672 | 628 | else |
charlesmn | 0:3ac96e360672 | 629 | valid_result = 0; |
charlesmn | 0:3ac96e360672 | 630 | |
charlesmn | 0:3ac96e360672 | 631 | if (valid_result == 1) { |
charlesmn | 0:3ac96e360672 | 632 | |
charlesmn | 0:3ac96e360672 | 633 | pxtalk_range_data->no_of_samples++; |
charlesmn | 0:3ac96e360672 | 634 | |
charlesmn | 0:3ac96e360672 | 635 | pxtalk_range_data->rate_per_spad_kcps_sum += |
charlesmn | 0:3ac96e360672 | 636 | prange_data->VL53L1_p_012; |
charlesmn | 0:3ac96e360672 | 637 | |
charlesmn | 0:3ac96e360672 | 638 | pxtalk_range_data->signal_total_events_sum += |
charlesmn | 0:3ac96e360672 | 639 | prange_data->VL53L1_p_013; |
charlesmn | 0:3ac96e360672 | 640 | |
charlesmn | 0:3ac96e360672 | 641 | pxtalk_range_data->sigma_mm_sum += |
charlesmn | 0:3ac96e360672 | 642 | (uint32_t)prange_data->VL53L1_p_005; |
charlesmn | 0:3ac96e360672 | 643 | |
charlesmn | 0:3ac96e360672 | 644 | |
charlesmn | 0:3ac96e360672 | 645 | |
charlesmn | 0:3ac96e360672 | 646 | pxtalk_range_data->median_phase_sum += |
charlesmn | 0:3ac96e360672 | 647 | (uint32_t)prange_data->VL53L1_p_014; |
charlesmn | 0:3ac96e360672 | 648 | |
charlesmn | 0:3ac96e360672 | 649 | |
charlesmn | 0:3ac96e360672 | 650 | |
charlesmn | 0:3ac96e360672 | 651 | |
charlesmn | 0:3ac96e360672 | 652 | } |
charlesmn | 0:3ac96e360672 | 653 | |
charlesmn | 0:3ac96e360672 | 654 | if ((valid_result == 1) && (zone_id >= 4)) { |
charlesmn | 0:3ac96e360672 | 655 | status = VL53L1_sum_histogram_data( |
charlesmn | 0:3ac96e360672 | 656 | &(pdev->hist_data), |
charlesmn | 0:3ac96e360672 | 657 | psum_histo); |
charlesmn | 0:3ac96e360672 | 658 | |
charlesmn | 0:3ac96e360672 | 659 | |
charlesmn | 0:3ac96e360672 | 660 | |
charlesmn | 0:3ac96e360672 | 661 | if (prange_data->VL53L1_p_015 < |
charlesmn | 0:3ac96e360672 | 662 | pXR->central_histogram__window_start) |
charlesmn | 0:3ac96e360672 | 663 | pXR->central_histogram__window_start = |
charlesmn | 0:3ac96e360672 | 664 | prange_data->VL53L1_p_015; |
charlesmn | 0:3ac96e360672 | 665 | |
charlesmn | 0:3ac96e360672 | 666 | |
charlesmn | 0:3ac96e360672 | 667 | if (prange_data->VL53L1_p_016 > |
charlesmn | 0:3ac96e360672 | 668 | pXR->central_histogram__window_end) |
charlesmn | 0:3ac96e360672 | 669 | pXR->central_histogram__window_end = |
charlesmn | 0:3ac96e360672 | 670 | prange_data->VL53L1_p_016; |
charlesmn | 0:3ac96e360672 | 671 | |
charlesmn | 0:3ac96e360672 | 672 | } |
charlesmn | 0:3ac96e360672 | 673 | |
charlesmn | 0:3ac96e360672 | 674 | } |
charlesmn | 0:3ac96e360672 | 675 | |
charlesmn | 0:3ac96e360672 | 676 | |
charlesmn | 0:3ac96e360672 | 677 | |
charlesmn | 0:3ac96e360672 | 678 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 679 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 680 | VL53L1_print_range_results( |
charlesmn | 0:3ac96e360672 | 681 | &(pres->range_results), |
charlesmn | 0:3ac96e360672 | 682 | "pres->range_results.", |
charlesmn | 0:3ac96e360672 | 683 | VL53L1_TRACE_MODULE_CORE); |
charlesmn | 0:3ac96e360672 | 684 | } |
charlesmn | 0:3ac96e360672 | 685 | #endif |
charlesmn | 0:3ac96e360672 | 686 | |
charlesmn | 0:3ac96e360672 | 687 | |
charlesmn | 0:3ac96e360672 | 688 | |
charlesmn | 0:3ac96e360672 | 689 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 690 | status = VL53L1_wait_for_firmware_ready(Dev); |
charlesmn | 0:3ac96e360672 | 691 | |
charlesmn | 0:3ac96e360672 | 692 | |
charlesmn | 0:3ac96e360672 | 693 | |
charlesmn | 0:3ac96e360672 | 694 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 695 | status = |
charlesmn | 0:3ac96e360672 | 696 | VL53L1_clear_interrupt_and_enable_next_range( |
charlesmn | 0:3ac96e360672 | 697 | Dev, |
charlesmn | 0:3ac96e360672 | 698 | measurement_mode); |
charlesmn | 0:3ac96e360672 | 699 | |
charlesmn | 0:3ac96e360672 | 700 | |
charlesmn | 0:3ac96e360672 | 701 | } |
charlesmn | 0:3ac96e360672 | 702 | |
charlesmn | 0:3ac96e360672 | 703 | |
charlesmn | 0:3ac96e360672 | 704 | |
charlesmn | 0:3ac96e360672 | 705 | |
charlesmn | 0:3ac96e360672 | 706 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 707 | status = VL53L1_stop_range(Dev); |
charlesmn | 0:3ac96e360672 | 708 | |
charlesmn | 0:3ac96e360672 | 709 | VL53L1_unload_patch(Dev); |
charlesmn | 0:3ac96e360672 | 710 | |
charlesmn | 0:3ac96e360672 | 711 | |
charlesmn | 0:3ac96e360672 | 712 | |
charlesmn | 0:3ac96e360672 | 713 | for (i = 0; i < (pdev->zone_cfg.active_zones+1); i++) { |
charlesmn | 0:3ac96e360672 | 714 | |
charlesmn | 0:3ac96e360672 | 715 | pxtalk_range_data = &(pXR->VL53L1_p_002[i+xtalk_result_id]); |
charlesmn | 0:3ac96e360672 | 716 | |
charlesmn | 0:3ac96e360672 | 717 | if (pxtalk_range_data->no_of_samples > 0) { |
charlesmn | 0:3ac96e360672 | 718 | pxtalk_range_data->rate_per_spad_kcps_avg = |
charlesmn | 0:3ac96e360672 | 719 | pxtalk_range_data->rate_per_spad_kcps_sum / |
charlesmn | 0:3ac96e360672 | 720 | (uint32_t)pxtalk_range_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 721 | |
charlesmn | 0:3ac96e360672 | 722 | pxtalk_range_data->signal_total_events_avg = |
charlesmn | 0:3ac96e360672 | 723 | pxtalk_range_data->signal_total_events_sum / |
charlesmn | 0:3ac96e360672 | 724 | (int32_t)pxtalk_range_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 725 | |
charlesmn | 0:3ac96e360672 | 726 | pxtalk_range_data->sigma_mm_avg = |
charlesmn | 0:3ac96e360672 | 727 | pxtalk_range_data->sigma_mm_sum / |
charlesmn | 0:3ac96e360672 | 728 | (uint32_t)pxtalk_range_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 729 | |
charlesmn | 0:3ac96e360672 | 730 | |
charlesmn | 0:3ac96e360672 | 731 | |
charlesmn | 0:3ac96e360672 | 732 | pxtalk_range_data->median_phase_avg = |
charlesmn | 0:3ac96e360672 | 733 | pxtalk_range_data->median_phase_sum / |
charlesmn | 0:3ac96e360672 | 734 | (uint32_t)pxtalk_range_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 735 | |
charlesmn | 0:3ac96e360672 | 736 | |
charlesmn | 0:3ac96e360672 | 737 | |
charlesmn | 0:3ac96e360672 | 738 | } else { |
charlesmn | 0:3ac96e360672 | 739 | pxtalk_range_data->rate_per_spad_kcps_avg = |
charlesmn | 0:3ac96e360672 | 740 | pxtalk_range_data->rate_per_spad_kcps_sum; |
charlesmn | 0:3ac96e360672 | 741 | pxtalk_range_data->signal_total_events_avg = |
charlesmn | 0:3ac96e360672 | 742 | pxtalk_range_data->signal_total_events_sum; |
charlesmn | 0:3ac96e360672 | 743 | pxtalk_range_data->sigma_mm_avg = |
charlesmn | 0:3ac96e360672 | 744 | pxtalk_range_data->sigma_mm_sum; |
charlesmn | 0:3ac96e360672 | 745 | |
charlesmn | 0:3ac96e360672 | 746 | |
charlesmn | 0:3ac96e360672 | 747 | |
charlesmn | 0:3ac96e360672 | 748 | pxtalk_range_data->median_phase_avg = |
charlesmn | 0:3ac96e360672 | 749 | pxtalk_range_data->median_phase_sum; |
charlesmn | 0:3ac96e360672 | 750 | |
charlesmn | 0:3ac96e360672 | 751 | |
charlesmn | 0:3ac96e360672 | 752 | } |
charlesmn | 0:3ac96e360672 | 753 | } |
charlesmn | 0:3ac96e360672 | 754 | |
charlesmn | 0:3ac96e360672 | 755 | |
charlesmn | 0:3ac96e360672 | 756 | |
charlesmn | 0:3ac96e360672 | 757 | memcpy(pavg_histo, &(pdev->hist_data), |
charlesmn | 0:3ac96e360672 | 758 | sizeof(VL53L1_histogram_bin_data_t)); |
charlesmn | 0:3ac96e360672 | 759 | |
charlesmn | 0:3ac96e360672 | 760 | |
charlesmn | 0:3ac96e360672 | 761 | |
charlesmn | 0:3ac96e360672 | 762 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 763 | |
charlesmn | 0:3ac96e360672 | 764 | pxtalk_range_data = &(pXR->VL53L1_p_002[xtalk_histo_id]); |
charlesmn | 0:3ac96e360672 | 765 | |
charlesmn | 0:3ac96e360672 | 766 | status = VL53L1_avg_histogram_data( |
charlesmn | 0:3ac96e360672 | 767 | pxtalk_range_data->no_of_samples, |
charlesmn | 0:3ac96e360672 | 768 | psum_histo, |
charlesmn | 0:3ac96e360672 | 769 | pavg_histo); |
charlesmn | 0:3ac96e360672 | 770 | } |
charlesmn | 0:3ac96e360672 | 771 | |
charlesmn | 0:3ac96e360672 | 772 | |
charlesmn | 0:3ac96e360672 | 773 | |
charlesmn | 0:3ac96e360672 | 774 | |
charlesmn | 0:3ac96e360672 | 775 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 776 | if (smudge_corr_en == 1) |
charlesmn | 0:3ac96e360672 | 777 | status = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 778 | } |
charlesmn | 0:3ac96e360672 | 779 | |
charlesmn | 0:3ac96e360672 | 780 | |
charlesmn | 0:3ac96e360672 | 781 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 782 | |
charlesmn | 0:3ac96e360672 | 783 | return status; |
charlesmn | 0:3ac96e360672 | 784 | |
charlesmn | 0:3ac96e360672 | 785 | } |
charlesmn | 0:3ac96e360672 | 786 | |
charlesmn | 0:3ac96e360672 | 787 | |
charlesmn | 0:3ac96e360672 | 788 | |
charlesmn | 0:3ac96e360672 | 789 | VL53L1_Error VL53L1_run_offset_calibration( |
charlesmn | 0:3ac96e360672 | 790 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 791 | int16_t cal_distance_mm, |
charlesmn | 0:3ac96e360672 | 792 | uint16_t cal_reflectance_pc, |
charlesmn | 0:3ac96e360672 | 793 | VL53L1_Error *pcal_status) |
charlesmn | 0:3ac96e360672 | 794 | { |
charlesmn | 0:3ac96e360672 | 795 | |
charlesmn | 0:3ac96e360672 | 796 | |
charlesmn | 0:3ac96e360672 | 797 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 798 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 799 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 800 | |
charlesmn | 0:3ac96e360672 | 801 | VL53L1_DevicePresetModes device_preset_modes[ |
charlesmn | 0:3ac96e360672 | 802 | VL53L1_MAX_OFFSET_RANGE_RESULTS]; |
charlesmn | 0:3ac96e360672 | 803 | |
charlesmn | 0:3ac96e360672 | 804 | VL53L1_range_results_t *prange_results = |
charlesmn | 0:3ac96e360672 | 805 | (VL53L1_range_results_t *) pdev->wArea1; |
charlesmn | 0:3ac96e360672 | 806 | |
charlesmn | 0:3ac96e360672 | 807 | VL53L1_range_data_t *pRData = NULL; |
charlesmn | 0:3ac96e360672 | 808 | VL53L1_offset_range_data_t *pfs = NULL; |
charlesmn | 0:3ac96e360672 | 809 | VL53L1_general_config_t *pG = &(pdev->gen_cfg); |
charlesmn | 0:3ac96e360672 | 810 | VL53L1_additional_offset_cal_data_t *pAO = &(pdev->add_off_cal_data); |
charlesmn | 0:3ac96e360672 | 811 | |
charlesmn | 0:3ac96e360672 | 812 | uint8_t i = 0; |
charlesmn | 0:3ac96e360672 | 813 | uint8_t m = 0; |
charlesmn | 0:3ac96e360672 | 814 | uint8_t measurement_mode = |
charlesmn | 0:3ac96e360672 | 815 | VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK; |
charlesmn | 0:3ac96e360672 | 816 | uint16_t manual_effective_spads = |
charlesmn | 0:3ac96e360672 | 817 | pG->dss_config__manual_effective_spads_select; |
charlesmn | 0:3ac96e360672 | 818 | |
charlesmn | 0:3ac96e360672 | 819 | uint8_t num_of_samples[VL53L1_MAX_OFFSET_RANGE_RESULTS]; |
charlesmn | 0:3ac96e360672 | 820 | |
charlesmn | 0:3ac96e360672 | 821 | uint8_t smudge_corr_en = 0; |
charlesmn | 0:3ac96e360672 | 822 | |
charlesmn | 0:3ac96e360672 | 823 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 824 | |
charlesmn | 0:3ac96e360672 | 825 | |
charlesmn | 0:3ac96e360672 | 826 | |
charlesmn | 0:3ac96e360672 | 827 | switch (pdev->offset_calibration_mode) { |
charlesmn | 0:3ac96e360672 | 828 | |
charlesmn | 0:3ac96e360672 | 829 | case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM: |
charlesmn | 0:3ac96e360672 | 830 | case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY: |
charlesmn | 0:3ac96e360672 | 831 | device_preset_modes[0] = |
charlesmn | 0:3ac96e360672 | 832 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING; |
charlesmn | 0:3ac96e360672 | 833 | device_preset_modes[1] = |
charlesmn | 0:3ac96e360672 | 834 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM1_CAL; |
charlesmn | 0:3ac96e360672 | 835 | device_preset_modes[2] = |
charlesmn | 0:3ac96e360672 | 836 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_RANGING_MM2_CAL; |
charlesmn | 0:3ac96e360672 | 837 | break; |
charlesmn | 0:3ac96e360672 | 838 | |
charlesmn | 0:3ac96e360672 | 839 | default: |
charlesmn | 0:3ac96e360672 | 840 | device_preset_modes[0] = |
charlesmn | 0:3ac96e360672 | 841 | VL53L1_DEVICEPRESETMODE_STANDARD_RANGING; |
charlesmn | 0:3ac96e360672 | 842 | device_preset_modes[1] = |
charlesmn | 0:3ac96e360672 | 843 | VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM1_CAL; |
charlesmn | 0:3ac96e360672 | 844 | device_preset_modes[2] = |
charlesmn | 0:3ac96e360672 | 845 | VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_MM2_CAL; |
charlesmn | 0:3ac96e360672 | 846 | break; |
charlesmn | 0:3ac96e360672 | 847 | } |
charlesmn | 0:3ac96e360672 | 848 | |
charlesmn | 0:3ac96e360672 | 849 | |
charlesmn | 0:3ac96e360672 | 850 | |
charlesmn | 0:3ac96e360672 | 851 | num_of_samples[0] = pdev->offsetcal_cfg.pre_num_of_samples; |
charlesmn | 0:3ac96e360672 | 852 | num_of_samples[1] = pdev->offsetcal_cfg.mm1_num_of_samples; |
charlesmn | 0:3ac96e360672 | 853 | num_of_samples[2] = pdev->offsetcal_cfg.mm2_num_of_samples; |
charlesmn | 0:3ac96e360672 | 854 | |
charlesmn | 0:3ac96e360672 | 855 | |
charlesmn | 0:3ac96e360672 | 856 | |
charlesmn | 0:3ac96e360672 | 857 | |
charlesmn | 0:3ac96e360672 | 858 | switch (pdev->offset_calibration_mode) { |
charlesmn | 0:3ac96e360672 | 859 | |
charlesmn | 0:3ac96e360672 | 860 | case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY: |
charlesmn | 0:3ac96e360672 | 861 | case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY: |
charlesmn | 0:3ac96e360672 | 862 | |
charlesmn | 0:3ac96e360672 | 863 | pdev->offset_results.active_results = 1; |
charlesmn | 0:3ac96e360672 | 864 | |
charlesmn | 0:3ac96e360672 | 865 | break; |
charlesmn | 0:3ac96e360672 | 866 | |
charlesmn | 0:3ac96e360672 | 867 | default: |
charlesmn | 0:3ac96e360672 | 868 | |
charlesmn | 0:3ac96e360672 | 869 | pdev->customer.mm_config__inner_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 870 | pdev->customer.mm_config__outer_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 871 | pdev->offset_results.active_results = |
charlesmn | 0:3ac96e360672 | 872 | VL53L1_MAX_OFFSET_RANGE_RESULTS; |
charlesmn | 0:3ac96e360672 | 873 | |
charlesmn | 0:3ac96e360672 | 874 | break; |
charlesmn | 0:3ac96e360672 | 875 | } |
charlesmn | 0:3ac96e360672 | 876 | |
charlesmn | 0:3ac96e360672 | 877 | pdev->customer.algo__part_to_part_range_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 878 | |
charlesmn | 0:3ac96e360672 | 879 | |
charlesmn | 0:3ac96e360672 | 880 | |
charlesmn | 0:3ac96e360672 | 881 | pdev->offset_results.max_results = VL53L1_MAX_OFFSET_RANGE_RESULTS; |
charlesmn | 0:3ac96e360672 | 882 | pdev->offset_results.cal_distance_mm = cal_distance_mm; |
charlesmn | 0:3ac96e360672 | 883 | pdev->offset_results.cal_reflectance_pc = cal_reflectance_pc; |
charlesmn | 0:3ac96e360672 | 884 | |
charlesmn | 0:3ac96e360672 | 885 | for (m = 0; m < VL53L1_MAX_OFFSET_RANGE_RESULTS; m++) { |
charlesmn | 0:3ac96e360672 | 886 | |
charlesmn | 0:3ac96e360672 | 887 | pfs = &(pdev->offset_results.VL53L1_p_002[m]); |
charlesmn | 0:3ac96e360672 | 888 | pfs->preset_mode = 0; |
charlesmn | 0:3ac96e360672 | 889 | pfs->no_of_samples = 0; |
charlesmn | 0:3ac96e360672 | 890 | pfs->effective_spads = 0; |
charlesmn | 0:3ac96e360672 | 891 | pfs->peak_rate_mcps = 0; |
charlesmn | 0:3ac96e360672 | 892 | pfs->VL53L1_p_005 = 0; |
charlesmn | 0:3ac96e360672 | 893 | pfs->median_range_mm = 0; |
charlesmn | 0:3ac96e360672 | 894 | } |
charlesmn | 0:3ac96e360672 | 895 | |
charlesmn | 0:3ac96e360672 | 896 | |
charlesmn | 0:3ac96e360672 | 897 | |
charlesmn | 0:3ac96e360672 | 898 | |
charlesmn | 0:3ac96e360672 | 899 | smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled; |
charlesmn | 0:3ac96e360672 | 900 | |
charlesmn | 0:3ac96e360672 | 901 | status = VL53L1_dynamic_xtalk_correction_disable(Dev); |
charlesmn | 0:3ac96e360672 | 902 | |
charlesmn | 0:3ac96e360672 | 903 | |
charlesmn | 0:3ac96e360672 | 904 | |
charlesmn | 0:3ac96e360672 | 905 | for (m = 0; m < pdev->offset_results.active_results; m++) { |
charlesmn | 0:3ac96e360672 | 906 | |
charlesmn | 0:3ac96e360672 | 907 | pfs = &(pdev->offset_results.VL53L1_p_002[m]); |
charlesmn | 0:3ac96e360672 | 908 | |
charlesmn | 0:3ac96e360672 | 909 | pfs->preset_mode = device_preset_modes[m]; |
charlesmn | 0:3ac96e360672 | 910 | |
charlesmn | 0:3ac96e360672 | 911 | |
charlesmn | 0:3ac96e360672 | 912 | |
charlesmn | 0:3ac96e360672 | 913 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 914 | status = |
charlesmn | 0:3ac96e360672 | 915 | VL53L1_set_preset_mode( |
charlesmn | 0:3ac96e360672 | 916 | Dev, |
charlesmn | 0:3ac96e360672 | 917 | device_preset_modes[m], |
charlesmn | 0:3ac96e360672 | 918 | |
charlesmn | 0:3ac96e360672 | 919 | pdev->offsetcal_cfg.dss_config__target_total_rate_mcps, |
charlesmn | 0:3ac96e360672 | 920 | pdev->offsetcal_cfg.phasecal_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 921 | pdev->offsetcal_cfg.mm_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 922 | pdev->offsetcal_cfg.range_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 923 | |
charlesmn | 0:3ac96e360672 | 924 | 100); |
charlesmn | 0:3ac96e360672 | 925 | |
charlesmn | 0:3ac96e360672 | 926 | pG->dss_config__manual_effective_spads_select = |
charlesmn | 0:3ac96e360672 | 927 | manual_effective_spads; |
charlesmn | 0:3ac96e360672 | 928 | |
charlesmn | 0:3ac96e360672 | 929 | |
charlesmn | 0:3ac96e360672 | 930 | VL53L1_load_patch(Dev); |
charlesmn | 0:3ac96e360672 | 931 | |
charlesmn | 0:3ac96e360672 | 932 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 933 | status = |
charlesmn | 0:3ac96e360672 | 934 | VL53L1_init_and_start_range( |
charlesmn | 0:3ac96e360672 | 935 | Dev, |
charlesmn | 0:3ac96e360672 | 936 | measurement_mode, |
charlesmn | 0:3ac96e360672 | 937 | VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS); |
charlesmn | 0:3ac96e360672 | 938 | |
charlesmn | 0:3ac96e360672 | 939 | for (i = 0; i <= (num_of_samples[m]+2); i++) { |
charlesmn | 0:3ac96e360672 | 940 | |
charlesmn | 0:3ac96e360672 | 941 | |
charlesmn | 0:3ac96e360672 | 942 | |
charlesmn | 0:3ac96e360672 | 943 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 944 | status = |
charlesmn | 0:3ac96e360672 | 945 | VL53L1_wait_for_range_completion(Dev); |
charlesmn | 0:3ac96e360672 | 946 | |
charlesmn | 0:3ac96e360672 | 947 | |
charlesmn | 0:3ac96e360672 | 948 | |
charlesmn | 0:3ac96e360672 | 949 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 950 | status = |
charlesmn | 0:3ac96e360672 | 951 | VL53L1_get_device_results( |
charlesmn | 0:3ac96e360672 | 952 | Dev, |
charlesmn | 0:3ac96e360672 | 953 | VL53L1_DEVICERESULTSLEVEL_FULL, |
charlesmn | 0:3ac96e360672 | 954 | prange_results); |
charlesmn | 0:3ac96e360672 | 955 | |
charlesmn | 0:3ac96e360672 | 956 | |
charlesmn | 0:3ac96e360672 | 957 | |
charlesmn | 0:3ac96e360672 | 958 | pRData = &(prange_results->VL53L1_p_002[0]); |
charlesmn | 0:3ac96e360672 | 959 | |
charlesmn | 0:3ac96e360672 | 960 | if ((prange_results->active_results > 0 && |
charlesmn | 0:3ac96e360672 | 961 | prange_results->stream_count > 1) && |
charlesmn | 0:3ac96e360672 | 962 | (pRData->range_status == |
charlesmn | 0:3ac96e360672 | 963 | VL53L1_DEVICEERROR_RANGECOMPLETE)) { |
charlesmn | 0:3ac96e360672 | 964 | |
charlesmn | 0:3ac96e360672 | 965 | pfs->no_of_samples++; |
charlesmn | 0:3ac96e360672 | 966 | pfs->effective_spads += |
charlesmn | 0:3ac96e360672 | 967 | (uint32_t)pRData->VL53L1_p_006; |
charlesmn | 0:3ac96e360672 | 968 | pfs->peak_rate_mcps += |
charlesmn | 0:3ac96e360672 | 969 | (uint32_t)pRData->peak_signal_count_rate_mcps; |
charlesmn | 0:3ac96e360672 | 970 | pfs->VL53L1_p_005 += |
charlesmn | 0:3ac96e360672 | 971 | (uint32_t)pRData->VL53L1_p_005; |
charlesmn | 0:3ac96e360672 | 972 | pfs->median_range_mm += |
charlesmn | 0:3ac96e360672 | 973 | (int32_t)pRData->median_range_mm; |
charlesmn | 0:3ac96e360672 | 974 | |
charlesmn | 0:3ac96e360672 | 975 | pfs->dss_config__roi_mode_control = |
charlesmn | 0:3ac96e360672 | 976 | pG->dss_config__roi_mode_control; |
charlesmn | 0:3ac96e360672 | 977 | pfs->dss_config__manual_effective_spads_select = |
charlesmn | 0:3ac96e360672 | 978 | pG->dss_config__manual_effective_spads_select; |
charlesmn | 0:3ac96e360672 | 979 | |
charlesmn | 0:3ac96e360672 | 980 | } |
charlesmn | 0:3ac96e360672 | 981 | |
charlesmn | 0:3ac96e360672 | 982 | |
charlesmn | 0:3ac96e360672 | 983 | |
charlesmn | 0:3ac96e360672 | 984 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 985 | status = |
charlesmn | 0:3ac96e360672 | 986 | VL53L1_wait_for_firmware_ready(Dev); |
charlesmn | 0:3ac96e360672 | 987 | |
charlesmn | 0:3ac96e360672 | 988 | |
charlesmn | 0:3ac96e360672 | 989 | |
charlesmn | 0:3ac96e360672 | 990 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 991 | status = |
charlesmn | 0:3ac96e360672 | 992 | VL53L1_clear_interrupt_and_enable_next_range( |
charlesmn | 0:3ac96e360672 | 993 | Dev, |
charlesmn | 0:3ac96e360672 | 994 | measurement_mode); |
charlesmn | 0:3ac96e360672 | 995 | } |
charlesmn | 0:3ac96e360672 | 996 | |
charlesmn | 0:3ac96e360672 | 997 | |
charlesmn | 0:3ac96e360672 | 998 | |
charlesmn | 0:3ac96e360672 | 999 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1000 | status = VL53L1_stop_range(Dev); |
charlesmn | 0:3ac96e360672 | 1001 | |
charlesmn | 0:3ac96e360672 | 1002 | |
charlesmn | 0:3ac96e360672 | 1003 | |
charlesmn | 0:3ac96e360672 | 1004 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1005 | status = VL53L1_WaitUs(Dev, 1000); |
charlesmn | 0:3ac96e360672 | 1006 | VL53L1_unload_patch(Dev); |
charlesmn | 0:3ac96e360672 | 1007 | |
charlesmn | 0:3ac96e360672 | 1008 | |
charlesmn | 0:3ac96e360672 | 1009 | if (pfs->no_of_samples > 0) { |
charlesmn | 0:3ac96e360672 | 1010 | |
charlesmn | 0:3ac96e360672 | 1011 | pfs->effective_spads += (pfs->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1012 | pfs->effective_spads /= pfs->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1013 | |
charlesmn | 0:3ac96e360672 | 1014 | pfs->peak_rate_mcps += (pfs->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1015 | pfs->peak_rate_mcps /= pfs->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1016 | |
charlesmn | 0:3ac96e360672 | 1017 | pfs->VL53L1_p_005 += (pfs->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1018 | pfs->VL53L1_p_005 /= pfs->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1019 | |
charlesmn | 0:3ac96e360672 | 1020 | pfs->median_range_mm += (pfs->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1021 | pfs->median_range_mm /= pfs->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1022 | |
charlesmn | 0:3ac96e360672 | 1023 | pfs->range_mm_offset = (int32_t)cal_distance_mm; |
charlesmn | 0:3ac96e360672 | 1024 | pfs->range_mm_offset -= pfs->median_range_mm; |
charlesmn | 0:3ac96e360672 | 1025 | |
charlesmn | 0:3ac96e360672 | 1026 | |
charlesmn | 0:3ac96e360672 | 1027 | if (pfs->preset_mode == |
charlesmn | 0:3ac96e360672 | 1028 | VL53L1_DEVICEPRESETMODE_STANDARD_RANGING) |
charlesmn | 0:3ac96e360672 | 1029 | manual_effective_spads = |
charlesmn | 0:3ac96e360672 | 1030 | (uint16_t)pfs->effective_spads; |
charlesmn | 0:3ac96e360672 | 1031 | } |
charlesmn | 0:3ac96e360672 | 1032 | } |
charlesmn | 0:3ac96e360672 | 1033 | |
charlesmn | 0:3ac96e360672 | 1034 | |
charlesmn | 0:3ac96e360672 | 1035 | |
charlesmn | 0:3ac96e360672 | 1036 | switch (pdev->offset_calibration_mode) { |
charlesmn | 0:3ac96e360672 | 1037 | |
charlesmn | 0:3ac96e360672 | 1038 | case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY: |
charlesmn | 0:3ac96e360672 | 1039 | case VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__HISTOGRAM_PRE_RANGE_ONLY: |
charlesmn | 0:3ac96e360672 | 1040 | |
charlesmn | 0:3ac96e360672 | 1041 | |
charlesmn | 0:3ac96e360672 | 1042 | pdev->customer.mm_config__inner_offset_mm += |
charlesmn | 0:3ac96e360672 | 1043 | (int16_t)pdev->offset_results.VL53L1_p_002[0].range_mm_offset; |
charlesmn | 0:3ac96e360672 | 1044 | pdev->customer.mm_config__outer_offset_mm += |
charlesmn | 0:3ac96e360672 | 1045 | (int16_t)pdev->offset_results.VL53L1_p_002[0].range_mm_offset; |
charlesmn | 0:3ac96e360672 | 1046 | break; |
charlesmn | 0:3ac96e360672 | 1047 | |
charlesmn | 0:3ac96e360672 | 1048 | default: |
charlesmn | 0:3ac96e360672 | 1049 | |
charlesmn | 0:3ac96e360672 | 1050 | pdev->customer.mm_config__inner_offset_mm = |
charlesmn | 0:3ac96e360672 | 1051 | (int16_t)pdev->offset_results.VL53L1_p_002[1].range_mm_offset; |
charlesmn | 0:3ac96e360672 | 1052 | pdev->customer.mm_config__outer_offset_mm = |
charlesmn | 0:3ac96e360672 | 1053 | (int16_t)pdev->offset_results.VL53L1_p_002[2].range_mm_offset; |
charlesmn | 0:3ac96e360672 | 1054 | pdev->customer.algo__part_to_part_range_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 1055 | |
charlesmn | 0:3ac96e360672 | 1056 | |
charlesmn | 0:3ac96e360672 | 1057 | |
charlesmn | 0:3ac96e360672 | 1058 | pAO->result__mm_inner_actual_effective_spads = |
charlesmn | 0:3ac96e360672 | 1059 | (uint16_t)pdev->offset_results.VL53L1_p_002[1].effective_spads; |
charlesmn | 0:3ac96e360672 | 1060 | pAO->result__mm_outer_actual_effective_spads = |
charlesmn | 0:3ac96e360672 | 1061 | (uint16_t)pdev->offset_results.VL53L1_p_002[2].effective_spads; |
charlesmn | 0:3ac96e360672 | 1062 | |
charlesmn | 0:3ac96e360672 | 1063 | pAO->result__mm_inner_peak_signal_count_rtn_mcps = |
charlesmn | 0:3ac96e360672 | 1064 | (uint16_t)pdev->offset_results.VL53L1_p_002[1].peak_rate_mcps; |
charlesmn | 0:3ac96e360672 | 1065 | pAO->result__mm_outer_peak_signal_count_rtn_mcps = |
charlesmn | 0:3ac96e360672 | 1066 | (uint16_t)pdev->offset_results.VL53L1_p_002[2].peak_rate_mcps; |
charlesmn | 0:3ac96e360672 | 1067 | |
charlesmn | 0:3ac96e360672 | 1068 | break; |
charlesmn | 0:3ac96e360672 | 1069 | } |
charlesmn | 0:3ac96e360672 | 1070 | |
charlesmn | 0:3ac96e360672 | 1071 | |
charlesmn | 0:3ac96e360672 | 1072 | |
charlesmn | 0:3ac96e360672 | 1073 | pdev->cust_dmax_cal.ref__actual_effective_spads = |
charlesmn | 0:3ac96e360672 | 1074 | (uint16_t)pdev->offset_results.VL53L1_p_002[0].effective_spads; |
charlesmn | 0:3ac96e360672 | 1075 | pdev->cust_dmax_cal.ref__peak_signal_count_rate_mcps = |
charlesmn | 0:3ac96e360672 | 1076 | (uint16_t)pdev->offset_results.VL53L1_p_002[0].peak_rate_mcps; |
charlesmn | 0:3ac96e360672 | 1077 | |
charlesmn | 0:3ac96e360672 | 1078 | |
charlesmn | 0:3ac96e360672 | 1079 | pdev->cust_dmax_cal.ref__distance_mm = cal_distance_mm * 16; |
charlesmn | 0:3ac96e360672 | 1080 | |
charlesmn | 0:3ac96e360672 | 1081 | pdev->cust_dmax_cal.ref_reflectance_pc = cal_reflectance_pc; |
charlesmn | 0:3ac96e360672 | 1082 | pdev->cust_dmax_cal.coverglass_transmission = 0x0100; |
charlesmn | 0:3ac96e360672 | 1083 | |
charlesmn | 0:3ac96e360672 | 1084 | |
charlesmn | 0:3ac96e360672 | 1085 | |
charlesmn | 0:3ac96e360672 | 1086 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1087 | status = |
charlesmn | 0:3ac96e360672 | 1088 | VL53L1_set_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 1089 | Dev, |
charlesmn | 0:3ac96e360672 | 1090 | &(pdev->customer)); |
charlesmn | 0:3ac96e360672 | 1091 | |
charlesmn | 0:3ac96e360672 | 1092 | |
charlesmn | 0:3ac96e360672 | 1093 | |
charlesmn | 0:3ac96e360672 | 1094 | |
charlesmn | 0:3ac96e360672 | 1095 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1096 | if (smudge_corr_en == 1) |
charlesmn | 0:3ac96e360672 | 1097 | status = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 1098 | } |
charlesmn | 0:3ac96e360672 | 1099 | |
charlesmn | 0:3ac96e360672 | 1100 | |
charlesmn | 0:3ac96e360672 | 1101 | |
charlesmn | 0:3ac96e360672 | 1102 | |
charlesmn | 0:3ac96e360672 | 1103 | for (m = 0; m < pdev->offset_results.active_results; m++) { |
charlesmn | 0:3ac96e360672 | 1104 | |
charlesmn | 0:3ac96e360672 | 1105 | pfs = &(pdev->offset_results.VL53L1_p_002[m]); |
charlesmn | 0:3ac96e360672 | 1106 | |
charlesmn | 0:3ac96e360672 | 1107 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1108 | |
charlesmn | 0:3ac96e360672 | 1109 | pdev->offset_results.cal_report = m; |
charlesmn | 0:3ac96e360672 | 1110 | |
charlesmn | 0:3ac96e360672 | 1111 | if (pfs->no_of_samples < num_of_samples[m]) |
charlesmn | 0:3ac96e360672 | 1112 | status = |
charlesmn | 0:3ac96e360672 | 1113 | VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES; |
charlesmn | 0:3ac96e360672 | 1114 | |
charlesmn | 0:3ac96e360672 | 1115 | |
charlesmn | 0:3ac96e360672 | 1116 | if (m == 0 && pfs->VL53L1_p_005 > |
charlesmn | 0:3ac96e360672 | 1117 | ((uint32_t)VL53L1_OFFSET_CAL_MAX_SIGMA_MM << 5)) |
charlesmn | 0:3ac96e360672 | 1118 | status = |
charlesmn | 0:3ac96e360672 | 1119 | VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 1120 | |
charlesmn | 0:3ac96e360672 | 1121 | if (pfs->peak_rate_mcps > |
charlesmn | 0:3ac96e360672 | 1122 | VL53L1_OFFSET_CAL_MAX_PRE_PEAK_RATE_MCPS) |
charlesmn | 0:3ac96e360672 | 1123 | status = |
charlesmn | 0:3ac96e360672 | 1124 | VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 1125 | |
charlesmn | 0:3ac96e360672 | 1126 | if (pfs->dss_config__manual_effective_spads_select < |
charlesmn | 0:3ac96e360672 | 1127 | VL53L1_OFFSET_CAL_MIN_EFFECTIVE_SPADS) |
charlesmn | 0:3ac96e360672 | 1128 | status = |
charlesmn | 0:3ac96e360672 | 1129 | VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW; |
charlesmn | 0:3ac96e360672 | 1130 | |
charlesmn | 0:3ac96e360672 | 1131 | if (pfs->dss_config__manual_effective_spads_select == 0) |
charlesmn | 0:3ac96e360672 | 1132 | status = |
charlesmn | 0:3ac96e360672 | 1133 | VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL; |
charlesmn | 0:3ac96e360672 | 1134 | |
charlesmn | 0:3ac96e360672 | 1135 | if (pfs->no_of_samples == 0) |
charlesmn | 0:3ac96e360672 | 1136 | status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL; |
charlesmn | 0:3ac96e360672 | 1137 | } |
charlesmn | 0:3ac96e360672 | 1138 | } |
charlesmn | 0:3ac96e360672 | 1139 | |
charlesmn | 0:3ac96e360672 | 1140 | |
charlesmn | 0:3ac96e360672 | 1141 | |
charlesmn | 0:3ac96e360672 | 1142 | pdev->offset_results.cal_status = status; |
charlesmn | 0:3ac96e360672 | 1143 | *pcal_status = pdev->offset_results.cal_status; |
charlesmn | 0:3ac96e360672 | 1144 | |
charlesmn | 0:3ac96e360672 | 1145 | |
charlesmn | 0:3ac96e360672 | 1146 | |
charlesmn | 0:3ac96e360672 | 1147 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 1148 | IGNORE_OFFSET_CAL_MISSING_SAMPLES, |
charlesmn | 0:3ac96e360672 | 1149 | VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES, |
charlesmn | 0:3ac96e360672 | 1150 | status); |
charlesmn | 0:3ac96e360672 | 1151 | |
charlesmn | 0:3ac96e360672 | 1152 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 1153 | IGNORE_OFFSET_CAL_SIGMA_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1154 | VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1155 | status); |
charlesmn | 0:3ac96e360672 | 1156 | |
charlesmn | 0:3ac96e360672 | 1157 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 1158 | IGNORE_OFFSET_CAL_RATE_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1159 | VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1160 | status); |
charlesmn | 0:3ac96e360672 | 1161 | |
charlesmn | 0:3ac96e360672 | 1162 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 1163 | IGNORE_OFFSET_CAL_SPAD_COUNT_TOO_LOW, |
charlesmn | 0:3ac96e360672 | 1164 | VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW, |
charlesmn | 0:3ac96e360672 | 1165 | status); |
charlesmn | 0:3ac96e360672 | 1166 | |
charlesmn | 0:3ac96e360672 | 1167 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 1168 | |
charlesmn | 0:3ac96e360672 | 1169 | |
charlesmn | 0:3ac96e360672 | 1170 | |
charlesmn | 0:3ac96e360672 | 1171 | VL53L1_print_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 1172 | &(pdev->customer), |
charlesmn | 0:3ac96e360672 | 1173 | "run_offset_calibration():pdev->lldata.customer.", |
charlesmn | 0:3ac96e360672 | 1174 | VL53L1_TRACE_MODULE_OFFSET_DATA); |
charlesmn | 0:3ac96e360672 | 1175 | |
charlesmn | 0:3ac96e360672 | 1176 | VL53L1_print_dmax_calibration_data( |
charlesmn | 0:3ac96e360672 | 1177 | &(pdev->fmt_dmax_cal), |
charlesmn | 0:3ac96e360672 | 1178 | "run_offset_calibration():pdev->lldata.fmt_dmax_cal.", |
charlesmn | 0:3ac96e360672 | 1179 | VL53L1_TRACE_MODULE_OFFSET_DATA); |
charlesmn | 0:3ac96e360672 | 1180 | |
charlesmn | 0:3ac96e360672 | 1181 | VL53L1_print_dmax_calibration_data( |
charlesmn | 0:3ac96e360672 | 1182 | &(pdev->cust_dmax_cal), |
charlesmn | 0:3ac96e360672 | 1183 | "run_offset_calibration():pdev->lldata.cust_dmax_cal.", |
charlesmn | 0:3ac96e360672 | 1184 | VL53L1_TRACE_MODULE_OFFSET_DATA); |
charlesmn | 0:3ac96e360672 | 1185 | |
charlesmn | 0:3ac96e360672 | 1186 | VL53L1_print_additional_offset_cal_data( |
charlesmn | 0:3ac96e360672 | 1187 | &(pdev->add_off_cal_data), |
charlesmn | 0:3ac96e360672 | 1188 | "run_offset_calibration():pdev->lldata.add_off_cal_data.", |
charlesmn | 0:3ac96e360672 | 1189 | VL53L1_TRACE_MODULE_OFFSET_DATA); |
charlesmn | 0:3ac96e360672 | 1190 | |
charlesmn | 0:3ac96e360672 | 1191 | VL53L1_print_offset_range_results( |
charlesmn | 0:3ac96e360672 | 1192 | &(pdev->offset_results), |
charlesmn | 0:3ac96e360672 | 1193 | "run_offset_calibration():pdev->lldata.offset_results.", |
charlesmn | 0:3ac96e360672 | 1194 | VL53L1_TRACE_MODULE_OFFSET_DATA); |
charlesmn | 0:3ac96e360672 | 1195 | #endif |
charlesmn | 0:3ac96e360672 | 1196 | |
charlesmn | 0:3ac96e360672 | 1197 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1198 | |
charlesmn | 0:3ac96e360672 | 1199 | return status; |
charlesmn | 0:3ac96e360672 | 1200 | } |
charlesmn | 0:3ac96e360672 | 1201 | |
charlesmn | 0:3ac96e360672 | 1202 | |
charlesmn | 0:3ac96e360672 | 1203 | VL53L1_Error VL53L1_run_phasecal_average( |
charlesmn | 0:3ac96e360672 | 1204 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1205 | uint8_t measurement_mode, |
charlesmn | 0:3ac96e360672 | 1206 | uint8_t phasecal_result__vcsel_start, |
charlesmn | 0:3ac96e360672 | 1207 | uint16_t phasecal_num_of_samples, |
charlesmn | 0:3ac96e360672 | 1208 | VL53L1_range_results_t *prange_results, |
charlesmn | 0:3ac96e360672 | 1209 | uint16_t *pphasecal_result__reference_phase, |
charlesmn | 0:3ac96e360672 | 1210 | uint16_t *pzero_distance_phase) |
charlesmn | 0:3ac96e360672 | 1211 | { |
charlesmn | 0:3ac96e360672 | 1212 | |
charlesmn | 0:3ac96e360672 | 1213 | |
charlesmn | 0:3ac96e360672 | 1214 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1215 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 1216 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1217 | |
charlesmn | 0:3ac96e360672 | 1218 | uint16_t i = 0; |
charlesmn | 0:3ac96e360672 | 1219 | uint16_t m = 0; |
charlesmn | 0:3ac96e360672 | 1220 | uint32_t samples = 0; |
charlesmn | 0:3ac96e360672 | 1221 | |
charlesmn | 0:3ac96e360672 | 1222 | uint32_t period = 0; |
charlesmn | 0:3ac96e360672 | 1223 | uint32_t VL53L1_p_017 = 0; |
charlesmn | 0:3ac96e360672 | 1224 | uint32_t phasecal_result__reference_phase = 0; |
charlesmn | 0:3ac96e360672 | 1225 | uint32_t zero_distance_phase = 0; |
charlesmn | 0:3ac96e360672 | 1226 | |
charlesmn | 0:3ac96e360672 | 1227 | |
charlesmn | 0:3ac96e360672 | 1228 | VL53L1_load_patch(Dev); |
charlesmn | 0:3ac96e360672 | 1229 | |
charlesmn | 0:3ac96e360672 | 1230 | for (m = 0; m < phasecal_num_of_samples; m++) { |
charlesmn | 0:3ac96e360672 | 1231 | |
charlesmn | 0:3ac96e360672 | 1232 | |
charlesmn | 0:3ac96e360672 | 1233 | |
charlesmn | 0:3ac96e360672 | 1234 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1235 | status = |
charlesmn | 0:3ac96e360672 | 1236 | VL53L1_init_and_start_range( |
charlesmn | 0:3ac96e360672 | 1237 | Dev, |
charlesmn | 0:3ac96e360672 | 1238 | measurement_mode, |
charlesmn | 0:3ac96e360672 | 1239 | VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS); |
charlesmn | 0:3ac96e360672 | 1240 | |
charlesmn | 0:3ac96e360672 | 1241 | for (i = 0; i <= 1; i++) { |
charlesmn | 0:3ac96e360672 | 1242 | |
charlesmn | 0:3ac96e360672 | 1243 | |
charlesmn | 0:3ac96e360672 | 1244 | |
charlesmn | 0:3ac96e360672 | 1245 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1246 | status = |
charlesmn | 0:3ac96e360672 | 1247 | VL53L1_wait_for_range_completion(Dev); |
charlesmn | 0:3ac96e360672 | 1248 | |
charlesmn | 0:3ac96e360672 | 1249 | |
charlesmn | 0:3ac96e360672 | 1250 | |
charlesmn | 0:3ac96e360672 | 1251 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1252 | status = |
charlesmn | 0:3ac96e360672 | 1253 | VL53L1_get_device_results( |
charlesmn | 0:3ac96e360672 | 1254 | Dev, |
charlesmn | 0:3ac96e360672 | 1255 | VL53L1_DEVICERESULTSLEVEL_FULL, |
charlesmn | 0:3ac96e360672 | 1256 | prange_results); |
charlesmn | 0:3ac96e360672 | 1257 | |
charlesmn | 0:3ac96e360672 | 1258 | |
charlesmn | 0:3ac96e360672 | 1259 | |
charlesmn | 0:3ac96e360672 | 1260 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1261 | status = |
charlesmn | 0:3ac96e360672 | 1262 | VL53L1_wait_for_firmware_ready(Dev); |
charlesmn | 0:3ac96e360672 | 1263 | |
charlesmn | 0:3ac96e360672 | 1264 | |
charlesmn | 0:3ac96e360672 | 1265 | |
charlesmn | 0:3ac96e360672 | 1266 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1267 | status = |
charlesmn | 0:3ac96e360672 | 1268 | VL53L1_clear_interrupt_and_enable_next_range( |
charlesmn | 0:3ac96e360672 | 1269 | Dev, |
charlesmn | 0:3ac96e360672 | 1270 | measurement_mode); |
charlesmn | 0:3ac96e360672 | 1271 | } |
charlesmn | 0:3ac96e360672 | 1272 | |
charlesmn | 0:3ac96e360672 | 1273 | |
charlesmn | 0:3ac96e360672 | 1274 | |
charlesmn | 0:3ac96e360672 | 1275 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1276 | status = VL53L1_stop_range(Dev); |
charlesmn | 0:3ac96e360672 | 1277 | |
charlesmn | 0:3ac96e360672 | 1278 | |
charlesmn | 0:3ac96e360672 | 1279 | |
charlesmn | 0:3ac96e360672 | 1280 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1281 | status = VL53L1_WaitUs(Dev, 1000); |
charlesmn | 0:3ac96e360672 | 1282 | |
charlesmn | 0:3ac96e360672 | 1283 | |
charlesmn | 0:3ac96e360672 | 1284 | |
charlesmn | 0:3ac96e360672 | 1285 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1286 | |
charlesmn | 0:3ac96e360672 | 1287 | samples++; |
charlesmn | 0:3ac96e360672 | 1288 | |
charlesmn | 0:3ac96e360672 | 1289 | |
charlesmn | 0:3ac96e360672 | 1290 | period = 2048 * |
charlesmn | 0:3ac96e360672 | 1291 | (uint32_t)VL53L1_decode_vcsel_period( |
charlesmn | 0:3ac96e360672 | 1292 | pdev->hist_data.VL53L1_p_009); |
charlesmn | 0:3ac96e360672 | 1293 | |
charlesmn | 0:3ac96e360672 | 1294 | VL53L1_p_017 = period; |
charlesmn | 0:3ac96e360672 | 1295 | VL53L1_p_017 += (uint32_t)( |
charlesmn | 0:3ac96e360672 | 1296 | pdev->hist_data.phasecal_result__reference_phase); |
charlesmn | 0:3ac96e360672 | 1297 | VL53L1_p_017 += |
charlesmn | 0:3ac96e360672 | 1298 | (2048 * |
charlesmn | 0:3ac96e360672 | 1299 | (uint32_t)phasecal_result__vcsel_start); |
charlesmn | 0:3ac96e360672 | 1300 | VL53L1_p_017 -= (2048 * |
charlesmn | 0:3ac96e360672 | 1301 | (uint32_t)pdev->hist_data.cal_config__vcsel_start); |
charlesmn | 0:3ac96e360672 | 1302 | |
charlesmn | 0:3ac96e360672 | 1303 | VL53L1_p_017 = VL53L1_p_017 % period; |
charlesmn | 0:3ac96e360672 | 1304 | |
charlesmn | 0:3ac96e360672 | 1305 | phasecal_result__reference_phase += (uint32_t)( |
charlesmn | 0:3ac96e360672 | 1306 | pdev->hist_data.phasecal_result__reference_phase); |
charlesmn | 0:3ac96e360672 | 1307 | |
charlesmn | 0:3ac96e360672 | 1308 | zero_distance_phase += (uint32_t)VL53L1_p_017; |
charlesmn | 0:3ac96e360672 | 1309 | } |
charlesmn | 0:3ac96e360672 | 1310 | } |
charlesmn | 0:3ac96e360672 | 1311 | VL53L1_unload_patch(Dev); |
charlesmn | 0:3ac96e360672 | 1312 | |
charlesmn | 0:3ac96e360672 | 1313 | |
charlesmn | 0:3ac96e360672 | 1314 | |
charlesmn | 0:3ac96e360672 | 1315 | if (status == VL53L1_ERROR_NONE && samples > 0) { |
charlesmn | 0:3ac96e360672 | 1316 | |
charlesmn | 0:3ac96e360672 | 1317 | phasecal_result__reference_phase += (samples >> 1); |
charlesmn | 0:3ac96e360672 | 1318 | phasecal_result__reference_phase /= samples; |
charlesmn | 0:3ac96e360672 | 1319 | |
charlesmn | 0:3ac96e360672 | 1320 | zero_distance_phase += (samples >> 1); |
charlesmn | 0:3ac96e360672 | 1321 | zero_distance_phase /= samples; |
charlesmn | 0:3ac96e360672 | 1322 | |
charlesmn | 0:3ac96e360672 | 1323 | *pphasecal_result__reference_phase = |
charlesmn | 0:3ac96e360672 | 1324 | (uint16_t)phasecal_result__reference_phase; |
charlesmn | 0:3ac96e360672 | 1325 | *pzero_distance_phase = |
charlesmn | 0:3ac96e360672 | 1326 | (uint16_t)zero_distance_phase; |
charlesmn | 0:3ac96e360672 | 1327 | } |
charlesmn | 0:3ac96e360672 | 1328 | |
charlesmn | 0:3ac96e360672 | 1329 | return status; |
charlesmn | 0:3ac96e360672 | 1330 | } |
charlesmn | 0:3ac96e360672 | 1331 | |
charlesmn | 0:3ac96e360672 | 1332 | |
charlesmn | 0:3ac96e360672 | 1333 | VL53L1_Error VL53L1_run_zone_calibration( |
charlesmn | 0:3ac96e360672 | 1334 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1335 | VL53L1_DevicePresetModes device_preset_mode, |
charlesmn | 0:3ac96e360672 | 1336 | VL53L1_DeviceZonePreset zone_preset, |
charlesmn | 0:3ac96e360672 | 1337 | VL53L1_zone_config_t *pzone_cfg, |
charlesmn | 0:3ac96e360672 | 1338 | int16_t cal_distance_mm, |
charlesmn | 0:3ac96e360672 | 1339 | uint16_t cal_reflectance_pc, |
charlesmn | 0:3ac96e360672 | 1340 | VL53L1_Error *pcal_status) |
charlesmn | 0:3ac96e360672 | 1341 | { |
charlesmn | 0:3ac96e360672 | 1342 | |
charlesmn | 0:3ac96e360672 | 1343 | |
charlesmn | 0:3ac96e360672 | 1344 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1345 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 1346 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1347 | |
charlesmn | 0:3ac96e360672 | 1348 | VL53L1_LLDriverResults_t *pres = |
charlesmn | 0:3ac96e360672 | 1349 | VL53L1DevStructGetLLResultsHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1350 | |
charlesmn | 0:3ac96e360672 | 1351 | VL53L1_range_results_t *pRR = |
charlesmn | 0:3ac96e360672 | 1352 | (VL53L1_range_results_t *) pdev->wArea1; |
charlesmn | 0:3ac96e360672 | 1353 | VL53L1_range_data_t *prange_data = NULL; |
charlesmn | 0:3ac96e360672 | 1354 | VL53L1_zone_calibration_data_t *pzone_data = NULL; |
charlesmn | 0:3ac96e360672 | 1355 | |
charlesmn | 0:3ac96e360672 | 1356 | uint16_t i = 0; |
charlesmn | 0:3ac96e360672 | 1357 | uint16_t m = 0; |
charlesmn | 0:3ac96e360672 | 1358 | |
charlesmn | 0:3ac96e360672 | 1359 | uint8_t z = 0; |
charlesmn | 0:3ac96e360672 | 1360 | uint8_t measurement_mode = |
charlesmn | 0:3ac96e360672 | 1361 | VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK; |
charlesmn | 0:3ac96e360672 | 1362 | |
charlesmn | 0:3ac96e360672 | 1363 | VL53L1_OffsetCorrectionMode offset_cor_mode = |
charlesmn | 0:3ac96e360672 | 1364 | VL53L1_OFFSETCORRECTIONMODE__NONE; |
charlesmn | 0:3ac96e360672 | 1365 | |
charlesmn | 0:3ac96e360672 | 1366 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1367 | |
charlesmn | 0:3ac96e360672 | 1368 | |
charlesmn | 0:3ac96e360672 | 1369 | |
charlesmn | 0:3ac96e360672 | 1370 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1371 | status = |
charlesmn | 0:3ac96e360672 | 1372 | VL53L1_set_preset_mode( |
charlesmn | 0:3ac96e360672 | 1373 | Dev, |
charlesmn | 0:3ac96e360672 | 1374 | device_preset_mode, |
charlesmn | 0:3ac96e360672 | 1375 | |
charlesmn | 0:3ac96e360672 | 1376 | pdev->zonecal_cfg.dss_config__target_total_rate_mcps, |
charlesmn | 0:3ac96e360672 | 1377 | pdev->zonecal_cfg.phasecal_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 1378 | pdev->zonecal_cfg.mm_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 1379 | pdev->zonecal_cfg.range_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 1380 | |
charlesmn | 0:3ac96e360672 | 1381 | 100); |
charlesmn | 0:3ac96e360672 | 1382 | |
charlesmn | 0:3ac96e360672 | 1383 | |
charlesmn | 0:3ac96e360672 | 1384 | |
charlesmn | 0:3ac96e360672 | 1385 | if (zone_preset == VL53L1_DEVICEZONEPRESET_CUSTOM) { |
charlesmn | 0:3ac96e360672 | 1386 | |
charlesmn | 0:3ac96e360672 | 1387 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1388 | status = |
charlesmn | 0:3ac96e360672 | 1389 | VL53L1_set_zone_config( |
charlesmn | 0:3ac96e360672 | 1390 | Dev, |
charlesmn | 0:3ac96e360672 | 1391 | pzone_cfg); |
charlesmn | 0:3ac96e360672 | 1392 | |
charlesmn | 0:3ac96e360672 | 1393 | } else if (zone_preset != VL53L1_DEVICEZONEPRESET_NONE) { |
charlesmn | 0:3ac96e360672 | 1394 | |
charlesmn | 0:3ac96e360672 | 1395 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1396 | status = |
charlesmn | 0:3ac96e360672 | 1397 | VL53L1_set_zone_preset( |
charlesmn | 0:3ac96e360672 | 1398 | Dev, |
charlesmn | 0:3ac96e360672 | 1399 | zone_preset); |
charlesmn | 0:3ac96e360672 | 1400 | } |
charlesmn | 0:3ac96e360672 | 1401 | |
charlesmn | 0:3ac96e360672 | 1402 | |
charlesmn | 0:3ac96e360672 | 1403 | |
charlesmn | 0:3ac96e360672 | 1404 | pres->zone_cal.preset_mode = device_preset_mode; |
charlesmn | 0:3ac96e360672 | 1405 | pres->zone_cal.zone_preset = zone_preset; |
charlesmn | 0:3ac96e360672 | 1406 | |
charlesmn | 0:3ac96e360672 | 1407 | pres->zone_cal.cal_distance_mm = cal_distance_mm * 16; |
charlesmn | 0:3ac96e360672 | 1408 | pres->zone_cal.cal_reflectance_pc = cal_reflectance_pc; |
charlesmn | 0:3ac96e360672 | 1409 | pres->zone_cal.max_zones = VL53L1_MAX_USER_ZONES; |
charlesmn | 0:3ac96e360672 | 1410 | pres->zone_cal.active_zones = pdev->zone_cfg.active_zones + 1; |
charlesmn | 0:3ac96e360672 | 1411 | |
charlesmn | 0:3ac96e360672 | 1412 | for (i = 0; i < VL53L1_MAX_USER_ZONES; i++) { |
charlesmn | 0:3ac96e360672 | 1413 | pres->zone_cal.VL53L1_p_002[i].no_of_samples = 0; |
charlesmn | 0:3ac96e360672 | 1414 | pres->zone_cal.VL53L1_p_002[i].effective_spads = 0; |
charlesmn | 0:3ac96e360672 | 1415 | pres->zone_cal.VL53L1_p_002[i].peak_rate_mcps = 0; |
charlesmn | 0:3ac96e360672 | 1416 | pres->zone_cal.VL53L1_p_002[i].VL53L1_p_014 = 0; |
charlesmn | 0:3ac96e360672 | 1417 | pres->zone_cal.VL53L1_p_002[i].VL53L1_p_005 = 0; |
charlesmn | 0:3ac96e360672 | 1418 | pres->zone_cal.VL53L1_p_002[i].median_range_mm = 0; |
charlesmn | 0:3ac96e360672 | 1419 | pres->zone_cal.VL53L1_p_002[i].range_mm_offset = 0; |
charlesmn | 0:3ac96e360672 | 1420 | } |
charlesmn | 0:3ac96e360672 | 1421 | |
charlesmn | 0:3ac96e360672 | 1422 | pres->zone_cal.phasecal_result__reference_phase = 0; |
charlesmn | 0:3ac96e360672 | 1423 | pres->zone_cal.zero_distance_phase = 0; |
charlesmn | 0:3ac96e360672 | 1424 | |
charlesmn | 0:3ac96e360672 | 1425 | |
charlesmn | 0:3ac96e360672 | 1426 | |
charlesmn | 0:3ac96e360672 | 1427 | status = |
charlesmn | 0:3ac96e360672 | 1428 | VL53L1_get_offset_correction_mode( |
charlesmn | 0:3ac96e360672 | 1429 | Dev, |
charlesmn | 0:3ac96e360672 | 1430 | &offset_cor_mode); |
charlesmn | 0:3ac96e360672 | 1431 | |
charlesmn | 0:3ac96e360672 | 1432 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1433 | status = |
charlesmn | 0:3ac96e360672 | 1434 | VL53L1_set_offset_correction_mode( |
charlesmn | 0:3ac96e360672 | 1435 | Dev, |
charlesmn | 0:3ac96e360672 | 1436 | VL53L1_OFFSETCORRECTIONMODE__NONE); |
charlesmn | 0:3ac96e360672 | 1437 | |
charlesmn | 0:3ac96e360672 | 1438 | |
charlesmn | 0:3ac96e360672 | 1439 | VL53L1_load_patch(Dev); |
charlesmn | 0:3ac96e360672 | 1440 | |
charlesmn | 0:3ac96e360672 | 1441 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1442 | status = |
charlesmn | 0:3ac96e360672 | 1443 | VL53L1_init_and_start_range( |
charlesmn | 0:3ac96e360672 | 1444 | Dev, |
charlesmn | 0:3ac96e360672 | 1445 | measurement_mode, |
charlesmn | 0:3ac96e360672 | 1446 | VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS); |
charlesmn | 0:3ac96e360672 | 1447 | |
charlesmn | 0:3ac96e360672 | 1448 | |
charlesmn | 0:3ac96e360672 | 1449 | |
charlesmn | 0:3ac96e360672 | 1450 | |
charlesmn | 0:3ac96e360672 | 1451 | m = (pdev->zonecal_cfg.zone_num_of_samples + 2) * |
charlesmn | 0:3ac96e360672 | 1452 | (uint16_t)pres->zone_cal.active_zones; |
charlesmn | 0:3ac96e360672 | 1453 | |
charlesmn | 0:3ac96e360672 | 1454 | |
charlesmn | 0:3ac96e360672 | 1455 | for (i = 0; i <= m; i++) { |
charlesmn | 0:3ac96e360672 | 1456 | |
charlesmn | 0:3ac96e360672 | 1457 | |
charlesmn | 0:3ac96e360672 | 1458 | |
charlesmn | 0:3ac96e360672 | 1459 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1460 | status = |
charlesmn | 0:3ac96e360672 | 1461 | VL53L1_wait_for_range_completion(Dev); |
charlesmn | 0:3ac96e360672 | 1462 | |
charlesmn | 0:3ac96e360672 | 1463 | |
charlesmn | 0:3ac96e360672 | 1464 | |
charlesmn | 0:3ac96e360672 | 1465 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1466 | status = |
charlesmn | 0:3ac96e360672 | 1467 | VL53L1_get_device_results( |
charlesmn | 0:3ac96e360672 | 1468 | Dev, |
charlesmn | 0:3ac96e360672 | 1469 | VL53L1_DEVICERESULTSLEVEL_FULL, |
charlesmn | 0:3ac96e360672 | 1470 | pRR); |
charlesmn | 0:3ac96e360672 | 1471 | |
charlesmn | 0:3ac96e360672 | 1472 | |
charlesmn | 0:3ac96e360672 | 1473 | |
charlesmn | 0:3ac96e360672 | 1474 | prange_data = &(pRR->VL53L1_p_002[0]); |
charlesmn | 0:3ac96e360672 | 1475 | |
charlesmn | 0:3ac96e360672 | 1476 | if (pRR->active_results > 0 && |
charlesmn | 0:3ac96e360672 | 1477 | i > (uint16_t)pres->zone_cal.active_zones) { |
charlesmn | 0:3ac96e360672 | 1478 | |
charlesmn | 0:3ac96e360672 | 1479 | if (prange_data->range_status == |
charlesmn | 0:3ac96e360672 | 1480 | VL53L1_DEVICEERROR_RANGECOMPLETE) { |
charlesmn | 0:3ac96e360672 | 1481 | |
charlesmn | 0:3ac96e360672 | 1482 | pres->zone_cal.phasecal_result__reference_phase |
charlesmn | 0:3ac96e360672 | 1483 | = |
charlesmn | 0:3ac96e360672 | 1484 | pdev->hist_data.phasecal_result__reference_phase |
charlesmn | 0:3ac96e360672 | 1485 | ; |
charlesmn | 0:3ac96e360672 | 1486 | pres->zone_cal.zero_distance_phase = |
charlesmn | 0:3ac96e360672 | 1487 | pdev->hist_data.zero_distance_phase; |
charlesmn | 0:3ac96e360672 | 1488 | |
charlesmn | 0:3ac96e360672 | 1489 | pzone_data = |
charlesmn | 0:3ac96e360672 | 1490 | &(pres->zone_cal.VL53L1_p_002[pRR->zone_id]); |
charlesmn | 0:3ac96e360672 | 1491 | pzone_data->no_of_samples++; |
charlesmn | 0:3ac96e360672 | 1492 | pzone_data->effective_spads += |
charlesmn | 0:3ac96e360672 | 1493 | (uint32_t)prange_data->VL53L1_p_006; |
charlesmn | 0:3ac96e360672 | 1494 | pzone_data->peak_rate_mcps += (uint32_t)( |
charlesmn | 0:3ac96e360672 | 1495 | prange_data->peak_signal_count_rate_mcps); |
charlesmn | 0:3ac96e360672 | 1496 | pzone_data->VL53L1_p_014 += |
charlesmn | 0:3ac96e360672 | 1497 | (uint32_t)prange_data->VL53L1_p_014; |
charlesmn | 0:3ac96e360672 | 1498 | pzone_data->VL53L1_p_005 += |
charlesmn | 0:3ac96e360672 | 1499 | (uint32_t)prange_data->VL53L1_p_005; |
charlesmn | 0:3ac96e360672 | 1500 | pzone_data->median_range_mm += |
charlesmn | 0:3ac96e360672 | 1501 | (int32_t)prange_data->median_range_mm; |
charlesmn | 0:3ac96e360672 | 1502 | |
charlesmn | 0:3ac96e360672 | 1503 | } |
charlesmn | 0:3ac96e360672 | 1504 | } |
charlesmn | 0:3ac96e360672 | 1505 | |
charlesmn | 0:3ac96e360672 | 1506 | |
charlesmn | 0:3ac96e360672 | 1507 | |
charlesmn | 0:3ac96e360672 | 1508 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1509 | status = |
charlesmn | 0:3ac96e360672 | 1510 | VL53L1_wait_for_firmware_ready(Dev); |
charlesmn | 0:3ac96e360672 | 1511 | |
charlesmn | 0:3ac96e360672 | 1512 | |
charlesmn | 0:3ac96e360672 | 1513 | |
charlesmn | 0:3ac96e360672 | 1514 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1515 | status = |
charlesmn | 0:3ac96e360672 | 1516 | VL53L1_clear_interrupt_and_enable_next_range( |
charlesmn | 0:3ac96e360672 | 1517 | Dev, |
charlesmn | 0:3ac96e360672 | 1518 | measurement_mode); |
charlesmn | 0:3ac96e360672 | 1519 | } |
charlesmn | 0:3ac96e360672 | 1520 | |
charlesmn | 0:3ac96e360672 | 1521 | |
charlesmn | 0:3ac96e360672 | 1522 | |
charlesmn | 0:3ac96e360672 | 1523 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1524 | status = VL53L1_stop_range(Dev); |
charlesmn | 0:3ac96e360672 | 1525 | |
charlesmn | 0:3ac96e360672 | 1526 | |
charlesmn | 0:3ac96e360672 | 1527 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1528 | status = VL53L1_WaitUs(Dev, 1000); |
charlesmn | 0:3ac96e360672 | 1529 | VL53L1_unload_patch(Dev); |
charlesmn | 0:3ac96e360672 | 1530 | |
charlesmn | 0:3ac96e360672 | 1531 | |
charlesmn | 0:3ac96e360672 | 1532 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1533 | status = |
charlesmn | 0:3ac96e360672 | 1534 | VL53L1_run_phasecal_average( |
charlesmn | 0:3ac96e360672 | 1535 | Dev, |
charlesmn | 0:3ac96e360672 | 1536 | measurement_mode, |
charlesmn | 0:3ac96e360672 | 1537 | pdev->hist_data.phasecal_result__vcsel_start, |
charlesmn | 0:3ac96e360672 | 1538 | |
charlesmn | 0:3ac96e360672 | 1539 | pdev->zonecal_cfg.phasecal_num_of_samples, |
charlesmn | 0:3ac96e360672 | 1540 | |
charlesmn | 0:3ac96e360672 | 1541 | pRR, |
charlesmn | 0:3ac96e360672 | 1542 | &(pres->zone_cal.phasecal_result__reference_phase), |
charlesmn | 0:3ac96e360672 | 1543 | &(pres->zone_cal.zero_distance_phase)); |
charlesmn | 0:3ac96e360672 | 1544 | |
charlesmn | 0:3ac96e360672 | 1545 | |
charlesmn | 0:3ac96e360672 | 1546 | |
charlesmn | 0:3ac96e360672 | 1547 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1548 | status = |
charlesmn | 0:3ac96e360672 | 1549 | VL53L1_set_offset_correction_mode( |
charlesmn | 0:3ac96e360672 | 1550 | Dev, |
charlesmn | 0:3ac96e360672 | 1551 | offset_cor_mode); |
charlesmn | 0:3ac96e360672 | 1552 | |
charlesmn | 0:3ac96e360672 | 1553 | |
charlesmn | 0:3ac96e360672 | 1554 | |
charlesmn | 0:3ac96e360672 | 1555 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1556 | |
charlesmn | 0:3ac96e360672 | 1557 | for (z = 0; z < pres->zone_cal.active_zones; z++) { |
charlesmn | 0:3ac96e360672 | 1558 | |
charlesmn | 0:3ac96e360672 | 1559 | pzone_data = &(pres->zone_cal.VL53L1_p_002[z]); |
charlesmn | 0:3ac96e360672 | 1560 | |
charlesmn | 0:3ac96e360672 | 1561 | |
charlesmn | 0:3ac96e360672 | 1562 | if (pzone_data->no_of_samples > 0) { |
charlesmn | 0:3ac96e360672 | 1563 | |
charlesmn | 0:3ac96e360672 | 1564 | pzone_data->effective_spads += |
charlesmn | 0:3ac96e360672 | 1565 | (pzone_data->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1566 | pzone_data->effective_spads /= |
charlesmn | 0:3ac96e360672 | 1567 | pzone_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1568 | |
charlesmn | 0:3ac96e360672 | 1569 | pzone_data->peak_rate_mcps += |
charlesmn | 0:3ac96e360672 | 1570 | (pzone_data->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1571 | pzone_data->peak_rate_mcps /= |
charlesmn | 0:3ac96e360672 | 1572 | pzone_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1573 | |
charlesmn | 0:3ac96e360672 | 1574 | pzone_data->VL53L1_p_014 += |
charlesmn | 0:3ac96e360672 | 1575 | (pzone_data->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1576 | pzone_data->VL53L1_p_014 /= |
charlesmn | 0:3ac96e360672 | 1577 | pzone_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1578 | |
charlesmn | 0:3ac96e360672 | 1579 | pzone_data->VL53L1_p_005 += |
charlesmn | 0:3ac96e360672 | 1580 | (pzone_data->no_of_samples/2); |
charlesmn | 0:3ac96e360672 | 1581 | pzone_data->VL53L1_p_005 /= |
charlesmn | 0:3ac96e360672 | 1582 | pzone_data->no_of_samples; |
charlesmn | 0:3ac96e360672 | 1583 | |
charlesmn | 0:3ac96e360672 | 1584 | |
charlesmn | 0:3ac96e360672 | 1585 | |
charlesmn | 0:3ac96e360672 | 1586 | pzone_data->median_range_mm = |
charlesmn | 0:3ac96e360672 | 1587 | VL53L1_range_maths( |
charlesmn | 0:3ac96e360672 | 1588 | pdev->stat_nvm.osc_measured__fast_osc__frequency |
charlesmn | 0:3ac96e360672 | 1589 | , (uint16_t)pzone_data->VL53L1_p_014, |
charlesmn | 0:3ac96e360672 | 1590 | pres->zone_cal.zero_distance_phase, |
charlesmn | 0:3ac96e360672 | 1591 | 2, |
charlesmn | 0:3ac96e360672 | 1592 | 0x0800, |
charlesmn | 0:3ac96e360672 | 1593 | 0); |
charlesmn | 0:3ac96e360672 | 1594 | |
charlesmn | 0:3ac96e360672 | 1595 | pzone_data->range_mm_offset = |
charlesmn | 0:3ac96e360672 | 1596 | ((int32_t)cal_distance_mm) * 4; |
charlesmn | 0:3ac96e360672 | 1597 | pzone_data->range_mm_offset -= |
charlesmn | 0:3ac96e360672 | 1598 | pzone_data->median_range_mm; |
charlesmn | 0:3ac96e360672 | 1599 | |
charlesmn | 0:3ac96e360672 | 1600 | |
charlesmn | 0:3ac96e360672 | 1601 | if (pzone_data->no_of_samples < |
charlesmn | 0:3ac96e360672 | 1602 | pdev->zonecal_cfg.zone_num_of_samples) |
charlesmn | 0:3ac96e360672 | 1603 | status = |
charlesmn | 0:3ac96e360672 | 1604 | VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES; |
charlesmn | 0:3ac96e360672 | 1605 | |
charlesmn | 0:3ac96e360672 | 1606 | |
charlesmn | 0:3ac96e360672 | 1607 | if (pzone_data->VL53L1_p_005 > |
charlesmn | 0:3ac96e360672 | 1608 | ((uint32_t)VL53L1_ZONE_CAL_MAX_SIGMA_MM |
charlesmn | 0:3ac96e360672 | 1609 | << 5)) |
charlesmn | 0:3ac96e360672 | 1610 | status = |
charlesmn | 0:3ac96e360672 | 1611 | VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 1612 | |
charlesmn | 0:3ac96e360672 | 1613 | if (pzone_data->peak_rate_mcps > |
charlesmn | 0:3ac96e360672 | 1614 | VL53L1_ZONE_CAL_MAX_PRE_PEAK_RATE_MCPS) |
charlesmn | 0:3ac96e360672 | 1615 | status = |
charlesmn | 0:3ac96e360672 | 1616 | VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 1617 | |
charlesmn | 0:3ac96e360672 | 1618 | } else { |
charlesmn | 0:3ac96e360672 | 1619 | status = VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL; |
charlesmn | 0:3ac96e360672 | 1620 | } |
charlesmn | 0:3ac96e360672 | 1621 | } |
charlesmn | 0:3ac96e360672 | 1622 | } |
charlesmn | 0:3ac96e360672 | 1623 | |
charlesmn | 0:3ac96e360672 | 1624 | |
charlesmn | 0:3ac96e360672 | 1625 | |
charlesmn | 0:3ac96e360672 | 1626 | pres->zone_cal.cal_status = status; |
charlesmn | 0:3ac96e360672 | 1627 | *pcal_status = pres->zone_cal.cal_status; |
charlesmn | 0:3ac96e360672 | 1628 | |
charlesmn | 0:3ac96e360672 | 1629 | |
charlesmn | 0:3ac96e360672 | 1630 | |
charlesmn | 0:3ac96e360672 | 1631 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 1632 | IGNORE_ZONE_CAL_MISSING_SAMPLES, |
charlesmn | 0:3ac96e360672 | 1633 | VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES, |
charlesmn | 0:3ac96e360672 | 1634 | status); |
charlesmn | 0:3ac96e360672 | 1635 | |
charlesmn | 0:3ac96e360672 | 1636 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 1637 | IGNORE_ZONE_CAL_SIGMA_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1638 | VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1639 | status); |
charlesmn | 0:3ac96e360672 | 1640 | |
charlesmn | 0:3ac96e360672 | 1641 | IGNORE_STATUS( |
charlesmn | 0:3ac96e360672 | 1642 | IGNORE_ZONE_CAL_RATE_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1643 | VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH, |
charlesmn | 0:3ac96e360672 | 1644 | status); |
charlesmn | 0:3ac96e360672 | 1645 | |
charlesmn | 0:3ac96e360672 | 1646 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 1647 | |
charlesmn | 0:3ac96e360672 | 1648 | |
charlesmn | 0:3ac96e360672 | 1649 | |
charlesmn | 0:3ac96e360672 | 1650 | VL53L1_print_zone_calibration_results( |
charlesmn | 0:3ac96e360672 | 1651 | &(pres->zone_cal), |
charlesmn | 0:3ac96e360672 | 1652 | "run_zone_calibration():pdev->llresults.zone_cal.", |
charlesmn | 0:3ac96e360672 | 1653 | VL53L1_TRACE_MODULE_OFFSET_DATA); |
charlesmn | 0:3ac96e360672 | 1654 | |
charlesmn | 0:3ac96e360672 | 1655 | #endif |
charlesmn | 0:3ac96e360672 | 1656 | |
charlesmn | 0:3ac96e360672 | 1657 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1658 | |
charlesmn | 0:3ac96e360672 | 1659 | return status; |
charlesmn | 0:3ac96e360672 | 1660 | } |
charlesmn | 0:3ac96e360672 | 1661 | |
charlesmn | 0:3ac96e360672 | 1662 | |
charlesmn | 0:3ac96e360672 | 1663 | VL53L1_Error VL53L1_run_spad_rate_map( |
charlesmn | 0:3ac96e360672 | 1664 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1665 | VL53L1_DeviceTestMode device_test_mode, |
charlesmn | 0:3ac96e360672 | 1666 | VL53L1_DeviceSscArray array_select, |
charlesmn | 0:3ac96e360672 | 1667 | uint32_t ssc_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 1668 | VL53L1_spad_rate_data_t *pspad_rate_data) |
charlesmn | 0:3ac96e360672 | 1669 | { |
charlesmn | 0:3ac96e360672 | 1670 | |
charlesmn | 0:3ac96e360672 | 1671 | |
charlesmn | 0:3ac96e360672 | 1672 | |
charlesmn | 0:3ac96e360672 | 1673 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1674 | |
charlesmn | 0:3ac96e360672 | 1675 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 1676 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1677 | |
charlesmn | 0:3ac96e360672 | 1678 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1679 | |
charlesmn | 0:3ac96e360672 | 1680 | |
charlesmn | 0:3ac96e360672 | 1681 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1682 | status = VL53L1_enable_powerforce(Dev); |
charlesmn | 0:3ac96e360672 | 1683 | |
charlesmn | 0:3ac96e360672 | 1684 | |
charlesmn | 0:3ac96e360672 | 1685 | |
charlesmn | 0:3ac96e360672 | 1686 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1687 | pdev->ssc_cfg.array_select = array_select; |
charlesmn | 0:3ac96e360672 | 1688 | pdev->ssc_cfg.timeout_us = ssc_config_timeout_us; |
charlesmn | 0:3ac96e360672 | 1689 | status = |
charlesmn | 0:3ac96e360672 | 1690 | VL53L1_set_ssc_config( |
charlesmn | 0:3ac96e360672 | 1691 | Dev, |
charlesmn | 0:3ac96e360672 | 1692 | &(pdev->ssc_cfg), |
charlesmn | 0:3ac96e360672 | 1693 | pdev->stat_nvm.osc_measured__fast_osc__frequency); |
charlesmn | 0:3ac96e360672 | 1694 | } |
charlesmn | 0:3ac96e360672 | 1695 | |
charlesmn | 0:3ac96e360672 | 1696 | |
charlesmn | 0:3ac96e360672 | 1697 | |
charlesmn | 0:3ac96e360672 | 1698 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1699 | status = |
charlesmn | 0:3ac96e360672 | 1700 | VL53L1_run_device_test( |
charlesmn | 0:3ac96e360672 | 1701 | Dev, |
charlesmn | 0:3ac96e360672 | 1702 | device_test_mode); |
charlesmn | 0:3ac96e360672 | 1703 | |
charlesmn | 0:3ac96e360672 | 1704 | |
charlesmn | 0:3ac96e360672 | 1705 | |
charlesmn | 0:3ac96e360672 | 1706 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1707 | status = |
charlesmn | 0:3ac96e360672 | 1708 | VL53L1_get_spad_rate_data( |
charlesmn | 0:3ac96e360672 | 1709 | Dev, |
charlesmn | 0:3ac96e360672 | 1710 | pspad_rate_data); |
charlesmn | 0:3ac96e360672 | 1711 | |
charlesmn | 0:3ac96e360672 | 1712 | if (device_test_mode == VL53L1_DEVICETESTMODE_LCR_VCSEL_ON) |
charlesmn | 0:3ac96e360672 | 1713 | pspad_rate_data->fractional_bits = 7; |
charlesmn | 0:3ac96e360672 | 1714 | else |
charlesmn | 0:3ac96e360672 | 1715 | pspad_rate_data->fractional_bits = 15; |
charlesmn | 0:3ac96e360672 | 1716 | |
charlesmn | 0:3ac96e360672 | 1717 | |
charlesmn | 0:3ac96e360672 | 1718 | |
charlesmn | 0:3ac96e360672 | 1719 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1720 | status = VL53L1_disable_powerforce(Dev); |
charlesmn | 0:3ac96e360672 | 1721 | |
charlesmn | 0:3ac96e360672 | 1722 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 1723 | |
charlesmn | 0:3ac96e360672 | 1724 | |
charlesmn | 0:3ac96e360672 | 1725 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1726 | VL53L1_print_spad_rate_data( |
charlesmn | 0:3ac96e360672 | 1727 | pspad_rate_data, |
charlesmn | 0:3ac96e360672 | 1728 | "run_spad_rate_map():", |
charlesmn | 0:3ac96e360672 | 1729 | VL53L1_TRACE_MODULE_SPAD_RATE_MAP); |
charlesmn | 0:3ac96e360672 | 1730 | VL53L1_print_spad_rate_map( |
charlesmn | 0:3ac96e360672 | 1731 | pspad_rate_data, |
charlesmn | 0:3ac96e360672 | 1732 | "run_spad_rate_map():", |
charlesmn | 0:3ac96e360672 | 1733 | VL53L1_TRACE_MODULE_SPAD_RATE_MAP); |
charlesmn | 0:3ac96e360672 | 1734 | } |
charlesmn | 0:3ac96e360672 | 1735 | #endif |
charlesmn | 0:3ac96e360672 | 1736 | |
charlesmn | 0:3ac96e360672 | 1737 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1738 | |
charlesmn | 0:3ac96e360672 | 1739 | return status; |
charlesmn | 0:3ac96e360672 | 1740 | } |
charlesmn | 0:3ac96e360672 | 1741 | |
charlesmn | 0:3ac96e360672 | 1742 | |
charlesmn | 0:3ac96e360672 | 1743 | VL53L1_Error VL53L1_run_device_test( |
charlesmn | 0:3ac96e360672 | 1744 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1745 | VL53L1_DeviceTestMode device_test_mode) |
charlesmn | 0:3ac96e360672 | 1746 | { |
charlesmn | 0:3ac96e360672 | 1747 | |
charlesmn | 0:3ac96e360672 | 1748 | |
charlesmn | 0:3ac96e360672 | 1749 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1750 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1751 | |
charlesmn | 0:3ac96e360672 | 1752 | uint8_t comms_buffer[2]; |
charlesmn | 0:3ac96e360672 | 1753 | uint8_t gpio_hv_mux__ctrl = 0; |
charlesmn | 0:3ac96e360672 | 1754 | |
charlesmn | 0:3ac96e360672 | 1755 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1756 | |
charlesmn | 0:3ac96e360672 | 1757 | |
charlesmn | 0:3ac96e360672 | 1758 | |
charlesmn | 0:3ac96e360672 | 1759 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1760 | status = |
charlesmn | 0:3ac96e360672 | 1761 | VL53L1_RdByte( |
charlesmn | 0:3ac96e360672 | 1762 | Dev, |
charlesmn | 0:3ac96e360672 | 1763 | VL53L1_GPIO_HV_MUX__CTRL, |
charlesmn | 0:3ac96e360672 | 1764 | &gpio_hv_mux__ctrl); |
charlesmn | 0:3ac96e360672 | 1765 | |
charlesmn | 0:3ac96e360672 | 1766 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1767 | pdev->stat_cfg.gpio_hv_mux__ctrl = gpio_hv_mux__ctrl; |
charlesmn | 0:3ac96e360672 | 1768 | |
charlesmn | 0:3ac96e360672 | 1769 | |
charlesmn | 0:3ac96e360672 | 1770 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1771 | status = VL53L1_start_test( |
charlesmn | 0:3ac96e360672 | 1772 | Dev, |
charlesmn | 0:3ac96e360672 | 1773 | device_test_mode); |
charlesmn | 0:3ac96e360672 | 1774 | |
charlesmn | 0:3ac96e360672 | 1775 | |
charlesmn | 0:3ac96e360672 | 1776 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1777 | status = VL53L1_wait_for_test_completion(Dev); |
charlesmn | 0:3ac96e360672 | 1778 | |
charlesmn | 0:3ac96e360672 | 1779 | |
charlesmn | 0:3ac96e360672 | 1780 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1781 | status = |
charlesmn | 0:3ac96e360672 | 1782 | VL53L1_ReadMulti( |
charlesmn | 0:3ac96e360672 | 1783 | Dev, |
charlesmn | 0:3ac96e360672 | 1784 | VL53L1_RESULT__RANGE_STATUS, |
charlesmn | 0:3ac96e360672 | 1785 | comms_buffer, |
charlesmn | 0:3ac96e360672 | 1786 | 2); |
charlesmn | 0:3ac96e360672 | 1787 | |
charlesmn | 0:3ac96e360672 | 1788 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1789 | pdev->sys_results.result__range_status = comms_buffer[0]; |
charlesmn | 0:3ac96e360672 | 1790 | pdev->sys_results.result__report_status = comms_buffer[1]; |
charlesmn | 0:3ac96e360672 | 1791 | } |
charlesmn | 0:3ac96e360672 | 1792 | |
charlesmn | 0:3ac96e360672 | 1793 | |
charlesmn | 0:3ac96e360672 | 1794 | |
charlesmn | 0:3ac96e360672 | 1795 | pdev->sys_results.result__range_status &= |
charlesmn | 0:3ac96e360672 | 1796 | VL53L1_RANGE_STATUS__RANGE_STATUS_MASK; |
charlesmn | 0:3ac96e360672 | 1797 | |
charlesmn | 0:3ac96e360672 | 1798 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1799 | trace_print( |
charlesmn | 0:3ac96e360672 | 1800 | VL53L1_TRACE_LEVEL_INFO, |
charlesmn | 0:3ac96e360672 | 1801 | " Device Test Complete:\n\t%-32s = %3u\n\t%-32s = %3u\n", |
charlesmn | 0:3ac96e360672 | 1802 | "result__range_status", |
charlesmn | 0:3ac96e360672 | 1803 | pdev->sys_results.result__range_status, |
charlesmn | 0:3ac96e360672 | 1804 | "result__report_status", |
charlesmn | 0:3ac96e360672 | 1805 | pdev->sys_results.result__report_status); |
charlesmn | 0:3ac96e360672 | 1806 | |
charlesmn | 0:3ac96e360672 | 1807 | |
charlesmn | 0:3ac96e360672 | 1808 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1809 | status = VL53L1_clear_interrupt(Dev); |
charlesmn | 0:3ac96e360672 | 1810 | } |
charlesmn | 0:3ac96e360672 | 1811 | |
charlesmn | 0:3ac96e360672 | 1812 | |
charlesmn | 0:3ac96e360672 | 1813 | |
charlesmn | 0:3ac96e360672 | 1814 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1815 | status = |
charlesmn | 0:3ac96e360672 | 1816 | VL53L1_start_test( |
charlesmn | 0:3ac96e360672 | 1817 | Dev, |
charlesmn | 0:3ac96e360672 | 1818 | 0x00); |
charlesmn | 0:3ac96e360672 | 1819 | |
charlesmn | 0:3ac96e360672 | 1820 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1821 | |
charlesmn | 0:3ac96e360672 | 1822 | return status; |
charlesmn | 0:3ac96e360672 | 1823 | } |
charlesmn | 0:3ac96e360672 | 1824 | |
charlesmn | 0:3ac96e360672 | 1825 | |
charlesmn | 0:3ac96e360672 | 1826 | void VL53L1_hist_xtalk_extract_data_init( |
charlesmn | 0:3ac96e360672 | 1827 | VL53L1_hist_xtalk_extract_data_t *pxtalk_data) |
charlesmn | 0:3ac96e360672 | 1828 | { |
charlesmn | 0:3ac96e360672 | 1829 | |
charlesmn | 0:3ac96e360672 | 1830 | |
charlesmn | 0:3ac96e360672 | 1831 | int32_t lb = 0; |
charlesmn | 0:3ac96e360672 | 1832 | |
charlesmn | 0:3ac96e360672 | 1833 | pxtalk_data->sample_count = 0U; |
charlesmn | 0:3ac96e360672 | 1834 | pxtalk_data->pll_period_mm = 0U; |
charlesmn | 0:3ac96e360672 | 1835 | pxtalk_data->peak_duration_us_sum = 0U; |
charlesmn | 0:3ac96e360672 | 1836 | pxtalk_data->effective_spad_count_sum = 0U; |
charlesmn | 0:3ac96e360672 | 1837 | pxtalk_data->zero_distance_phase_sum = 0U; |
charlesmn | 0:3ac96e360672 | 1838 | pxtalk_data->zero_distance_phase_avg = 0U; |
charlesmn | 0:3ac96e360672 | 1839 | pxtalk_data->event_scaler_sum = 0U; |
charlesmn | 0:3ac96e360672 | 1840 | pxtalk_data->event_scaler_avg = 4096U; |
charlesmn | 0:3ac96e360672 | 1841 | pxtalk_data->signal_events_sum = 0; |
charlesmn | 0:3ac96e360672 | 1842 | pxtalk_data->xtalk_rate_kcps_per_spad = 0U; |
charlesmn | 0:3ac96e360672 | 1843 | pxtalk_data->VL53L1_p_015 = 0U; |
charlesmn | 0:3ac96e360672 | 1844 | pxtalk_data->VL53L1_p_016 = 0U; |
charlesmn | 0:3ac96e360672 | 1845 | pxtalk_data->target_start = 0U; |
charlesmn | 0:3ac96e360672 | 1846 | |
charlesmn | 0:3ac96e360672 | 1847 | for (lb = 0; lb < VL53L1_XTALK_HISTO_BINS; lb++) |
charlesmn | 0:3ac96e360672 | 1848 | pxtalk_data->bin_data_sums[lb] = 0; |
charlesmn | 0:3ac96e360672 | 1849 | |
charlesmn | 0:3ac96e360672 | 1850 | } |
charlesmn | 0:3ac96e360672 | 1851 | |
charlesmn | 0:3ac96e360672 | 1852 | |
charlesmn | 0:3ac96e360672 | 1853 | VL53L1_Error VL53L1_hist_xtalk_extract_update( |
charlesmn | 0:3ac96e360672 | 1854 | int16_t target_distance_mm, |
charlesmn | 0:3ac96e360672 | 1855 | uint16_t target_width_oversize, |
charlesmn | 0:3ac96e360672 | 1856 | VL53L1_histogram_bin_data_t *phist_bins, |
charlesmn | 0:3ac96e360672 | 1857 | VL53L1_hist_xtalk_extract_data_t *pxtalk_data) |
charlesmn | 0:3ac96e360672 | 1858 | { |
charlesmn | 0:3ac96e360672 | 1859 | |
charlesmn | 0:3ac96e360672 | 1860 | |
charlesmn | 0:3ac96e360672 | 1861 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1862 | |
charlesmn | 0:3ac96e360672 | 1863 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1864 | |
charlesmn | 0:3ac96e360672 | 1865 | status = |
charlesmn | 0:3ac96e360672 | 1866 | VL53L1_hist_xtalk_extract_calc_window( |
charlesmn | 0:3ac96e360672 | 1867 | target_distance_mm, |
charlesmn | 0:3ac96e360672 | 1868 | target_width_oversize, |
charlesmn | 0:3ac96e360672 | 1869 | phist_bins, |
charlesmn | 0:3ac96e360672 | 1870 | pxtalk_data); |
charlesmn | 0:3ac96e360672 | 1871 | |
charlesmn | 0:3ac96e360672 | 1872 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1873 | status = |
charlesmn | 0:3ac96e360672 | 1874 | VL53L1_hist_xtalk_extract_calc_event_sums( |
charlesmn | 0:3ac96e360672 | 1875 | phist_bins, |
charlesmn | 0:3ac96e360672 | 1876 | pxtalk_data); |
charlesmn | 0:3ac96e360672 | 1877 | } |
charlesmn | 0:3ac96e360672 | 1878 | |
charlesmn | 0:3ac96e360672 | 1879 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1880 | |
charlesmn | 0:3ac96e360672 | 1881 | return status; |
charlesmn | 0:3ac96e360672 | 1882 | } |
charlesmn | 0:3ac96e360672 | 1883 | |
charlesmn | 0:3ac96e360672 | 1884 | |
charlesmn | 0:3ac96e360672 | 1885 | VL53L1_Error VL53L1_hist_xtalk_extract_fini( |
charlesmn | 0:3ac96e360672 | 1886 | VL53L1_histogram_bin_data_t *phist_bins, |
charlesmn | 0:3ac96e360672 | 1887 | VL53L1_hist_xtalk_extract_data_t *pxtalk_data, |
charlesmn | 0:3ac96e360672 | 1888 | VL53L1_xtalk_calibration_results_t *pxtalk_cal, |
charlesmn | 0:3ac96e360672 | 1889 | VL53L1_xtalk_histogram_shape_t *pxtalk_shape) |
charlesmn | 0:3ac96e360672 | 1890 | { |
charlesmn | 0:3ac96e360672 | 1891 | |
charlesmn | 0:3ac96e360672 | 1892 | |
charlesmn | 0:3ac96e360672 | 1893 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1894 | VL53L1_xtalk_calibration_results_t *pX = pxtalk_cal; |
charlesmn | 0:3ac96e360672 | 1895 | |
charlesmn | 0:3ac96e360672 | 1896 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1897 | |
charlesmn | 0:3ac96e360672 | 1898 | if (pxtalk_data->sample_count > 0) { |
charlesmn | 0:3ac96e360672 | 1899 | |
charlesmn | 0:3ac96e360672 | 1900 | |
charlesmn | 0:3ac96e360672 | 1901 | pxtalk_data->event_scaler_avg = pxtalk_data->event_scaler_sum; |
charlesmn | 0:3ac96e360672 | 1902 | pxtalk_data->event_scaler_avg += |
charlesmn | 0:3ac96e360672 | 1903 | (pxtalk_data->sample_count >> 1); |
charlesmn | 0:3ac96e360672 | 1904 | pxtalk_data->event_scaler_avg /= pxtalk_data->sample_count; |
charlesmn | 0:3ac96e360672 | 1905 | |
charlesmn | 0:3ac96e360672 | 1906 | |
charlesmn | 0:3ac96e360672 | 1907 | |
charlesmn | 0:3ac96e360672 | 1908 | status = |
charlesmn | 0:3ac96e360672 | 1909 | VL53L1_hist_xtalk_extract_calc_rate_per_spad( |
charlesmn | 0:3ac96e360672 | 1910 | pxtalk_data); |
charlesmn | 0:3ac96e360672 | 1911 | |
charlesmn | 0:3ac96e360672 | 1912 | |
charlesmn | 0:3ac96e360672 | 1913 | |
charlesmn | 0:3ac96e360672 | 1914 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1915 | |
charlesmn | 0:3ac96e360672 | 1916 | |
charlesmn | 0:3ac96e360672 | 1917 | pxtalk_data->zero_distance_phase_avg = |
charlesmn | 0:3ac96e360672 | 1918 | pxtalk_data->zero_distance_phase_sum; |
charlesmn | 0:3ac96e360672 | 1919 | pxtalk_data->zero_distance_phase_avg += |
charlesmn | 0:3ac96e360672 | 1920 | (pxtalk_data->sample_count >> 1); |
charlesmn | 0:3ac96e360672 | 1921 | pxtalk_data->zero_distance_phase_avg /= |
charlesmn | 0:3ac96e360672 | 1922 | pxtalk_data->sample_count; |
charlesmn | 0:3ac96e360672 | 1923 | |
charlesmn | 0:3ac96e360672 | 1924 | |
charlesmn | 0:3ac96e360672 | 1925 | status = |
charlesmn | 0:3ac96e360672 | 1926 | VL53L1_hist_xtalk_extract_calc_shape( |
charlesmn | 0:3ac96e360672 | 1927 | pxtalk_data, |
charlesmn | 0:3ac96e360672 | 1928 | pxtalk_shape); |
charlesmn | 0:3ac96e360672 | 1929 | |
charlesmn | 0:3ac96e360672 | 1930 | |
charlesmn | 0:3ac96e360672 | 1931 | |
charlesmn | 0:3ac96e360672 | 1932 | |
charlesmn | 0:3ac96e360672 | 1933 | pxtalk_shape->phasecal_result__vcsel_start = |
charlesmn | 0:3ac96e360672 | 1934 | phist_bins->phasecal_result__vcsel_start; |
charlesmn | 0:3ac96e360672 | 1935 | pxtalk_shape->cal_config__vcsel_start = |
charlesmn | 0:3ac96e360672 | 1936 | phist_bins->cal_config__vcsel_start; |
charlesmn | 0:3ac96e360672 | 1937 | pxtalk_shape->vcsel_width = |
charlesmn | 0:3ac96e360672 | 1938 | phist_bins->vcsel_width; |
charlesmn | 0:3ac96e360672 | 1939 | pxtalk_shape->VL53L1_p_019 = |
charlesmn | 0:3ac96e360672 | 1940 | phist_bins->VL53L1_p_019; |
charlesmn | 0:3ac96e360672 | 1941 | } |
charlesmn | 0:3ac96e360672 | 1942 | |
charlesmn | 0:3ac96e360672 | 1943 | |
charlesmn | 0:3ac96e360672 | 1944 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1945 | |
charlesmn | 0:3ac96e360672 | 1946 | |
charlesmn | 0:3ac96e360672 | 1947 | pX->algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 1948 | pxtalk_data->xtalk_rate_kcps_per_spad; |
charlesmn | 0:3ac96e360672 | 1949 | pX->algo__crosstalk_compensation_x_plane_gradient_kcps |
charlesmn | 0:3ac96e360672 | 1950 | = 0U; |
charlesmn | 0:3ac96e360672 | 1951 | pX->algo__crosstalk_compensation_y_plane_gradient_kcps |
charlesmn | 0:3ac96e360672 | 1952 | = 0U; |
charlesmn | 0:3ac96e360672 | 1953 | |
charlesmn | 0:3ac96e360672 | 1954 | } |
charlesmn | 0:3ac96e360672 | 1955 | } |
charlesmn | 0:3ac96e360672 | 1956 | |
charlesmn | 0:3ac96e360672 | 1957 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 1958 | |
charlesmn | 0:3ac96e360672 | 1959 | return status; |
charlesmn | 0:3ac96e360672 | 1960 | } |
charlesmn | 0:3ac96e360672 | 1961 | |
charlesmn | 0:3ac96e360672 | 1962 | |
charlesmn | 0:3ac96e360672 | 1963 | VL53L1_Error VL53L1_run_hist_xtalk_extraction( |
charlesmn | 0:3ac96e360672 | 1964 | VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1965 | int16_t cal_distance_mm, |
charlesmn | 0:3ac96e360672 | 1966 | VL53L1_Error *pcal_status) |
charlesmn | 0:3ac96e360672 | 1967 | { |
charlesmn | 0:3ac96e360672 | 1968 | |
charlesmn | 0:3ac96e360672 | 1969 | |
charlesmn | 0:3ac96e360672 | 1970 | #define OVERSIZE 4 |
charlesmn | 0:3ac96e360672 | 1971 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1972 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1973 | VL53L1_xtalkextract_config_t *pX = &(pdev->xtalk_extract_cfg); |
charlesmn | 0:3ac96e360672 | 1974 | VL53L1_xtalk_config_t *pC = &(pdev->xtalk_cfg); |
charlesmn | 0:3ac96e360672 | 1975 | VL53L1_xtalk_calibration_results_t *pXC = &(pdev->xtalk_cal); |
charlesmn | 0:3ac96e360672 | 1976 | |
charlesmn | 0:3ac96e360672 | 1977 | |
charlesmn | 0:3ac96e360672 | 1978 | |
charlesmn | 0:3ac96e360672 | 1979 | uint8_t smudge_corr_en = 0; |
charlesmn | 0:3ac96e360672 | 1980 | uint8_t i = 0; |
charlesmn | 0:3ac96e360672 | 1981 | int8_t k = 0; |
charlesmn | 0:3ac96e360672 | 1982 | uint8_t nbloops; |
charlesmn | 0:3ac96e360672 | 1983 | int32_t initMergeSize = 0; |
charlesmn | 0:3ac96e360672 | 1984 | int32_t MergeEnabled = 0; |
charlesmn | 0:3ac96e360672 | 1985 | uint32_t deltaXtalk; |
charlesmn | 0:3ac96e360672 | 1986 | uint32_t stepXtalk; |
charlesmn | 0:3ac96e360672 | 1987 | uint32_t XtalkMin; |
charlesmn | 0:3ac96e360672 | 1988 | uint32_t XtalkMax; |
charlesmn | 0:3ac96e360672 | 1989 | uint8_t measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK; |
charlesmn | 0:3ac96e360672 | 1990 | int8_t MaxId; |
charlesmn | 0:3ac96e360672 | 1991 | uint8_t histo_merge_nb; |
charlesmn | 0:3ac96e360672 | 1992 | uint8_t wait_for_accumulation; |
charlesmn | 0:3ac96e360672 | 1993 | VL53L1_range_results_t *prange_results = |
charlesmn | 0:3ac96e360672 | 1994 | (VL53L1_range_results_t *) pdev->wArea1; |
charlesmn | 0:3ac96e360672 | 1995 | uint8_t Very1stRange = 0; |
charlesmn | 0:3ac96e360672 | 1996 | |
charlesmn | 0:3ac96e360672 | 1997 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1998 | |
charlesmn | 0:3ac96e360672 | 1999 | |
charlesmn | 0:3ac96e360672 | 2000 | |
charlesmn | 0:3ac96e360672 | 2001 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2002 | status = |
charlesmn | 0:3ac96e360672 | 2003 | VL53L1_set_preset_mode( |
charlesmn | 0:3ac96e360672 | 2004 | Dev, |
charlesmn | 0:3ac96e360672 | 2005 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE, |
charlesmn | 0:3ac96e360672 | 2006 | pX->dss_config__target_total_rate_mcps, |
charlesmn | 0:3ac96e360672 | 2007 | pX->phasecal_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 2008 | pX->mm_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 2009 | pX->range_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 2010 | 100); |
charlesmn | 0:3ac96e360672 | 2011 | |
charlesmn | 0:3ac96e360672 | 2012 | |
charlesmn | 0:3ac96e360672 | 2013 | |
charlesmn | 0:3ac96e360672 | 2014 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2015 | status = VL53L1_disable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 2016 | |
charlesmn | 0:3ac96e360672 | 2017 | |
charlesmn | 0:3ac96e360672 | 2018 | |
charlesmn | 0:3ac96e360672 | 2019 | smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled; |
charlesmn | 0:3ac96e360672 | 2020 | |
charlesmn | 0:3ac96e360672 | 2021 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2022 | status = VL53L1_dynamic_xtalk_correction_disable(Dev); |
charlesmn | 0:3ac96e360672 | 2023 | |
charlesmn | 0:3ac96e360672 | 2024 | |
charlesmn | 0:3ac96e360672 | 2025 | VL53L1_load_patch(Dev); |
charlesmn | 0:3ac96e360672 | 2026 | |
charlesmn | 0:3ac96e360672 | 2027 | VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE, |
charlesmn | 0:3ac96e360672 | 2028 | &initMergeSize); |
charlesmn | 0:3ac96e360672 | 2029 | VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, |
charlesmn | 0:3ac96e360672 | 2030 | &MergeEnabled); |
charlesmn | 0:3ac96e360672 | 2031 | memset(&pdev->xtalk_cal, 0, sizeof(pdev->xtalk_cal)); |
charlesmn | 0:3ac96e360672 | 2032 | |
charlesmn | 0:3ac96e360672 | 2033 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2034 | status = VL53L1_init_and_start_range( |
charlesmn | 0:3ac96e360672 | 2035 | Dev, measurement_mode, |
charlesmn | 0:3ac96e360672 | 2036 | VL53L1_DEVICECONFIGLEVEL_CUSTOMER_ONWARDS); |
charlesmn | 0:3ac96e360672 | 2037 | |
charlesmn | 0:3ac96e360672 | 2038 | MaxId = pdev->tuning_parms.tp_hist_merge_max_size - 1; |
charlesmn | 0:3ac96e360672 | 2039 | nbloops = (MergeEnabled == 0 ? 1 : 2); |
charlesmn | 0:3ac96e360672 | 2040 | for (k = 0; k < nbloops; k++) { |
charlesmn | 0:3ac96e360672 | 2041 | |
charlesmn | 0:3ac96e360672 | 2042 | VL53L1_hist_xtalk_extract_data_init( |
charlesmn | 0:3ac96e360672 | 2043 | &(pdev->xtalk_extract)); |
charlesmn | 0:3ac96e360672 | 2044 | VL53L1_set_tuning_parm(Dev, |
charlesmn | 0:3ac96e360672 | 2045 | VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE, |
charlesmn | 0:3ac96e360672 | 2046 | k * MaxId + 1); |
charlesmn | 0:3ac96e360672 | 2047 | |
charlesmn | 0:3ac96e360672 | 2048 | for (i = 0; i <= pX->num_of_samples; i++) { |
charlesmn | 0:3ac96e360672 | 2049 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2050 | status = VL53L1_wait_for_range_completion(Dev); |
charlesmn | 0:3ac96e360672 | 2051 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2052 | status = VL53L1_get_device_results(Dev, |
charlesmn | 0:3ac96e360672 | 2053 | VL53L1_DEVICERESULTSLEVEL_FULL, |
charlesmn | 0:3ac96e360672 | 2054 | prange_results); |
charlesmn | 0:3ac96e360672 | 2055 | Very1stRange = |
charlesmn | 0:3ac96e360672 | 2056 | (pdev->ll_state.rd_device_state == |
charlesmn | 0:3ac96e360672 | 2057 | VL53L1_DEVICESTATE_RANGING_WAIT_GPH_SYNC); |
charlesmn | 0:3ac96e360672 | 2058 | |
charlesmn | 0:3ac96e360672 | 2059 | VL53L1_compute_histo_merge_nb(Dev, &histo_merge_nb); |
charlesmn | 0:3ac96e360672 | 2060 | wait_for_accumulation = ((k != 0) && |
charlesmn | 0:3ac96e360672 | 2061 | (MergeEnabled) && |
charlesmn | 0:3ac96e360672 | 2062 | (status == VL53L1_ERROR_NONE) && |
charlesmn | 0:3ac96e360672 | 2063 | (histo_merge_nb < |
charlesmn | 0:3ac96e360672 | 2064 | pdev->tuning_parms.tp_hist_merge_max_size)); |
charlesmn | 0:3ac96e360672 | 2065 | if (wait_for_accumulation) |
charlesmn | 0:3ac96e360672 | 2066 | i = 0; |
charlesmn | 0:3ac96e360672 | 2067 | else { |
charlesmn | 0:3ac96e360672 | 2068 | if ((status == VL53L1_ERROR_NONE) && |
charlesmn | 0:3ac96e360672 | 2069 | (!Very1stRange)) { |
charlesmn | 0:3ac96e360672 | 2070 | status = |
charlesmn | 0:3ac96e360672 | 2071 | VL53L1_hist_xtalk_extract_update( |
charlesmn | 0:3ac96e360672 | 2072 | cal_distance_mm, |
charlesmn | 0:3ac96e360672 | 2073 | OVERSIZE, |
charlesmn | 0:3ac96e360672 | 2074 | &(pdev->hist_data), |
charlesmn | 0:3ac96e360672 | 2075 | &(pdev->xtalk_extract)); |
charlesmn | 0:3ac96e360672 | 2076 | } |
charlesmn | 0:3ac96e360672 | 2077 | } |
charlesmn | 0:3ac96e360672 | 2078 | |
charlesmn | 0:3ac96e360672 | 2079 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2080 | status = VL53L1_wait_for_firmware_ready(Dev); |
charlesmn | 0:3ac96e360672 | 2081 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2082 | status = |
charlesmn | 0:3ac96e360672 | 2083 | VL53L1_clear_interrupt_and_enable_next_range( |
charlesmn | 0:3ac96e360672 | 2084 | Dev, measurement_mode); |
charlesmn | 0:3ac96e360672 | 2085 | |
charlesmn | 0:3ac96e360672 | 2086 | |
charlesmn | 0:3ac96e360672 | 2087 | if (status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2088 | status = |
charlesmn | 0:3ac96e360672 | 2089 | VL53L1_hist_xtalk_extract_fini( |
charlesmn | 0:3ac96e360672 | 2090 | &(pdev->hist_data), |
charlesmn | 0:3ac96e360672 | 2091 | &(pdev->xtalk_extract), |
charlesmn | 0:3ac96e360672 | 2092 | &(pdev->xtalk_cal), |
charlesmn | 0:3ac96e360672 | 2093 | &(pdev->xtalk_shapes.xtalk_shape)); |
charlesmn | 0:3ac96e360672 | 2094 | if (status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2095 | goto LOOPOUT; |
charlesmn | 0:3ac96e360672 | 2096 | pXC->algo__xtalk_cpo_HistoMerge_kcps[k * MaxId] = |
charlesmn | 0:3ac96e360672 | 2097 | pXC->algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 2098 | } |
charlesmn | 0:3ac96e360672 | 2099 | } |
charlesmn | 0:3ac96e360672 | 2100 | |
charlesmn | 0:3ac96e360672 | 2101 | LOOPOUT: |
charlesmn | 0:3ac96e360672 | 2102 | |
charlesmn | 0:3ac96e360672 | 2103 | VL53L1_stop_range(Dev); |
charlesmn | 0:3ac96e360672 | 2104 | |
charlesmn | 0:3ac96e360672 | 2105 | VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE_MAX_SIZE, |
charlesmn | 0:3ac96e360672 | 2106 | initMergeSize); |
charlesmn | 0:3ac96e360672 | 2107 | VL53L1_unload_patch(Dev); |
charlesmn | 0:3ac96e360672 | 2108 | |
charlesmn | 0:3ac96e360672 | 2109 | if (status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2110 | status = VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL; |
charlesmn | 0:3ac96e360672 | 2111 | else if ((MergeEnabled == 1) && (MaxId > 0)) { |
charlesmn | 0:3ac96e360672 | 2112 | XtalkMin = pXC->algo__xtalk_cpo_HistoMerge_kcps[0]; |
charlesmn | 0:3ac96e360672 | 2113 | XtalkMax = pXC->algo__xtalk_cpo_HistoMerge_kcps[MaxId]; |
charlesmn | 0:3ac96e360672 | 2114 | pXC->algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 2115 | XtalkMin; |
charlesmn | 0:3ac96e360672 | 2116 | if (XtalkMax >= XtalkMin) { |
charlesmn | 0:3ac96e360672 | 2117 | deltaXtalk = XtalkMax - XtalkMin; |
charlesmn | 0:3ac96e360672 | 2118 | stepXtalk = deltaXtalk / MaxId; |
charlesmn | 0:3ac96e360672 | 2119 | for (k = 1; k < MaxId; k++) |
charlesmn | 0:3ac96e360672 | 2120 | pXC->algo__xtalk_cpo_HistoMerge_kcps[k] = |
charlesmn | 0:3ac96e360672 | 2121 | XtalkMin + stepXtalk * k; |
charlesmn | 0:3ac96e360672 | 2122 | } else |
charlesmn | 0:3ac96e360672 | 2123 | status = |
charlesmn | 0:3ac96e360672 | 2124 | VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL; |
charlesmn | 0:3ac96e360672 | 2125 | } |
charlesmn | 0:3ac96e360672 | 2126 | |
charlesmn | 0:3ac96e360672 | 2127 | if (status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 2128 | pC->algo__crosstalk_compensation_x_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 2129 | pXC->algo__crosstalk_compensation_x_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 2130 | pC->algo__crosstalk_compensation_y_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 2131 | pXC->algo__crosstalk_compensation_y_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 2132 | pC->algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 2133 | pXC->algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 2134 | } |
charlesmn | 0:3ac96e360672 | 2135 | |
charlesmn | 0:3ac96e360672 | 2136 | |
charlesmn | 0:3ac96e360672 | 2137 | pdev->xtalk_results.cal_status = status; |
charlesmn | 0:3ac96e360672 | 2138 | *pcal_status = pdev->xtalk_results.cal_status; |
charlesmn | 0:3ac96e360672 | 2139 | |
charlesmn | 0:3ac96e360672 | 2140 | |
charlesmn | 0:3ac96e360672 | 2141 | status = VL53L1_enable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 2142 | if (smudge_corr_en == 1) |
charlesmn | 0:3ac96e360672 | 2143 | status = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 2144 | |
charlesmn | 0:3ac96e360672 | 2145 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 2146 | |
charlesmn | 0:3ac96e360672 | 2147 | |
charlesmn | 0:3ac96e360672 | 2148 | |
charlesmn | 0:3ac96e360672 | 2149 | VL53L1_print_customer_nvm_managed( |
charlesmn | 0:3ac96e360672 | 2150 | &(pdev->customer), |
charlesmn | 0:3ac96e360672 | 2151 | "run_xtalk_extraction():pdev->lldata.customer.", |
charlesmn | 0:3ac96e360672 | 2152 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 2153 | |
charlesmn | 0:3ac96e360672 | 2154 | VL53L1_print_xtalk_config( |
charlesmn | 0:3ac96e360672 | 2155 | &(pdev->xtalk_cfg), |
charlesmn | 0:3ac96e360672 | 2156 | "run_xtalk_extraction():pdev->lldata.xtalk_cfg.", |
charlesmn | 0:3ac96e360672 | 2157 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 2158 | |
charlesmn | 0:3ac96e360672 | 2159 | VL53L1_print_xtalk_histogram_data( |
charlesmn | 0:3ac96e360672 | 2160 | &(pdev->xtalk_shapes), |
charlesmn | 0:3ac96e360672 | 2161 | "pdev->lldata.xtalk_shapes.", |
charlesmn | 0:3ac96e360672 | 2162 | VL53L1_TRACE_MODULE_XTALK_DATA); |
charlesmn | 0:3ac96e360672 | 2163 | |
charlesmn | 0:3ac96e360672 | 2164 | #endif |
charlesmn | 0:3ac96e360672 | 2165 | |
charlesmn | 0:3ac96e360672 | 2166 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 2167 | |
charlesmn | 0:3ac96e360672 | 2168 | return status; |
charlesmn | 0:3ac96e360672 | 2169 | } |
charlesmn | 0:3ac96e360672 | 2170 |