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_dmax.c@18:0696efe39d08, 2021-07-21 (annotated)
- Committer:
- lugandc
- Date:
- Wed Jul 21 17:06:38 2021 +0200
- Revision:
- 18:0696efe39d08
- Parent:
- 7:1add29d51e72
Cleanup i2c functions, removed all bad references to L1X
Cleanup VL53L1CB class:
- i2c device object is passed in a consistent way in MyDevice structure
- removed useless functions
Updated VL53L1CB component driver with bare driver release 6.6.7 content
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: BSD-3-Clause |
Charles MacNeill |
7:1add29d51e72 | 3 | /****************************************************************************** |
Charles MacNeill |
7:1add29d51e72 | 4 | * Copyright (c) 2020, STMicroelectronics - All Rights Reserved |
charlesmn | 0:3ac96e360672 | 5 | |
Charles MacNeill |
7:1add29d51e72 | 6 | This file is part of VL53L1 Protected and is dual licensed, |
Charles MacNeill |
7:1add29d51e72 | 7 | either 'STMicroelectronics Proprietary license' |
Charles MacNeill |
7:1add29d51e72 | 8 | or 'BSD 3-clause "New" or "Revised" License' , at your option. |
Charles MacNeill |
7:1add29d51e72 | 9 | |
Charles MacNeill |
7:1add29d51e72 | 10 | ****************************************************************************** |
Charles MacNeill |
7:1add29d51e72 | 11 | |
Charles MacNeill |
7:1add29d51e72 | 12 | 'STMicroelectronics Proprietary license' |
Charles MacNeill |
7:1add29d51e72 | 13 | |
Charles MacNeill |
7:1add29d51e72 | 14 | ****************************************************************************** |
charlesmn | 0:3ac96e360672 | 15 | |
charlesmn | 0:3ac96e360672 | 16 | License terms: STMicroelectronics Proprietary in accordance with licensing |
charlesmn | 0:3ac96e360672 | 17 | terms at www.st.com/sla0081 |
charlesmn | 0:3ac96e360672 | 18 | |
Charles MacNeill |
7:1add29d51e72 | 19 | ****************************************************************************** |
Charles MacNeill |
7:1add29d51e72 | 20 | */ |
charlesmn | 0:3ac96e360672 | 21 | |
charlesmn | 0:3ac96e360672 | 22 | |
charlesmn | 0:3ac96e360672 | 23 | |
charlesmn | 0:3ac96e360672 | 24 | |
charlesmn | 0:3ac96e360672 | 25 | #include "vl53l1_types.h" |
charlesmn | 0:3ac96e360672 | 26 | #include "vl53l1_platform_log.h" |
charlesmn | 0:3ac96e360672 | 27 | #include "vl53l1_platform_user_defines.h" |
charlesmn | 0:3ac96e360672 | 28 | #include "vl53l1_core_support.h" |
charlesmn | 0:3ac96e360672 | 29 | #include "vl53l1_error_codes.h" |
charlesmn | 0:3ac96e360672 | 30 | |
charlesmn | 0:3ac96e360672 | 31 | #include "vl53l1_dmax.h" |
charlesmn | 0:3ac96e360672 | 32 | |
charlesmn | 0:3ac96e360672 | 33 | |
charlesmn | 0:3ac96e360672 | 34 | #define LOG_FUNCTION_START(fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 35 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_PROTECTED, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 36 | #define LOG_FUNCTION_END(status, ...) \ |
charlesmn | 0:3ac96e360672 | 37 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_PROTECTED, status, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 38 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 39 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_PROTECTED, \ |
charlesmn | 0:3ac96e360672 | 40 | status, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 41 | |
charlesmn | 0:3ac96e360672 | 42 | #define trace_print(level, ...) \ |
charlesmn | 0:3ac96e360672 | 43 | _LOG_TRACE_PRINT(VL53L1_TRACE_MODULE_PROTECTED, \ |
charlesmn | 0:3ac96e360672 | 44 | level, VL53L1_TRACE_FUNCTION_NONE, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 45 | |
charlesmn | 0:3ac96e360672 | 46 | |
charlesmn | 0:3ac96e360672 | 47 | VL53L1_Error VL53L1_f_001( |
charlesmn | 0:3ac96e360672 | 48 | uint16_t target_reflectance, |
charlesmn | 0:3ac96e360672 | 49 | VL53L1_dmax_calibration_data_t *pcal, |
charlesmn | 0:3ac96e360672 | 50 | VL53L1_hist_gen3_dmax_config_t *pcfg, |
charlesmn | 0:3ac96e360672 | 51 | VL53L1_histogram_bin_data_t *pbins, |
charlesmn | 0:3ac96e360672 | 52 | VL53L1_hist_gen3_dmax_private_data_t *pdata, |
charlesmn | 0:3ac96e360672 | 53 | int16_t *pambient_dmax_mm) |
charlesmn | 0:3ac96e360672 | 54 | { |
charlesmn | 0:3ac96e360672 | 55 | |
charlesmn | 0:3ac96e360672 | 56 | |
charlesmn | 0:3ac96e360672 | 57 | |
charlesmn | 0:3ac96e360672 | 58 | VL53L1_Error status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 59 | |
charlesmn | 0:3ac96e360672 | 60 | uint32_t pll_period_us = 0; |
charlesmn | 0:3ac96e360672 | 61 | uint32_t periods_elapsed = 0; |
charlesmn | 0:3ac96e360672 | 62 | |
charlesmn | 0:3ac96e360672 | 63 | uint32_t tmp32 = 0; |
charlesmn | 0:3ac96e360672 | 64 | uint64_t tmp64 = 0; |
charlesmn | 0:3ac96e360672 | 65 | |
charlesmn | 0:3ac96e360672 | 66 | uint32_t amb_thres_delta = 0; |
charlesmn | 0:3ac96e360672 | 67 | |
charlesmn | 0:3ac96e360672 | 68 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 69 | |
charlesmn | 0:3ac96e360672 | 70 | |
charlesmn | 0:3ac96e360672 | 71 | |
charlesmn | 0:3ac96e360672 | 72 | pdata->VL53L1_p_006 = 0x0000; |
charlesmn | 0:3ac96e360672 | 73 | pdata->VL53L1_p_033 = 0x0000; |
charlesmn | 0:3ac96e360672 | 74 | pdata->VL53L1_p_001 = 0x0000; |
charlesmn | 0:3ac96e360672 | 75 | pdata->VL53L1_p_012 = 0x0000; |
charlesmn | 0:3ac96e360672 | 76 | pdata->VL53L1_p_004 = 0x0000; |
charlesmn | 0:3ac96e360672 | 77 | pdata->VL53L1_p_034 = 0x0000; |
charlesmn | 0:3ac96e360672 | 78 | pdata->VL53L1_p_035 = 0; |
charlesmn | 0:3ac96e360672 | 79 | pdata->VL53L1_p_007 = 0; |
charlesmn | 0:3ac96e360672 | 80 | |
charlesmn | 0:3ac96e360672 | 81 | *pambient_dmax_mm = 0; |
charlesmn | 0:3ac96e360672 | 82 | |
charlesmn | 0:3ac96e360672 | 83 | |
charlesmn | 0:3ac96e360672 | 84 | if ((pbins->VL53L1_p_019 != 0) && |
charlesmn | 0:3ac96e360672 | 85 | (pbins->total_periods_elapsed != 0)) { |
charlesmn | 0:3ac96e360672 | 86 | |
charlesmn | 0:3ac96e360672 | 87 | |
charlesmn | 0:3ac96e360672 | 88 | |
charlesmn | 0:3ac96e360672 | 89 | pll_period_us = |
charlesmn | 0:3ac96e360672 | 90 | VL53L1_calc_pll_period_us(pbins->VL53L1_p_019); |
charlesmn | 0:3ac96e360672 | 91 | |
charlesmn | 0:3ac96e360672 | 92 | |
charlesmn | 0:3ac96e360672 | 93 | |
charlesmn | 0:3ac96e360672 | 94 | periods_elapsed = pbins->total_periods_elapsed + 1; |
charlesmn | 0:3ac96e360672 | 95 | |
charlesmn | 0:3ac96e360672 | 96 | |
charlesmn | 0:3ac96e360672 | 97 | |
charlesmn | 0:3ac96e360672 | 98 | pdata->VL53L1_p_036 = |
charlesmn | 0:3ac96e360672 | 99 | VL53L1_duration_maths( |
charlesmn | 0:3ac96e360672 | 100 | pll_period_us, |
charlesmn | 0:3ac96e360672 | 101 | 1<<4, |
charlesmn | 0:3ac96e360672 | 102 | VL53L1_RANGING_WINDOW_VCSEL_PERIODS, |
charlesmn | 0:3ac96e360672 | 103 | periods_elapsed); |
charlesmn | 0:3ac96e360672 | 104 | |
charlesmn | 0:3ac96e360672 | 105 | |
charlesmn | 0:3ac96e360672 | 106 | pdata->VL53L1_p_001 = |
charlesmn | 0:3ac96e360672 | 107 | VL53L1_rate_maths( |
charlesmn | 0:3ac96e360672 | 108 | pbins->VL53L1_p_004, |
charlesmn | 0:3ac96e360672 | 109 | pdata->VL53L1_p_036); |
charlesmn | 0:3ac96e360672 | 110 | |
charlesmn | 0:3ac96e360672 | 111 | |
charlesmn | 0:3ac96e360672 | 112 | |
charlesmn | 0:3ac96e360672 | 113 | pdata->VL53L1_p_033 = |
charlesmn | 0:3ac96e360672 | 114 | VL53L1_events_per_spad_maths( |
charlesmn | 0:3ac96e360672 | 115 | pbins->VL53L1_p_004, |
charlesmn | 0:3ac96e360672 | 116 | pbins->result__dss_actual_effective_spads, |
charlesmn | 0:3ac96e360672 | 117 | pdata->VL53L1_p_036); |
charlesmn | 0:3ac96e360672 | 118 | |
charlesmn | 0:3ac96e360672 | 119 | |
charlesmn | 0:3ac96e360672 | 120 | |
charlesmn | 0:3ac96e360672 | 121 | pdata->VL53L1_p_037 = pcfg->max_effective_spads; |
charlesmn | 0:3ac96e360672 | 122 | pdata->VL53L1_p_006 = pcfg->max_effective_spads; |
charlesmn | 0:3ac96e360672 | 123 | |
charlesmn | 0:3ac96e360672 | 124 | if (pdata->VL53L1_p_033 > 0) { |
charlesmn | 0:3ac96e360672 | 125 | tmp64 = |
charlesmn | 0:3ac96e360672 | 126 | (uint64_t)pcfg->dss_config__target_total_rate_mcps; |
charlesmn | 0:3ac96e360672 | 127 | tmp64 *= 1000; |
charlesmn | 0:3ac96e360672 | 128 | tmp64 <<= (11+1); |
charlesmn | 0:3ac96e360672 | 129 | tmp32 = pdata->VL53L1_p_033/2; |
charlesmn | 0:3ac96e360672 | 130 | tmp64 += (uint64_t)tmp32; |
charlesmn | 0:3ac96e360672 | 131 | tmp64 = do_division_u(tmp64, |
charlesmn | 0:3ac96e360672 | 132 | (uint64_t)pdata->VL53L1_p_033); |
charlesmn | 0:3ac96e360672 | 133 | |
charlesmn | 0:3ac96e360672 | 134 | if (tmp64 < (uint64_t)pcfg->max_effective_spads) |
charlesmn | 0:3ac96e360672 | 135 | pdata->VL53L1_p_006 = (uint16_t)tmp64; |
charlesmn | 0:3ac96e360672 | 136 | } |
charlesmn | 0:3ac96e360672 | 137 | } |
charlesmn | 0:3ac96e360672 | 138 | |
charlesmn | 0:3ac96e360672 | 139 | |
charlesmn | 0:3ac96e360672 | 140 | |
charlesmn | 0:3ac96e360672 | 141 | if ((pcal->ref__actual_effective_spads != 0) && |
charlesmn | 0:3ac96e360672 | 142 | (pbins->VL53L1_p_019 != 0) && |
charlesmn | 0:3ac96e360672 | 143 | (pcal->ref_reflectance_pc != 0) && |
charlesmn | 0:3ac96e360672 | 144 | (pbins->total_periods_elapsed != 0)) { |
charlesmn | 0:3ac96e360672 | 145 | |
charlesmn | 0:3ac96e360672 | 146 | |
charlesmn | 0:3ac96e360672 | 147 | |
charlesmn | 0:3ac96e360672 | 148 | tmp64 = (uint64_t)pcal->ref__peak_signal_count_rate_mcps; |
charlesmn | 0:3ac96e360672 | 149 | tmp64 *= (1000 * 256); |
charlesmn | 0:3ac96e360672 | 150 | tmp32 = pcal->ref__actual_effective_spads/2; |
charlesmn | 0:3ac96e360672 | 151 | tmp64 += (uint64_t)tmp32; |
charlesmn | 0:3ac96e360672 | 152 | tmp64 = do_division_u(tmp64, |
charlesmn | 0:3ac96e360672 | 153 | (uint64_t)pcal->ref__actual_effective_spads); |
charlesmn | 0:3ac96e360672 | 154 | |
charlesmn | 0:3ac96e360672 | 155 | pdata->VL53L1_p_012 = (uint32_t)tmp64; |
charlesmn | 0:3ac96e360672 | 156 | pdata->VL53L1_p_012 <<= 4; |
charlesmn | 0:3ac96e360672 | 157 | |
charlesmn | 0:3ac96e360672 | 158 | |
charlesmn | 0:3ac96e360672 | 159 | |
charlesmn | 0:3ac96e360672 | 160 | tmp64 = (uint64_t)pdata->VL53L1_p_036; |
charlesmn | 0:3ac96e360672 | 161 | tmp64 *= (uint64_t)pdata->VL53L1_p_033; |
charlesmn | 0:3ac96e360672 | 162 | tmp64 *= (uint64_t)pdata->VL53L1_p_006; |
charlesmn | 0:3ac96e360672 | 163 | tmp64 += (1<<(11+7)); |
charlesmn | 0:3ac96e360672 | 164 | tmp64 >>= (11+8); |
charlesmn | 0:3ac96e360672 | 165 | tmp64 += 500; |
charlesmn | 0:3ac96e360672 | 166 | tmp64 = do_division_u(tmp64, 1000); |
charlesmn | 0:3ac96e360672 | 167 | |
charlesmn | 0:3ac96e360672 | 168 | |
charlesmn | 0:3ac96e360672 | 169 | if (tmp64 > 0x00FFFFFF) |
charlesmn | 0:3ac96e360672 | 170 | tmp64 = 0x00FFFFFF; |
charlesmn | 0:3ac96e360672 | 171 | |
charlesmn | 0:3ac96e360672 | 172 | pdata->VL53L1_p_004 = (uint32_t)tmp64; |
charlesmn | 0:3ac96e360672 | 173 | |
charlesmn | 0:3ac96e360672 | 174 | |
charlesmn | 0:3ac96e360672 | 175 | |
charlesmn | 0:3ac96e360672 | 176 | tmp64 = (uint64_t)pdata->VL53L1_p_036; |
charlesmn | 0:3ac96e360672 | 177 | tmp64 *= (uint64_t)pdata->VL53L1_p_012; |
charlesmn | 0:3ac96e360672 | 178 | tmp64 *= (uint64_t)pdata->VL53L1_p_006; |
charlesmn | 0:3ac96e360672 | 179 | tmp64 += (1<<(11+7)); |
charlesmn | 0:3ac96e360672 | 180 | tmp64 >>= (11+8); |
charlesmn | 0:3ac96e360672 | 181 | |
charlesmn | 0:3ac96e360672 | 182 | |
charlesmn | 0:3ac96e360672 | 183 | |
charlesmn | 0:3ac96e360672 | 184 | tmp64 *= ((uint64_t)target_reflectance * |
charlesmn | 0:3ac96e360672 | 185 | (uint64_t)pcal->coverglass_transmission); |
charlesmn | 0:3ac96e360672 | 186 | |
charlesmn | 0:3ac96e360672 | 187 | tmp64 += ((uint64_t)pcal->ref_reflectance_pc * 128); |
charlesmn | 0:3ac96e360672 | 188 | tmp64 = do_division_u(tmp64, |
charlesmn | 0:3ac96e360672 | 189 | ((uint64_t)pcal->ref_reflectance_pc * 256)); |
charlesmn | 0:3ac96e360672 | 190 | |
charlesmn | 0:3ac96e360672 | 191 | tmp64 += 500; |
charlesmn | 0:3ac96e360672 | 192 | tmp64 = do_division_u(tmp64, 1000); |
charlesmn | 0:3ac96e360672 | 193 | |
charlesmn | 0:3ac96e360672 | 194 | |
charlesmn | 0:3ac96e360672 | 195 | if (tmp64 > 0x00FFFFFF) |
charlesmn | 0:3ac96e360672 | 196 | tmp64 = 0x00FFFFFF; |
charlesmn | 0:3ac96e360672 | 197 | |
charlesmn | 0:3ac96e360672 | 198 | pdata->VL53L1_p_034 = (uint32_t)tmp64; |
charlesmn | 0:3ac96e360672 | 199 | |
charlesmn | 0:3ac96e360672 | 200 | |
charlesmn | 0:3ac96e360672 | 201 | |
charlesmn | 0:3ac96e360672 | 202 | tmp32 = VL53L1_isqrt(pdata->VL53L1_p_004 << 8); |
charlesmn | 0:3ac96e360672 | 203 | tmp32 *= (uint32_t)pcfg->ambient_thresh_sigma; |
charlesmn | 0:3ac96e360672 | 204 | |
charlesmn | 0:3ac96e360672 | 205 | |
charlesmn | 0:3ac96e360672 | 206 | |
charlesmn | 0:3ac96e360672 | 207 | if (pdata->VL53L1_p_004 < |
charlesmn | 0:3ac96e360672 | 208 | (uint32_t)pcfg->min_ambient_thresh_events) { |
charlesmn | 0:3ac96e360672 | 209 | |
charlesmn | 0:3ac96e360672 | 210 | amb_thres_delta = |
charlesmn | 0:3ac96e360672 | 211 | pcfg->min_ambient_thresh_events - |
charlesmn | 0:3ac96e360672 | 212 | (uint32_t)pdata->VL53L1_p_004; |
charlesmn | 0:3ac96e360672 | 213 | |
charlesmn | 0:3ac96e360672 | 214 | |
charlesmn | 0:3ac96e360672 | 215 | amb_thres_delta <<= 8; |
charlesmn | 0:3ac96e360672 | 216 | |
charlesmn | 0:3ac96e360672 | 217 | if (tmp32 < amb_thres_delta) |
charlesmn | 0:3ac96e360672 | 218 | tmp32 = amb_thres_delta; |
charlesmn | 0:3ac96e360672 | 219 | } |
charlesmn | 0:3ac96e360672 | 220 | |
charlesmn | 0:3ac96e360672 | 221 | |
charlesmn | 0:3ac96e360672 | 222 | |
charlesmn | 0:3ac96e360672 | 223 | pdata->VL53L1_p_007 = |
charlesmn | 0:3ac96e360672 | 224 | (int16_t)VL53L1_f_002( |
charlesmn | 0:3ac96e360672 | 225 | tmp32, |
charlesmn | 0:3ac96e360672 | 226 | pdata->VL53L1_p_034, |
charlesmn | 0:3ac96e360672 | 227 | (uint32_t)pcal->ref__distance_mm, |
charlesmn | 0:3ac96e360672 | 228 | (uint32_t)pcfg->signal_thresh_sigma); |
charlesmn | 0:3ac96e360672 | 229 | |
charlesmn | 0:3ac96e360672 | 230 | |
charlesmn | 0:3ac96e360672 | 231 | |
charlesmn | 0:3ac96e360672 | 232 | tmp32 = (uint32_t)pdata->VL53L1_p_034; |
charlesmn | 0:3ac96e360672 | 233 | tmp32 *= (uint32_t)pbins->vcsel_width; |
charlesmn | 0:3ac96e360672 | 234 | tmp32 += (1 << 3); |
charlesmn | 0:3ac96e360672 | 235 | tmp32 /= (1 << 4); |
charlesmn | 0:3ac96e360672 | 236 | |
charlesmn | 0:3ac96e360672 | 237 | pdata->VL53L1_p_035 = |
charlesmn | 0:3ac96e360672 | 238 | (int16_t)VL53L1_f_002( |
charlesmn | 0:3ac96e360672 | 239 | 256 * (uint32_t)pcfg->signal_total_events_limit, |
charlesmn | 0:3ac96e360672 | 240 | tmp32, |
charlesmn | 0:3ac96e360672 | 241 | (uint32_t)pcal->ref__distance_mm, |
charlesmn | 0:3ac96e360672 | 242 | (uint32_t)pcfg->signal_thresh_sigma); |
charlesmn | 0:3ac96e360672 | 243 | |
charlesmn | 0:3ac96e360672 | 244 | |
charlesmn | 0:3ac96e360672 | 245 | |
charlesmn | 0:3ac96e360672 | 246 | |
charlesmn | 0:3ac96e360672 | 247 | if (pdata->VL53L1_p_035 < pdata->VL53L1_p_007) |
charlesmn | 0:3ac96e360672 | 248 | *pambient_dmax_mm = pdata->VL53L1_p_035; |
charlesmn | 0:3ac96e360672 | 249 | else |
charlesmn | 0:3ac96e360672 | 250 | *pambient_dmax_mm = pdata->VL53L1_p_007; |
charlesmn | 0:3ac96e360672 | 251 | |
charlesmn | 0:3ac96e360672 | 252 | } |
charlesmn | 0:3ac96e360672 | 253 | |
charlesmn | 0:3ac96e360672 | 254 | LOG_FUNCTION_END(status); |
charlesmn | 0:3ac96e360672 | 255 | |
charlesmn | 0:3ac96e360672 | 256 | return status; |
charlesmn | 0:3ac96e360672 | 257 | |
charlesmn | 0:3ac96e360672 | 258 | } |
charlesmn | 0:3ac96e360672 | 259 | |
charlesmn | 0:3ac96e360672 | 260 | |
charlesmn | 0:3ac96e360672 | 261 | uint32_t VL53L1_f_002( |
charlesmn | 0:3ac96e360672 | 262 | uint32_t events_threshold, |
charlesmn | 0:3ac96e360672 | 263 | uint32_t ref_signal_events, |
charlesmn | 0:3ac96e360672 | 264 | uint32_t ref_distance_mm, |
charlesmn | 0:3ac96e360672 | 265 | uint32_t signal_thresh_sigma) |
charlesmn | 0:3ac96e360672 | 266 | { |
charlesmn | 0:3ac96e360672 | 267 | |
charlesmn | 0:3ac96e360672 | 268 | |
charlesmn | 0:3ac96e360672 | 269 | |
charlesmn | 0:3ac96e360672 | 270 | uint32_t tmp32 = 0; |
charlesmn | 0:3ac96e360672 | 271 | uint32_t range_mm = 0; |
charlesmn | 0:3ac96e360672 | 272 | |
charlesmn | 0:3ac96e360672 | 273 | tmp32 = 4 * events_threshold; |
charlesmn | 0:3ac96e360672 | 274 | |
charlesmn | 0:3ac96e360672 | 275 | |
charlesmn | 0:3ac96e360672 | 276 | |
charlesmn | 0:3ac96e360672 | 277 | tmp32 += ((uint32_t)signal_thresh_sigma * |
charlesmn | 0:3ac96e360672 | 278 | (uint32_t)signal_thresh_sigma); |
charlesmn | 0:3ac96e360672 | 279 | |
charlesmn | 0:3ac96e360672 | 280 | |
charlesmn | 0:3ac96e360672 | 281 | |
charlesmn | 0:3ac96e360672 | 282 | tmp32 = VL53L1_isqrt(tmp32); |
charlesmn | 0:3ac96e360672 | 283 | tmp32 += (uint32_t)signal_thresh_sigma; |
charlesmn | 0:3ac96e360672 | 284 | |
charlesmn | 0:3ac96e360672 | 285 | |
charlesmn | 0:3ac96e360672 | 286 | |
charlesmn | 0:3ac96e360672 | 287 | range_mm = |
charlesmn | 0:3ac96e360672 | 288 | (uint32_t)VL53L1_isqrt(ref_signal_events << 4); |
charlesmn | 0:3ac96e360672 | 289 | range_mm *= ref_distance_mm; |
charlesmn | 0:3ac96e360672 | 290 | |
charlesmn | 0:3ac96e360672 | 291 | if (tmp32 > 0) { |
charlesmn | 0:3ac96e360672 | 292 | range_mm += (tmp32); |
charlesmn | 0:3ac96e360672 | 293 | range_mm /= (2*tmp32); |
charlesmn | 0:3ac96e360672 | 294 | } |
charlesmn | 0:3ac96e360672 | 295 | |
charlesmn | 0:3ac96e360672 | 296 | return range_mm; |
charlesmn | 0:3ac96e360672 | 297 | |
charlesmn | 0:3ac96e360672 | 298 | } |
charlesmn | 0:3ac96e360672 | 299 |