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.

Committer:
charlesmn
Date:
Fri Nov 06 10:06:37 2020 +0000
Revision:
0:3ac96e360672
Child:
7:1add29d51e72
Library for ST Vl53L1A1 time of flight sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:3ac96e360672 1
charlesmn 0:3ac96e360672 2 /*******************************************************************************
charlesmn 0:3ac96e360672 3 This file is part of VL53L1 Protected
charlesmn 0:3ac96e360672 4
charlesmn 0:3ac96e360672 5 Copyright (c) 2020, STMicroelectronics - All Rights Reserved
charlesmn 0:3ac96e360672 6
charlesmn 0:3ac96e360672 7 License terms: STMicroelectronics Proprietary in accordance with licensing
charlesmn 0:3ac96e360672 8 terms at www.st.com/sla0081
charlesmn 0:3ac96e360672 9
charlesmn 0:3ac96e360672 10 STMicroelectronics confidential
charlesmn 0:3ac96e360672 11 Reproduction and Communication of this document is strictly prohibited unless
charlesmn 0:3ac96e360672 12 specifically authorized in writing by STMicroelectronics.
charlesmn 0:3ac96e360672 13
charlesmn 0:3ac96e360672 14 */
charlesmn 0:3ac96e360672 15
charlesmn 0:3ac96e360672 16
charlesmn 0:3ac96e360672 17
charlesmn 0:3ac96e360672 18
charlesmn 0:3ac96e360672 19 #include "vl53l1_types.h"
charlesmn 0:3ac96e360672 20 #include "vl53l1_platform_log.h"
charlesmn 0:3ac96e360672 21
charlesmn 0:3ac96e360672 22 #include "vl53l1_core_support.h"
charlesmn 0:3ac96e360672 23 #include "vl53l1_error_codes.h"
charlesmn 0:3ac96e360672 24
charlesmn 0:3ac96e360672 25 #include "vl53l1_hist_core.h"
charlesmn 0:3ac96e360672 26 #include "vl53l1_hist_algos_gen3.h"
charlesmn 0:3ac96e360672 27 #include "vl53l1_sigma_estimate.h"
charlesmn 0:3ac96e360672 28 #include "vl53l1_dmax.h"
charlesmn 0:3ac96e360672 29
charlesmn 0:3ac96e360672 30
charlesmn 0:3ac96e360672 31
charlesmn 0:3ac96e360672 32 #define LOG_FUNCTION_START(fmt, ...) \
charlesmn 0:3ac96e360672 33 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_HISTOGRAM, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 34 #define LOG_FUNCTION_END(status, ...) \
charlesmn 0:3ac96e360672 35 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_HISTOGRAM, status, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 36 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
charlesmn 0:3ac96e360672 37 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_HISTOGRAM,\
charlesmn 0:3ac96e360672 38 status, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 39
charlesmn 0:3ac96e360672 40 #define trace_print(level, ...) \
charlesmn 0:3ac96e360672 41 _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_HISTOGRAM, \
charlesmn 0:3ac96e360672 42 level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 43
charlesmn 0:3ac96e360672 44
charlesmn 0:3ac96e360672 45 void VL53L1_f_016(
charlesmn 0:3ac96e360672 46 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 47 {
charlesmn 0:3ac96e360672 48
charlesmn 0:3ac96e360672 49
charlesmn 0:3ac96e360672 50 uint8_t lb = 0;
charlesmn 0:3ac96e360672 51
charlesmn 0:3ac96e360672 52 palgo->VL53L1_p_023 = VL53L1_HISTOGRAM_BUFFER_SIZE;
charlesmn 0:3ac96e360672 53 palgo->VL53L1_p_022 = 0;
charlesmn 0:3ac96e360672 54 palgo->VL53L1_p_024 = 0;
charlesmn 0:3ac96e360672 55 palgo->VL53L1_p_045 = 0;
charlesmn 0:3ac96e360672 56 palgo->VL53L1_p_004 = 0;
charlesmn 0:3ac96e360672 57 palgo->VL53L1_p_032 = 0;
charlesmn 0:3ac96e360672 58
charlesmn 0:3ac96e360672 59 for (lb = palgo->VL53L1_p_022; lb < palgo->VL53L1_p_023; lb++) {
charlesmn 0:3ac96e360672 60 palgo->VL53L1_p_043[lb] = 0;
charlesmn 0:3ac96e360672 61 palgo->VL53L1_p_046[lb] = 0;
charlesmn 0:3ac96e360672 62 palgo->VL53L1_p_047[lb] = 0;
charlesmn 0:3ac96e360672 63 palgo->VL53L1_p_048[lb] = 0;
charlesmn 0:3ac96e360672 64 palgo->VL53L1_p_008[lb] = 0;
charlesmn 0:3ac96e360672 65 }
charlesmn 0:3ac96e360672 66
charlesmn 0:3ac96e360672 67 palgo->VL53L1_p_049 = 0;
charlesmn 0:3ac96e360672 68 palgo->VL53L1_p_050 = VL53L1_D_001;
charlesmn 0:3ac96e360672 69 palgo->VL53L1_p_051 = 0;
charlesmn 0:3ac96e360672 70
charlesmn 0:3ac96e360672 71
charlesmn 0:3ac96e360672 72
charlesmn 0:3ac96e360672 73 VL53L1_init_histogram_bin_data_struct(
charlesmn 0:3ac96e360672 74 0,
charlesmn 0:3ac96e360672 75 VL53L1_HISTOGRAM_BUFFER_SIZE,
charlesmn 0:3ac96e360672 76 &(palgo->VL53L1_p_010));
charlesmn 0:3ac96e360672 77 VL53L1_init_histogram_bin_data_struct(
charlesmn 0:3ac96e360672 78 0,
charlesmn 0:3ac96e360672 79 VL53L1_HISTOGRAM_BUFFER_SIZE,
charlesmn 0:3ac96e360672 80 &(palgo->VL53L1_p_038));
charlesmn 0:3ac96e360672 81 VL53L1_init_histogram_bin_data_struct(
charlesmn 0:3ac96e360672 82 0,
charlesmn 0:3ac96e360672 83 VL53L1_HISTOGRAM_BUFFER_SIZE,
charlesmn 0:3ac96e360672 84 &(palgo->VL53L1_p_052));
charlesmn 0:3ac96e360672 85 VL53L1_init_histogram_bin_data_struct(
charlesmn 0:3ac96e360672 86 0,
charlesmn 0:3ac96e360672 87 VL53L1_HISTOGRAM_BUFFER_SIZE,
charlesmn 0:3ac96e360672 88 &(palgo->VL53L1_p_053));
charlesmn 0:3ac96e360672 89 VL53L1_init_histogram_bin_data_struct(
charlesmn 0:3ac96e360672 90 0,
charlesmn 0:3ac96e360672 91 VL53L1_HISTOGRAM_BUFFER_SIZE,
charlesmn 0:3ac96e360672 92 &(palgo->VL53L1_p_054));
charlesmn 0:3ac96e360672 93 }
charlesmn 0:3ac96e360672 94
charlesmn 0:3ac96e360672 95
charlesmn 0:3ac96e360672 96
charlesmn 0:3ac96e360672 97 VL53L1_Error VL53L1_f_018(
charlesmn 0:3ac96e360672 98 uint16_t ambient_threshold_events_scaler,
charlesmn 0:3ac96e360672 99 int32_t ambient_threshold_sigma,
charlesmn 0:3ac96e360672 100 int32_t min_ambient_threshold_events,
charlesmn 0:3ac96e360672 101 uint8_t algo__crosstalk_compensation_enable,
charlesmn 0:3ac96e360672 102 VL53L1_histogram_bin_data_t *pbins,
charlesmn 0:3ac96e360672 103 VL53L1_histogram_bin_data_t *pxtalk,
charlesmn 0:3ac96e360672 104 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 105 {
charlesmn 0:3ac96e360672 106
charlesmn 0:3ac96e360672 107
charlesmn 0:3ac96e360672 108
charlesmn 0:3ac96e360672 109 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 110 uint8_t lb = 0;
charlesmn 0:3ac96e360672 111 uint8_t VL53L1_p_001 = 0;
charlesmn 0:3ac96e360672 112 int64_t tmp = 0;
charlesmn 0:3ac96e360672 113 int32_t amb_events = 0;
charlesmn 0:3ac96e360672 114 int32_t VL53L1_p_008 = 0;
charlesmn 0:3ac96e360672 115 int32_t samples = 0;
charlesmn 0:3ac96e360672 116
charlesmn 0:3ac96e360672 117 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 118
charlesmn 0:3ac96e360672 119
charlesmn 0:3ac96e360672 120 palgo->VL53L1_p_023 = pbins->VL53L1_p_023;
charlesmn 0:3ac96e360672 121 palgo->VL53L1_p_022 = pbins->VL53L1_p_022;
charlesmn 0:3ac96e360672 122 palgo->VL53L1_p_024 = pbins->VL53L1_p_024;
charlesmn 0:3ac96e360672 123 palgo->VL53L1_p_004 = pbins->VL53L1_p_004;
charlesmn 0:3ac96e360672 124
charlesmn 0:3ac96e360672 125
charlesmn 0:3ac96e360672 126
charlesmn 0:3ac96e360672 127 palgo->VL53L1_p_031 =
charlesmn 0:3ac96e360672 128 VL53L1_decode_vcsel_period(pbins->VL53L1_p_009);
charlesmn 0:3ac96e360672 129
charlesmn 0:3ac96e360672 130
charlesmn 0:3ac96e360672 131
charlesmn 0:3ac96e360672 132 tmp = (int64_t)pbins->VL53L1_p_004;
charlesmn 0:3ac96e360672 133 tmp *= (int64_t)ambient_threshold_events_scaler;
charlesmn 0:3ac96e360672 134 tmp += 2048;
charlesmn 0:3ac96e360672 135 tmp = do_division_s(tmp, 4096);
charlesmn 0:3ac96e360672 136 amb_events = (int32_t)tmp;
charlesmn 0:3ac96e360672 137
charlesmn 0:3ac96e360672 138
charlesmn 0:3ac96e360672 139
charlesmn 0:3ac96e360672 140 for (lb = 0; lb < pbins->VL53L1_p_024; lb++) {
charlesmn 0:3ac96e360672 141
charlesmn 0:3ac96e360672 142 VL53L1_p_001 = lb >> 2;
charlesmn 0:3ac96e360672 143 samples = (int32_t)pbins->bin_rep[VL53L1_p_001];
charlesmn 0:3ac96e360672 144
charlesmn 0:3ac96e360672 145 if (samples > 0) {
charlesmn 0:3ac96e360672 146
charlesmn 0:3ac96e360672 147 if (lb < pxtalk->VL53L1_p_024 &&
charlesmn 0:3ac96e360672 148 algo__crosstalk_compensation_enable > 0)
charlesmn 0:3ac96e360672 149 VL53L1_p_008 = samples * (amb_events +
charlesmn 0:3ac96e360672 150 pxtalk->bin_data[lb]);
charlesmn 0:3ac96e360672 151 else
charlesmn 0:3ac96e360672 152 VL53L1_p_008 = samples * amb_events;
charlesmn 0:3ac96e360672 153
charlesmn 0:3ac96e360672 154 VL53L1_p_008 = VL53L1_isqrt(VL53L1_p_008);
charlesmn 0:3ac96e360672 155
charlesmn 0:3ac96e360672 156 VL53L1_p_008 += (samples/2);
charlesmn 0:3ac96e360672 157 VL53L1_p_008 /= samples;
charlesmn 0:3ac96e360672 158 VL53L1_p_008 *= ambient_threshold_sigma;
charlesmn 0:3ac96e360672 159 VL53L1_p_008 += 8;
charlesmn 0:3ac96e360672 160 VL53L1_p_008 /= 16;
charlesmn 0:3ac96e360672 161 VL53L1_p_008 += amb_events;
charlesmn 0:3ac96e360672 162
charlesmn 0:3ac96e360672 163 if (VL53L1_p_008 < min_ambient_threshold_events)
charlesmn 0:3ac96e360672 164 VL53L1_p_008 = min_ambient_threshold_events;
charlesmn 0:3ac96e360672 165
charlesmn 0:3ac96e360672 166 palgo->VL53L1_p_056[lb] = VL53L1_p_008;
charlesmn 0:3ac96e360672 167 palgo->VL53L1_p_032 = VL53L1_p_008;
charlesmn 0:3ac96e360672 168 }
charlesmn 0:3ac96e360672 169
charlesmn 0:3ac96e360672 170
charlesmn 0:3ac96e360672 171
charlesmn 0:3ac96e360672 172 }
charlesmn 0:3ac96e360672 173
charlesmn 0:3ac96e360672 174
charlesmn 0:3ac96e360672 175
charlesmn 0:3ac96e360672 176 palgo->VL53L1_p_045 = 0;
charlesmn 0:3ac96e360672 177
charlesmn 0:3ac96e360672 178 for (lb = pbins->VL53L1_p_022; lb < pbins->VL53L1_p_024; lb++) {
charlesmn 0:3ac96e360672 179
charlesmn 0:3ac96e360672 180 if (pbins->bin_data[lb] > palgo->VL53L1_p_056[lb]) {
charlesmn 0:3ac96e360672 181 palgo->VL53L1_p_043[lb] = 1;
charlesmn 0:3ac96e360672 182 palgo->VL53L1_p_046[lb] = 1;
charlesmn 0:3ac96e360672 183 palgo->VL53L1_p_045++;
charlesmn 0:3ac96e360672 184 } else {
charlesmn 0:3ac96e360672 185 palgo->VL53L1_p_043[lb] = 0;
charlesmn 0:3ac96e360672 186 palgo->VL53L1_p_046[lb] = 0;
charlesmn 0:3ac96e360672 187 }
charlesmn 0:3ac96e360672 188 }
charlesmn 0:3ac96e360672 189
charlesmn 0:3ac96e360672 190 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 191
charlesmn 0:3ac96e360672 192 return status;
charlesmn 0:3ac96e360672 193
charlesmn 0:3ac96e360672 194 }
charlesmn 0:3ac96e360672 195
charlesmn 0:3ac96e360672 196
charlesmn 0:3ac96e360672 197
charlesmn 0:3ac96e360672 198
charlesmn 0:3ac96e360672 199 VL53L1_Error VL53L1_f_019(
charlesmn 0:3ac96e360672 200 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 201 {
charlesmn 0:3ac96e360672 202
charlesmn 0:3ac96e360672 203
charlesmn 0:3ac96e360672 204
charlesmn 0:3ac96e360672 205 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 206
charlesmn 0:3ac96e360672 207 uint8_t i = 0;
charlesmn 0:3ac96e360672 208 uint8_t j = 0;
charlesmn 0:3ac96e360672 209 uint8_t found = 0;
charlesmn 0:3ac96e360672 210
charlesmn 0:3ac96e360672 211 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 212
charlesmn 0:3ac96e360672 213 palgo->VL53L1_p_049 = 0;
charlesmn 0:3ac96e360672 214
charlesmn 0:3ac96e360672 215 for (i = 0; i < palgo->VL53L1_p_031; i++) {
charlesmn 0:3ac96e360672 216
charlesmn 0:3ac96e360672 217 j = (i + 1) % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 218
charlesmn 0:3ac96e360672 219
charlesmn 0:3ac96e360672 220
charlesmn 0:3ac96e360672 221 if (i < palgo->VL53L1_p_024 && j < palgo->VL53L1_p_024) {
charlesmn 0:3ac96e360672 222 if (palgo->VL53L1_p_046[i] == 0 &&
charlesmn 0:3ac96e360672 223 palgo->VL53L1_p_046[j] == 1 &&
charlesmn 0:3ac96e360672 224 found == 0) {
charlesmn 0:3ac96e360672 225 palgo->VL53L1_p_049 = i;
charlesmn 0:3ac96e360672 226 found = 1;
charlesmn 0:3ac96e360672 227 }
charlesmn 0:3ac96e360672 228 }
charlesmn 0:3ac96e360672 229 }
charlesmn 0:3ac96e360672 230
charlesmn 0:3ac96e360672 231 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 232
charlesmn 0:3ac96e360672 233 return status;
charlesmn 0:3ac96e360672 234 }
charlesmn 0:3ac96e360672 235
charlesmn 0:3ac96e360672 236
charlesmn 0:3ac96e360672 237 VL53L1_Error VL53L1_f_020(
charlesmn 0:3ac96e360672 238 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 239 {
charlesmn 0:3ac96e360672 240
charlesmn 0:3ac96e360672 241
charlesmn 0:3ac96e360672 242
charlesmn 0:3ac96e360672 243 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 244 uint8_t i = 0;
charlesmn 0:3ac96e360672 245 uint8_t j = 0;
charlesmn 0:3ac96e360672 246 uint8_t lb = 0;
charlesmn 0:3ac96e360672 247
charlesmn 0:3ac96e360672 248 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 249
charlesmn 0:3ac96e360672 250 for (lb = palgo->VL53L1_p_049;
charlesmn 0:3ac96e360672 251 lb < (palgo->VL53L1_p_049 +
charlesmn 0:3ac96e360672 252 palgo->VL53L1_p_031);
charlesmn 0:3ac96e360672 253 lb++) {
charlesmn 0:3ac96e360672 254
charlesmn 0:3ac96e360672 255
charlesmn 0:3ac96e360672 256
charlesmn 0:3ac96e360672 257 i = lb % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 258 j = (lb + 1) % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 259
charlesmn 0:3ac96e360672 260
charlesmn 0:3ac96e360672 261
charlesmn 0:3ac96e360672 262 if (i < palgo->VL53L1_p_024 && j < palgo->VL53L1_p_024) {
charlesmn 0:3ac96e360672 263
charlesmn 0:3ac96e360672 264 if (palgo->VL53L1_p_046[i] == 0 &&
charlesmn 0:3ac96e360672 265 palgo->VL53L1_p_046[j] == 1)
charlesmn 0:3ac96e360672 266 palgo->VL53L1_p_051++;
charlesmn 0:3ac96e360672 267
charlesmn 0:3ac96e360672 268 if (palgo->VL53L1_p_046[i] > 0)
charlesmn 0:3ac96e360672 269 palgo->VL53L1_p_047[i] = palgo->VL53L1_p_051;
charlesmn 0:3ac96e360672 270 else
charlesmn 0:3ac96e360672 271 palgo->VL53L1_p_047[i] = 0;
charlesmn 0:3ac96e360672 272 }
charlesmn 0:3ac96e360672 273
charlesmn 0:3ac96e360672 274 }
charlesmn 0:3ac96e360672 275
charlesmn 0:3ac96e360672 276
charlesmn 0:3ac96e360672 277 if (palgo->VL53L1_p_051 > palgo->VL53L1_p_050)
charlesmn 0:3ac96e360672 278 palgo->VL53L1_p_051 = palgo->VL53L1_p_050;
charlesmn 0:3ac96e360672 279
charlesmn 0:3ac96e360672 280 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 281
charlesmn 0:3ac96e360672 282 return status;
charlesmn 0:3ac96e360672 283
charlesmn 0:3ac96e360672 284 }
charlesmn 0:3ac96e360672 285
charlesmn 0:3ac96e360672 286
charlesmn 0:3ac96e360672 287 VL53L1_Error VL53L1_f_021(
charlesmn 0:3ac96e360672 288 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 289 {
charlesmn 0:3ac96e360672 290
charlesmn 0:3ac96e360672 291
charlesmn 0:3ac96e360672 292
charlesmn 0:3ac96e360672 293 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 294
charlesmn 0:3ac96e360672 295 uint8_t i = 0;
charlesmn 0:3ac96e360672 296 uint8_t j = 0;
charlesmn 0:3ac96e360672 297 uint8_t blb = 0;
charlesmn 0:3ac96e360672 298 uint8_t pulse_no = 0;
charlesmn 0:3ac96e360672 299
charlesmn 0:3ac96e360672 300 uint8_t max_filter_half_width = 0;
charlesmn 0:3ac96e360672 301
charlesmn 0:3ac96e360672 302 VL53L1_hist_pulse_data_t *pdata;
charlesmn 0:3ac96e360672 303
charlesmn 0:3ac96e360672 304 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 305
charlesmn 0:3ac96e360672 306
charlesmn 0:3ac96e360672 307
charlesmn 0:3ac96e360672 308 max_filter_half_width = palgo->VL53L1_p_031 - 1;
charlesmn 0:3ac96e360672 309 max_filter_half_width = max_filter_half_width >> 1;
charlesmn 0:3ac96e360672 310
charlesmn 0:3ac96e360672 311 for (blb = palgo->VL53L1_p_049;
charlesmn 0:3ac96e360672 312 blb < (palgo->VL53L1_p_049 +
charlesmn 0:3ac96e360672 313 palgo->VL53L1_p_031);
charlesmn 0:3ac96e360672 314 blb++) {
charlesmn 0:3ac96e360672 315
charlesmn 0:3ac96e360672 316
charlesmn 0:3ac96e360672 317
charlesmn 0:3ac96e360672 318 i = blb % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 319 j = (blb + 1) % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 320
charlesmn 0:3ac96e360672 321
charlesmn 0:3ac96e360672 322
charlesmn 0:3ac96e360672 323 if (i < palgo->VL53L1_p_024 &&
charlesmn 0:3ac96e360672 324 j < palgo->VL53L1_p_024) {
charlesmn 0:3ac96e360672 325
charlesmn 0:3ac96e360672 326
charlesmn 0:3ac96e360672 327
charlesmn 0:3ac96e360672 328 if (palgo->VL53L1_p_047[i] == 0 &&
charlesmn 0:3ac96e360672 329 palgo->VL53L1_p_047[j] > 0) {
charlesmn 0:3ac96e360672 330
charlesmn 0:3ac96e360672 331 pulse_no = palgo->VL53L1_p_047[j] - 1;
charlesmn 0:3ac96e360672 332 pdata = &(palgo->VL53L1_p_002[pulse_no]);
charlesmn 0:3ac96e360672 333
charlesmn 0:3ac96e360672 334 if (pulse_no < palgo->VL53L1_p_050) {
charlesmn 0:3ac96e360672 335 pdata->VL53L1_p_015 = blb;
charlesmn 0:3ac96e360672 336 pdata->VL53L1_p_022 = blb + 1;
charlesmn 0:3ac96e360672 337 pdata->VL53L1_p_025 = 0xFF;
charlesmn 0:3ac96e360672 338 pdata->VL53L1_p_026 = 0;
charlesmn 0:3ac96e360672 339 pdata->VL53L1_p_016 = 0;
charlesmn 0:3ac96e360672 340 }
charlesmn 0:3ac96e360672 341 }
charlesmn 0:3ac96e360672 342
charlesmn 0:3ac96e360672 343
charlesmn 0:3ac96e360672 344
charlesmn 0:3ac96e360672 345 if (palgo->VL53L1_p_047[i] > 0
charlesmn 0:3ac96e360672 346 && palgo->VL53L1_p_047[j] == 0) {
charlesmn 0:3ac96e360672 347
charlesmn 0:3ac96e360672 348 pulse_no = palgo->VL53L1_p_047[i] - 1;
charlesmn 0:3ac96e360672 349 pdata = &(palgo->VL53L1_p_002[pulse_no]);
charlesmn 0:3ac96e360672 350
charlesmn 0:3ac96e360672 351 if (pulse_no < palgo->VL53L1_p_050) {
charlesmn 0:3ac96e360672 352
charlesmn 0:3ac96e360672 353 pdata->VL53L1_p_026 = blb;
charlesmn 0:3ac96e360672 354 pdata->VL53L1_p_016 = blb + 1;
charlesmn 0:3ac96e360672 355
charlesmn 0:3ac96e360672 356 pdata->VL53L1_p_027 =
charlesmn 0:3ac96e360672 357 (pdata->VL53L1_p_026 + 1) -
charlesmn 0:3ac96e360672 358 pdata->VL53L1_p_022;
charlesmn 0:3ac96e360672 359 pdata->VL53L1_p_055 =
charlesmn 0:3ac96e360672 360 (pdata->VL53L1_p_016 + 1) -
charlesmn 0:3ac96e360672 361 pdata->VL53L1_p_015;
charlesmn 0:3ac96e360672 362
charlesmn 0:3ac96e360672 363 if (pdata->VL53L1_p_055 >
charlesmn 0:3ac96e360672 364 max_filter_half_width)
charlesmn 0:3ac96e360672 365 pdata->VL53L1_p_055 =
charlesmn 0:3ac96e360672 366 max_filter_half_width;
charlesmn 0:3ac96e360672 367 }
charlesmn 0:3ac96e360672 368
charlesmn 0:3ac96e360672 369 }
charlesmn 0:3ac96e360672 370 }
charlesmn 0:3ac96e360672 371 }
charlesmn 0:3ac96e360672 372
charlesmn 0:3ac96e360672 373 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 374
charlesmn 0:3ac96e360672 375 return status;
charlesmn 0:3ac96e360672 376
charlesmn 0:3ac96e360672 377 }
charlesmn 0:3ac96e360672 378
charlesmn 0:3ac96e360672 379
charlesmn 0:3ac96e360672 380 VL53L1_Error VL53L1_f_028(
charlesmn 0:3ac96e360672 381 VL53L1_HistTargetOrder target_order,
charlesmn 0:3ac96e360672 382 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 383 {
charlesmn 0:3ac96e360672 384
charlesmn 0:3ac96e360672 385
charlesmn 0:3ac96e360672 386
charlesmn 0:3ac96e360672 387 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 388
charlesmn 0:3ac96e360672 389 VL53L1_hist_pulse_data_t tmp;
charlesmn 0:3ac96e360672 390 VL53L1_hist_pulse_data_t *ptmp = &tmp;
charlesmn 0:3ac96e360672 391 VL53L1_hist_pulse_data_t *p0;
charlesmn 0:3ac96e360672 392 VL53L1_hist_pulse_data_t *p1;
charlesmn 0:3ac96e360672 393
charlesmn 0:3ac96e360672 394 uint8_t i = 0;
charlesmn 0:3ac96e360672 395 uint8_t swapped = 1;
charlesmn 0:3ac96e360672 396
charlesmn 0:3ac96e360672 397 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 398
charlesmn 0:3ac96e360672 399 if (!(palgo->VL53L1_p_051 > 1))
charlesmn 0:3ac96e360672 400 goto ENDFUNC;
charlesmn 0:3ac96e360672 401
charlesmn 0:3ac96e360672 402 while (swapped > 0) {
charlesmn 0:3ac96e360672 403
charlesmn 0:3ac96e360672 404 swapped = 0;
charlesmn 0:3ac96e360672 405
charlesmn 0:3ac96e360672 406 for (i = 1; i < palgo->VL53L1_p_051; i++) {
charlesmn 0:3ac96e360672 407
charlesmn 0:3ac96e360672 408 p0 = &(palgo->VL53L1_p_002[i-1]);
charlesmn 0:3ac96e360672 409 p1 = &(palgo->VL53L1_p_002[i]);
charlesmn 0:3ac96e360672 410
charlesmn 0:3ac96e360672 411
charlesmn 0:3ac96e360672 412
charlesmn 0:3ac96e360672 413 if (target_order
charlesmn 0:3ac96e360672 414 == VL53L1_HIST_TARGET_ORDER__STRONGEST_FIRST) {
charlesmn 0:3ac96e360672 415
charlesmn 0:3ac96e360672 416 if (p0->VL53L1_p_013 <
charlesmn 0:3ac96e360672 417 p1->VL53L1_p_013) {
charlesmn 0:3ac96e360672 418
charlesmn 0:3ac96e360672 419
charlesmn 0:3ac96e360672 420
charlesmn 0:3ac96e360672 421 memcpy(ptmp,
charlesmn 0:3ac96e360672 422 p1, sizeof(VL53L1_hist_pulse_data_t));
charlesmn 0:3ac96e360672 423 memcpy(p1,
charlesmn 0:3ac96e360672 424 p0, sizeof(VL53L1_hist_pulse_data_t));
charlesmn 0:3ac96e360672 425 memcpy(p0,
charlesmn 0:3ac96e360672 426 ptmp, sizeof(VL53L1_hist_pulse_data_t));
charlesmn 0:3ac96e360672 427
charlesmn 0:3ac96e360672 428 swapped = 1;
charlesmn 0:3ac96e360672 429 }
charlesmn 0:3ac96e360672 430
charlesmn 0:3ac96e360672 431 } else {
charlesmn 0:3ac96e360672 432
charlesmn 0:3ac96e360672 433 if (p0->VL53L1_p_014 > p1->VL53L1_p_014) {
charlesmn 0:3ac96e360672 434
charlesmn 0:3ac96e360672 435
charlesmn 0:3ac96e360672 436
charlesmn 0:3ac96e360672 437 memcpy(ptmp,
charlesmn 0:3ac96e360672 438 p1, sizeof(VL53L1_hist_pulse_data_t));
charlesmn 0:3ac96e360672 439 memcpy(p1,
charlesmn 0:3ac96e360672 440 p0, sizeof(VL53L1_hist_pulse_data_t));
charlesmn 0:3ac96e360672 441 memcpy(p0,
charlesmn 0:3ac96e360672 442 ptmp, sizeof(VL53L1_hist_pulse_data_t));
charlesmn 0:3ac96e360672 443
charlesmn 0:3ac96e360672 444 swapped = 1;
charlesmn 0:3ac96e360672 445 }
charlesmn 0:3ac96e360672 446
charlesmn 0:3ac96e360672 447 }
charlesmn 0:3ac96e360672 448 }
charlesmn 0:3ac96e360672 449 }
charlesmn 0:3ac96e360672 450
charlesmn 0:3ac96e360672 451 ENDFUNC:
charlesmn 0:3ac96e360672 452 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 453
charlesmn 0:3ac96e360672 454 return status;
charlesmn 0:3ac96e360672 455
charlesmn 0:3ac96e360672 456 }
charlesmn 0:3ac96e360672 457
charlesmn 0:3ac96e360672 458
charlesmn 0:3ac96e360672 459 VL53L1_Error VL53L1_f_022(
charlesmn 0:3ac96e360672 460 uint8_t pulse_no,
charlesmn 0:3ac96e360672 461 VL53L1_histogram_bin_data_t *pbins,
charlesmn 0:3ac96e360672 462 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 463 {
charlesmn 0:3ac96e360672 464
charlesmn 0:3ac96e360672 465
charlesmn 0:3ac96e360672 466 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 467
charlesmn 0:3ac96e360672 468 uint8_t i = 0;
charlesmn 0:3ac96e360672 469 uint8_t lb = 0;
charlesmn 0:3ac96e360672 470
charlesmn 0:3ac96e360672 471 VL53L1_hist_pulse_data_t *pdata = &(palgo->VL53L1_p_002[pulse_no]);
charlesmn 0:3ac96e360672 472
charlesmn 0:3ac96e360672 473 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 474
charlesmn 0:3ac96e360672 475
charlesmn 0:3ac96e360672 476
charlesmn 0:3ac96e360672 477 pdata->VL53L1_p_021 = 0;
charlesmn 0:3ac96e360672 478 pdata->VL53L1_p_020 = 0;
charlesmn 0:3ac96e360672 479
charlesmn 0:3ac96e360672 480 for (lb = pdata->VL53L1_p_015; lb <= pdata->VL53L1_p_016; lb++) {
charlesmn 0:3ac96e360672 481 i = lb % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 482 pdata->VL53L1_p_021 += pbins->bin_data[i];
charlesmn 0:3ac96e360672 483 pdata->VL53L1_p_020 += palgo->VL53L1_p_004;
charlesmn 0:3ac96e360672 484 }
charlesmn 0:3ac96e360672 485
charlesmn 0:3ac96e360672 486
charlesmn 0:3ac96e360672 487
charlesmn 0:3ac96e360672 488 pdata->VL53L1_p_013 =
charlesmn 0:3ac96e360672 489 pdata->VL53L1_p_021 - pdata->VL53L1_p_020;
charlesmn 0:3ac96e360672 490
charlesmn 0:3ac96e360672 491 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 492
charlesmn 0:3ac96e360672 493 return status;
charlesmn 0:3ac96e360672 494 }
charlesmn 0:3ac96e360672 495
charlesmn 0:3ac96e360672 496
charlesmn 0:3ac96e360672 497 VL53L1_Error VL53L1_f_027(
charlesmn 0:3ac96e360672 498 uint8_t pulse_no,
charlesmn 0:3ac96e360672 499 uint8_t clip_events,
charlesmn 0:3ac96e360672 500 VL53L1_histogram_bin_data_t *pbins,
charlesmn 0:3ac96e360672 501 VL53L1_hist_gen3_algo_private_data_t *palgo)
charlesmn 0:3ac96e360672 502 {
charlesmn 0:3ac96e360672 503
charlesmn 0:3ac96e360672 504
charlesmn 0:3ac96e360672 505 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 506
charlesmn 0:3ac96e360672 507 uint8_t i = 0;
charlesmn 0:3ac96e360672 508 int16_t VL53L1_p_015 = 0;
charlesmn 0:3ac96e360672 509 int16_t VL53L1_p_016 = 0;
charlesmn 0:3ac96e360672 510 int16_t window_width = 0;
charlesmn 0:3ac96e360672 511 uint32_t tmp_phase = 0;
charlesmn 0:3ac96e360672 512
charlesmn 0:3ac96e360672 513 VL53L1_hist_pulse_data_t *pdata = &(palgo->VL53L1_p_002[pulse_no]);
charlesmn 0:3ac96e360672 514
charlesmn 0:3ac96e360672 515 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 516
charlesmn 0:3ac96e360672 517
charlesmn 0:3ac96e360672 518
charlesmn 0:3ac96e360672 519 i = pdata->VL53L1_p_025 % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 520
charlesmn 0:3ac96e360672 521 VL53L1_p_015 = (int16_t)i;
charlesmn 0:3ac96e360672 522 VL53L1_p_015 += (int16_t)pdata->VL53L1_p_015;
charlesmn 0:3ac96e360672 523 VL53L1_p_015 -= (int16_t)pdata->VL53L1_p_025;
charlesmn 0:3ac96e360672 524
charlesmn 0:3ac96e360672 525 VL53L1_p_016 = (int16_t)i;
charlesmn 0:3ac96e360672 526 VL53L1_p_016 += (int16_t)pdata->VL53L1_p_016;
charlesmn 0:3ac96e360672 527 VL53L1_p_016 -= (int16_t)pdata->VL53L1_p_025;
charlesmn 0:3ac96e360672 528
charlesmn 0:3ac96e360672 529
charlesmn 0:3ac96e360672 530 window_width = VL53L1_p_016 - VL53L1_p_015;
charlesmn 0:3ac96e360672 531 if (window_width > 3)
charlesmn 0:3ac96e360672 532 window_width = 3;
charlesmn 0:3ac96e360672 533
charlesmn 0:3ac96e360672 534 status =
charlesmn 0:3ac96e360672 535 VL53L1_f_030(
charlesmn 0:3ac96e360672 536 VL53L1_p_015,
charlesmn 0:3ac96e360672 537 VL53L1_p_015 + window_width,
charlesmn 0:3ac96e360672 538 palgo->VL53L1_p_031,
charlesmn 0:3ac96e360672 539 clip_events,
charlesmn 0:3ac96e360672 540 pbins,
charlesmn 0:3ac96e360672 541 &(pdata->VL53L1_p_028));
charlesmn 0:3ac96e360672 542
charlesmn 0:3ac96e360672 543
charlesmn 0:3ac96e360672 544 if (status == VL53L1_ERROR_NONE)
charlesmn 0:3ac96e360672 545 status =
charlesmn 0:3ac96e360672 546 VL53L1_f_030(
charlesmn 0:3ac96e360672 547 VL53L1_p_016 - window_width,
charlesmn 0:3ac96e360672 548 VL53L1_p_016,
charlesmn 0:3ac96e360672 549 palgo->VL53L1_p_031,
charlesmn 0:3ac96e360672 550 clip_events,
charlesmn 0:3ac96e360672 551 pbins,
charlesmn 0:3ac96e360672 552 &(pdata->VL53L1_p_029));
charlesmn 0:3ac96e360672 553
charlesmn 0:3ac96e360672 554
charlesmn 0:3ac96e360672 555 if (pdata->VL53L1_p_028 > pdata->VL53L1_p_029) {
charlesmn 0:3ac96e360672 556 tmp_phase = pdata->VL53L1_p_028;
charlesmn 0:3ac96e360672 557 pdata->VL53L1_p_028 = pdata->VL53L1_p_029;
charlesmn 0:3ac96e360672 558 pdata->VL53L1_p_029 = tmp_phase;
charlesmn 0:3ac96e360672 559 }
charlesmn 0:3ac96e360672 560
charlesmn 0:3ac96e360672 561
charlesmn 0:3ac96e360672 562 if (pdata->VL53L1_p_014 < pdata->VL53L1_p_028)
charlesmn 0:3ac96e360672 563 pdata->VL53L1_p_028 = pdata->VL53L1_p_014;
charlesmn 0:3ac96e360672 564
charlesmn 0:3ac96e360672 565
charlesmn 0:3ac96e360672 566 if (pdata->VL53L1_p_014 > pdata->VL53L1_p_029)
charlesmn 0:3ac96e360672 567 pdata->VL53L1_p_029 = pdata->VL53L1_p_014;
charlesmn 0:3ac96e360672 568
charlesmn 0:3ac96e360672 569 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 570
charlesmn 0:3ac96e360672 571 return status;
charlesmn 0:3ac96e360672 572 }
charlesmn 0:3ac96e360672 573
charlesmn 0:3ac96e360672 574
charlesmn 0:3ac96e360672 575 VL53L1_Error VL53L1_f_030(
charlesmn 0:3ac96e360672 576 int16_t VL53L1_p_022,
charlesmn 0:3ac96e360672 577 int16_t VL53L1_p_026,
charlesmn 0:3ac96e360672 578 uint8_t VL53L1_p_031,
charlesmn 0:3ac96e360672 579 uint8_t clip_events,
charlesmn 0:3ac96e360672 580 VL53L1_histogram_bin_data_t *pbins,
charlesmn 0:3ac96e360672 581 uint32_t *pphase)
charlesmn 0:3ac96e360672 582 {
charlesmn 0:3ac96e360672 583
charlesmn 0:3ac96e360672 584
charlesmn 0:3ac96e360672 585 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 586
charlesmn 0:3ac96e360672 587 int16_t i = 0;
charlesmn 0:3ac96e360672 588 int16_t lb = 0;
charlesmn 0:3ac96e360672 589
charlesmn 0:3ac96e360672 590 int64_t VL53L1_p_008 = 0;
charlesmn 0:3ac96e360672 591 int64_t event_sum = 0;
charlesmn 0:3ac96e360672 592 int64_t weighted_sum = 0;
charlesmn 0:3ac96e360672 593
charlesmn 0:3ac96e360672 594 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 595
charlesmn 0:3ac96e360672 596 *pphase = VL53L1_MAX_ALLOWED_PHASE;
charlesmn 0:3ac96e360672 597
charlesmn 0:3ac96e360672 598 for (lb = VL53L1_p_022; lb <= VL53L1_p_026; lb++) {
charlesmn 0:3ac96e360672 599
charlesmn 0:3ac96e360672 600
charlesmn 0:3ac96e360672 601 if (lb < 0)
charlesmn 0:3ac96e360672 602 i = lb + (int16_t)VL53L1_p_031;
charlesmn 0:3ac96e360672 603 else
charlesmn 0:3ac96e360672 604 i = lb % (int16_t)VL53L1_p_031;
charlesmn 0:3ac96e360672 605
charlesmn 0:3ac96e360672 606 VL53L1_p_008 =
charlesmn 0:3ac96e360672 607 (int64_t)pbins->bin_data[i] -
charlesmn 0:3ac96e360672 608 (int64_t)pbins->VL53L1_p_004;
charlesmn 0:3ac96e360672 609
charlesmn 0:3ac96e360672 610
charlesmn 0:3ac96e360672 611 if (clip_events > 0 && VL53L1_p_008 < 0)
charlesmn 0:3ac96e360672 612 VL53L1_p_008 = 0;
charlesmn 0:3ac96e360672 613
charlesmn 0:3ac96e360672 614 event_sum += VL53L1_p_008;
charlesmn 0:3ac96e360672 615
charlesmn 0:3ac96e360672 616 weighted_sum +=
charlesmn 0:3ac96e360672 617 (VL53L1_p_008 * (1024 + (2048*(int64_t)lb)));
charlesmn 0:3ac96e360672 618
charlesmn 0:3ac96e360672 619 trace_print(
charlesmn 0:3ac96e360672 620 VL53L1_TRACE_LEVEL_INFO,
charlesmn 0:3ac96e360672 621 "\tb = %5d : i = %5d : VL53L1_p_008 = %8d,",
charlesmn 0:3ac96e360672 622 lb, i, VL53L1_p_008);
charlesmn 0:3ac96e360672 623
charlesmn 0:3ac96e360672 624 trace_print(
charlesmn 0:3ac96e360672 625 VL53L1_TRACE_LEVEL_INFO,
charlesmn 0:3ac96e360672 626 " event_sum = %8d, weighted_sum = %8d\n",
charlesmn 0:3ac96e360672 627 event_sum, weighted_sum);
charlesmn 0:3ac96e360672 628 }
charlesmn 0:3ac96e360672 629
charlesmn 0:3ac96e360672 630 if (event_sum > 0) {
charlesmn 0:3ac96e360672 631
charlesmn 0:3ac96e360672 632 weighted_sum += do_division_s(event_sum, 2);
charlesmn 0:3ac96e360672 633 weighted_sum = do_division_s(weighted_sum, event_sum);
charlesmn 0:3ac96e360672 634
charlesmn 0:3ac96e360672 635 if (weighted_sum < 0)
charlesmn 0:3ac96e360672 636 weighted_sum = 0;
charlesmn 0:3ac96e360672 637
charlesmn 0:3ac96e360672 638 *pphase = (uint32_t)weighted_sum;
charlesmn 0:3ac96e360672 639 }
charlesmn 0:3ac96e360672 640
charlesmn 0:3ac96e360672 641 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 642
charlesmn 0:3ac96e360672 643 return status;
charlesmn 0:3ac96e360672 644 }
charlesmn 0:3ac96e360672 645
charlesmn 0:3ac96e360672 646
charlesmn 0:3ac96e360672 647 VL53L1_Error VL53L1_f_023(
charlesmn 0:3ac96e360672 648 uint8_t pulse_no,
charlesmn 0:3ac96e360672 649 VL53L1_histogram_bin_data_t *pbins,
charlesmn 0:3ac96e360672 650 VL53L1_hist_gen3_algo_private_data_t *palgo,
charlesmn 0:3ac96e360672 651 int32_t pad_value,
charlesmn 0:3ac96e360672 652 VL53L1_histogram_bin_data_t *ppulse)
charlesmn 0:3ac96e360672 653 {
charlesmn 0:3ac96e360672 654
charlesmn 0:3ac96e360672 655
charlesmn 0:3ac96e360672 656
charlesmn 0:3ac96e360672 657 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 658
charlesmn 0:3ac96e360672 659 uint8_t i = 0;
charlesmn 0:3ac96e360672 660 uint8_t lb = 0;
charlesmn 0:3ac96e360672 661
charlesmn 0:3ac96e360672 662 VL53L1_hist_pulse_data_t *pdata = &(palgo->VL53L1_p_002[pulse_no]);
charlesmn 0:3ac96e360672 663
charlesmn 0:3ac96e360672 664 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 665
charlesmn 0:3ac96e360672 666
charlesmn 0:3ac96e360672 667
charlesmn 0:3ac96e360672 668 memcpy(ppulse, pbins, sizeof(VL53L1_histogram_bin_data_t));
charlesmn 0:3ac96e360672 669
charlesmn 0:3ac96e360672 670
charlesmn 0:3ac96e360672 671
charlesmn 0:3ac96e360672 672 for (lb = palgo->VL53L1_p_049;
charlesmn 0:3ac96e360672 673 lb < (palgo->VL53L1_p_049 +
charlesmn 0:3ac96e360672 674 palgo->VL53L1_p_031);
charlesmn 0:3ac96e360672 675 lb++) {
charlesmn 0:3ac96e360672 676
charlesmn 0:3ac96e360672 677 if (lb < pdata->VL53L1_p_015 || lb > pdata->VL53L1_p_016) {
charlesmn 0:3ac96e360672 678 i = lb % palgo->VL53L1_p_031;
charlesmn 0:3ac96e360672 679 if (i < ppulse->VL53L1_p_024)
charlesmn 0:3ac96e360672 680 ppulse->bin_data[i] = pad_value;
charlesmn 0:3ac96e360672 681 }
charlesmn 0:3ac96e360672 682 }
charlesmn 0:3ac96e360672 683
charlesmn 0:3ac96e360672 684 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 685
charlesmn 0:3ac96e360672 686 return status;
charlesmn 0:3ac96e360672 687 }
charlesmn 0:3ac96e360672 688
charlesmn 0:3ac96e360672 689
charlesmn 0:3ac96e360672 690 VL53L1_Error VL53L1_f_026(
charlesmn 0:3ac96e360672 691 uint8_t bin,
charlesmn 0:3ac96e360672 692 uint8_t sigma_estimator__sigma_ref_mm,
charlesmn 0:3ac96e360672 693 uint8_t VL53L1_p_031,
charlesmn 0:3ac96e360672 694 uint8_t VL53L1_p_055,
charlesmn 0:3ac96e360672 695 uint8_t crosstalk_compensation_enable,
charlesmn 0:3ac96e360672 696 VL53L1_histogram_bin_data_t *phist_data_ap,
charlesmn 0:3ac96e360672 697 VL53L1_histogram_bin_data_t *phist_data_zp,
charlesmn 0:3ac96e360672 698 VL53L1_histogram_bin_data_t *pxtalk_hist,
charlesmn 0:3ac96e360672 699 uint16_t *psigma_est)
charlesmn 0:3ac96e360672 700 {
charlesmn 0:3ac96e360672 701
charlesmn 0:3ac96e360672 702
charlesmn 0:3ac96e360672 703 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 704 VL53L1_Error func_status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 705
charlesmn 0:3ac96e360672 706 uint8_t i = 0;
charlesmn 0:3ac96e360672 707 int32_t VL53L1_p_003 = 0;
charlesmn 0:3ac96e360672 708 int32_t VL53L1_p_018 = 0;
charlesmn 0:3ac96e360672 709 int32_t VL53L1_p_001 = 0;
charlesmn 0:3ac96e360672 710 int32_t a_zp = 0;
charlesmn 0:3ac96e360672 711 int32_t c_zp = 0;
charlesmn 0:3ac96e360672 712 int32_t ax = 0;
charlesmn 0:3ac96e360672 713 int32_t bx = 0;
charlesmn 0:3ac96e360672 714 int32_t cx = 0;
charlesmn 0:3ac96e360672 715
charlesmn 0:3ac96e360672 716
charlesmn 0:3ac96e360672 717
charlesmn 0:3ac96e360672 718 i = bin % VL53L1_p_031;
charlesmn 0:3ac96e360672 719
charlesmn 0:3ac96e360672 720
charlesmn 0:3ac96e360672 721
charlesmn 0:3ac96e360672 722 VL53L1_f_013(
charlesmn 0:3ac96e360672 723 i,
charlesmn 0:3ac96e360672 724 VL53L1_p_055,
charlesmn 0:3ac96e360672 725 phist_data_zp,
charlesmn 0:3ac96e360672 726 &a_zp,
charlesmn 0:3ac96e360672 727 &VL53L1_p_018,
charlesmn 0:3ac96e360672 728 &c_zp);
charlesmn 0:3ac96e360672 729
charlesmn 0:3ac96e360672 730
charlesmn 0:3ac96e360672 731
charlesmn 0:3ac96e360672 732 VL53L1_f_013(
charlesmn 0:3ac96e360672 733 i,
charlesmn 0:3ac96e360672 734 VL53L1_p_055,
charlesmn 0:3ac96e360672 735 phist_data_ap,
charlesmn 0:3ac96e360672 736 &VL53L1_p_003,
charlesmn 0:3ac96e360672 737 &VL53L1_p_018,
charlesmn 0:3ac96e360672 738 &VL53L1_p_001);
charlesmn 0:3ac96e360672 739
charlesmn 0:3ac96e360672 740 if (crosstalk_compensation_enable > 0)
charlesmn 0:3ac96e360672 741 VL53L1_f_013(
charlesmn 0:3ac96e360672 742 i,
charlesmn 0:3ac96e360672 743 VL53L1_p_055,
charlesmn 0:3ac96e360672 744 pxtalk_hist,
charlesmn 0:3ac96e360672 745 &ax,
charlesmn 0:3ac96e360672 746 &bx,
charlesmn 0:3ac96e360672 747 &cx);
charlesmn 0:3ac96e360672 748
charlesmn 0:3ac96e360672 749
charlesmn 0:3ac96e360672 750
charlesmn 0:3ac96e360672 751
charlesmn 0:3ac96e360672 752
charlesmn 0:3ac96e360672 753
charlesmn 0:3ac96e360672 754
charlesmn 0:3ac96e360672 755 func_status =
charlesmn 0:3ac96e360672 756 VL53L1_f_014(
charlesmn 0:3ac96e360672 757 sigma_estimator__sigma_ref_mm,
charlesmn 0:3ac96e360672 758 (uint32_t)VL53L1_p_003,
charlesmn 0:3ac96e360672 759 (uint32_t)VL53L1_p_018,
charlesmn 0:3ac96e360672 760 (uint32_t)VL53L1_p_001,
charlesmn 0:3ac96e360672 761 (uint32_t)a_zp,
charlesmn 0:3ac96e360672 762 (uint32_t)c_zp,
charlesmn 0:3ac96e360672 763 (uint32_t)bx,
charlesmn 0:3ac96e360672 764 (uint32_t)ax,
charlesmn 0:3ac96e360672 765 (uint32_t)cx,
charlesmn 0:3ac96e360672 766 (uint32_t)phist_data_ap->VL53L1_p_004,
charlesmn 0:3ac96e360672 767 phist_data_ap->VL53L1_p_019,
charlesmn 0:3ac96e360672 768 psigma_est);
charlesmn 0:3ac96e360672 769
charlesmn 0:3ac96e360672 770
charlesmn 0:3ac96e360672 771
charlesmn 0:3ac96e360672 772
charlesmn 0:3ac96e360672 773 if (func_status == VL53L1_ERROR_DIVISION_BY_ZERO)
charlesmn 0:3ac96e360672 774 *psigma_est = 0xFFFF;
charlesmn 0:3ac96e360672 775
charlesmn 0:3ac96e360672 776
charlesmn 0:3ac96e360672 777 return status;
charlesmn 0:3ac96e360672 778 }
charlesmn 0:3ac96e360672 779
charlesmn 0:3ac96e360672 780
charlesmn 0:3ac96e360672 781 void VL53L1_f_029(
charlesmn 0:3ac96e360672 782 uint8_t range_id,
charlesmn 0:3ac96e360672 783 uint8_t valid_phase_low,
charlesmn 0:3ac96e360672 784 uint8_t valid_phase_high,
charlesmn 0:3ac96e360672 785 uint16_t sigma_thres,
charlesmn 0:3ac96e360672 786 VL53L1_histogram_bin_data_t *pbins,
charlesmn 0:3ac96e360672 787 VL53L1_hist_pulse_data_t *ppulse,
charlesmn 0:3ac96e360672 788 VL53L1_range_data_t *pdata)
charlesmn 0:3ac96e360672 789 {
charlesmn 0:3ac96e360672 790
charlesmn 0:3ac96e360672 791 uint16_t lower_phase_limit = 0;
charlesmn 0:3ac96e360672 792 uint16_t upper_phase_limit = 0;
charlesmn 0:3ac96e360672 793
charlesmn 0:3ac96e360672 794
charlesmn 0:3ac96e360672 795
charlesmn 0:3ac96e360672 796 pdata->range_id = range_id;
charlesmn 0:3ac96e360672 797 pdata->time_stamp = 0;
charlesmn 0:3ac96e360672 798
charlesmn 0:3ac96e360672 799 pdata->VL53L1_p_015 = ppulse->VL53L1_p_015;
charlesmn 0:3ac96e360672 800 pdata->VL53L1_p_022 = ppulse->VL53L1_p_022;
charlesmn 0:3ac96e360672 801 pdata->VL53L1_p_025 = ppulse->VL53L1_p_025;
charlesmn 0:3ac96e360672 802 pdata->VL53L1_p_026 = ppulse->VL53L1_p_026;
charlesmn 0:3ac96e360672 803 pdata->VL53L1_p_016 = ppulse->VL53L1_p_016;
charlesmn 0:3ac96e360672 804 pdata->VL53L1_p_027 = ppulse->VL53L1_p_027;
charlesmn 0:3ac96e360672 805
charlesmn 0:3ac96e360672 806
charlesmn 0:3ac96e360672 807
charlesmn 0:3ac96e360672 808 pdata->VL53L1_p_030 =
charlesmn 0:3ac96e360672 809 (ppulse->VL53L1_p_016 + 1) - ppulse->VL53L1_p_015;
charlesmn 0:3ac96e360672 810
charlesmn 0:3ac96e360672 811
charlesmn 0:3ac96e360672 812
charlesmn 0:3ac96e360672 813 pdata->zero_distance_phase = pbins->zero_distance_phase;
charlesmn 0:3ac96e360672 814 pdata->VL53L1_p_005 = ppulse->VL53L1_p_005;
charlesmn 0:3ac96e360672 815 pdata->VL53L1_p_028 = (uint16_t)ppulse->VL53L1_p_028;
charlesmn 0:3ac96e360672 816 pdata->VL53L1_p_014 = (uint16_t)ppulse->VL53L1_p_014;
charlesmn 0:3ac96e360672 817 pdata->VL53L1_p_029 = (uint16_t)ppulse->VL53L1_p_029;
charlesmn 0:3ac96e360672 818 pdata->VL53L1_p_021 = (uint32_t)ppulse->VL53L1_p_021;
charlesmn 0:3ac96e360672 819 pdata->VL53L1_p_013 = ppulse->VL53L1_p_013;
charlesmn 0:3ac96e360672 820 pdata->VL53L1_p_020 = (uint32_t)ppulse->VL53L1_p_020;
charlesmn 0:3ac96e360672 821 pdata->total_periods_elapsed = pbins->total_periods_elapsed;
charlesmn 0:3ac96e360672 822
charlesmn 0:3ac96e360672 823
charlesmn 0:3ac96e360672 824
charlesmn 0:3ac96e360672 825 pdata->range_status = VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK;
charlesmn 0:3ac96e360672 826
charlesmn 0:3ac96e360672 827
charlesmn 0:3ac96e360672 828 if (sigma_thres > 0 &&
charlesmn 0:3ac96e360672 829 (uint32_t)ppulse->VL53L1_p_005 > ((uint32_t)sigma_thres << 5))
charlesmn 0:3ac96e360672 830 pdata->range_status = VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK;
charlesmn 0:3ac96e360672 831
charlesmn 0:3ac96e360672 832
charlesmn 0:3ac96e360672 833
charlesmn 0:3ac96e360672 834 lower_phase_limit = (uint8_t)valid_phase_low << 8;
charlesmn 0:3ac96e360672 835 if (lower_phase_limit < pdata->zero_distance_phase)
charlesmn 0:3ac96e360672 836 lower_phase_limit =
charlesmn 0:3ac96e360672 837 pdata->zero_distance_phase -
charlesmn 0:3ac96e360672 838 lower_phase_limit;
charlesmn 0:3ac96e360672 839 else
charlesmn 0:3ac96e360672 840 lower_phase_limit = 0;
charlesmn 0:3ac96e360672 841
charlesmn 0:3ac96e360672 842 upper_phase_limit = (uint8_t)valid_phase_high << 8;
charlesmn 0:3ac96e360672 843 upper_phase_limit += pbins->zero_distance_phase;
charlesmn 0:3ac96e360672 844
charlesmn 0:3ac96e360672 845 if (pdata->VL53L1_p_014 < lower_phase_limit ||
charlesmn 0:3ac96e360672 846 pdata->VL53L1_p_014 > upper_phase_limit)
charlesmn 0:3ac96e360672 847 pdata->range_status = VL53L1_DEVICEERROR_RANGEPHASECHECK;
charlesmn 0:3ac96e360672 848
charlesmn 0:3ac96e360672 849 }
charlesmn 0:3ac96e360672 850
charlesmn 0:3ac96e360672 851
charlesmn 0:3ac96e360672 852