77 #include "vl53l1_debug.h"
78 #include "vl53l1_register_debug.h"
81 #define LOG_FUNCTION_START(fmt, ...) \
82 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
83 #define LOG_FUNCTION_END(status, ...) \
84 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
85 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
86 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, \
87 status, fmt, ##__VA_ARGS__)
89 #define trace_print(level, ...) \
90 _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_CORE, \
91 level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__)
114 pll_period_us = (0x01 << 30) / fast_osc_frequency;
116 #ifdef VL53L1_LOGGING
118 " %-48s : %10u\n",
"pll_period_us",
124 return pll_period_us;
151 duration_us = window_vclks * pll_period_us;
156 duration_us = duration_us >> 12;
159 tmp_long_int = (
uint64_t)duration_us;
165 duration_us = elapsed_mclks * vcsel_parm_pclks;
170 duration_us = duration_us >> 4;
175 tmp_long_int = tmp_long_int * (
uint64_t)duration_us;
180 tmp_long_int = tmp_long_int >> 12;
183 if (tmp_long_int > 0xFFFFFFFF) {
184 tmp_long_int = 0xFFFFFFFF;
187 duration_us = (
uint32_t)tmp_long_int;
211 if (num >= res + bit) {
213 res = (res >> 1) + bit;
249 }
else if (events > 0) {
270 tmp_int = ((tmp_int << frac_bits) + (time_us / 2)) / time_us;
277 tmp_int = tmp_int << 4;
285 if (tmp_int > 0xFFFF) {
294 uint16_t VL53L1_rate_per_spad_maths(
313 tmp_int = (peak_count_rate << 8) << frac_bits;
316 tmp_int = ((peak_count_rate) << frac_bits);
321 if (tmp_int > max_output_value) {
322 tmp_int = max_output_value;
327 return rate_per_spad;
343 int64_t tmp_long_int = 0;
358 tmp_long_int = (int64_t)phase - (int64_t)zero_distance_phase;
368 tmp_long_int = tmp_long_int * (int64_t)pll_period_us;
374 tmp_long_int = tmp_long_int / (0x01 << 9);
391 tmp_long_int = tmp_long_int / (0x01 << 22);
394 range_mm = (
int32_t)tmp_long_int + range_offset_mm;
397 range_mm *= gain_factor;
402 if (fractional_bits == 0)
403 range_mm = range_mm / (0x01 << 2);
404 else if (fractional_bits == 1)
405 range_mm = range_mm / (0x01 << 1);
418 uint8_t vcsel_period_pclks = 0;
420 vcsel_period_pclks = (vcsel_period_reg + 1) << 1;
422 return vcsel_period_pclks;
437 if (spad_number > 127) {
438 *prow = 8 + ((255-spad_number) & 0x07);
439 *pcol = (spad_number-128) >> 3;
441 *prow = spad_number & 0x07;
442 *pcol = (127-spad_number) >> 3;