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.c@1:76429facbf6f, 2020-11-08 (annotated)
- Committer:
- charlesmn
- Date:
- Sun Nov 08 13:50:58 2020 +0000
- Revision:
- 1:76429facbf6f
- Parent:
- 0:3ac96e360672
- Child:
- 7:1add29d51e72
Cope with MBed 6.4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charlesmn | 0:3ac96e360672 | 1 | |
charlesmn | 0:3ac96e360672 | 2 | /******************************************************************************* |
charlesmn | 0:3ac96e360672 | 3 | * Copyright (c) 2020, STMicroelectronics - All Rights Reserved |
charlesmn | 0:3ac96e360672 | 4 | |
charlesmn | 0:3ac96e360672 | 5 | This file is part of VL53L1 Core and is dual licensed, |
charlesmn | 0:3ac96e360672 | 6 | either 'STMicroelectronics |
charlesmn | 0:3ac96e360672 | 7 | Proprietary license' |
charlesmn | 0:3ac96e360672 | 8 | or 'BSD 3-clause "New" or "Revised" License' , at your option. |
charlesmn | 0:3ac96e360672 | 9 | |
charlesmn | 0:3ac96e360672 | 10 | ******************************************************************************** |
charlesmn | 0:3ac96e360672 | 11 | |
charlesmn | 0:3ac96e360672 | 12 | 'STMicroelectronics Proprietary license' |
charlesmn | 0:3ac96e360672 | 13 | |
charlesmn | 0:3ac96e360672 | 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 | |
charlesmn | 0:3ac96e360672 | 19 | STMicroelectronics confidential |
charlesmn | 0:3ac96e360672 | 20 | Reproduction and Communication of this document is strictly prohibited unless |
charlesmn | 0:3ac96e360672 | 21 | specifically authorized in writing by STMicroelectronics. |
charlesmn | 0:3ac96e360672 | 22 | |
charlesmn | 0:3ac96e360672 | 23 | |
charlesmn | 0:3ac96e360672 | 24 | ******************************************************************************** |
charlesmn | 0:3ac96e360672 | 25 | |
charlesmn | 0:3ac96e360672 | 26 | Alternatively, VL53L1 Core may be distributed under the terms of |
charlesmn | 0:3ac96e360672 | 27 | 'BSD 3-clause "New" or "Revised" License', in which case the following |
charlesmn | 0:3ac96e360672 | 28 | provisions apply instead of the ones |
charlesmn | 0:3ac96e360672 | 29 | mentioned above : |
charlesmn | 0:3ac96e360672 | 30 | |
charlesmn | 0:3ac96e360672 | 31 | ******************************************************************************** |
charlesmn | 0:3ac96e360672 | 32 | |
charlesmn | 0:3ac96e360672 | 33 | License terms: BSD 3-clause "New" or "Revised" License. |
charlesmn | 0:3ac96e360672 | 34 | |
charlesmn | 0:3ac96e360672 | 35 | Redistribution and use in source and binary forms, with or without |
charlesmn | 0:3ac96e360672 | 36 | modification, are permitted provided that the following conditions are met: |
charlesmn | 0:3ac96e360672 | 37 | |
charlesmn | 0:3ac96e360672 | 38 | 1. Redistributions of source code must retain the above copyright notice, this |
charlesmn | 0:3ac96e360672 | 39 | list of conditions and the following disclaimer. |
charlesmn | 0:3ac96e360672 | 40 | |
charlesmn | 0:3ac96e360672 | 41 | 2. Redistributions in binary form must reproduce the above copyright notice, |
charlesmn | 0:3ac96e360672 | 42 | this list of conditions and the following disclaimer in the documentation |
charlesmn | 0:3ac96e360672 | 43 | and/or other materials provided with the distribution. |
charlesmn | 0:3ac96e360672 | 44 | |
charlesmn | 0:3ac96e360672 | 45 | 3. Neither the name of the copyright holder nor the names of its contributors |
charlesmn | 0:3ac96e360672 | 46 | may be used to endorse or promote products derived from this software |
charlesmn | 0:3ac96e360672 | 47 | without specific prior written permission. |
charlesmn | 0:3ac96e360672 | 48 | |
charlesmn | 0:3ac96e360672 | 49 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
charlesmn | 0:3ac96e360672 | 50 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
charlesmn | 0:3ac96e360672 | 51 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
charlesmn | 0:3ac96e360672 | 52 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
charlesmn | 0:3ac96e360672 | 53 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
charlesmn | 0:3ac96e360672 | 54 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
charlesmn | 0:3ac96e360672 | 55 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
charlesmn | 0:3ac96e360672 | 56 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
charlesmn | 0:3ac96e360672 | 57 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
charlesmn | 0:3ac96e360672 | 58 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
charlesmn | 0:3ac96e360672 | 59 | |
charlesmn | 0:3ac96e360672 | 60 | |
charlesmn | 0:3ac96e360672 | 61 | ******************************************************************************** |
charlesmn | 0:3ac96e360672 | 62 | |
charlesmn | 0:3ac96e360672 | 63 | */ |
charlesmn | 0:3ac96e360672 | 64 | |
charlesmn | 0:3ac96e360672 | 65 | |
charlesmn | 0:3ac96e360672 | 66 | #include "vl53l1_api.h" |
charlesmn | 0:3ac96e360672 | 67 | #include "vl53l1_api_strings.h" |
charlesmn | 0:3ac96e360672 | 68 | #include "vl53l1_register_settings.h" |
charlesmn | 0:3ac96e360672 | 69 | #include "vl53l1_register_funcs.h" |
charlesmn | 0:3ac96e360672 | 70 | #include "vl53l1_core.h" |
charlesmn | 0:3ac96e360672 | 71 | #include "vl53l1_api_calibration.h" |
charlesmn | 0:3ac96e360672 | 72 | #include "vl53l1_wait.h" |
charlesmn | 0:3ac96e360672 | 73 | #include "vl53l1_preset_setup.h" |
charlesmn | 0:3ac96e360672 | 74 | #include "vl53l1_api_debug.h" |
charlesmn | 0:3ac96e360672 | 75 | #include "vl53l1_api_core.h" |
charlesmn | 0:3ac96e360672 | 76 | #include "vl53l1_nvm.h" |
charlesmn | 0:3ac96e360672 | 77 | |
charlesmn | 1:76429facbf6f | 78 | #include "mbed_wait_api.h" |
charlesmn | 1:76429facbf6f | 79 | |
charlesmn | 0:3ac96e360672 | 80 | |
charlesmn | 0:3ac96e360672 | 81 | #define ZONE_CHECK VL53L1_MAX_USER_ZONES |
charlesmn | 0:3ac96e360672 | 82 | |
charlesmn | 0:3ac96e360672 | 83 | #if ZONE_CHECK < 5 |
charlesmn | 0:3ac96e360672 | 84 | #error Must define at least 5 zones in MAX_USER_ZONES constant |
charlesmn | 0:3ac96e360672 | 85 | #endif |
charlesmn | 0:3ac96e360672 | 86 | |
charlesmn | 0:3ac96e360672 | 87 | #define LOG_FUNCTION_START(fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 88 | _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 89 | #define LOG_FUNCTION_END(status, ...) \ |
charlesmn | 0:3ac96e360672 | 90 | _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 91 | #define LOG_FUNCTION_END_FMT(status, fmt, ...) \ |
charlesmn | 0:3ac96e360672 | 92 | _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, \ |
charlesmn | 0:3ac96e360672 | 93 | fmt, ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 94 | |
charlesmn | 0:3ac96e360672 | 95 | #ifdef VL53L1_LOG_ENABLE |
charlesmn | 0:3ac96e360672 | 96 | #define trace_print(level, ...) trace_print_module_function(\ |
charlesmn | 0:3ac96e360672 | 97 | VL53L1_TRACE_MODULE_API, level, VL53L1_TRACE_FUNCTION_NONE, \ |
charlesmn | 0:3ac96e360672 | 98 | ##__VA_ARGS__) |
charlesmn | 0:3ac96e360672 | 99 | #endif |
charlesmn | 0:3ac96e360672 | 100 | |
charlesmn | 0:3ac96e360672 | 101 | #ifndef MIN |
charlesmn | 0:3ac96e360672 | 102 | #define MIN(v1, v2) ((v1) < (v2) ? (v1) : (v2)) |
charlesmn | 0:3ac96e360672 | 103 | #endif |
charlesmn | 0:3ac96e360672 | 104 | #ifndef MAX |
charlesmn | 0:3ac96e360672 | 105 | #define MAX(v1, v2) ((v1) < (v2) ? (v2) : (v1)) |
charlesmn | 0:3ac96e360672 | 106 | #endif |
charlesmn | 0:3ac96e360672 | 107 | |
charlesmn | 0:3ac96e360672 | 108 | #define DMAX_REFLECTANCE_IDX 2 |
charlesmn | 0:3ac96e360672 | 109 | |
charlesmn | 0:3ac96e360672 | 110 | |
charlesmn | 0:3ac96e360672 | 111 | |
charlesmn | 0:3ac96e360672 | 112 | #define LOWPOWER_AUTO_VHV_LOOP_DURATION_US 245 |
charlesmn | 0:3ac96e360672 | 113 | #define LOWPOWER_AUTO_OVERHEAD_BEFORE_A_RANGING 1448 |
charlesmn | 0:3ac96e360672 | 114 | #define LOWPOWER_AUTO_OVERHEAD_BETWEEN_A_B_RANGING 2100 |
charlesmn | 0:3ac96e360672 | 115 | |
charlesmn | 0:3ac96e360672 | 116 | #define FDA_MAX_TIMING_BUDGET_US 550000 |
charlesmn | 0:3ac96e360672 | 117 | |
charlesmn | 0:3ac96e360672 | 118 | |
charlesmn | 0:3ac96e360672 | 119 | |
charlesmn | 0:3ac96e360672 | 120 | |
charlesmn | 0:3ac96e360672 | 121 | static int32_t BDTable[VL53L1_TUNING_MAX_TUNABLE_KEY] = { |
charlesmn | 0:3ac96e360672 | 122 | TUNING_VERSION, |
charlesmn | 0:3ac96e360672 | 123 | TUNING_PROXY_MIN, |
charlesmn | 0:3ac96e360672 | 124 | TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM, |
charlesmn | 0:3ac96e360672 | 125 | TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER, |
charlesmn | 0:3ac96e360672 | 126 | TUNING_MIN_AMBIENT_DMAX_VALID, |
charlesmn | 0:3ac96e360672 | 127 | TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER, |
charlesmn | 0:3ac96e360672 | 128 | TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM, |
charlesmn | 0:3ac96e360672 | 129 | TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT, |
charlesmn | 0:3ac96e360672 | 130 | TUNING_XTALK_FULL_ROI_BIN_SUM_MARGIN, |
charlesmn | 0:3ac96e360672 | 131 | TUNING_XTALK_FULL_ROI_DEFAULT_OFFSET, |
charlesmn | 0:3ac96e360672 | 132 | TUNING_ZERO_DISTANCE_OFFSET_NON_LINEAR_FACTOR_DEFAULT, |
charlesmn | 0:3ac96e360672 | 133 | }; |
charlesmn | 0:3ac96e360672 | 134 | |
charlesmn | 0:3ac96e360672 | 135 | |
charlesmn | 0:3ac96e360672 | 136 | VL53L1_Error SingleTargetXTalkCalibration(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 137 | { |
charlesmn | 0:3ac96e360672 | 138 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 139 | |
charlesmn | 0:3ac96e360672 | 140 | uint32_t sum_ranging = 0; |
charlesmn | 0:3ac96e360672 | 141 | uint32_t sum_spads = 0; |
charlesmn | 0:3ac96e360672 | 142 | FixPoint1616_t sum_signalRate = 0; |
charlesmn | 0:3ac96e360672 | 143 | FixPoint1616_t total_count = 0; |
charlesmn | 0:3ac96e360672 | 144 | uint8_t xtalk_meas = 0; |
charlesmn | 0:3ac96e360672 | 145 | uint8_t xtalk_measmax = |
charlesmn | 0:3ac96e360672 | 146 | BDTable[VL53L1_TUNING_SINGLE_TARGET_XTALK_SAMPLE_NUMBER]; |
charlesmn | 0:3ac96e360672 | 147 | VL53L1_RangingMeasurementData_t RMData; |
charlesmn | 0:3ac96e360672 | 148 | FixPoint1616_t xTalkStoredMeanSignalRate; |
charlesmn | 0:3ac96e360672 | 149 | FixPoint1616_t xTalkStoredMeanRange; |
charlesmn | 0:3ac96e360672 | 150 | FixPoint1616_t xTalkStoredMeanRtnSpads; |
charlesmn | 0:3ac96e360672 | 151 | uint32_t xTalkStoredMeanRtnSpadsAsInt; |
charlesmn | 0:3ac96e360672 | 152 | uint32_t xTalkCalDistanceAsInt; |
charlesmn | 0:3ac96e360672 | 153 | FixPoint1616_t XTalkCompensationRateMegaCps; |
charlesmn | 0:3ac96e360672 | 154 | uint32_t signalXTalkTotalPerSpad; |
charlesmn | 0:3ac96e360672 | 155 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 156 | VL53L1_CalibrationData_t CalibrationData; |
charlesmn | 0:3ac96e360672 | 157 | VL53L1_CustomerNvmManaged_t *pC; |
charlesmn | 0:3ac96e360672 | 158 | |
charlesmn | 0:3ac96e360672 | 159 | |
charlesmn | 0:3ac96e360672 | 160 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 161 | |
charlesmn | 0:3ac96e360672 | 162 | |
charlesmn | 0:3ac96e360672 | 163 | PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 164 | |
charlesmn | 0:3ac96e360672 | 165 | if ((PresetMode != VL53L1_PRESETMODE_AUTONOMOUS) && |
charlesmn | 0:3ac96e360672 | 166 | (PresetMode != VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS) && |
charlesmn | 0:3ac96e360672 | 167 | (PresetMode != VL53L1_PRESETMODE_LITE_RANGING)) { |
charlesmn | 0:3ac96e360672 | 168 | Status = VL53L1_ERROR_MODE_NOT_SUPPORTED; |
charlesmn | 0:3ac96e360672 | 169 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 170 | } |
charlesmn | 0:3ac96e360672 | 171 | |
charlesmn | 0:3ac96e360672 | 172 | |
charlesmn | 0:3ac96e360672 | 173 | Status = VL53L1_disable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 174 | |
charlesmn | 0:3ac96e360672 | 175 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 176 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 177 | |
charlesmn | 0:3ac96e360672 | 178 | Status = VL53L1_StartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 179 | |
charlesmn | 0:3ac96e360672 | 180 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 181 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 182 | |
charlesmn | 0:3ac96e360672 | 183 | |
charlesmn | 0:3ac96e360672 | 184 | VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 185 | VL53L1_GetRangingMeasurementData(Dev, &RMData); |
charlesmn | 0:3ac96e360672 | 186 | VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 187 | |
charlesmn | 0:3ac96e360672 | 188 | sum_ranging = 0; |
charlesmn | 0:3ac96e360672 | 189 | sum_spads = 0; |
charlesmn | 0:3ac96e360672 | 190 | sum_signalRate = 0; |
charlesmn | 0:3ac96e360672 | 191 | total_count = 0; |
charlesmn | 0:3ac96e360672 | 192 | for (xtalk_meas = 0; xtalk_meas < xtalk_measmax; xtalk_meas++) { |
charlesmn | 0:3ac96e360672 | 193 | VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 194 | VL53L1_GetRangingMeasurementData(Dev, &RMData); |
charlesmn | 0:3ac96e360672 | 195 | VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 196 | if (RMData.RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) { |
charlesmn | 0:3ac96e360672 | 197 | sum_ranging += RMData.RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 198 | sum_signalRate += RMData.SignalRateRtnMegaCps; |
charlesmn | 0:3ac96e360672 | 199 | sum_spads += RMData.EffectiveSpadRtnCount / 256; |
charlesmn | 0:3ac96e360672 | 200 | total_count++; |
charlesmn | 0:3ac96e360672 | 201 | } |
charlesmn | 0:3ac96e360672 | 202 | } |
charlesmn | 0:3ac96e360672 | 203 | Status = VL53L1_StopMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 204 | |
charlesmn | 0:3ac96e360672 | 205 | if (total_count > 0) { |
charlesmn | 0:3ac96e360672 | 206 | |
charlesmn | 0:3ac96e360672 | 207 | xTalkStoredMeanSignalRate = sum_signalRate / total_count; |
charlesmn | 0:3ac96e360672 | 208 | xTalkStoredMeanRange = (FixPoint1616_t)(sum_ranging << 16); |
charlesmn | 0:3ac96e360672 | 209 | xTalkStoredMeanRange /= total_count; |
charlesmn | 0:3ac96e360672 | 210 | xTalkStoredMeanRtnSpads = (FixPoint1616_t)(sum_spads << 16); |
charlesmn | 0:3ac96e360672 | 211 | xTalkStoredMeanRtnSpads /= total_count; |
charlesmn | 0:3ac96e360672 | 212 | |
charlesmn | 0:3ac96e360672 | 213 | |
charlesmn | 0:3ac96e360672 | 214 | xTalkStoredMeanRtnSpadsAsInt = (xTalkStoredMeanRtnSpads + |
charlesmn | 0:3ac96e360672 | 215 | 0x8000) >> 16; |
charlesmn | 0:3ac96e360672 | 216 | |
charlesmn | 0:3ac96e360672 | 217 | |
charlesmn | 0:3ac96e360672 | 218 | xTalkCalDistanceAsInt = ((uint32_t)BDTable[ |
charlesmn | 0:3ac96e360672 | 219 | VL53L1_TUNING_SINGLE_TARGET_XTALK_TARGET_DISTANCE_MM]); |
charlesmn | 0:3ac96e360672 | 220 | if (xTalkStoredMeanRtnSpadsAsInt == 0 || |
charlesmn | 0:3ac96e360672 | 221 | xTalkCalDistanceAsInt == 0 || |
charlesmn | 0:3ac96e360672 | 222 | xTalkStoredMeanRange >= (xTalkCalDistanceAsInt << 16)) { |
charlesmn | 0:3ac96e360672 | 223 | XTalkCompensationRateMegaCps = 0; |
charlesmn | 0:3ac96e360672 | 224 | } else { |
charlesmn | 0:3ac96e360672 | 225 | |
charlesmn | 0:3ac96e360672 | 226 | signalXTalkTotalPerSpad = (xTalkStoredMeanSignalRate) / |
charlesmn | 0:3ac96e360672 | 227 | xTalkStoredMeanRtnSpadsAsInt; |
charlesmn | 0:3ac96e360672 | 228 | |
charlesmn | 0:3ac96e360672 | 229 | |
charlesmn | 0:3ac96e360672 | 230 | signalXTalkTotalPerSpad *= (((uint32_t)1 << 16) - |
charlesmn | 0:3ac96e360672 | 231 | (xTalkStoredMeanRange / xTalkCalDistanceAsInt)); |
charlesmn | 0:3ac96e360672 | 232 | |
charlesmn | 0:3ac96e360672 | 233 | |
charlesmn | 0:3ac96e360672 | 234 | XTalkCompensationRateMegaCps = (signalXTalkTotalPerSpad |
charlesmn | 0:3ac96e360672 | 235 | + 0x8000) >> 16; |
charlesmn | 0:3ac96e360672 | 236 | } |
charlesmn | 0:3ac96e360672 | 237 | |
charlesmn | 0:3ac96e360672 | 238 | |
charlesmn | 0:3ac96e360672 | 239 | Status = VL53L1_GetCalibrationData(Dev, &CalibrationData); |
charlesmn | 0:3ac96e360672 | 240 | |
charlesmn | 0:3ac96e360672 | 241 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 242 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 243 | |
charlesmn | 0:3ac96e360672 | 244 | pC = &CalibrationData.customer; |
charlesmn | 0:3ac96e360672 | 245 | |
charlesmn | 0:3ac96e360672 | 246 | pC->algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 247 | (uint32_t)(1000 * ((XTalkCompensationRateMegaCps + |
charlesmn | 0:3ac96e360672 | 248 | ((uint32_t)1<<6)) >> (16-9))); |
charlesmn | 0:3ac96e360672 | 249 | |
charlesmn | 0:3ac96e360672 | 250 | Status = VL53L1_SetCalibrationData(Dev, &CalibrationData); |
charlesmn | 0:3ac96e360672 | 251 | |
charlesmn | 0:3ac96e360672 | 252 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 253 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 254 | |
charlesmn | 0:3ac96e360672 | 255 | Status = VL53L1_enable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 256 | |
charlesmn | 0:3ac96e360672 | 257 | } else |
charlesmn | 0:3ac96e360672 | 258 | |
charlesmn | 0:3ac96e360672 | 259 | Status = VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL; |
charlesmn | 0:3ac96e360672 | 260 | |
charlesmn | 0:3ac96e360672 | 261 | ENDFUNC: |
charlesmn | 0:3ac96e360672 | 262 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 263 | return Status; |
charlesmn | 0:3ac96e360672 | 264 | |
charlesmn | 0:3ac96e360672 | 265 | } |
charlesmn | 0:3ac96e360672 | 266 | |
charlesmn | 0:3ac96e360672 | 267 | |
charlesmn | 0:3ac96e360672 | 268 | static VL53L1_Error CheckValidRectRoi(VL53L1_UserRoi_t ROI) |
charlesmn | 0:3ac96e360672 | 269 | { |
charlesmn | 0:3ac96e360672 | 270 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 271 | |
charlesmn | 0:3ac96e360672 | 272 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 273 | |
charlesmn | 0:3ac96e360672 | 274 | |
charlesmn | 0:3ac96e360672 | 275 | if ((ROI.TopLeftX > 15) || (ROI.TopLeftY > 15) || |
charlesmn | 0:3ac96e360672 | 276 | (ROI.BotRightX > 15) || (ROI.BotRightY > 15)) |
charlesmn | 0:3ac96e360672 | 277 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 278 | |
charlesmn | 0:3ac96e360672 | 279 | if ((ROI.TopLeftX > ROI.BotRightX) || (ROI.TopLeftY < ROI.BotRightY)) |
charlesmn | 0:3ac96e360672 | 280 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 281 | |
charlesmn | 0:3ac96e360672 | 282 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 283 | return Status; |
charlesmn | 0:3ac96e360672 | 284 | } |
charlesmn | 0:3ac96e360672 | 285 | |
charlesmn | 0:3ac96e360672 | 286 | static VL53L1_GPIO_Interrupt_Mode ConvertModeToLLD(VL53L1_Error *pStatus, |
charlesmn | 0:3ac96e360672 | 287 | VL53L1_ThresholdMode CrossMode) |
charlesmn | 0:3ac96e360672 | 288 | { |
charlesmn | 0:3ac96e360672 | 289 | VL53L1_GPIO_Interrupt_Mode Mode; |
charlesmn | 0:3ac96e360672 | 290 | |
charlesmn | 0:3ac96e360672 | 291 | switch (CrossMode) { |
charlesmn | 0:3ac96e360672 | 292 | case VL53L1_THRESHOLD_CROSSED_LOW: |
charlesmn | 0:3ac96e360672 | 293 | Mode = VL53L1_GPIOINTMODE_LEVEL_LOW; |
charlesmn | 0:3ac96e360672 | 294 | break; |
charlesmn | 0:3ac96e360672 | 295 | case VL53L1_THRESHOLD_CROSSED_HIGH: |
charlesmn | 0:3ac96e360672 | 296 | Mode = VL53L1_GPIOINTMODE_LEVEL_HIGH; |
charlesmn | 0:3ac96e360672 | 297 | break; |
charlesmn | 0:3ac96e360672 | 298 | case VL53L1_THRESHOLD_OUT_OF_WINDOW: |
charlesmn | 0:3ac96e360672 | 299 | Mode = VL53L1_GPIOINTMODE_OUT_OF_WINDOW; |
charlesmn | 0:3ac96e360672 | 300 | break; |
charlesmn | 0:3ac96e360672 | 301 | case VL53L1_THRESHOLD_IN_WINDOW: |
charlesmn | 0:3ac96e360672 | 302 | Mode = VL53L1_GPIOINTMODE_IN_WINDOW; |
charlesmn | 0:3ac96e360672 | 303 | break; |
charlesmn | 0:3ac96e360672 | 304 | default: |
charlesmn | 0:3ac96e360672 | 305 | |
charlesmn | 0:3ac96e360672 | 306 | Mode = VL53L1_GPIOINTMODE_LEVEL_HIGH; |
charlesmn | 0:3ac96e360672 | 307 | *pStatus = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 308 | } |
charlesmn | 0:3ac96e360672 | 309 | return Mode; |
charlesmn | 0:3ac96e360672 | 310 | } |
charlesmn | 0:3ac96e360672 | 311 | |
charlesmn | 0:3ac96e360672 | 312 | static VL53L1_ThresholdMode ConvertModeFromLLD(VL53L1_Error *pStatus, |
charlesmn | 0:3ac96e360672 | 313 | VL53L1_GPIO_Interrupt_Mode CrossMode) |
charlesmn | 0:3ac96e360672 | 314 | { |
charlesmn | 0:3ac96e360672 | 315 | VL53L1_ThresholdMode Mode; |
charlesmn | 0:3ac96e360672 | 316 | |
charlesmn | 0:3ac96e360672 | 317 | switch (CrossMode) { |
charlesmn | 0:3ac96e360672 | 318 | case VL53L1_GPIOINTMODE_LEVEL_LOW: |
charlesmn | 0:3ac96e360672 | 319 | Mode = VL53L1_THRESHOLD_CROSSED_LOW; |
charlesmn | 0:3ac96e360672 | 320 | break; |
charlesmn | 0:3ac96e360672 | 321 | case VL53L1_GPIOINTMODE_LEVEL_HIGH: |
charlesmn | 0:3ac96e360672 | 322 | Mode = VL53L1_THRESHOLD_CROSSED_HIGH; |
charlesmn | 0:3ac96e360672 | 323 | break; |
charlesmn | 0:3ac96e360672 | 324 | case VL53L1_GPIOINTMODE_OUT_OF_WINDOW: |
charlesmn | 0:3ac96e360672 | 325 | Mode = VL53L1_THRESHOLD_OUT_OF_WINDOW; |
charlesmn | 0:3ac96e360672 | 326 | break; |
charlesmn | 0:3ac96e360672 | 327 | case VL53L1_GPIOINTMODE_IN_WINDOW: |
charlesmn | 0:3ac96e360672 | 328 | Mode = VL53L1_THRESHOLD_IN_WINDOW; |
charlesmn | 0:3ac96e360672 | 329 | break; |
charlesmn | 0:3ac96e360672 | 330 | default: |
charlesmn | 0:3ac96e360672 | 331 | |
charlesmn | 0:3ac96e360672 | 332 | Mode = VL53L1_THRESHOLD_CROSSED_HIGH; |
charlesmn | 0:3ac96e360672 | 333 | *pStatus = VL53L1_ERROR_UNDEFINED; |
charlesmn | 0:3ac96e360672 | 334 | } |
charlesmn | 0:3ac96e360672 | 335 | return Mode; |
charlesmn | 0:3ac96e360672 | 336 | } |
charlesmn | 0:3ac96e360672 | 337 | |
charlesmn | 0:3ac96e360672 | 338 | |
charlesmn | 0:3ac96e360672 | 339 | |
charlesmn | 0:3ac96e360672 | 340 | VL53L1_Error VL53L1_GetVersion(VL53L1_Version_t *pVersion) |
charlesmn | 0:3ac96e360672 | 341 | { |
charlesmn | 0:3ac96e360672 | 342 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 343 | |
charlesmn | 0:3ac96e360672 | 344 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 345 | |
charlesmn | 0:3ac96e360672 | 346 | pVersion->major = VL53L1_IMPLEMENTATION_VER_MAJOR; |
charlesmn | 0:3ac96e360672 | 347 | pVersion->minor = VL53L1_IMPLEMENTATION_VER_MINOR; |
charlesmn | 0:3ac96e360672 | 348 | pVersion->build = VL53L1_IMPLEMENTATION_VER_SUB; |
charlesmn | 0:3ac96e360672 | 349 | |
charlesmn | 0:3ac96e360672 | 350 | pVersion->revision = VL53L1_IMPLEMENTATION_VER_REVISION; |
charlesmn | 0:3ac96e360672 | 351 | |
charlesmn | 0:3ac96e360672 | 352 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 353 | return Status; |
charlesmn | 0:3ac96e360672 | 354 | } |
charlesmn | 0:3ac96e360672 | 355 | |
charlesmn | 0:3ac96e360672 | 356 | VL53L1_Error VL53L1_GetProductRevision(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 357 | uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor) |
charlesmn | 0:3ac96e360672 | 358 | { |
charlesmn | 0:3ac96e360672 | 359 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 360 | uint8_t revision_id; |
charlesmn | 0:3ac96e360672 | 361 | VL53L1_LLDriverData_t *pLLData; |
charlesmn | 0:3ac96e360672 | 362 | |
charlesmn | 0:3ac96e360672 | 363 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 364 | |
charlesmn | 0:3ac96e360672 | 365 | pLLData = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 366 | revision_id = pLLData->nvm_copy_data.identification__revision_id; |
charlesmn | 0:3ac96e360672 | 367 | *pProductRevisionMajor = 1; |
charlesmn | 0:3ac96e360672 | 368 | *pProductRevisionMinor = (revision_id & 0xF0) >> 4; |
charlesmn | 0:3ac96e360672 | 369 | |
charlesmn | 0:3ac96e360672 | 370 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 371 | return Status; |
charlesmn | 0:3ac96e360672 | 372 | |
charlesmn | 0:3ac96e360672 | 373 | } |
charlesmn | 0:3ac96e360672 | 374 | |
charlesmn | 0:3ac96e360672 | 375 | VL53L1_Error VL53L1_GetDeviceInfo(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 376 | VL53L1_DeviceInfo_t *pVL53L1_DeviceInfo) |
charlesmn | 0:3ac96e360672 | 377 | { |
charlesmn | 0:3ac96e360672 | 378 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 379 | uint8_t revision_id; |
charlesmn | 0:3ac96e360672 | 380 | VL53L1_LLDriverData_t *pLLData; |
charlesmn | 0:3ac96e360672 | 381 | |
charlesmn | 0:3ac96e360672 | 382 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 383 | |
charlesmn | 0:3ac96e360672 | 384 | pLLData = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 385 | |
charlesmn | 0:3ac96e360672 | 386 | strncpy(pVL53L1_DeviceInfo->ProductId, "", |
charlesmn | 0:3ac96e360672 | 387 | VL53L1_DEVINFO_STRLEN-1); |
charlesmn | 0:3ac96e360672 | 388 | pVL53L1_DeviceInfo->ProductType = |
charlesmn | 0:3ac96e360672 | 389 | pLLData->nvm_copy_data.identification__module_type; |
charlesmn | 0:3ac96e360672 | 390 | |
charlesmn | 0:3ac96e360672 | 391 | revision_id = pLLData->nvm_copy_data.identification__revision_id; |
charlesmn | 0:3ac96e360672 | 392 | pVL53L1_DeviceInfo->ProductRevisionMajor = 1; |
charlesmn | 0:3ac96e360672 | 393 | pVL53L1_DeviceInfo->ProductRevisionMinor = (revision_id & 0xF0) >> 4; |
charlesmn | 0:3ac96e360672 | 394 | |
charlesmn | 0:3ac96e360672 | 395 | #ifndef VL53L1_USE_EMPTY_STRING |
charlesmn | 0:3ac96e360672 | 396 | if (pVL53L1_DeviceInfo->ProductRevisionMinor == 0) |
charlesmn | 0:3ac96e360672 | 397 | strncpy(pVL53L1_DeviceInfo->Name, |
charlesmn | 0:3ac96e360672 | 398 | VL53L1_STRING_DEVICE_INFO_NAME0, |
charlesmn | 0:3ac96e360672 | 399 | VL53L1_DEVINFO_STRLEN-1); |
charlesmn | 0:3ac96e360672 | 400 | else |
charlesmn | 0:3ac96e360672 | 401 | strncpy(pVL53L1_DeviceInfo->Name, |
charlesmn | 0:3ac96e360672 | 402 | VL53L1_STRING_DEVICE_INFO_NAME1, |
charlesmn | 0:3ac96e360672 | 403 | VL53L1_DEVINFO_STRLEN-1); |
charlesmn | 0:3ac96e360672 | 404 | strncpy(pVL53L1_DeviceInfo->Type, |
charlesmn | 0:3ac96e360672 | 405 | VL53L1_STRING_DEVICE_INFO_TYPE, |
charlesmn | 0:3ac96e360672 | 406 | VL53L1_DEVINFO_STRLEN-1); |
charlesmn | 0:3ac96e360672 | 407 | |
charlesmn | 0:3ac96e360672 | 408 | if (pVL53L1_DeviceInfo->ProductType == 0xAA) { |
charlesmn | 0:3ac96e360672 | 409 | pVL53L1_DeviceInfo->Name[5] = '3'; |
charlesmn | 0:3ac96e360672 | 410 | pVL53L1_DeviceInfo->Type[5] = '3'; |
charlesmn | 0:3ac96e360672 | 411 | } |
charlesmn | 0:3ac96e360672 | 412 | #else |
charlesmn | 0:3ac96e360672 | 413 | pVL53L1_DeviceInfo->Name[0] = 0; |
charlesmn | 0:3ac96e360672 | 414 | pVL53L1_DeviceInfo->Type[0] = 0; |
charlesmn | 0:3ac96e360672 | 415 | #endif |
charlesmn | 0:3ac96e360672 | 416 | |
charlesmn | 0:3ac96e360672 | 417 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 418 | return Status; |
charlesmn | 0:3ac96e360672 | 419 | } |
charlesmn | 0:3ac96e360672 | 420 | |
charlesmn | 0:3ac96e360672 | 421 | VL53L1_Error VL53L1_GetUID(VL53L1_DEV Dev, uint64_t *pUid) |
charlesmn | 0:3ac96e360672 | 422 | { |
charlesmn | 0:3ac96e360672 | 423 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 424 | uint8_t fmtdata[8]; |
charlesmn | 0:3ac96e360672 | 425 | |
charlesmn | 0:3ac96e360672 | 426 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 427 | |
charlesmn | 0:3ac96e360672 | 428 | Status = VL53L1_read_nvm_raw_data(Dev, |
charlesmn | 0:3ac96e360672 | 429 | (uint8_t)(0x1F8 >> 2), |
charlesmn | 0:3ac96e360672 | 430 | (uint8_t)(8 >> 2), |
charlesmn | 0:3ac96e360672 | 431 | fmtdata); |
charlesmn | 0:3ac96e360672 | 432 | memcpy(pUid, fmtdata, sizeof(uint64_t)); |
charlesmn | 0:3ac96e360672 | 433 | |
charlesmn | 0:3ac96e360672 | 434 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 435 | return Status; |
charlesmn | 0:3ac96e360672 | 436 | } |
charlesmn | 0:3ac96e360672 | 437 | |
charlesmn | 0:3ac96e360672 | 438 | VL53L1_Error VL53L1_GetRangeStatusString(uint8_t RangeStatus, |
charlesmn | 0:3ac96e360672 | 439 | char *pRangeStatusString) |
charlesmn | 0:3ac96e360672 | 440 | { |
charlesmn | 0:3ac96e360672 | 441 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 442 | |
charlesmn | 0:3ac96e360672 | 443 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 444 | |
charlesmn | 0:3ac96e360672 | 445 | Status = VL53L1_get_range_status_string(RangeStatus, |
charlesmn | 0:3ac96e360672 | 446 | pRangeStatusString); |
charlesmn | 0:3ac96e360672 | 447 | |
charlesmn | 0:3ac96e360672 | 448 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 449 | return Status; |
charlesmn | 0:3ac96e360672 | 450 | } |
charlesmn | 0:3ac96e360672 | 451 | |
charlesmn | 0:3ac96e360672 | 452 | VL53L1_Error VL53L1_GetPalErrorString(VL53L1_Error PalErrorCode, |
charlesmn | 0:3ac96e360672 | 453 | char *pPalErrorString) |
charlesmn | 0:3ac96e360672 | 454 | { |
charlesmn | 0:3ac96e360672 | 455 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 456 | |
charlesmn | 0:3ac96e360672 | 457 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 458 | |
charlesmn | 0:3ac96e360672 | 459 | Status = VL53L1_get_pal_error_string(PalErrorCode, pPalErrorString); |
charlesmn | 0:3ac96e360672 | 460 | |
charlesmn | 0:3ac96e360672 | 461 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 462 | return Status; |
charlesmn | 0:3ac96e360672 | 463 | } |
charlesmn | 0:3ac96e360672 | 464 | |
charlesmn | 0:3ac96e360672 | 465 | VL53L1_Error VL53L1_GetPalStateString(VL53L1_State PalStateCode, |
charlesmn | 0:3ac96e360672 | 466 | char *pPalStateString) |
charlesmn | 0:3ac96e360672 | 467 | { |
charlesmn | 0:3ac96e360672 | 468 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 469 | |
charlesmn | 0:3ac96e360672 | 470 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 471 | |
charlesmn | 0:3ac96e360672 | 472 | Status = VL53L1_get_pal_state_string(PalStateCode, pPalStateString); |
charlesmn | 0:3ac96e360672 | 473 | |
charlesmn | 0:3ac96e360672 | 474 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 475 | return Status; |
charlesmn | 0:3ac96e360672 | 476 | } |
charlesmn | 0:3ac96e360672 | 477 | |
charlesmn | 0:3ac96e360672 | 478 | VL53L1_Error VL53L1_GetPalState(VL53L1_DEV Dev, VL53L1_State *pPalState) |
charlesmn | 0:3ac96e360672 | 479 | { |
charlesmn | 0:3ac96e360672 | 480 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 481 | |
charlesmn | 0:3ac96e360672 | 482 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 483 | |
charlesmn | 0:3ac96e360672 | 484 | *pPalState = VL53L1DevDataGet(Dev, PalState); |
charlesmn | 0:3ac96e360672 | 485 | |
charlesmn | 0:3ac96e360672 | 486 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 487 | return Status; |
charlesmn | 0:3ac96e360672 | 488 | } |
charlesmn | 0:3ac96e360672 | 489 | |
charlesmn | 0:3ac96e360672 | 490 | |
charlesmn | 0:3ac96e360672 | 491 | |
charlesmn | 0:3ac96e360672 | 492 | |
charlesmn | 0:3ac96e360672 | 493 | VL53L1_Error VL53L1_SetDeviceAddress(VL53L1_DEV Dev, uint8_t DeviceAddress) |
charlesmn | 0:3ac96e360672 | 494 | { |
charlesmn | 0:3ac96e360672 | 495 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 496 | |
charlesmn | 0:3ac96e360672 | 497 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 498 | |
charlesmn | 0:3ac96e360672 | 499 | Status = VL53L1_WrByte(Dev, VL53L1_I2C_SLAVE__DEVICE_ADDRESS, |
charlesmn | 0:3ac96e360672 | 500 | DeviceAddress / 2); |
charlesmn | 0:3ac96e360672 | 501 | |
charlesmn | 0:3ac96e360672 | 502 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 503 | return Status; |
charlesmn | 0:3ac96e360672 | 504 | } |
charlesmn | 0:3ac96e360672 | 505 | |
charlesmn | 0:3ac96e360672 | 506 | VL53L1_Error VL53L1_DataInit(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 507 | { |
charlesmn | 0:3ac96e360672 | 508 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 509 | uint8_t i; |
charlesmn | 0:3ac96e360672 | 510 | VL53L1_LLDriverData_t *pdev; |
charlesmn | 0:3ac96e360672 | 511 | |
charlesmn | 0:3ac96e360672 | 512 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 513 | |
charlesmn | 0:3ac96e360672 | 514 | |
charlesmn | 0:3ac96e360672 | 515 | #ifdef USE_I2C_2V8 |
charlesmn | 0:3ac96e360672 | 516 | Status = VL53L1_RdByte(Dev, VL53L1_PAD_I2C_HV__EXTSUP_CONFIG, &i); |
charlesmn | 0:3ac96e360672 | 517 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 518 | i = (i & 0xfe) | 0x01; |
charlesmn | 0:3ac96e360672 | 519 | Status = VL53L1_WrByte(Dev, VL53L1_PAD_I2C_HV__EXTSUP_CONFIG, |
charlesmn | 0:3ac96e360672 | 520 | i); |
charlesmn | 0:3ac96e360672 | 521 | } |
charlesmn | 0:3ac96e360672 | 522 | #endif |
charlesmn | 0:3ac96e360672 | 523 | |
charlesmn | 0:3ac96e360672 | 524 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 525 | Status = VL53L1_data_init(Dev, 1); |
charlesmn | 0:3ac96e360672 | 526 | |
charlesmn | 0:3ac96e360672 | 527 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 528 | pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 529 | memset(&pdev->per_vcsel_cal_data, 0, |
charlesmn | 0:3ac96e360672 | 530 | sizeof(pdev->per_vcsel_cal_data)); |
charlesmn | 0:3ac96e360672 | 531 | } |
charlesmn | 0:3ac96e360672 | 532 | |
charlesmn | 0:3ac96e360672 | 533 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 534 | VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_WAIT_STATICINIT); |
charlesmn | 0:3ac96e360672 | 535 | VL53L1DevDataSet(Dev, CurrentParameters.PresetMode, |
charlesmn | 0:3ac96e360672 | 536 | VL53L1_PRESETMODE_RANGING); |
charlesmn | 0:3ac96e360672 | 537 | } |
charlesmn | 0:3ac96e360672 | 538 | |
charlesmn | 0:3ac96e360672 | 539 | |
charlesmn | 0:3ac96e360672 | 540 | for (i = 0; i < VL53L1_CHECKENABLE_NUMBER_OF_CHECKS; i++) { |
charlesmn | 0:3ac96e360672 | 541 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 542 | Status |= VL53L1_SetLimitCheckEnable(Dev, i, 1); |
charlesmn | 0:3ac96e360672 | 543 | else |
charlesmn | 0:3ac96e360672 | 544 | break; |
charlesmn | 0:3ac96e360672 | 545 | |
charlesmn | 0:3ac96e360672 | 546 | } |
charlesmn | 0:3ac96e360672 | 547 | |
charlesmn | 0:3ac96e360672 | 548 | |
charlesmn | 0:3ac96e360672 | 549 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 550 | Status = VL53L1_set_dmax_mode(Dev, |
charlesmn | 0:3ac96e360672 | 551 | VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA); |
charlesmn | 0:3ac96e360672 | 552 | } |
charlesmn | 0:3ac96e360672 | 553 | |
charlesmn | 0:3ac96e360672 | 554 | |
charlesmn | 0:3ac96e360672 | 555 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 556 | return Status; |
charlesmn | 0:3ac96e360672 | 557 | } |
charlesmn | 0:3ac96e360672 | 558 | |
charlesmn | 0:3ac96e360672 | 559 | |
charlesmn | 0:3ac96e360672 | 560 | VL53L1_Error VL53L1_StaticInit(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 561 | { |
charlesmn | 0:3ac96e360672 | 562 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 563 | uint8_t measurement_mode; |
charlesmn | 0:3ac96e360672 | 564 | |
charlesmn | 0:3ac96e360672 | 565 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 566 | |
charlesmn | 0:3ac96e360672 | 567 | VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_IDLE); |
charlesmn | 0:3ac96e360672 | 568 | |
charlesmn | 0:3ac96e360672 | 569 | measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK; |
charlesmn | 0:3ac96e360672 | 570 | VL53L1DevDataSet(Dev, LLData.measurement_mode, measurement_mode); |
charlesmn | 0:3ac96e360672 | 571 | |
charlesmn | 0:3ac96e360672 | 572 | VL53L1DevDataSet(Dev, CurrentParameters.DistanceMode, |
charlesmn | 0:3ac96e360672 | 573 | VL53L1_DISTANCEMODE_LONG); |
charlesmn | 0:3ac96e360672 | 574 | VL53L1DevDataSet(Dev, CurrentParameters.OutputMode, |
charlesmn | 0:3ac96e360672 | 575 | VL53L1_OUTPUTMODE_NEAREST); |
charlesmn | 0:3ac96e360672 | 576 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 577 | return Status; |
charlesmn | 0:3ac96e360672 | 578 | } |
charlesmn | 0:3ac96e360672 | 579 | |
charlesmn | 0:3ac96e360672 | 580 | VL53L1_Error VL53L1_WaitDeviceBooted(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 581 | { |
charlesmn | 0:3ac96e360672 | 582 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 583 | |
charlesmn | 0:3ac96e360672 | 584 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 585 | |
charlesmn | 0:3ac96e360672 | 586 | Status = VL53L1_poll_for_boot_completion(Dev, |
charlesmn | 0:3ac96e360672 | 587 | VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS); |
charlesmn | 0:3ac96e360672 | 588 | |
charlesmn | 0:3ac96e360672 | 589 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 590 | return Status; |
charlesmn | 0:3ac96e360672 | 591 | } |
charlesmn | 0:3ac96e360672 | 592 | |
charlesmn | 0:3ac96e360672 | 593 | |
charlesmn | 0:3ac96e360672 | 594 | |
charlesmn | 0:3ac96e360672 | 595 | |
charlesmn | 0:3ac96e360672 | 596 | static VL53L1_Error ComputeDevicePresetMode( |
charlesmn | 0:3ac96e360672 | 597 | VL53L1_PresetModes PresetMode, |
charlesmn | 0:3ac96e360672 | 598 | VL53L1_DistanceModes DistanceMode, |
charlesmn | 0:3ac96e360672 | 599 | VL53L1_DevicePresetModes *pDevicePresetMode) |
charlesmn | 0:3ac96e360672 | 600 | { |
charlesmn | 0:3ac96e360672 | 601 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 602 | |
charlesmn | 0:3ac96e360672 | 603 | uint8_t DistIdx; |
charlesmn | 0:3ac96e360672 | 604 | VL53L1_DevicePresetModes LightModes[3] = { |
charlesmn | 0:3ac96e360672 | 605 | VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_SHORT_RANGE, |
charlesmn | 0:3ac96e360672 | 606 | VL53L1_DEVICEPRESETMODE_STANDARD_RANGING, |
charlesmn | 0:3ac96e360672 | 607 | VL53L1_DEVICEPRESETMODE_STANDARD_RANGING_LONG_RANGE}; |
charlesmn | 0:3ac96e360672 | 608 | |
charlesmn | 0:3ac96e360672 | 609 | VL53L1_DevicePresetModes RangingModes[3] = { |
charlesmn | 0:3ac96e360672 | 610 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE, |
charlesmn | 0:3ac96e360672 | 611 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE, |
charlesmn | 0:3ac96e360672 | 612 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE}; |
charlesmn | 0:3ac96e360672 | 613 | |
charlesmn | 0:3ac96e360672 | 614 | VL53L1_DevicePresetModes ScanningModes[3] = { |
charlesmn | 0:3ac96e360672 | 615 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_SHORT_RANGE, |
charlesmn | 0:3ac96e360672 | 616 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE, |
charlesmn | 0:3ac96e360672 | 617 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE}; |
charlesmn | 0:3ac96e360672 | 618 | |
charlesmn | 0:3ac96e360672 | 619 | VL53L1_DevicePresetModes TimedModes[3] = { |
charlesmn | 0:3ac96e360672 | 620 | VL53L1_DEVICEPRESETMODE_TIMED_RANGING_SHORT_RANGE, |
charlesmn | 0:3ac96e360672 | 621 | VL53L1_DEVICEPRESETMODE_TIMED_RANGING, |
charlesmn | 0:3ac96e360672 | 622 | VL53L1_DEVICEPRESETMODE_TIMED_RANGING_LONG_RANGE}; |
charlesmn | 0:3ac96e360672 | 623 | |
charlesmn | 0:3ac96e360672 | 624 | VL53L1_DevicePresetModes LowPowerTimedModes[3] = { |
charlesmn | 0:3ac96e360672 | 625 | VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_SHORT_RANGE, |
charlesmn | 0:3ac96e360672 | 626 | VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_MEDIUM_RANGE, |
charlesmn | 0:3ac96e360672 | 627 | VL53L1_DEVICEPRESETMODE_LOWPOWERAUTO_LONG_RANGE}; |
charlesmn | 0:3ac96e360672 | 628 | |
charlesmn | 0:3ac96e360672 | 629 | *pDevicePresetMode = VL53L1_DEVICEPRESETMODE_STANDARD_RANGING; |
charlesmn | 0:3ac96e360672 | 630 | |
charlesmn | 0:3ac96e360672 | 631 | switch (DistanceMode) { |
charlesmn | 0:3ac96e360672 | 632 | case VL53L1_DISTANCEMODE_SHORT: |
charlesmn | 0:3ac96e360672 | 633 | DistIdx = 0; |
charlesmn | 0:3ac96e360672 | 634 | break; |
charlesmn | 0:3ac96e360672 | 635 | case VL53L1_DISTANCEMODE_MEDIUM: |
charlesmn | 0:3ac96e360672 | 636 | DistIdx = 1; |
charlesmn | 0:3ac96e360672 | 637 | break; |
charlesmn | 0:3ac96e360672 | 638 | default: |
charlesmn | 0:3ac96e360672 | 639 | DistIdx = 2; |
charlesmn | 0:3ac96e360672 | 640 | } |
charlesmn | 0:3ac96e360672 | 641 | |
charlesmn | 0:3ac96e360672 | 642 | switch (PresetMode) { |
charlesmn | 0:3ac96e360672 | 643 | case VL53L1_PRESETMODE_LITE_RANGING: |
charlesmn | 0:3ac96e360672 | 644 | *pDevicePresetMode = LightModes[DistIdx]; |
charlesmn | 0:3ac96e360672 | 645 | break; |
charlesmn | 0:3ac96e360672 | 646 | |
charlesmn | 0:3ac96e360672 | 647 | case VL53L1_PRESETMODE_RANGING: |
charlesmn | 0:3ac96e360672 | 648 | *pDevicePresetMode = RangingModes[DistIdx]; |
charlesmn | 0:3ac96e360672 | 649 | break; |
charlesmn | 0:3ac96e360672 | 650 | |
charlesmn | 0:3ac96e360672 | 651 | case VL53L1_PRESETMODE_MULTIZONES_SCANNING: |
charlesmn | 0:3ac96e360672 | 652 | *pDevicePresetMode = ScanningModes[DistIdx]; |
charlesmn | 0:3ac96e360672 | 653 | break; |
charlesmn | 0:3ac96e360672 | 654 | |
charlesmn | 0:3ac96e360672 | 655 | case VL53L1_PRESETMODE_AUTONOMOUS: |
charlesmn | 0:3ac96e360672 | 656 | *pDevicePresetMode = TimedModes[DistIdx]; |
charlesmn | 0:3ac96e360672 | 657 | break; |
charlesmn | 0:3ac96e360672 | 658 | |
charlesmn | 0:3ac96e360672 | 659 | case VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS: |
charlesmn | 0:3ac96e360672 | 660 | *pDevicePresetMode = LowPowerTimedModes[DistIdx]; |
charlesmn | 0:3ac96e360672 | 661 | break; |
charlesmn | 0:3ac96e360672 | 662 | case VL53L1_PRESETMODE_OLT: |
charlesmn | 0:3ac96e360672 | 663 | *pDevicePresetMode = VL53L1_DEVICEPRESETMODE_OLT; |
charlesmn | 0:3ac96e360672 | 664 | break; |
charlesmn | 0:3ac96e360672 | 665 | case VL53L1_PRESETMODE_PROXY_RANGING_MODE: |
charlesmn | 0:3ac96e360672 | 666 | *pDevicePresetMode = |
charlesmn | 0:3ac96e360672 | 667 | VL53L1_DEVICEPRESETMODE_SPECIAL_HISTOGRAM_SHORT_RANGE; |
charlesmn | 0:3ac96e360672 | 668 | break; |
charlesmn | 0:3ac96e360672 | 669 | |
charlesmn | 0:3ac96e360672 | 670 | default: |
charlesmn | 0:3ac96e360672 | 671 | |
charlesmn | 0:3ac96e360672 | 672 | Status = VL53L1_ERROR_MODE_NOT_SUPPORTED; |
charlesmn | 0:3ac96e360672 | 673 | } |
charlesmn | 0:3ac96e360672 | 674 | |
charlesmn | 0:3ac96e360672 | 675 | return Status; |
charlesmn | 0:3ac96e360672 | 676 | } |
charlesmn | 0:3ac96e360672 | 677 | |
charlesmn | 0:3ac96e360672 | 678 | static VL53L1_Error SetPresetMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 679 | VL53L1_PresetModes PresetMode, |
charlesmn | 0:3ac96e360672 | 680 | VL53L1_DistanceModes DistanceMode, |
charlesmn | 0:3ac96e360672 | 681 | uint32_t inter_measurement_period_ms) |
charlesmn | 0:3ac96e360672 | 682 | { |
charlesmn | 0:3ac96e360672 | 683 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 684 | VL53L1_DevicePresetModes device_preset_mode; |
charlesmn | 0:3ac96e360672 | 685 | uint8_t measurement_mode; |
charlesmn | 0:3ac96e360672 | 686 | uint16_t dss_config__target_total_rate_mcps; |
charlesmn | 0:3ac96e360672 | 687 | uint32_t phasecal_config_timeout_us; |
charlesmn | 0:3ac96e360672 | 688 | uint32_t mm_config_timeout_us; |
charlesmn | 0:3ac96e360672 | 689 | uint32_t lld_range_config_timeout_us; |
charlesmn | 0:3ac96e360672 | 690 | |
charlesmn | 0:3ac96e360672 | 691 | LOG_FUNCTION_START("%d", (int)PresetMode); |
charlesmn | 0:3ac96e360672 | 692 | |
charlesmn | 0:3ac96e360672 | 693 | if ((PresetMode == VL53L1_PRESETMODE_AUTONOMOUS) || |
charlesmn | 0:3ac96e360672 | 694 | (PresetMode == VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS)) |
charlesmn | 0:3ac96e360672 | 695 | measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_TIMED; |
charlesmn | 0:3ac96e360672 | 696 | else |
charlesmn | 0:3ac96e360672 | 697 | measurement_mode = VL53L1_DEVICEMEASUREMENTMODE_BACKTOBACK; |
charlesmn | 0:3ac96e360672 | 698 | |
charlesmn | 0:3ac96e360672 | 699 | |
charlesmn | 0:3ac96e360672 | 700 | Status = ComputeDevicePresetMode(PresetMode, DistanceMode, |
charlesmn | 0:3ac96e360672 | 701 | &device_preset_mode); |
charlesmn | 0:3ac96e360672 | 702 | |
charlesmn | 0:3ac96e360672 | 703 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 704 | Status = VL53L1_get_preset_mode_timing_cfg(Dev, |
charlesmn | 0:3ac96e360672 | 705 | device_preset_mode, |
charlesmn | 0:3ac96e360672 | 706 | &dss_config__target_total_rate_mcps, |
charlesmn | 0:3ac96e360672 | 707 | &phasecal_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 708 | &mm_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 709 | &lld_range_config_timeout_us); |
charlesmn | 0:3ac96e360672 | 710 | |
charlesmn | 0:3ac96e360672 | 711 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 712 | Status = VL53L1_set_preset_mode( |
charlesmn | 0:3ac96e360672 | 713 | Dev, |
charlesmn | 0:3ac96e360672 | 714 | device_preset_mode, |
charlesmn | 0:3ac96e360672 | 715 | dss_config__target_total_rate_mcps, |
charlesmn | 0:3ac96e360672 | 716 | phasecal_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 717 | mm_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 718 | lld_range_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 719 | inter_measurement_period_ms); |
charlesmn | 0:3ac96e360672 | 720 | |
charlesmn | 0:3ac96e360672 | 721 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 722 | VL53L1DevDataSet(Dev, LLData.measurement_mode, |
charlesmn | 0:3ac96e360672 | 723 | measurement_mode); |
charlesmn | 0:3ac96e360672 | 724 | |
charlesmn | 0:3ac96e360672 | 725 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 726 | VL53L1DevDataSet(Dev, CurrentParameters.PresetMode, PresetMode); |
charlesmn | 0:3ac96e360672 | 727 | |
charlesmn | 0:3ac96e360672 | 728 | VL53L1DevDataSet(Dev, CurrentParameters.OutputMode, |
charlesmn | 0:3ac96e360672 | 729 | VL53L1_OUTPUTMODE_NEAREST); |
charlesmn | 0:3ac96e360672 | 730 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 731 | return Status; |
charlesmn | 0:3ac96e360672 | 732 | } |
charlesmn | 0:3ac96e360672 | 733 | |
charlesmn | 0:3ac96e360672 | 734 | |
charlesmn | 0:3ac96e360672 | 735 | VL53L1_Error VL53L1_SetPresetMode(VL53L1_DEV Dev, VL53L1_PresetModes PresetMode) |
charlesmn | 0:3ac96e360672 | 736 | { |
charlesmn | 0:3ac96e360672 | 737 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 738 | VL53L1_DistanceModes DistanceMode = VL53L1_DISTANCEMODE_LONG; |
charlesmn | 0:3ac96e360672 | 739 | |
charlesmn | 0:3ac96e360672 | 740 | LOG_FUNCTION_START("%d", (int)PresetMode); |
charlesmn | 0:3ac96e360672 | 741 | |
charlesmn | 0:3ac96e360672 | 742 | |
charlesmn | 0:3ac96e360672 | 743 | Status = VL53L1_low_power_auto_data_init(Dev); |
charlesmn | 0:3ac96e360672 | 744 | |
charlesmn | 0:3ac96e360672 | 745 | if (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE) |
charlesmn | 0:3ac96e360672 | 746 | DistanceMode = VL53L1_DISTANCEMODE_SHORT; |
charlesmn | 0:3ac96e360672 | 747 | Status = SetPresetMode(Dev, |
charlesmn | 0:3ac96e360672 | 748 | PresetMode, |
charlesmn | 0:3ac96e360672 | 749 | DistanceMode, |
charlesmn | 0:3ac96e360672 | 750 | 1000); |
charlesmn | 0:3ac96e360672 | 751 | |
charlesmn | 0:3ac96e360672 | 752 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 753 | if ((PresetMode == VL53L1_PRESETMODE_LITE_RANGING) || |
charlesmn | 0:3ac96e360672 | 754 | (PresetMode == VL53L1_PRESETMODE_AUTONOMOUS) || |
charlesmn | 0:3ac96e360672 | 755 | (PresetMode == VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS)) |
charlesmn | 0:3ac96e360672 | 756 | Status = VL53L1_SetMeasurementTimingBudgetMicroSeconds( |
charlesmn | 0:3ac96e360672 | 757 | Dev, 41000); |
charlesmn | 0:3ac96e360672 | 758 | else |
charlesmn | 0:3ac96e360672 | 759 | |
charlesmn | 0:3ac96e360672 | 760 | Status = VL53L1_SetMeasurementTimingBudgetMicroSeconds( |
charlesmn | 0:3ac96e360672 | 761 | Dev, 33333); |
charlesmn | 0:3ac96e360672 | 762 | } |
charlesmn | 0:3ac96e360672 | 763 | |
charlesmn | 0:3ac96e360672 | 764 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 765 | |
charlesmn | 0:3ac96e360672 | 766 | Status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, |
charlesmn | 0:3ac96e360672 | 767 | 1000); |
charlesmn | 0:3ac96e360672 | 768 | } |
charlesmn | 0:3ac96e360672 | 769 | |
charlesmn | 0:3ac96e360672 | 770 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 771 | return Status; |
charlesmn | 0:3ac96e360672 | 772 | } |
charlesmn | 0:3ac96e360672 | 773 | |
charlesmn | 0:3ac96e360672 | 774 | |
charlesmn | 0:3ac96e360672 | 775 | VL53L1_Error VL53L1_GetPresetMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 776 | VL53L1_PresetModes *pPresetMode) |
charlesmn | 0:3ac96e360672 | 777 | { |
charlesmn | 0:3ac96e360672 | 778 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 779 | |
charlesmn | 0:3ac96e360672 | 780 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 781 | |
charlesmn | 0:3ac96e360672 | 782 | *pPresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 783 | |
charlesmn | 0:3ac96e360672 | 784 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 785 | return Status; |
charlesmn | 0:3ac96e360672 | 786 | } |
charlesmn | 0:3ac96e360672 | 787 | |
charlesmn | 0:3ac96e360672 | 788 | VL53L1_Error VL53L1_SetDistanceMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 789 | VL53L1_DistanceModes DistanceMode) |
charlesmn | 0:3ac96e360672 | 790 | { |
charlesmn | 0:3ac96e360672 | 791 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 792 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 793 | uint32_t inter_measurement_period_ms; |
charlesmn | 0:3ac96e360672 | 794 | uint32_t TimingBudget; |
charlesmn | 0:3ac96e360672 | 795 | uint32_t MmTimeoutUs; |
charlesmn | 0:3ac96e360672 | 796 | uint32_t PhaseCalTimeoutUs; |
charlesmn | 0:3ac96e360672 | 797 | VL53L1_zone_config_t zone_config; |
charlesmn | 0:3ac96e360672 | 798 | |
charlesmn | 0:3ac96e360672 | 799 | LOG_FUNCTION_START("%d", (int)DistanceMode); |
charlesmn | 0:3ac96e360672 | 800 | |
charlesmn | 0:3ac96e360672 | 801 | PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 802 | |
charlesmn | 0:3ac96e360672 | 803 | |
charlesmn | 0:3ac96e360672 | 804 | |
charlesmn | 0:3ac96e360672 | 805 | if ((PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE) && |
charlesmn | 0:3ac96e360672 | 806 | (DistanceMode != VL53L1_DISTANCEMODE_SHORT)) |
charlesmn | 0:3ac96e360672 | 807 | return VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 808 | if ((DistanceMode != VL53L1_DISTANCEMODE_SHORT) && |
charlesmn | 0:3ac96e360672 | 809 | (DistanceMode != VL53L1_DISTANCEMODE_MEDIUM) && |
charlesmn | 0:3ac96e360672 | 810 | (DistanceMode != VL53L1_DISTANCEMODE_LONG)) |
charlesmn | 0:3ac96e360672 | 811 | return VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 812 | |
charlesmn | 0:3ac96e360672 | 813 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 814 | Status = VL53L1_get_zone_config(Dev, &zone_config); |
charlesmn | 0:3ac96e360672 | 815 | |
charlesmn | 0:3ac96e360672 | 816 | inter_measurement_period_ms = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 817 | LLData.inter_measurement_period_ms); |
charlesmn | 0:3ac96e360672 | 818 | |
charlesmn | 0:3ac96e360672 | 819 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 820 | Status = VL53L1_get_timeouts_us(Dev, &PhaseCalTimeoutUs, |
charlesmn | 0:3ac96e360672 | 821 | &MmTimeoutUs, &TimingBudget); |
charlesmn | 0:3ac96e360672 | 822 | |
charlesmn | 0:3ac96e360672 | 823 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 824 | Status = SetPresetMode(Dev, |
charlesmn | 0:3ac96e360672 | 825 | PresetMode, |
charlesmn | 0:3ac96e360672 | 826 | DistanceMode, |
charlesmn | 0:3ac96e360672 | 827 | inter_measurement_period_ms); |
charlesmn | 0:3ac96e360672 | 828 | |
charlesmn | 0:3ac96e360672 | 829 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 830 | VL53L1DevDataSet(Dev, CurrentParameters.DistanceMode, |
charlesmn | 0:3ac96e360672 | 831 | DistanceMode); |
charlesmn | 0:3ac96e360672 | 832 | } |
charlesmn | 0:3ac96e360672 | 833 | |
charlesmn | 0:3ac96e360672 | 834 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 835 | Status = VL53L1_set_timeouts_us(Dev, PhaseCalTimeoutUs, |
charlesmn | 0:3ac96e360672 | 836 | MmTimeoutUs, TimingBudget); |
charlesmn | 0:3ac96e360672 | 837 | |
charlesmn | 0:3ac96e360672 | 838 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 839 | VL53L1DevDataSet(Dev, LLData.range_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 840 | TimingBudget); |
charlesmn | 0:3ac96e360672 | 841 | } |
charlesmn | 0:3ac96e360672 | 842 | |
charlesmn | 0:3ac96e360672 | 843 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 844 | Status = VL53L1_set_zone_config(Dev, &zone_config); |
charlesmn | 0:3ac96e360672 | 845 | |
charlesmn | 0:3ac96e360672 | 846 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 847 | return Status; |
charlesmn | 0:3ac96e360672 | 848 | } |
charlesmn | 0:3ac96e360672 | 849 | |
charlesmn | 0:3ac96e360672 | 850 | VL53L1_Error VL53L1_GetDistanceMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 851 | VL53L1_DistanceModes *pDistanceMode) |
charlesmn | 0:3ac96e360672 | 852 | { |
charlesmn | 0:3ac96e360672 | 853 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 854 | |
charlesmn | 0:3ac96e360672 | 855 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 856 | |
charlesmn | 0:3ac96e360672 | 857 | *pDistanceMode = VL53L1DevDataGet(Dev, CurrentParameters.DistanceMode); |
charlesmn | 0:3ac96e360672 | 858 | |
charlesmn | 0:3ac96e360672 | 859 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 860 | return Status; |
charlesmn | 0:3ac96e360672 | 861 | } |
charlesmn | 0:3ac96e360672 | 862 | |
charlesmn | 0:3ac96e360672 | 863 | VL53L1_Error VL53L1_SetOutputMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 864 | VL53L1_OutputModes OutputMode) |
charlesmn | 0:3ac96e360672 | 865 | { |
charlesmn | 0:3ac96e360672 | 866 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 867 | |
charlesmn | 0:3ac96e360672 | 868 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 869 | |
charlesmn | 0:3ac96e360672 | 870 | if ((OutputMode != VL53L1_OUTPUTMODE_NEAREST) && |
charlesmn | 0:3ac96e360672 | 871 | (OutputMode != VL53L1_OUTPUTMODE_STRONGEST)) |
charlesmn | 0:3ac96e360672 | 872 | Status = VL53L1_ERROR_MODE_NOT_SUPPORTED; |
charlesmn | 0:3ac96e360672 | 873 | else |
charlesmn | 0:3ac96e360672 | 874 | VL53L1DevDataSet(Dev, CurrentParameters.OutputMode, OutputMode); |
charlesmn | 0:3ac96e360672 | 875 | |
charlesmn | 0:3ac96e360672 | 876 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 877 | return Status; |
charlesmn | 0:3ac96e360672 | 878 | } |
charlesmn | 0:3ac96e360672 | 879 | |
charlesmn | 0:3ac96e360672 | 880 | VL53L1_Error VL53L1_GetOutputMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 881 | VL53L1_OutputModes *pOutputMode) |
charlesmn | 0:3ac96e360672 | 882 | { |
charlesmn | 0:3ac96e360672 | 883 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 884 | |
charlesmn | 0:3ac96e360672 | 885 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 886 | |
charlesmn | 0:3ac96e360672 | 887 | *pOutputMode = VL53L1DevDataGet(Dev, CurrentParameters.OutputMode); |
charlesmn | 0:3ac96e360672 | 888 | |
charlesmn | 0:3ac96e360672 | 889 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 890 | return Status; |
charlesmn | 0:3ac96e360672 | 891 | } |
charlesmn | 0:3ac96e360672 | 892 | |
charlesmn | 0:3ac96e360672 | 893 | |
charlesmn | 0:3ac96e360672 | 894 | |
charlesmn | 0:3ac96e360672 | 895 | VL53L1_Error VL53L1_SetMeasurementTimingBudgetMicroSeconds(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 896 | uint32_t MeasurementTimingBudgetMicroSeconds) |
charlesmn | 0:3ac96e360672 | 897 | { |
charlesmn | 0:3ac96e360672 | 898 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 899 | uint8_t Mm1Enabled; |
charlesmn | 0:3ac96e360672 | 900 | uint8_t Mm2Enabled; |
charlesmn | 0:3ac96e360672 | 901 | uint32_t TimingGuard; |
charlesmn | 0:3ac96e360672 | 902 | uint32_t divisor; |
charlesmn | 0:3ac96e360672 | 903 | uint32_t TimingBudget; |
charlesmn | 0:3ac96e360672 | 904 | uint32_t MmTimeoutUs; |
charlesmn | 0:3ac96e360672 | 905 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 906 | uint32_t PhaseCalTimeoutUs; |
charlesmn | 0:3ac96e360672 | 907 | uint32_t vhv; |
charlesmn | 0:3ac96e360672 | 908 | int32_t vhv_loops; |
charlesmn | 0:3ac96e360672 | 909 | uint32_t FDAMaxTimingBudgetUs = FDA_MAX_TIMING_BUDGET_US; |
charlesmn | 0:3ac96e360672 | 910 | |
charlesmn | 0:3ac96e360672 | 911 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 912 | |
charlesmn | 0:3ac96e360672 | 913 | |
charlesmn | 0:3ac96e360672 | 914 | if (MeasurementTimingBudgetMicroSeconds > 10000000) |
charlesmn | 0:3ac96e360672 | 915 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 916 | |
charlesmn | 0:3ac96e360672 | 917 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 918 | Status = VL53L1_GetSequenceStepEnable(Dev, |
charlesmn | 0:3ac96e360672 | 919 | VL53L1_SEQUENCESTEP_MM1, &Mm1Enabled); |
charlesmn | 0:3ac96e360672 | 920 | } |
charlesmn | 0:3ac96e360672 | 921 | |
charlesmn | 0:3ac96e360672 | 922 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 923 | Status = VL53L1_GetSequenceStepEnable(Dev, |
charlesmn | 0:3ac96e360672 | 924 | VL53L1_SEQUENCESTEP_MM2, &Mm2Enabled); |
charlesmn | 0:3ac96e360672 | 925 | } |
charlesmn | 0:3ac96e360672 | 926 | |
charlesmn | 0:3ac96e360672 | 927 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 928 | Status = VL53L1_get_timeouts_us(Dev, |
charlesmn | 0:3ac96e360672 | 929 | &PhaseCalTimeoutUs, |
charlesmn | 0:3ac96e360672 | 930 | &MmTimeoutUs, |
charlesmn | 0:3ac96e360672 | 931 | &TimingBudget); |
charlesmn | 0:3ac96e360672 | 932 | |
charlesmn | 0:3ac96e360672 | 933 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 934 | PresetMode = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 935 | CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 936 | |
charlesmn | 0:3ac96e360672 | 937 | TimingGuard = 0; |
charlesmn | 0:3ac96e360672 | 938 | divisor = 1; |
charlesmn | 0:3ac96e360672 | 939 | switch (PresetMode) { |
charlesmn | 0:3ac96e360672 | 940 | case VL53L1_PRESETMODE_LITE_RANGING: |
charlesmn | 0:3ac96e360672 | 941 | if ((Mm1Enabled == 1) || (Mm2Enabled == 1)) |
charlesmn | 0:3ac96e360672 | 942 | TimingGuard = 5000; |
charlesmn | 0:3ac96e360672 | 943 | else |
charlesmn | 0:3ac96e360672 | 944 | TimingGuard = 1000; |
charlesmn | 0:3ac96e360672 | 945 | break; |
charlesmn | 0:3ac96e360672 | 946 | |
charlesmn | 0:3ac96e360672 | 947 | case VL53L1_PRESETMODE_AUTONOMOUS: |
charlesmn | 0:3ac96e360672 | 948 | FDAMaxTimingBudgetUs *= 2; |
charlesmn | 0:3ac96e360672 | 949 | if ((Mm1Enabled == 1) || (Mm2Enabled == 1)) |
charlesmn | 0:3ac96e360672 | 950 | TimingGuard = 26600; |
charlesmn | 0:3ac96e360672 | 951 | else |
charlesmn | 0:3ac96e360672 | 952 | TimingGuard = 21600; |
charlesmn | 0:3ac96e360672 | 953 | divisor = 2; |
charlesmn | 0:3ac96e360672 | 954 | break; |
charlesmn | 0:3ac96e360672 | 955 | |
charlesmn | 0:3ac96e360672 | 956 | case VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS: |
charlesmn | 0:3ac96e360672 | 957 | FDAMaxTimingBudgetUs *= 2; |
charlesmn | 0:3ac96e360672 | 958 | vhv = LOWPOWER_AUTO_VHV_LOOP_DURATION_US; |
charlesmn | 0:3ac96e360672 | 959 | VL53L1_get_tuning_parm(Dev, |
charlesmn | 0:3ac96e360672 | 960 | VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND, |
charlesmn | 0:3ac96e360672 | 961 | &vhv_loops); |
charlesmn | 0:3ac96e360672 | 962 | if (vhv_loops > 0) { |
charlesmn | 0:3ac96e360672 | 963 | vhv += vhv_loops * |
charlesmn | 0:3ac96e360672 | 964 | LOWPOWER_AUTO_VHV_LOOP_DURATION_US; |
charlesmn | 0:3ac96e360672 | 965 | } |
charlesmn | 0:3ac96e360672 | 966 | TimingGuard = LOWPOWER_AUTO_OVERHEAD_BEFORE_A_RANGING + |
charlesmn | 0:3ac96e360672 | 967 | LOWPOWER_AUTO_OVERHEAD_BETWEEN_A_B_RANGING + |
charlesmn | 0:3ac96e360672 | 968 | vhv; |
charlesmn | 0:3ac96e360672 | 969 | divisor = 2; |
charlesmn | 0:3ac96e360672 | 970 | break; |
charlesmn | 0:3ac96e360672 | 971 | |
charlesmn | 0:3ac96e360672 | 972 | case VL53L1_PRESETMODE_RANGING: |
charlesmn | 0:3ac96e360672 | 973 | case VL53L1_PRESETMODE_MULTIZONES_SCANNING: |
charlesmn | 0:3ac96e360672 | 974 | case VL53L1_PRESETMODE_PROXY_RANGING_MODE: |
charlesmn | 0:3ac96e360672 | 975 | TimingGuard = 1700; |
charlesmn | 0:3ac96e360672 | 976 | divisor = 6; |
charlesmn | 0:3ac96e360672 | 977 | break; |
charlesmn | 0:3ac96e360672 | 978 | |
charlesmn | 0:3ac96e360672 | 979 | case VL53L1_PRESETMODE_OLT: |
charlesmn | 0:3ac96e360672 | 980 | TimingGuard = MmTimeoutUs + 5000; |
charlesmn | 0:3ac96e360672 | 981 | break; |
charlesmn | 0:3ac96e360672 | 982 | default: |
charlesmn | 0:3ac96e360672 | 983 | |
charlesmn | 0:3ac96e360672 | 984 | Status = VL53L1_ERROR_MODE_NOT_SUPPORTED; |
charlesmn | 0:3ac96e360672 | 985 | } |
charlesmn | 0:3ac96e360672 | 986 | |
charlesmn | 0:3ac96e360672 | 987 | if (MeasurementTimingBudgetMicroSeconds <= TimingGuard) |
charlesmn | 0:3ac96e360672 | 988 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 989 | else { |
charlesmn | 0:3ac96e360672 | 990 | TimingBudget = (MeasurementTimingBudgetMicroSeconds |
charlesmn | 0:3ac96e360672 | 991 | - TimingGuard); |
charlesmn | 0:3ac96e360672 | 992 | } |
charlesmn | 0:3ac96e360672 | 993 | |
charlesmn | 0:3ac96e360672 | 994 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 995 | if (TimingBudget > FDAMaxTimingBudgetUs) |
charlesmn | 0:3ac96e360672 | 996 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 997 | else { |
charlesmn | 0:3ac96e360672 | 998 | TimingBudget /= divisor; |
charlesmn | 0:3ac96e360672 | 999 | Status = VL53L1_set_timeouts_us( |
charlesmn | 0:3ac96e360672 | 1000 | Dev, |
charlesmn | 0:3ac96e360672 | 1001 | PhaseCalTimeoutUs, |
charlesmn | 0:3ac96e360672 | 1002 | MmTimeoutUs, |
charlesmn | 0:3ac96e360672 | 1003 | TimingBudget); |
charlesmn | 0:3ac96e360672 | 1004 | } |
charlesmn | 0:3ac96e360672 | 1005 | |
charlesmn | 0:3ac96e360672 | 1006 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1007 | VL53L1DevDataSet(Dev, |
charlesmn | 0:3ac96e360672 | 1008 | LLData.range_config_timeout_us, |
charlesmn | 0:3ac96e360672 | 1009 | TimingBudget); |
charlesmn | 0:3ac96e360672 | 1010 | } |
charlesmn | 0:3ac96e360672 | 1011 | } |
charlesmn | 0:3ac96e360672 | 1012 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1013 | VL53L1DevDataSet(Dev, |
charlesmn | 0:3ac96e360672 | 1014 | CurrentParameters.MeasurementTimingBudgetMicroSeconds, |
charlesmn | 0:3ac96e360672 | 1015 | MeasurementTimingBudgetMicroSeconds); |
charlesmn | 0:3ac96e360672 | 1016 | } |
charlesmn | 0:3ac96e360672 | 1017 | |
charlesmn | 0:3ac96e360672 | 1018 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1019 | return Status; |
charlesmn | 0:3ac96e360672 | 1020 | } |
charlesmn | 0:3ac96e360672 | 1021 | |
charlesmn | 0:3ac96e360672 | 1022 | |
charlesmn | 0:3ac96e360672 | 1023 | VL53L1_Error VL53L1_GetMeasurementTimingBudgetMicroSeconds(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1024 | uint32_t *pMeasurementTimingBudgetMicroSeconds) |
charlesmn | 0:3ac96e360672 | 1025 | { |
charlesmn | 0:3ac96e360672 | 1026 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1027 | uint8_t Mm1Enabled = 0; |
charlesmn | 0:3ac96e360672 | 1028 | uint8_t Mm2Enabled = 0; |
charlesmn | 0:3ac96e360672 | 1029 | uint32_t MmTimeoutUs = 0; |
charlesmn | 0:3ac96e360672 | 1030 | uint32_t RangeTimeoutUs = 0; |
charlesmn | 0:3ac96e360672 | 1031 | uint32_t MeasTimingBdg = 0; |
charlesmn | 0:3ac96e360672 | 1032 | uint32_t PhaseCalTimeoutUs = 0; |
charlesmn | 0:3ac96e360672 | 1033 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 1034 | uint32_t TimingGuard; |
charlesmn | 0:3ac96e360672 | 1035 | uint32_t vhv; |
charlesmn | 0:3ac96e360672 | 1036 | int32_t vhv_loops; |
charlesmn | 0:3ac96e360672 | 1037 | |
charlesmn | 0:3ac96e360672 | 1038 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1039 | |
charlesmn | 0:3ac96e360672 | 1040 | *pMeasurementTimingBudgetMicroSeconds = 0; |
charlesmn | 0:3ac96e360672 | 1041 | |
charlesmn | 0:3ac96e360672 | 1042 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1043 | Status = VL53L1_GetSequenceStepEnable(Dev, |
charlesmn | 0:3ac96e360672 | 1044 | VL53L1_SEQUENCESTEP_MM1, &Mm1Enabled); |
charlesmn | 0:3ac96e360672 | 1045 | |
charlesmn | 0:3ac96e360672 | 1046 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1047 | Status = VL53L1_GetSequenceStepEnable(Dev, |
charlesmn | 0:3ac96e360672 | 1048 | VL53L1_SEQUENCESTEP_MM2, &Mm2Enabled); |
charlesmn | 0:3ac96e360672 | 1049 | |
charlesmn | 0:3ac96e360672 | 1050 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1051 | Status = VL53L1_get_timeouts_us(Dev, |
charlesmn | 0:3ac96e360672 | 1052 | &PhaseCalTimeoutUs, |
charlesmn | 0:3ac96e360672 | 1053 | &MmTimeoutUs, |
charlesmn | 0:3ac96e360672 | 1054 | &RangeTimeoutUs); |
charlesmn | 0:3ac96e360672 | 1055 | |
charlesmn | 0:3ac96e360672 | 1056 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1057 | PresetMode = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 1058 | CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 1059 | |
charlesmn | 0:3ac96e360672 | 1060 | switch (PresetMode) { |
charlesmn | 0:3ac96e360672 | 1061 | case VL53L1_PRESETMODE_LITE_RANGING: |
charlesmn | 0:3ac96e360672 | 1062 | if ((Mm1Enabled == 1) || (Mm2Enabled == 1)) |
charlesmn | 0:3ac96e360672 | 1063 | MeasTimingBdg = RangeTimeoutUs + 5000; |
charlesmn | 0:3ac96e360672 | 1064 | else |
charlesmn | 0:3ac96e360672 | 1065 | MeasTimingBdg = RangeTimeoutUs + 1000; |
charlesmn | 0:3ac96e360672 | 1066 | |
charlesmn | 0:3ac96e360672 | 1067 | break; |
charlesmn | 0:3ac96e360672 | 1068 | |
charlesmn | 0:3ac96e360672 | 1069 | case VL53L1_PRESETMODE_AUTONOMOUS: |
charlesmn | 0:3ac96e360672 | 1070 | if ((Mm1Enabled == 1) || (Mm2Enabled == 1)) |
charlesmn | 0:3ac96e360672 | 1071 | MeasTimingBdg = 2 * RangeTimeoutUs + 26600; |
charlesmn | 0:3ac96e360672 | 1072 | else |
charlesmn | 0:3ac96e360672 | 1073 | MeasTimingBdg = 2 * RangeTimeoutUs + 21600; |
charlesmn | 0:3ac96e360672 | 1074 | |
charlesmn | 0:3ac96e360672 | 1075 | break; |
charlesmn | 0:3ac96e360672 | 1076 | |
charlesmn | 0:3ac96e360672 | 1077 | case VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS: |
charlesmn | 0:3ac96e360672 | 1078 | vhv = LOWPOWER_AUTO_VHV_LOOP_DURATION_US; |
charlesmn | 0:3ac96e360672 | 1079 | VL53L1_get_tuning_parm(Dev, |
charlesmn | 0:3ac96e360672 | 1080 | VL53L1_TUNINGPARM_LOWPOWERAUTO_VHV_LOOP_BOUND, |
charlesmn | 0:3ac96e360672 | 1081 | &vhv_loops); |
charlesmn | 0:3ac96e360672 | 1082 | if (vhv_loops > 0) { |
charlesmn | 0:3ac96e360672 | 1083 | vhv += vhv_loops * |
charlesmn | 0:3ac96e360672 | 1084 | LOWPOWER_AUTO_VHV_LOOP_DURATION_US; |
charlesmn | 0:3ac96e360672 | 1085 | } |
charlesmn | 0:3ac96e360672 | 1086 | TimingGuard = LOWPOWER_AUTO_OVERHEAD_BEFORE_A_RANGING + |
charlesmn | 0:3ac96e360672 | 1087 | LOWPOWER_AUTO_OVERHEAD_BETWEEN_A_B_RANGING + |
charlesmn | 0:3ac96e360672 | 1088 | vhv; |
charlesmn | 0:3ac96e360672 | 1089 | MeasTimingBdg = 2 * RangeTimeoutUs + TimingGuard; |
charlesmn | 0:3ac96e360672 | 1090 | break; |
charlesmn | 0:3ac96e360672 | 1091 | |
charlesmn | 0:3ac96e360672 | 1092 | case VL53L1_PRESETMODE_RANGING: |
charlesmn | 0:3ac96e360672 | 1093 | case VL53L1_PRESETMODE_MULTIZONES_SCANNING: |
charlesmn | 0:3ac96e360672 | 1094 | case VL53L1_PRESETMODE_PROXY_RANGING_MODE: |
charlesmn | 0:3ac96e360672 | 1095 | MeasTimingBdg = (6 * RangeTimeoutUs) + 1700; |
charlesmn | 0:3ac96e360672 | 1096 | break; |
charlesmn | 0:3ac96e360672 | 1097 | |
charlesmn | 0:3ac96e360672 | 1098 | case VL53L1_PRESETMODE_OLT: |
charlesmn | 0:3ac96e360672 | 1099 | MeasTimingBdg = RangeTimeoutUs + MmTimeoutUs + 5000; |
charlesmn | 0:3ac96e360672 | 1100 | break; |
charlesmn | 0:3ac96e360672 | 1101 | default: |
charlesmn | 0:3ac96e360672 | 1102 | |
charlesmn | 0:3ac96e360672 | 1103 | Status = VL53L1_ERROR_MODE_NOT_SUPPORTED; |
charlesmn | 0:3ac96e360672 | 1104 | } |
charlesmn | 0:3ac96e360672 | 1105 | } |
charlesmn | 0:3ac96e360672 | 1106 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1107 | *pMeasurementTimingBudgetMicroSeconds = MeasTimingBdg; |
charlesmn | 0:3ac96e360672 | 1108 | |
charlesmn | 0:3ac96e360672 | 1109 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1110 | return Status; |
charlesmn | 0:3ac96e360672 | 1111 | } |
charlesmn | 0:3ac96e360672 | 1112 | |
charlesmn | 0:3ac96e360672 | 1113 | |
charlesmn | 0:3ac96e360672 | 1114 | |
charlesmn | 0:3ac96e360672 | 1115 | VL53L1_Error VL53L1_SetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1116 | uint32_t InterMeasurementPeriodMilliSeconds) |
charlesmn | 0:3ac96e360672 | 1117 | { |
charlesmn | 0:3ac96e360672 | 1118 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1119 | uint32_t adjustedIMP; |
charlesmn | 0:3ac96e360672 | 1120 | |
charlesmn | 0:3ac96e360672 | 1121 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1122 | |
charlesmn | 0:3ac96e360672 | 1123 | |
charlesmn | 0:3ac96e360672 | 1124 | adjustedIMP = InterMeasurementPeriodMilliSeconds; |
charlesmn | 0:3ac96e360672 | 1125 | adjustedIMP += (adjustedIMP * 64) / 1000; |
charlesmn | 0:3ac96e360672 | 1126 | |
charlesmn | 0:3ac96e360672 | 1127 | Status = VL53L1_set_inter_measurement_period_ms(Dev, |
charlesmn | 0:3ac96e360672 | 1128 | adjustedIMP); |
charlesmn | 0:3ac96e360672 | 1129 | |
charlesmn | 0:3ac96e360672 | 1130 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1131 | return Status; |
charlesmn | 0:3ac96e360672 | 1132 | } |
charlesmn | 0:3ac96e360672 | 1133 | |
charlesmn | 0:3ac96e360672 | 1134 | VL53L1_Error VL53L1_GetInterMeasurementPeriodMilliSeconds(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1135 | uint32_t *pInterMeasurementPeriodMilliSeconds) |
charlesmn | 0:3ac96e360672 | 1136 | { |
charlesmn | 0:3ac96e360672 | 1137 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1138 | uint32_t adjustedIMP; |
charlesmn | 0:3ac96e360672 | 1139 | |
charlesmn | 0:3ac96e360672 | 1140 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1141 | |
charlesmn | 0:3ac96e360672 | 1142 | Status = VL53L1_get_inter_measurement_period_ms(Dev, &adjustedIMP); |
charlesmn | 0:3ac96e360672 | 1143 | |
charlesmn | 0:3ac96e360672 | 1144 | adjustedIMP -= (adjustedIMP * 64) / 1000; |
charlesmn | 0:3ac96e360672 | 1145 | *pInterMeasurementPeriodMilliSeconds = adjustedIMP; |
charlesmn | 0:3ac96e360672 | 1146 | |
charlesmn | 0:3ac96e360672 | 1147 | |
charlesmn | 0:3ac96e360672 | 1148 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1149 | return Status; |
charlesmn | 0:3ac96e360672 | 1150 | } |
charlesmn | 0:3ac96e360672 | 1151 | |
charlesmn | 0:3ac96e360672 | 1152 | VL53L1_Error VL53L1_SetDmaxReflectance(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1153 | FixPoint1616_t DmaxReflectance) |
charlesmn | 0:3ac96e360672 | 1154 | { |
charlesmn | 0:3ac96e360672 | 1155 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1156 | VL53L1_dmax_reflectance_array_t dmax_reflectances; |
charlesmn | 0:3ac96e360672 | 1157 | |
charlesmn | 0:3ac96e360672 | 1158 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1159 | |
charlesmn | 0:3ac96e360672 | 1160 | if (DmaxReflectance > 100*65536) |
charlesmn | 0:3ac96e360672 | 1161 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1162 | |
charlesmn | 0:3ac96e360672 | 1163 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1164 | Status = VL53L1_get_dmax_reflectance_values(Dev, |
charlesmn | 0:3ac96e360672 | 1165 | &dmax_reflectances); |
charlesmn | 0:3ac96e360672 | 1166 | |
charlesmn | 0:3ac96e360672 | 1167 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1168 | dmax_reflectances.target_reflectance_for_dmax[ |
charlesmn | 0:3ac96e360672 | 1169 | DMAX_REFLECTANCE_IDX] = |
charlesmn | 0:3ac96e360672 | 1170 | VL53L1_FIXPOINT1616TOFIXPOINT72(DmaxReflectance); |
charlesmn | 0:3ac96e360672 | 1171 | Status = VL53L1_set_dmax_reflectance_values(Dev, |
charlesmn | 0:3ac96e360672 | 1172 | &dmax_reflectances); |
charlesmn | 0:3ac96e360672 | 1173 | } |
charlesmn | 0:3ac96e360672 | 1174 | |
charlesmn | 0:3ac96e360672 | 1175 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1176 | return Status; |
charlesmn | 0:3ac96e360672 | 1177 | } |
charlesmn | 0:3ac96e360672 | 1178 | |
charlesmn | 0:3ac96e360672 | 1179 | VL53L1_Error VL53L1_GetDmaxReflectance(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1180 | FixPoint1616_t *pDmaxReflectance) |
charlesmn | 0:3ac96e360672 | 1181 | { |
charlesmn | 0:3ac96e360672 | 1182 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1183 | VL53L1_dmax_reflectance_array_t dmax_reflectances; |
charlesmn | 0:3ac96e360672 | 1184 | uint16_t r; |
charlesmn | 0:3ac96e360672 | 1185 | |
charlesmn | 0:3ac96e360672 | 1186 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1187 | Status = VL53L1_get_dmax_reflectance_values(Dev, &dmax_reflectances); |
charlesmn | 0:3ac96e360672 | 1188 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1189 | r = dmax_reflectances.target_reflectance_for_dmax[ |
charlesmn | 0:3ac96e360672 | 1190 | DMAX_REFLECTANCE_IDX]; |
charlesmn | 0:3ac96e360672 | 1191 | *pDmaxReflectance = VL53L1_FIXPOINT72TOFIXPOINT1616(r); |
charlesmn | 0:3ac96e360672 | 1192 | } |
charlesmn | 0:3ac96e360672 | 1193 | |
charlesmn | 0:3ac96e360672 | 1194 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1195 | return Status; |
charlesmn | 0:3ac96e360672 | 1196 | } |
charlesmn | 0:3ac96e360672 | 1197 | |
charlesmn | 0:3ac96e360672 | 1198 | |
charlesmn | 0:3ac96e360672 | 1199 | VL53L1_Error VL53L1_SetDmaxMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1200 | VL53L1_DeviceDmaxModes DmaxMode) |
charlesmn | 0:3ac96e360672 | 1201 | { |
charlesmn | 0:3ac96e360672 | 1202 | |
charlesmn | 0:3ac96e360672 | 1203 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1204 | VL53L1_DeviceDmaxMode dmax_mode; |
charlesmn | 0:3ac96e360672 | 1205 | |
charlesmn | 0:3ac96e360672 | 1206 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1207 | |
charlesmn | 0:3ac96e360672 | 1208 | switch (DmaxMode) { |
charlesmn | 0:3ac96e360672 | 1209 | case VL53L1_DMAXMODE_FMT_CAL_DATA: |
charlesmn | 0:3ac96e360672 | 1210 | dmax_mode = VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA; |
charlesmn | 0:3ac96e360672 | 1211 | break; |
charlesmn | 0:3ac96e360672 | 1212 | case VL53L1_DMAXMODE_CUSTCAL_DATA: |
charlesmn | 0:3ac96e360672 | 1213 | dmax_mode = VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA; |
charlesmn | 0:3ac96e360672 | 1214 | break; |
charlesmn | 0:3ac96e360672 | 1215 | case VL53L1_DMAXMODE_PER_ZONE_CAL_DATA: |
charlesmn | 0:3ac96e360672 | 1216 | dmax_mode = VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA; |
charlesmn | 0:3ac96e360672 | 1217 | break; |
charlesmn | 0:3ac96e360672 | 1218 | default: |
charlesmn | 0:3ac96e360672 | 1219 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1220 | break; |
charlesmn | 0:3ac96e360672 | 1221 | } |
charlesmn | 0:3ac96e360672 | 1222 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1223 | Status = VL53L1_set_dmax_mode(Dev, dmax_mode); |
charlesmn | 0:3ac96e360672 | 1224 | |
charlesmn | 0:3ac96e360672 | 1225 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1226 | return Status; |
charlesmn | 0:3ac96e360672 | 1227 | } |
charlesmn | 0:3ac96e360672 | 1228 | |
charlesmn | 0:3ac96e360672 | 1229 | |
charlesmn | 0:3ac96e360672 | 1230 | VL53L1_Error VL53L1_GetDmaxMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1231 | VL53L1_DeviceDmaxModes *pDmaxMode) |
charlesmn | 0:3ac96e360672 | 1232 | { |
charlesmn | 0:3ac96e360672 | 1233 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1234 | VL53L1_DeviceDmaxMode dmax_mode; |
charlesmn | 0:3ac96e360672 | 1235 | |
charlesmn | 0:3ac96e360672 | 1236 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1237 | |
charlesmn | 0:3ac96e360672 | 1238 | Status = VL53L1_get_dmax_mode(Dev, &dmax_mode); |
charlesmn | 0:3ac96e360672 | 1239 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1240 | switch (dmax_mode) { |
charlesmn | 0:3ac96e360672 | 1241 | case VL53L1_DEVICEDMAXMODE__FMT_CAL_DATA: |
charlesmn | 0:3ac96e360672 | 1242 | *pDmaxMode = VL53L1_DMAXMODE_FMT_CAL_DATA; |
charlesmn | 0:3ac96e360672 | 1243 | break; |
charlesmn | 0:3ac96e360672 | 1244 | case VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA: |
charlesmn | 0:3ac96e360672 | 1245 | *pDmaxMode = VL53L1_DMAXMODE_CUSTCAL_DATA; |
charlesmn | 0:3ac96e360672 | 1246 | break; |
charlesmn | 0:3ac96e360672 | 1247 | case VL53L1_DEVICEDMAXMODE__PER_ZONE_CAL_DATA: |
charlesmn | 0:3ac96e360672 | 1248 | *pDmaxMode = VL53L1_DMAXMODE_PER_ZONE_CAL_DATA; |
charlesmn | 0:3ac96e360672 | 1249 | break; |
charlesmn | 0:3ac96e360672 | 1250 | default: |
charlesmn | 0:3ac96e360672 | 1251 | *pDmaxMode = VL53L1_DEVICEDMAXMODE__CUST_CAL_DATA; |
charlesmn | 0:3ac96e360672 | 1252 | Status = VL53L1_ERROR_NOT_IMPLEMENTED; |
charlesmn | 0:3ac96e360672 | 1253 | break; |
charlesmn | 0:3ac96e360672 | 1254 | } |
charlesmn | 0:3ac96e360672 | 1255 | } |
charlesmn | 0:3ac96e360672 | 1256 | |
charlesmn | 0:3ac96e360672 | 1257 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1258 | return Status; |
charlesmn | 0:3ac96e360672 | 1259 | } |
charlesmn | 0:3ac96e360672 | 1260 | |
charlesmn | 0:3ac96e360672 | 1261 | |
charlesmn | 0:3ac96e360672 | 1262 | |
charlesmn | 0:3ac96e360672 | 1263 | |
charlesmn | 0:3ac96e360672 | 1264 | |
charlesmn | 0:3ac96e360672 | 1265 | |
charlesmn | 0:3ac96e360672 | 1266 | VL53L1_Error VL53L1_GetNumberOfLimitCheck(uint16_t *pNumberOfLimitCheck) |
charlesmn | 0:3ac96e360672 | 1267 | { |
charlesmn | 0:3ac96e360672 | 1268 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1269 | |
charlesmn | 0:3ac96e360672 | 1270 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1271 | |
charlesmn | 0:3ac96e360672 | 1272 | *pNumberOfLimitCheck = VL53L1_CHECKENABLE_NUMBER_OF_CHECKS; |
charlesmn | 0:3ac96e360672 | 1273 | |
charlesmn | 0:3ac96e360672 | 1274 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1275 | return Status; |
charlesmn | 0:3ac96e360672 | 1276 | } |
charlesmn | 0:3ac96e360672 | 1277 | |
charlesmn | 0:3ac96e360672 | 1278 | VL53L1_Error VL53L1_GetLimitCheckInfo(uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1279 | char *pLimitCheckString) |
charlesmn | 0:3ac96e360672 | 1280 | { |
charlesmn | 0:3ac96e360672 | 1281 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1282 | |
charlesmn | 0:3ac96e360672 | 1283 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1284 | |
charlesmn | 0:3ac96e360672 | 1285 | Status = VL53L1_get_limit_check_info(LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1286 | pLimitCheckString); |
charlesmn | 0:3ac96e360672 | 1287 | |
charlesmn | 0:3ac96e360672 | 1288 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1289 | return Status; |
charlesmn | 0:3ac96e360672 | 1290 | } |
charlesmn | 0:3ac96e360672 | 1291 | |
charlesmn | 0:3ac96e360672 | 1292 | VL53L1_Error VL53L1_GetLimitCheckStatus(VL53L1_DEV Dev, uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1293 | uint8_t *pLimitCheckStatus) |
charlesmn | 0:3ac96e360672 | 1294 | { |
charlesmn | 0:3ac96e360672 | 1295 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1296 | uint8_t Temp8; |
charlesmn | 0:3ac96e360672 | 1297 | |
charlesmn | 0:3ac96e360672 | 1298 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1299 | |
charlesmn | 0:3ac96e360672 | 1300 | if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) { |
charlesmn | 0:3ac96e360672 | 1301 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1302 | } else { |
charlesmn | 0:3ac96e360672 | 1303 | VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksStatus, |
charlesmn | 0:3ac96e360672 | 1304 | LimitCheckId, Temp8); |
charlesmn | 0:3ac96e360672 | 1305 | *pLimitCheckStatus = Temp8; |
charlesmn | 0:3ac96e360672 | 1306 | } |
charlesmn | 0:3ac96e360672 | 1307 | |
charlesmn | 0:3ac96e360672 | 1308 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1309 | return Status; |
charlesmn | 0:3ac96e360672 | 1310 | } |
charlesmn | 0:3ac96e360672 | 1311 | |
charlesmn | 0:3ac96e360672 | 1312 | static VL53L1_Error SetLimitValue(VL53L1_DEV Dev, uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1313 | FixPoint1616_t value) |
charlesmn | 0:3ac96e360672 | 1314 | { |
charlesmn | 0:3ac96e360672 | 1315 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1316 | uint16_t tmpuint16; |
charlesmn | 0:3ac96e360672 | 1317 | |
charlesmn | 0:3ac96e360672 | 1318 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1319 | |
charlesmn | 0:3ac96e360672 | 1320 | switch (LimitCheckId) { |
charlesmn | 0:3ac96e360672 | 1321 | case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE: |
charlesmn | 0:3ac96e360672 | 1322 | tmpuint16 = VL53L1_FIXPOINT1616TOFIXPOINT142(value); |
charlesmn | 0:3ac96e360672 | 1323 | VL53L1_set_lite_sigma_threshold(Dev, tmpuint16); |
charlesmn | 0:3ac96e360672 | 1324 | break; |
charlesmn | 0:3ac96e360672 | 1325 | case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE: |
charlesmn | 0:3ac96e360672 | 1326 | tmpuint16 = VL53L1_FIXPOINT1616TOFIXPOINT97(value); |
charlesmn | 0:3ac96e360672 | 1327 | VL53L1_set_lite_min_count_rate(Dev, tmpuint16); |
charlesmn | 0:3ac96e360672 | 1328 | break; |
charlesmn | 0:3ac96e360672 | 1329 | default: |
charlesmn | 0:3ac96e360672 | 1330 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1331 | } |
charlesmn | 0:3ac96e360672 | 1332 | |
charlesmn | 0:3ac96e360672 | 1333 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1334 | return Status; |
charlesmn | 0:3ac96e360672 | 1335 | } |
charlesmn | 0:3ac96e360672 | 1336 | |
charlesmn | 0:3ac96e360672 | 1337 | |
charlesmn | 0:3ac96e360672 | 1338 | VL53L1_Error VL53L1_SetLimitCheckEnable(VL53L1_DEV Dev, uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1339 | uint8_t LimitCheckEnable) |
charlesmn | 0:3ac96e360672 | 1340 | { |
charlesmn | 0:3ac96e360672 | 1341 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1342 | FixPoint1616_t TempFix1616 = 0; |
charlesmn | 0:3ac96e360672 | 1343 | |
charlesmn | 0:3ac96e360672 | 1344 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1345 | |
charlesmn | 0:3ac96e360672 | 1346 | |
charlesmn | 0:3ac96e360672 | 1347 | if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) { |
charlesmn | 0:3ac96e360672 | 1348 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1349 | } else { |
charlesmn | 0:3ac96e360672 | 1350 | |
charlesmn | 0:3ac96e360672 | 1351 | if (LimitCheckEnable == 0) |
charlesmn | 0:3ac96e360672 | 1352 | TempFix1616 = 0; |
charlesmn | 0:3ac96e360672 | 1353 | else |
charlesmn | 0:3ac96e360672 | 1354 | VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue, |
charlesmn | 0:3ac96e360672 | 1355 | LimitCheckId, TempFix1616); |
charlesmn | 0:3ac96e360672 | 1356 | |
charlesmn | 0:3ac96e360672 | 1357 | Status = SetLimitValue(Dev, LimitCheckId, TempFix1616); |
charlesmn | 0:3ac96e360672 | 1358 | } |
charlesmn | 0:3ac96e360672 | 1359 | |
charlesmn | 0:3ac96e360672 | 1360 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1361 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 1362 | LimitChecksEnable, |
charlesmn | 0:3ac96e360672 | 1363 | LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1364 | ((LimitCheckEnable == 0) ? 0 : 1)); |
charlesmn | 0:3ac96e360672 | 1365 | |
charlesmn | 0:3ac96e360672 | 1366 | |
charlesmn | 0:3ac96e360672 | 1367 | |
charlesmn | 0:3ac96e360672 | 1368 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1369 | return Status; |
charlesmn | 0:3ac96e360672 | 1370 | } |
charlesmn | 0:3ac96e360672 | 1371 | |
charlesmn | 0:3ac96e360672 | 1372 | VL53L1_Error VL53L1_GetLimitCheckEnable(VL53L1_DEV Dev, uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1373 | uint8_t *pLimitCheckEnable) |
charlesmn | 0:3ac96e360672 | 1374 | { |
charlesmn | 0:3ac96e360672 | 1375 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1376 | uint8_t Temp8; |
charlesmn | 0:3ac96e360672 | 1377 | |
charlesmn | 0:3ac96e360672 | 1378 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1379 | |
charlesmn | 0:3ac96e360672 | 1380 | if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) { |
charlesmn | 0:3ac96e360672 | 1381 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1382 | *pLimitCheckEnable = 0; |
charlesmn | 0:3ac96e360672 | 1383 | } else { |
charlesmn | 0:3ac96e360672 | 1384 | VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable, |
charlesmn | 0:3ac96e360672 | 1385 | LimitCheckId, Temp8); |
charlesmn | 0:3ac96e360672 | 1386 | *pLimitCheckEnable = Temp8; |
charlesmn | 0:3ac96e360672 | 1387 | } |
charlesmn | 0:3ac96e360672 | 1388 | |
charlesmn | 0:3ac96e360672 | 1389 | |
charlesmn | 0:3ac96e360672 | 1390 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1391 | return Status; |
charlesmn | 0:3ac96e360672 | 1392 | } |
charlesmn | 0:3ac96e360672 | 1393 | |
charlesmn | 0:3ac96e360672 | 1394 | VL53L1_Error VL53L1_SetLimitCheckValue(VL53L1_DEV Dev, uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1395 | FixPoint1616_t LimitCheckValue) |
charlesmn | 0:3ac96e360672 | 1396 | { |
charlesmn | 0:3ac96e360672 | 1397 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1398 | uint8_t LimitChecksEnable; |
charlesmn | 0:3ac96e360672 | 1399 | |
charlesmn | 0:3ac96e360672 | 1400 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1401 | |
charlesmn | 0:3ac96e360672 | 1402 | if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) { |
charlesmn | 0:3ac96e360672 | 1403 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1404 | } else { |
charlesmn | 0:3ac96e360672 | 1405 | |
charlesmn | 0:3ac96e360672 | 1406 | VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable, |
charlesmn | 0:3ac96e360672 | 1407 | LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1408 | LimitChecksEnable); |
charlesmn | 0:3ac96e360672 | 1409 | |
charlesmn | 0:3ac96e360672 | 1410 | if (LimitChecksEnable == 0) { |
charlesmn | 0:3ac96e360672 | 1411 | |
charlesmn | 0:3ac96e360672 | 1412 | VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue, |
charlesmn | 0:3ac96e360672 | 1413 | LimitCheckId, LimitCheckValue); |
charlesmn | 0:3ac96e360672 | 1414 | } else { |
charlesmn | 0:3ac96e360672 | 1415 | |
charlesmn | 0:3ac96e360672 | 1416 | Status = SetLimitValue(Dev, LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1417 | LimitCheckValue); |
charlesmn | 0:3ac96e360672 | 1418 | |
charlesmn | 0:3ac96e360672 | 1419 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1420 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 1421 | LimitChecksValue, |
charlesmn | 0:3ac96e360672 | 1422 | LimitCheckId, LimitCheckValue); |
charlesmn | 0:3ac96e360672 | 1423 | } |
charlesmn | 0:3ac96e360672 | 1424 | } |
charlesmn | 0:3ac96e360672 | 1425 | } |
charlesmn | 0:3ac96e360672 | 1426 | |
charlesmn | 0:3ac96e360672 | 1427 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1428 | return Status; |
charlesmn | 0:3ac96e360672 | 1429 | } |
charlesmn | 0:3ac96e360672 | 1430 | |
charlesmn | 0:3ac96e360672 | 1431 | VL53L1_Error VL53L1_GetLimitCheckValue(VL53L1_DEV Dev, uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1432 | FixPoint1616_t *pLimitCheckValue) |
charlesmn | 0:3ac96e360672 | 1433 | { |
charlesmn | 0:3ac96e360672 | 1434 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1435 | uint16_t MinCountRate; |
charlesmn | 0:3ac96e360672 | 1436 | FixPoint1616_t TempFix1616; |
charlesmn | 0:3ac96e360672 | 1437 | uint16_t SigmaThresh; |
charlesmn | 0:3ac96e360672 | 1438 | |
charlesmn | 0:3ac96e360672 | 1439 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1440 | |
charlesmn | 0:3ac96e360672 | 1441 | switch (LimitCheckId) { |
charlesmn | 0:3ac96e360672 | 1442 | case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE: |
charlesmn | 0:3ac96e360672 | 1443 | Status = VL53L1_get_lite_sigma_threshold(Dev, &SigmaThresh); |
charlesmn | 0:3ac96e360672 | 1444 | TempFix1616 = VL53L1_FIXPOINT142TOFIXPOINT1616(SigmaThresh); |
charlesmn | 0:3ac96e360672 | 1445 | break; |
charlesmn | 0:3ac96e360672 | 1446 | case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE: |
charlesmn | 0:3ac96e360672 | 1447 | Status = VL53L1_get_lite_min_count_rate(Dev, &MinCountRate); |
charlesmn | 0:3ac96e360672 | 1448 | TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616(MinCountRate); |
charlesmn | 0:3ac96e360672 | 1449 | break; |
charlesmn | 0:3ac96e360672 | 1450 | default: |
charlesmn | 0:3ac96e360672 | 1451 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1452 | } |
charlesmn | 0:3ac96e360672 | 1453 | |
charlesmn | 0:3ac96e360672 | 1454 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1455 | |
charlesmn | 0:3ac96e360672 | 1456 | if (TempFix1616 == 0) { |
charlesmn | 0:3ac96e360672 | 1457 | |
charlesmn | 0:3ac96e360672 | 1458 | VL53L1_GETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 1459 | LimitChecksValue, LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1460 | TempFix1616); |
charlesmn | 0:3ac96e360672 | 1461 | *pLimitCheckValue = TempFix1616; |
charlesmn | 0:3ac96e360672 | 1462 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 1463 | LimitChecksEnable, LimitCheckId, 0); |
charlesmn | 0:3ac96e360672 | 1464 | } else { |
charlesmn | 0:3ac96e360672 | 1465 | *pLimitCheckValue = TempFix1616; |
charlesmn | 0:3ac96e360672 | 1466 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 1467 | LimitChecksValue, LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1468 | TempFix1616); |
charlesmn | 0:3ac96e360672 | 1469 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 1470 | LimitChecksEnable, LimitCheckId, 1); |
charlesmn | 0:3ac96e360672 | 1471 | } |
charlesmn | 0:3ac96e360672 | 1472 | } |
charlesmn | 0:3ac96e360672 | 1473 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1474 | return Status; |
charlesmn | 0:3ac96e360672 | 1475 | |
charlesmn | 0:3ac96e360672 | 1476 | } |
charlesmn | 0:3ac96e360672 | 1477 | |
charlesmn | 0:3ac96e360672 | 1478 | VL53L1_Error VL53L1_GetLimitCheckCurrent(VL53L1_DEV Dev, uint16_t LimitCheckId, |
charlesmn | 0:3ac96e360672 | 1479 | FixPoint1616_t *pLimitCheckCurrent) |
charlesmn | 0:3ac96e360672 | 1480 | { |
charlesmn | 0:3ac96e360672 | 1481 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1482 | FixPoint1616_t TempFix1616 = 0; |
charlesmn | 0:3ac96e360672 | 1483 | |
charlesmn | 0:3ac96e360672 | 1484 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1485 | |
charlesmn | 0:3ac96e360672 | 1486 | if (LimitCheckId >= VL53L1_CHECKENABLE_NUMBER_OF_CHECKS) { |
charlesmn | 0:3ac96e360672 | 1487 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1488 | } else { |
charlesmn | 0:3ac96e360672 | 1489 | VL53L1_GETARRAYPARAMETERFIELD(Dev, LimitChecksCurrent, |
charlesmn | 0:3ac96e360672 | 1490 | LimitCheckId, TempFix1616); |
charlesmn | 0:3ac96e360672 | 1491 | *pLimitCheckCurrent = TempFix1616; |
charlesmn | 0:3ac96e360672 | 1492 | } |
charlesmn | 0:3ac96e360672 | 1493 | |
charlesmn | 0:3ac96e360672 | 1494 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1495 | return Status; |
charlesmn | 0:3ac96e360672 | 1496 | |
charlesmn | 0:3ac96e360672 | 1497 | } |
charlesmn | 0:3ac96e360672 | 1498 | |
charlesmn | 0:3ac96e360672 | 1499 | |
charlesmn | 0:3ac96e360672 | 1500 | |
charlesmn | 0:3ac96e360672 | 1501 | |
charlesmn | 0:3ac96e360672 | 1502 | |
charlesmn | 0:3ac96e360672 | 1503 | |
charlesmn | 0:3ac96e360672 | 1504 | |
charlesmn | 0:3ac96e360672 | 1505 | |
charlesmn | 0:3ac96e360672 | 1506 | VL53L1_Error VL53L1_GetMaxNumberOfROI(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1507 | uint8_t *pMaxNumberOfROI) |
charlesmn | 0:3ac96e360672 | 1508 | { |
charlesmn | 0:3ac96e360672 | 1509 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1510 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 1511 | |
charlesmn | 0:3ac96e360672 | 1512 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1513 | |
charlesmn | 0:3ac96e360672 | 1514 | PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 1515 | |
charlesmn | 0:3ac96e360672 | 1516 | |
charlesmn | 0:3ac96e360672 | 1517 | if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) |
charlesmn | 0:3ac96e360672 | 1518 | *pMaxNumberOfROI = VL53L1_MAX_USER_ZONES; |
charlesmn | 0:3ac96e360672 | 1519 | else |
charlesmn | 0:3ac96e360672 | 1520 | *pMaxNumberOfROI = 1; |
charlesmn | 0:3ac96e360672 | 1521 | |
charlesmn | 0:3ac96e360672 | 1522 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1523 | return Status; |
charlesmn | 0:3ac96e360672 | 1524 | } |
charlesmn | 0:3ac96e360672 | 1525 | |
charlesmn | 0:3ac96e360672 | 1526 | VL53L1_Error VL53L1_SetROI(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1527 | VL53L1_RoiConfig_t *pRoiConfig) |
charlesmn | 0:3ac96e360672 | 1528 | { |
charlesmn | 0:3ac96e360672 | 1529 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1530 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 1531 | uint8_t MaxNumberOfROI = 1; |
charlesmn | 0:3ac96e360672 | 1532 | VL53L1_zone_config_t zone_cfg; |
charlesmn | 0:3ac96e360672 | 1533 | VL53L1_UserRoi_t CurrROI; |
charlesmn | 0:3ac96e360672 | 1534 | uint8_t i; |
charlesmn | 0:3ac96e360672 | 1535 | uint8_t x_centre; |
charlesmn | 0:3ac96e360672 | 1536 | uint8_t y_centre; |
charlesmn | 0:3ac96e360672 | 1537 | uint8_t width, height; |
charlesmn | 0:3ac96e360672 | 1538 | |
charlesmn | 0:3ac96e360672 | 1539 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1540 | |
charlesmn | 0:3ac96e360672 | 1541 | |
charlesmn | 0:3ac96e360672 | 1542 | PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 1543 | |
charlesmn | 0:3ac96e360672 | 1544 | |
charlesmn | 0:3ac96e360672 | 1545 | if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) |
charlesmn | 0:3ac96e360672 | 1546 | MaxNumberOfROI = VL53L1_MAX_USER_ZONES; |
charlesmn | 0:3ac96e360672 | 1547 | |
charlesmn | 0:3ac96e360672 | 1548 | if ((pRoiConfig->NumberOfRoi > MaxNumberOfROI) || |
charlesmn | 0:3ac96e360672 | 1549 | (pRoiConfig->NumberOfRoi < 1)) |
charlesmn | 0:3ac96e360672 | 1550 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1551 | |
charlesmn | 0:3ac96e360672 | 1552 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1553 | |
charlesmn | 0:3ac96e360672 | 1554 | |
charlesmn | 0:3ac96e360672 | 1555 | zone_cfg.max_zones = MaxNumberOfROI; |
charlesmn | 0:3ac96e360672 | 1556 | zone_cfg.active_zones = pRoiConfig->NumberOfRoi - 1; |
charlesmn | 0:3ac96e360672 | 1557 | |
charlesmn | 0:3ac96e360672 | 1558 | for (i = 0; i < pRoiConfig->NumberOfRoi; i++) { |
charlesmn | 0:3ac96e360672 | 1559 | CurrROI = pRoiConfig->UserRois[i]; |
charlesmn | 0:3ac96e360672 | 1560 | |
charlesmn | 0:3ac96e360672 | 1561 | Status = CheckValidRectRoi(CurrROI); |
charlesmn | 0:3ac96e360672 | 1562 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1563 | break; |
charlesmn | 0:3ac96e360672 | 1564 | |
charlesmn | 0:3ac96e360672 | 1565 | x_centre = (CurrROI.BotRightX + CurrROI.TopLeftX + 1) |
charlesmn | 0:3ac96e360672 | 1566 | / 2; |
charlesmn | 0:3ac96e360672 | 1567 | y_centre = (CurrROI.TopLeftY + CurrROI.BotRightY + 1) |
charlesmn | 0:3ac96e360672 | 1568 | / 2; |
charlesmn | 0:3ac96e360672 | 1569 | width = (CurrROI.BotRightX - CurrROI.TopLeftX); |
charlesmn | 0:3ac96e360672 | 1570 | height = (CurrROI.TopLeftY - CurrROI.BotRightY); |
charlesmn | 0:3ac96e360672 | 1571 | if ((width < 3) || (height < 3)) { |
charlesmn | 0:3ac96e360672 | 1572 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1573 | break; |
charlesmn | 0:3ac96e360672 | 1574 | } |
charlesmn | 0:3ac96e360672 | 1575 | zone_cfg.user_zones[i].x_centre = x_centre; |
charlesmn | 0:3ac96e360672 | 1576 | zone_cfg.user_zones[i].y_centre = y_centre; |
charlesmn | 0:3ac96e360672 | 1577 | zone_cfg.user_zones[i].width = width; |
charlesmn | 0:3ac96e360672 | 1578 | zone_cfg.user_zones[i].height = height; |
charlesmn | 0:3ac96e360672 | 1579 | } |
charlesmn | 0:3ac96e360672 | 1580 | } |
charlesmn | 0:3ac96e360672 | 1581 | |
charlesmn | 0:3ac96e360672 | 1582 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1583 | Status = VL53L1_set_zone_config(Dev, &zone_cfg); |
charlesmn | 0:3ac96e360672 | 1584 | |
charlesmn | 0:3ac96e360672 | 1585 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1586 | return Status; |
charlesmn | 0:3ac96e360672 | 1587 | } |
charlesmn | 0:3ac96e360672 | 1588 | |
charlesmn | 0:3ac96e360672 | 1589 | VL53L1_Error VL53L1_GetROI(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1590 | VL53L1_RoiConfig_t *pRoiConfig) |
charlesmn | 0:3ac96e360672 | 1591 | { |
charlesmn | 0:3ac96e360672 | 1592 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1593 | VL53L1_zone_config_t zone_cfg; |
charlesmn | 0:3ac96e360672 | 1594 | uint8_t i; |
charlesmn | 0:3ac96e360672 | 1595 | uint8_t TopLeftX; |
charlesmn | 0:3ac96e360672 | 1596 | uint8_t TopLeftY; |
charlesmn | 0:3ac96e360672 | 1597 | uint8_t BotRightX; |
charlesmn | 0:3ac96e360672 | 1598 | uint8_t BotRightY; |
charlesmn | 0:3ac96e360672 | 1599 | |
charlesmn | 0:3ac96e360672 | 1600 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1601 | |
charlesmn | 0:3ac96e360672 | 1602 | VL53L1_get_zone_config(Dev, &zone_cfg); |
charlesmn | 0:3ac96e360672 | 1603 | |
charlesmn | 0:3ac96e360672 | 1604 | pRoiConfig->NumberOfRoi = zone_cfg.active_zones + 1; |
charlesmn | 0:3ac96e360672 | 1605 | |
charlesmn | 0:3ac96e360672 | 1606 | for (i = 0; i < pRoiConfig->NumberOfRoi; i++) { |
charlesmn | 0:3ac96e360672 | 1607 | TopLeftX = (2 * zone_cfg.user_zones[i].x_centre - |
charlesmn | 0:3ac96e360672 | 1608 | zone_cfg.user_zones[i].width) >> 1; |
charlesmn | 0:3ac96e360672 | 1609 | TopLeftY = (2 * zone_cfg.user_zones[i].y_centre + |
charlesmn | 0:3ac96e360672 | 1610 | zone_cfg.user_zones[i].height) >> 1; |
charlesmn | 0:3ac96e360672 | 1611 | BotRightX = (2 * zone_cfg.user_zones[i].x_centre + |
charlesmn | 0:3ac96e360672 | 1612 | zone_cfg.user_zones[i].width) >> 1; |
charlesmn | 0:3ac96e360672 | 1613 | BotRightY = (2 * zone_cfg.user_zones[i].y_centre - |
charlesmn | 0:3ac96e360672 | 1614 | zone_cfg.user_zones[i].height) >> 1; |
charlesmn | 0:3ac96e360672 | 1615 | pRoiConfig->UserRois[i].TopLeftX = TopLeftX; |
charlesmn | 0:3ac96e360672 | 1616 | pRoiConfig->UserRois[i].TopLeftY = TopLeftY; |
charlesmn | 0:3ac96e360672 | 1617 | pRoiConfig->UserRois[i].BotRightX = BotRightX; |
charlesmn | 0:3ac96e360672 | 1618 | pRoiConfig->UserRois[i].BotRightY = BotRightY; |
charlesmn | 0:3ac96e360672 | 1619 | } |
charlesmn | 0:3ac96e360672 | 1620 | |
charlesmn | 0:3ac96e360672 | 1621 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1622 | return Status; |
charlesmn | 0:3ac96e360672 | 1623 | } |
charlesmn | 0:3ac96e360672 | 1624 | |
charlesmn | 0:3ac96e360672 | 1625 | |
charlesmn | 0:3ac96e360672 | 1626 | |
charlesmn | 0:3ac96e360672 | 1627 | |
charlesmn | 0:3ac96e360672 | 1628 | |
charlesmn | 0:3ac96e360672 | 1629 | |
charlesmn | 0:3ac96e360672 | 1630 | |
charlesmn | 0:3ac96e360672 | 1631 | VL53L1_Error VL53L1_GetNumberOfSequenceSteps(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1632 | uint8_t *pNumberOfSequenceSteps) |
charlesmn | 0:3ac96e360672 | 1633 | { |
charlesmn | 0:3ac96e360672 | 1634 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1635 | |
charlesmn | 0:3ac96e360672 | 1636 | SUPPRESS_UNUSED_WARNING(Dev); |
charlesmn | 0:3ac96e360672 | 1637 | |
charlesmn | 0:3ac96e360672 | 1638 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1639 | |
charlesmn | 0:3ac96e360672 | 1640 | *pNumberOfSequenceSteps = VL53L1_SEQUENCESTEP_NUMBER_OF_ITEMS; |
charlesmn | 0:3ac96e360672 | 1641 | |
charlesmn | 0:3ac96e360672 | 1642 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1643 | return Status; |
charlesmn | 0:3ac96e360672 | 1644 | } |
charlesmn | 0:3ac96e360672 | 1645 | |
charlesmn | 0:3ac96e360672 | 1646 | VL53L1_Error VL53L1_GetSequenceStepsInfo(VL53L1_SequenceStepId SequenceStepId, |
charlesmn | 0:3ac96e360672 | 1647 | char *pSequenceStepsString) |
charlesmn | 0:3ac96e360672 | 1648 | { |
charlesmn | 0:3ac96e360672 | 1649 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1650 | |
charlesmn | 0:3ac96e360672 | 1651 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1652 | |
charlesmn | 0:3ac96e360672 | 1653 | Status = VL53L1_get_sequence_steps_info( |
charlesmn | 0:3ac96e360672 | 1654 | SequenceStepId, |
charlesmn | 0:3ac96e360672 | 1655 | pSequenceStepsString); |
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 | VL53L1_Error VL53L1_SetSequenceStepEnable(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1663 | VL53L1_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled) |
charlesmn | 0:3ac96e360672 | 1664 | { |
charlesmn | 0:3ac96e360672 | 1665 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1666 | uint32_t MeasurementTimingBudgetMicroSeconds; |
charlesmn | 0:3ac96e360672 | 1667 | |
charlesmn | 0:3ac96e360672 | 1668 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1669 | |
charlesmn | 0:3ac96e360672 | 1670 | |
charlesmn | 0:3ac96e360672 | 1671 | |
charlesmn | 0:3ac96e360672 | 1672 | Status = VL53L1_set_sequence_config_bit(Dev, |
charlesmn | 0:3ac96e360672 | 1673 | (VL53L1_DeviceSequenceConfig)SequenceStepId, |
charlesmn | 0:3ac96e360672 | 1674 | SequenceStepEnabled); |
charlesmn | 0:3ac96e360672 | 1675 | |
charlesmn | 0:3ac96e360672 | 1676 | |
charlesmn | 0:3ac96e360672 | 1677 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 1678 | |
charlesmn | 0:3ac96e360672 | 1679 | |
charlesmn | 0:3ac96e360672 | 1680 | MeasurementTimingBudgetMicroSeconds = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 1681 | CurrentParameters.MeasurementTimingBudgetMicroSeconds); |
charlesmn | 0:3ac96e360672 | 1682 | |
charlesmn | 0:3ac96e360672 | 1683 | VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, |
charlesmn | 0:3ac96e360672 | 1684 | MeasurementTimingBudgetMicroSeconds); |
charlesmn | 0:3ac96e360672 | 1685 | } |
charlesmn | 0:3ac96e360672 | 1686 | |
charlesmn | 0:3ac96e360672 | 1687 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1688 | |
charlesmn | 0:3ac96e360672 | 1689 | return Status; |
charlesmn | 0:3ac96e360672 | 1690 | } |
charlesmn | 0:3ac96e360672 | 1691 | |
charlesmn | 0:3ac96e360672 | 1692 | |
charlesmn | 0:3ac96e360672 | 1693 | VL53L1_Error VL53L1_GetSequenceStepEnable(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1694 | VL53L1_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled) |
charlesmn | 0:3ac96e360672 | 1695 | { |
charlesmn | 0:3ac96e360672 | 1696 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1697 | |
charlesmn | 0:3ac96e360672 | 1698 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1699 | |
charlesmn | 0:3ac96e360672 | 1700 | Status = VL53L1_get_sequence_config_bit(Dev, |
charlesmn | 0:3ac96e360672 | 1701 | (VL53L1_DeviceSequenceConfig)SequenceStepId, |
charlesmn | 0:3ac96e360672 | 1702 | pSequenceStepEnabled); |
charlesmn | 0:3ac96e360672 | 1703 | |
charlesmn | 0:3ac96e360672 | 1704 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1705 | return Status; |
charlesmn | 0:3ac96e360672 | 1706 | } |
charlesmn | 0:3ac96e360672 | 1707 | |
charlesmn | 0:3ac96e360672 | 1708 | |
charlesmn | 0:3ac96e360672 | 1709 | |
charlesmn | 0:3ac96e360672 | 1710 | |
charlesmn | 0:3ac96e360672 | 1711 | |
charlesmn | 0:3ac96e360672 | 1712 | |
charlesmn | 0:3ac96e360672 | 1713 | |
charlesmn | 0:3ac96e360672 | 1714 | |
charlesmn | 0:3ac96e360672 | 1715 | |
charlesmn | 0:3ac96e360672 | 1716 | |
charlesmn | 0:3ac96e360672 | 1717 | VL53L1_Error VL53L1_StartMeasurement(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 1718 | { |
charlesmn | 0:3ac96e360672 | 1719 | #define TIMED_MODE_TIMING_GUARD_MILLISECONDS 4 |
charlesmn | 0:3ac96e360672 | 1720 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1721 | uint8_t DeviceMeasurementMode; |
charlesmn | 0:3ac96e360672 | 1722 | VL53L1_State CurrPalState; |
charlesmn | 0:3ac96e360672 | 1723 | VL53L1_Error lStatus; |
charlesmn | 0:3ac96e360672 | 1724 | uint32_t MTBus, IMPms; |
charlesmn | 0:3ac96e360672 | 1725 | uint8_t i; |
charlesmn | 0:3ac96e360672 | 1726 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1727 | |
charlesmn | 0:3ac96e360672 | 1728 | |
charlesmn | 0:3ac96e360672 | 1729 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1730 | VL53L1_load_patch(Dev); |
charlesmn | 0:3ac96e360672 | 1731 | for (i = 0; i < VL53L1_MAX_RANGE_RESULTS; i++) { |
charlesmn | 0:3ac96e360672 | 1732 | pdev->PreviousRangeMilliMeter[i] = 0; |
charlesmn | 0:3ac96e360672 | 1733 | pdev->PreviousRangeStatus[i] = 255; |
charlesmn | 0:3ac96e360672 | 1734 | pdev->PreviousExtendedRange[i] = 0; |
charlesmn | 0:3ac96e360672 | 1735 | } |
charlesmn | 0:3ac96e360672 | 1736 | pdev->PreviousStreamCount = 0; |
charlesmn | 0:3ac96e360672 | 1737 | CurrPalState = VL53L1DevDataGet(Dev, PalState); |
charlesmn | 0:3ac96e360672 | 1738 | switch (CurrPalState) { |
charlesmn | 0:3ac96e360672 | 1739 | case VL53L1_STATE_IDLE: |
charlesmn | 0:3ac96e360672 | 1740 | Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1741 | break; |
charlesmn | 0:3ac96e360672 | 1742 | case VL53L1_STATE_POWERDOWN: |
charlesmn | 0:3ac96e360672 | 1743 | case VL53L1_STATE_WAIT_STATICINIT: |
charlesmn | 0:3ac96e360672 | 1744 | case VL53L1_STATE_STANDBY: |
charlesmn | 0:3ac96e360672 | 1745 | case VL53L1_STATE_RUNNING: |
charlesmn | 0:3ac96e360672 | 1746 | case VL53L1_STATE_RESET: |
charlesmn | 0:3ac96e360672 | 1747 | case VL53L1_STATE_UNKNOWN: |
charlesmn | 0:3ac96e360672 | 1748 | case VL53L1_STATE_ERROR: |
charlesmn | 0:3ac96e360672 | 1749 | Status = VL53L1_ERROR_INVALID_COMMAND; |
charlesmn | 0:3ac96e360672 | 1750 | break; |
charlesmn | 0:3ac96e360672 | 1751 | default: |
charlesmn | 0:3ac96e360672 | 1752 | Status = VL53L1_ERROR_UNDEFINED; |
charlesmn | 0:3ac96e360672 | 1753 | } |
charlesmn | 0:3ac96e360672 | 1754 | |
charlesmn | 0:3ac96e360672 | 1755 | DeviceMeasurementMode = VL53L1DevDataGet(Dev, LLData.measurement_mode); |
charlesmn | 0:3ac96e360672 | 1756 | |
charlesmn | 0:3ac96e360672 | 1757 | |
charlesmn | 0:3ac96e360672 | 1758 | if ((Status == VL53L1_ERROR_NONE) && |
charlesmn | 0:3ac96e360672 | 1759 | (DeviceMeasurementMode == VL53L1_DEVICEMEASUREMENTMODE_TIMED)) { |
charlesmn | 0:3ac96e360672 | 1760 | lStatus = VL53L1_GetMeasurementTimingBudgetMicroSeconds(Dev, |
charlesmn | 0:3ac96e360672 | 1761 | &MTBus); |
charlesmn | 0:3ac96e360672 | 1762 | |
charlesmn | 0:3ac96e360672 | 1763 | MTBus /= 1000; |
charlesmn | 0:3ac96e360672 | 1764 | lStatus = VL53L1_GetInterMeasurementPeriodMilliSeconds(Dev, |
charlesmn | 0:3ac96e360672 | 1765 | &IMPms); |
charlesmn | 0:3ac96e360672 | 1766 | |
charlesmn | 0:3ac96e360672 | 1767 | SUPPRESS_UNUSED_WARNING(lStatus); |
charlesmn | 0:3ac96e360672 | 1768 | if (IMPms < MTBus + TIMED_MODE_TIMING_GUARD_MILLISECONDS) |
charlesmn | 0:3ac96e360672 | 1769 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 1770 | } |
charlesmn | 0:3ac96e360672 | 1771 | |
charlesmn | 0:3ac96e360672 | 1772 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1773 | Status = VL53L1_init_and_start_range( |
charlesmn | 0:3ac96e360672 | 1774 | Dev, |
charlesmn | 0:3ac96e360672 | 1775 | DeviceMeasurementMode, |
charlesmn | 0:3ac96e360672 | 1776 | VL53L1_DEVICECONFIGLEVEL_FULL); |
charlesmn | 0:3ac96e360672 | 1777 | |
charlesmn | 0:3ac96e360672 | 1778 | |
charlesmn | 0:3ac96e360672 | 1779 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1780 | VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_RUNNING); |
charlesmn | 0:3ac96e360672 | 1781 | |
charlesmn | 0:3ac96e360672 | 1782 | |
charlesmn | 0:3ac96e360672 | 1783 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1784 | return Status; |
charlesmn | 0:3ac96e360672 | 1785 | } |
charlesmn | 0:3ac96e360672 | 1786 | |
charlesmn | 0:3ac96e360672 | 1787 | VL53L1_Error VL53L1_StopMeasurement(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 1788 | { |
charlesmn | 0:3ac96e360672 | 1789 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1790 | |
charlesmn | 0:3ac96e360672 | 1791 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1792 | |
charlesmn | 0:3ac96e360672 | 1793 | Status = VL53L1_stop_range(Dev); |
charlesmn | 0:3ac96e360672 | 1794 | VL53L1_unload_patch(Dev); |
charlesmn | 0:3ac96e360672 | 1795 | |
charlesmn | 0:3ac96e360672 | 1796 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 1797 | VL53L1DevDataSet(Dev, PalState, VL53L1_STATE_IDLE); |
charlesmn | 0:3ac96e360672 | 1798 | |
charlesmn | 0:3ac96e360672 | 1799 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1800 | return Status; |
charlesmn | 0:3ac96e360672 | 1801 | } |
charlesmn | 0:3ac96e360672 | 1802 | |
charlesmn | 0:3ac96e360672 | 1803 | |
charlesmn | 0:3ac96e360672 | 1804 | VL53L1_Error VL53L1_ClearInterruptAndStartMeasurement(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 1805 | { |
charlesmn | 0:3ac96e360672 | 1806 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1807 | uint8_t DeviceMeasurementMode; |
charlesmn | 0:3ac96e360672 | 1808 | |
charlesmn | 0:3ac96e360672 | 1809 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1810 | |
charlesmn | 0:3ac96e360672 | 1811 | DeviceMeasurementMode = VL53L1DevDataGet(Dev, LLData.measurement_mode); |
charlesmn | 0:3ac96e360672 | 1812 | |
charlesmn | 0:3ac96e360672 | 1813 | Status = VL53L1_clear_interrupt_and_enable_next_range(Dev, |
charlesmn | 0:3ac96e360672 | 1814 | DeviceMeasurementMode); |
charlesmn | 0:3ac96e360672 | 1815 | |
charlesmn | 0:3ac96e360672 | 1816 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1817 | return Status; |
charlesmn | 0:3ac96e360672 | 1818 | } |
charlesmn | 0:3ac96e360672 | 1819 | |
charlesmn | 0:3ac96e360672 | 1820 | |
charlesmn | 0:3ac96e360672 | 1821 | VL53L1_Error VL53L1_GetMeasurementDataReady(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1822 | uint8_t *pMeasurementDataReady) |
charlesmn | 0:3ac96e360672 | 1823 | { |
charlesmn | 0:3ac96e360672 | 1824 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1825 | |
charlesmn | 0:3ac96e360672 | 1826 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1827 | |
charlesmn | 0:3ac96e360672 | 1828 | Status = VL53L1_is_new_data_ready(Dev, pMeasurementDataReady); |
charlesmn | 0:3ac96e360672 | 1829 | |
charlesmn | 0:3ac96e360672 | 1830 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1831 | return Status; |
charlesmn | 0:3ac96e360672 | 1832 | } |
charlesmn | 0:3ac96e360672 | 1833 | |
charlesmn | 0:3ac96e360672 | 1834 | VL53L1_Error VL53L1_WaitMeasurementDataReady(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 1835 | { |
charlesmn | 0:3ac96e360672 | 1836 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 1837 | |
charlesmn | 0:3ac96e360672 | 1838 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 1839 | |
charlesmn | 0:3ac96e360672 | 1840 | |
charlesmn | 0:3ac96e360672 | 1841 | |
charlesmn | 0:3ac96e360672 | 1842 | Status = VL53L1_poll_for_range_completion(Dev, |
charlesmn | 0:3ac96e360672 | 1843 | VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS); |
charlesmn | 0:3ac96e360672 | 1844 | |
charlesmn | 0:3ac96e360672 | 1845 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 1846 | return Status; |
charlesmn | 0:3ac96e360672 | 1847 | } |
charlesmn | 0:3ac96e360672 | 1848 | |
charlesmn | 0:3ac96e360672 | 1849 | static void GenNewPresetMode(int16_t RefRange, |
charlesmn | 0:3ac96e360672 | 1850 | VL53L1_DistanceModes InternalDistanceMode, |
charlesmn | 0:3ac96e360672 | 1851 | VL53L1_DistanceModes *pNewDistanceMode) |
charlesmn | 0:3ac96e360672 | 1852 | { |
charlesmn | 0:3ac96e360672 | 1853 | uint16_t HRLI = 600; |
charlesmn | 0:3ac96e360672 | 1854 | uint16_t HRLH = 700; |
charlesmn | 0:3ac96e360672 | 1855 | uint16_t MRLI = 1400; |
charlesmn | 0:3ac96e360672 | 1856 | uint16_t MRLH = 1500; |
charlesmn | 0:3ac96e360672 | 1857 | |
charlesmn | 0:3ac96e360672 | 1858 | switch (InternalDistanceMode) { |
charlesmn | 0:3ac96e360672 | 1859 | case VL53L1_DISTANCEMODE_SHORT: |
charlesmn | 0:3ac96e360672 | 1860 | |
charlesmn | 0:3ac96e360672 | 1861 | if (RefRange > MRLH) |
charlesmn | 0:3ac96e360672 | 1862 | *pNewDistanceMode = VL53L1_DISTANCEMODE_LONG; |
charlesmn | 0:3ac96e360672 | 1863 | else if (RefRange > HRLH) |
charlesmn | 0:3ac96e360672 | 1864 | *pNewDistanceMode = VL53L1_DISTANCEMODE_MEDIUM; |
charlesmn | 0:3ac96e360672 | 1865 | break; |
charlesmn | 0:3ac96e360672 | 1866 | case VL53L1_DISTANCEMODE_MEDIUM: |
charlesmn | 0:3ac96e360672 | 1867 | |
charlesmn | 0:3ac96e360672 | 1868 | if (RefRange > MRLH) |
charlesmn | 0:3ac96e360672 | 1869 | *pNewDistanceMode = VL53L1_DISTANCEMODE_LONG; |
charlesmn | 0:3ac96e360672 | 1870 | else if (RefRange < HRLI) |
charlesmn | 0:3ac96e360672 | 1871 | *pNewDistanceMode = VL53L1_DISTANCEMODE_SHORT; |
charlesmn | 0:3ac96e360672 | 1872 | break; |
charlesmn | 0:3ac96e360672 | 1873 | default: |
charlesmn | 0:3ac96e360672 | 1874 | |
charlesmn | 0:3ac96e360672 | 1875 | if (RefRange < HRLI) |
charlesmn | 0:3ac96e360672 | 1876 | *pNewDistanceMode = VL53L1_DISTANCEMODE_SHORT; |
charlesmn | 0:3ac96e360672 | 1877 | else if (RefRange < MRLI) |
charlesmn | 0:3ac96e360672 | 1878 | *pNewDistanceMode = VL53L1_DISTANCEMODE_MEDIUM; |
charlesmn | 0:3ac96e360672 | 1879 | break; |
charlesmn | 0:3ac96e360672 | 1880 | } |
charlesmn | 0:3ac96e360672 | 1881 | } |
charlesmn | 0:3ac96e360672 | 1882 | |
charlesmn | 0:3ac96e360672 | 1883 | static void CheckAndChangeDistanceMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 1884 | VL53L1_TargetRangeData_t *pRangeData, |
charlesmn | 0:3ac96e360672 | 1885 | int16_t Ambient100DmaxMm, |
charlesmn | 0:3ac96e360672 | 1886 | VL53L1_DistanceModes *pNewDistanceMode |
charlesmn | 0:3ac96e360672 | 1887 | ) |
charlesmn | 0:3ac96e360672 | 1888 | { |
charlesmn | 0:3ac96e360672 | 1889 | VL53L1_DistanceModes DistanceMode; |
charlesmn | 0:3ac96e360672 | 1890 | uint8_t RangeStatus = pRangeData->RangeStatus; |
charlesmn | 0:3ac96e360672 | 1891 | uint8_t DmaxValid; |
charlesmn | 0:3ac96e360672 | 1892 | int32_t MinAmbient = BDTable[VL53L1_TUNING_MIN_AMBIENT_DMAX_VALID]; |
charlesmn | 0:3ac96e360672 | 1893 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 1894 | int32_t tmpint32; |
charlesmn | 0:3ac96e360672 | 1895 | |
charlesmn | 0:3ac96e360672 | 1896 | |
charlesmn | 0:3ac96e360672 | 1897 | switch (RangeStatus) { |
charlesmn | 0:3ac96e360672 | 1898 | case VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL: |
charlesmn | 0:3ac96e360672 | 1899 | case VL53L1_RANGESTATUS_WRAP_TARGET_FAIL: |
charlesmn | 0:3ac96e360672 | 1900 | case VL53L1_RANGESTATUS_RANGE_VALID_MERGED_PULSE: |
charlesmn | 0:3ac96e360672 | 1901 | case VL53L1_RANGESTATUS_TARGET_PRESENT_LACK_OF_SIGNAL: |
charlesmn | 0:3ac96e360672 | 1902 | case VL53L1_RANGESTATUS_SYNCRONISATION_INT: |
charlesmn | 0:3ac96e360672 | 1903 | case VL53L1_RANGESTATUS_NONE: |
charlesmn | 0:3ac96e360672 | 1904 | return; |
charlesmn | 0:3ac96e360672 | 1905 | default: |
charlesmn | 0:3ac96e360672 | 1906 | |
charlesmn | 0:3ac96e360672 | 1907 | break; |
charlesmn | 0:3ac96e360672 | 1908 | } |
charlesmn | 0:3ac96e360672 | 1909 | |
charlesmn | 0:3ac96e360672 | 1910 | DmaxValid = 1; |
charlesmn | 0:3ac96e360672 | 1911 | tmpint32 = pdev->hist_data.VL53L1_p_004; |
charlesmn | 0:3ac96e360672 | 1912 | if ((tmpint32 < MinAmbient) || (Ambient100DmaxMm == 0)) |
charlesmn | 0:3ac96e360672 | 1913 | DmaxValid = 0; |
charlesmn | 0:3ac96e360672 | 1914 | |
charlesmn | 0:3ac96e360672 | 1915 | DistanceMode = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 1916 | CurrentParameters.DistanceMode); |
charlesmn | 0:3ac96e360672 | 1917 | |
charlesmn | 0:3ac96e360672 | 1918 | *pNewDistanceMode = DistanceMode; |
charlesmn | 0:3ac96e360672 | 1919 | |
charlesmn | 0:3ac96e360672 | 1920 | if (RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) |
charlesmn | 0:3ac96e360672 | 1921 | GenNewPresetMode(pRangeData->RangeMilliMeter, |
charlesmn | 0:3ac96e360672 | 1922 | DistanceMode, pNewDistanceMode); |
charlesmn | 0:3ac96e360672 | 1923 | else { |
charlesmn | 0:3ac96e360672 | 1924 | if (DmaxValid) |
charlesmn | 0:3ac96e360672 | 1925 | GenNewPresetMode(Ambient100DmaxMm, |
charlesmn | 0:3ac96e360672 | 1926 | DistanceMode, pNewDistanceMode); |
charlesmn | 0:3ac96e360672 | 1927 | else |
charlesmn | 0:3ac96e360672 | 1928 | *pNewDistanceMode = VL53L1_DISTANCEMODE_LONG; |
charlesmn | 0:3ac96e360672 | 1929 | } |
charlesmn | 0:3ac96e360672 | 1930 | } |
charlesmn | 0:3ac96e360672 | 1931 | |
charlesmn | 0:3ac96e360672 | 1932 | static uint8_t ComputeRQL(uint8_t active_results, |
charlesmn | 0:3ac96e360672 | 1933 | uint8_t FilteredRangeStatus, |
charlesmn | 0:3ac96e360672 | 1934 | VL53L1_range_data_t *presults_data) |
charlesmn | 0:3ac96e360672 | 1935 | { |
charlesmn | 0:3ac96e360672 | 1936 | int16_t T_Wide = 150; |
charlesmn | 0:3ac96e360672 | 1937 | int16_t SRL = 300; |
charlesmn | 0:3ac96e360672 | 1938 | uint16_t SRAS = 30; |
charlesmn | 0:3ac96e360672 | 1939 | FixPoint1616_t RAS; |
charlesmn | 0:3ac96e360672 | 1940 | FixPoint1616_t SRQL; |
charlesmn | 0:3ac96e360672 | 1941 | FixPoint1616_t GI = 7713587; |
charlesmn | 0:3ac96e360672 | 1942 | FixPoint1616_t GGm = 3198157; |
charlesmn | 0:3ac96e360672 | 1943 | FixPoint1616_t LRAP = 6554; |
charlesmn | 0:3ac96e360672 | 1944 | FixPoint1616_t partial; |
charlesmn | 0:3ac96e360672 | 1945 | uint8_t finalvalue; |
charlesmn | 0:3ac96e360672 | 1946 | uint8_t returnvalue; |
charlesmn | 0:3ac96e360672 | 1947 | |
charlesmn | 0:3ac96e360672 | 1948 | if (active_results == 0) |
charlesmn | 0:3ac96e360672 | 1949 | returnvalue = 0; |
charlesmn | 0:3ac96e360672 | 1950 | else if (((presults_data->max_range_mm - |
charlesmn | 0:3ac96e360672 | 1951 | presults_data->min_range_mm) >= T_Wide) || |
charlesmn | 0:3ac96e360672 | 1952 | (FilteredRangeStatus == VL53L1_DEVICEERROR_PHASECONSISTENCY)) |
charlesmn | 0:3ac96e360672 | 1953 | returnvalue = 50; |
charlesmn | 0:3ac96e360672 | 1954 | else { |
charlesmn | 0:3ac96e360672 | 1955 | if (presults_data->median_range_mm < SRL) |
charlesmn | 0:3ac96e360672 | 1956 | RAS = SRAS * 65536; |
charlesmn | 0:3ac96e360672 | 1957 | else |
charlesmn | 0:3ac96e360672 | 1958 | RAS = LRAP * presults_data->median_range_mm; |
charlesmn | 0:3ac96e360672 | 1959 | |
charlesmn | 0:3ac96e360672 | 1960 | |
charlesmn | 0:3ac96e360672 | 1961 | if (RAS != 0) { |
charlesmn | 0:3ac96e360672 | 1962 | partial = (GGm * presults_data->VL53L1_p_005); |
charlesmn | 0:3ac96e360672 | 1963 | partial = partial + (RAS >> 1); |
charlesmn | 0:3ac96e360672 | 1964 | partial = partial / RAS; |
charlesmn | 0:3ac96e360672 | 1965 | partial = partial * 65536; |
charlesmn | 0:3ac96e360672 | 1966 | if (partial <= GI) |
charlesmn | 0:3ac96e360672 | 1967 | SRQL = GI - partial; |
charlesmn | 0:3ac96e360672 | 1968 | else |
charlesmn | 0:3ac96e360672 | 1969 | SRQL = 50 * 65536; |
charlesmn | 0:3ac96e360672 | 1970 | } else |
charlesmn | 0:3ac96e360672 | 1971 | SRQL = 100 * 65536; |
charlesmn | 0:3ac96e360672 | 1972 | |
charlesmn | 0:3ac96e360672 | 1973 | finalvalue = (uint8_t)(SRQL >> 16); |
charlesmn | 0:3ac96e360672 | 1974 | returnvalue = MAX(50, MIN(100, finalvalue)); |
charlesmn | 0:3ac96e360672 | 1975 | } |
charlesmn | 0:3ac96e360672 | 1976 | |
charlesmn | 0:3ac96e360672 | 1977 | return returnvalue; |
charlesmn | 0:3ac96e360672 | 1978 | } |
charlesmn | 0:3ac96e360672 | 1979 | |
charlesmn | 0:3ac96e360672 | 1980 | |
charlesmn | 0:3ac96e360672 | 1981 | static uint8_t ConvertStatusLite(uint8_t FilteredRangeStatus) |
charlesmn | 0:3ac96e360672 | 1982 | { |
charlesmn | 0:3ac96e360672 | 1983 | uint8_t RangeStatus; |
charlesmn | 0:3ac96e360672 | 1984 | |
charlesmn | 0:3ac96e360672 | 1985 | switch (FilteredRangeStatus) { |
charlesmn | 0:3ac96e360672 | 1986 | case VL53L1_DEVICEERROR_GPHSTREAMCOUNT0READY: |
charlesmn | 0:3ac96e360672 | 1987 | RangeStatus = VL53L1_RANGESTATUS_SYNCRONISATION_INT; |
charlesmn | 0:3ac96e360672 | 1988 | break; |
charlesmn | 0:3ac96e360672 | 1989 | case VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK: |
charlesmn | 0:3ac96e360672 | 1990 | RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL; |
charlesmn | 0:3ac96e360672 | 1991 | break; |
charlesmn | 0:3ac96e360672 | 1992 | case VL53L1_DEVICEERROR_RANGEPHASECHECK: |
charlesmn | 0:3ac96e360672 | 1993 | RangeStatus = VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL; |
charlesmn | 0:3ac96e360672 | 1994 | break; |
charlesmn | 0:3ac96e360672 | 1995 | case VL53L1_DEVICEERROR_MSRCNOTARGET: |
charlesmn | 0:3ac96e360672 | 1996 | RangeStatus = VL53L1_RANGESTATUS_SIGNAL_FAIL; |
charlesmn | 0:3ac96e360672 | 1997 | break; |
charlesmn | 0:3ac96e360672 | 1998 | case VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK: |
charlesmn | 0:3ac96e360672 | 1999 | RangeStatus = VL53L1_RANGESTATUS_SIGMA_FAIL; |
charlesmn | 0:3ac96e360672 | 2000 | break; |
charlesmn | 0:3ac96e360672 | 2001 | case VL53L1_DEVICEERROR_PHASECONSISTENCY: |
charlesmn | 0:3ac96e360672 | 2002 | RangeStatus = VL53L1_RANGESTATUS_WRAP_TARGET_FAIL; |
charlesmn | 0:3ac96e360672 | 2003 | break; |
charlesmn | 0:3ac96e360672 | 2004 | case VL53L1_DEVICEERROR_RANGEIGNORETHRESHOLD: |
charlesmn | 0:3ac96e360672 | 2005 | RangeStatus = VL53L1_RANGESTATUS_XTALK_SIGNAL_FAIL; |
charlesmn | 0:3ac96e360672 | 2006 | break; |
charlesmn | 0:3ac96e360672 | 2007 | case VL53L1_DEVICEERROR_MINCLIP: |
charlesmn | 0:3ac96e360672 | 2008 | RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_MIN_RANGE_CLIPPED; |
charlesmn | 0:3ac96e360672 | 2009 | break; |
charlesmn | 0:3ac96e360672 | 2010 | case VL53L1_DEVICEERROR_RANGECOMPLETE: |
charlesmn | 0:3ac96e360672 | 2011 | RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID; |
charlesmn | 0:3ac96e360672 | 2012 | break; |
charlesmn | 0:3ac96e360672 | 2013 | default: |
charlesmn | 0:3ac96e360672 | 2014 | RangeStatus = VL53L1_RANGESTATUS_NONE; |
charlesmn | 0:3ac96e360672 | 2015 | } |
charlesmn | 0:3ac96e360672 | 2016 | |
charlesmn | 0:3ac96e360672 | 2017 | return RangeStatus; |
charlesmn | 0:3ac96e360672 | 2018 | } |
charlesmn | 0:3ac96e360672 | 2019 | |
charlesmn | 0:3ac96e360672 | 2020 | |
charlesmn | 0:3ac96e360672 | 2021 | static uint8_t ConvertStatusHisto(uint8_t FilteredRangeStatus) |
charlesmn | 0:3ac96e360672 | 2022 | { |
charlesmn | 0:3ac96e360672 | 2023 | uint8_t RangeStatus; |
charlesmn | 0:3ac96e360672 | 2024 | |
charlesmn | 0:3ac96e360672 | 2025 | switch (FilteredRangeStatus) { |
charlesmn | 0:3ac96e360672 | 2026 | case VL53L1_DEVICEERROR_RANGEPHASECHECK: |
charlesmn | 0:3ac96e360672 | 2027 | RangeStatus = VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL; |
charlesmn | 0:3ac96e360672 | 2028 | break; |
charlesmn | 0:3ac96e360672 | 2029 | case VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK: |
charlesmn | 0:3ac96e360672 | 2030 | RangeStatus = VL53L1_RANGESTATUS_SIGMA_FAIL; |
charlesmn | 0:3ac96e360672 | 2031 | break; |
charlesmn | 0:3ac96e360672 | 2032 | case VL53L1_DEVICEERROR_RANGECOMPLETE_NO_WRAP_CHECK: |
charlesmn | 0:3ac96e360672 | 2033 | RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL; |
charlesmn | 0:3ac96e360672 | 2034 | break; |
charlesmn | 0:3ac96e360672 | 2035 | case VL53L1_DEVICEERROR_PHASECONSISTENCY: |
charlesmn | 0:3ac96e360672 | 2036 | RangeStatus = VL53L1_RANGESTATUS_WRAP_TARGET_FAIL; |
charlesmn | 0:3ac96e360672 | 2037 | break; |
charlesmn | 0:3ac96e360672 | 2038 | case VL53L1_DEVICEERROR_PREV_RANGE_NO_TARGETS: |
charlesmn | 0:3ac96e360672 | 2039 | RangeStatus = VL53L1_RANGESTATUS_TARGET_PRESENT_LACK_OF_SIGNAL; |
charlesmn | 0:3ac96e360672 | 2040 | break; |
charlesmn | 0:3ac96e360672 | 2041 | case VL53L1_DEVICEERROR_EVENTCONSISTENCY: |
charlesmn | 0:3ac96e360672 | 2042 | RangeStatus = VL53L1_RANGESTATUS_WRAP_TARGET_FAIL; |
charlesmn | 0:3ac96e360672 | 2043 | break; |
charlesmn | 0:3ac96e360672 | 2044 | case VL53L1_DEVICEERROR_RANGECOMPLETE_MERGED_PULSE: |
charlesmn | 0:3ac96e360672 | 2045 | RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID_MERGED_PULSE; |
charlesmn | 0:3ac96e360672 | 2046 | break; |
charlesmn | 0:3ac96e360672 | 2047 | case VL53L1_DEVICEERROR_RANGECOMPLETE: |
charlesmn | 0:3ac96e360672 | 2048 | RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID; |
charlesmn | 0:3ac96e360672 | 2049 | break; |
charlesmn | 0:3ac96e360672 | 2050 | default: |
charlesmn | 0:3ac96e360672 | 2051 | RangeStatus = VL53L1_RANGESTATUS_NONE; |
charlesmn | 0:3ac96e360672 | 2052 | } |
charlesmn | 0:3ac96e360672 | 2053 | |
charlesmn | 0:3ac96e360672 | 2054 | return RangeStatus; |
charlesmn | 0:3ac96e360672 | 2055 | } |
charlesmn | 0:3ac96e360672 | 2056 | |
charlesmn | 0:3ac96e360672 | 2057 | static VL53L1_Error SetSimpleData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2058 | uint8_t active_results, uint8_t device_status, |
charlesmn | 0:3ac96e360672 | 2059 | VL53L1_range_data_t *presults_data, |
charlesmn | 0:3ac96e360672 | 2060 | VL53L1_RangingMeasurementData_t *pRangeData) |
charlesmn | 0:3ac96e360672 | 2061 | { |
charlesmn | 0:3ac96e360672 | 2062 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2063 | uint8_t FilteredRangeStatus; |
charlesmn | 0:3ac96e360672 | 2064 | uint8_t SigmaLimitflag; |
charlesmn | 0:3ac96e360672 | 2065 | uint8_t SignalLimitflag; |
charlesmn | 0:3ac96e360672 | 2066 | uint8_t Temp8Enable; |
charlesmn | 0:3ac96e360672 | 2067 | uint8_t Temp8; |
charlesmn | 0:3ac96e360672 | 2068 | FixPoint1616_t AmbientRate; |
charlesmn | 0:3ac96e360672 | 2069 | FixPoint1616_t SignalRate; |
charlesmn | 0:3ac96e360672 | 2070 | FixPoint1616_t TempFix1616; |
charlesmn | 0:3ac96e360672 | 2071 | FixPoint1616_t LimitCheckValue; |
charlesmn | 0:3ac96e360672 | 2072 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 2073 | int16_t Range; |
charlesmn | 0:3ac96e360672 | 2074 | |
charlesmn | 0:3ac96e360672 | 2075 | pRangeData->TimeStamp = presults_data->time_stamp; |
charlesmn | 0:3ac96e360672 | 2076 | |
charlesmn | 0:3ac96e360672 | 2077 | FilteredRangeStatus = presults_data->range_status & 0x1F; |
charlesmn | 0:3ac96e360672 | 2078 | |
charlesmn | 0:3ac96e360672 | 2079 | pRangeData->RangeQualityLevel = ComputeRQL(active_results, |
charlesmn | 0:3ac96e360672 | 2080 | FilteredRangeStatus, |
charlesmn | 0:3ac96e360672 | 2081 | presults_data); |
charlesmn | 0:3ac96e360672 | 2082 | |
charlesmn | 0:3ac96e360672 | 2083 | SignalRate = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2084 | presults_data->peak_signal_count_rate_mcps); |
charlesmn | 0:3ac96e360672 | 2085 | pRangeData->SignalRateRtnMegaCps |
charlesmn | 0:3ac96e360672 | 2086 | = SignalRate; |
charlesmn | 0:3ac96e360672 | 2087 | |
charlesmn | 0:3ac96e360672 | 2088 | AmbientRate = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2089 | presults_data->ambient_count_rate_mcps); |
charlesmn | 0:3ac96e360672 | 2090 | pRangeData->AmbientRateRtnMegaCps = AmbientRate; |
charlesmn | 0:3ac96e360672 | 2091 | |
charlesmn | 0:3ac96e360672 | 2092 | pRangeData->EffectiveSpadRtnCount = |
charlesmn | 0:3ac96e360672 | 2093 | presults_data->VL53L1_p_006; |
charlesmn | 0:3ac96e360672 | 2094 | |
charlesmn | 0:3ac96e360672 | 2095 | TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2096 | presults_data->VL53L1_p_005); |
charlesmn | 0:3ac96e360672 | 2097 | |
charlesmn | 0:3ac96e360672 | 2098 | pRangeData->SigmaMilliMeter = TempFix1616; |
charlesmn | 0:3ac96e360672 | 2099 | |
charlesmn | 0:3ac96e360672 | 2100 | pRangeData->RangeMilliMeter = presults_data->median_range_mm; |
charlesmn | 0:3ac96e360672 | 2101 | |
charlesmn | 0:3ac96e360672 | 2102 | pRangeData->RangeFractionalPart = 0; |
charlesmn | 0:3ac96e360672 | 2103 | |
charlesmn | 0:3ac96e360672 | 2104 | |
charlesmn | 0:3ac96e360672 | 2105 | switch (device_status) { |
charlesmn | 0:3ac96e360672 | 2106 | case VL53L1_DEVICEERROR_MULTCLIPFAIL: |
charlesmn | 0:3ac96e360672 | 2107 | case VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE: |
charlesmn | 0:3ac96e360672 | 2108 | case VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE: |
charlesmn | 0:3ac96e360672 | 2109 | case VL53L1_DEVICEERROR_NOVHVVALUEFOUND: |
charlesmn | 0:3ac96e360672 | 2110 | pRangeData->RangeStatus = VL53L1_RANGESTATUS_HARDWARE_FAIL; |
charlesmn | 0:3ac96e360672 | 2111 | break; |
charlesmn | 0:3ac96e360672 | 2112 | case VL53L1_DEVICEERROR_USERROICLIP: |
charlesmn | 0:3ac96e360672 | 2113 | pRangeData->RangeStatus = VL53L1_RANGESTATUS_MIN_RANGE_FAIL; |
charlesmn | 0:3ac96e360672 | 2114 | break; |
charlesmn | 0:3ac96e360672 | 2115 | default: |
charlesmn | 0:3ac96e360672 | 2116 | pRangeData->RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID; |
charlesmn | 0:3ac96e360672 | 2117 | } |
charlesmn | 0:3ac96e360672 | 2118 | |
charlesmn | 0:3ac96e360672 | 2119 | |
charlesmn | 0:3ac96e360672 | 2120 | if (pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) { |
charlesmn | 0:3ac96e360672 | 2121 | PresetMode = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 2122 | CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 2123 | if ((PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) || |
charlesmn | 0:3ac96e360672 | 2124 | (PresetMode == VL53L1_PRESETMODE_RANGING) || |
charlesmn | 0:3ac96e360672 | 2125 | (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE)) |
charlesmn | 0:3ac96e360672 | 2126 | pRangeData->RangeStatus = |
charlesmn | 0:3ac96e360672 | 2127 | ConvertStatusHisto(FilteredRangeStatus); |
charlesmn | 0:3ac96e360672 | 2128 | else |
charlesmn | 0:3ac96e360672 | 2129 | pRangeData->RangeStatus = |
charlesmn | 0:3ac96e360672 | 2130 | ConvertStatusLite(FilteredRangeStatus); |
charlesmn | 0:3ac96e360672 | 2131 | } |
charlesmn | 0:3ac96e360672 | 2132 | |
charlesmn | 0:3ac96e360672 | 2133 | |
charlesmn | 0:3ac96e360672 | 2134 | TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2135 | presults_data->VL53L1_p_005); |
charlesmn | 0:3ac96e360672 | 2136 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 2137 | LimitChecksCurrent, VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2138 | TempFix1616); |
charlesmn | 0:3ac96e360672 | 2139 | |
charlesmn | 0:3ac96e360672 | 2140 | TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2141 | presults_data->peak_signal_count_rate_mcps); |
charlesmn | 0:3ac96e360672 | 2142 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 2143 | LimitChecksCurrent, VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2144 | TempFix1616); |
charlesmn | 0:3ac96e360672 | 2145 | |
charlesmn | 0:3ac96e360672 | 2146 | |
charlesmn | 0:3ac96e360672 | 2147 | |
charlesmn | 0:3ac96e360672 | 2148 | VL53L1_GetLimitCheckValue(Dev, |
charlesmn | 0:3ac96e360672 | 2149 | VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2150 | &LimitCheckValue); |
charlesmn | 0:3ac96e360672 | 2151 | |
charlesmn | 0:3ac96e360672 | 2152 | SigmaLimitflag = (FilteredRangeStatus == |
charlesmn | 0:3ac96e360672 | 2153 | VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK) |
charlesmn | 0:3ac96e360672 | 2154 | ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2155 | |
charlesmn | 0:3ac96e360672 | 2156 | VL53L1_GetLimitCheckEnable(Dev, |
charlesmn | 0:3ac96e360672 | 2157 | VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2158 | &Temp8Enable); |
charlesmn | 0:3ac96e360672 | 2159 | |
charlesmn | 0:3ac96e360672 | 2160 | Temp8 = ((Temp8Enable == 1) && (SigmaLimitflag == 1)) ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2161 | VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus, |
charlesmn | 0:3ac96e360672 | 2162 | VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, Temp8); |
charlesmn | 0:3ac96e360672 | 2163 | |
charlesmn | 0:3ac96e360672 | 2164 | |
charlesmn | 0:3ac96e360672 | 2165 | VL53L1_GetLimitCheckValue(Dev, |
charlesmn | 0:3ac96e360672 | 2166 | VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2167 | &LimitCheckValue); |
charlesmn | 0:3ac96e360672 | 2168 | |
charlesmn | 0:3ac96e360672 | 2169 | SignalLimitflag = (FilteredRangeStatus == |
charlesmn | 0:3ac96e360672 | 2170 | VL53L1_DEVICEERROR_MSRCNOTARGET) |
charlesmn | 0:3ac96e360672 | 2171 | ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2172 | |
charlesmn | 0:3ac96e360672 | 2173 | VL53L1_GetLimitCheckEnable(Dev, |
charlesmn | 0:3ac96e360672 | 2174 | VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2175 | &Temp8Enable); |
charlesmn | 0:3ac96e360672 | 2176 | |
charlesmn | 0:3ac96e360672 | 2177 | Temp8 = ((Temp8Enable == 1) && (SignalLimitflag == 1)) ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2178 | VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus, |
charlesmn | 0:3ac96e360672 | 2179 | VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, Temp8); |
charlesmn | 0:3ac96e360672 | 2180 | |
charlesmn | 0:3ac96e360672 | 2181 | Range = pRangeData->RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 2182 | if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) && |
charlesmn | 0:3ac96e360672 | 2183 | (Range < 0)) { |
charlesmn | 0:3ac96e360672 | 2184 | if (Range < BDTable[VL53L1_TUNING_PROXY_MIN]) |
charlesmn | 0:3ac96e360672 | 2185 | pRangeData->RangeStatus = |
charlesmn | 0:3ac96e360672 | 2186 | VL53L1_RANGESTATUS_RANGE_INVALID; |
charlesmn | 0:3ac96e360672 | 2187 | else |
charlesmn | 0:3ac96e360672 | 2188 | pRangeData->RangeMilliMeter = 0; |
charlesmn | 0:3ac96e360672 | 2189 | } |
charlesmn | 0:3ac96e360672 | 2190 | |
charlesmn | 0:3ac96e360672 | 2191 | return Status; |
charlesmn | 0:3ac96e360672 | 2192 | } |
charlesmn | 0:3ac96e360672 | 2193 | |
charlesmn | 0:3ac96e360672 | 2194 | static VL53L1_Error SetTargetData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2195 | uint8_t active_results, uint8_t streamcount, uint8_t iteration, |
charlesmn | 0:3ac96e360672 | 2196 | uint8_t device_status, VL53L1_range_data_t *presults_data, |
charlesmn | 0:3ac96e360672 | 2197 | VL53L1_TargetRangeData_t *pRangeData) |
charlesmn | 0:3ac96e360672 | 2198 | { |
charlesmn | 0:3ac96e360672 | 2199 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2200 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 2201 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 2202 | VL53L1_tuning_parm_storage_t *tp = |
charlesmn | 0:3ac96e360672 | 2203 | &(pdev->tuning_parms); |
charlesmn | 0:3ac96e360672 | 2204 | uint8_t sequency; |
charlesmn | 0:3ac96e360672 | 2205 | uint8_t FilteredRangeStatus; |
charlesmn | 0:3ac96e360672 | 2206 | uint8_t SigmaLimitflag; |
charlesmn | 0:3ac96e360672 | 2207 | uint8_t SignalLimitflag; |
charlesmn | 0:3ac96e360672 | 2208 | uint8_t Temp8Enable; |
charlesmn | 0:3ac96e360672 | 2209 | uint8_t Temp8; |
charlesmn | 0:3ac96e360672 | 2210 | FixPoint1616_t AmbientRate; |
charlesmn | 0:3ac96e360672 | 2211 | FixPoint1616_t SignalRate; |
charlesmn | 0:3ac96e360672 | 2212 | FixPoint1616_t TempFix1616; |
charlesmn | 0:3ac96e360672 | 2213 | FixPoint1616_t LimitCheckValue; |
charlesmn | 0:3ac96e360672 | 2214 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 2215 | int16_t Range, RangeDiff, RangeMillimeterInit; |
charlesmn | 0:3ac96e360672 | 2216 | uint8_t ExtendedRangeEnabled = 0; |
charlesmn | 0:3ac96e360672 | 2217 | uint8_t uwr_status; |
charlesmn | 0:3ac96e360672 | 2218 | int16_t AddOffset; |
charlesmn | 0:3ac96e360672 | 2219 | |
charlesmn | 0:3ac96e360672 | 2220 | FilteredRangeStatus = presults_data->range_status & 0x1F; |
charlesmn | 0:3ac96e360672 | 2221 | |
charlesmn | 0:3ac96e360672 | 2222 | pRangeData->RangeQualityLevel = ComputeRQL(active_results, |
charlesmn | 0:3ac96e360672 | 2223 | FilteredRangeStatus, |
charlesmn | 0:3ac96e360672 | 2224 | presults_data); |
charlesmn | 0:3ac96e360672 | 2225 | |
charlesmn | 0:3ac96e360672 | 2226 | SignalRate = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2227 | presults_data->peak_signal_count_rate_mcps); |
charlesmn | 0:3ac96e360672 | 2228 | pRangeData->SignalRateRtnMegaCps |
charlesmn | 0:3ac96e360672 | 2229 | = SignalRate; |
charlesmn | 0:3ac96e360672 | 2230 | |
charlesmn | 0:3ac96e360672 | 2231 | AmbientRate = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2232 | presults_data->ambient_count_rate_mcps); |
charlesmn | 0:3ac96e360672 | 2233 | pRangeData->AmbientRateRtnMegaCps = AmbientRate; |
charlesmn | 0:3ac96e360672 | 2234 | |
charlesmn | 0:3ac96e360672 | 2235 | TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2236 | presults_data->VL53L1_p_005); |
charlesmn | 0:3ac96e360672 | 2237 | |
charlesmn | 0:3ac96e360672 | 2238 | pRangeData->SigmaMilliMeter = TempFix1616; |
charlesmn | 0:3ac96e360672 | 2239 | |
charlesmn | 0:3ac96e360672 | 2240 | pRangeData->RangeMilliMeter = presults_data->median_range_mm; |
charlesmn | 0:3ac96e360672 | 2241 | pRangeData->RangeMaxMilliMeter = presults_data->max_range_mm; |
charlesmn | 0:3ac96e360672 | 2242 | pRangeData->RangeMinMilliMeter = presults_data->min_range_mm; |
charlesmn | 0:3ac96e360672 | 2243 | |
charlesmn | 0:3ac96e360672 | 2244 | pRangeData->RangeFractionalPart = 0; |
charlesmn | 0:3ac96e360672 | 2245 | |
charlesmn | 0:3ac96e360672 | 2246 | |
charlesmn | 0:3ac96e360672 | 2247 | switch (device_status) { |
charlesmn | 0:3ac96e360672 | 2248 | case VL53L1_DEVICEERROR_MULTCLIPFAIL: |
charlesmn | 0:3ac96e360672 | 2249 | case VL53L1_DEVICEERROR_VCSELWATCHDOGTESTFAILURE: |
charlesmn | 0:3ac96e360672 | 2250 | case VL53L1_DEVICEERROR_VCSELCONTINUITYTESTFAILURE: |
charlesmn | 0:3ac96e360672 | 2251 | case VL53L1_DEVICEERROR_NOVHVVALUEFOUND: |
charlesmn | 0:3ac96e360672 | 2252 | pRangeData->RangeStatus = VL53L1_RANGESTATUS_HARDWARE_FAIL; |
charlesmn | 0:3ac96e360672 | 2253 | break; |
charlesmn | 0:3ac96e360672 | 2254 | case VL53L1_DEVICEERROR_USERROICLIP: |
charlesmn | 0:3ac96e360672 | 2255 | pRangeData->RangeStatus = VL53L1_RANGESTATUS_MIN_RANGE_FAIL; |
charlesmn | 0:3ac96e360672 | 2256 | break; |
charlesmn | 0:3ac96e360672 | 2257 | default: |
charlesmn | 0:3ac96e360672 | 2258 | pRangeData->RangeStatus = VL53L1_RANGESTATUS_RANGE_VALID; |
charlesmn | 0:3ac96e360672 | 2259 | } |
charlesmn | 0:3ac96e360672 | 2260 | |
charlesmn | 0:3ac96e360672 | 2261 | |
charlesmn | 0:3ac96e360672 | 2262 | if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) && |
charlesmn | 0:3ac96e360672 | 2263 | (active_results == 0)) { |
charlesmn | 0:3ac96e360672 | 2264 | pRangeData->RangeStatus = VL53L1_RANGESTATUS_NONE; |
charlesmn | 0:3ac96e360672 | 2265 | pRangeData->SignalRateRtnMegaCps = 0; |
charlesmn | 0:3ac96e360672 | 2266 | pRangeData->SigmaMilliMeter = 0; |
charlesmn | 0:3ac96e360672 | 2267 | pRangeData->RangeMilliMeter = 8191; |
charlesmn | 0:3ac96e360672 | 2268 | pRangeData->RangeMaxMilliMeter = 8191; |
charlesmn | 0:3ac96e360672 | 2269 | pRangeData->RangeMinMilliMeter = 8191; |
charlesmn | 0:3ac96e360672 | 2270 | } |
charlesmn | 0:3ac96e360672 | 2271 | |
charlesmn | 0:3ac96e360672 | 2272 | |
charlesmn | 0:3ac96e360672 | 2273 | if (pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) { |
charlesmn | 0:3ac96e360672 | 2274 | PresetMode = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 2275 | CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 2276 | if ((PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) || |
charlesmn | 0:3ac96e360672 | 2277 | (PresetMode == VL53L1_PRESETMODE_RANGING) || |
charlesmn | 0:3ac96e360672 | 2278 | (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE)) |
charlesmn | 0:3ac96e360672 | 2279 | pRangeData->RangeStatus = |
charlesmn | 0:3ac96e360672 | 2280 | ConvertStatusHisto(FilteredRangeStatus); |
charlesmn | 0:3ac96e360672 | 2281 | else |
charlesmn | 0:3ac96e360672 | 2282 | pRangeData->RangeStatus = |
charlesmn | 0:3ac96e360672 | 2283 | ConvertStatusLite(FilteredRangeStatus); |
charlesmn | 0:3ac96e360672 | 2284 | } |
charlesmn | 0:3ac96e360672 | 2285 | |
charlesmn | 0:3ac96e360672 | 2286 | |
charlesmn | 0:3ac96e360672 | 2287 | TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2288 | presults_data->VL53L1_p_005); |
charlesmn | 0:3ac96e360672 | 2289 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 2290 | LimitChecksCurrent, VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2291 | TempFix1616); |
charlesmn | 0:3ac96e360672 | 2292 | |
charlesmn | 0:3ac96e360672 | 2293 | TempFix1616 = VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 2294 | presults_data->peak_signal_count_rate_mcps); |
charlesmn | 0:3ac96e360672 | 2295 | VL53L1_SETARRAYPARAMETERFIELD(Dev, |
charlesmn | 0:3ac96e360672 | 2296 | LimitChecksCurrent, VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2297 | TempFix1616); |
charlesmn | 0:3ac96e360672 | 2298 | |
charlesmn | 0:3ac96e360672 | 2299 | |
charlesmn | 0:3ac96e360672 | 2300 | |
charlesmn | 0:3ac96e360672 | 2301 | VL53L1_GetLimitCheckValue(Dev, |
charlesmn | 0:3ac96e360672 | 2302 | VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2303 | &LimitCheckValue); |
charlesmn | 0:3ac96e360672 | 2304 | |
charlesmn | 0:3ac96e360672 | 2305 | SigmaLimitflag = (FilteredRangeStatus == |
charlesmn | 0:3ac96e360672 | 2306 | VL53L1_DEVICEERROR_SIGMATHRESHOLDCHECK) |
charlesmn | 0:3ac96e360672 | 2307 | ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2308 | |
charlesmn | 0:3ac96e360672 | 2309 | VL53L1_GetLimitCheckEnable(Dev, |
charlesmn | 0:3ac96e360672 | 2310 | VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2311 | &Temp8Enable); |
charlesmn | 0:3ac96e360672 | 2312 | |
charlesmn | 0:3ac96e360672 | 2313 | Temp8 = ((Temp8Enable == 1) && (SigmaLimitflag == 1)) ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2314 | VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus, |
charlesmn | 0:3ac96e360672 | 2315 | VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE, Temp8); |
charlesmn | 0:3ac96e360672 | 2316 | |
charlesmn | 0:3ac96e360672 | 2317 | |
charlesmn | 0:3ac96e360672 | 2318 | VL53L1_GetLimitCheckValue(Dev, |
charlesmn | 0:3ac96e360672 | 2319 | VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2320 | &LimitCheckValue); |
charlesmn | 0:3ac96e360672 | 2321 | |
charlesmn | 0:3ac96e360672 | 2322 | SignalLimitflag = (FilteredRangeStatus == |
charlesmn | 0:3ac96e360672 | 2323 | VL53L1_DEVICEERROR_MSRCNOTARGET) |
charlesmn | 0:3ac96e360672 | 2324 | ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2325 | |
charlesmn | 0:3ac96e360672 | 2326 | VL53L1_GetLimitCheckEnable(Dev, |
charlesmn | 0:3ac96e360672 | 2327 | VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, |
charlesmn | 0:3ac96e360672 | 2328 | &Temp8Enable); |
charlesmn | 0:3ac96e360672 | 2329 | |
charlesmn | 0:3ac96e360672 | 2330 | Temp8 = ((Temp8Enable == 1) && (SignalLimitflag == 1)) ? 1 : 0; |
charlesmn | 0:3ac96e360672 | 2331 | VL53L1_SETARRAYPARAMETERFIELD(Dev, LimitChecksStatus, |
charlesmn | 0:3ac96e360672 | 2332 | VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, Temp8); |
charlesmn | 0:3ac96e360672 | 2333 | |
charlesmn | 0:3ac96e360672 | 2334 | Range = pRangeData->RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 2335 | if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) && |
charlesmn | 0:3ac96e360672 | 2336 | (Range < 0)) { |
charlesmn | 0:3ac96e360672 | 2337 | if (Range < BDTable[VL53L1_TUNING_PROXY_MIN]) |
charlesmn | 0:3ac96e360672 | 2338 | pRangeData->RangeStatus = |
charlesmn | 0:3ac96e360672 | 2339 | VL53L1_RANGESTATUS_RANGE_INVALID; |
charlesmn | 0:3ac96e360672 | 2340 | else |
charlesmn | 0:3ac96e360672 | 2341 | pRangeData->RangeMilliMeter = 0; |
charlesmn | 0:3ac96e360672 | 2342 | } |
charlesmn | 0:3ac96e360672 | 2343 | |
charlesmn | 0:3ac96e360672 | 2344 | |
charlesmn | 0:3ac96e360672 | 2345 | |
charlesmn | 0:3ac96e360672 | 2346 | VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_UWR_ENABLE, |
charlesmn | 0:3ac96e360672 | 2347 | (int32_t *)&ExtendedRangeEnabled); |
charlesmn | 0:3ac96e360672 | 2348 | |
charlesmn | 0:3ac96e360672 | 2349 | sequency = streamcount % 2; |
charlesmn | 0:3ac96e360672 | 2350 | uwr_status = 1; |
charlesmn | 0:3ac96e360672 | 2351 | RangeMillimeterInit = pRangeData->RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 2352 | AddOffset = 0; |
charlesmn | 0:3ac96e360672 | 2353 | |
charlesmn | 0:3ac96e360672 | 2354 | pRangeData->ExtendedRange = 0; |
charlesmn | 0:3ac96e360672 | 2355 | |
charlesmn | 0:3ac96e360672 | 2356 | if (ExtendedRangeEnabled && |
charlesmn | 0:3ac96e360672 | 2357 | (pRangeData->RangeStatus == |
charlesmn | 0:3ac96e360672 | 2358 | VL53L1_RANGESTATUS_WRAP_TARGET_FAIL || |
charlesmn | 0:3ac96e360672 | 2359 | pRangeData->RangeStatus == |
charlesmn | 0:3ac96e360672 | 2360 | VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL) |
charlesmn | 0:3ac96e360672 | 2361 | && (pdev->PreviousRangeStatus[iteration] == |
charlesmn | 0:3ac96e360672 | 2362 | VL53L1_RANGESTATUS_WRAP_TARGET_FAIL || |
charlesmn | 0:3ac96e360672 | 2363 | pdev->PreviousRangeStatus[iteration] == |
charlesmn | 0:3ac96e360672 | 2364 | VL53L1_RANGESTATUS_OUTOFBOUNDS_FAIL || |
charlesmn | 0:3ac96e360672 | 2365 | (pdev->PreviousRangeStatus[iteration] == |
charlesmn | 0:3ac96e360672 | 2366 | VL53L1_RANGESTATUS_RANGE_VALID && |
charlesmn | 0:3ac96e360672 | 2367 | pdev->PreviousExtendedRange[iteration] == 1))) |
charlesmn | 0:3ac96e360672 | 2368 | { |
charlesmn | 0:3ac96e360672 | 2369 | if (((pdev->PreviousStreamCount) == |
charlesmn | 0:3ac96e360672 | 2370 | (pdev->hist_data.result__stream_count - 1 )) |
charlesmn | 0:3ac96e360672 | 2371 | || ((pdev->PreviousStreamCount) == |
charlesmn | 0:3ac96e360672 | 2372 | (pdev->hist_data.result__stream_count + 127))) |
charlesmn | 0:3ac96e360672 | 2373 | { |
charlesmn | 0:3ac96e360672 | 2374 | RangeDiff = pRangeData->RangeMilliMeter - |
charlesmn | 0:3ac96e360672 | 2375 | pdev->PreviousRangeMilliMeter[iteration]; |
charlesmn | 0:3ac96e360672 | 2376 | |
charlesmn | 0:3ac96e360672 | 2377 | switch (pdev->preset_mode) { |
charlesmn | 0:3ac96e360672 | 2378 | case VL53L1_DEVICEPRESETMODE_HISTOGRAM_SHORT_RANGE: |
charlesmn | 0:3ac96e360672 | 2379 | |
charlesmn | 0:3ac96e360672 | 2380 | uwr_status = 0; |
charlesmn | 0:3ac96e360672 | 2381 | break; |
charlesmn | 0:3ac96e360672 | 2382 | |
charlesmn | 0:3ac96e360672 | 2383 | case VL53L1_DEVICEPRESETMODE_HISTOGRAM_MEDIUM_RANGE: |
charlesmn | 0:3ac96e360672 | 2384 | if (RangeDiff > tp->tp_uwr_med_z_1_min && |
charlesmn | 0:3ac96e360672 | 2385 | RangeDiff < tp->tp_uwr_med_z_1_max && |
charlesmn | 0:3ac96e360672 | 2386 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2387 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2388 | tp->tp_uwr_med_corr_z_1_rangeb; |
charlesmn | 0:3ac96e360672 | 2389 | } |
charlesmn | 0:3ac96e360672 | 2390 | else |
charlesmn | 0:3ac96e360672 | 2391 | if (RangeDiff < -tp->tp_uwr_med_z_1_min && |
charlesmn | 0:3ac96e360672 | 2392 | RangeDiff > -tp->tp_uwr_med_z_1_max && |
charlesmn | 0:3ac96e360672 | 2393 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2394 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2395 | tp->tp_uwr_med_corr_z_1_rangea; |
charlesmn | 0:3ac96e360672 | 2396 | } |
charlesmn | 0:3ac96e360672 | 2397 | else |
charlesmn | 0:3ac96e360672 | 2398 | if (RangeDiff > tp->tp_uwr_med_z_2_min && |
charlesmn | 0:3ac96e360672 | 2399 | RangeDiff < tp->tp_uwr_med_z_2_max && |
charlesmn | 0:3ac96e360672 | 2400 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2401 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2402 | tp->tp_uwr_med_corr_z_2_rangea; |
charlesmn | 0:3ac96e360672 | 2403 | } |
charlesmn | 0:3ac96e360672 | 2404 | else |
charlesmn | 0:3ac96e360672 | 2405 | if (RangeDiff < -tp->tp_uwr_med_z_2_min && |
charlesmn | 0:3ac96e360672 | 2406 | RangeDiff > -tp->tp_uwr_med_z_2_max && |
charlesmn | 0:3ac96e360672 | 2407 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2408 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2409 | tp->tp_uwr_med_corr_z_2_rangeb; |
charlesmn | 0:3ac96e360672 | 2410 | } |
charlesmn | 0:3ac96e360672 | 2411 | else |
charlesmn | 0:3ac96e360672 | 2412 | if (RangeDiff > tp->tp_uwr_med_z_3_min && |
charlesmn | 0:3ac96e360672 | 2413 | RangeDiff < tp->tp_uwr_med_z_3_max && |
charlesmn | 0:3ac96e360672 | 2414 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2415 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2416 | tp->tp_uwr_med_corr_z_3_rangeb; |
charlesmn | 0:3ac96e360672 | 2417 | } |
charlesmn | 0:3ac96e360672 | 2418 | else |
charlesmn | 0:3ac96e360672 | 2419 | if (RangeDiff < -tp->tp_uwr_med_z_3_min && |
charlesmn | 0:3ac96e360672 | 2420 | RangeDiff > -tp->tp_uwr_med_z_3_max && |
charlesmn | 0:3ac96e360672 | 2421 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2422 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2423 | tp->tp_uwr_med_corr_z_3_rangea; |
charlesmn | 0:3ac96e360672 | 2424 | } |
charlesmn | 0:3ac96e360672 | 2425 | else |
charlesmn | 0:3ac96e360672 | 2426 | if (RangeDiff > tp->tp_uwr_med_z_4_min && |
charlesmn | 0:3ac96e360672 | 2427 | RangeDiff < tp->tp_uwr_med_z_4_max && |
charlesmn | 0:3ac96e360672 | 2428 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2429 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2430 | tp->tp_uwr_med_corr_z_4_rangea; |
charlesmn | 0:3ac96e360672 | 2431 | } |
charlesmn | 0:3ac96e360672 | 2432 | else |
charlesmn | 0:3ac96e360672 | 2433 | if (RangeDiff < -tp->tp_uwr_med_z_4_min && |
charlesmn | 0:3ac96e360672 | 2434 | RangeDiff > -tp->tp_uwr_med_z_4_max && |
charlesmn | 0:3ac96e360672 | 2435 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2436 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2437 | tp->tp_uwr_med_corr_z_4_rangeb; |
charlesmn | 0:3ac96e360672 | 2438 | } |
charlesmn | 0:3ac96e360672 | 2439 | else |
charlesmn | 0:3ac96e360672 | 2440 | if (RangeDiff < tp->tp_uwr_med_z_5_max && |
charlesmn | 0:3ac96e360672 | 2441 | RangeDiff > tp->tp_uwr_med_z_5_min) { |
charlesmn | 0:3ac96e360672 | 2442 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2443 | tp->tp_uwr_med_corr_z_5_rangea; |
charlesmn | 0:3ac96e360672 | 2444 | } |
charlesmn | 0:3ac96e360672 | 2445 | else |
charlesmn | 0:3ac96e360672 | 2446 | if (RangeDiff > tp->tp_uwr_med_z_6_min && |
charlesmn | 0:3ac96e360672 | 2447 | RangeDiff < tp->tp_uwr_med_z_6_max && |
charlesmn | 0:3ac96e360672 | 2448 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2449 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2450 | tp->tp_uwr_med_corr_z_6_rangeb; |
charlesmn | 0:3ac96e360672 | 2451 | } |
charlesmn | 0:3ac96e360672 | 2452 | else |
charlesmn | 0:3ac96e360672 | 2453 | if (RangeDiff < -tp->tp_uwr_med_z_6_min && |
charlesmn | 0:3ac96e360672 | 2454 | RangeDiff > -tp->tp_uwr_med_z_6_max && |
charlesmn | 0:3ac96e360672 | 2455 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2456 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2457 | tp->tp_uwr_med_corr_z_6_rangea; |
charlesmn | 0:3ac96e360672 | 2458 | } |
charlesmn | 0:3ac96e360672 | 2459 | else |
charlesmn | 0:3ac96e360672 | 2460 | |
charlesmn | 0:3ac96e360672 | 2461 | |
charlesmn | 0:3ac96e360672 | 2462 | |
charlesmn | 0:3ac96e360672 | 2463 | |
charlesmn | 0:3ac96e360672 | 2464 | |
charlesmn | 0:3ac96e360672 | 2465 | |
charlesmn | 0:3ac96e360672 | 2466 | |
charlesmn | 0:3ac96e360672 | 2467 | |
charlesmn | 0:3ac96e360672 | 2468 | |
charlesmn | 0:3ac96e360672 | 2469 | |
charlesmn | 0:3ac96e360672 | 2470 | |
charlesmn | 0:3ac96e360672 | 2471 | uwr_status = 0; |
charlesmn | 0:3ac96e360672 | 2472 | break; |
charlesmn | 0:3ac96e360672 | 2473 | |
charlesmn | 0:3ac96e360672 | 2474 | case VL53L1_DEVICEPRESETMODE_HISTOGRAM_LONG_RANGE: |
charlesmn | 0:3ac96e360672 | 2475 | if (RangeDiff > tp->tp_uwr_lng_z_1_min && |
charlesmn | 0:3ac96e360672 | 2476 | RangeDiff < tp->tp_uwr_lng_z_1_max && |
charlesmn | 0:3ac96e360672 | 2477 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2478 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2479 | tp->tp_uwr_lng_corr_z_1_rangea; |
charlesmn | 0:3ac96e360672 | 2480 | } |
charlesmn | 0:3ac96e360672 | 2481 | else |
charlesmn | 0:3ac96e360672 | 2482 | if (RangeDiff < -tp->tp_uwr_lng_z_1_min && |
charlesmn | 0:3ac96e360672 | 2483 | RangeDiff > -tp->tp_uwr_lng_z_1_max && |
charlesmn | 0:3ac96e360672 | 2484 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2485 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2486 | tp->tp_uwr_lng_corr_z_1_rangeb; |
charlesmn | 0:3ac96e360672 | 2487 | } |
charlesmn | 0:3ac96e360672 | 2488 | else |
charlesmn | 0:3ac96e360672 | 2489 | if (RangeDiff > tp->tp_uwr_lng_z_2_min && |
charlesmn | 0:3ac96e360672 | 2490 | RangeDiff < tp->tp_uwr_lng_z_2_max && |
charlesmn | 0:3ac96e360672 | 2491 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2492 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2493 | tp->tp_uwr_lng_corr_z_2_rangeb; |
charlesmn | 0:3ac96e360672 | 2494 | } |
charlesmn | 0:3ac96e360672 | 2495 | else |
charlesmn | 0:3ac96e360672 | 2496 | if (RangeDiff < -tp->tp_uwr_lng_z_2_min && |
charlesmn | 0:3ac96e360672 | 2497 | RangeDiff > -tp->tp_uwr_lng_z_2_max && |
charlesmn | 0:3ac96e360672 | 2498 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2499 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2500 | tp->tp_uwr_lng_corr_z_2_rangea; |
charlesmn | 0:3ac96e360672 | 2501 | } |
charlesmn | 0:3ac96e360672 | 2502 | else |
charlesmn | 0:3ac96e360672 | 2503 | if (RangeDiff < tp->tp_uwr_lng_z_3_max && |
charlesmn | 0:3ac96e360672 | 2504 | RangeDiff > tp->tp_uwr_lng_z_3_min) { |
charlesmn | 0:3ac96e360672 | 2505 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2506 | tp->tp_uwr_lng_corr_z_3_rangea; |
charlesmn | 0:3ac96e360672 | 2507 | } |
charlesmn | 0:3ac96e360672 | 2508 | else |
charlesmn | 0:3ac96e360672 | 2509 | if (RangeDiff > tp->tp_uwr_lng_z_4_min && |
charlesmn | 0:3ac96e360672 | 2510 | RangeDiff < tp->tp_uwr_lng_z_4_max && |
charlesmn | 0:3ac96e360672 | 2511 | sequency == 1) { |
charlesmn | 0:3ac96e360672 | 2512 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2513 | tp->tp_uwr_lng_corr_z_4_rangeb; |
charlesmn | 0:3ac96e360672 | 2514 | } |
charlesmn | 0:3ac96e360672 | 2515 | else |
charlesmn | 0:3ac96e360672 | 2516 | if (RangeDiff < -tp->tp_uwr_lng_z_4_min && |
charlesmn | 0:3ac96e360672 | 2517 | RangeDiff > -tp->tp_uwr_lng_z_4_max && |
charlesmn | 0:3ac96e360672 | 2518 | sequency == 0) { |
charlesmn | 0:3ac96e360672 | 2519 | AddOffset = |
charlesmn | 0:3ac96e360672 | 2520 | tp->tp_uwr_lng_corr_z_4_rangea; |
charlesmn | 0:3ac96e360672 | 2521 | } |
charlesmn | 0:3ac96e360672 | 2522 | else |
charlesmn | 0:3ac96e360672 | 2523 | uwr_status = 0; |
charlesmn | 0:3ac96e360672 | 2524 | break; |
charlesmn | 0:3ac96e360672 | 2525 | |
charlesmn | 0:3ac96e360672 | 2526 | default: |
charlesmn | 0:3ac96e360672 | 2527 | uwr_status = 0; |
charlesmn | 0:3ac96e360672 | 2528 | break; |
charlesmn | 0:3ac96e360672 | 2529 | } |
charlesmn | 0:3ac96e360672 | 2530 | } |
charlesmn | 0:3ac96e360672 | 2531 | |
charlesmn | 0:3ac96e360672 | 2532 | if (uwr_status) { |
charlesmn | 0:3ac96e360672 | 2533 | pRangeData->RangeMilliMeter += AddOffset; |
charlesmn | 0:3ac96e360672 | 2534 | pRangeData->RangeMinMilliMeter += AddOffset; |
charlesmn | 0:3ac96e360672 | 2535 | pRangeData->RangeMaxMilliMeter += AddOffset; |
charlesmn | 0:3ac96e360672 | 2536 | pRangeData->ExtendedRange = 1; |
charlesmn | 0:3ac96e360672 | 2537 | pRangeData->RangeStatus = 0; |
charlesmn | 0:3ac96e360672 | 2538 | } |
charlesmn | 0:3ac96e360672 | 2539 | |
charlesmn | 0:3ac96e360672 | 2540 | } |
charlesmn | 0:3ac96e360672 | 2541 | |
charlesmn | 0:3ac96e360672 | 2542 | pdev->PreviousRangeMilliMeter[iteration] = RangeMillimeterInit; |
charlesmn | 0:3ac96e360672 | 2543 | pdev->PreviousRangeStatus[iteration] = pRangeData->RangeStatus; |
charlesmn | 0:3ac96e360672 | 2544 | pdev->PreviousExtendedRange[iteration] = pRangeData->ExtendedRange; |
charlesmn | 0:3ac96e360672 | 2545 | pdev->PreviousStreamCount = pdev->hist_data.result__stream_count; |
charlesmn | 0:3ac96e360672 | 2546 | |
charlesmn | 0:3ac96e360672 | 2547 | return Status; |
charlesmn | 0:3ac96e360672 | 2548 | } |
charlesmn | 0:3ac96e360672 | 2549 | |
charlesmn | 0:3ac96e360672 | 2550 | static uint8_t GetOutputDataIndex(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2551 | VL53L1_range_results_t *presults) |
charlesmn | 0:3ac96e360672 | 2552 | { |
charlesmn | 0:3ac96e360672 | 2553 | uint8_t i; |
charlesmn | 0:3ac96e360672 | 2554 | uint8_t index = 0; |
charlesmn | 0:3ac96e360672 | 2555 | VL53L1_OutputModes OutputMode; |
charlesmn | 0:3ac96e360672 | 2556 | |
charlesmn | 0:3ac96e360672 | 2557 | OutputMode = VL53L1DevDataGet(Dev, CurrentParameters.OutputMode); |
charlesmn | 0:3ac96e360672 | 2558 | |
charlesmn | 0:3ac96e360672 | 2559 | |
charlesmn | 0:3ac96e360672 | 2560 | if (OutputMode == VL53L1_OUTPUTMODE_NEAREST) |
charlesmn | 0:3ac96e360672 | 2561 | return 0; |
charlesmn | 0:3ac96e360672 | 2562 | |
charlesmn | 0:3ac96e360672 | 2563 | |
charlesmn | 0:3ac96e360672 | 2564 | for (i = 1; i < presults->active_results; i++) { |
charlesmn | 0:3ac96e360672 | 2565 | if (presults->VL53L1_p_002[i].peak_signal_count_rate_mcps > |
charlesmn | 0:3ac96e360672 | 2566 | presults->VL53L1_p_002[index].peak_signal_count_rate_mcps) |
charlesmn | 0:3ac96e360672 | 2567 | index = i; |
charlesmn | 0:3ac96e360672 | 2568 | } |
charlesmn | 0:3ac96e360672 | 2569 | |
charlesmn | 0:3ac96e360672 | 2570 | return index; |
charlesmn | 0:3ac96e360672 | 2571 | } |
charlesmn | 0:3ac96e360672 | 2572 | |
charlesmn | 0:3ac96e360672 | 2573 | VL53L1_Error VL53L1_GetRangingMeasurementData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2574 | VL53L1_RangingMeasurementData_t *pRangingMeasurementData) |
charlesmn | 0:3ac96e360672 | 2575 | { |
charlesmn | 0:3ac96e360672 | 2576 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2577 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 2578 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 2579 | VL53L1_range_results_t *presults = |
charlesmn | 0:3ac96e360672 | 2580 | (VL53L1_range_results_t *) pdev->wArea1; |
charlesmn | 0:3ac96e360672 | 2581 | VL53L1_range_data_t *presults_data; |
charlesmn | 0:3ac96e360672 | 2582 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 2583 | uint8_t index = 0; |
charlesmn | 0:3ac96e360672 | 2584 | |
charlesmn | 0:3ac96e360672 | 2585 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2586 | |
charlesmn | 0:3ac96e360672 | 2587 | |
charlesmn | 0:3ac96e360672 | 2588 | PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 2589 | |
charlesmn | 0:3ac96e360672 | 2590 | if (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) { |
charlesmn | 0:3ac96e360672 | 2591 | Status = VL53L1_ERROR_MODE_NOT_SUPPORTED; |
charlesmn | 0:3ac96e360672 | 2592 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2593 | return Status; |
charlesmn | 0:3ac96e360672 | 2594 | } |
charlesmn | 0:3ac96e360672 | 2595 | |
charlesmn | 0:3ac96e360672 | 2596 | |
charlesmn | 0:3ac96e360672 | 2597 | memset(pRangingMeasurementData, 0xFF, |
charlesmn | 0:3ac96e360672 | 2598 | sizeof(VL53L1_RangingMeasurementData_t)); |
charlesmn | 0:3ac96e360672 | 2599 | |
charlesmn | 0:3ac96e360672 | 2600 | |
charlesmn | 0:3ac96e360672 | 2601 | Status = VL53L1_get_device_results( |
charlesmn | 0:3ac96e360672 | 2602 | Dev, |
charlesmn | 0:3ac96e360672 | 2603 | VL53L1_DEVICERESULTSLEVEL_FULL, |
charlesmn | 0:3ac96e360672 | 2604 | presults); |
charlesmn | 0:3ac96e360672 | 2605 | |
charlesmn | 0:3ac96e360672 | 2606 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 2607 | pRangingMeasurementData->StreamCount = presults->stream_count; |
charlesmn | 0:3ac96e360672 | 2608 | |
charlesmn | 0:3ac96e360672 | 2609 | |
charlesmn | 0:3ac96e360672 | 2610 | index = GetOutputDataIndex(Dev, presults); |
charlesmn | 0:3ac96e360672 | 2611 | presults_data = &(presults->VL53L1_p_002[index]); |
charlesmn | 0:3ac96e360672 | 2612 | Status = SetSimpleData(Dev, presults->active_results, |
charlesmn | 0:3ac96e360672 | 2613 | presults->device_status, |
charlesmn | 0:3ac96e360672 | 2614 | presults_data, |
charlesmn | 0:3ac96e360672 | 2615 | pRangingMeasurementData); |
charlesmn | 0:3ac96e360672 | 2616 | } |
charlesmn | 0:3ac96e360672 | 2617 | |
charlesmn | 0:3ac96e360672 | 2618 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2619 | return Status; |
charlesmn | 0:3ac96e360672 | 2620 | } |
charlesmn | 0:3ac96e360672 | 2621 | |
charlesmn | 0:3ac96e360672 | 2622 | static VL53L1_Error SetMeasurementData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2623 | VL53L1_range_results_t *presults, |
charlesmn | 0:3ac96e360672 | 2624 | VL53L1_MultiRangingData_t *pMultiRangingData) |
charlesmn | 0:3ac96e360672 | 2625 | { |
charlesmn | 0:3ac96e360672 | 2626 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 2627 | uint8_t i; |
charlesmn | 0:3ac96e360672 | 2628 | uint8_t iteration; |
charlesmn | 0:3ac96e360672 | 2629 | VL53L1_TargetRangeData_t *pRangeData; |
charlesmn | 0:3ac96e360672 | 2630 | VL53L1_range_data_t *presults_data; |
charlesmn | 0:3ac96e360672 | 2631 | int16_t dmax_min; |
charlesmn | 0:3ac96e360672 | 2632 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2633 | uint8_t Furthest_idx = 0; |
charlesmn | 0:3ac96e360672 | 2634 | int16_t Furthest_range = 0; |
charlesmn | 0:3ac96e360672 | 2635 | uint8_t ActiveResults, amb_idx; |
charlesmn | 0:3ac96e360672 | 2636 | |
charlesmn | 0:3ac96e360672 | 2637 | pMultiRangingData->NumberOfObjectsFound = presults->active_results; |
charlesmn | 0:3ac96e360672 | 2638 | pMultiRangingData->RoiNumber = presults->zone_id; |
charlesmn | 0:3ac96e360672 | 2639 | pMultiRangingData->HasXtalkValueChanged = |
charlesmn | 0:3ac96e360672 | 2640 | presults->smudge_corrector_data.new_xtalk_applied_flag; |
charlesmn | 0:3ac96e360672 | 2641 | dmax_min = MIN(presults->wrap_dmax_mm, |
charlesmn | 0:3ac96e360672 | 2642 | presults->VL53L1_p_007[DMAX_REFLECTANCE_IDX]); |
charlesmn | 0:3ac96e360672 | 2643 | pMultiRangingData->DmaxMilliMeter = dmax_min; |
charlesmn | 0:3ac96e360672 | 2644 | |
charlesmn | 0:3ac96e360672 | 2645 | |
charlesmn | 0:3ac96e360672 | 2646 | pMultiRangingData->TimeStamp = 0; |
charlesmn | 0:3ac96e360672 | 2647 | |
charlesmn | 0:3ac96e360672 | 2648 | pMultiRangingData->StreamCount = presults->stream_count; |
charlesmn | 0:3ac96e360672 | 2649 | |
charlesmn | 0:3ac96e360672 | 2650 | pMultiRangingData->RecommendedDistanceMode = |
charlesmn | 0:3ac96e360672 | 2651 | VL53L1DevDataGet(Dev, CurrentParameters.DistanceMode); |
charlesmn | 0:3ac96e360672 | 2652 | ActiveResults = presults->active_results; |
charlesmn | 0:3ac96e360672 | 2653 | if (ActiveResults < 1) |
charlesmn | 0:3ac96e360672 | 2654 | |
charlesmn | 0:3ac96e360672 | 2655 | iteration = 1; |
charlesmn | 0:3ac96e360672 | 2656 | else |
charlesmn | 0:3ac96e360672 | 2657 | iteration = ActiveResults; |
charlesmn | 0:3ac96e360672 | 2658 | for (i = 0; i < iteration; i++) { |
charlesmn | 0:3ac96e360672 | 2659 | pRangeData = &(pMultiRangingData->RangeData[i]); |
charlesmn | 0:3ac96e360672 | 2660 | |
charlesmn | 0:3ac96e360672 | 2661 | presults_data = &(presults->VL53L1_p_002[i]); |
charlesmn | 0:3ac96e360672 | 2662 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2663 | Status = SetTargetData(Dev, ActiveResults, |
charlesmn | 0:3ac96e360672 | 2664 | pMultiRangingData->StreamCount, |
charlesmn | 0:3ac96e360672 | 2665 | i, |
charlesmn | 0:3ac96e360672 | 2666 | presults->device_status, |
charlesmn | 0:3ac96e360672 | 2667 | presults_data, |
charlesmn | 0:3ac96e360672 | 2668 | pRangeData); |
charlesmn | 0:3ac96e360672 | 2669 | |
charlesmn | 0:3ac96e360672 | 2670 | pMultiRangingData->EffectiveSpadRtnCount = |
charlesmn | 0:3ac96e360672 | 2671 | presults_data->VL53L1_p_006; |
charlesmn | 0:3ac96e360672 | 2672 | |
charlesmn | 0:3ac96e360672 | 2673 | if ((pRangeData->RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) |
charlesmn | 0:3ac96e360672 | 2674 | && (pRangeData->RangeMilliMeter > Furthest_range)) { |
charlesmn | 0:3ac96e360672 | 2675 | Furthest_range = pRangeData->RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 2676 | Furthest_idx = i; |
charlesmn | 0:3ac96e360672 | 2677 | } |
charlesmn | 0:3ac96e360672 | 2678 | } |
charlesmn | 0:3ac96e360672 | 2679 | for (i = iteration; i < VL53L1_MAX_RANGE_RESULTS; i++) { |
charlesmn | 0:3ac96e360672 | 2680 | pdev->PreviousRangeMilliMeter[i] = 0; |
charlesmn | 0:3ac96e360672 | 2681 | pdev->PreviousRangeStatus[i] = 255; |
charlesmn | 0:3ac96e360672 | 2682 | pdev->PreviousExtendedRange[i] = 0; |
charlesmn | 0:3ac96e360672 | 2683 | } |
charlesmn | 0:3ac96e360672 | 2684 | |
charlesmn | 0:3ac96e360672 | 2685 | if ((Status == VL53L1_ERROR_NONE) && (ActiveResults > 0)) { |
charlesmn | 0:3ac96e360672 | 2686 | pRangeData = &(pMultiRangingData->RangeData[Furthest_idx]); |
charlesmn | 0:3ac96e360672 | 2687 | amb_idx = VL53L1_MAX_AMBIENT_DMAX_VALUES-1; |
charlesmn | 0:3ac96e360672 | 2688 | CheckAndChangeDistanceMode(Dev, pRangeData, |
charlesmn | 0:3ac96e360672 | 2689 | presults->VL53L1_p_007[amb_idx], |
charlesmn | 0:3ac96e360672 | 2690 | &pMultiRangingData->RecommendedDistanceMode); |
charlesmn | 0:3ac96e360672 | 2691 | } |
charlesmn | 0:3ac96e360672 | 2692 | |
charlesmn | 0:3ac96e360672 | 2693 | return Status; |
charlesmn | 0:3ac96e360672 | 2694 | } |
charlesmn | 0:3ac96e360672 | 2695 | |
charlesmn | 0:3ac96e360672 | 2696 | VL53L1_Error VL53L1_GetMultiRangingData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2697 | VL53L1_MultiRangingData_t *pMultiRangingData) |
charlesmn | 0:3ac96e360672 | 2698 | { |
charlesmn | 0:3ac96e360672 | 2699 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2700 | VL53L1_LLDriverData_t *pdev = |
charlesmn | 0:3ac96e360672 | 2701 | VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 2702 | VL53L1_range_results_t *presults = |
charlesmn | 0:3ac96e360672 | 2703 | (VL53L1_range_results_t *) pdev->wArea1; |
charlesmn | 0:3ac96e360672 | 2704 | |
charlesmn | 0:3ac96e360672 | 2705 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2706 | |
charlesmn | 0:3ac96e360672 | 2707 | |
charlesmn | 0:3ac96e360672 | 2708 | memset(pMultiRangingData, 0xFF, |
charlesmn | 0:3ac96e360672 | 2709 | sizeof(VL53L1_MultiRangingData_t)); |
charlesmn | 0:3ac96e360672 | 2710 | |
charlesmn | 0:3ac96e360672 | 2711 | |
charlesmn | 0:3ac96e360672 | 2712 | Status = VL53L1_get_device_results( |
charlesmn | 0:3ac96e360672 | 2713 | Dev, |
charlesmn | 0:3ac96e360672 | 2714 | VL53L1_DEVICERESULTSLEVEL_FULL, |
charlesmn | 0:3ac96e360672 | 2715 | presults); |
charlesmn | 0:3ac96e360672 | 2716 | |
charlesmn | 0:3ac96e360672 | 2717 | |
charlesmn | 0:3ac96e360672 | 2718 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 2719 | switch (presults->rd_device_state) { |
charlesmn | 0:3ac96e360672 | 2720 | case VL53L1_DEVICESTATE_RANGING_GATHER_DATA: |
charlesmn | 0:3ac96e360672 | 2721 | pMultiRangingData->RoiStatus = |
charlesmn | 0:3ac96e360672 | 2722 | VL53L1_ROISTATUS_VALID_NOT_LAST; |
charlesmn | 0:3ac96e360672 | 2723 | break; |
charlesmn | 0:3ac96e360672 | 2724 | case VL53L1_DEVICESTATE_RANGING_OUTPUT_DATA: |
charlesmn | 0:3ac96e360672 | 2725 | pMultiRangingData->RoiStatus = |
charlesmn | 0:3ac96e360672 | 2726 | VL53L1_ROISTATUS_VALID_LAST; |
charlesmn | 0:3ac96e360672 | 2727 | break; |
charlesmn | 0:3ac96e360672 | 2728 | default: |
charlesmn | 0:3ac96e360672 | 2729 | pMultiRangingData->RoiStatus = |
charlesmn | 0:3ac96e360672 | 2730 | VL53L1_ROISTATUS_NOT_VALID; |
charlesmn | 0:3ac96e360672 | 2731 | } |
charlesmn | 0:3ac96e360672 | 2732 | |
charlesmn | 0:3ac96e360672 | 2733 | Status = SetMeasurementData(Dev, |
charlesmn | 0:3ac96e360672 | 2734 | presults, |
charlesmn | 0:3ac96e360672 | 2735 | pMultiRangingData); |
charlesmn | 0:3ac96e360672 | 2736 | |
charlesmn | 0:3ac96e360672 | 2737 | } |
charlesmn | 0:3ac96e360672 | 2738 | |
charlesmn | 0:3ac96e360672 | 2739 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2740 | return Status; |
charlesmn | 0:3ac96e360672 | 2741 | } |
charlesmn | 0:3ac96e360672 | 2742 | |
charlesmn | 0:3ac96e360672 | 2743 | VL53L1_Error VL53L1_GetAdditionalData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2744 | VL53L1_AdditionalData_t *pAdditionalData) |
charlesmn | 0:3ac96e360672 | 2745 | { |
charlesmn | 0:3ac96e360672 | 2746 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2747 | |
charlesmn | 0:3ac96e360672 | 2748 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2749 | |
charlesmn | 0:3ac96e360672 | 2750 | Status = VL53L1_get_additional_data(Dev, pAdditionalData); |
charlesmn | 0:3ac96e360672 | 2751 | |
charlesmn | 0:3ac96e360672 | 2752 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2753 | return Status; |
charlesmn | 0:3ac96e360672 | 2754 | } |
charlesmn | 0:3ac96e360672 | 2755 | |
charlesmn | 0:3ac96e360672 | 2756 | |
charlesmn | 0:3ac96e360672 | 2757 | |
charlesmn | 0:3ac96e360672 | 2758 | |
charlesmn | 0:3ac96e360672 | 2759 | |
charlesmn | 0:3ac96e360672 | 2760 | |
charlesmn | 0:3ac96e360672 | 2761 | VL53L1_Error VL53L1_SetTuningParameter(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2762 | uint16_t TuningParameterId, int32_t TuningParameterValue) |
charlesmn | 0:3ac96e360672 | 2763 | { |
charlesmn | 0:3ac96e360672 | 2764 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2765 | |
charlesmn | 0:3ac96e360672 | 2766 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2767 | |
charlesmn | 0:3ac96e360672 | 2768 | if (TuningParameterId == |
charlesmn | 0:3ac96e360672 | 2769 | VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS) |
charlesmn | 0:3ac96e360672 | 2770 | return VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 2771 | |
charlesmn | 0:3ac96e360672 | 2772 | if (TuningParameterId >= 32768) |
charlesmn | 0:3ac96e360672 | 2773 | Status = VL53L1_set_tuning_parm(Dev, |
charlesmn | 0:3ac96e360672 | 2774 | TuningParameterId, |
charlesmn | 0:3ac96e360672 | 2775 | TuningParameterValue); |
charlesmn | 0:3ac96e360672 | 2776 | else { |
charlesmn | 0:3ac96e360672 | 2777 | if (TuningParameterId < VL53L1_TUNING_MAX_TUNABLE_KEY) |
charlesmn | 0:3ac96e360672 | 2778 | BDTable[TuningParameterId] = TuningParameterValue; |
charlesmn | 0:3ac96e360672 | 2779 | else |
charlesmn | 0:3ac96e360672 | 2780 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 2781 | } |
charlesmn | 0:3ac96e360672 | 2782 | |
charlesmn | 0:3ac96e360672 | 2783 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2784 | return Status; |
charlesmn | 0:3ac96e360672 | 2785 | } |
charlesmn | 0:3ac96e360672 | 2786 | |
charlesmn | 0:3ac96e360672 | 2787 | VL53L1_Error VL53L1_GetTuningParameter(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2788 | uint16_t TuningParameterId, int32_t *pTuningParameterValue) |
charlesmn | 0:3ac96e360672 | 2789 | { |
charlesmn | 0:3ac96e360672 | 2790 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2791 | |
charlesmn | 0:3ac96e360672 | 2792 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2793 | |
charlesmn | 0:3ac96e360672 | 2794 | if (TuningParameterId >= 32768) |
charlesmn | 0:3ac96e360672 | 2795 | Status = VL53L1_get_tuning_parm(Dev, |
charlesmn | 0:3ac96e360672 | 2796 | TuningParameterId, |
charlesmn | 0:3ac96e360672 | 2797 | pTuningParameterValue); |
charlesmn | 0:3ac96e360672 | 2798 | else { |
charlesmn | 0:3ac96e360672 | 2799 | if (TuningParameterId < VL53L1_TUNING_MAX_TUNABLE_KEY) |
charlesmn | 0:3ac96e360672 | 2800 | *pTuningParameterValue = BDTable[TuningParameterId]; |
charlesmn | 0:3ac96e360672 | 2801 | else |
charlesmn | 0:3ac96e360672 | 2802 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 2803 | } |
charlesmn | 0:3ac96e360672 | 2804 | |
charlesmn | 0:3ac96e360672 | 2805 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2806 | return Status; |
charlesmn | 0:3ac96e360672 | 2807 | } |
charlesmn | 0:3ac96e360672 | 2808 | |
charlesmn | 0:3ac96e360672 | 2809 | |
charlesmn | 0:3ac96e360672 | 2810 | VL53L1_Error VL53L1_PerformRefSpadManagement(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 2811 | { |
charlesmn | 0:3ac96e360672 | 2812 | #ifdef VL53L1_NOCALIB |
charlesmn | 0:3ac96e360672 | 2813 | VL53L1_Error Status = VL53L1_ERROR_NOT_SUPPORTED; |
charlesmn | 0:3ac96e360672 | 2814 | |
charlesmn | 0:3ac96e360672 | 2815 | SUPPRESS_UNUSED_WARNING(Dev); |
charlesmn | 0:3ac96e360672 | 2816 | |
charlesmn | 0:3ac96e360672 | 2817 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2818 | #else |
charlesmn | 0:3ac96e360672 | 2819 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2820 | VL53L1_Error RawStatus; |
charlesmn | 0:3ac96e360672 | 2821 | uint8_t dcrbuffer[24]; |
charlesmn | 0:3ac96e360672 | 2822 | uint8_t *commbuf; |
charlesmn | 0:3ac96e360672 | 2823 | uint8_t numloc[2] = {5, 3}; |
charlesmn | 0:3ac96e360672 | 2824 | VL53L1_LLDriverData_t *pdev; |
charlesmn | 0:3ac96e360672 | 2825 | VL53L1_customer_nvm_managed_t *pc; |
charlesmn | 0:3ac96e360672 | 2826 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 2827 | |
charlesmn | 0:3ac96e360672 | 2828 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2829 | |
charlesmn | 0:3ac96e360672 | 2830 | pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 2831 | pc = &pdev->customer; |
charlesmn | 0:3ac96e360672 | 2832 | |
charlesmn | 0:3ac96e360672 | 2833 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 2834 | PresetMode = VL53L1DevDataGet(Dev, |
charlesmn | 0:3ac96e360672 | 2835 | CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 2836 | Status = VL53L1_run_ref_spad_char(Dev, &RawStatus); |
charlesmn | 0:3ac96e360672 | 2837 | |
charlesmn | 0:3ac96e360672 | 2838 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2839 | Status = VL53L1_SetPresetMode(Dev, PresetMode); |
charlesmn | 0:3ac96e360672 | 2840 | } |
charlesmn | 0:3ac96e360672 | 2841 | |
charlesmn | 0:3ac96e360672 | 2842 | if (Status == VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH) { |
charlesmn | 0:3ac96e360672 | 2843 | |
charlesmn | 0:3ac96e360672 | 2844 | Status = VL53L1_read_nvm_raw_data(Dev, |
charlesmn | 0:3ac96e360672 | 2845 | (uint8_t)(0xA0 >> 2), |
charlesmn | 0:3ac96e360672 | 2846 | (uint8_t)(24 >> 2), |
charlesmn | 0:3ac96e360672 | 2847 | dcrbuffer); |
charlesmn | 0:3ac96e360672 | 2848 | |
charlesmn | 0:3ac96e360672 | 2849 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2850 | Status = VL53L1_WriteMulti(Dev, |
charlesmn | 0:3ac96e360672 | 2851 | VL53L1_REF_SPAD_MAN__NUM_REQUESTED_REF_SPADS, |
charlesmn | 0:3ac96e360672 | 2852 | numloc, 2); |
charlesmn | 0:3ac96e360672 | 2853 | |
charlesmn | 0:3ac96e360672 | 2854 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 2855 | pc->ref_spad_man__num_requested_ref_spads = numloc[0]; |
charlesmn | 0:3ac96e360672 | 2856 | pc->ref_spad_man__ref_location = numloc[1]; |
charlesmn | 0:3ac96e360672 | 2857 | } |
charlesmn | 0:3ac96e360672 | 2858 | |
charlesmn | 0:3ac96e360672 | 2859 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2860 | commbuf = &dcrbuffer[16]; |
charlesmn | 0:3ac96e360672 | 2861 | |
charlesmn | 0:3ac96e360672 | 2862 | |
charlesmn | 0:3ac96e360672 | 2863 | |
charlesmn | 0:3ac96e360672 | 2864 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2865 | Status = VL53L1_WriteMulti(Dev, |
charlesmn | 0:3ac96e360672 | 2866 | VL53L1_GLOBAL_CONFIG__SPAD_ENABLES_REF_0, |
charlesmn | 0:3ac96e360672 | 2867 | commbuf, 6); |
charlesmn | 0:3ac96e360672 | 2868 | |
charlesmn | 0:3ac96e360672 | 2869 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 2870 | pc->global_config__spad_enables_ref_0 = commbuf[0]; |
charlesmn | 0:3ac96e360672 | 2871 | pc->global_config__spad_enables_ref_1 = commbuf[1]; |
charlesmn | 0:3ac96e360672 | 2872 | pc->global_config__spad_enables_ref_2 = commbuf[2]; |
charlesmn | 0:3ac96e360672 | 2873 | pc->global_config__spad_enables_ref_3 = commbuf[3]; |
charlesmn | 0:3ac96e360672 | 2874 | pc->global_config__spad_enables_ref_4 = commbuf[4]; |
charlesmn | 0:3ac96e360672 | 2875 | pc->global_config__spad_enables_ref_5 = commbuf[5]; |
charlesmn | 0:3ac96e360672 | 2876 | } |
charlesmn | 0:3ac96e360672 | 2877 | |
charlesmn | 0:3ac96e360672 | 2878 | } |
charlesmn | 0:3ac96e360672 | 2879 | |
charlesmn | 0:3ac96e360672 | 2880 | #endif |
charlesmn | 0:3ac96e360672 | 2881 | |
charlesmn | 0:3ac96e360672 | 2882 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2883 | return Status; |
charlesmn | 0:3ac96e360672 | 2884 | } |
charlesmn | 0:3ac96e360672 | 2885 | |
charlesmn | 0:3ac96e360672 | 2886 | VL53L1_Error VL53L1_SmudgeCorrectionEnable(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2887 | VL53L1_SmudgeCorrectionModes Mode) |
charlesmn | 0:3ac96e360672 | 2888 | { |
charlesmn | 0:3ac96e360672 | 2889 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2890 | VL53L1_Error s1 = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2891 | VL53L1_Error s2 = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2892 | VL53L1_Error s3 = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2893 | |
charlesmn | 0:3ac96e360672 | 2894 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2895 | |
charlesmn | 0:3ac96e360672 | 2896 | switch (Mode) { |
charlesmn | 0:3ac96e360672 | 2897 | case VL53L1_SMUDGE_CORRECTION_NONE: |
charlesmn | 0:3ac96e360672 | 2898 | s1 = VL53L1_dynamic_xtalk_correction_disable(Dev); |
charlesmn | 0:3ac96e360672 | 2899 | s2 = VL53L1_dynamic_xtalk_correction_apply_disable(Dev); |
charlesmn | 0:3ac96e360672 | 2900 | s3 = VL53L1_dynamic_xtalk_correction_single_apply_disable(Dev); |
charlesmn | 0:3ac96e360672 | 2901 | break; |
charlesmn | 0:3ac96e360672 | 2902 | case VL53L1_SMUDGE_CORRECTION_CONTINUOUS: |
charlesmn | 0:3ac96e360672 | 2903 | s1 = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 2904 | s2 = VL53L1_dynamic_xtalk_correction_apply_enable(Dev); |
charlesmn | 0:3ac96e360672 | 2905 | s3 = VL53L1_dynamic_xtalk_correction_single_apply_disable(Dev); |
charlesmn | 0:3ac96e360672 | 2906 | break; |
charlesmn | 0:3ac96e360672 | 2907 | case VL53L1_SMUDGE_CORRECTION_SINGLE: |
charlesmn | 0:3ac96e360672 | 2908 | s1 = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 2909 | s2 = VL53L1_dynamic_xtalk_correction_apply_enable(Dev); |
charlesmn | 0:3ac96e360672 | 2910 | s3 = VL53L1_dynamic_xtalk_correction_single_apply_enable(Dev); |
charlesmn | 0:3ac96e360672 | 2911 | break; |
charlesmn | 0:3ac96e360672 | 2912 | case VL53L1_SMUDGE_CORRECTION_DEBUG: |
charlesmn | 0:3ac96e360672 | 2913 | s1 = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 2914 | s2 = VL53L1_dynamic_xtalk_correction_apply_disable(Dev); |
charlesmn | 0:3ac96e360672 | 2915 | s3 = VL53L1_dynamic_xtalk_correction_single_apply_disable(Dev); |
charlesmn | 0:3ac96e360672 | 2916 | break; |
charlesmn | 0:3ac96e360672 | 2917 | default: |
charlesmn | 0:3ac96e360672 | 2918 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 2919 | break; |
charlesmn | 0:3ac96e360672 | 2920 | } |
charlesmn | 0:3ac96e360672 | 2921 | |
charlesmn | 0:3ac96e360672 | 2922 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 2923 | Status = s1; |
charlesmn | 0:3ac96e360672 | 2924 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2925 | Status = s2; |
charlesmn | 0:3ac96e360672 | 2926 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 2927 | Status = s3; |
charlesmn | 0:3ac96e360672 | 2928 | } |
charlesmn | 0:3ac96e360672 | 2929 | |
charlesmn | 0:3ac96e360672 | 2930 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2931 | return Status; |
charlesmn | 0:3ac96e360672 | 2932 | } |
charlesmn | 0:3ac96e360672 | 2933 | |
charlesmn | 0:3ac96e360672 | 2934 | VL53L1_Error VL53L1_SetXTalkCompensationEnable(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2935 | uint8_t XTalkCompensationEnable) |
charlesmn | 0:3ac96e360672 | 2936 | { |
charlesmn | 0:3ac96e360672 | 2937 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2938 | |
charlesmn | 0:3ac96e360672 | 2939 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2940 | |
charlesmn | 0:3ac96e360672 | 2941 | if (XTalkCompensationEnable == 0) |
charlesmn | 0:3ac96e360672 | 2942 | Status = VL53L1_disable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 2943 | else |
charlesmn | 0:3ac96e360672 | 2944 | Status = VL53L1_enable_xtalk_compensation(Dev); |
charlesmn | 0:3ac96e360672 | 2945 | |
charlesmn | 0:3ac96e360672 | 2946 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2947 | return Status; |
charlesmn | 0:3ac96e360672 | 2948 | } |
charlesmn | 0:3ac96e360672 | 2949 | |
charlesmn | 0:3ac96e360672 | 2950 | |
charlesmn | 0:3ac96e360672 | 2951 | VL53L1_Error VL53L1_GetXTalkCompensationEnable(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2952 | uint8_t *pXTalkCompensationEnable) |
charlesmn | 0:3ac96e360672 | 2953 | { |
charlesmn | 0:3ac96e360672 | 2954 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2955 | |
charlesmn | 0:3ac96e360672 | 2956 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2957 | |
charlesmn | 0:3ac96e360672 | 2958 | VL53L1_get_xtalk_compensation_enable( |
charlesmn | 0:3ac96e360672 | 2959 | Dev, |
charlesmn | 0:3ac96e360672 | 2960 | pXTalkCompensationEnable); |
charlesmn | 0:3ac96e360672 | 2961 | |
charlesmn | 0:3ac96e360672 | 2962 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 2963 | return Status; |
charlesmn | 0:3ac96e360672 | 2964 | } |
charlesmn | 0:3ac96e360672 | 2965 | |
charlesmn | 0:3ac96e360672 | 2966 | |
charlesmn | 0:3ac96e360672 | 2967 | VL53L1_Error VL53L1_PerformXTalkCalibration(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 2968 | uint8_t CalibrationOption) |
charlesmn | 0:3ac96e360672 | 2969 | { |
charlesmn | 0:3ac96e360672 | 2970 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 2971 | VL53L1_Error UStatus; |
charlesmn | 0:3ac96e360672 | 2972 | int16_t CalDistanceMm; |
charlesmn | 0:3ac96e360672 | 2973 | VL53L1_xtalk_calibration_results_t xtalk; |
charlesmn | 0:3ac96e360672 | 2974 | |
charlesmn | 0:3ac96e360672 | 2975 | VL53L1_CalibrationData_t caldata; |
charlesmn | 0:3ac96e360672 | 2976 | VL53L1_LLDriverData_t *pLLData; |
charlesmn | 0:3ac96e360672 | 2977 | int i; |
charlesmn | 0:3ac96e360672 | 2978 | uint32_t *pPlaneOffsetKcps; |
charlesmn | 0:3ac96e360672 | 2979 | uint32_t Margin = |
charlesmn | 0:3ac96e360672 | 2980 | BDTable[VL53L1_TUNING_XTALK_FULL_ROI_BIN_SUM_MARGIN]; |
charlesmn | 0:3ac96e360672 | 2981 | uint32_t DefaultOffset = |
charlesmn | 0:3ac96e360672 | 2982 | BDTable[VL53L1_TUNING_XTALK_FULL_ROI_DEFAULT_OFFSET]; |
charlesmn | 0:3ac96e360672 | 2983 | uint32_t *pLLDataPlaneOffsetKcps; |
charlesmn | 0:3ac96e360672 | 2984 | uint32_t sum = 0; |
charlesmn | 0:3ac96e360672 | 2985 | uint8_t binok = 0; |
charlesmn | 0:3ac96e360672 | 2986 | int32_t merge; |
charlesmn | 0:3ac96e360672 | 2987 | |
charlesmn | 0:3ac96e360672 | 2988 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 2989 | |
charlesmn | 0:3ac96e360672 | 2990 | pPlaneOffsetKcps = |
charlesmn | 0:3ac96e360672 | 2991 | &caldata.customer.algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 2992 | pLLData = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 2993 | pLLDataPlaneOffsetKcps = |
charlesmn | 0:3ac96e360672 | 2994 | &pLLData->xtalk_cal.algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 2995 | VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, &merge); |
charlesmn | 0:3ac96e360672 | 2996 | |
charlesmn | 0:3ac96e360672 | 2997 | VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, 0); |
charlesmn | 0:3ac96e360672 | 2998 | switch (CalibrationOption) { |
charlesmn | 0:3ac96e360672 | 2999 | case VL53L1_XTALKCALIBRATIONMODE_NO_TARGET: |
charlesmn | 0:3ac96e360672 | 3000 | Status = VL53L1_run_xtalk_extraction(Dev, &UStatus); |
charlesmn | 0:3ac96e360672 | 3001 | |
charlesmn | 0:3ac96e360672 | 3002 | if (Status == VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL) |
charlesmn | 0:3ac96e360672 | 3003 | VL53L1_xtalk_cal_data_init(Dev); |
charlesmn | 0:3ac96e360672 | 3004 | break; |
charlesmn | 0:3ac96e360672 | 3005 | case VL53L1_XTALKCALIBRATIONMODE_SINGLE_TARGET: |
charlesmn | 0:3ac96e360672 | 3006 | Status = SingleTargetXTalkCalibration(Dev); |
charlesmn | 0:3ac96e360672 | 3007 | break; |
charlesmn | 0:3ac96e360672 | 3008 | case VL53L1_XTALKCALIBRATIONMODE_FULL_ROI: |
charlesmn | 0:3ac96e360672 | 3009 | CalDistanceMm = (int16_t) |
charlesmn | 0:3ac96e360672 | 3010 | BDTable[VL53L1_TUNING_XTALK_FULL_ROI_TARGET_DISTANCE_MM]; |
charlesmn | 0:3ac96e360672 | 3011 | |
charlesmn | 0:3ac96e360672 | 3012 | VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, |
charlesmn | 0:3ac96e360672 | 3013 | merge); |
charlesmn | 0:3ac96e360672 | 3014 | Status = VL53L1_run_hist_xtalk_extraction(Dev, CalDistanceMm, |
charlesmn | 0:3ac96e360672 | 3015 | &UStatus); |
charlesmn | 0:3ac96e360672 | 3016 | |
charlesmn | 0:3ac96e360672 | 3017 | VL53L1_GetCalibrationData(Dev, &caldata); |
charlesmn | 0:3ac96e360672 | 3018 | for (i = 0; i < VL53L1_XTALK_HISTO_BINS; i++) { |
charlesmn | 0:3ac96e360672 | 3019 | sum += caldata.xtalkhisto.xtalk_shape.bin_data[i]; |
charlesmn | 0:3ac96e360672 | 3020 | if (caldata.xtalkhisto.xtalk_shape.bin_data[i] > 0) |
charlesmn | 0:3ac96e360672 | 3021 | binok++; |
charlesmn | 0:3ac96e360672 | 3022 | } |
charlesmn | 0:3ac96e360672 | 3023 | if ((UStatus == |
charlesmn | 0:3ac96e360672 | 3024 | VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL) || |
charlesmn | 0:3ac96e360672 | 3025 | (sum > (1024 + Margin)) || (sum < (1024 - Margin)) || |
charlesmn | 0:3ac96e360672 | 3026 | (binok < 3)) { |
charlesmn | 0:3ac96e360672 | 3027 | *pPlaneOffsetKcps = DefaultOffset; |
charlesmn | 0:3ac96e360672 | 3028 | *pLLDataPlaneOffsetKcps = DefaultOffset; |
charlesmn | 0:3ac96e360672 | 3029 | caldata.xtalkhisto.xtalk_shape.bin_data[0] = 307; |
charlesmn | 0:3ac96e360672 | 3030 | caldata.xtalkhisto.xtalk_shape.bin_data[1] = 410; |
charlesmn | 0:3ac96e360672 | 3031 | caldata.xtalkhisto.xtalk_shape.bin_data[2] = 410; |
charlesmn | 0:3ac96e360672 | 3032 | caldata.xtalkhisto.xtalk_shape.bin_data[3] = 307; |
charlesmn | 0:3ac96e360672 | 3033 | for (i = 4; i < VL53L1_XTALK_HISTO_BINS; i++) |
charlesmn | 0:3ac96e360672 | 3034 | caldata.xtalkhisto.xtalk_shape.bin_data[i] = 0; |
charlesmn | 0:3ac96e360672 | 3035 | for (i = 0; i < VL53L1_BIN_REC_SIZE; i++) |
charlesmn | 0:3ac96e360672 | 3036 | caldata.algo__xtalk_cpo_HistoMerge_kcps[i] = |
charlesmn | 0:3ac96e360672 | 3037 | DefaultOffset + DefaultOffset * i; |
charlesmn | 0:3ac96e360672 | 3038 | VL53L1_SetCalibrationData(Dev, &caldata); |
charlesmn | 0:3ac96e360672 | 3039 | } |
charlesmn | 0:3ac96e360672 | 3040 | |
charlesmn | 0:3ac96e360672 | 3041 | break; |
charlesmn | 0:3ac96e360672 | 3042 | default: |
charlesmn | 0:3ac96e360672 | 3043 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 3044 | } |
charlesmn | 0:3ac96e360672 | 3045 | VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, merge); |
charlesmn | 0:3ac96e360672 | 3046 | |
charlesmn | 0:3ac96e360672 | 3047 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3048 | Status = VL53L1_get_current_xtalk_settings(Dev, &xtalk); |
charlesmn | 0:3ac96e360672 | 3049 | Status = VL53L1_set_tuning_parm(Dev, |
charlesmn | 0:3ac96e360672 | 3050 | VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS, |
charlesmn | 0:3ac96e360672 | 3051 | xtalk.algo__crosstalk_compensation_plane_offset_kcps); |
charlesmn | 0:3ac96e360672 | 3052 | } |
charlesmn | 0:3ac96e360672 | 3053 | |
charlesmn | 0:3ac96e360672 | 3054 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3055 | return Status; |
charlesmn | 0:3ac96e360672 | 3056 | } |
charlesmn | 0:3ac96e360672 | 3057 | |
charlesmn | 0:3ac96e360672 | 3058 | VL53L1_Error VL53L1_SetOffsetCalibrationMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3059 | VL53L1_OffsetCalibrationModes OffsetCalibrationMode) |
charlesmn | 0:3ac96e360672 | 3060 | { |
charlesmn | 0:3ac96e360672 | 3061 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3062 | VL53L1_OffsetCalibrationMode offset_cal_mode; |
charlesmn | 0:3ac96e360672 | 3063 | |
charlesmn | 0:3ac96e360672 | 3064 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3065 | |
charlesmn | 0:3ac96e360672 | 3066 | if (OffsetCalibrationMode == VL53L1_OFFSETCALIBRATIONMODE_STANDARD) { |
charlesmn | 0:3ac96e360672 | 3067 | offset_cal_mode = |
charlesmn | 0:3ac96e360672 | 3068 | VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD; |
charlesmn | 0:3ac96e360672 | 3069 | } else if (OffsetCalibrationMode == |
charlesmn | 0:3ac96e360672 | 3070 | VL53L1_OFFSETCALIBRATIONMODE_PRERANGE_ONLY) { |
charlesmn | 0:3ac96e360672 | 3071 | offset_cal_mode = |
charlesmn | 0:3ac96e360672 | 3072 | VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY; |
charlesmn | 0:3ac96e360672 | 3073 | } else if (OffsetCalibrationMode == |
charlesmn | 0:3ac96e360672 | 3074 | VL53L1_OFFSETCALIBRATIONMODE_MULTI_ZONE) { |
charlesmn | 0:3ac96e360672 | 3075 | offset_cal_mode = |
charlesmn | 0:3ac96e360672 | 3076 | VL53L1_OFFSETCALIBRATIONMODE__PER_ZONE; |
charlesmn | 0:3ac96e360672 | 3077 | } else { |
charlesmn | 0:3ac96e360672 | 3078 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 3079 | } |
charlesmn | 0:3ac96e360672 | 3080 | |
charlesmn | 0:3ac96e360672 | 3081 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3082 | Status = VL53L1_set_offset_calibration_mode(Dev, |
charlesmn | 0:3ac96e360672 | 3083 | offset_cal_mode); |
charlesmn | 0:3ac96e360672 | 3084 | |
charlesmn | 0:3ac96e360672 | 3085 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3086 | return Status; |
charlesmn | 0:3ac96e360672 | 3087 | } |
charlesmn | 0:3ac96e360672 | 3088 | |
charlesmn | 0:3ac96e360672 | 3089 | VL53L1_Error VL53L1_SetOffsetCorrectionMode(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3090 | VL53L1_OffsetCorrectionModes OffsetCorrectionMode) |
charlesmn | 0:3ac96e360672 | 3091 | { |
charlesmn | 0:3ac96e360672 | 3092 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3093 | VL53L1_OffsetCorrectionMode offset_cor_mode; |
charlesmn | 0:3ac96e360672 | 3094 | |
charlesmn | 0:3ac96e360672 | 3095 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3096 | |
charlesmn | 0:3ac96e360672 | 3097 | if (OffsetCorrectionMode == VL53L1_OFFSETCORRECTIONMODE_STANDARD) { |
charlesmn | 0:3ac96e360672 | 3098 | offset_cor_mode = |
charlesmn | 0:3ac96e360672 | 3099 | VL53L1_OFFSETCORRECTIONMODE__MM1_MM2_OFFSETS; |
charlesmn | 0:3ac96e360672 | 3100 | } else if (OffsetCorrectionMode == |
charlesmn | 0:3ac96e360672 | 3101 | VL53L1_OFFSETCORRECTIONMODE_PERZONE) { |
charlesmn | 0:3ac96e360672 | 3102 | offset_cor_mode = |
charlesmn | 0:3ac96e360672 | 3103 | VL53L1_OFFSETCORRECTIONMODE__PER_ZONE_OFFSETS; |
charlesmn | 0:3ac96e360672 | 3104 | } else if (OffsetCorrectionMode == |
charlesmn | 0:3ac96e360672 | 3105 | VL53L1_OFFSETCORRECTIONMODE_PERVCSEL) { |
charlesmn | 0:3ac96e360672 | 3106 | offset_cor_mode = |
charlesmn | 0:3ac96e360672 | 3107 | VL53L1_OFFSETCORRECTIONMODE__PER_VCSEL_OFFSETS; |
charlesmn | 0:3ac96e360672 | 3108 | } else { |
charlesmn | 0:3ac96e360672 | 3109 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 3110 | } |
charlesmn | 0:3ac96e360672 | 3111 | |
charlesmn | 0:3ac96e360672 | 3112 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3113 | Status = VL53L1_set_offset_correction_mode(Dev, |
charlesmn | 0:3ac96e360672 | 3114 | offset_cor_mode); |
charlesmn | 0:3ac96e360672 | 3115 | |
charlesmn | 0:3ac96e360672 | 3116 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3117 | return Status; |
charlesmn | 0:3ac96e360672 | 3118 | } |
charlesmn | 0:3ac96e360672 | 3119 | |
charlesmn | 0:3ac96e360672 | 3120 | VL53L1_Error VL53L1_PerformOffsetCalibration(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3121 | int32_t CalDistanceMilliMeter, FixPoint1616_t CalReflectancePercent) |
charlesmn | 0:3ac96e360672 | 3122 | { |
charlesmn | 0:3ac96e360672 | 3123 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3124 | VL53L1_Error UnfilteredStatus; |
charlesmn | 0:3ac96e360672 | 3125 | VL53L1_OffsetCalibrationMode offset_cal_mode; |
charlesmn | 0:3ac96e360672 | 3126 | uint16_t CalReflectancePercent_int; |
charlesmn | 0:3ac96e360672 | 3127 | |
charlesmn | 0:3ac96e360672 | 3128 | VL53L1_DevicePresetModes device_preset_mode; |
charlesmn | 0:3ac96e360672 | 3129 | VL53L1_DeviceZonePreset zone_preset; |
charlesmn | 0:3ac96e360672 | 3130 | VL53L1_zone_config_t zone_cfg; |
charlesmn | 0:3ac96e360672 | 3131 | int32_t MergeEnabled; |
charlesmn | 0:3ac96e360672 | 3132 | |
charlesmn | 0:3ac96e360672 | 3133 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3134 | |
charlesmn | 0:3ac96e360672 | 3135 | CalReflectancePercent_int = |
charlesmn | 0:3ac96e360672 | 3136 | VL53L1_FIXPOINT1616TOFIXPOINT72(CalReflectancePercent); |
charlesmn | 0:3ac96e360672 | 3137 | |
charlesmn | 0:3ac96e360672 | 3138 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3139 | Status = VL53L1_get_offset_calibration_mode(Dev, |
charlesmn | 0:3ac96e360672 | 3140 | &offset_cal_mode); |
charlesmn | 0:3ac96e360672 | 3141 | |
charlesmn | 0:3ac96e360672 | 3142 | if (Status != VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3143 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3144 | return Status; |
charlesmn | 0:3ac96e360672 | 3145 | } |
charlesmn | 0:3ac96e360672 | 3146 | |
charlesmn | 0:3ac96e360672 | 3147 | |
charlesmn | 0:3ac96e360672 | 3148 | if ((offset_cal_mode == |
charlesmn | 0:3ac96e360672 | 3149 | VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD) || |
charlesmn | 0:3ac96e360672 | 3150 | (offset_cal_mode == |
charlesmn | 0:3ac96e360672 | 3151 | VL53L1_OFFSETCALIBRATIONMODE__MM1_MM2__STANDARD_PRE_RANGE_ONLY |
charlesmn | 0:3ac96e360672 | 3152 | )) { |
charlesmn | 0:3ac96e360672 | 3153 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3154 | Status = VL53L1_run_offset_calibration( |
charlesmn | 0:3ac96e360672 | 3155 | Dev, |
charlesmn | 0:3ac96e360672 | 3156 | (int16_t)CalDistanceMilliMeter, |
charlesmn | 0:3ac96e360672 | 3157 | CalReflectancePercent_int, |
charlesmn | 0:3ac96e360672 | 3158 | &UnfilteredStatus); |
charlesmn | 0:3ac96e360672 | 3159 | |
charlesmn | 0:3ac96e360672 | 3160 | } else if (offset_cal_mode == |
charlesmn | 0:3ac96e360672 | 3161 | VL53L1_OFFSETCALIBRATIONMODE__PER_ZONE) { |
charlesmn | 0:3ac96e360672 | 3162 | VL53L1_get_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, |
charlesmn | 0:3ac96e360672 | 3163 | &MergeEnabled); |
charlesmn | 0:3ac96e360672 | 3164 | VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, 0); |
charlesmn | 0:3ac96e360672 | 3165 | device_preset_mode = |
charlesmn | 0:3ac96e360672 | 3166 | VL53L1_DEVICEPRESETMODE_HISTOGRAM_MULTIZONE_LONG_RANGE; |
charlesmn | 0:3ac96e360672 | 3167 | zone_preset = VL53L1_DEVICEZONEPRESET_CUSTOM; |
charlesmn | 0:3ac96e360672 | 3168 | |
charlesmn | 0:3ac96e360672 | 3169 | Status = VL53L1_get_zone_config(Dev, &zone_cfg); |
charlesmn | 0:3ac96e360672 | 3170 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3171 | Status = VL53L1_run_zone_calibration( |
charlesmn | 0:3ac96e360672 | 3172 | Dev, |
charlesmn | 0:3ac96e360672 | 3173 | device_preset_mode, |
charlesmn | 0:3ac96e360672 | 3174 | zone_preset, |
charlesmn | 0:3ac96e360672 | 3175 | &zone_cfg, |
charlesmn | 0:3ac96e360672 | 3176 | (int16_t)CalDistanceMilliMeter, |
charlesmn | 0:3ac96e360672 | 3177 | CalReflectancePercent_int, |
charlesmn | 0:3ac96e360672 | 3178 | &UnfilteredStatus); |
charlesmn | 0:3ac96e360672 | 3179 | VL53L1_set_tuning_parm(Dev, VL53L1_TUNINGPARM_HIST_MERGE, |
charlesmn | 0:3ac96e360672 | 3180 | MergeEnabled); |
charlesmn | 0:3ac96e360672 | 3181 | |
charlesmn | 0:3ac96e360672 | 3182 | } else { |
charlesmn | 0:3ac96e360672 | 3183 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 3184 | } |
charlesmn | 0:3ac96e360672 | 3185 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3186 | return Status; |
charlesmn | 0:3ac96e360672 | 3187 | } |
charlesmn | 0:3ac96e360672 | 3188 | |
charlesmn | 0:3ac96e360672 | 3189 | VL53L1_Error VL53L1_PerformOffsetSimpleCalibration(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3190 | int32_t CalDistanceMilliMeter) |
charlesmn | 0:3ac96e360672 | 3191 | { |
charlesmn | 0:3ac96e360672 | 3192 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3193 | int32_t sum_ranging; |
charlesmn | 0:3ac96e360672 | 3194 | uint8_t offset_meas; |
charlesmn | 0:3ac96e360672 | 3195 | int16_t Max, UnderMax, OverMax, Repeat; |
charlesmn | 0:3ac96e360672 | 3196 | int32_t total_count, inloopcount; |
charlesmn | 0:3ac96e360672 | 3197 | int32_t IncRounding; |
charlesmn | 0:3ac96e360672 | 3198 | int16_t meanDistance_mm; |
charlesmn | 0:3ac96e360672 | 3199 | int16_t offset; |
charlesmn | 0:3ac96e360672 | 3200 | VL53L1_RangingMeasurementData_t RangingMeasurementData; |
charlesmn | 0:3ac96e360672 | 3201 | VL53L1_LLDriverData_t *pdev; |
charlesmn | 0:3ac96e360672 | 3202 | uint8_t goodmeas; |
charlesmn | 0:3ac96e360672 | 3203 | VL53L1_Error SmudgeStatus = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3204 | uint8_t smudge_corr_en; |
charlesmn | 0:3ac96e360672 | 3205 | |
charlesmn | 0:3ac96e360672 | 3206 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3207 | |
charlesmn | 0:3ac96e360672 | 3208 | pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 3209 | |
charlesmn | 0:3ac96e360672 | 3210 | smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled; |
charlesmn | 0:3ac96e360672 | 3211 | SmudgeStatus = VL53L1_dynamic_xtalk_correction_disable(Dev); |
charlesmn | 0:3ac96e360672 | 3212 | |
charlesmn | 0:3ac96e360672 | 3213 | pdev->customer.algo__part_to_part_range_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3214 | pdev->customer.mm_config__inner_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3215 | pdev->customer.mm_config__outer_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3216 | memset(&pdev->per_vcsel_cal_data, 0, sizeof(pdev->per_vcsel_cal_data)); |
charlesmn | 0:3ac96e360672 | 3217 | Repeat = BDTable[VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT]; |
charlesmn | 0:3ac96e360672 | 3218 | Max = BDTable[ |
charlesmn | 0:3ac96e360672 | 3219 | VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER]; |
charlesmn | 0:3ac96e360672 | 3220 | UnderMax = 1 + (Max / 2); |
charlesmn | 0:3ac96e360672 | 3221 | OverMax = Max + (Max / 2); |
charlesmn | 0:3ac96e360672 | 3222 | sum_ranging = 0; |
charlesmn | 0:3ac96e360672 | 3223 | total_count = 0; |
charlesmn | 0:3ac96e360672 | 3224 | |
charlesmn | 0:3ac96e360672 | 3225 | while ((Repeat > 0) && (Status == VL53L1_ERROR_NONE)) { |
charlesmn | 0:3ac96e360672 | 3226 | Status = VL53L1_StartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3227 | |
charlesmn | 0:3ac96e360672 | 3228 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3229 | VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 3230 | VL53L1_GetRangingMeasurementData(Dev, |
charlesmn | 0:3ac96e360672 | 3231 | &RangingMeasurementData); |
charlesmn | 0:3ac96e360672 | 3232 | VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3233 | } |
charlesmn | 0:3ac96e360672 | 3234 | |
charlesmn | 0:3ac96e360672 | 3235 | inloopcount = 0; |
charlesmn | 0:3ac96e360672 | 3236 | offset_meas = 0; |
charlesmn | 0:3ac96e360672 | 3237 | while ((Status == VL53L1_ERROR_NONE) && (inloopcount < Max) && |
charlesmn | 0:3ac96e360672 | 3238 | (offset_meas < OverMax)) { |
charlesmn | 0:3ac96e360672 | 3239 | Status = VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 3240 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3241 | Status = VL53L1_GetRangingMeasurementData(Dev, |
charlesmn | 0:3ac96e360672 | 3242 | &RangingMeasurementData); |
charlesmn | 0:3ac96e360672 | 3243 | goodmeas = (RangingMeasurementData.RangeStatus == |
charlesmn | 0:3ac96e360672 | 3244 | VL53L1_RANGESTATUS_RANGE_VALID); |
charlesmn | 0:3ac96e360672 | 3245 | if ((Status == VL53L1_ERROR_NONE) && goodmeas) { |
charlesmn | 0:3ac96e360672 | 3246 | sum_ranging = sum_ranging + |
charlesmn | 0:3ac96e360672 | 3247 | RangingMeasurementData.RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 3248 | inloopcount++; |
charlesmn | 0:3ac96e360672 | 3249 | } |
charlesmn | 0:3ac96e360672 | 3250 | Status = VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3251 | offset_meas++; |
charlesmn | 0:3ac96e360672 | 3252 | } |
charlesmn | 0:3ac96e360672 | 3253 | total_count += inloopcount; |
charlesmn | 0:3ac96e360672 | 3254 | |
charlesmn | 0:3ac96e360672 | 3255 | |
charlesmn | 0:3ac96e360672 | 3256 | if (inloopcount < UnderMax) |
charlesmn | 0:3ac96e360672 | 3257 | Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL; |
charlesmn | 0:3ac96e360672 | 3258 | |
charlesmn | 0:3ac96e360672 | 3259 | VL53L1_StopMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3260 | |
charlesmn | 0:3ac96e360672 | 3261 | Repeat--; |
charlesmn | 0:3ac96e360672 | 3262 | |
charlesmn | 0:3ac96e360672 | 3263 | } |
charlesmn | 0:3ac96e360672 | 3264 | |
charlesmn | 0:3ac96e360672 | 3265 | if ((SmudgeStatus == VL53L1_ERROR_NONE) && (smudge_corr_en == 1)) |
charlesmn | 0:3ac96e360672 | 3266 | SmudgeStatus = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 3267 | |
charlesmn | 0:3ac96e360672 | 3268 | if ((sum_ranging < 0) || |
charlesmn | 0:3ac96e360672 | 3269 | (sum_ranging > ((int32_t) total_count * 0xffff))) |
charlesmn | 0:3ac96e360672 | 3270 | Status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 3271 | |
charlesmn | 0:3ac96e360672 | 3272 | if ((Status == VL53L1_ERROR_NONE) && (total_count > 0)) { |
charlesmn | 0:3ac96e360672 | 3273 | IncRounding = total_count / 2; |
charlesmn | 0:3ac96e360672 | 3274 | meanDistance_mm = (int16_t)((sum_ranging + IncRounding) |
charlesmn | 0:3ac96e360672 | 3275 | / total_count); |
charlesmn | 0:3ac96e360672 | 3276 | offset = (int16_t)CalDistanceMilliMeter - meanDistance_mm; |
charlesmn | 0:3ac96e360672 | 3277 | pdev->customer.algo__part_to_part_range_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3278 | pdev->customer.mm_config__inner_offset_mm = offset; |
charlesmn | 0:3ac96e360672 | 3279 | pdev->customer.mm_config__outer_offset_mm = offset; |
charlesmn | 0:3ac96e360672 | 3280 | |
charlesmn | 0:3ac96e360672 | 3281 | Status = VL53L1_set_customer_nvm_managed(Dev, |
charlesmn | 0:3ac96e360672 | 3282 | &(pdev->customer)); |
charlesmn | 0:3ac96e360672 | 3283 | } |
charlesmn | 0:3ac96e360672 | 3284 | |
charlesmn | 0:3ac96e360672 | 3285 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3286 | return Status; |
charlesmn | 0:3ac96e360672 | 3287 | } |
charlesmn | 0:3ac96e360672 | 3288 | |
charlesmn | 0:3ac96e360672 | 3289 | VL53L1_Error VL53L1_PerformOffsetZeroDistanceCalibration(VL53L1_DEV Dev) |
charlesmn | 0:3ac96e360672 | 3290 | { |
charlesmn | 0:3ac96e360672 | 3291 | #define START_OFFSET 50 |
charlesmn | 0:3ac96e360672 | 3292 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3293 | int32_t sum_ranging; |
charlesmn | 0:3ac96e360672 | 3294 | uint8_t offset_meas; |
charlesmn | 0:3ac96e360672 | 3295 | int16_t Max, UnderMax, OverMax, Repeat; |
charlesmn | 0:3ac96e360672 | 3296 | int32_t total_count, inloopcount; |
charlesmn | 0:3ac96e360672 | 3297 | int32_t IncRounding; |
charlesmn | 0:3ac96e360672 | 3298 | int16_t meanDistance_mm; |
charlesmn | 0:3ac96e360672 | 3299 | int16_t offset, ZeroDistanceOffset; |
charlesmn | 0:3ac96e360672 | 3300 | VL53L1_RangingMeasurementData_t RangingMeasurementData; |
charlesmn | 0:3ac96e360672 | 3301 | VL53L1_LLDriverData_t *pdev; |
charlesmn | 0:3ac96e360672 | 3302 | uint8_t goodmeas; |
charlesmn | 0:3ac96e360672 | 3303 | VL53L1_Error SmudgeStatus = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3304 | uint8_t smudge_corr_en; |
charlesmn | 0:3ac96e360672 | 3305 | |
charlesmn | 0:3ac96e360672 | 3306 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3307 | |
charlesmn | 0:3ac96e360672 | 3308 | pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 3309 | smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled; |
charlesmn | 0:3ac96e360672 | 3310 | SmudgeStatus = VL53L1_dynamic_xtalk_correction_disable(Dev); |
charlesmn | 0:3ac96e360672 | 3311 | pdev->customer.algo__part_to_part_range_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3312 | pdev->customer.mm_config__inner_offset_mm = START_OFFSET; |
charlesmn | 0:3ac96e360672 | 3313 | pdev->customer.mm_config__outer_offset_mm = START_OFFSET; |
charlesmn | 0:3ac96e360672 | 3314 | memset(&pdev->per_vcsel_cal_data, 0, sizeof(pdev->per_vcsel_cal_data)); |
charlesmn | 0:3ac96e360672 | 3315 | ZeroDistanceOffset = BDTable[ |
charlesmn | 0:3ac96e360672 | 3316 | VL53L1_TUNING_ZERO_DISTANCE_OFFSET_NON_LINEAR_FACTOR]; |
charlesmn | 0:3ac96e360672 | 3317 | Repeat = BDTable[VL53L1_TUNING_SIMPLE_OFFSET_CALIBRATION_REPEAT]; |
charlesmn | 0:3ac96e360672 | 3318 | Max = BDTable[ |
charlesmn | 0:3ac96e360672 | 3319 | VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER]; |
charlesmn | 0:3ac96e360672 | 3320 | UnderMax = 1 + (Max / 2); |
charlesmn | 0:3ac96e360672 | 3321 | OverMax = Max + (Max / 2); |
charlesmn | 0:3ac96e360672 | 3322 | sum_ranging = 0; |
charlesmn | 0:3ac96e360672 | 3323 | total_count = 0; |
charlesmn | 0:3ac96e360672 | 3324 | |
charlesmn | 0:3ac96e360672 | 3325 | while ((Repeat > 0) && (Status == VL53L1_ERROR_NONE)) { |
charlesmn | 0:3ac96e360672 | 3326 | Status = VL53L1_StartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3327 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3328 | VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 3329 | VL53L1_GetRangingMeasurementData(Dev, |
charlesmn | 0:3ac96e360672 | 3330 | &RangingMeasurementData); |
charlesmn | 0:3ac96e360672 | 3331 | VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3332 | } |
charlesmn | 0:3ac96e360672 | 3333 | inloopcount = 0; |
charlesmn | 0:3ac96e360672 | 3334 | offset_meas = 0; |
charlesmn | 0:3ac96e360672 | 3335 | while ((Status == VL53L1_ERROR_NONE) && (inloopcount < Max) && |
charlesmn | 0:3ac96e360672 | 3336 | (offset_meas < OverMax)) { |
charlesmn | 0:3ac96e360672 | 3337 | Status = VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 3338 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3339 | Status = VL53L1_GetRangingMeasurementData(Dev, |
charlesmn | 0:3ac96e360672 | 3340 | &RangingMeasurementData); |
charlesmn | 0:3ac96e360672 | 3341 | goodmeas = (RangingMeasurementData.RangeStatus == |
charlesmn | 0:3ac96e360672 | 3342 | VL53L1_RANGESTATUS_RANGE_VALID); |
charlesmn | 0:3ac96e360672 | 3343 | if ((Status == VL53L1_ERROR_NONE) && goodmeas) { |
charlesmn | 0:3ac96e360672 | 3344 | sum_ranging = sum_ranging + |
charlesmn | 0:3ac96e360672 | 3345 | RangingMeasurementData.RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 3346 | inloopcount++; |
charlesmn | 0:3ac96e360672 | 3347 | } |
charlesmn | 0:3ac96e360672 | 3348 | Status = VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3349 | offset_meas++; |
charlesmn | 0:3ac96e360672 | 3350 | } |
charlesmn | 0:3ac96e360672 | 3351 | total_count += inloopcount; |
charlesmn | 0:3ac96e360672 | 3352 | if (inloopcount < UnderMax) |
charlesmn | 0:3ac96e360672 | 3353 | Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL; |
charlesmn | 0:3ac96e360672 | 3354 | VL53L1_StopMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3355 | Repeat--; |
charlesmn | 0:3ac96e360672 | 3356 | } |
charlesmn | 0:3ac96e360672 | 3357 | if ((SmudgeStatus == VL53L1_ERROR_NONE) && (smudge_corr_en == 1)) |
charlesmn | 0:3ac96e360672 | 3358 | SmudgeStatus = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 3359 | if ((sum_ranging < 0) || |
charlesmn | 0:3ac96e360672 | 3360 | (sum_ranging > ((int32_t) total_count * 0xffff))) |
charlesmn | 0:3ac96e360672 | 3361 | Status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 3362 | |
charlesmn | 0:3ac96e360672 | 3363 | if ((Status == VL53L1_ERROR_NONE) && (total_count > 0)) { |
charlesmn | 0:3ac96e360672 | 3364 | IncRounding = total_count / 2; |
charlesmn | 0:3ac96e360672 | 3365 | meanDistance_mm = (int16_t) |
charlesmn | 0:3ac96e360672 | 3366 | ((sum_ranging + IncRounding) / total_count); |
charlesmn | 0:3ac96e360672 | 3367 | offset = START_OFFSET - meanDistance_mm + ZeroDistanceOffset; |
charlesmn | 0:3ac96e360672 | 3368 | pdev->customer.algo__part_to_part_range_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3369 | pdev->customer.mm_config__inner_offset_mm = offset; |
charlesmn | 0:3ac96e360672 | 3370 | pdev->customer.mm_config__outer_offset_mm = offset; |
charlesmn | 0:3ac96e360672 | 3371 | Status = VL53L1_set_customer_nvm_managed(Dev, |
charlesmn | 0:3ac96e360672 | 3372 | &(pdev->customer)); |
charlesmn | 0:3ac96e360672 | 3373 | } |
charlesmn | 0:3ac96e360672 | 3374 | |
charlesmn | 0:3ac96e360672 | 3375 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3376 | return Status; |
charlesmn | 0:3ac96e360672 | 3377 | } |
charlesmn | 0:3ac96e360672 | 3378 | |
charlesmn | 0:3ac96e360672 | 3379 | VL53L1_Error VL53L1_SetCalibrationData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3380 | VL53L1_CalibrationData_t *pCalibrationData) |
charlesmn | 0:3ac96e360672 | 3381 | { |
charlesmn | 0:3ac96e360672 | 3382 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3383 | VL53L1_CustomerNvmManaged_t *pC; |
charlesmn | 0:3ac96e360672 | 3384 | VL53L1_calibration_data_t cal_data; |
charlesmn | 0:3ac96e360672 | 3385 | uint32_t x, IncomeVersion, CurrentVersion; |
charlesmn | 0:3ac96e360672 | 3386 | uint8_t CalStopsOn_cal_peak_rate_map = 0; |
charlesmn | 0:3ac96e360672 | 3387 | VL53L1_xtalk_calibration_results_t xtalk; |
charlesmn | 0:3ac96e360672 | 3388 | VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 3389 | |
charlesmn | 0:3ac96e360672 | 3390 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3391 | |
charlesmn | 0:3ac96e360672 | 3392 | cal_data.struct_version = pCalibrationData->struct_version - |
charlesmn | 0:3ac96e360672 | 3393 | VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION; |
charlesmn | 0:3ac96e360672 | 3394 | |
charlesmn | 0:3ac96e360672 | 3395 | IncomeVersion = pCalibrationData->struct_version; |
charlesmn | 0:3ac96e360672 | 3396 | CurrentVersion = VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION + |
charlesmn | 0:3ac96e360672 | 3397 | VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION; |
charlesmn | 0:3ac96e360672 | 3398 | |
charlesmn | 0:3ac96e360672 | 3399 | if ((IncomeVersion < CurrentVersion) && |
charlesmn | 0:3ac96e360672 | 3400 | ((IncomeVersion & 0xFFFFFF0F) == |
charlesmn | 0:3ac96e360672 | 3401 | (CurrentVersion & 0xFFFFFF0F))) { |
charlesmn | 0:3ac96e360672 | 3402 | cal_data.struct_version = |
charlesmn | 0:3ac96e360672 | 3403 | VL53L1_LL_CALIBRATION_DATA_STRUCT_VERSION; |
charlesmn | 0:3ac96e360672 | 3404 | CalStopsOn_cal_peak_rate_map = 1; |
charlesmn | 0:3ac96e360672 | 3405 | |
charlesmn | 0:3ac96e360672 | 3406 | pdev->tuning_parms.tp_hist_merge = 0; |
charlesmn | 0:3ac96e360672 | 3407 | } |
charlesmn | 0:3ac96e360672 | 3408 | |
charlesmn | 0:3ac96e360672 | 3409 | |
charlesmn | 0:3ac96e360672 | 3410 | |
charlesmn | 0:3ac96e360672 | 3411 | memcpy( |
charlesmn | 0:3ac96e360672 | 3412 | &(cal_data.fmt_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3413 | &(pCalibrationData->fmt_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3414 | sizeof(VL53L1_dmax_calibration_data_t)); |
charlesmn | 0:3ac96e360672 | 3415 | |
charlesmn | 0:3ac96e360672 | 3416 | |
charlesmn | 0:3ac96e360672 | 3417 | memcpy( |
charlesmn | 0:3ac96e360672 | 3418 | &(cal_data.cust_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3419 | &(pCalibrationData->cust_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3420 | sizeof(VL53L1_dmax_calibration_data_t)); |
charlesmn | 0:3ac96e360672 | 3421 | |
charlesmn | 0:3ac96e360672 | 3422 | |
charlesmn | 0:3ac96e360672 | 3423 | memcpy( |
charlesmn | 0:3ac96e360672 | 3424 | &(cal_data.add_off_cal_data), |
charlesmn | 0:3ac96e360672 | 3425 | &(pCalibrationData->add_off_cal_data), |
charlesmn | 0:3ac96e360672 | 3426 | sizeof(VL53L1_additional_offset_cal_data_t)); |
charlesmn | 0:3ac96e360672 | 3427 | |
charlesmn | 0:3ac96e360672 | 3428 | |
charlesmn | 0:3ac96e360672 | 3429 | memcpy( |
charlesmn | 0:3ac96e360672 | 3430 | &(cal_data.optical_centre), |
charlesmn | 0:3ac96e360672 | 3431 | &(pCalibrationData->optical_centre), |
charlesmn | 0:3ac96e360672 | 3432 | sizeof(VL53L1_optical_centre_t)); |
charlesmn | 0:3ac96e360672 | 3433 | |
charlesmn | 0:3ac96e360672 | 3434 | |
charlesmn | 0:3ac96e360672 | 3435 | memcpy( |
charlesmn | 0:3ac96e360672 | 3436 | &(cal_data.xtalkhisto), |
charlesmn | 0:3ac96e360672 | 3437 | &(pCalibrationData->xtalkhisto), |
charlesmn | 0:3ac96e360672 | 3438 | sizeof(VL53L1_xtalk_histogram_data_t)); |
charlesmn | 0:3ac96e360672 | 3439 | |
charlesmn | 0:3ac96e360672 | 3440 | |
charlesmn | 0:3ac96e360672 | 3441 | memcpy( |
charlesmn | 0:3ac96e360672 | 3442 | &(cal_data.gain_cal), |
charlesmn | 0:3ac96e360672 | 3443 | &(pCalibrationData->gain_cal), |
charlesmn | 0:3ac96e360672 | 3444 | sizeof(VL53L1_gain_calibration_data_t)); |
charlesmn | 0:3ac96e360672 | 3445 | |
charlesmn | 0:3ac96e360672 | 3446 | |
charlesmn | 0:3ac96e360672 | 3447 | memcpy( |
charlesmn | 0:3ac96e360672 | 3448 | &(cal_data.cal_peak_rate_map), |
charlesmn | 0:3ac96e360672 | 3449 | &(pCalibrationData->cal_peak_rate_map), |
charlesmn | 0:3ac96e360672 | 3450 | sizeof(VL53L1_cal_peak_rate_map_t)); |
charlesmn | 0:3ac96e360672 | 3451 | |
charlesmn | 0:3ac96e360672 | 3452 | |
charlesmn | 0:3ac96e360672 | 3453 | if (!CalStopsOn_cal_peak_rate_map) |
charlesmn | 0:3ac96e360672 | 3454 | memcpy( |
charlesmn | 0:3ac96e360672 | 3455 | &(cal_data.per_vcsel_cal_data), |
charlesmn | 0:3ac96e360672 | 3456 | &(pCalibrationData->per_vcsel_cal_data), |
charlesmn | 0:3ac96e360672 | 3457 | sizeof(VL53L1_per_vcsel_period_offset_cal_data_t)); |
charlesmn | 0:3ac96e360672 | 3458 | else { |
charlesmn | 0:3ac96e360672 | 3459 | cal_data.per_vcsel_cal_data.short_a_offset_mm = |
charlesmn | 0:3ac96e360672 | 3460 | cal_data.per_vcsel_cal_data.short_b_offset_mm = |
charlesmn | 0:3ac96e360672 | 3461 | cal_data.per_vcsel_cal_data.medium_a_offset_mm = |
charlesmn | 0:3ac96e360672 | 3462 | cal_data.per_vcsel_cal_data.medium_b_offset_mm = |
charlesmn | 0:3ac96e360672 | 3463 | cal_data.per_vcsel_cal_data.long_a_offset_mm = |
charlesmn | 0:3ac96e360672 | 3464 | cal_data.per_vcsel_cal_data.long_b_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3465 | } |
charlesmn | 0:3ac96e360672 | 3466 | |
charlesmn | 0:3ac96e360672 | 3467 | pC = &pCalibrationData->customer; |
charlesmn | 0:3ac96e360672 | 3468 | x = pC->algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 3469 | cal_data.customer.algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 3470 | (uint16_t)(x&0x0000FFFF); |
charlesmn | 0:3ac96e360672 | 3471 | |
charlesmn | 0:3ac96e360672 | 3472 | cal_data.customer.global_config__spad_enables_ref_0 = |
charlesmn | 0:3ac96e360672 | 3473 | pC->global_config__spad_enables_ref_0; |
charlesmn | 0:3ac96e360672 | 3474 | cal_data.customer.global_config__spad_enables_ref_1 = |
charlesmn | 0:3ac96e360672 | 3475 | pC->global_config__spad_enables_ref_1; |
charlesmn | 0:3ac96e360672 | 3476 | cal_data.customer.global_config__spad_enables_ref_2 = |
charlesmn | 0:3ac96e360672 | 3477 | pC->global_config__spad_enables_ref_2; |
charlesmn | 0:3ac96e360672 | 3478 | cal_data.customer.global_config__spad_enables_ref_3 = |
charlesmn | 0:3ac96e360672 | 3479 | pC->global_config__spad_enables_ref_3; |
charlesmn | 0:3ac96e360672 | 3480 | cal_data.customer.global_config__spad_enables_ref_4 = |
charlesmn | 0:3ac96e360672 | 3481 | pC->global_config__spad_enables_ref_4; |
charlesmn | 0:3ac96e360672 | 3482 | cal_data.customer.global_config__spad_enables_ref_5 = |
charlesmn | 0:3ac96e360672 | 3483 | pC->global_config__spad_enables_ref_5; |
charlesmn | 0:3ac96e360672 | 3484 | cal_data.customer.global_config__ref_en_start_select = |
charlesmn | 0:3ac96e360672 | 3485 | pC->global_config__ref_en_start_select; |
charlesmn | 0:3ac96e360672 | 3486 | cal_data.customer.ref_spad_man__num_requested_ref_spads = |
charlesmn | 0:3ac96e360672 | 3487 | pC->ref_spad_man__num_requested_ref_spads; |
charlesmn | 0:3ac96e360672 | 3488 | cal_data.customer.ref_spad_man__ref_location = |
charlesmn | 0:3ac96e360672 | 3489 | pC->ref_spad_man__ref_location; |
charlesmn | 0:3ac96e360672 | 3490 | cal_data.customer.algo__crosstalk_compensation_x_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 3491 | pC->algo__crosstalk_compensation_x_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 3492 | cal_data.customer.algo__crosstalk_compensation_y_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 3493 | pC->algo__crosstalk_compensation_y_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 3494 | cal_data.customer.ref_spad_char__total_rate_target_mcps = |
charlesmn | 0:3ac96e360672 | 3495 | pC->ref_spad_char__total_rate_target_mcps; |
charlesmn | 0:3ac96e360672 | 3496 | cal_data.customer.algo__part_to_part_range_offset_mm = |
charlesmn | 0:3ac96e360672 | 3497 | pC->algo__part_to_part_range_offset_mm; |
charlesmn | 0:3ac96e360672 | 3498 | cal_data.customer.mm_config__inner_offset_mm = |
charlesmn | 0:3ac96e360672 | 3499 | pC->mm_config__inner_offset_mm; |
charlesmn | 0:3ac96e360672 | 3500 | cal_data.customer.mm_config__outer_offset_mm = |
charlesmn | 0:3ac96e360672 | 3501 | pC->mm_config__outer_offset_mm; |
charlesmn | 0:3ac96e360672 | 3502 | |
charlesmn | 0:3ac96e360672 | 3503 | Status = VL53L1_set_part_to_part_data(Dev, &cal_data); |
charlesmn | 0:3ac96e360672 | 3504 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3505 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 3506 | |
charlesmn | 0:3ac96e360672 | 3507 | Status = VL53L1_get_current_xtalk_settings(Dev, &xtalk); |
charlesmn | 0:3ac96e360672 | 3508 | |
charlesmn | 0:3ac96e360672 | 3509 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3510 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 3511 | |
charlesmn | 0:3ac96e360672 | 3512 | xtalk.algo__crosstalk_compensation_plane_offset_kcps = x; |
charlesmn | 0:3ac96e360672 | 3513 | |
charlesmn | 0:3ac96e360672 | 3514 | Status = VL53L1_set_tuning_parm(Dev, |
charlesmn | 0:3ac96e360672 | 3515 | VL53L1_TUNINGPARM_DYNXTALK_NODETECT_XTALK_OFFSET_KCPS, |
charlesmn | 0:3ac96e360672 | 3516 | x); |
charlesmn | 0:3ac96e360672 | 3517 | |
charlesmn | 0:3ac96e360672 | 3518 | |
charlesmn | 0:3ac96e360672 | 3519 | if (!CalStopsOn_cal_peak_rate_map) |
charlesmn | 0:3ac96e360672 | 3520 | memcpy( |
charlesmn | 0:3ac96e360672 | 3521 | &(xtalk.algo__xtalk_cpo_HistoMerge_kcps[0]), |
charlesmn | 0:3ac96e360672 | 3522 | &(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps[0]), |
charlesmn | 0:3ac96e360672 | 3523 | sizeof(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps)); |
charlesmn | 0:3ac96e360672 | 3524 | else |
charlesmn | 0:3ac96e360672 | 3525 | memset( |
charlesmn | 0:3ac96e360672 | 3526 | &(xtalk.algo__xtalk_cpo_HistoMerge_kcps[0]), 0, |
charlesmn | 0:3ac96e360672 | 3527 | sizeof(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps)); |
charlesmn | 0:3ac96e360672 | 3528 | |
charlesmn | 0:3ac96e360672 | 3529 | Status = VL53L1_set_current_xtalk_settings(Dev, &xtalk); |
charlesmn | 0:3ac96e360672 | 3530 | |
charlesmn | 0:3ac96e360672 | 3531 | ENDFUNC: |
charlesmn | 0:3ac96e360672 | 3532 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3533 | return Status; |
charlesmn | 0:3ac96e360672 | 3534 | |
charlesmn | 0:3ac96e360672 | 3535 | } |
charlesmn | 0:3ac96e360672 | 3536 | |
charlesmn | 0:3ac96e360672 | 3537 | VL53L1_Error VL53L1_GetCalibrationData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3538 | VL53L1_CalibrationData_t *pCalibrationData) |
charlesmn | 0:3ac96e360672 | 3539 | { |
charlesmn | 0:3ac96e360672 | 3540 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3541 | VL53L1_calibration_data_t cal_data; |
charlesmn | 0:3ac96e360672 | 3542 | VL53L1_CustomerNvmManaged_t *pC; |
charlesmn | 0:3ac96e360672 | 3543 | VL53L1_customer_nvm_managed_t *pC2; |
charlesmn | 0:3ac96e360672 | 3544 | VL53L1_xtalk_calibration_results_t xtalk; |
charlesmn | 0:3ac96e360672 | 3545 | uint32_t tmp; |
charlesmn | 0:3ac96e360672 | 3546 | VL53L1_PresetModes PresetMode; |
charlesmn | 0:3ac96e360672 | 3547 | |
charlesmn | 0:3ac96e360672 | 3548 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3549 | |
charlesmn | 0:3ac96e360672 | 3550 | |
charlesmn | 0:3ac96e360672 | 3551 | Status = VL53L1_get_part_to_part_data(Dev, &cal_data); |
charlesmn | 0:3ac96e360672 | 3552 | |
charlesmn | 0:3ac96e360672 | 3553 | pCalibrationData->struct_version = cal_data.struct_version + |
charlesmn | 0:3ac96e360672 | 3554 | VL53L1_ADDITIONAL_CALIBRATION_DATA_STRUCT_VERSION; |
charlesmn | 0:3ac96e360672 | 3555 | |
charlesmn | 0:3ac96e360672 | 3556 | |
charlesmn | 0:3ac96e360672 | 3557 | memcpy( |
charlesmn | 0:3ac96e360672 | 3558 | &(pCalibrationData->fmt_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3559 | &(cal_data.fmt_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3560 | sizeof(VL53L1_dmax_calibration_data_t)); |
charlesmn | 0:3ac96e360672 | 3561 | |
charlesmn | 0:3ac96e360672 | 3562 | |
charlesmn | 0:3ac96e360672 | 3563 | memcpy( |
charlesmn | 0:3ac96e360672 | 3564 | &(pCalibrationData->cust_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3565 | &(cal_data.cust_dmax_cal), |
charlesmn | 0:3ac96e360672 | 3566 | sizeof(VL53L1_dmax_calibration_data_t)); |
charlesmn | 0:3ac96e360672 | 3567 | |
charlesmn | 0:3ac96e360672 | 3568 | |
charlesmn | 0:3ac96e360672 | 3569 | memcpy( |
charlesmn | 0:3ac96e360672 | 3570 | &(pCalibrationData->add_off_cal_data), |
charlesmn | 0:3ac96e360672 | 3571 | &(cal_data.add_off_cal_data), |
charlesmn | 0:3ac96e360672 | 3572 | sizeof(VL53L1_additional_offset_cal_data_t)); |
charlesmn | 0:3ac96e360672 | 3573 | |
charlesmn | 0:3ac96e360672 | 3574 | |
charlesmn | 0:3ac96e360672 | 3575 | memcpy( |
charlesmn | 0:3ac96e360672 | 3576 | &(pCalibrationData->optical_centre), |
charlesmn | 0:3ac96e360672 | 3577 | &(cal_data.optical_centre), |
charlesmn | 0:3ac96e360672 | 3578 | sizeof(VL53L1_optical_centre_t)); |
charlesmn | 0:3ac96e360672 | 3579 | |
charlesmn | 0:3ac96e360672 | 3580 | |
charlesmn | 0:3ac96e360672 | 3581 | memcpy( |
charlesmn | 0:3ac96e360672 | 3582 | &(pCalibrationData->xtalkhisto), |
charlesmn | 0:3ac96e360672 | 3583 | &(cal_data.xtalkhisto), |
charlesmn | 0:3ac96e360672 | 3584 | sizeof(VL53L1_xtalk_histogram_data_t)); |
charlesmn | 0:3ac96e360672 | 3585 | |
charlesmn | 0:3ac96e360672 | 3586 | memcpy( |
charlesmn | 0:3ac96e360672 | 3587 | &(pCalibrationData->gain_cal), |
charlesmn | 0:3ac96e360672 | 3588 | &(cal_data.gain_cal), |
charlesmn | 0:3ac96e360672 | 3589 | sizeof(VL53L1_gain_calibration_data_t)); |
charlesmn | 0:3ac96e360672 | 3590 | |
charlesmn | 0:3ac96e360672 | 3591 | |
charlesmn | 0:3ac96e360672 | 3592 | memcpy( |
charlesmn | 0:3ac96e360672 | 3593 | &(pCalibrationData->cal_peak_rate_map), |
charlesmn | 0:3ac96e360672 | 3594 | &(cal_data.cal_peak_rate_map), |
charlesmn | 0:3ac96e360672 | 3595 | sizeof(VL53L1_cal_peak_rate_map_t)); |
charlesmn | 0:3ac96e360672 | 3596 | |
charlesmn | 0:3ac96e360672 | 3597 | |
charlesmn | 0:3ac96e360672 | 3598 | memcpy( |
charlesmn | 0:3ac96e360672 | 3599 | &(pCalibrationData->per_vcsel_cal_data), |
charlesmn | 0:3ac96e360672 | 3600 | &(cal_data.per_vcsel_cal_data), |
charlesmn | 0:3ac96e360672 | 3601 | sizeof(VL53L1_per_vcsel_period_offset_cal_data_t)); |
charlesmn | 0:3ac96e360672 | 3602 | |
charlesmn | 0:3ac96e360672 | 3603 | pC = &pCalibrationData->customer; |
charlesmn | 0:3ac96e360672 | 3604 | pC2 = &cal_data.customer; |
charlesmn | 0:3ac96e360672 | 3605 | pC->global_config__spad_enables_ref_0 = |
charlesmn | 0:3ac96e360672 | 3606 | pC2->global_config__spad_enables_ref_0; |
charlesmn | 0:3ac96e360672 | 3607 | pC->global_config__spad_enables_ref_1 = |
charlesmn | 0:3ac96e360672 | 3608 | pC2->global_config__spad_enables_ref_1; |
charlesmn | 0:3ac96e360672 | 3609 | pC->global_config__spad_enables_ref_2 = |
charlesmn | 0:3ac96e360672 | 3610 | pC2->global_config__spad_enables_ref_2; |
charlesmn | 0:3ac96e360672 | 3611 | pC->global_config__spad_enables_ref_3 = |
charlesmn | 0:3ac96e360672 | 3612 | pC2->global_config__spad_enables_ref_3; |
charlesmn | 0:3ac96e360672 | 3613 | pC->global_config__spad_enables_ref_4 = |
charlesmn | 0:3ac96e360672 | 3614 | pC2->global_config__spad_enables_ref_4; |
charlesmn | 0:3ac96e360672 | 3615 | pC->global_config__spad_enables_ref_5 = |
charlesmn | 0:3ac96e360672 | 3616 | pC2->global_config__spad_enables_ref_5; |
charlesmn | 0:3ac96e360672 | 3617 | pC->global_config__ref_en_start_select = |
charlesmn | 0:3ac96e360672 | 3618 | pC2->global_config__ref_en_start_select; |
charlesmn | 0:3ac96e360672 | 3619 | pC->ref_spad_man__num_requested_ref_spads = |
charlesmn | 0:3ac96e360672 | 3620 | pC2->ref_spad_man__num_requested_ref_spads; |
charlesmn | 0:3ac96e360672 | 3621 | pC->ref_spad_man__ref_location = |
charlesmn | 0:3ac96e360672 | 3622 | pC2->ref_spad_man__ref_location; |
charlesmn | 0:3ac96e360672 | 3623 | pC->algo__crosstalk_compensation_x_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 3624 | pC2->algo__crosstalk_compensation_x_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 3625 | pC->algo__crosstalk_compensation_y_plane_gradient_kcps = |
charlesmn | 0:3ac96e360672 | 3626 | pC2->algo__crosstalk_compensation_y_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 3627 | pC->ref_spad_char__total_rate_target_mcps = |
charlesmn | 0:3ac96e360672 | 3628 | pC2->ref_spad_char__total_rate_target_mcps; |
charlesmn | 0:3ac96e360672 | 3629 | pC->algo__part_to_part_range_offset_mm = |
charlesmn | 0:3ac96e360672 | 3630 | pC2->algo__part_to_part_range_offset_mm; |
charlesmn | 0:3ac96e360672 | 3631 | pC->mm_config__inner_offset_mm = |
charlesmn | 0:3ac96e360672 | 3632 | pC2->mm_config__inner_offset_mm; |
charlesmn | 0:3ac96e360672 | 3633 | pC->mm_config__outer_offset_mm = |
charlesmn | 0:3ac96e360672 | 3634 | pC2->mm_config__outer_offset_mm; |
charlesmn | 0:3ac96e360672 | 3635 | |
charlesmn | 0:3ac96e360672 | 3636 | pC->algo__crosstalk_compensation_plane_offset_kcps = |
charlesmn | 0:3ac96e360672 | 3637 | (uint32_t)( |
charlesmn | 0:3ac96e360672 | 3638 | pC2->algo__crosstalk_compensation_plane_offset_kcps); |
charlesmn | 0:3ac96e360672 | 3639 | |
charlesmn | 0:3ac96e360672 | 3640 | PresetMode = VL53L1DevDataGet(Dev, CurrentParameters.PresetMode); |
charlesmn | 0:3ac96e360672 | 3641 | |
charlesmn | 0:3ac96e360672 | 3642 | if ((PresetMode == VL53L1_PRESETMODE_RANGING) || |
charlesmn | 0:3ac96e360672 | 3643 | (PresetMode == VL53L1_PRESETMODE_MULTIZONES_SCANNING) || |
charlesmn | 0:3ac96e360672 | 3644 | (PresetMode == VL53L1_PRESETMODE_PROXY_RANGING_MODE) |
charlesmn | 0:3ac96e360672 | 3645 | ) { |
charlesmn | 0:3ac96e360672 | 3646 | |
charlesmn | 0:3ac96e360672 | 3647 | Status = VL53L1_get_current_xtalk_settings(Dev, &xtalk); |
charlesmn | 0:3ac96e360672 | 3648 | |
charlesmn | 0:3ac96e360672 | 3649 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3650 | goto ENDFUNC; |
charlesmn | 0:3ac96e360672 | 3651 | |
charlesmn | 0:3ac96e360672 | 3652 | tmp = xtalk.algo__crosstalk_compensation_plane_offset_kcps; |
charlesmn | 0:3ac96e360672 | 3653 | pC->algo__crosstalk_compensation_plane_offset_kcps = tmp; |
charlesmn | 0:3ac96e360672 | 3654 | tmp = xtalk.algo__crosstalk_compensation_x_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 3655 | pC->algo__crosstalk_compensation_x_plane_gradient_kcps = tmp; |
charlesmn | 0:3ac96e360672 | 3656 | tmp = xtalk.algo__crosstalk_compensation_y_plane_gradient_kcps; |
charlesmn | 0:3ac96e360672 | 3657 | pC->algo__crosstalk_compensation_y_plane_gradient_kcps = tmp; |
charlesmn | 0:3ac96e360672 | 3658 | |
charlesmn | 0:3ac96e360672 | 3659 | memcpy(&(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps[0]), |
charlesmn | 0:3ac96e360672 | 3660 | &(xtalk.algo__xtalk_cpo_HistoMerge_kcps[0]), |
charlesmn | 0:3ac96e360672 | 3661 | sizeof(pCalibrationData->algo__xtalk_cpo_HistoMerge_kcps)); |
charlesmn | 0:3ac96e360672 | 3662 | } |
charlesmn | 0:3ac96e360672 | 3663 | ENDFUNC: |
charlesmn | 0:3ac96e360672 | 3664 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3665 | return Status; |
charlesmn | 0:3ac96e360672 | 3666 | } |
charlesmn | 0:3ac96e360672 | 3667 | |
charlesmn | 0:3ac96e360672 | 3668 | |
charlesmn | 0:3ac96e360672 | 3669 | VL53L1_Error VL53L1_SetZoneCalibrationData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3670 | VL53L1_ZoneCalibrationData_t *pZoneCalibrationData) |
charlesmn | 0:3ac96e360672 | 3671 | { |
charlesmn | 0:3ac96e360672 | 3672 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3673 | |
charlesmn | 0:3ac96e360672 | 3674 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3675 | |
charlesmn | 0:3ac96e360672 | 3676 | Status = VL53L1_set_zone_calibration_data(Dev, pZoneCalibrationData); |
charlesmn | 0:3ac96e360672 | 3677 | |
charlesmn | 0:3ac96e360672 | 3678 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3679 | return Status; |
charlesmn | 0:3ac96e360672 | 3680 | |
charlesmn | 0:3ac96e360672 | 3681 | } |
charlesmn | 0:3ac96e360672 | 3682 | |
charlesmn | 0:3ac96e360672 | 3683 | VL53L1_Error VL53L1_GetZoneCalibrationData(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3684 | VL53L1_ZoneCalibrationData_t *pZoneCalibrationData) |
charlesmn | 0:3ac96e360672 | 3685 | { |
charlesmn | 0:3ac96e360672 | 3686 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3687 | |
charlesmn | 0:3ac96e360672 | 3688 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3689 | |
charlesmn | 0:3ac96e360672 | 3690 | Status = VL53L1_get_zone_calibration_data(Dev, pZoneCalibrationData); |
charlesmn | 0:3ac96e360672 | 3691 | |
charlesmn | 0:3ac96e360672 | 3692 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3693 | return Status; |
charlesmn | 0:3ac96e360672 | 3694 | } |
charlesmn | 0:3ac96e360672 | 3695 | |
charlesmn | 0:3ac96e360672 | 3696 | VL53L1_Error VL53L1_GetOpticalCenter(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3697 | FixPoint1616_t *pOpticalCenterX, |
charlesmn | 0:3ac96e360672 | 3698 | FixPoint1616_t *pOpticalCenterY) |
charlesmn | 0:3ac96e360672 | 3699 | { |
charlesmn | 0:3ac96e360672 | 3700 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3701 | VL53L1_calibration_data_t CalibrationData; |
charlesmn | 0:3ac96e360672 | 3702 | |
charlesmn | 0:3ac96e360672 | 3703 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3704 | |
charlesmn | 0:3ac96e360672 | 3705 | *pOpticalCenterX = 0; |
charlesmn | 0:3ac96e360672 | 3706 | *pOpticalCenterY = 0; |
charlesmn | 0:3ac96e360672 | 3707 | Status = VL53L1_get_part_to_part_data(Dev, &CalibrationData); |
charlesmn | 0:3ac96e360672 | 3708 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3709 | *pOpticalCenterX = VL53L1_FIXPOINT44TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 3710 | CalibrationData.optical_centre.x_centre); |
charlesmn | 0:3ac96e360672 | 3711 | *pOpticalCenterY = VL53L1_FIXPOINT44TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 3712 | CalibrationData.optical_centre.y_centre); |
charlesmn | 0:3ac96e360672 | 3713 | } |
charlesmn | 0:3ac96e360672 | 3714 | |
charlesmn | 0:3ac96e360672 | 3715 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3716 | return Status; |
charlesmn | 0:3ac96e360672 | 3717 | } |
charlesmn | 0:3ac96e360672 | 3718 | |
charlesmn | 0:3ac96e360672 | 3719 | |
charlesmn | 0:3ac96e360672 | 3720 | |
charlesmn | 0:3ac96e360672 | 3721 | |
charlesmn | 0:3ac96e360672 | 3722 | |
charlesmn | 0:3ac96e360672 | 3723 | |
charlesmn | 0:3ac96e360672 | 3724 | VL53L1_Error VL53L1_SetThresholdConfig(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3725 | VL53L1_DetectionConfig_t *pConfig) |
charlesmn | 0:3ac96e360672 | 3726 | { |
charlesmn | 0:3ac96e360672 | 3727 | #define BADTHRESBOUNDS(T) \ |
charlesmn | 0:3ac96e360672 | 3728 | (((T.CrossMode == VL53L1_THRESHOLD_OUT_OF_WINDOW) || \ |
charlesmn | 0:3ac96e360672 | 3729 | (T.CrossMode == VL53L1_THRESHOLD_IN_WINDOW)) && (T.Low > T.High)) |
charlesmn | 0:3ac96e360672 | 3730 | |
charlesmn | 0:3ac96e360672 | 3731 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3732 | VL53L1_GPIO_interrupt_config_t Cfg; |
charlesmn | 0:3ac96e360672 | 3733 | uint16_t g; |
charlesmn | 0:3ac96e360672 | 3734 | FixPoint1616_t gain, high1616, low1616; |
charlesmn | 0:3ac96e360672 | 3735 | VL53L1_LLDriverData_t *pdev; |
charlesmn | 0:3ac96e360672 | 3736 | |
charlesmn | 0:3ac96e360672 | 3737 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3738 | |
charlesmn | 0:3ac96e360672 | 3739 | pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 3740 | |
charlesmn | 0:3ac96e360672 | 3741 | Status = VL53L1_get_GPIO_interrupt_config(Dev, &Cfg); |
charlesmn | 0:3ac96e360672 | 3742 | if (Status != VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3743 | return Status; |
charlesmn | 0:3ac96e360672 | 3744 | |
charlesmn | 0:3ac96e360672 | 3745 | if (pConfig->DetectionMode == VL53L1_DETECTION_NORMAL_RUN) { |
charlesmn | 0:3ac96e360672 | 3746 | Cfg.intr_new_measure_ready = 1; |
charlesmn | 0:3ac96e360672 | 3747 | Status = VL53L1_set_GPIO_interrupt_config_struct(Dev, |
charlesmn | 0:3ac96e360672 | 3748 | Cfg); |
charlesmn | 0:3ac96e360672 | 3749 | } else { |
charlesmn | 0:3ac96e360672 | 3750 | if (BADTHRESBOUNDS(pConfig->Distance)) |
charlesmn | 0:3ac96e360672 | 3751 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 3752 | if ((Status == VL53L1_ERROR_NONE) && |
charlesmn | 0:3ac96e360672 | 3753 | (BADTHRESBOUNDS(pConfig->Rate))) |
charlesmn | 0:3ac96e360672 | 3754 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 3755 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3756 | Cfg.intr_new_measure_ready = 0; |
charlesmn | 0:3ac96e360672 | 3757 | Cfg.intr_no_target = pConfig->IntrNoTarget; |
charlesmn | 0:3ac96e360672 | 3758 | |
charlesmn | 0:3ac96e360672 | 3759 | g = pdev->gain_cal.standard_ranging_gain_factor; |
charlesmn | 0:3ac96e360672 | 3760 | if (g != 0) { |
charlesmn | 0:3ac96e360672 | 3761 | |
charlesmn | 0:3ac96e360672 | 3762 | gain = (FixPoint1616_t) ((uint32_t)g << 5); |
charlesmn | 0:3ac96e360672 | 3763 | high1616 = (FixPoint1616_t) ((uint32_t) |
charlesmn | 0:3ac96e360672 | 3764 | pConfig->Distance.High << 16); |
charlesmn | 0:3ac96e360672 | 3765 | low1616 = (FixPoint1616_t) ((uint32_t) |
charlesmn | 0:3ac96e360672 | 3766 | pConfig->Distance.Low << 16); |
charlesmn | 0:3ac96e360672 | 3767 | |
charlesmn | 0:3ac96e360672 | 3768 | high1616 = (high1616 + 32768) / gain; |
charlesmn | 0:3ac96e360672 | 3769 | low1616 = (low1616 + 32768) / gain; |
charlesmn | 0:3ac96e360672 | 3770 | Cfg.threshold_distance_high = (uint16_t) |
charlesmn | 0:3ac96e360672 | 3771 | (high1616 & 0xFFFF); |
charlesmn | 0:3ac96e360672 | 3772 | Cfg.threshold_distance_low = (uint16_t) |
charlesmn | 0:3ac96e360672 | 3773 | (low1616 & 0xFFFF); |
charlesmn | 0:3ac96e360672 | 3774 | } |
charlesmn | 0:3ac96e360672 | 3775 | Cfg.threshold_rate_high = |
charlesmn | 0:3ac96e360672 | 3776 | VL53L1_FIXPOINT1616TOFIXPOINT97( |
charlesmn | 0:3ac96e360672 | 3777 | pConfig->Rate.High); |
charlesmn | 0:3ac96e360672 | 3778 | Cfg.threshold_rate_low = |
charlesmn | 0:3ac96e360672 | 3779 | VL53L1_FIXPOINT1616TOFIXPOINT97( |
charlesmn | 0:3ac96e360672 | 3780 | pConfig->Rate.Low); |
charlesmn | 0:3ac96e360672 | 3781 | |
charlesmn | 0:3ac96e360672 | 3782 | Cfg.intr_mode_distance = ConvertModeToLLD( |
charlesmn | 0:3ac96e360672 | 3783 | &Status, |
charlesmn | 0:3ac96e360672 | 3784 | pConfig->Distance.CrossMode); |
charlesmn | 0:3ac96e360672 | 3785 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3786 | Cfg.intr_mode_rate = ConvertModeToLLD( |
charlesmn | 0:3ac96e360672 | 3787 | &Status, |
charlesmn | 0:3ac96e360672 | 3788 | pConfig->Rate.CrossMode); |
charlesmn | 0:3ac96e360672 | 3789 | } |
charlesmn | 0:3ac96e360672 | 3790 | |
charlesmn | 0:3ac96e360672 | 3791 | |
charlesmn | 0:3ac96e360672 | 3792 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3793 | Cfg.intr_combined_mode = 1; |
charlesmn | 0:3ac96e360672 | 3794 | switch (pConfig->DetectionMode) { |
charlesmn | 0:3ac96e360672 | 3795 | case VL53L1_DETECTION_DISTANCE_ONLY: |
charlesmn | 0:3ac96e360672 | 3796 | Cfg.threshold_rate_high = 0; |
charlesmn | 0:3ac96e360672 | 3797 | Cfg.threshold_rate_low = 0; |
charlesmn | 0:3ac96e360672 | 3798 | break; |
charlesmn | 0:3ac96e360672 | 3799 | case VL53L1_DETECTION_RATE_ONLY: |
charlesmn | 0:3ac96e360672 | 3800 | Cfg.threshold_distance_high = 0; |
charlesmn | 0:3ac96e360672 | 3801 | Cfg.threshold_distance_low = 0; |
charlesmn | 0:3ac96e360672 | 3802 | break; |
charlesmn | 0:3ac96e360672 | 3803 | case VL53L1_DETECTION_DISTANCE_OR_RATE: |
charlesmn | 0:3ac96e360672 | 3804 | |
charlesmn | 0:3ac96e360672 | 3805 | break; |
charlesmn | 0:3ac96e360672 | 3806 | case VL53L1_DETECTION_DISTANCE_AND_RATE: |
charlesmn | 0:3ac96e360672 | 3807 | Cfg.intr_combined_mode = 0; |
charlesmn | 0:3ac96e360672 | 3808 | break; |
charlesmn | 0:3ac96e360672 | 3809 | default: |
charlesmn | 0:3ac96e360672 | 3810 | Status = VL53L1_ERROR_INVALID_PARAMS; |
charlesmn | 0:3ac96e360672 | 3811 | } |
charlesmn | 0:3ac96e360672 | 3812 | } |
charlesmn | 0:3ac96e360672 | 3813 | |
charlesmn | 0:3ac96e360672 | 3814 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3815 | Status = |
charlesmn | 0:3ac96e360672 | 3816 | VL53L1_set_GPIO_interrupt_config_struct(Dev, Cfg); |
charlesmn | 0:3ac96e360672 | 3817 | |
charlesmn | 0:3ac96e360672 | 3818 | } |
charlesmn | 0:3ac96e360672 | 3819 | |
charlesmn | 0:3ac96e360672 | 3820 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3821 | return Status; |
charlesmn | 0:3ac96e360672 | 3822 | } |
charlesmn | 0:3ac96e360672 | 3823 | |
charlesmn | 0:3ac96e360672 | 3824 | |
charlesmn | 0:3ac96e360672 | 3825 | VL53L1_Error VL53L1_GetThresholdConfig(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3826 | VL53L1_DetectionConfig_t *pConfig) |
charlesmn | 0:3ac96e360672 | 3827 | { |
charlesmn | 0:3ac96e360672 | 3828 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3829 | VL53L1_GPIO_interrupt_config_t Cfg; |
charlesmn | 0:3ac96e360672 | 3830 | |
charlesmn | 0:3ac96e360672 | 3831 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3832 | |
charlesmn | 0:3ac96e360672 | 3833 | Status = VL53L1_get_GPIO_interrupt_config(Dev, &Cfg); |
charlesmn | 0:3ac96e360672 | 3834 | |
charlesmn | 0:3ac96e360672 | 3835 | if (Status != VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3836 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3837 | return Status; |
charlesmn | 0:3ac96e360672 | 3838 | } |
charlesmn | 0:3ac96e360672 | 3839 | |
charlesmn | 0:3ac96e360672 | 3840 | pConfig->IntrNoTarget = Cfg.intr_no_target; |
charlesmn | 0:3ac96e360672 | 3841 | pConfig->Distance.High = Cfg.threshold_distance_high; |
charlesmn | 0:3ac96e360672 | 3842 | pConfig->Distance.Low = Cfg.threshold_distance_low; |
charlesmn | 0:3ac96e360672 | 3843 | pConfig->Rate.High = |
charlesmn | 0:3ac96e360672 | 3844 | VL53L1_FIXPOINT97TOFIXPOINT1616( |
charlesmn | 0:3ac96e360672 | 3845 | Cfg.threshold_rate_high); |
charlesmn | 0:3ac96e360672 | 3846 | pConfig->Rate.Low = |
charlesmn | 0:3ac96e360672 | 3847 | VL53L1_FIXPOINT97TOFIXPOINT1616(Cfg.threshold_rate_low); |
charlesmn | 0:3ac96e360672 | 3848 | pConfig->Distance.CrossMode = |
charlesmn | 0:3ac96e360672 | 3849 | ConvertModeFromLLD(&Status, Cfg.intr_mode_distance); |
charlesmn | 0:3ac96e360672 | 3850 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3851 | pConfig->Rate.CrossMode = |
charlesmn | 0:3ac96e360672 | 3852 | ConvertModeFromLLD(&Status, Cfg.intr_mode_rate); |
charlesmn | 0:3ac96e360672 | 3853 | |
charlesmn | 0:3ac96e360672 | 3854 | if (Cfg.intr_new_measure_ready == 1) { |
charlesmn | 0:3ac96e360672 | 3855 | pConfig->DetectionMode = VL53L1_DETECTION_NORMAL_RUN; |
charlesmn | 0:3ac96e360672 | 3856 | } else { |
charlesmn | 0:3ac96e360672 | 3857 | |
charlesmn | 0:3ac96e360672 | 3858 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3859 | if (Cfg.intr_combined_mode == 0) |
charlesmn | 0:3ac96e360672 | 3860 | pConfig->DetectionMode = |
charlesmn | 0:3ac96e360672 | 3861 | VL53L1_DETECTION_DISTANCE_AND_RATE; |
charlesmn | 0:3ac96e360672 | 3862 | else { |
charlesmn | 0:3ac96e360672 | 3863 | if ((Cfg.threshold_distance_high == 0) && |
charlesmn | 0:3ac96e360672 | 3864 | (Cfg.threshold_distance_low == 0)) |
charlesmn | 0:3ac96e360672 | 3865 | pConfig->DetectionMode = |
charlesmn | 0:3ac96e360672 | 3866 | VL53L1_DETECTION_RATE_ONLY; |
charlesmn | 0:3ac96e360672 | 3867 | else if ((Cfg.threshold_rate_high == 0) && |
charlesmn | 0:3ac96e360672 | 3868 | (Cfg.threshold_rate_low == 0)) |
charlesmn | 0:3ac96e360672 | 3869 | pConfig->DetectionMode = |
charlesmn | 0:3ac96e360672 | 3870 | VL53L1_DETECTION_DISTANCE_ONLY; |
charlesmn | 0:3ac96e360672 | 3871 | else |
charlesmn | 0:3ac96e360672 | 3872 | pConfig->DetectionMode = |
charlesmn | 0:3ac96e360672 | 3873 | VL53L1_DETECTION_DISTANCE_OR_RATE; |
charlesmn | 0:3ac96e360672 | 3874 | } |
charlesmn | 0:3ac96e360672 | 3875 | } |
charlesmn | 0:3ac96e360672 | 3876 | } |
charlesmn | 0:3ac96e360672 | 3877 | |
charlesmn | 0:3ac96e360672 | 3878 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 3879 | return Status; |
charlesmn | 0:3ac96e360672 | 3880 | } |
charlesmn | 0:3ac96e360672 | 3881 | |
charlesmn | 0:3ac96e360672 | 3882 | |
charlesmn | 0:3ac96e360672 | 3883 | |
charlesmn | 0:3ac96e360672 | 3884 | |
charlesmn | 0:3ac96e360672 | 3885 | VL53L1_Error VL53L1_PerformOffsetPerVcselCalibration(VL53L1_DEV Dev, |
charlesmn | 0:3ac96e360672 | 3886 | int32_t CalDistanceMilliMeter) |
charlesmn | 0:3ac96e360672 | 3887 | { |
charlesmn | 0:3ac96e360672 | 3888 | VL53L1_Error Status = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3889 | int32_t sum_ranging_range_A, sum_ranging_range_B; |
charlesmn | 0:3ac96e360672 | 3890 | uint8_t offset_meas_range_A, offset_meas_range_B; |
charlesmn | 0:3ac96e360672 | 3891 | int16_t Max, UnderMax, OverMax, Repeat; |
charlesmn | 0:3ac96e360672 | 3892 | int32_t inloopcount; |
charlesmn | 0:3ac96e360672 | 3893 | int32_t IncRounding; |
charlesmn | 0:3ac96e360672 | 3894 | int16_t meanDistance_mm; |
charlesmn | 0:3ac96e360672 | 3895 | VL53L1_RangingMeasurementData_t RangingMeasurementData; |
charlesmn | 0:3ac96e360672 | 3896 | VL53L1_LLDriverData_t *pdev; |
charlesmn | 0:3ac96e360672 | 3897 | uint8_t goodmeas; |
charlesmn | 0:3ac96e360672 | 3898 | VL53L1_PresetModes currentMode; |
charlesmn | 0:3ac96e360672 | 3899 | VL53L1_DistanceModes currentDist; |
charlesmn | 0:3ac96e360672 | 3900 | VL53L1_DistanceModes DistMode[3] = {VL53L1_DISTANCEMODE_SHORT, |
charlesmn | 0:3ac96e360672 | 3901 | VL53L1_DISTANCEMODE_MEDIUM, VL53L1_DISTANCEMODE_LONG}; |
charlesmn | 0:3ac96e360672 | 3902 | int16_t offsetA[3]; |
charlesmn | 0:3ac96e360672 | 3903 | int16_t offsetB[3]; |
charlesmn | 0:3ac96e360672 | 3904 | |
charlesmn | 0:3ac96e360672 | 3905 | VL53L1_Error SmudgeStatus = VL53L1_ERROR_NONE; |
charlesmn | 0:3ac96e360672 | 3906 | uint8_t smudge_corr_en, isc; |
charlesmn | 0:3ac96e360672 | 3907 | |
charlesmn | 0:3ac96e360672 | 3908 | LOG_FUNCTION_START(""); |
charlesmn | 0:3ac96e360672 | 3909 | |
charlesmn | 0:3ac96e360672 | 3910 | pdev = VL53L1DevStructGetLLDriverHandle(Dev); |
charlesmn | 0:3ac96e360672 | 3911 | |
charlesmn | 0:3ac96e360672 | 3912 | smudge_corr_en = pdev->smudge_correct_config.smudge_corr_enabled; |
charlesmn | 0:3ac96e360672 | 3913 | SmudgeStatus = VL53L1_dynamic_xtalk_correction_disable(Dev); |
charlesmn | 0:3ac96e360672 | 3914 | |
charlesmn | 0:3ac96e360672 | 3915 | pdev->customer.algo__part_to_part_range_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3916 | pdev->customer.mm_config__inner_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3917 | pdev->customer.mm_config__outer_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3918 | pdev->customer.mm_config__outer_offset_mm = 0; |
charlesmn | 0:3ac96e360672 | 3919 | memset(&pdev->per_vcsel_cal_data, 0, sizeof(pdev->per_vcsel_cal_data)); |
charlesmn | 0:3ac96e360672 | 3920 | |
charlesmn | 0:3ac96e360672 | 3921 | Repeat = 0; |
charlesmn | 0:3ac96e360672 | 3922 | Max = 2 * BDTable[ |
charlesmn | 0:3ac96e360672 | 3923 | VL53L1_TUNING_MAX_SIMPLE_OFFSET_CALIBRATION_SAMPLE_NUMBER]; |
charlesmn | 0:3ac96e360672 | 3924 | UnderMax = 1 + (Max / 2); |
charlesmn | 0:3ac96e360672 | 3925 | OverMax = Max + (Max / 2); |
charlesmn | 0:3ac96e360672 | 3926 | |
charlesmn | 0:3ac96e360672 | 3927 | Status = VL53L1_GetPresetMode(Dev, ¤tMode); |
charlesmn | 0:3ac96e360672 | 3928 | Status = VL53L1_GetDistanceMode(Dev, ¤tDist); |
charlesmn | 0:3ac96e360672 | 3929 | |
charlesmn | 0:3ac96e360672 | 3930 | while ((Repeat < 3) && (Status == VL53L1_ERROR_NONE)) { |
charlesmn | 0:3ac96e360672 | 3931 | Status = VL53L1_SetDistanceMode(Dev, DistMode[Repeat]); |
charlesmn | 0:3ac96e360672 | 3932 | Status = VL53L1_StartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3933 | |
charlesmn | 0:3ac96e360672 | 3934 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 3935 | VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 3936 | VL53L1_GetRangingMeasurementData(Dev, |
charlesmn | 0:3ac96e360672 | 3937 | &RangingMeasurementData); |
charlesmn | 0:3ac96e360672 | 3938 | VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3939 | } |
charlesmn | 0:3ac96e360672 | 3940 | |
charlesmn | 0:3ac96e360672 | 3941 | inloopcount = 0; |
charlesmn | 0:3ac96e360672 | 3942 | offset_meas_range_A = 0; |
charlesmn | 0:3ac96e360672 | 3943 | sum_ranging_range_A = 0; |
charlesmn | 0:3ac96e360672 | 3944 | offset_meas_range_B = 0; |
charlesmn | 0:3ac96e360672 | 3945 | sum_ranging_range_B = 0; |
charlesmn | 0:3ac96e360672 | 3946 | while ((Status == VL53L1_ERROR_NONE) && (inloopcount < Max) && |
charlesmn | 0:3ac96e360672 | 3947 | (inloopcount < OverMax)) { |
charlesmn | 0:3ac96e360672 | 3948 | Status = VL53L1_WaitMeasurementDataReady(Dev); |
charlesmn | 0:3ac96e360672 | 3949 | if (Status == VL53L1_ERROR_NONE) |
charlesmn | 0:3ac96e360672 | 3950 | Status = VL53L1_GetRangingMeasurementData(Dev, |
charlesmn | 0:3ac96e360672 | 3951 | &RangingMeasurementData); |
charlesmn | 0:3ac96e360672 | 3952 | goodmeas = (RangingMeasurementData.RangeStatus == |
charlesmn | 0:3ac96e360672 | 3953 | VL53L1_RANGESTATUS_RANGE_VALID); |
charlesmn | 0:3ac96e360672 | 3954 | isc = pdev->ll_state.cfg_internal_stream_count; |
charlesmn | 0:3ac96e360672 | 3955 | if ((Status == VL53L1_ERROR_NONE) && goodmeas) { |
charlesmn | 0:3ac96e360672 | 3956 | if (isc & 0x01) { |
charlesmn | 0:3ac96e360672 | 3957 | sum_ranging_range_A += |
charlesmn | 0:3ac96e360672 | 3958 | RangingMeasurementData.RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 3959 | offset_meas_range_A++; |
charlesmn | 0:3ac96e360672 | 3960 | } else { |
charlesmn | 0:3ac96e360672 | 3961 | sum_ranging_range_B += |
charlesmn | 0:3ac96e360672 | 3962 | RangingMeasurementData.RangeMilliMeter; |
charlesmn | 0:3ac96e360672 | 3963 | offset_meas_range_B++; |
charlesmn | 0:3ac96e360672 | 3964 | } |
charlesmn | 0:3ac96e360672 | 3965 | inloopcount = offset_meas_range_A + |
charlesmn | 0:3ac96e360672 | 3966 | offset_meas_range_B; |
charlesmn | 0:3ac96e360672 | 3967 | } |
charlesmn | 0:3ac96e360672 | 3968 | Status = VL53L1_ClearInterruptAndStartMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3969 | } |
charlesmn | 0:3ac96e360672 | 3970 | |
charlesmn | 0:3ac96e360672 | 3971 | |
charlesmn | 0:3ac96e360672 | 3972 | if (inloopcount < UnderMax) |
charlesmn | 0:3ac96e360672 | 3973 | Status = VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL; |
charlesmn | 0:3ac96e360672 | 3974 | |
charlesmn | 0:3ac96e360672 | 3975 | VL53L1_StopMeasurement(Dev); |
charlesmn | 0:3ac96e360672 | 3976 | |
charlesmn | 0:3ac96e360672 | 3977 | |
charlesmn | 0:3ac96e360672 | 3978 | if ((sum_ranging_range_A < 0) || |
charlesmn | 0:3ac96e360672 | 3979 | (sum_ranging_range_B < 0) || |
charlesmn | 0:3ac96e360672 | 3980 | (sum_ranging_range_A > |
charlesmn | 0:3ac96e360672 | 3981 | ((int32_t) offset_meas_range_A * 0xffff)) || |
charlesmn | 0:3ac96e360672 | 3982 | (sum_ranging_range_B > |
charlesmn | 0:3ac96e360672 | 3983 | ((int32_t) offset_meas_range_B * 0xffff))) { |
charlesmn | 0:3ac96e360672 | 3984 | Status = VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH; |
charlesmn | 0:3ac96e360672 | 3985 | } |
charlesmn | 0:3ac96e360672 | 3986 | |
charlesmn | 0:3ac96e360672 | 3987 | if ((Status == VL53L1_ERROR_NONE) && |
charlesmn | 0:3ac96e360672 | 3988 | (offset_meas_range_A > 0)) { |
charlesmn | 0:3ac96e360672 | 3989 | IncRounding = offset_meas_range_A / 2; |
charlesmn | 0:3ac96e360672 | 3990 | meanDistance_mm = (int16_t) |
charlesmn | 0:3ac96e360672 | 3991 | ((sum_ranging_range_A + IncRounding) |
charlesmn | 0:3ac96e360672 | 3992 | / offset_meas_range_A); |
charlesmn | 0:3ac96e360672 | 3993 | offsetA[Repeat] = (int16_t) |
charlesmn | 0:3ac96e360672 | 3994 | CalDistanceMilliMeter - meanDistance_mm; |
charlesmn | 0:3ac96e360672 | 3995 | } |
charlesmn | 0:3ac96e360672 | 3996 | |
charlesmn | 0:3ac96e360672 | 3997 | if ((Status == VL53L1_ERROR_NONE) && |
charlesmn | 0:3ac96e360672 | 3998 | (offset_meas_range_B > 0)) { |
charlesmn | 0:3ac96e360672 | 3999 | IncRounding = offset_meas_range_B / 2; |
charlesmn | 0:3ac96e360672 | 4000 | meanDistance_mm = (int16_t) |
charlesmn | 0:3ac96e360672 | 4001 | ((sum_ranging_range_B + IncRounding) |
charlesmn | 0:3ac96e360672 | 4002 | / offset_meas_range_B); |
charlesmn | 0:3ac96e360672 | 4003 | offsetB[Repeat] = (int16_t) |
charlesmn | 0:3ac96e360672 | 4004 | CalDistanceMilliMeter - meanDistance_mm; |
charlesmn | 0:3ac96e360672 | 4005 | } |
charlesmn | 0:3ac96e360672 | 4006 | Repeat++; |
charlesmn | 0:3ac96e360672 | 4007 | } |
charlesmn | 0:3ac96e360672 | 4008 | |
charlesmn | 0:3ac96e360672 | 4009 | if ((SmudgeStatus == VL53L1_ERROR_NONE) && (smudge_corr_en == 1)) |
charlesmn | 0:3ac96e360672 | 4010 | SmudgeStatus = VL53L1_dynamic_xtalk_correction_enable(Dev); |
charlesmn | 0:3ac96e360672 | 4011 | |
charlesmn | 0:3ac96e360672 | 4012 | if (Status == VL53L1_ERROR_NONE) { |
charlesmn | 0:3ac96e360672 | 4013 | pdev->per_vcsel_cal_data.short_a_offset_mm = offsetA[0]; |
charlesmn | 0:3ac96e360672 | 4014 | pdev->per_vcsel_cal_data.short_b_offset_mm = offsetB[0]; |
charlesmn | 0:3ac96e360672 | 4015 | pdev->per_vcsel_cal_data.medium_a_offset_mm = offsetA[1]; |
charlesmn | 0:3ac96e360672 | 4016 | pdev->per_vcsel_cal_data.medium_b_offset_mm = offsetB[1]; |
charlesmn | 0:3ac96e360672 | 4017 | pdev->per_vcsel_cal_data.long_a_offset_mm = offsetA[2]; |
charlesmn | 0:3ac96e360672 | 4018 | pdev->per_vcsel_cal_data.long_b_offset_mm = offsetB[2]; |
charlesmn | 0:3ac96e360672 | 4019 | } |
charlesmn | 0:3ac96e360672 | 4020 | |
charlesmn | 0:3ac96e360672 | 4021 | VL53L1_SetPresetMode(Dev, currentMode); |
charlesmn | 0:3ac96e360672 | 4022 | VL53L1_SetDistanceMode(Dev, currentDist); |
charlesmn | 0:3ac96e360672 | 4023 | |
charlesmn | 0:3ac96e360672 | 4024 | LOG_FUNCTION_END(Status); |
charlesmn | 0:3ac96e360672 | 4025 | return Status; |
charlesmn | 0:3ac96e360672 | 4026 | } |
charlesmn | 0:3ac96e360672 | 4027 | |
charlesmn | 0:3ac96e360672 | 4028 |