hh

Dependents:   VL53L0X-mbedOS-master VL53L0X-mbedOS-masterbb

Committer:
mohamedachour
Date:
Tue Apr 23 14:27:07 2019 +0000
Revision:
2:a1dffa1ff38a
Parent:
0:e6fcdb78a136
xc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjarvisal 0:e6fcdb78a136 1 /*******************************************************************************
mohamedachour 2:a1dffa1ff38a 2 Copyright � 2016, STMicroelectronics International N.V.
mjarvisal 0:e6fcdb78a136 3 All rights reserved.
mjarvisal 0:e6fcdb78a136 4
mjarvisal 0:e6fcdb78a136 5 Redistribution and use in source and binary forms, with or without
mjarvisal 0:e6fcdb78a136 6 modification, are permitted provided that the following conditions are met:
mjarvisal 0:e6fcdb78a136 7 * Redistributions of source code must retain the above copyright
mjarvisal 0:e6fcdb78a136 8 notice, this list of conditions and the following disclaimer.
mjarvisal 0:e6fcdb78a136 9 * Redistributions in binary form must reproduce the above copyright
mjarvisal 0:e6fcdb78a136 10 notice, this list of conditions and the following disclaimer in the
mjarvisal 0:e6fcdb78a136 11 documentation and/or other materials provided with the distribution.
mjarvisal 0:e6fcdb78a136 12 * Neither the name of STMicroelectronics nor the
mjarvisal 0:e6fcdb78a136 13 names of its contributors may be used to endorse or promote products
mjarvisal 0:e6fcdb78a136 14 derived from this software without specific prior written permission.
mjarvisal 0:e6fcdb78a136 15
mjarvisal 0:e6fcdb78a136 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mjarvisal 0:e6fcdb78a136 17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mjarvisal 0:e6fcdb78a136 18 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
mjarvisal 0:e6fcdb78a136 19 NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED.
mjarvisal 0:e6fcdb78a136 20 IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY
mjarvisal 0:e6fcdb78a136 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mjarvisal 0:e6fcdb78a136 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mjarvisal 0:e6fcdb78a136 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
mjarvisal 0:e6fcdb78a136 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mjarvisal 0:e6fcdb78a136 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mjarvisal 0:e6fcdb78a136 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mjarvisal 0:e6fcdb78a136 27 ******************************************************************************/
mjarvisal 0:e6fcdb78a136 28
mjarvisal 0:e6fcdb78a136 29 #include "vl53l0x_api.h"
mjarvisal 0:e6fcdb78a136 30 #include "vl53l0x_tuning.h"
mjarvisal 0:e6fcdb78a136 31 #include "vl53l0x_interrupt_threshold_settings.h"
mjarvisal 0:e6fcdb78a136 32 #include "vl53l0x_api_core.h"
mjarvisal 0:e6fcdb78a136 33 #include "vl53l0x_api_calibration.h"
mjarvisal 0:e6fcdb78a136 34 #include "vl53l0x_api_strings.h"
mjarvisal 0:e6fcdb78a136 35
mjarvisal 0:e6fcdb78a136 36 #ifndef __KERNEL__
mjarvisal 0:e6fcdb78a136 37 #include <stdlib.h>
mjarvisal 0:e6fcdb78a136 38 #endif
mjarvisal 0:e6fcdb78a136 39 #define LOG_FUNCTION_START(fmt, ...) \
mjarvisal 0:e6fcdb78a136 40 _LOG_FUNCTION_START(TRACE_MODULE_API, fmt, ##__VA_ARGS__)
mjarvisal 0:e6fcdb78a136 41 #define LOG_FUNCTION_END(status, ...) \
mjarvisal 0:e6fcdb78a136 42 _LOG_FUNCTION_END(TRACE_MODULE_API, status, ##__VA_ARGS__)
mjarvisal 0:e6fcdb78a136 43 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
mjarvisal 0:e6fcdb78a136 44 _LOG_FUNCTION_END_FMT(TRACE_MODULE_API, status, fmt, ##__VA_ARGS__)
mjarvisal 0:e6fcdb78a136 45
mjarvisal 0:e6fcdb78a136 46 #ifdef VL53L0X_LOG_ENABLE
mjarvisal 0:e6fcdb78a136 47 #define trace_print(level, ...) trace_print_module_function(TRACE_MODULE_API, \
mjarvisal 0:e6fcdb78a136 48 level, TRACE_FUNCTION_NONE, ##__VA_ARGS__)
mjarvisal 0:e6fcdb78a136 49 #endif
mjarvisal 0:e6fcdb78a136 50
mjarvisal 0:e6fcdb78a136 51 /* Group PAL General Functions */
mjarvisal 0:e6fcdb78a136 52
mjarvisal 0:e6fcdb78a136 53 VL53L0X_Error VL53L0X_GetVersion(VL53L0X_Version_t *pVersion)
mjarvisal 0:e6fcdb78a136 54 {
mjarvisal 0:e6fcdb78a136 55 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 56 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 57
mjarvisal 0:e6fcdb78a136 58 pVersion->major = VL53L0X_IMPLEMENTATION_VER_MAJOR;
mjarvisal 0:e6fcdb78a136 59 pVersion->minor = VL53L0X_IMPLEMENTATION_VER_MINOR;
mjarvisal 0:e6fcdb78a136 60 pVersion->build = VL53L0X_IMPLEMENTATION_VER_SUB;
mjarvisal 0:e6fcdb78a136 61
mjarvisal 0:e6fcdb78a136 62 pVersion->revision = VL53L0X_IMPLEMENTATION_VER_REVISION;
mjarvisal 0:e6fcdb78a136 63
mjarvisal 0:e6fcdb78a136 64 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 65 return Status;
mjarvisal 0:e6fcdb78a136 66 }
mjarvisal 0:e6fcdb78a136 67
mjarvisal 0:e6fcdb78a136 68 VL53L0X_Error VL53L0X_GetPalSpecVersion(VL53L0X_Version_t *pPalSpecVersion)
mjarvisal 0:e6fcdb78a136 69 {
mjarvisal 0:e6fcdb78a136 70 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 71
mjarvisal 0:e6fcdb78a136 72 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 73
mjarvisal 0:e6fcdb78a136 74 pPalSpecVersion->major = VL53L0X_SPECIFICATION_VER_MAJOR;
mjarvisal 0:e6fcdb78a136 75 pPalSpecVersion->minor = VL53L0X_SPECIFICATION_VER_MINOR;
mjarvisal 0:e6fcdb78a136 76 pPalSpecVersion->build = VL53L0X_SPECIFICATION_VER_SUB;
mjarvisal 0:e6fcdb78a136 77
mjarvisal 0:e6fcdb78a136 78 pPalSpecVersion->revision = VL53L0X_SPECIFICATION_VER_REVISION;
mjarvisal 0:e6fcdb78a136 79
mjarvisal 0:e6fcdb78a136 80 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 81 return Status;
mjarvisal 0:e6fcdb78a136 82 }
mjarvisal 0:e6fcdb78a136 83
mjarvisal 0:e6fcdb78a136 84 VL53L0X_Error VL53L0X_GetProductRevision(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 85 uint8_t *pProductRevisionMajor, uint8_t *pProductRevisionMinor)
mjarvisal 0:e6fcdb78a136 86 {
mjarvisal 0:e6fcdb78a136 87 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 88 uint8_t revision_id;
mjarvisal 0:e6fcdb78a136 89
mjarvisal 0:e6fcdb78a136 90 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 91
mjarvisal 0:e6fcdb78a136 92 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_IDENTIFICATION_REVISION_ID,
mjarvisal 0:e6fcdb78a136 93 &revision_id);
mjarvisal 0:e6fcdb78a136 94 *pProductRevisionMajor = 1;
mjarvisal 0:e6fcdb78a136 95 *pProductRevisionMinor = (revision_id & 0xF0) >> 4;
mjarvisal 0:e6fcdb78a136 96
mjarvisal 0:e6fcdb78a136 97 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 98 return Status;
mjarvisal 0:e6fcdb78a136 99
mjarvisal 0:e6fcdb78a136 100 }
mjarvisal 0:e6fcdb78a136 101
mjarvisal 0:e6fcdb78a136 102 VL53L0X_Error VL53L0X_GetDeviceInfo(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 103 VL53L0X_DeviceInfo_t *pVL53L0X_DeviceInfo)
mjarvisal 0:e6fcdb78a136 104 {
mjarvisal 0:e6fcdb78a136 105 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 106 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 107
mjarvisal 0:e6fcdb78a136 108 Status = VL53L0X_get_device_info(Dev, pVL53L0X_DeviceInfo);
mjarvisal 0:e6fcdb78a136 109
mjarvisal 0:e6fcdb78a136 110 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 111 return Status;
mjarvisal 0:e6fcdb78a136 112 }
mjarvisal 0:e6fcdb78a136 113
mjarvisal 0:e6fcdb78a136 114 VL53L0X_Error VL53L0X_GetDeviceErrorStatus(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 115 VL53L0X_DeviceError *pDeviceErrorStatus)
mjarvisal 0:e6fcdb78a136 116 {
mjarvisal 0:e6fcdb78a136 117 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 118 uint8_t RangeStatus;
mjarvisal 0:e6fcdb78a136 119
mjarvisal 0:e6fcdb78a136 120 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 121
mjarvisal 0:e6fcdb78a136 122 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_RESULT_RANGE_STATUS,
mjarvisal 0:e6fcdb78a136 123 &RangeStatus);
mjarvisal 0:e6fcdb78a136 124
mjarvisal 0:e6fcdb78a136 125 *pDeviceErrorStatus = (VL53L0X_DeviceError)((RangeStatus & 0x78) >> 3);
mjarvisal 0:e6fcdb78a136 126
mjarvisal 0:e6fcdb78a136 127 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 128 return Status;
mjarvisal 0:e6fcdb78a136 129 }
mjarvisal 0:e6fcdb78a136 130
mjarvisal 0:e6fcdb78a136 131
mjarvisal 0:e6fcdb78a136 132 VL53L0X_Error VL53L0X_GetDeviceErrorString(VL53L0X_DeviceError ErrorCode,
mjarvisal 0:e6fcdb78a136 133 char *pDeviceErrorString)
mjarvisal 0:e6fcdb78a136 134 {
mjarvisal 0:e6fcdb78a136 135 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 136
mjarvisal 0:e6fcdb78a136 137 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 138
mjarvisal 0:e6fcdb78a136 139 Status = VL53L0X_get_device_error_string(ErrorCode, pDeviceErrorString);
mjarvisal 0:e6fcdb78a136 140
mjarvisal 0:e6fcdb78a136 141 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 142 return Status;
mjarvisal 0:e6fcdb78a136 143 }
mjarvisal 0:e6fcdb78a136 144
mjarvisal 0:e6fcdb78a136 145 VL53L0X_Error VL53L0X_GetRangeStatusString(uint8_t RangeStatus,
mjarvisal 0:e6fcdb78a136 146 char *pRangeStatusString)
mjarvisal 0:e6fcdb78a136 147 {
mjarvisal 0:e6fcdb78a136 148 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 149 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 150
mjarvisal 0:e6fcdb78a136 151 Status = VL53L0X_get_range_status_string(RangeStatus,
mjarvisal 0:e6fcdb78a136 152 pRangeStatusString);
mjarvisal 0:e6fcdb78a136 153
mjarvisal 0:e6fcdb78a136 154 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 155 return Status;
mjarvisal 0:e6fcdb78a136 156 }
mjarvisal 0:e6fcdb78a136 157
mjarvisal 0:e6fcdb78a136 158 VL53L0X_Error VL53L0X_GetPalErrorString(VL53L0X_Error PalErrorCode,
mjarvisal 0:e6fcdb78a136 159 char *pPalErrorString)
mjarvisal 0:e6fcdb78a136 160 {
mjarvisal 0:e6fcdb78a136 161 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 162 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 163
mjarvisal 0:e6fcdb78a136 164 Status = VL53L0X_get_pal_error_string(PalErrorCode, pPalErrorString);
mjarvisal 0:e6fcdb78a136 165
mjarvisal 0:e6fcdb78a136 166 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 167 return Status;
mjarvisal 0:e6fcdb78a136 168 }
mjarvisal 0:e6fcdb78a136 169
mjarvisal 0:e6fcdb78a136 170 VL53L0X_Error VL53L0X_GetPalStateString(VL53L0X_State PalStateCode,
mjarvisal 0:e6fcdb78a136 171 char *pPalStateString)
mjarvisal 0:e6fcdb78a136 172 {
mjarvisal 0:e6fcdb78a136 173 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 174 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 175
mjarvisal 0:e6fcdb78a136 176 Status = VL53L0X_get_pal_state_string(PalStateCode, pPalStateString);
mjarvisal 0:e6fcdb78a136 177
mjarvisal 0:e6fcdb78a136 178 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 179 return Status;
mjarvisal 0:e6fcdb78a136 180 }
mjarvisal 0:e6fcdb78a136 181
mjarvisal 0:e6fcdb78a136 182 VL53L0X_Error VL53L0X_GetPalState(VL53L0X_DEV Dev, VL53L0X_State *pPalState)
mjarvisal 0:e6fcdb78a136 183 {
mjarvisal 0:e6fcdb78a136 184 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 185 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 186
mjarvisal 0:e6fcdb78a136 187 *pPalState = PALDevDataGet(Dev, PalState);
mjarvisal 0:e6fcdb78a136 188
mjarvisal 0:e6fcdb78a136 189 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 190 return Status;
mjarvisal 0:e6fcdb78a136 191 }
mjarvisal 0:e6fcdb78a136 192
mjarvisal 0:e6fcdb78a136 193 VL53L0X_Error VL53L0X_SetPowerMode(VL53L0X_DEV Dev, VL53L0X_PowerModes PowerMode)
mjarvisal 0:e6fcdb78a136 194 {
mjarvisal 0:e6fcdb78a136 195 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 196 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 197
mjarvisal 0:e6fcdb78a136 198 /* Only level1 of Power mode exists */
mjarvisal 0:e6fcdb78a136 199 if ((PowerMode != VL53L0X_POWERMODE_STANDBY_LEVEL1)
mjarvisal 0:e6fcdb78a136 200 && (PowerMode != VL53L0X_POWERMODE_IDLE_LEVEL1)) {
mjarvisal 0:e6fcdb78a136 201 Status = VL53L0X_ERROR_MODE_NOT_SUPPORTED;
mjarvisal 0:e6fcdb78a136 202 } else if (PowerMode == VL53L0X_POWERMODE_STANDBY_LEVEL1) {
mjarvisal 0:e6fcdb78a136 203 /* set the standby level1 of power mode */
mjarvisal 0:e6fcdb78a136 204 Status = VL53L0X_WrByte(Dev, 0x80, 0x00);
mjarvisal 0:e6fcdb78a136 205 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 206 /* Set PAL State to standby */
mjarvisal 0:e6fcdb78a136 207 PALDevDataSet(Dev, PalState, VL53L0X_STATE_STANDBY);
mjarvisal 0:e6fcdb78a136 208 PALDevDataSet(Dev, PowerMode,
mjarvisal 0:e6fcdb78a136 209 VL53L0X_POWERMODE_STANDBY_LEVEL1);
mjarvisal 0:e6fcdb78a136 210 }
mjarvisal 0:e6fcdb78a136 211
mjarvisal 0:e6fcdb78a136 212 } else {
mjarvisal 0:e6fcdb78a136 213 /* VL53L0X_POWERMODE_IDLE_LEVEL1 */
mjarvisal 0:e6fcdb78a136 214 Status = VL53L0X_WrByte(Dev, 0x80, 0x00);
mjarvisal 0:e6fcdb78a136 215 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 216 Status = VL53L0X_StaticInit(Dev);
mjarvisal 0:e6fcdb78a136 217
mjarvisal 0:e6fcdb78a136 218 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 219 PALDevDataSet(Dev, PowerMode,
mjarvisal 0:e6fcdb78a136 220 VL53L0X_POWERMODE_IDLE_LEVEL1);
mjarvisal 0:e6fcdb78a136 221
mjarvisal 0:e6fcdb78a136 222 }
mjarvisal 0:e6fcdb78a136 223
mjarvisal 0:e6fcdb78a136 224 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 225 return Status;
mjarvisal 0:e6fcdb78a136 226 }
mjarvisal 0:e6fcdb78a136 227
mjarvisal 0:e6fcdb78a136 228 VL53L0X_Error VL53L0X_GetPowerMode(VL53L0X_DEV Dev, VL53L0X_PowerModes *pPowerMode)
mjarvisal 0:e6fcdb78a136 229 {
mjarvisal 0:e6fcdb78a136 230 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 231 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 232 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 233
mjarvisal 0:e6fcdb78a136 234 /* Only level1 of Power mode exists */
mjarvisal 0:e6fcdb78a136 235 Status = VL53L0X_RdByte(Dev, 0x80, &Byte);
mjarvisal 0:e6fcdb78a136 236
mjarvisal 0:e6fcdb78a136 237 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 238 if (Byte == 1) {
mjarvisal 0:e6fcdb78a136 239 PALDevDataSet(Dev, PowerMode,
mjarvisal 0:e6fcdb78a136 240 VL53L0X_POWERMODE_IDLE_LEVEL1);
mjarvisal 0:e6fcdb78a136 241 } else {
mjarvisal 0:e6fcdb78a136 242 PALDevDataSet(Dev, PowerMode,
mjarvisal 0:e6fcdb78a136 243 VL53L0X_POWERMODE_STANDBY_LEVEL1);
mjarvisal 0:e6fcdb78a136 244 }
mjarvisal 0:e6fcdb78a136 245 }
mjarvisal 0:e6fcdb78a136 246
mjarvisal 0:e6fcdb78a136 247 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 248 return Status;
mjarvisal 0:e6fcdb78a136 249 }
mjarvisal 0:e6fcdb78a136 250
mjarvisal 0:e6fcdb78a136 251 VL53L0X_Error VL53L0X_SetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 252 int32_t OffsetCalibrationDataMicroMeter)
mjarvisal 0:e6fcdb78a136 253 {
mjarvisal 0:e6fcdb78a136 254 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 255 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 256
mjarvisal 0:e6fcdb78a136 257 Status = VL53L0X_set_offset_calibration_data_micro_meter(Dev,
mjarvisal 0:e6fcdb78a136 258 OffsetCalibrationDataMicroMeter);
mjarvisal 0:e6fcdb78a136 259
mjarvisal 0:e6fcdb78a136 260 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 261 return Status;
mjarvisal 0:e6fcdb78a136 262 }
mjarvisal 0:e6fcdb78a136 263
mjarvisal 0:e6fcdb78a136 264 VL53L0X_Error VL53L0X_GetOffsetCalibrationDataMicroMeter(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 265 int32_t *pOffsetCalibrationDataMicroMeter)
mjarvisal 0:e6fcdb78a136 266 {
mjarvisal 0:e6fcdb78a136 267 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 268 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 269
mjarvisal 0:e6fcdb78a136 270 Status = VL53L0X_get_offset_calibration_data_micro_meter(Dev,
mjarvisal 0:e6fcdb78a136 271 pOffsetCalibrationDataMicroMeter);
mjarvisal 0:e6fcdb78a136 272
mjarvisal 0:e6fcdb78a136 273 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 274 return Status;
mjarvisal 0:e6fcdb78a136 275 }
mjarvisal 0:e6fcdb78a136 276
mjarvisal 0:e6fcdb78a136 277 VL53L0X_Error VL53L0X_SetLinearityCorrectiveGain(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 278 int16_t LinearityCorrectiveGain)
mjarvisal 0:e6fcdb78a136 279 {
mjarvisal 0:e6fcdb78a136 280 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 281 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 282
mjarvisal 0:e6fcdb78a136 283 if ((LinearityCorrectiveGain < 0) || (LinearityCorrectiveGain > 1000))
mjarvisal 0:e6fcdb78a136 284 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 285 else {
mjarvisal 0:e6fcdb78a136 286 PALDevDataSet(Dev, LinearityCorrectiveGain,
mjarvisal 0:e6fcdb78a136 287 LinearityCorrectiveGain);
mjarvisal 0:e6fcdb78a136 288
mjarvisal 0:e6fcdb78a136 289 if (LinearityCorrectiveGain != 1000) {
mjarvisal 0:e6fcdb78a136 290 /* Disable FW Xtalk */
mjarvisal 0:e6fcdb78a136 291 Status = VL53L0X_WrWord(Dev,
mjarvisal 0:e6fcdb78a136 292 VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, 0);
mjarvisal 0:e6fcdb78a136 293 }
mjarvisal 0:e6fcdb78a136 294 }
mjarvisal 0:e6fcdb78a136 295
mjarvisal 0:e6fcdb78a136 296 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 297 return Status;
mjarvisal 0:e6fcdb78a136 298 }
mjarvisal 0:e6fcdb78a136 299
mjarvisal 0:e6fcdb78a136 300 VL53L0X_Error VL53L0X_GetLinearityCorrectiveGain(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 301 uint16_t *pLinearityCorrectiveGain)
mjarvisal 0:e6fcdb78a136 302 {
mjarvisal 0:e6fcdb78a136 303 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 304 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 305
mjarvisal 0:e6fcdb78a136 306 *pLinearityCorrectiveGain = PALDevDataGet(Dev, LinearityCorrectiveGain);
mjarvisal 0:e6fcdb78a136 307
mjarvisal 0:e6fcdb78a136 308 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 309 return Status;
mjarvisal 0:e6fcdb78a136 310 }
mjarvisal 0:e6fcdb78a136 311
mjarvisal 0:e6fcdb78a136 312 VL53L0X_Error VL53L0X_SetGroupParamHold(VL53L0X_DEV Dev, uint8_t GroupParamHold)
mjarvisal 0:e6fcdb78a136 313 {
mjarvisal 0:e6fcdb78a136 314 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 315 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 316
mjarvisal 0:e6fcdb78a136 317 /* not implemented on VL53L0X */
mjarvisal 0:e6fcdb78a136 318
mjarvisal 0:e6fcdb78a136 319 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 320 return Status;
mjarvisal 0:e6fcdb78a136 321 }
mjarvisal 0:e6fcdb78a136 322
mjarvisal 0:e6fcdb78a136 323 VL53L0X_Error VL53L0X_GetUpperLimitMilliMeter(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 324 uint16_t *pUpperLimitMilliMeter)
mjarvisal 0:e6fcdb78a136 325 {
mjarvisal 0:e6fcdb78a136 326 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 327 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 328
mjarvisal 0:e6fcdb78a136 329 /* not implemented on VL53L0X */
mjarvisal 0:e6fcdb78a136 330
mjarvisal 0:e6fcdb78a136 331 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 332 return Status;
mjarvisal 0:e6fcdb78a136 333 }
mjarvisal 0:e6fcdb78a136 334
mjarvisal 0:e6fcdb78a136 335 VL53L0X_Error VL53L0X_GetTotalSignalRate(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 336 FixPoint1616_t *pTotalSignalRate)
mjarvisal 0:e6fcdb78a136 337 {
mjarvisal 0:e6fcdb78a136 338 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 339 VL53L0X_RangingMeasurementData_t LastRangeDataBuffer;
mjarvisal 0:e6fcdb78a136 340
mjarvisal 0:e6fcdb78a136 341 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 342
mjarvisal 0:e6fcdb78a136 343 LastRangeDataBuffer = PALDevDataGet(Dev, LastRangeMeasure);
mjarvisal 0:e6fcdb78a136 344
mjarvisal 0:e6fcdb78a136 345 Status = VL53L0X_get_total_signal_rate(
mjarvisal 0:e6fcdb78a136 346 Dev, &LastRangeDataBuffer, pTotalSignalRate);
mjarvisal 0:e6fcdb78a136 347
mjarvisal 0:e6fcdb78a136 348 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 349 return Status;
mjarvisal 0:e6fcdb78a136 350 }
mjarvisal 0:e6fcdb78a136 351
mjarvisal 0:e6fcdb78a136 352 /* End Group PAL General Functions */
mjarvisal 0:e6fcdb78a136 353
mjarvisal 0:e6fcdb78a136 354 /* Group PAL Init Functions */
mjarvisal 0:e6fcdb78a136 355 VL53L0X_Error VL53L0X_SetDeviceAddress(VL53L0X_DEV Dev, uint8_t DeviceAddress)
mjarvisal 0:e6fcdb78a136 356 {
mjarvisal 0:e6fcdb78a136 357 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 358 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 359
mjarvisal 0:e6fcdb78a136 360 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_I2C_SLAVE_DEVICE_ADDRESS,
mjarvisal 0:e6fcdb78a136 361 DeviceAddress / 2);
mjarvisal 0:e6fcdb78a136 362
mjarvisal 0:e6fcdb78a136 363 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 364 return Status;
mjarvisal 0:e6fcdb78a136 365 }
mjarvisal 0:e6fcdb78a136 366
mjarvisal 0:e6fcdb78a136 367 VL53L0X_Error VL53L0X_DataInit(VL53L0X_DEV Dev)
mjarvisal 0:e6fcdb78a136 368 {
mjarvisal 0:e6fcdb78a136 369 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 370 VL53L0X_DeviceParameters_t CurrentParameters;
mjarvisal 0:e6fcdb78a136 371 int i;
mjarvisal 0:e6fcdb78a136 372 uint8_t StopVariable;
mjarvisal 0:e6fcdb78a136 373
mjarvisal 0:e6fcdb78a136 374 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 375
mjarvisal 0:e6fcdb78a136 376 /* by default the I2C is running at 1V8 if you want to change it you
mjarvisal 0:e6fcdb78a136 377 * need to include this define at compilation level. */
mjarvisal 0:e6fcdb78a136 378 #ifdef USE_I2C_2V8
mjarvisal 0:e6fcdb78a136 379 Status = VL53L0X_UpdateByte(Dev,
mjarvisal 0:e6fcdb78a136 380 VL53L0X_REG_VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV,
mjarvisal 0:e6fcdb78a136 381 0xFE,
mjarvisal 0:e6fcdb78a136 382 0x01);
mjarvisal 0:e6fcdb78a136 383 #endif
mjarvisal 0:e6fcdb78a136 384
mjarvisal 0:e6fcdb78a136 385 /* Set I2C standard mode */
mjarvisal 0:e6fcdb78a136 386 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 387 Status = VL53L0X_WrByte(Dev, 0x88, 0x00);
mjarvisal 0:e6fcdb78a136 388
mjarvisal 0:e6fcdb78a136 389 VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, ReadDataFromDeviceDone, 0);
mjarvisal 0:e6fcdb78a136 390
mjarvisal 0:e6fcdb78a136 391 #ifdef USE_IQC_STATION
mjarvisal 0:e6fcdb78a136 392 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 393 Status = VL53L0X_apply_offset_adjustment(Dev);
mjarvisal 0:e6fcdb78a136 394 #endif
mjarvisal 0:e6fcdb78a136 395
mjarvisal 0:e6fcdb78a136 396 /* Default value is 1000 for Linearity Corrective Gain */
mjarvisal 0:e6fcdb78a136 397 PALDevDataSet(Dev, LinearityCorrectiveGain, 1000);
mjarvisal 0:e6fcdb78a136 398
mjarvisal 0:e6fcdb78a136 399 /* Dmax default Parameter */
mjarvisal 0:e6fcdb78a136 400 PALDevDataSet(Dev, DmaxCalRangeMilliMeter, 400);
mjarvisal 0:e6fcdb78a136 401 PALDevDataSet(Dev, DmaxCalSignalRateRtnMegaCps,
mjarvisal 0:e6fcdb78a136 402 (FixPoint1616_t)((0x00016B85))); /* 1.42 No Cover Glass*/
mjarvisal 0:e6fcdb78a136 403
mjarvisal 0:e6fcdb78a136 404 /* Set Default static parameters
mjarvisal 0:e6fcdb78a136 405 *set first temporary values 9.44MHz * 65536 = 618660 */
mjarvisal 0:e6fcdb78a136 406 VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz, 618660);
mjarvisal 0:e6fcdb78a136 407
mjarvisal 0:e6fcdb78a136 408 /* Set Default XTalkCompensationRateMegaCps to 0 */
mjarvisal 0:e6fcdb78a136 409 VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps, 0);
mjarvisal 0:e6fcdb78a136 410
mjarvisal 0:e6fcdb78a136 411 /* Get default parameters */
mjarvisal 0:e6fcdb78a136 412 Status = VL53L0X_GetDeviceParameters(Dev, &CurrentParameters);
mjarvisal 0:e6fcdb78a136 413 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 414 /* initialize PAL values */
mjarvisal 0:e6fcdb78a136 415 CurrentParameters.DeviceMode = VL53L0X_DEVICEMODE_SINGLE_RANGING;
mjarvisal 0:e6fcdb78a136 416 CurrentParameters.HistogramMode = VL53L0X_HISTOGRAMMODE_DISABLED;
mjarvisal 0:e6fcdb78a136 417 PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
mjarvisal 0:e6fcdb78a136 418 }
mjarvisal 0:e6fcdb78a136 419
mjarvisal 0:e6fcdb78a136 420 /* Sigma estimator variable */
mjarvisal 0:e6fcdb78a136 421 PALDevDataSet(Dev, SigmaEstRefArray, 100);
mjarvisal 0:e6fcdb78a136 422 PALDevDataSet(Dev, SigmaEstEffPulseWidth, 900);
mjarvisal 0:e6fcdb78a136 423 PALDevDataSet(Dev, SigmaEstEffAmbWidth, 500);
mjarvisal 0:e6fcdb78a136 424 PALDevDataSet(Dev, targetRefRate, 0x0A00); /* 20 MCPS in 9:7 format */
mjarvisal 0:e6fcdb78a136 425
mjarvisal 0:e6fcdb78a136 426 /* Use internal default settings */
mjarvisal 0:e6fcdb78a136 427 PALDevDataSet(Dev, UseInternalTuningSettings, 1);
mjarvisal 0:e6fcdb78a136 428
mjarvisal 0:e6fcdb78a136 429 Status |= VL53L0X_WrByte(Dev, 0x80, 0x01);
mjarvisal 0:e6fcdb78a136 430 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 431 Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
mjarvisal 0:e6fcdb78a136 432 Status |= VL53L0X_RdByte(Dev, 0x91, &StopVariable);
mjarvisal 0:e6fcdb78a136 433 PALDevDataSet(Dev, StopVariable, StopVariable);
mjarvisal 0:e6fcdb78a136 434 Status |= VL53L0X_WrByte(Dev, 0x00, 0x01);
mjarvisal 0:e6fcdb78a136 435 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 436 Status |= VL53L0X_WrByte(Dev, 0x80, 0x00);
mjarvisal 0:e6fcdb78a136 437
mjarvisal 0:e6fcdb78a136 438 /* Enable all check */
mjarvisal 0:e6fcdb78a136 439 for (i = 0; i < VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
mjarvisal 0:e6fcdb78a136 440 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 441 Status |= VL53L0X_SetLimitCheckEnable(Dev, i, 1);
mjarvisal 0:e6fcdb78a136 442 else
mjarvisal 0:e6fcdb78a136 443 break;
mjarvisal 0:e6fcdb78a136 444
mjarvisal 0:e6fcdb78a136 445 }
mjarvisal 0:e6fcdb78a136 446
mjarvisal 0:e6fcdb78a136 447 /* Disable the following checks */
mjarvisal 0:e6fcdb78a136 448 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 449 Status = VL53L0X_SetLimitCheckEnable(Dev,
mjarvisal 0:e6fcdb78a136 450 VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, 0);
mjarvisal 0:e6fcdb78a136 451
mjarvisal 0:e6fcdb78a136 452 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 453 Status = VL53L0X_SetLimitCheckEnable(Dev,
mjarvisal 0:e6fcdb78a136 454 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 0);
mjarvisal 0:e6fcdb78a136 455
mjarvisal 0:e6fcdb78a136 456 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 457 Status = VL53L0X_SetLimitCheckEnable(Dev,
mjarvisal 0:e6fcdb78a136 458 VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC, 0);
mjarvisal 0:e6fcdb78a136 459
mjarvisal 0:e6fcdb78a136 460 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 461 Status = VL53L0X_SetLimitCheckEnable(Dev,
mjarvisal 0:e6fcdb78a136 462 VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE, 0);
mjarvisal 0:e6fcdb78a136 463
mjarvisal 0:e6fcdb78a136 464 /* Limit default values */
mjarvisal 0:e6fcdb78a136 465 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 466 Status = VL53L0X_SetLimitCheckValue(Dev,
mjarvisal 0:e6fcdb78a136 467 VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
mjarvisal 0:e6fcdb78a136 468 (FixPoint1616_t)(18 * 65536));
mjarvisal 0:e6fcdb78a136 469 }
mjarvisal 0:e6fcdb78a136 470 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 471 Status = VL53L0X_SetLimitCheckValue(Dev,
mjarvisal 0:e6fcdb78a136 472 VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE,
mjarvisal 0:e6fcdb78a136 473 (FixPoint1616_t)(25 * 65536 / 100));
mjarvisal 0:e6fcdb78a136 474 /* 0.25 * 65536 */
mjarvisal 0:e6fcdb78a136 475 }
mjarvisal 0:e6fcdb78a136 476
mjarvisal 0:e6fcdb78a136 477 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 478 Status = VL53L0X_SetLimitCheckValue(Dev,
mjarvisal 0:e6fcdb78a136 479 VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
mjarvisal 0:e6fcdb78a136 480 (FixPoint1616_t)(35 * 65536));
mjarvisal 0:e6fcdb78a136 481 }
mjarvisal 0:e6fcdb78a136 482
mjarvisal 0:e6fcdb78a136 483 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 484 Status = VL53L0X_SetLimitCheckValue(Dev,
mjarvisal 0:e6fcdb78a136 485 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
mjarvisal 0:e6fcdb78a136 486 (FixPoint1616_t)(0 * 65536));
mjarvisal 0:e6fcdb78a136 487 }
mjarvisal 0:e6fcdb78a136 488
mjarvisal 0:e6fcdb78a136 489 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 490
mjarvisal 0:e6fcdb78a136 491 PALDevDataSet(Dev, SequenceConfig, 0xFF);
mjarvisal 0:e6fcdb78a136 492 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
mjarvisal 0:e6fcdb78a136 493 0xFF);
mjarvisal 0:e6fcdb78a136 494
mjarvisal 0:e6fcdb78a136 495 /* Set PAL state to tell that we are waiting for call to
mjarvisal 0:e6fcdb78a136 496 * VL53L0X_StaticInit */
mjarvisal 0:e6fcdb78a136 497 PALDevDataSet(Dev, PalState, VL53L0X_STATE_WAIT_STATICINIT);
mjarvisal 0:e6fcdb78a136 498 }
mjarvisal 0:e6fcdb78a136 499
mjarvisal 0:e6fcdb78a136 500 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 501 VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, RefSpadsInitialised, 0);
mjarvisal 0:e6fcdb78a136 502
mjarvisal 0:e6fcdb78a136 503
mjarvisal 0:e6fcdb78a136 504 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 505 return Status;
mjarvisal 0:e6fcdb78a136 506 }
mjarvisal 0:e6fcdb78a136 507
mjarvisal 0:e6fcdb78a136 508 VL53L0X_Error VL53L0X_SetTuningSettingBuffer(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 509 uint8_t *pTuningSettingBuffer, uint8_t UseInternalTuningSettings)
mjarvisal 0:e6fcdb78a136 510 {
mjarvisal 0:e6fcdb78a136 511 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 512
mjarvisal 0:e6fcdb78a136 513 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 514
mjarvisal 0:e6fcdb78a136 515 if (UseInternalTuningSettings == 1) {
mjarvisal 0:e6fcdb78a136 516 /* Force use internal settings */
mjarvisal 0:e6fcdb78a136 517 PALDevDataSet(Dev, UseInternalTuningSettings, 1);
mjarvisal 0:e6fcdb78a136 518 } else {
mjarvisal 0:e6fcdb78a136 519
mjarvisal 0:e6fcdb78a136 520 /* check that the first byte is not 0 */
mjarvisal 0:e6fcdb78a136 521 if (*pTuningSettingBuffer != 0) {
mjarvisal 0:e6fcdb78a136 522 PALDevDataSet(Dev, pTuningSettingsPointer,
mjarvisal 0:e6fcdb78a136 523 pTuningSettingBuffer);
mjarvisal 0:e6fcdb78a136 524 PALDevDataSet(Dev, UseInternalTuningSettings, 0);
mjarvisal 0:e6fcdb78a136 525
mjarvisal 0:e6fcdb78a136 526 } else {
mjarvisal 0:e6fcdb78a136 527 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 528 }
mjarvisal 0:e6fcdb78a136 529 }
mjarvisal 0:e6fcdb78a136 530
mjarvisal 0:e6fcdb78a136 531 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 532 return Status;
mjarvisal 0:e6fcdb78a136 533 }
mjarvisal 0:e6fcdb78a136 534
mjarvisal 0:e6fcdb78a136 535 VL53L0X_Error VL53L0X_GetTuningSettingBuffer(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 536 uint8_t **ppTuningSettingBuffer, uint8_t *pUseInternalTuningSettings)
mjarvisal 0:e6fcdb78a136 537 {
mjarvisal 0:e6fcdb78a136 538 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 539
mjarvisal 0:e6fcdb78a136 540 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 541
mjarvisal 0:e6fcdb78a136 542 *ppTuningSettingBuffer = PALDevDataGet(Dev, pTuningSettingsPointer);
mjarvisal 0:e6fcdb78a136 543 *pUseInternalTuningSettings = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 544 UseInternalTuningSettings);
mjarvisal 0:e6fcdb78a136 545
mjarvisal 0:e6fcdb78a136 546 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 547 return Status;
mjarvisal 0:e6fcdb78a136 548 }
mjarvisal 0:e6fcdb78a136 549
mjarvisal 0:e6fcdb78a136 550 VL53L0X_Error VL53L0X_StaticInit(VL53L0X_DEV Dev)
mjarvisal 0:e6fcdb78a136 551 {
mjarvisal 0:e6fcdb78a136 552 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 553 VL53L0X_DeviceParameters_t CurrentParameters = {0};
mjarvisal 0:e6fcdb78a136 554 uint8_t *pTuningSettingBuffer;
mjarvisal 0:e6fcdb78a136 555 uint16_t tempword = 0;
mjarvisal 0:e6fcdb78a136 556 uint8_t tempbyte = 0;
mjarvisal 0:e6fcdb78a136 557 uint8_t UseInternalTuningSettings = 0;
mjarvisal 0:e6fcdb78a136 558 uint32_t count = 0;
mjarvisal 0:e6fcdb78a136 559 uint8_t isApertureSpads = 0;
mjarvisal 0:e6fcdb78a136 560 uint32_t refSpadCount = 0;
mjarvisal 0:e6fcdb78a136 561 uint8_t ApertureSpads = 0;
mjarvisal 0:e6fcdb78a136 562 uint8_t vcselPulsePeriodPCLK;
mjarvisal 0:e6fcdb78a136 563 FixPoint1616_t seqTimeoutMilliSecs;
mjarvisal 0:e6fcdb78a136 564
mjarvisal 0:e6fcdb78a136 565 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 566
mjarvisal 0:e6fcdb78a136 567 Status = VL53L0X_get_info_from_device(Dev, 1);
mjarvisal 0:e6fcdb78a136 568
mjarvisal 0:e6fcdb78a136 569 /* set the ref spad from NVM */
mjarvisal 0:e6fcdb78a136 570 count = (uint32_t)VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
mjarvisal 0:e6fcdb78a136 571 ReferenceSpadCount);
mjarvisal 0:e6fcdb78a136 572 ApertureSpads = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
mjarvisal 0:e6fcdb78a136 573 ReferenceSpadType);
mjarvisal 0:e6fcdb78a136 574
mjarvisal 0:e6fcdb78a136 575 /* NVM value invalid */
mjarvisal 0:e6fcdb78a136 576 if ((ApertureSpads > 1) ||
mjarvisal 0:e6fcdb78a136 577 ((ApertureSpads == 1) && (count > 32)) ||
mjarvisal 0:e6fcdb78a136 578 ((ApertureSpads == 0) && (count > 12)))
mjarvisal 0:e6fcdb78a136 579 Status = VL53L0X_perform_ref_spad_management(Dev, &refSpadCount,
mjarvisal 0:e6fcdb78a136 580 &isApertureSpads);
mjarvisal 0:e6fcdb78a136 581 else
mjarvisal 0:e6fcdb78a136 582 Status = VL53L0X_set_reference_spads(Dev, count, ApertureSpads);
mjarvisal 0:e6fcdb78a136 583
mjarvisal 0:e6fcdb78a136 584
mjarvisal 0:e6fcdb78a136 585 /* Initialize tuning settings buffer to prevent compiler warning. */
mjarvisal 0:e6fcdb78a136 586 pTuningSettingBuffer = DefaultTuningSettings;
mjarvisal 0:e6fcdb78a136 587
mjarvisal 0:e6fcdb78a136 588 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 589 UseInternalTuningSettings = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 590 UseInternalTuningSettings);
mjarvisal 0:e6fcdb78a136 591
mjarvisal 0:e6fcdb78a136 592 if (UseInternalTuningSettings == 0)
mjarvisal 0:e6fcdb78a136 593 pTuningSettingBuffer = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 594 pTuningSettingsPointer);
mjarvisal 0:e6fcdb78a136 595 else
mjarvisal 0:e6fcdb78a136 596 pTuningSettingBuffer = DefaultTuningSettings;
mjarvisal 0:e6fcdb78a136 597
mjarvisal 0:e6fcdb78a136 598 }
mjarvisal 0:e6fcdb78a136 599
mjarvisal 0:e6fcdb78a136 600 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 601 Status = VL53L0X_load_tuning_settings(Dev, pTuningSettingBuffer);
mjarvisal 0:e6fcdb78a136 602
mjarvisal 0:e6fcdb78a136 603
mjarvisal 0:e6fcdb78a136 604 /* Set interrupt config to new sample ready */
mjarvisal 0:e6fcdb78a136 605 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 606 Status = VL53L0X_SetGpioConfig(Dev, 0, 0,
mjarvisal 0:e6fcdb78a136 607 VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY,
mjarvisal 0:e6fcdb78a136 608 VL53L0X_INTERRUPTPOLARITY_LOW);
mjarvisal 0:e6fcdb78a136 609 }
mjarvisal 0:e6fcdb78a136 610
mjarvisal 0:e6fcdb78a136 611 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 612 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 613 Status |= VL53L0X_RdWord(Dev, 0x84, &tempword);
mjarvisal 0:e6fcdb78a136 614 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 615 }
mjarvisal 0:e6fcdb78a136 616
mjarvisal 0:e6fcdb78a136 617 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 618 VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, OscFrequencyMHz,
mjarvisal 0:e6fcdb78a136 619 VL53L0X_FIXPOINT412TOFIXPOINT1616(tempword));
mjarvisal 0:e6fcdb78a136 620 }
mjarvisal 0:e6fcdb78a136 621
mjarvisal 0:e6fcdb78a136 622 /* After static init, some device parameters may be changed,
mjarvisal 0:e6fcdb78a136 623 * so update them */
mjarvisal 0:e6fcdb78a136 624 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 625 Status = VL53L0X_GetDeviceParameters(Dev, &CurrentParameters);
mjarvisal 0:e6fcdb78a136 626
mjarvisal 0:e6fcdb78a136 627
mjarvisal 0:e6fcdb78a136 628 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 629 Status = VL53L0X_GetFractionEnable(Dev, &tempbyte);
mjarvisal 0:e6fcdb78a136 630 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 631 PALDevDataSet(Dev, RangeFractionalEnable, tempbyte);
mjarvisal 0:e6fcdb78a136 632
mjarvisal 0:e6fcdb78a136 633 }
mjarvisal 0:e6fcdb78a136 634
mjarvisal 0:e6fcdb78a136 635 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 636 PALDevDataSet(Dev, CurrentParameters, CurrentParameters);
mjarvisal 0:e6fcdb78a136 637
mjarvisal 0:e6fcdb78a136 638
mjarvisal 0:e6fcdb78a136 639 /* read the sequence config and save it */
mjarvisal 0:e6fcdb78a136 640 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 641 Status = VL53L0X_RdByte(Dev,
mjarvisal 0:e6fcdb78a136 642 VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &tempbyte);
mjarvisal 0:e6fcdb78a136 643 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 644 PALDevDataSet(Dev, SequenceConfig, tempbyte);
mjarvisal 0:e6fcdb78a136 645
mjarvisal 0:e6fcdb78a136 646 }
mjarvisal 0:e6fcdb78a136 647
mjarvisal 0:e6fcdb78a136 648 /* Disable MSRC and TCC by default */
mjarvisal 0:e6fcdb78a136 649 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 650 Status = VL53L0X_SetSequenceStepEnable(Dev,
mjarvisal 0:e6fcdb78a136 651 VL53L0X_SEQUENCESTEP_TCC, 0);
mjarvisal 0:e6fcdb78a136 652
mjarvisal 0:e6fcdb78a136 653
mjarvisal 0:e6fcdb78a136 654 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 655 Status = VL53L0X_SetSequenceStepEnable(Dev,
mjarvisal 0:e6fcdb78a136 656 VL53L0X_SEQUENCESTEP_MSRC, 0);
mjarvisal 0:e6fcdb78a136 657
mjarvisal 0:e6fcdb78a136 658
mjarvisal 0:e6fcdb78a136 659 /* Set PAL State to standby */
mjarvisal 0:e6fcdb78a136 660 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 661 PALDevDataSet(Dev, PalState, VL53L0X_STATE_IDLE);
mjarvisal 0:e6fcdb78a136 662
mjarvisal 0:e6fcdb78a136 663
mjarvisal 0:e6fcdb78a136 664
mjarvisal 0:e6fcdb78a136 665 /* Store pre-range vcsel period */
mjarvisal 0:e6fcdb78a136 666 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 667 Status = VL53L0X_GetVcselPulsePeriod(
mjarvisal 0:e6fcdb78a136 668 Dev,
mjarvisal 0:e6fcdb78a136 669 VL53L0X_VCSEL_PERIOD_PRE_RANGE,
mjarvisal 0:e6fcdb78a136 670 &vcselPulsePeriodPCLK);
mjarvisal 0:e6fcdb78a136 671 }
mjarvisal 0:e6fcdb78a136 672
mjarvisal 0:e6fcdb78a136 673 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 674 VL53L0X_SETDEVICESPECIFICPARAMETER(
mjarvisal 0:e6fcdb78a136 675 Dev,
mjarvisal 0:e6fcdb78a136 676 PreRangeVcselPulsePeriod,
mjarvisal 0:e6fcdb78a136 677 vcselPulsePeriodPCLK);
mjarvisal 0:e6fcdb78a136 678 }
mjarvisal 0:e6fcdb78a136 679
mjarvisal 0:e6fcdb78a136 680 /* Store final-range vcsel period */
mjarvisal 0:e6fcdb78a136 681 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 682 Status = VL53L0X_GetVcselPulsePeriod(
mjarvisal 0:e6fcdb78a136 683 Dev,
mjarvisal 0:e6fcdb78a136 684 VL53L0X_VCSEL_PERIOD_FINAL_RANGE,
mjarvisal 0:e6fcdb78a136 685 &vcselPulsePeriodPCLK);
mjarvisal 0:e6fcdb78a136 686 }
mjarvisal 0:e6fcdb78a136 687
mjarvisal 0:e6fcdb78a136 688 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 689 VL53L0X_SETDEVICESPECIFICPARAMETER(
mjarvisal 0:e6fcdb78a136 690 Dev,
mjarvisal 0:e6fcdb78a136 691 FinalRangeVcselPulsePeriod,
mjarvisal 0:e6fcdb78a136 692 vcselPulsePeriodPCLK);
mjarvisal 0:e6fcdb78a136 693 }
mjarvisal 0:e6fcdb78a136 694
mjarvisal 0:e6fcdb78a136 695 /* Store pre-range timeout */
mjarvisal 0:e6fcdb78a136 696 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 697 Status = VL53L0X_GetSequenceStepTimeout(
mjarvisal 0:e6fcdb78a136 698 Dev,
mjarvisal 0:e6fcdb78a136 699 VL53L0X_SEQUENCESTEP_PRE_RANGE,
mjarvisal 0:e6fcdb78a136 700 &seqTimeoutMilliSecs);
mjarvisal 0:e6fcdb78a136 701 }
mjarvisal 0:e6fcdb78a136 702
mjarvisal 0:e6fcdb78a136 703 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 704 VL53L0X_SETDEVICESPECIFICPARAMETER(
mjarvisal 0:e6fcdb78a136 705 Dev,
mjarvisal 0:e6fcdb78a136 706 PreRangeTimeoutMicroSecs,
mjarvisal 0:e6fcdb78a136 707 seqTimeoutMilliSecs);
mjarvisal 0:e6fcdb78a136 708 }
mjarvisal 0:e6fcdb78a136 709
mjarvisal 0:e6fcdb78a136 710 /* Store final-range timeout */
mjarvisal 0:e6fcdb78a136 711 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 712 Status = VL53L0X_GetSequenceStepTimeout(
mjarvisal 0:e6fcdb78a136 713 Dev,
mjarvisal 0:e6fcdb78a136 714 VL53L0X_SEQUENCESTEP_FINAL_RANGE,
mjarvisal 0:e6fcdb78a136 715 &seqTimeoutMilliSecs);
mjarvisal 0:e6fcdb78a136 716 }
mjarvisal 0:e6fcdb78a136 717
mjarvisal 0:e6fcdb78a136 718 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 719 VL53L0X_SETDEVICESPECIFICPARAMETER(
mjarvisal 0:e6fcdb78a136 720 Dev,
mjarvisal 0:e6fcdb78a136 721 FinalRangeTimeoutMicroSecs,
mjarvisal 0:e6fcdb78a136 722 seqTimeoutMilliSecs);
mjarvisal 0:e6fcdb78a136 723 }
mjarvisal 0:e6fcdb78a136 724
mjarvisal 0:e6fcdb78a136 725 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 726 return Status;
mjarvisal 0:e6fcdb78a136 727 }
mjarvisal 0:e6fcdb78a136 728
mjarvisal 0:e6fcdb78a136 729 VL53L0X_Error VL53L0X_WaitDeviceBooted(VL53L0X_DEV Dev)
mjarvisal 0:e6fcdb78a136 730 {
mjarvisal 0:e6fcdb78a136 731 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 732 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 733
mjarvisal 0:e6fcdb78a136 734 /* not implemented on VL53L0X */
mjarvisal 0:e6fcdb78a136 735
mjarvisal 0:e6fcdb78a136 736 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 737 return Status;
mjarvisal 0:e6fcdb78a136 738 }
mjarvisal 0:e6fcdb78a136 739
mjarvisal 0:e6fcdb78a136 740 VL53L0X_Error VL53L0X_ResetDevice(VL53L0X_DEV Dev)
mjarvisal 0:e6fcdb78a136 741 {
mjarvisal 0:e6fcdb78a136 742 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 743 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 744 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 745
mjarvisal 0:e6fcdb78a136 746 /* Set reset bit */
mjarvisal 0:e6fcdb78a136 747 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SOFT_RESET_GO2_SOFT_RESET_N,
mjarvisal 0:e6fcdb78a136 748 0x00);
mjarvisal 0:e6fcdb78a136 749
mjarvisal 0:e6fcdb78a136 750 /* Wait for some time */
mjarvisal 0:e6fcdb78a136 751 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 752 do {
mjarvisal 0:e6fcdb78a136 753 Status = VL53L0X_RdByte(Dev,
mjarvisal 0:e6fcdb78a136 754 VL53L0X_REG_IDENTIFICATION_MODEL_ID, &Byte);
mjarvisal 0:e6fcdb78a136 755 } while (Byte != 0x00);
mjarvisal 0:e6fcdb78a136 756 }
mjarvisal 0:e6fcdb78a136 757
mjarvisal 0:e6fcdb78a136 758 /* Release reset */
mjarvisal 0:e6fcdb78a136 759 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SOFT_RESET_GO2_SOFT_RESET_N,
mjarvisal 0:e6fcdb78a136 760 0x01);
mjarvisal 0:e6fcdb78a136 761
mjarvisal 0:e6fcdb78a136 762 /* Wait until correct boot-up of the device */
mjarvisal 0:e6fcdb78a136 763 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 764 do {
mjarvisal 0:e6fcdb78a136 765 Status = VL53L0X_RdByte(Dev,
mjarvisal 0:e6fcdb78a136 766 VL53L0X_REG_IDENTIFICATION_MODEL_ID, &Byte);
mjarvisal 0:e6fcdb78a136 767 } while (Byte == 0x00);
mjarvisal 0:e6fcdb78a136 768 }
mjarvisal 0:e6fcdb78a136 769
mjarvisal 0:e6fcdb78a136 770 /* Set PAL State to VL53L0X_STATE_POWERDOWN */
mjarvisal 0:e6fcdb78a136 771 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 772 PALDevDataSet(Dev, PalState, VL53L0X_STATE_POWERDOWN);
mjarvisal 0:e6fcdb78a136 773
mjarvisal 0:e6fcdb78a136 774
mjarvisal 0:e6fcdb78a136 775 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 776 return Status;
mjarvisal 0:e6fcdb78a136 777 }
mjarvisal 0:e6fcdb78a136 778 /* End Group PAL Init Functions */
mjarvisal 0:e6fcdb78a136 779
mjarvisal 0:e6fcdb78a136 780 /* Group PAL Parameters Functions */
mjarvisal 0:e6fcdb78a136 781 VL53L0X_Error VL53L0X_SetDeviceParameters(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 782 const VL53L0X_DeviceParameters_t *pDeviceParameters)
mjarvisal 0:e6fcdb78a136 783 {
mjarvisal 0:e6fcdb78a136 784 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 785 int i;
mjarvisal 0:e6fcdb78a136 786 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 787 Status = VL53L0X_SetDeviceMode(Dev, pDeviceParameters->DeviceMode);
mjarvisal 0:e6fcdb78a136 788
mjarvisal 0:e6fcdb78a136 789 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 790 Status = VL53L0X_SetInterMeasurementPeriodMilliSeconds(Dev,
mjarvisal 0:e6fcdb78a136 791 pDeviceParameters->InterMeasurementPeriodMilliSeconds);
mjarvisal 0:e6fcdb78a136 792
mjarvisal 0:e6fcdb78a136 793
mjarvisal 0:e6fcdb78a136 794 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 795 Status = VL53L0X_SetXTalkCompensationRateMegaCps(Dev,
mjarvisal 0:e6fcdb78a136 796 pDeviceParameters->XTalkCompensationRateMegaCps);
mjarvisal 0:e6fcdb78a136 797
mjarvisal 0:e6fcdb78a136 798
mjarvisal 0:e6fcdb78a136 799 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 800 Status = VL53L0X_SetOffsetCalibrationDataMicroMeter(Dev,
mjarvisal 0:e6fcdb78a136 801 pDeviceParameters->RangeOffsetMicroMeters);
mjarvisal 0:e6fcdb78a136 802
mjarvisal 0:e6fcdb78a136 803
mjarvisal 0:e6fcdb78a136 804 for (i = 0; i < VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
mjarvisal 0:e6fcdb78a136 805 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 806 Status |= VL53L0X_SetLimitCheckEnable(Dev, i,
mjarvisal 0:e6fcdb78a136 807 pDeviceParameters->LimitChecksEnable[i]);
mjarvisal 0:e6fcdb78a136 808 else
mjarvisal 0:e6fcdb78a136 809 break;
mjarvisal 0:e6fcdb78a136 810
mjarvisal 0:e6fcdb78a136 811 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 812 Status |= VL53L0X_SetLimitCheckValue(Dev, i,
mjarvisal 0:e6fcdb78a136 813 pDeviceParameters->LimitChecksValue[i]);
mjarvisal 0:e6fcdb78a136 814 else
mjarvisal 0:e6fcdb78a136 815 break;
mjarvisal 0:e6fcdb78a136 816
mjarvisal 0:e6fcdb78a136 817 }
mjarvisal 0:e6fcdb78a136 818
mjarvisal 0:e6fcdb78a136 819 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 820 Status = VL53L0X_SetWrapAroundCheckEnable(Dev,
mjarvisal 0:e6fcdb78a136 821 pDeviceParameters->WrapAroundCheckEnable);
mjarvisal 0:e6fcdb78a136 822
mjarvisal 0:e6fcdb78a136 823 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 824 Status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev,
mjarvisal 0:e6fcdb78a136 825 pDeviceParameters->MeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 826
mjarvisal 0:e6fcdb78a136 827
mjarvisal 0:e6fcdb78a136 828 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 829 return Status;
mjarvisal 0:e6fcdb78a136 830 }
mjarvisal 0:e6fcdb78a136 831
mjarvisal 0:e6fcdb78a136 832 VL53L0X_Error VL53L0X_GetDeviceParameters(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 833 VL53L0X_DeviceParameters_t *pDeviceParameters)
mjarvisal 0:e6fcdb78a136 834 {
mjarvisal 0:e6fcdb78a136 835 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 836 int i;
mjarvisal 0:e6fcdb78a136 837
mjarvisal 0:e6fcdb78a136 838 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 839
mjarvisal 0:e6fcdb78a136 840 Status = VL53L0X_GetDeviceMode(Dev, &(pDeviceParameters->DeviceMode));
mjarvisal 0:e6fcdb78a136 841
mjarvisal 0:e6fcdb78a136 842 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 843 Status = VL53L0X_GetInterMeasurementPeriodMilliSeconds(Dev,
mjarvisal 0:e6fcdb78a136 844 &(pDeviceParameters->InterMeasurementPeriodMilliSeconds));
mjarvisal 0:e6fcdb78a136 845
mjarvisal 0:e6fcdb78a136 846
mjarvisal 0:e6fcdb78a136 847 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 848 pDeviceParameters->XTalkCompensationEnable = 0;
mjarvisal 0:e6fcdb78a136 849
mjarvisal 0:e6fcdb78a136 850 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 851 Status = VL53L0X_GetXTalkCompensationRateMegaCps(Dev,
mjarvisal 0:e6fcdb78a136 852 &(pDeviceParameters->XTalkCompensationRateMegaCps));
mjarvisal 0:e6fcdb78a136 853
mjarvisal 0:e6fcdb78a136 854
mjarvisal 0:e6fcdb78a136 855 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 856 Status = VL53L0X_GetOffsetCalibrationDataMicroMeter(Dev,
mjarvisal 0:e6fcdb78a136 857 &(pDeviceParameters->RangeOffsetMicroMeters));
mjarvisal 0:e6fcdb78a136 858
mjarvisal 0:e6fcdb78a136 859
mjarvisal 0:e6fcdb78a136 860 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 861 for (i = 0; i < VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS; i++) {
mjarvisal 0:e6fcdb78a136 862 /* get first the values, then the enables.
mjarvisal 0:e6fcdb78a136 863 * VL53L0X_GetLimitCheckValue will modify the enable
mjarvisal 0:e6fcdb78a136 864 * flags
mjarvisal 0:e6fcdb78a136 865 */
mjarvisal 0:e6fcdb78a136 866 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 867 Status |= VL53L0X_GetLimitCheckValue(Dev, i,
mjarvisal 0:e6fcdb78a136 868 &(pDeviceParameters->LimitChecksValue[i]));
mjarvisal 0:e6fcdb78a136 869 } else {
mjarvisal 0:e6fcdb78a136 870 break;
mjarvisal 0:e6fcdb78a136 871 }
mjarvisal 0:e6fcdb78a136 872 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 873 Status |= VL53L0X_GetLimitCheckEnable(Dev, i,
mjarvisal 0:e6fcdb78a136 874 &(pDeviceParameters->LimitChecksEnable[i]));
mjarvisal 0:e6fcdb78a136 875 } else {
mjarvisal 0:e6fcdb78a136 876 break;
mjarvisal 0:e6fcdb78a136 877 }
mjarvisal 0:e6fcdb78a136 878 }
mjarvisal 0:e6fcdb78a136 879 }
mjarvisal 0:e6fcdb78a136 880
mjarvisal 0:e6fcdb78a136 881 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 882 Status = VL53L0X_GetWrapAroundCheckEnable(Dev,
mjarvisal 0:e6fcdb78a136 883 &(pDeviceParameters->WrapAroundCheckEnable));
mjarvisal 0:e6fcdb78a136 884 }
mjarvisal 0:e6fcdb78a136 885
mjarvisal 0:e6fcdb78a136 886 /* Need to be done at the end as it uses VCSELPulsePeriod */
mjarvisal 0:e6fcdb78a136 887 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 888 Status = VL53L0X_GetMeasurementTimingBudgetMicroSeconds(Dev,
mjarvisal 0:e6fcdb78a136 889 &(pDeviceParameters->MeasurementTimingBudgetMicroSeconds));
mjarvisal 0:e6fcdb78a136 890 }
mjarvisal 0:e6fcdb78a136 891
mjarvisal 0:e6fcdb78a136 892 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 893 return Status;
mjarvisal 0:e6fcdb78a136 894 }
mjarvisal 0:e6fcdb78a136 895
mjarvisal 0:e6fcdb78a136 896 VL53L0X_Error VL53L0X_SetDeviceMode(VL53L0X_DEV Dev, VL53L0X_DeviceModes DeviceMode)
mjarvisal 0:e6fcdb78a136 897 {
mjarvisal 0:e6fcdb78a136 898 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 899
mjarvisal 0:e6fcdb78a136 900 LOG_FUNCTION_START("%d", (int)DeviceMode);
mjarvisal 0:e6fcdb78a136 901
mjarvisal 0:e6fcdb78a136 902 switch (DeviceMode) {
mjarvisal 0:e6fcdb78a136 903 case VL53L0X_DEVICEMODE_SINGLE_RANGING:
mjarvisal 0:e6fcdb78a136 904 case VL53L0X_DEVICEMODE_CONTINUOUS_RANGING:
mjarvisal 0:e6fcdb78a136 905 case VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
mjarvisal 0:e6fcdb78a136 906 case VL53L0X_DEVICEMODE_GPIO_DRIVE:
mjarvisal 0:e6fcdb78a136 907 case VL53L0X_DEVICEMODE_GPIO_OSC:
mjarvisal 0:e6fcdb78a136 908 /* Supported modes */
mjarvisal 0:e6fcdb78a136 909 VL53L0X_SETPARAMETERFIELD(Dev, DeviceMode, DeviceMode);
mjarvisal 0:e6fcdb78a136 910 break;
mjarvisal 0:e6fcdb78a136 911 default:
mjarvisal 0:e6fcdb78a136 912 /* Unsupported mode */
mjarvisal 0:e6fcdb78a136 913 Status = VL53L0X_ERROR_MODE_NOT_SUPPORTED;
mjarvisal 0:e6fcdb78a136 914 }
mjarvisal 0:e6fcdb78a136 915
mjarvisal 0:e6fcdb78a136 916 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 917 return Status;
mjarvisal 0:e6fcdb78a136 918 }
mjarvisal 0:e6fcdb78a136 919
mjarvisal 0:e6fcdb78a136 920 VL53L0X_Error VL53L0X_GetDeviceMode(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 921 VL53L0X_DeviceModes *pDeviceMode)
mjarvisal 0:e6fcdb78a136 922 {
mjarvisal 0:e6fcdb78a136 923 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 924 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 925
mjarvisal 0:e6fcdb78a136 926 VL53L0X_GETPARAMETERFIELD(Dev, DeviceMode, *pDeviceMode);
mjarvisal 0:e6fcdb78a136 927
mjarvisal 0:e6fcdb78a136 928 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 929 return Status;
mjarvisal 0:e6fcdb78a136 930 }
mjarvisal 0:e6fcdb78a136 931
mjarvisal 0:e6fcdb78a136 932 VL53L0X_Error VL53L0X_SetRangeFractionEnable(VL53L0X_DEV Dev, uint8_t Enable)
mjarvisal 0:e6fcdb78a136 933 {
mjarvisal 0:e6fcdb78a136 934 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 935
mjarvisal 0:e6fcdb78a136 936 LOG_FUNCTION_START("%d", (int)Enable);
mjarvisal 0:e6fcdb78a136 937
mjarvisal 0:e6fcdb78a136 938 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_RANGE_CONFIG, Enable);
mjarvisal 0:e6fcdb78a136 939
mjarvisal 0:e6fcdb78a136 940 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 941 PALDevDataSet(Dev, RangeFractionalEnable, Enable);
mjarvisal 0:e6fcdb78a136 942
mjarvisal 0:e6fcdb78a136 943 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 944 return Status;
mjarvisal 0:e6fcdb78a136 945 }
mjarvisal 0:e6fcdb78a136 946
mjarvisal 0:e6fcdb78a136 947 VL53L0X_Error VL53L0X_GetFractionEnable(VL53L0X_DEV Dev, uint8_t *pEnabled)
mjarvisal 0:e6fcdb78a136 948 {
mjarvisal 0:e6fcdb78a136 949 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 950 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 951
mjarvisal 0:e6fcdb78a136 952 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_RANGE_CONFIG, pEnabled);
mjarvisal 0:e6fcdb78a136 953
mjarvisal 0:e6fcdb78a136 954 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 955 *pEnabled = (*pEnabled & 1);
mjarvisal 0:e6fcdb78a136 956
mjarvisal 0:e6fcdb78a136 957 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 958 return Status;
mjarvisal 0:e6fcdb78a136 959 }
mjarvisal 0:e6fcdb78a136 960
mjarvisal 0:e6fcdb78a136 961 VL53L0X_Error VL53L0X_SetHistogramMode(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 962 VL53L0X_HistogramModes HistogramMode)
mjarvisal 0:e6fcdb78a136 963 {
mjarvisal 0:e6fcdb78a136 964 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 965 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 966
mjarvisal 0:e6fcdb78a136 967 /* not implemented on VL53L0X */
mjarvisal 0:e6fcdb78a136 968
mjarvisal 0:e6fcdb78a136 969 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 970 return Status;
mjarvisal 0:e6fcdb78a136 971 }
mjarvisal 0:e6fcdb78a136 972
mjarvisal 0:e6fcdb78a136 973 VL53L0X_Error VL53L0X_GetHistogramMode(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 974 VL53L0X_HistogramModes *pHistogramMode)
mjarvisal 0:e6fcdb78a136 975 {
mjarvisal 0:e6fcdb78a136 976 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 977 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 978
mjarvisal 0:e6fcdb78a136 979 /* not implemented on VL53L0X */
mjarvisal 0:e6fcdb78a136 980
mjarvisal 0:e6fcdb78a136 981 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 982 return Status;
mjarvisal 0:e6fcdb78a136 983 }
mjarvisal 0:e6fcdb78a136 984
mjarvisal 0:e6fcdb78a136 985 VL53L0X_Error VL53L0X_SetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 986 uint32_t MeasurementTimingBudgetMicroSeconds)
mjarvisal 0:e6fcdb78a136 987 {
mjarvisal 0:e6fcdb78a136 988 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 989 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 990
mjarvisal 0:e6fcdb78a136 991 Status = VL53L0X_set_measurement_timing_budget_micro_seconds(Dev,
mjarvisal 0:e6fcdb78a136 992 MeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 993
mjarvisal 0:e6fcdb78a136 994 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 995
mjarvisal 0:e6fcdb78a136 996 return Status;
mjarvisal 0:e6fcdb78a136 997 }
mjarvisal 0:e6fcdb78a136 998
mjarvisal 0:e6fcdb78a136 999 VL53L0X_Error VL53L0X_GetMeasurementTimingBudgetMicroSeconds(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1000 uint32_t *pMeasurementTimingBudgetMicroSeconds)
mjarvisal 0:e6fcdb78a136 1001 {
mjarvisal 0:e6fcdb78a136 1002 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1003 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1004
mjarvisal 0:e6fcdb78a136 1005 Status = VL53L0X_get_measurement_timing_budget_micro_seconds(Dev,
mjarvisal 0:e6fcdb78a136 1006 pMeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 1007
mjarvisal 0:e6fcdb78a136 1008 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1009 return Status;
mjarvisal 0:e6fcdb78a136 1010 }
mjarvisal 0:e6fcdb78a136 1011
mjarvisal 0:e6fcdb78a136 1012 VL53L0X_Error VL53L0X_SetVcselPulsePeriod(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1013 VL53L0X_VcselPeriod VcselPeriodType, uint8_t VCSELPulsePeriodPCLK)
mjarvisal 0:e6fcdb78a136 1014 {
mjarvisal 0:e6fcdb78a136 1015 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1016 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1017
mjarvisal 0:e6fcdb78a136 1018 Status = VL53L0X_set_vcsel_pulse_period(Dev, VcselPeriodType,
mjarvisal 0:e6fcdb78a136 1019 VCSELPulsePeriodPCLK);
mjarvisal 0:e6fcdb78a136 1020
mjarvisal 0:e6fcdb78a136 1021 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1022 return Status;
mjarvisal 0:e6fcdb78a136 1023 }
mjarvisal 0:e6fcdb78a136 1024
mjarvisal 0:e6fcdb78a136 1025 VL53L0X_Error VL53L0X_GetVcselPulsePeriod(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1026 VL53L0X_VcselPeriod VcselPeriodType, uint8_t *pVCSELPulsePeriodPCLK)
mjarvisal 0:e6fcdb78a136 1027 {
mjarvisal 0:e6fcdb78a136 1028 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1029 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1030
mjarvisal 0:e6fcdb78a136 1031 Status = VL53L0X_get_vcsel_pulse_period(Dev, VcselPeriodType,
mjarvisal 0:e6fcdb78a136 1032 pVCSELPulsePeriodPCLK);
mjarvisal 0:e6fcdb78a136 1033
mjarvisal 0:e6fcdb78a136 1034 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1035 return Status;
mjarvisal 0:e6fcdb78a136 1036 }
mjarvisal 0:e6fcdb78a136 1037
mjarvisal 0:e6fcdb78a136 1038 VL53L0X_Error VL53L0X_SetSequenceStepEnable(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1039 VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceStepEnabled)
mjarvisal 0:e6fcdb78a136 1040 {
mjarvisal 0:e6fcdb78a136 1041 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1042 uint8_t SequenceConfig = 0;
mjarvisal 0:e6fcdb78a136 1043 uint8_t SequenceConfigNew = 0;
mjarvisal 0:e6fcdb78a136 1044 uint32_t MeasurementTimingBudgetMicroSeconds;
mjarvisal 0:e6fcdb78a136 1045 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1046
mjarvisal 0:e6fcdb78a136 1047 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
mjarvisal 0:e6fcdb78a136 1048 &SequenceConfig);
mjarvisal 0:e6fcdb78a136 1049
mjarvisal 0:e6fcdb78a136 1050 SequenceConfigNew = SequenceConfig;
mjarvisal 0:e6fcdb78a136 1051
mjarvisal 0:e6fcdb78a136 1052 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1053 if (SequenceStepEnabled == 1) {
mjarvisal 0:e6fcdb78a136 1054
mjarvisal 0:e6fcdb78a136 1055 /* Enable requested sequence step
mjarvisal 0:e6fcdb78a136 1056 */
mjarvisal 0:e6fcdb78a136 1057 switch (SequenceStepId) {
mjarvisal 0:e6fcdb78a136 1058 case VL53L0X_SEQUENCESTEP_TCC:
mjarvisal 0:e6fcdb78a136 1059 SequenceConfigNew |= 0x10;
mjarvisal 0:e6fcdb78a136 1060 break;
mjarvisal 0:e6fcdb78a136 1061 case VL53L0X_SEQUENCESTEP_DSS:
mjarvisal 0:e6fcdb78a136 1062 SequenceConfigNew |= 0x28;
mjarvisal 0:e6fcdb78a136 1063 break;
mjarvisal 0:e6fcdb78a136 1064 case VL53L0X_SEQUENCESTEP_MSRC:
mjarvisal 0:e6fcdb78a136 1065 SequenceConfigNew |= 0x04;
mjarvisal 0:e6fcdb78a136 1066 break;
mjarvisal 0:e6fcdb78a136 1067 case VL53L0X_SEQUENCESTEP_PRE_RANGE:
mjarvisal 0:e6fcdb78a136 1068 SequenceConfigNew |= 0x40;
mjarvisal 0:e6fcdb78a136 1069 break;
mjarvisal 0:e6fcdb78a136 1070 case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1071 SequenceConfigNew |= 0x80;
mjarvisal 0:e6fcdb78a136 1072 break;
mjarvisal 0:e6fcdb78a136 1073 default:
mjarvisal 0:e6fcdb78a136 1074 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1075 }
mjarvisal 0:e6fcdb78a136 1076 } else {
mjarvisal 0:e6fcdb78a136 1077 /* Disable requested sequence step
mjarvisal 0:e6fcdb78a136 1078 */
mjarvisal 0:e6fcdb78a136 1079 switch (SequenceStepId) {
mjarvisal 0:e6fcdb78a136 1080 case VL53L0X_SEQUENCESTEP_TCC:
mjarvisal 0:e6fcdb78a136 1081 SequenceConfigNew &= 0xef;
mjarvisal 0:e6fcdb78a136 1082 break;
mjarvisal 0:e6fcdb78a136 1083 case VL53L0X_SEQUENCESTEP_DSS:
mjarvisal 0:e6fcdb78a136 1084 SequenceConfigNew &= 0xd7;
mjarvisal 0:e6fcdb78a136 1085 break;
mjarvisal 0:e6fcdb78a136 1086 case VL53L0X_SEQUENCESTEP_MSRC:
mjarvisal 0:e6fcdb78a136 1087 SequenceConfigNew &= 0xfb;
mjarvisal 0:e6fcdb78a136 1088 break;
mjarvisal 0:e6fcdb78a136 1089 case VL53L0X_SEQUENCESTEP_PRE_RANGE:
mjarvisal 0:e6fcdb78a136 1090 SequenceConfigNew &= 0xbf;
mjarvisal 0:e6fcdb78a136 1091 break;
mjarvisal 0:e6fcdb78a136 1092 case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1093 SequenceConfigNew &= 0x7f;
mjarvisal 0:e6fcdb78a136 1094 break;
mjarvisal 0:e6fcdb78a136 1095 default:
mjarvisal 0:e6fcdb78a136 1096 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1097 }
mjarvisal 0:e6fcdb78a136 1098 }
mjarvisal 0:e6fcdb78a136 1099 }
mjarvisal 0:e6fcdb78a136 1100
mjarvisal 0:e6fcdb78a136 1101 if (SequenceConfigNew != SequenceConfig) {
mjarvisal 0:e6fcdb78a136 1102 /* Apply New Setting */
mjarvisal 0:e6fcdb78a136 1103 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1104 Status = VL53L0X_WrByte(Dev,
mjarvisal 0:e6fcdb78a136 1105 VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, SequenceConfigNew);
mjarvisal 0:e6fcdb78a136 1106 }
mjarvisal 0:e6fcdb78a136 1107 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 1108 PALDevDataSet(Dev, SequenceConfig, SequenceConfigNew);
mjarvisal 0:e6fcdb78a136 1109
mjarvisal 0:e6fcdb78a136 1110
mjarvisal 0:e6fcdb78a136 1111 /* Recalculate timing budget */
mjarvisal 0:e6fcdb78a136 1112 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1113 VL53L0X_GETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1114 MeasurementTimingBudgetMicroSeconds,
mjarvisal 0:e6fcdb78a136 1115 MeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 1116
mjarvisal 0:e6fcdb78a136 1117 VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev,
mjarvisal 0:e6fcdb78a136 1118 MeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 1119 }
mjarvisal 0:e6fcdb78a136 1120 }
mjarvisal 0:e6fcdb78a136 1121
mjarvisal 0:e6fcdb78a136 1122 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1123
mjarvisal 0:e6fcdb78a136 1124 return Status;
mjarvisal 0:e6fcdb78a136 1125 }
mjarvisal 0:e6fcdb78a136 1126
mjarvisal 0:e6fcdb78a136 1127 VL53L0X_Error sequence_step_enabled(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1128 VL53L0X_SequenceStepId SequenceStepId, uint8_t SequenceConfig,
mjarvisal 0:e6fcdb78a136 1129 uint8_t *pSequenceStepEnabled)
mjarvisal 0:e6fcdb78a136 1130 {
mjarvisal 0:e6fcdb78a136 1131 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1132 *pSequenceStepEnabled = 0;
mjarvisal 0:e6fcdb78a136 1133 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1134
mjarvisal 0:e6fcdb78a136 1135 switch (SequenceStepId) {
mjarvisal 0:e6fcdb78a136 1136 case VL53L0X_SEQUENCESTEP_TCC:
mjarvisal 0:e6fcdb78a136 1137 *pSequenceStepEnabled = (SequenceConfig & 0x10) >> 4;
mjarvisal 0:e6fcdb78a136 1138 break;
mjarvisal 0:e6fcdb78a136 1139 case VL53L0X_SEQUENCESTEP_DSS:
mjarvisal 0:e6fcdb78a136 1140 *pSequenceStepEnabled = (SequenceConfig & 0x08) >> 3;
mjarvisal 0:e6fcdb78a136 1141 break;
mjarvisal 0:e6fcdb78a136 1142 case VL53L0X_SEQUENCESTEP_MSRC:
mjarvisal 0:e6fcdb78a136 1143 *pSequenceStepEnabled = (SequenceConfig & 0x04) >> 2;
mjarvisal 0:e6fcdb78a136 1144 break;
mjarvisal 0:e6fcdb78a136 1145 case VL53L0X_SEQUENCESTEP_PRE_RANGE:
mjarvisal 0:e6fcdb78a136 1146 *pSequenceStepEnabled = (SequenceConfig & 0x40) >> 6;
mjarvisal 0:e6fcdb78a136 1147 break;
mjarvisal 0:e6fcdb78a136 1148 case VL53L0X_SEQUENCESTEP_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1149 *pSequenceStepEnabled = (SequenceConfig & 0x80) >> 7;
mjarvisal 0:e6fcdb78a136 1150 break;
mjarvisal 0:e6fcdb78a136 1151 default:
mjarvisal 0:e6fcdb78a136 1152 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1153 }
mjarvisal 0:e6fcdb78a136 1154
mjarvisal 0:e6fcdb78a136 1155 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1156 return Status;
mjarvisal 0:e6fcdb78a136 1157 }
mjarvisal 0:e6fcdb78a136 1158
mjarvisal 0:e6fcdb78a136 1159 VL53L0X_Error VL53L0X_GetSequenceStepEnable(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1160 VL53L0X_SequenceStepId SequenceStepId, uint8_t *pSequenceStepEnabled)
mjarvisal 0:e6fcdb78a136 1161 {
mjarvisal 0:e6fcdb78a136 1162 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1163 uint8_t SequenceConfig = 0;
mjarvisal 0:e6fcdb78a136 1164 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1165
mjarvisal 0:e6fcdb78a136 1166 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
mjarvisal 0:e6fcdb78a136 1167 &SequenceConfig);
mjarvisal 0:e6fcdb78a136 1168
mjarvisal 0:e6fcdb78a136 1169 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1170 Status = sequence_step_enabled(Dev, SequenceStepId,
mjarvisal 0:e6fcdb78a136 1171 SequenceConfig, pSequenceStepEnabled);
mjarvisal 0:e6fcdb78a136 1172 }
mjarvisal 0:e6fcdb78a136 1173
mjarvisal 0:e6fcdb78a136 1174 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1175 return Status;
mjarvisal 0:e6fcdb78a136 1176 }
mjarvisal 0:e6fcdb78a136 1177
mjarvisal 0:e6fcdb78a136 1178 VL53L0X_Error VL53L0X_GetSequenceStepEnables(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1179 VL53L0X_SchedulerSequenceSteps_t *pSchedulerSequenceSteps)
mjarvisal 0:e6fcdb78a136 1180 {
mjarvisal 0:e6fcdb78a136 1181 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1182 uint8_t SequenceConfig = 0;
mjarvisal 0:e6fcdb78a136 1183 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1184
mjarvisal 0:e6fcdb78a136 1185 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG,
mjarvisal 0:e6fcdb78a136 1186 &SequenceConfig);
mjarvisal 0:e6fcdb78a136 1187
mjarvisal 0:e6fcdb78a136 1188 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1189 Status = sequence_step_enabled(Dev,
mjarvisal 0:e6fcdb78a136 1190 VL53L0X_SEQUENCESTEP_TCC, SequenceConfig,
mjarvisal 0:e6fcdb78a136 1191 &pSchedulerSequenceSteps->TccOn);
mjarvisal 0:e6fcdb78a136 1192 }
mjarvisal 0:e6fcdb78a136 1193 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1194 Status = sequence_step_enabled(Dev,
mjarvisal 0:e6fcdb78a136 1195 VL53L0X_SEQUENCESTEP_DSS, SequenceConfig,
mjarvisal 0:e6fcdb78a136 1196 &pSchedulerSequenceSteps->DssOn);
mjarvisal 0:e6fcdb78a136 1197 }
mjarvisal 0:e6fcdb78a136 1198 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1199 Status = sequence_step_enabled(Dev,
mjarvisal 0:e6fcdb78a136 1200 VL53L0X_SEQUENCESTEP_MSRC, SequenceConfig,
mjarvisal 0:e6fcdb78a136 1201 &pSchedulerSequenceSteps->MsrcOn);
mjarvisal 0:e6fcdb78a136 1202 }
mjarvisal 0:e6fcdb78a136 1203 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1204 Status = sequence_step_enabled(Dev,
mjarvisal 0:e6fcdb78a136 1205 VL53L0X_SEQUENCESTEP_PRE_RANGE, SequenceConfig,
mjarvisal 0:e6fcdb78a136 1206 &pSchedulerSequenceSteps->PreRangeOn);
mjarvisal 0:e6fcdb78a136 1207 }
mjarvisal 0:e6fcdb78a136 1208 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1209 Status = sequence_step_enabled(Dev,
mjarvisal 0:e6fcdb78a136 1210 VL53L0X_SEQUENCESTEP_FINAL_RANGE, SequenceConfig,
mjarvisal 0:e6fcdb78a136 1211 &pSchedulerSequenceSteps->FinalRangeOn);
mjarvisal 0:e6fcdb78a136 1212 }
mjarvisal 0:e6fcdb78a136 1213
mjarvisal 0:e6fcdb78a136 1214 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1215 return Status;
mjarvisal 0:e6fcdb78a136 1216 }
mjarvisal 0:e6fcdb78a136 1217
mjarvisal 0:e6fcdb78a136 1218 VL53L0X_Error VL53L0X_GetNumberOfSequenceSteps(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1219 uint8_t *pNumberOfSequenceSteps)
mjarvisal 0:e6fcdb78a136 1220 {
mjarvisal 0:e6fcdb78a136 1221 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1222 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1223
mjarvisal 0:e6fcdb78a136 1224 *pNumberOfSequenceSteps = VL53L0X_SEQUENCESTEP_NUMBER_OF_CHECKS;
mjarvisal 0:e6fcdb78a136 1225
mjarvisal 0:e6fcdb78a136 1226 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1227 return Status;
mjarvisal 0:e6fcdb78a136 1228 }
mjarvisal 0:e6fcdb78a136 1229
mjarvisal 0:e6fcdb78a136 1230 VL53L0X_Error VL53L0X_GetSequenceStepsInfo(VL53L0X_SequenceStepId SequenceStepId,
mjarvisal 0:e6fcdb78a136 1231 char *pSequenceStepsString)
mjarvisal 0:e6fcdb78a136 1232 {
mjarvisal 0:e6fcdb78a136 1233 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1234 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1235
mjarvisal 0:e6fcdb78a136 1236 Status = VL53L0X_get_sequence_steps_info(
mjarvisal 0:e6fcdb78a136 1237 SequenceStepId,
mjarvisal 0:e6fcdb78a136 1238 pSequenceStepsString);
mjarvisal 0:e6fcdb78a136 1239
mjarvisal 0:e6fcdb78a136 1240 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1241
mjarvisal 0:e6fcdb78a136 1242 return Status;
mjarvisal 0:e6fcdb78a136 1243 }
mjarvisal 0:e6fcdb78a136 1244
mjarvisal 0:e6fcdb78a136 1245 VL53L0X_Error VL53L0X_SetSequenceStepTimeout(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1246 VL53L0X_SequenceStepId SequenceStepId, FixPoint1616_t TimeOutMilliSecs)
mjarvisal 0:e6fcdb78a136 1247 {
mjarvisal 0:e6fcdb78a136 1248 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1249 VL53L0X_Error Status1 = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1250 uint32_t TimeoutMicroSeconds = ((TimeOutMilliSecs * 1000) + 0x8000)
mjarvisal 0:e6fcdb78a136 1251 >> 16;
mjarvisal 0:e6fcdb78a136 1252 uint32_t MeasurementTimingBudgetMicroSeconds;
mjarvisal 0:e6fcdb78a136 1253 FixPoint1616_t OldTimeOutMicroSeconds;
mjarvisal 0:e6fcdb78a136 1254
mjarvisal 0:e6fcdb78a136 1255 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1256
mjarvisal 0:e6fcdb78a136 1257 /* Read back the current value in case we need to revert back to this.
mjarvisal 0:e6fcdb78a136 1258 */
mjarvisal 0:e6fcdb78a136 1259 Status = get_sequence_step_timeout(Dev, SequenceStepId,
mjarvisal 0:e6fcdb78a136 1260 &OldTimeOutMicroSeconds);
mjarvisal 0:e6fcdb78a136 1261
mjarvisal 0:e6fcdb78a136 1262 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1263 Status = set_sequence_step_timeout(Dev, SequenceStepId,
mjarvisal 0:e6fcdb78a136 1264 TimeoutMicroSeconds);
mjarvisal 0:e6fcdb78a136 1265 }
mjarvisal 0:e6fcdb78a136 1266
mjarvisal 0:e6fcdb78a136 1267 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1268 VL53L0X_GETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1269 MeasurementTimingBudgetMicroSeconds,
mjarvisal 0:e6fcdb78a136 1270 MeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 1271
mjarvisal 0:e6fcdb78a136 1272 /* At this point we don't know if the requested value is valid,
mjarvisal 0:e6fcdb78a136 1273 therefore proceed to update the entire timing budget and
mjarvisal 0:e6fcdb78a136 1274 if this fails, revert back to the previous value.
mjarvisal 0:e6fcdb78a136 1275 */
mjarvisal 0:e6fcdb78a136 1276 Status = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(Dev,
mjarvisal 0:e6fcdb78a136 1277 MeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 1278
mjarvisal 0:e6fcdb78a136 1279 if (Status != VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1280 Status1 = set_sequence_step_timeout(Dev, SequenceStepId,
mjarvisal 0:e6fcdb78a136 1281 OldTimeOutMicroSeconds);
mjarvisal 0:e6fcdb78a136 1282
mjarvisal 0:e6fcdb78a136 1283 if (Status1 == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1284 Status1 =
mjarvisal 0:e6fcdb78a136 1285 VL53L0X_SetMeasurementTimingBudgetMicroSeconds(
mjarvisal 0:e6fcdb78a136 1286 Dev,
mjarvisal 0:e6fcdb78a136 1287 MeasurementTimingBudgetMicroSeconds);
mjarvisal 0:e6fcdb78a136 1288 }
mjarvisal 0:e6fcdb78a136 1289
mjarvisal 0:e6fcdb78a136 1290 Status = Status1;
mjarvisal 0:e6fcdb78a136 1291 }
mjarvisal 0:e6fcdb78a136 1292 }
mjarvisal 0:e6fcdb78a136 1293
mjarvisal 0:e6fcdb78a136 1294 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1295
mjarvisal 0:e6fcdb78a136 1296 return Status;
mjarvisal 0:e6fcdb78a136 1297 }
mjarvisal 0:e6fcdb78a136 1298
mjarvisal 0:e6fcdb78a136 1299 VL53L0X_Error VL53L0X_GetSequenceStepTimeout(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1300 VL53L0X_SequenceStepId SequenceStepId, FixPoint1616_t *pTimeOutMilliSecs)
mjarvisal 0:e6fcdb78a136 1301 {
mjarvisal 0:e6fcdb78a136 1302 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1303 uint32_t TimeoutMicroSeconds;
mjarvisal 0:e6fcdb78a136 1304 uint32_t WholeNumber_ms = 0;
mjarvisal 0:e6fcdb78a136 1305 uint32_t Fraction_ms = 0;
mjarvisal 0:e6fcdb78a136 1306 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1307
mjarvisal 0:e6fcdb78a136 1308 Status = get_sequence_step_timeout(Dev, SequenceStepId,
mjarvisal 0:e6fcdb78a136 1309 &TimeoutMicroSeconds);
mjarvisal 0:e6fcdb78a136 1310 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1311 WholeNumber_ms = TimeoutMicroSeconds / 1000;
mjarvisal 0:e6fcdb78a136 1312 Fraction_ms = TimeoutMicroSeconds - (WholeNumber_ms * 1000);
mjarvisal 0:e6fcdb78a136 1313 *pTimeOutMilliSecs = (WholeNumber_ms << 16)
mjarvisal 0:e6fcdb78a136 1314 + (((Fraction_ms * 0xffff) + 500) / 1000);
mjarvisal 0:e6fcdb78a136 1315 }
mjarvisal 0:e6fcdb78a136 1316
mjarvisal 0:e6fcdb78a136 1317 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1318 return Status;
mjarvisal 0:e6fcdb78a136 1319 }
mjarvisal 0:e6fcdb78a136 1320
mjarvisal 0:e6fcdb78a136 1321 VL53L0X_Error VL53L0X_SetInterMeasurementPeriodMilliSeconds(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1322 uint32_t InterMeasurementPeriodMilliSeconds)
mjarvisal 0:e6fcdb78a136 1323 {
mjarvisal 0:e6fcdb78a136 1324 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1325 uint16_t osc_calibrate_val;
mjarvisal 0:e6fcdb78a136 1326 uint32_t IMPeriodMilliSeconds;
mjarvisal 0:e6fcdb78a136 1327
mjarvisal 0:e6fcdb78a136 1328 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1329
mjarvisal 0:e6fcdb78a136 1330 Status = VL53L0X_RdWord(Dev, VL53L0X_REG_OSC_CALIBRATE_VAL,
mjarvisal 0:e6fcdb78a136 1331 &osc_calibrate_val);
mjarvisal 0:e6fcdb78a136 1332
mjarvisal 0:e6fcdb78a136 1333 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1334 if (osc_calibrate_val != 0) {
mjarvisal 0:e6fcdb78a136 1335 IMPeriodMilliSeconds =
mjarvisal 0:e6fcdb78a136 1336 InterMeasurementPeriodMilliSeconds
mjarvisal 0:e6fcdb78a136 1337 * osc_calibrate_val;
mjarvisal 0:e6fcdb78a136 1338 } else {
mjarvisal 0:e6fcdb78a136 1339 IMPeriodMilliSeconds =
mjarvisal 0:e6fcdb78a136 1340 InterMeasurementPeriodMilliSeconds;
mjarvisal 0:e6fcdb78a136 1341 }
mjarvisal 0:e6fcdb78a136 1342 Status = VL53L0X_WrDWord(Dev,
mjarvisal 0:e6fcdb78a136 1343 VL53L0X_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
mjarvisal 0:e6fcdb78a136 1344 IMPeriodMilliSeconds);
mjarvisal 0:e6fcdb78a136 1345 }
mjarvisal 0:e6fcdb78a136 1346
mjarvisal 0:e6fcdb78a136 1347 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1348 VL53L0X_SETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1349 InterMeasurementPeriodMilliSeconds,
mjarvisal 0:e6fcdb78a136 1350 InterMeasurementPeriodMilliSeconds);
mjarvisal 0:e6fcdb78a136 1351 }
mjarvisal 0:e6fcdb78a136 1352
mjarvisal 0:e6fcdb78a136 1353 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1354 return Status;
mjarvisal 0:e6fcdb78a136 1355 }
mjarvisal 0:e6fcdb78a136 1356
mjarvisal 0:e6fcdb78a136 1357 VL53L0X_Error VL53L0X_GetInterMeasurementPeriodMilliSeconds(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1358 uint32_t *pInterMeasurementPeriodMilliSeconds)
mjarvisal 0:e6fcdb78a136 1359 {
mjarvisal 0:e6fcdb78a136 1360 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1361 uint16_t osc_calibrate_val;
mjarvisal 0:e6fcdb78a136 1362 uint32_t IMPeriodMilliSeconds;
mjarvisal 0:e6fcdb78a136 1363
mjarvisal 0:e6fcdb78a136 1364 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1365
mjarvisal 0:e6fcdb78a136 1366 Status = VL53L0X_RdWord(Dev, VL53L0X_REG_OSC_CALIBRATE_VAL,
mjarvisal 0:e6fcdb78a136 1367 &osc_calibrate_val);
mjarvisal 0:e6fcdb78a136 1368
mjarvisal 0:e6fcdb78a136 1369 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1370 Status = VL53L0X_RdDWord(Dev,
mjarvisal 0:e6fcdb78a136 1371 VL53L0X_REG_SYSTEM_INTERMEASUREMENT_PERIOD,
mjarvisal 0:e6fcdb78a136 1372 &IMPeriodMilliSeconds);
mjarvisal 0:e6fcdb78a136 1373 }
mjarvisal 0:e6fcdb78a136 1374
mjarvisal 0:e6fcdb78a136 1375 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1376 if (osc_calibrate_val != 0) {
mjarvisal 0:e6fcdb78a136 1377 *pInterMeasurementPeriodMilliSeconds =
mjarvisal 0:e6fcdb78a136 1378 IMPeriodMilliSeconds / osc_calibrate_val;
mjarvisal 0:e6fcdb78a136 1379 }
mjarvisal 0:e6fcdb78a136 1380 VL53L0X_SETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1381 InterMeasurementPeriodMilliSeconds,
mjarvisal 0:e6fcdb78a136 1382 *pInterMeasurementPeriodMilliSeconds);
mjarvisal 0:e6fcdb78a136 1383 }
mjarvisal 0:e6fcdb78a136 1384
mjarvisal 0:e6fcdb78a136 1385 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1386 return Status;
mjarvisal 0:e6fcdb78a136 1387 }
mjarvisal 0:e6fcdb78a136 1388
mjarvisal 0:e6fcdb78a136 1389 VL53L0X_Error VL53L0X_SetXTalkCompensationEnable(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1390 uint8_t XTalkCompensationEnable)
mjarvisal 0:e6fcdb78a136 1391 {
mjarvisal 0:e6fcdb78a136 1392 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1393 FixPoint1616_t TempFix1616;
mjarvisal 0:e6fcdb78a136 1394 uint16_t LinearityCorrectiveGain;
mjarvisal 0:e6fcdb78a136 1395
mjarvisal 0:e6fcdb78a136 1396 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1397
mjarvisal 0:e6fcdb78a136 1398 LinearityCorrectiveGain = PALDevDataGet(Dev, LinearityCorrectiveGain);
mjarvisal 0:e6fcdb78a136 1399
mjarvisal 0:e6fcdb78a136 1400 if ((XTalkCompensationEnable == 0)
mjarvisal 0:e6fcdb78a136 1401 || (LinearityCorrectiveGain != 1000)) {
mjarvisal 0:e6fcdb78a136 1402 TempFix1616 = 0;
mjarvisal 0:e6fcdb78a136 1403 } else {
mjarvisal 0:e6fcdb78a136 1404 VL53L0X_GETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
mjarvisal 0:e6fcdb78a136 1405 TempFix1616);
mjarvisal 0:e6fcdb78a136 1406 }
mjarvisal 0:e6fcdb78a136 1407
mjarvisal 0:e6fcdb78a136 1408 /* the following register has a format 3.13 */
mjarvisal 0:e6fcdb78a136 1409 Status = VL53L0X_WrWord(Dev,
mjarvisal 0:e6fcdb78a136 1410 VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS,
mjarvisal 0:e6fcdb78a136 1411 VL53L0X_FIXPOINT1616TOFIXPOINT313(TempFix1616));
mjarvisal 0:e6fcdb78a136 1412
mjarvisal 0:e6fcdb78a136 1413 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1414 if (XTalkCompensationEnable == 0) {
mjarvisal 0:e6fcdb78a136 1415 VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
mjarvisal 0:e6fcdb78a136 1416 0);
mjarvisal 0:e6fcdb78a136 1417 } else {
mjarvisal 0:e6fcdb78a136 1418 VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
mjarvisal 0:e6fcdb78a136 1419 1);
mjarvisal 0:e6fcdb78a136 1420 }
mjarvisal 0:e6fcdb78a136 1421 }
mjarvisal 0:e6fcdb78a136 1422
mjarvisal 0:e6fcdb78a136 1423 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1424 return Status;
mjarvisal 0:e6fcdb78a136 1425 }
mjarvisal 0:e6fcdb78a136 1426
mjarvisal 0:e6fcdb78a136 1427 VL53L0X_Error VL53L0X_GetXTalkCompensationEnable(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1428 uint8_t *pXTalkCompensationEnable)
mjarvisal 0:e6fcdb78a136 1429 {
mjarvisal 0:e6fcdb78a136 1430 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1431 uint8_t Temp8;
mjarvisal 0:e6fcdb78a136 1432 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1433
mjarvisal 0:e6fcdb78a136 1434 VL53L0X_GETPARAMETERFIELD(Dev, XTalkCompensationEnable, Temp8);
mjarvisal 0:e6fcdb78a136 1435 *pXTalkCompensationEnable = Temp8;
mjarvisal 0:e6fcdb78a136 1436
mjarvisal 0:e6fcdb78a136 1437 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1438 return Status;
mjarvisal 0:e6fcdb78a136 1439 }
mjarvisal 0:e6fcdb78a136 1440
mjarvisal 0:e6fcdb78a136 1441 VL53L0X_Error VL53L0X_SetXTalkCompensationRateMegaCps(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1442 FixPoint1616_t XTalkCompensationRateMegaCps)
mjarvisal 0:e6fcdb78a136 1443 {
mjarvisal 0:e6fcdb78a136 1444 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1445 uint8_t Temp8;
mjarvisal 0:e6fcdb78a136 1446 uint16_t LinearityCorrectiveGain;
mjarvisal 0:e6fcdb78a136 1447 uint16_t data;
mjarvisal 0:e6fcdb78a136 1448 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1449
mjarvisal 0:e6fcdb78a136 1450 VL53L0X_GETPARAMETERFIELD(Dev, XTalkCompensationEnable, Temp8);
mjarvisal 0:e6fcdb78a136 1451 LinearityCorrectiveGain = PALDevDataGet(Dev, LinearityCorrectiveGain);
mjarvisal 0:e6fcdb78a136 1452
mjarvisal 0:e6fcdb78a136 1453 if (Temp8 == 0) { /* disabled write only internal value */
mjarvisal 0:e6fcdb78a136 1454 VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationRateMegaCps,
mjarvisal 0:e6fcdb78a136 1455 XTalkCompensationRateMegaCps);
mjarvisal 0:e6fcdb78a136 1456 } else {
mjarvisal 0:e6fcdb78a136 1457 /* the following register has a format 3.13 */
mjarvisal 0:e6fcdb78a136 1458 if (LinearityCorrectiveGain == 1000) {
mjarvisal 0:e6fcdb78a136 1459 data = VL53L0X_FIXPOINT1616TOFIXPOINT313(
mjarvisal 0:e6fcdb78a136 1460 XTalkCompensationRateMegaCps);
mjarvisal 0:e6fcdb78a136 1461 } else {
mjarvisal 0:e6fcdb78a136 1462 data = 0;
mjarvisal 0:e6fcdb78a136 1463 }
mjarvisal 0:e6fcdb78a136 1464
mjarvisal 0:e6fcdb78a136 1465 Status = VL53L0X_WrWord(Dev,
mjarvisal 0:e6fcdb78a136 1466 VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, data);
mjarvisal 0:e6fcdb78a136 1467
mjarvisal 0:e6fcdb78a136 1468 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1469 VL53L0X_SETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1470 XTalkCompensationRateMegaCps,
mjarvisal 0:e6fcdb78a136 1471 XTalkCompensationRateMegaCps);
mjarvisal 0:e6fcdb78a136 1472 }
mjarvisal 0:e6fcdb78a136 1473 }
mjarvisal 0:e6fcdb78a136 1474
mjarvisal 0:e6fcdb78a136 1475 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1476 return Status;
mjarvisal 0:e6fcdb78a136 1477 }
mjarvisal 0:e6fcdb78a136 1478
mjarvisal 0:e6fcdb78a136 1479 VL53L0X_Error VL53L0X_GetXTalkCompensationRateMegaCps(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1480 FixPoint1616_t *pXTalkCompensationRateMegaCps)
mjarvisal 0:e6fcdb78a136 1481 {
mjarvisal 0:e6fcdb78a136 1482 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1483 uint16_t Value;
mjarvisal 0:e6fcdb78a136 1484 FixPoint1616_t TempFix1616;
mjarvisal 0:e6fcdb78a136 1485
mjarvisal 0:e6fcdb78a136 1486 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1487
mjarvisal 0:e6fcdb78a136 1488 Status = VL53L0X_RdWord(Dev,
mjarvisal 0:e6fcdb78a136 1489 VL53L0X_REG_CROSSTALK_COMPENSATION_PEAK_RATE_MCPS, (uint16_t *)&Value);
mjarvisal 0:e6fcdb78a136 1490 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1491 if (Value == 0) {
mjarvisal 0:e6fcdb78a136 1492 /* the Xtalk is disabled return value from memory */
mjarvisal 0:e6fcdb78a136 1493 VL53L0X_GETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1494 XTalkCompensationRateMegaCps, TempFix1616);
mjarvisal 0:e6fcdb78a136 1495 *pXTalkCompensationRateMegaCps = TempFix1616;
mjarvisal 0:e6fcdb78a136 1496 VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
mjarvisal 0:e6fcdb78a136 1497 0);
mjarvisal 0:e6fcdb78a136 1498 } else {
mjarvisal 0:e6fcdb78a136 1499 TempFix1616 = VL53L0X_FIXPOINT313TOFIXPOINT1616(Value);
mjarvisal 0:e6fcdb78a136 1500 *pXTalkCompensationRateMegaCps = TempFix1616;
mjarvisal 0:e6fcdb78a136 1501 VL53L0X_SETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1502 XTalkCompensationRateMegaCps, TempFix1616);
mjarvisal 0:e6fcdb78a136 1503 VL53L0X_SETPARAMETERFIELD(Dev, XTalkCompensationEnable,
mjarvisal 0:e6fcdb78a136 1504 1);
mjarvisal 0:e6fcdb78a136 1505 }
mjarvisal 0:e6fcdb78a136 1506 }
mjarvisal 0:e6fcdb78a136 1507
mjarvisal 0:e6fcdb78a136 1508 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1509 return Status;
mjarvisal 0:e6fcdb78a136 1510 }
mjarvisal 0:e6fcdb78a136 1511
mjarvisal 0:e6fcdb78a136 1512 VL53L0X_Error VL53L0X_SetRefCalibration(VL53L0X_DEV Dev, uint8_t VhvSettings,
mjarvisal 0:e6fcdb78a136 1513 uint8_t PhaseCal)
mjarvisal 0:e6fcdb78a136 1514 {
mjarvisal 0:e6fcdb78a136 1515 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1516 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1517
mjarvisal 0:e6fcdb78a136 1518 Status = VL53L0X_set_ref_calibration(Dev, VhvSettings, PhaseCal);
mjarvisal 0:e6fcdb78a136 1519
mjarvisal 0:e6fcdb78a136 1520 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1521 return Status;
mjarvisal 0:e6fcdb78a136 1522 }
mjarvisal 0:e6fcdb78a136 1523
mjarvisal 0:e6fcdb78a136 1524 VL53L0X_Error VL53L0X_GetRefCalibration(VL53L0X_DEV Dev, uint8_t *pVhvSettings,
mjarvisal 0:e6fcdb78a136 1525 uint8_t *pPhaseCal)
mjarvisal 0:e6fcdb78a136 1526 {
mjarvisal 0:e6fcdb78a136 1527 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1528 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1529
mjarvisal 0:e6fcdb78a136 1530 Status = VL53L0X_get_ref_calibration(Dev, pVhvSettings, pPhaseCal);
mjarvisal 0:e6fcdb78a136 1531
mjarvisal 0:e6fcdb78a136 1532 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1533 return Status;
mjarvisal 0:e6fcdb78a136 1534 }
mjarvisal 0:e6fcdb78a136 1535
mjarvisal 0:e6fcdb78a136 1536 /*
mjarvisal 0:e6fcdb78a136 1537 * CHECK LIMIT FUNCTIONS
mjarvisal 0:e6fcdb78a136 1538 */
mjarvisal 0:e6fcdb78a136 1539
mjarvisal 0:e6fcdb78a136 1540 VL53L0X_Error VL53L0X_GetNumberOfLimitCheck(uint16_t *pNumberOfLimitCheck)
mjarvisal 0:e6fcdb78a136 1541 {
mjarvisal 0:e6fcdb78a136 1542 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1543 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1544
mjarvisal 0:e6fcdb78a136 1545 *pNumberOfLimitCheck = VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS;
mjarvisal 0:e6fcdb78a136 1546
mjarvisal 0:e6fcdb78a136 1547 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1548 return Status;
mjarvisal 0:e6fcdb78a136 1549 }
mjarvisal 0:e6fcdb78a136 1550
mjarvisal 0:e6fcdb78a136 1551 VL53L0X_Error VL53L0X_GetLimitCheckInfo(VL53L0X_DEV Dev, uint16_t LimitCheckId,
mjarvisal 0:e6fcdb78a136 1552 char *pLimitCheckString)
mjarvisal 0:e6fcdb78a136 1553 {
mjarvisal 0:e6fcdb78a136 1554 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1555
mjarvisal 0:e6fcdb78a136 1556 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1557
mjarvisal 0:e6fcdb78a136 1558 Status = VL53L0X_get_limit_check_info(Dev, LimitCheckId,
mjarvisal 0:e6fcdb78a136 1559 pLimitCheckString);
mjarvisal 0:e6fcdb78a136 1560
mjarvisal 0:e6fcdb78a136 1561 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1562 return Status;
mjarvisal 0:e6fcdb78a136 1563 }
mjarvisal 0:e6fcdb78a136 1564
mjarvisal 0:e6fcdb78a136 1565 VL53L0X_Error VL53L0X_GetLimitCheckStatus(VL53L0X_DEV Dev, uint16_t LimitCheckId,
mjarvisal 0:e6fcdb78a136 1566 uint8_t *pLimitCheckStatus)
mjarvisal 0:e6fcdb78a136 1567 {
mjarvisal 0:e6fcdb78a136 1568 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1569 uint8_t Temp8;
mjarvisal 0:e6fcdb78a136 1570
mjarvisal 0:e6fcdb78a136 1571 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1572
mjarvisal 0:e6fcdb78a136 1573 if (LimitCheckId >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
mjarvisal 0:e6fcdb78a136 1574 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1575 } else {
mjarvisal 0:e6fcdb78a136 1576
mjarvisal 0:e6fcdb78a136 1577 VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksStatus,
mjarvisal 0:e6fcdb78a136 1578 LimitCheckId, Temp8);
mjarvisal 0:e6fcdb78a136 1579
mjarvisal 0:e6fcdb78a136 1580 *pLimitCheckStatus = Temp8;
mjarvisal 0:e6fcdb78a136 1581
mjarvisal 0:e6fcdb78a136 1582 }
mjarvisal 0:e6fcdb78a136 1583
mjarvisal 0:e6fcdb78a136 1584 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1585 return Status;
mjarvisal 0:e6fcdb78a136 1586 }
mjarvisal 0:e6fcdb78a136 1587
mjarvisal 0:e6fcdb78a136 1588 VL53L0X_Error VL53L0X_SetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
mjarvisal 0:e6fcdb78a136 1589 uint8_t LimitCheckEnable)
mjarvisal 0:e6fcdb78a136 1590 {
mjarvisal 0:e6fcdb78a136 1591 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1592 FixPoint1616_t TempFix1616 = 0;
mjarvisal 0:e6fcdb78a136 1593 uint8_t LimitCheckEnableInt = 0;
mjarvisal 0:e6fcdb78a136 1594 uint8_t LimitCheckDisable = 0;
mjarvisal 0:e6fcdb78a136 1595 uint8_t Temp8;
mjarvisal 0:e6fcdb78a136 1596
mjarvisal 0:e6fcdb78a136 1597 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1598
mjarvisal 0:e6fcdb78a136 1599 if (LimitCheckId >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
mjarvisal 0:e6fcdb78a136 1600 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1601 } else {
mjarvisal 0:e6fcdb78a136 1602 if (LimitCheckEnable == 0) {
mjarvisal 0:e6fcdb78a136 1603 TempFix1616 = 0;
mjarvisal 0:e6fcdb78a136 1604 LimitCheckEnableInt = 0;
mjarvisal 0:e6fcdb78a136 1605 LimitCheckDisable = 1;
mjarvisal 0:e6fcdb78a136 1606
mjarvisal 0:e6fcdb78a136 1607 } else {
mjarvisal 0:e6fcdb78a136 1608 VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1609 LimitCheckId, TempFix1616);
mjarvisal 0:e6fcdb78a136 1610 LimitCheckDisable = 0;
mjarvisal 0:e6fcdb78a136 1611 /* this to be sure to have either 0 or 1 */
mjarvisal 0:e6fcdb78a136 1612 LimitCheckEnableInt = 1;
mjarvisal 0:e6fcdb78a136 1613 }
mjarvisal 0:e6fcdb78a136 1614
mjarvisal 0:e6fcdb78a136 1615 switch (LimitCheckId) {
mjarvisal 0:e6fcdb78a136 1616
mjarvisal 0:e6fcdb78a136 1617 case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1618 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1619 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
mjarvisal 0:e6fcdb78a136 1620 VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
mjarvisal 0:e6fcdb78a136 1621 LimitCheckEnableInt);
mjarvisal 0:e6fcdb78a136 1622
mjarvisal 0:e6fcdb78a136 1623 break;
mjarvisal 0:e6fcdb78a136 1624
mjarvisal 0:e6fcdb78a136 1625 case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1626
mjarvisal 0:e6fcdb78a136 1627 Status = VL53L0X_WrWord(Dev,
mjarvisal 0:e6fcdb78a136 1628 VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
mjarvisal 0:e6fcdb78a136 1629 VL53L0X_FIXPOINT1616TOFIXPOINT97(TempFix1616));
mjarvisal 0:e6fcdb78a136 1630
mjarvisal 0:e6fcdb78a136 1631 break;
mjarvisal 0:e6fcdb78a136 1632
mjarvisal 0:e6fcdb78a136 1633 case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
mjarvisal 0:e6fcdb78a136 1634
mjarvisal 0:e6fcdb78a136 1635 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1636 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
mjarvisal 0:e6fcdb78a136 1637 VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
mjarvisal 0:e6fcdb78a136 1638 LimitCheckEnableInt);
mjarvisal 0:e6fcdb78a136 1639
mjarvisal 0:e6fcdb78a136 1640 break;
mjarvisal 0:e6fcdb78a136 1641
mjarvisal 0:e6fcdb78a136 1642 case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
mjarvisal 0:e6fcdb78a136 1643
mjarvisal 0:e6fcdb78a136 1644 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1645 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
mjarvisal 0:e6fcdb78a136 1646 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
mjarvisal 0:e6fcdb78a136 1647 LimitCheckEnableInt);
mjarvisal 0:e6fcdb78a136 1648
mjarvisal 0:e6fcdb78a136 1649 break;
mjarvisal 0:e6fcdb78a136 1650
mjarvisal 0:e6fcdb78a136 1651 case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
mjarvisal 0:e6fcdb78a136 1652
mjarvisal 0:e6fcdb78a136 1653 Temp8 = (uint8_t)(LimitCheckDisable << 1);
mjarvisal 0:e6fcdb78a136 1654 Status = VL53L0X_UpdateByte(Dev,
mjarvisal 0:e6fcdb78a136 1655 VL53L0X_REG_MSRC_CONFIG_CONTROL,
mjarvisal 0:e6fcdb78a136 1656 0xFE, Temp8);
mjarvisal 0:e6fcdb78a136 1657
mjarvisal 0:e6fcdb78a136 1658 break;
mjarvisal 0:e6fcdb78a136 1659
mjarvisal 0:e6fcdb78a136 1660 case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
mjarvisal 0:e6fcdb78a136 1661
mjarvisal 0:e6fcdb78a136 1662 Temp8 = (uint8_t)(LimitCheckDisable << 4);
mjarvisal 0:e6fcdb78a136 1663 Status = VL53L0X_UpdateByte(Dev,
mjarvisal 0:e6fcdb78a136 1664 VL53L0X_REG_MSRC_CONFIG_CONTROL,
mjarvisal 0:e6fcdb78a136 1665 0xEF, Temp8);
mjarvisal 0:e6fcdb78a136 1666
mjarvisal 0:e6fcdb78a136 1667 break;
mjarvisal 0:e6fcdb78a136 1668
mjarvisal 0:e6fcdb78a136 1669
mjarvisal 0:e6fcdb78a136 1670 default:
mjarvisal 0:e6fcdb78a136 1671 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1672
mjarvisal 0:e6fcdb78a136 1673 }
mjarvisal 0:e6fcdb78a136 1674
mjarvisal 0:e6fcdb78a136 1675 }
mjarvisal 0:e6fcdb78a136 1676
mjarvisal 0:e6fcdb78a136 1677 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1678 if (LimitCheckEnable == 0) {
mjarvisal 0:e6fcdb78a136 1679 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
mjarvisal 0:e6fcdb78a136 1680 LimitCheckId, 0);
mjarvisal 0:e6fcdb78a136 1681 } else {
mjarvisal 0:e6fcdb78a136 1682 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
mjarvisal 0:e6fcdb78a136 1683 LimitCheckId, 1);
mjarvisal 0:e6fcdb78a136 1684 }
mjarvisal 0:e6fcdb78a136 1685 }
mjarvisal 0:e6fcdb78a136 1686
mjarvisal 0:e6fcdb78a136 1687 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1688 return Status;
mjarvisal 0:e6fcdb78a136 1689 }
mjarvisal 0:e6fcdb78a136 1690
mjarvisal 0:e6fcdb78a136 1691 VL53L0X_Error VL53L0X_GetLimitCheckEnable(VL53L0X_DEV Dev, uint16_t LimitCheckId,
mjarvisal 0:e6fcdb78a136 1692 uint8_t *pLimitCheckEnable)
mjarvisal 0:e6fcdb78a136 1693 {
mjarvisal 0:e6fcdb78a136 1694 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1695 uint8_t Temp8;
mjarvisal 0:e6fcdb78a136 1696
mjarvisal 0:e6fcdb78a136 1697 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1698
mjarvisal 0:e6fcdb78a136 1699 if (LimitCheckId >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
mjarvisal 0:e6fcdb78a136 1700 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1701 *pLimitCheckEnable = 0;
mjarvisal 0:e6fcdb78a136 1702 } else {
mjarvisal 0:e6fcdb78a136 1703 VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable,
mjarvisal 0:e6fcdb78a136 1704 LimitCheckId, Temp8);
mjarvisal 0:e6fcdb78a136 1705 *pLimitCheckEnable = Temp8;
mjarvisal 0:e6fcdb78a136 1706 }
mjarvisal 0:e6fcdb78a136 1707
mjarvisal 0:e6fcdb78a136 1708 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1709 return Status;
mjarvisal 0:e6fcdb78a136 1710 }
mjarvisal 0:e6fcdb78a136 1711
mjarvisal 0:e6fcdb78a136 1712 VL53L0X_Error VL53L0X_SetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
mjarvisal 0:e6fcdb78a136 1713 FixPoint1616_t LimitCheckValue)
mjarvisal 0:e6fcdb78a136 1714 {
mjarvisal 0:e6fcdb78a136 1715 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1716 uint8_t Temp8;
mjarvisal 0:e6fcdb78a136 1717
mjarvisal 0:e6fcdb78a136 1718 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1719
mjarvisal 0:e6fcdb78a136 1720 VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksEnable, LimitCheckId,
mjarvisal 0:e6fcdb78a136 1721 Temp8);
mjarvisal 0:e6fcdb78a136 1722
mjarvisal 0:e6fcdb78a136 1723 if (Temp8 == 0) { /* disabled write only internal value */
mjarvisal 0:e6fcdb78a136 1724 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1725 LimitCheckId, LimitCheckValue);
mjarvisal 0:e6fcdb78a136 1726 } else {
mjarvisal 0:e6fcdb78a136 1727
mjarvisal 0:e6fcdb78a136 1728 switch (LimitCheckId) {
mjarvisal 0:e6fcdb78a136 1729
mjarvisal 0:e6fcdb78a136 1730 case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1731 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1732 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1733 VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE,
mjarvisal 0:e6fcdb78a136 1734 LimitCheckValue);
mjarvisal 0:e6fcdb78a136 1735 break;
mjarvisal 0:e6fcdb78a136 1736
mjarvisal 0:e6fcdb78a136 1737 case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1738
mjarvisal 0:e6fcdb78a136 1739 Status = VL53L0X_WrWord(Dev,
mjarvisal 0:e6fcdb78a136 1740 VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
mjarvisal 0:e6fcdb78a136 1741 VL53L0X_FIXPOINT1616TOFIXPOINT97(
mjarvisal 0:e6fcdb78a136 1742 LimitCheckValue));
mjarvisal 0:e6fcdb78a136 1743
mjarvisal 0:e6fcdb78a136 1744 break;
mjarvisal 0:e6fcdb78a136 1745
mjarvisal 0:e6fcdb78a136 1746 case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
mjarvisal 0:e6fcdb78a136 1747
mjarvisal 0:e6fcdb78a136 1748 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1749 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1750 VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP,
mjarvisal 0:e6fcdb78a136 1751 LimitCheckValue);
mjarvisal 0:e6fcdb78a136 1752
mjarvisal 0:e6fcdb78a136 1753 break;
mjarvisal 0:e6fcdb78a136 1754
mjarvisal 0:e6fcdb78a136 1755 case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
mjarvisal 0:e6fcdb78a136 1756
mjarvisal 0:e6fcdb78a136 1757 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1758 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1759 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD,
mjarvisal 0:e6fcdb78a136 1760 LimitCheckValue);
mjarvisal 0:e6fcdb78a136 1761
mjarvisal 0:e6fcdb78a136 1762 break;
mjarvisal 0:e6fcdb78a136 1763
mjarvisal 0:e6fcdb78a136 1764 case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
mjarvisal 0:e6fcdb78a136 1765 case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
mjarvisal 0:e6fcdb78a136 1766
mjarvisal 0:e6fcdb78a136 1767 Status = VL53L0X_WrWord(Dev,
mjarvisal 0:e6fcdb78a136 1768 VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT,
mjarvisal 0:e6fcdb78a136 1769 VL53L0X_FIXPOINT1616TOFIXPOINT97(
mjarvisal 0:e6fcdb78a136 1770 LimitCheckValue));
mjarvisal 0:e6fcdb78a136 1771
mjarvisal 0:e6fcdb78a136 1772 break;
mjarvisal 0:e6fcdb78a136 1773
mjarvisal 0:e6fcdb78a136 1774 default:
mjarvisal 0:e6fcdb78a136 1775 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1776
mjarvisal 0:e6fcdb78a136 1777 }
mjarvisal 0:e6fcdb78a136 1778
mjarvisal 0:e6fcdb78a136 1779 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1780 VL53L0X_SETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1781 LimitCheckId, LimitCheckValue);
mjarvisal 0:e6fcdb78a136 1782 }
mjarvisal 0:e6fcdb78a136 1783 }
mjarvisal 0:e6fcdb78a136 1784
mjarvisal 0:e6fcdb78a136 1785 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1786 return Status;
mjarvisal 0:e6fcdb78a136 1787 }
mjarvisal 0:e6fcdb78a136 1788
mjarvisal 0:e6fcdb78a136 1789 VL53L0X_Error VL53L0X_GetLimitCheckValue(VL53L0X_DEV Dev, uint16_t LimitCheckId,
mjarvisal 0:e6fcdb78a136 1790 FixPoint1616_t *pLimitCheckValue)
mjarvisal 0:e6fcdb78a136 1791 {
mjarvisal 0:e6fcdb78a136 1792 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1793 uint8_t EnableZeroValue = 0;
mjarvisal 0:e6fcdb78a136 1794 uint16_t Temp16;
mjarvisal 0:e6fcdb78a136 1795 FixPoint1616_t TempFix1616;
mjarvisal 0:e6fcdb78a136 1796
mjarvisal 0:e6fcdb78a136 1797 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1798
mjarvisal 0:e6fcdb78a136 1799 switch (LimitCheckId) {
mjarvisal 0:e6fcdb78a136 1800
mjarvisal 0:e6fcdb78a136 1801 case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1802 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1803 VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1804 VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, TempFix1616);
mjarvisal 0:e6fcdb78a136 1805 EnableZeroValue = 0;
mjarvisal 0:e6fcdb78a136 1806 break;
mjarvisal 0:e6fcdb78a136 1807
mjarvisal 0:e6fcdb78a136 1808 case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1809 Status = VL53L0X_RdWord(Dev,
mjarvisal 0:e6fcdb78a136 1810 VL53L0X_REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
mjarvisal 0:e6fcdb78a136 1811 &Temp16);
mjarvisal 0:e6fcdb78a136 1812 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 1813 TempFix1616 = VL53L0X_FIXPOINT97TOFIXPOINT1616(Temp16);
mjarvisal 0:e6fcdb78a136 1814
mjarvisal 0:e6fcdb78a136 1815
mjarvisal 0:e6fcdb78a136 1816 EnableZeroValue = 1;
mjarvisal 0:e6fcdb78a136 1817 break;
mjarvisal 0:e6fcdb78a136 1818
mjarvisal 0:e6fcdb78a136 1819 case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
mjarvisal 0:e6fcdb78a136 1820 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1821 VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1822 VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP, TempFix1616);
mjarvisal 0:e6fcdb78a136 1823 EnableZeroValue = 0;
mjarvisal 0:e6fcdb78a136 1824 break;
mjarvisal 0:e6fcdb78a136 1825
mjarvisal 0:e6fcdb78a136 1826 case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
mjarvisal 0:e6fcdb78a136 1827 /* internal computation: */
mjarvisal 0:e6fcdb78a136 1828 VL53L0X_GETARRAYPARAMETERFIELD(Dev, LimitChecksValue,
mjarvisal 0:e6fcdb78a136 1829 VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, TempFix1616);
mjarvisal 0:e6fcdb78a136 1830 EnableZeroValue = 0;
mjarvisal 0:e6fcdb78a136 1831 break;
mjarvisal 0:e6fcdb78a136 1832
mjarvisal 0:e6fcdb78a136 1833 case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
mjarvisal 0:e6fcdb78a136 1834 case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
mjarvisal 0:e6fcdb78a136 1835 Status = VL53L0X_RdWord(Dev,
mjarvisal 0:e6fcdb78a136 1836 VL53L0X_REG_PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT,
mjarvisal 0:e6fcdb78a136 1837 &Temp16);
mjarvisal 0:e6fcdb78a136 1838 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 1839 TempFix1616 = VL53L0X_FIXPOINT97TOFIXPOINT1616(Temp16);
mjarvisal 0:e6fcdb78a136 1840
mjarvisal 0:e6fcdb78a136 1841
mjarvisal 0:e6fcdb78a136 1842 EnableZeroValue = 0;
mjarvisal 0:e6fcdb78a136 1843 break;
mjarvisal 0:e6fcdb78a136 1844
mjarvisal 0:e6fcdb78a136 1845 default:
mjarvisal 0:e6fcdb78a136 1846 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1847
mjarvisal 0:e6fcdb78a136 1848 }
mjarvisal 0:e6fcdb78a136 1849
mjarvisal 0:e6fcdb78a136 1850 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1851
mjarvisal 0:e6fcdb78a136 1852 if (EnableZeroValue == 1) {
mjarvisal 0:e6fcdb78a136 1853
mjarvisal 0:e6fcdb78a136 1854 if (TempFix1616 == 0) {
mjarvisal 0:e6fcdb78a136 1855 /* disabled: return value from memory */
mjarvisal 0:e6fcdb78a136 1856 VL53L0X_GETARRAYPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1857 LimitChecksValue, LimitCheckId,
mjarvisal 0:e6fcdb78a136 1858 TempFix1616);
mjarvisal 0:e6fcdb78a136 1859 *pLimitCheckValue = TempFix1616;
mjarvisal 0:e6fcdb78a136 1860 VL53L0X_SETARRAYPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1861 LimitChecksEnable, LimitCheckId, 0);
mjarvisal 0:e6fcdb78a136 1862 } else {
mjarvisal 0:e6fcdb78a136 1863 *pLimitCheckValue = TempFix1616;
mjarvisal 0:e6fcdb78a136 1864 VL53L0X_SETARRAYPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1865 LimitChecksValue, LimitCheckId,
mjarvisal 0:e6fcdb78a136 1866 TempFix1616);
mjarvisal 0:e6fcdb78a136 1867 VL53L0X_SETARRAYPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 1868 LimitChecksEnable, LimitCheckId, 1);
mjarvisal 0:e6fcdb78a136 1869 }
mjarvisal 0:e6fcdb78a136 1870 } else {
mjarvisal 0:e6fcdb78a136 1871 *pLimitCheckValue = TempFix1616;
mjarvisal 0:e6fcdb78a136 1872 }
mjarvisal 0:e6fcdb78a136 1873 }
mjarvisal 0:e6fcdb78a136 1874
mjarvisal 0:e6fcdb78a136 1875 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1876 return Status;
mjarvisal 0:e6fcdb78a136 1877
mjarvisal 0:e6fcdb78a136 1878 }
mjarvisal 0:e6fcdb78a136 1879
mjarvisal 0:e6fcdb78a136 1880 VL53L0X_Error VL53L0X_GetLimitCheckCurrent(VL53L0X_DEV Dev, uint16_t LimitCheckId,
mjarvisal 0:e6fcdb78a136 1881 FixPoint1616_t *pLimitCheckCurrent)
mjarvisal 0:e6fcdb78a136 1882 {
mjarvisal 0:e6fcdb78a136 1883 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1884 VL53L0X_RangingMeasurementData_t LastRangeDataBuffer;
mjarvisal 0:e6fcdb78a136 1885
mjarvisal 0:e6fcdb78a136 1886 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1887
mjarvisal 0:e6fcdb78a136 1888 if (LimitCheckId >= VL53L0X_CHECKENABLE_NUMBER_OF_CHECKS) {
mjarvisal 0:e6fcdb78a136 1889 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1890 } else {
mjarvisal 0:e6fcdb78a136 1891 switch (LimitCheckId) {
mjarvisal 0:e6fcdb78a136 1892 case VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1893 /* Need to run a ranging to have the latest values */
mjarvisal 0:e6fcdb78a136 1894 *pLimitCheckCurrent = PALDevDataGet(Dev, SigmaEstimate);
mjarvisal 0:e6fcdb78a136 1895
mjarvisal 0:e6fcdb78a136 1896 break;
mjarvisal 0:e6fcdb78a136 1897
mjarvisal 0:e6fcdb78a136 1898 case VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
mjarvisal 0:e6fcdb78a136 1899 /* Need to run a ranging to have the latest values */
mjarvisal 0:e6fcdb78a136 1900 LastRangeDataBuffer = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 1901 LastRangeMeasure);
mjarvisal 0:e6fcdb78a136 1902 *pLimitCheckCurrent =
mjarvisal 0:e6fcdb78a136 1903 LastRangeDataBuffer.SignalRateRtnMegaCps;
mjarvisal 0:e6fcdb78a136 1904
mjarvisal 0:e6fcdb78a136 1905 break;
mjarvisal 0:e6fcdb78a136 1906
mjarvisal 0:e6fcdb78a136 1907 case VL53L0X_CHECKENABLE_SIGNAL_REF_CLIP:
mjarvisal 0:e6fcdb78a136 1908 /* Need to run a ranging to have the latest values */
mjarvisal 0:e6fcdb78a136 1909 *pLimitCheckCurrent = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 1910 LastSignalRefMcps);
mjarvisal 0:e6fcdb78a136 1911
mjarvisal 0:e6fcdb78a136 1912 break;
mjarvisal 0:e6fcdb78a136 1913
mjarvisal 0:e6fcdb78a136 1914 case VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD:
mjarvisal 0:e6fcdb78a136 1915 /* Need to run a ranging to have the latest values */
mjarvisal 0:e6fcdb78a136 1916 LastRangeDataBuffer = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 1917 LastRangeMeasure);
mjarvisal 0:e6fcdb78a136 1918 *pLimitCheckCurrent =
mjarvisal 0:e6fcdb78a136 1919 LastRangeDataBuffer.SignalRateRtnMegaCps;
mjarvisal 0:e6fcdb78a136 1920
mjarvisal 0:e6fcdb78a136 1921 break;
mjarvisal 0:e6fcdb78a136 1922
mjarvisal 0:e6fcdb78a136 1923 case VL53L0X_CHECKENABLE_SIGNAL_RATE_MSRC:
mjarvisal 0:e6fcdb78a136 1924 /* Need to run a ranging to have the latest values */
mjarvisal 0:e6fcdb78a136 1925 LastRangeDataBuffer = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 1926 LastRangeMeasure);
mjarvisal 0:e6fcdb78a136 1927 *pLimitCheckCurrent =
mjarvisal 0:e6fcdb78a136 1928 LastRangeDataBuffer.SignalRateRtnMegaCps;
mjarvisal 0:e6fcdb78a136 1929
mjarvisal 0:e6fcdb78a136 1930 break;
mjarvisal 0:e6fcdb78a136 1931
mjarvisal 0:e6fcdb78a136 1932 case VL53L0X_CHECKENABLE_SIGNAL_RATE_PRE_RANGE:
mjarvisal 0:e6fcdb78a136 1933 /* Need to run a ranging to have the latest values */
mjarvisal 0:e6fcdb78a136 1934 LastRangeDataBuffer = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 1935 LastRangeMeasure);
mjarvisal 0:e6fcdb78a136 1936 *pLimitCheckCurrent =
mjarvisal 0:e6fcdb78a136 1937 LastRangeDataBuffer.SignalRateRtnMegaCps;
mjarvisal 0:e6fcdb78a136 1938
mjarvisal 0:e6fcdb78a136 1939 break;
mjarvisal 0:e6fcdb78a136 1940
mjarvisal 0:e6fcdb78a136 1941 default:
mjarvisal 0:e6fcdb78a136 1942 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 1943 }
mjarvisal 0:e6fcdb78a136 1944 }
mjarvisal 0:e6fcdb78a136 1945
mjarvisal 0:e6fcdb78a136 1946 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1947 return Status;
mjarvisal 0:e6fcdb78a136 1948
mjarvisal 0:e6fcdb78a136 1949 }
mjarvisal 0:e6fcdb78a136 1950
mjarvisal 0:e6fcdb78a136 1951 /*
mjarvisal 0:e6fcdb78a136 1952 * WRAPAROUND Check
mjarvisal 0:e6fcdb78a136 1953 */
mjarvisal 0:e6fcdb78a136 1954 VL53L0X_Error VL53L0X_SetWrapAroundCheckEnable(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1955 uint8_t WrapAroundCheckEnable)
mjarvisal 0:e6fcdb78a136 1956 {
mjarvisal 0:e6fcdb78a136 1957 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1958 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 1959 uint8_t WrapAroundCheckEnableInt;
mjarvisal 0:e6fcdb78a136 1960
mjarvisal 0:e6fcdb78a136 1961 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1962
mjarvisal 0:e6fcdb78a136 1963 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &Byte);
mjarvisal 0:e6fcdb78a136 1964 if (WrapAroundCheckEnable == 0) {
mjarvisal 0:e6fcdb78a136 1965 /* Disable wraparound */
mjarvisal 0:e6fcdb78a136 1966 Byte = Byte & 0x7F;
mjarvisal 0:e6fcdb78a136 1967 WrapAroundCheckEnableInt = 0;
mjarvisal 0:e6fcdb78a136 1968 } else {
mjarvisal 0:e6fcdb78a136 1969 /*Enable wraparound */
mjarvisal 0:e6fcdb78a136 1970 Byte = Byte | 0x80;
mjarvisal 0:e6fcdb78a136 1971 WrapAroundCheckEnableInt = 1;
mjarvisal 0:e6fcdb78a136 1972 }
mjarvisal 0:e6fcdb78a136 1973
mjarvisal 0:e6fcdb78a136 1974 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, Byte);
mjarvisal 0:e6fcdb78a136 1975
mjarvisal 0:e6fcdb78a136 1976 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1977 PALDevDataSet(Dev, SequenceConfig, Byte);
mjarvisal 0:e6fcdb78a136 1978 VL53L0X_SETPARAMETERFIELD(Dev, WrapAroundCheckEnable,
mjarvisal 0:e6fcdb78a136 1979 WrapAroundCheckEnableInt);
mjarvisal 0:e6fcdb78a136 1980 }
mjarvisal 0:e6fcdb78a136 1981
mjarvisal 0:e6fcdb78a136 1982 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 1983 return Status;
mjarvisal 0:e6fcdb78a136 1984 }
mjarvisal 0:e6fcdb78a136 1985
mjarvisal 0:e6fcdb78a136 1986 VL53L0X_Error VL53L0X_GetWrapAroundCheckEnable(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 1987 uint8_t *pWrapAroundCheckEnable)
mjarvisal 0:e6fcdb78a136 1988 {
mjarvisal 0:e6fcdb78a136 1989 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 1990 uint8_t data;
mjarvisal 0:e6fcdb78a136 1991
mjarvisal 0:e6fcdb78a136 1992 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 1993
mjarvisal 0:e6fcdb78a136 1994 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_SYSTEM_SEQUENCE_CONFIG, &data);
mjarvisal 0:e6fcdb78a136 1995 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 1996 PALDevDataSet(Dev, SequenceConfig, data);
mjarvisal 0:e6fcdb78a136 1997 if (data & (0x01 << 7))
mjarvisal 0:e6fcdb78a136 1998 *pWrapAroundCheckEnable = 0x01;
mjarvisal 0:e6fcdb78a136 1999 else
mjarvisal 0:e6fcdb78a136 2000 *pWrapAroundCheckEnable = 0x00;
mjarvisal 0:e6fcdb78a136 2001 }
mjarvisal 0:e6fcdb78a136 2002 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2003 VL53L0X_SETPARAMETERFIELD(Dev, WrapAroundCheckEnable,
mjarvisal 0:e6fcdb78a136 2004 *pWrapAroundCheckEnable);
mjarvisal 0:e6fcdb78a136 2005 }
mjarvisal 0:e6fcdb78a136 2006
mjarvisal 0:e6fcdb78a136 2007 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2008 return Status;
mjarvisal 0:e6fcdb78a136 2009 }
mjarvisal 0:e6fcdb78a136 2010
mjarvisal 0:e6fcdb78a136 2011 VL53L0X_Error VL53L0X_SetDmaxCalParameters(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2012 uint16_t RangeMilliMeter, FixPoint1616_t SignalRateRtnMegaCps)
mjarvisal 0:e6fcdb78a136 2013 {
mjarvisal 0:e6fcdb78a136 2014 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2015 FixPoint1616_t SignalRateRtnMegaCpsTemp = 0;
mjarvisal 0:e6fcdb78a136 2016
mjarvisal 0:e6fcdb78a136 2017 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2018
mjarvisal 0:e6fcdb78a136 2019 /* Check if one of input parameter is zero, in that case the
mjarvisal 0:e6fcdb78a136 2020 * value are get from NVM */
mjarvisal 0:e6fcdb78a136 2021 if ((RangeMilliMeter == 0) || (SignalRateRtnMegaCps == 0)) {
mjarvisal 0:e6fcdb78a136 2022 /* NVM parameters */
mjarvisal 0:e6fcdb78a136 2023 /* Run VL53L0X_get_info_from_device wit option 4 to get
mjarvisal 0:e6fcdb78a136 2024 * signal rate at 400 mm if the value have been already
mjarvisal 0:e6fcdb78a136 2025 * get this function will return with no access to device */
mjarvisal 0:e6fcdb78a136 2026 VL53L0X_get_info_from_device(Dev, 4);
mjarvisal 0:e6fcdb78a136 2027
mjarvisal 0:e6fcdb78a136 2028 SignalRateRtnMegaCpsTemp = VL53L0X_GETDEVICESPECIFICPARAMETER(
mjarvisal 0:e6fcdb78a136 2029 Dev, SignalRateMeasFixed400mm);
mjarvisal 0:e6fcdb78a136 2030
mjarvisal 0:e6fcdb78a136 2031 PALDevDataSet(Dev, DmaxCalRangeMilliMeter, 400);
mjarvisal 0:e6fcdb78a136 2032 PALDevDataSet(Dev, DmaxCalSignalRateRtnMegaCps,
mjarvisal 0:e6fcdb78a136 2033 SignalRateRtnMegaCpsTemp);
mjarvisal 0:e6fcdb78a136 2034 } else {
mjarvisal 0:e6fcdb78a136 2035 /* User parameters */
mjarvisal 0:e6fcdb78a136 2036 PALDevDataSet(Dev, DmaxCalRangeMilliMeter, RangeMilliMeter);
mjarvisal 0:e6fcdb78a136 2037 PALDevDataSet(Dev, DmaxCalSignalRateRtnMegaCps,
mjarvisal 0:e6fcdb78a136 2038 SignalRateRtnMegaCps);
mjarvisal 0:e6fcdb78a136 2039 }
mjarvisal 0:e6fcdb78a136 2040
mjarvisal 0:e6fcdb78a136 2041 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2042 return Status;
mjarvisal 0:e6fcdb78a136 2043 }
mjarvisal 0:e6fcdb78a136 2044
mjarvisal 0:e6fcdb78a136 2045 VL53L0X_Error VL53L0X_GetDmaxCalParameters(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2046 uint16_t *pRangeMilliMeter, FixPoint1616_t *pSignalRateRtnMegaCps)
mjarvisal 0:e6fcdb78a136 2047 {
mjarvisal 0:e6fcdb78a136 2048 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2049
mjarvisal 0:e6fcdb78a136 2050 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2051
mjarvisal 0:e6fcdb78a136 2052 *pRangeMilliMeter = PALDevDataGet(Dev, DmaxCalRangeMilliMeter);
mjarvisal 0:e6fcdb78a136 2053 *pSignalRateRtnMegaCps = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 2054 DmaxCalSignalRateRtnMegaCps);
mjarvisal 0:e6fcdb78a136 2055
mjarvisal 0:e6fcdb78a136 2056 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2057 return Status;
mjarvisal 0:e6fcdb78a136 2058 }
mjarvisal 0:e6fcdb78a136 2059
mjarvisal 0:e6fcdb78a136 2060 /* End Group PAL Parameters Functions */
mjarvisal 0:e6fcdb78a136 2061
mjarvisal 0:e6fcdb78a136 2062 /* Group PAL Measurement Functions */
mjarvisal 0:e6fcdb78a136 2063 VL53L0X_Error VL53L0X_PerformSingleMeasurement(VL53L0X_DEV Dev)
mjarvisal 0:e6fcdb78a136 2064 {
mjarvisal 0:e6fcdb78a136 2065 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2066 VL53L0X_DeviceModes DeviceMode;
mjarvisal 0:e6fcdb78a136 2067
mjarvisal 0:e6fcdb78a136 2068 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2069
mjarvisal 0:e6fcdb78a136 2070 /* Get Current DeviceMode */
mjarvisal 0:e6fcdb78a136 2071 Status = VL53L0X_GetDeviceMode(Dev, &DeviceMode);
mjarvisal 0:e6fcdb78a136 2072
mjarvisal 0:e6fcdb78a136 2073 /* Start immediately to run a single ranging measurement in case of
mjarvisal 0:e6fcdb78a136 2074 * single ranging or single histogram */
mjarvisal 0:e6fcdb78a136 2075 if (Status == VL53L0X_ERROR_NONE
mjarvisal 0:e6fcdb78a136 2076 && DeviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING)
mjarvisal 0:e6fcdb78a136 2077 Status = VL53L0X_StartMeasurement(Dev);
mjarvisal 0:e6fcdb78a136 2078
mjarvisal 0:e6fcdb78a136 2079
mjarvisal 0:e6fcdb78a136 2080 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2081 Status = VL53L0X_measurement_poll_for_completion(Dev);
mjarvisal 0:e6fcdb78a136 2082
mjarvisal 0:e6fcdb78a136 2083
mjarvisal 0:e6fcdb78a136 2084 /* Change PAL State in case of single ranging or single histogram */
mjarvisal 0:e6fcdb78a136 2085 if (Status == VL53L0X_ERROR_NONE
mjarvisal 0:e6fcdb78a136 2086 && DeviceMode == VL53L0X_DEVICEMODE_SINGLE_RANGING)
mjarvisal 0:e6fcdb78a136 2087 PALDevDataSet(Dev, PalState, VL53L0X_STATE_IDLE);
mjarvisal 0:e6fcdb78a136 2088
mjarvisal 0:e6fcdb78a136 2089
mjarvisal 0:e6fcdb78a136 2090 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2091 return Status;
mjarvisal 0:e6fcdb78a136 2092 }
mjarvisal 0:e6fcdb78a136 2093
mjarvisal 0:e6fcdb78a136 2094 VL53L0X_Error VL53L0X_PerformSingleHistogramMeasurement(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2095 VL53L0X_HistogramMeasurementData_t *pHistogramMeasurementData)
mjarvisal 0:e6fcdb78a136 2096 {
mjarvisal 0:e6fcdb78a136 2097 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 2098 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2099
mjarvisal 0:e6fcdb78a136 2100 /* not implemented on VL53L0X */
mjarvisal 0:e6fcdb78a136 2101
mjarvisal 0:e6fcdb78a136 2102 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2103 return Status;
mjarvisal 0:e6fcdb78a136 2104 }
mjarvisal 0:e6fcdb78a136 2105
mjarvisal 0:e6fcdb78a136 2106 VL53L0X_Error VL53L0X_PerformRefCalibration(VL53L0X_DEV Dev, uint8_t *pVhvSettings,
mjarvisal 0:e6fcdb78a136 2107 uint8_t *pPhaseCal)
mjarvisal 0:e6fcdb78a136 2108 {
mjarvisal 0:e6fcdb78a136 2109 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2110 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2111
mjarvisal 0:e6fcdb78a136 2112 Status = VL53L0X_perform_ref_calibration(Dev, pVhvSettings,
mjarvisal 0:e6fcdb78a136 2113 pPhaseCal, 1);
mjarvisal 0:e6fcdb78a136 2114
mjarvisal 0:e6fcdb78a136 2115 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2116 return Status;
mjarvisal 0:e6fcdb78a136 2117 }
mjarvisal 0:e6fcdb78a136 2118
mjarvisal 0:e6fcdb78a136 2119 VL53L0X_Error VL53L0X_PerformXTalkMeasurement(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2120 uint32_t TimeoutMs, FixPoint1616_t *pXtalkPerSpad,
mjarvisal 0:e6fcdb78a136 2121 uint8_t *pAmbientTooHigh)
mjarvisal 0:e6fcdb78a136 2122 {
mjarvisal 0:e6fcdb78a136 2123 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 2124 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2125
mjarvisal 0:e6fcdb78a136 2126 /* not implemented on VL53L0X */
mjarvisal 0:e6fcdb78a136 2127
mjarvisal 0:e6fcdb78a136 2128 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2129 return Status;
mjarvisal 0:e6fcdb78a136 2130 }
mjarvisal 0:e6fcdb78a136 2131
mjarvisal 0:e6fcdb78a136 2132 VL53L0X_Error VL53L0X_PerformXTalkCalibration(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2133 FixPoint1616_t XTalkCalDistance,
mjarvisal 0:e6fcdb78a136 2134 FixPoint1616_t *pXTalkCompensationRateMegaCps)
mjarvisal 0:e6fcdb78a136 2135 {
mjarvisal 0:e6fcdb78a136 2136 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2137 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2138
mjarvisal 0:e6fcdb78a136 2139 Status = VL53L0X_perform_xtalk_calibration(Dev, XTalkCalDistance,
mjarvisal 0:e6fcdb78a136 2140 pXTalkCompensationRateMegaCps);
mjarvisal 0:e6fcdb78a136 2141
mjarvisal 0:e6fcdb78a136 2142 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2143 return Status;
mjarvisal 0:e6fcdb78a136 2144 }
mjarvisal 0:e6fcdb78a136 2145
mjarvisal 0:e6fcdb78a136 2146 VL53L0X_Error VL53L0X_PerformOffsetCalibration(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2147 FixPoint1616_t CalDistanceMilliMeter, int32_t *pOffsetMicroMeter)
mjarvisal 0:e6fcdb78a136 2148 {
mjarvisal 0:e6fcdb78a136 2149 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2150 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2151
mjarvisal 0:e6fcdb78a136 2152 Status = VL53L0X_perform_offset_calibration(Dev, CalDistanceMilliMeter,
mjarvisal 0:e6fcdb78a136 2153 pOffsetMicroMeter);
mjarvisal 0:e6fcdb78a136 2154
mjarvisal 0:e6fcdb78a136 2155 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2156 return Status;
mjarvisal 0:e6fcdb78a136 2157 }
mjarvisal 0:e6fcdb78a136 2158
mjarvisal 0:e6fcdb78a136 2159 VL53L0X_Error VL53L0X_CheckAndLoadInterruptSettings(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2160 uint8_t StartNotStopFlag)
mjarvisal 0:e6fcdb78a136 2161 {
mjarvisal 0:e6fcdb78a136 2162 uint8_t InterruptConfig;
mjarvisal 0:e6fcdb78a136 2163 FixPoint1616_t ThresholdLow;
mjarvisal 0:e6fcdb78a136 2164 FixPoint1616_t ThresholdHigh;
mjarvisal 0:e6fcdb78a136 2165 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2166
mjarvisal 0:e6fcdb78a136 2167 InterruptConfig = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
mjarvisal 0:e6fcdb78a136 2168 Pin0GpioFunctionality);
mjarvisal 0:e6fcdb78a136 2169
mjarvisal 0:e6fcdb78a136 2170 if ((InterruptConfig ==
mjarvisal 0:e6fcdb78a136 2171 VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW) ||
mjarvisal 0:e6fcdb78a136 2172 (InterruptConfig ==
mjarvisal 0:e6fcdb78a136 2173 VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH) ||
mjarvisal 0:e6fcdb78a136 2174 (InterruptConfig ==
mjarvisal 0:e6fcdb78a136 2175 VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT)) {
mjarvisal 0:e6fcdb78a136 2176
mjarvisal 0:e6fcdb78a136 2177 Status = VL53L0X_GetInterruptThresholds(Dev,
mjarvisal 0:e6fcdb78a136 2178 VL53L0X_DEVICEMODE_CONTINUOUS_RANGING,
mjarvisal 0:e6fcdb78a136 2179 &ThresholdLow, &ThresholdHigh);
mjarvisal 0:e6fcdb78a136 2180
mjarvisal 0:e6fcdb78a136 2181 if (((ThresholdLow > 255*65536) ||
mjarvisal 0:e6fcdb78a136 2182 (ThresholdHigh > 255*65536)) &&
mjarvisal 0:e6fcdb78a136 2183 (Status == VL53L0X_ERROR_NONE)) {
mjarvisal 0:e6fcdb78a136 2184
mjarvisal 0:e6fcdb78a136 2185 if (StartNotStopFlag != 0) {
mjarvisal 0:e6fcdb78a136 2186 Status = VL53L0X_load_tuning_settings(Dev,
mjarvisal 0:e6fcdb78a136 2187 InterruptThresholdSettings);
mjarvisal 0:e6fcdb78a136 2188 } else {
mjarvisal 0:e6fcdb78a136 2189 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x04);
mjarvisal 0:e6fcdb78a136 2190 Status |= VL53L0X_WrByte(Dev, 0x70, 0x00);
mjarvisal 0:e6fcdb78a136 2191 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2192 Status |= VL53L0X_WrByte(Dev, 0x80, 0x00);
mjarvisal 0:e6fcdb78a136 2193 }
mjarvisal 0:e6fcdb78a136 2194
mjarvisal 0:e6fcdb78a136 2195 }
mjarvisal 0:e6fcdb78a136 2196
mjarvisal 0:e6fcdb78a136 2197
mjarvisal 0:e6fcdb78a136 2198 }
mjarvisal 0:e6fcdb78a136 2199
mjarvisal 0:e6fcdb78a136 2200 return Status;
mjarvisal 0:e6fcdb78a136 2201
mjarvisal 0:e6fcdb78a136 2202 }
mjarvisal 0:e6fcdb78a136 2203
mjarvisal 0:e6fcdb78a136 2204
mjarvisal 0:e6fcdb78a136 2205 VL53L0X_Error VL53L0X_StartMeasurement(VL53L0X_DEV Dev)
mjarvisal 0:e6fcdb78a136 2206 {
mjarvisal 0:e6fcdb78a136 2207 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2208 VL53L0X_DeviceModes DeviceMode;
mjarvisal 0:e6fcdb78a136 2209 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 2210 uint8_t StartStopByte = VL53L0X_REG_SYSRANGE_MODE_START_STOP;
mjarvisal 0:e6fcdb78a136 2211 uint32_t LoopNb;
mjarvisal 0:e6fcdb78a136 2212 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2213
mjarvisal 0:e6fcdb78a136 2214 /* Get Current DeviceMode */
mjarvisal 0:e6fcdb78a136 2215 VL53L0X_GetDeviceMode(Dev, &DeviceMode);
mjarvisal 0:e6fcdb78a136 2216
mjarvisal 0:e6fcdb78a136 2217 Status = VL53L0X_WrByte(Dev, 0x80, 0x01);
mjarvisal 0:e6fcdb78a136 2218 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2219 Status = VL53L0X_WrByte(Dev, 0x00, 0x00);
mjarvisal 0:e6fcdb78a136 2220 Status = VL53L0X_WrByte(Dev, 0x91, PALDevDataGet(Dev, StopVariable));
mjarvisal 0:e6fcdb78a136 2221 Status = VL53L0X_WrByte(Dev, 0x00, 0x01);
mjarvisal 0:e6fcdb78a136 2222 Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2223 Status = VL53L0X_WrByte(Dev, 0x80, 0x00);
mjarvisal 0:e6fcdb78a136 2224
mjarvisal 0:e6fcdb78a136 2225 switch (DeviceMode) {
mjarvisal 0:e6fcdb78a136 2226 case VL53L0X_DEVICEMODE_SINGLE_RANGING:
mjarvisal 0:e6fcdb78a136 2227 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START, 0x01);
mjarvisal 0:e6fcdb78a136 2228
mjarvisal 0:e6fcdb78a136 2229 Byte = StartStopByte;
mjarvisal 0:e6fcdb78a136 2230 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2231 /* Wait until start bit has been cleared */
mjarvisal 0:e6fcdb78a136 2232 LoopNb = 0;
mjarvisal 0:e6fcdb78a136 2233 do {
mjarvisal 0:e6fcdb78a136 2234 if (LoopNb > 0)
mjarvisal 0:e6fcdb78a136 2235 Status = VL53L0X_RdByte(Dev,
mjarvisal 0:e6fcdb78a136 2236 VL53L0X_REG_SYSRANGE_START, &Byte);
mjarvisal 0:e6fcdb78a136 2237 LoopNb = LoopNb + 1;
mjarvisal 0:e6fcdb78a136 2238 } while (((Byte & StartStopByte) == StartStopByte)
mjarvisal 0:e6fcdb78a136 2239 && (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2240 && (LoopNb < VL53L0X_DEFAULT_MAX_LOOP));
mjarvisal 0:e6fcdb78a136 2241
mjarvisal 0:e6fcdb78a136 2242 if (LoopNb >= VL53L0X_DEFAULT_MAX_LOOP)
mjarvisal 0:e6fcdb78a136 2243 Status = VL53L0X_ERROR_TIME_OUT;
mjarvisal 0:e6fcdb78a136 2244
mjarvisal 0:e6fcdb78a136 2245 }
mjarvisal 0:e6fcdb78a136 2246
mjarvisal 0:e6fcdb78a136 2247 break;
mjarvisal 0:e6fcdb78a136 2248 case VL53L0X_DEVICEMODE_CONTINUOUS_RANGING:
mjarvisal 0:e6fcdb78a136 2249 /* Back-to-back mode */
mjarvisal 0:e6fcdb78a136 2250
mjarvisal 0:e6fcdb78a136 2251 /* Check if need to apply interrupt settings */
mjarvisal 0:e6fcdb78a136 2252 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2253 Status = VL53L0X_CheckAndLoadInterruptSettings(Dev, 1);
mjarvisal 0:e6fcdb78a136 2254
mjarvisal 0:e6fcdb78a136 2255 Status = VL53L0X_WrByte(Dev,
mjarvisal 0:e6fcdb78a136 2256 VL53L0X_REG_SYSRANGE_START,
mjarvisal 0:e6fcdb78a136 2257 VL53L0X_REG_SYSRANGE_MODE_BACKTOBACK);
mjarvisal 0:e6fcdb78a136 2258 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2259 /* Set PAL State to Running */
mjarvisal 0:e6fcdb78a136 2260 PALDevDataSet(Dev, PalState, VL53L0X_STATE_RUNNING);
mjarvisal 0:e6fcdb78a136 2261 }
mjarvisal 0:e6fcdb78a136 2262 break;
mjarvisal 0:e6fcdb78a136 2263 case VL53L0X_DEVICEMODE_CONTINUOUS_TIMED_RANGING:
mjarvisal 0:e6fcdb78a136 2264 /* Continuous mode */
mjarvisal 0:e6fcdb78a136 2265 /* Check if need to apply interrupt settings */
mjarvisal 0:e6fcdb78a136 2266 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2267 Status = VL53L0X_CheckAndLoadInterruptSettings(Dev, 1);
mjarvisal 0:e6fcdb78a136 2268
mjarvisal 0:e6fcdb78a136 2269 Status = VL53L0X_WrByte(Dev,
mjarvisal 0:e6fcdb78a136 2270 VL53L0X_REG_SYSRANGE_START,
mjarvisal 0:e6fcdb78a136 2271 VL53L0X_REG_SYSRANGE_MODE_TIMED);
mjarvisal 0:e6fcdb78a136 2272
mjarvisal 0:e6fcdb78a136 2273 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2274 /* Set PAL State to Running */
mjarvisal 0:e6fcdb78a136 2275 PALDevDataSet(Dev, PalState, VL53L0X_STATE_RUNNING);
mjarvisal 0:e6fcdb78a136 2276 }
mjarvisal 0:e6fcdb78a136 2277 break;
mjarvisal 0:e6fcdb78a136 2278 default:
mjarvisal 0:e6fcdb78a136 2279 /* Selected mode not supported */
mjarvisal 0:e6fcdb78a136 2280 Status = VL53L0X_ERROR_MODE_NOT_SUPPORTED;
mjarvisal 0:e6fcdb78a136 2281 }
mjarvisal 0:e6fcdb78a136 2282
mjarvisal 0:e6fcdb78a136 2283
mjarvisal 0:e6fcdb78a136 2284 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2285 return Status;
mjarvisal 0:e6fcdb78a136 2286 }
mjarvisal 0:e6fcdb78a136 2287
mjarvisal 0:e6fcdb78a136 2288 VL53L0X_Error VL53L0X_StopMeasurement(VL53L0X_DEV Dev)
mjarvisal 0:e6fcdb78a136 2289 {
mjarvisal 0:e6fcdb78a136 2290 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2291 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2292
mjarvisal 0:e6fcdb78a136 2293 Status = VL53L0X_WrByte(Dev, VL53L0X_REG_SYSRANGE_START,
mjarvisal 0:e6fcdb78a136 2294 VL53L0X_REG_SYSRANGE_MODE_SINGLESHOT);
mjarvisal 0:e6fcdb78a136 2295
mjarvisal 0:e6fcdb78a136 2296 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2297 Status = VL53L0X_WrByte(Dev, 0x00, 0x00);
mjarvisal 0:e6fcdb78a136 2298 Status = VL53L0X_WrByte(Dev, 0x91, 0x00);
mjarvisal 0:e6fcdb78a136 2299 Status = VL53L0X_WrByte(Dev, 0x00, 0x01);
mjarvisal 0:e6fcdb78a136 2300 Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2301
mjarvisal 0:e6fcdb78a136 2302 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2303 /* Set PAL State to Idle */
mjarvisal 0:e6fcdb78a136 2304 PALDevDataSet(Dev, PalState, VL53L0X_STATE_IDLE);
mjarvisal 0:e6fcdb78a136 2305 }
mjarvisal 0:e6fcdb78a136 2306
mjarvisal 0:e6fcdb78a136 2307 /* Check if need to apply interrupt settings */
mjarvisal 0:e6fcdb78a136 2308 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2309 Status = VL53L0X_CheckAndLoadInterruptSettings(Dev, 0);
mjarvisal 0:e6fcdb78a136 2310
mjarvisal 0:e6fcdb78a136 2311 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2312 return Status;
mjarvisal 0:e6fcdb78a136 2313 }
mjarvisal 0:e6fcdb78a136 2314
mjarvisal 0:e6fcdb78a136 2315 VL53L0X_Error VL53L0X_GetMeasurementDataReady(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2316 uint8_t *pMeasurementDataReady)
mjarvisal 0:e6fcdb78a136 2317 {
mjarvisal 0:e6fcdb78a136 2318 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2319 uint8_t SysRangeStatusRegister;
mjarvisal 0:e6fcdb78a136 2320 uint8_t InterruptConfig;
mjarvisal 0:e6fcdb78a136 2321 uint32_t InterruptMask;
mjarvisal 0:e6fcdb78a136 2322 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2323
mjarvisal 0:e6fcdb78a136 2324 InterruptConfig = VL53L0X_GETDEVICESPECIFICPARAMETER(Dev,
mjarvisal 0:e6fcdb78a136 2325 Pin0GpioFunctionality);
mjarvisal 0:e6fcdb78a136 2326
mjarvisal 0:e6fcdb78a136 2327 if (InterruptConfig ==
mjarvisal 0:e6fcdb78a136 2328 VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY) {
mjarvisal 0:e6fcdb78a136 2329 Status = VL53L0X_GetInterruptMaskStatus(Dev, &InterruptMask);
mjarvisal 0:e6fcdb78a136 2330 if (InterruptMask ==
mjarvisal 0:e6fcdb78a136 2331 VL53L0X_REG_SYSTEM_INTERRUPT_GPIO_NEW_SAMPLE_READY)
mjarvisal 0:e6fcdb78a136 2332 *pMeasurementDataReady = 1;
mjarvisal 0:e6fcdb78a136 2333 else
mjarvisal 0:e6fcdb78a136 2334 *pMeasurementDataReady = 0;
mjarvisal 0:e6fcdb78a136 2335 } else {
mjarvisal 0:e6fcdb78a136 2336 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_RESULT_RANGE_STATUS,
mjarvisal 0:e6fcdb78a136 2337 &SysRangeStatusRegister);
mjarvisal 0:e6fcdb78a136 2338 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2339 if (SysRangeStatusRegister & 0x01)
mjarvisal 0:e6fcdb78a136 2340 *pMeasurementDataReady = 1;
mjarvisal 0:e6fcdb78a136 2341 else
mjarvisal 0:e6fcdb78a136 2342 *pMeasurementDataReady = 0;
mjarvisal 0:e6fcdb78a136 2343 }
mjarvisal 0:e6fcdb78a136 2344 }
mjarvisal 0:e6fcdb78a136 2345
mjarvisal 0:e6fcdb78a136 2346 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2347 return Status;
mjarvisal 0:e6fcdb78a136 2348 }
mjarvisal 0:e6fcdb78a136 2349
mjarvisal 0:e6fcdb78a136 2350 VL53L0X_Error VL53L0X_WaitDeviceReadyForNewMeasurement(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2351 uint32_t MaxLoop)
mjarvisal 0:e6fcdb78a136 2352 {
mjarvisal 0:e6fcdb78a136 2353 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 2354 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2355
mjarvisal 0:e6fcdb78a136 2356 /* not implemented for VL53L0X */
mjarvisal 0:e6fcdb78a136 2357
mjarvisal 0:e6fcdb78a136 2358 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2359 return Status;
mjarvisal 0:e6fcdb78a136 2360 }
mjarvisal 0:e6fcdb78a136 2361
mjarvisal 0:e6fcdb78a136 2362
mjarvisal 0:e6fcdb78a136 2363 VL53L0X_Error VL53L0X_GetRangingMeasurementData(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2364 VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
mjarvisal 0:e6fcdb78a136 2365 {
mjarvisal 0:e6fcdb78a136 2366 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2367 uint8_t DeviceRangeStatus;
mjarvisal 0:e6fcdb78a136 2368 uint8_t RangeFractionalEnable;
mjarvisal 0:e6fcdb78a136 2369 uint8_t PalRangeStatus;
mjarvisal 0:e6fcdb78a136 2370 uint8_t XTalkCompensationEnable;
mjarvisal 0:e6fcdb78a136 2371 uint16_t AmbientRate;
mjarvisal 0:e6fcdb78a136 2372 FixPoint1616_t SignalRate;
mjarvisal 0:e6fcdb78a136 2373 uint16_t XTalkCompensationRateMegaCps;
mjarvisal 0:e6fcdb78a136 2374 uint16_t EffectiveSpadRtnCount;
mjarvisal 0:e6fcdb78a136 2375 uint16_t tmpuint16;
mjarvisal 0:e6fcdb78a136 2376 uint16_t XtalkRangeMilliMeter;
mjarvisal 0:e6fcdb78a136 2377 uint16_t LinearityCorrectiveGain;
mjarvisal 0:e6fcdb78a136 2378 uint8_t localBuffer[12];
mjarvisal 0:e6fcdb78a136 2379 VL53L0X_RangingMeasurementData_t LastRangeDataBuffer;
mjarvisal 0:e6fcdb78a136 2380
mjarvisal 0:e6fcdb78a136 2381 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2382
mjarvisal 0:e6fcdb78a136 2383 /*
mjarvisal 0:e6fcdb78a136 2384 * use multi read even if some registers are not useful, result will
mjarvisal 0:e6fcdb78a136 2385 * be more efficient
mjarvisal 0:e6fcdb78a136 2386 * start reading at 0x14 dec20
mjarvisal 0:e6fcdb78a136 2387 * end reading at 0x21 dec33 total 14 bytes to read
mjarvisal 0:e6fcdb78a136 2388 */
mjarvisal 0:e6fcdb78a136 2389 Status = VL53L0X_ReadMulti(Dev, 0x14, localBuffer, 12);
mjarvisal 0:e6fcdb78a136 2390
mjarvisal 0:e6fcdb78a136 2391 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2392
mjarvisal 0:e6fcdb78a136 2393 pRangingMeasurementData->ZoneId = 0; /* Only one zone */
mjarvisal 0:e6fcdb78a136 2394 pRangingMeasurementData->TimeStamp = 0; /* Not Implemented */
mjarvisal 0:e6fcdb78a136 2395
mjarvisal 0:e6fcdb78a136 2396 tmpuint16 = VL53L0X_MAKEUINT16(localBuffer[11], localBuffer[10]);
mjarvisal 0:e6fcdb78a136 2397 /* cut1.1 if SYSTEM__RANGE_CONFIG if 1 range is 2bits fractional
mjarvisal 0:e6fcdb78a136 2398 *(format 11.2) else no fractional
mjarvisal 0:e6fcdb78a136 2399 */
mjarvisal 0:e6fcdb78a136 2400
mjarvisal 0:e6fcdb78a136 2401 pRangingMeasurementData->MeasurementTimeUsec = 0;
mjarvisal 0:e6fcdb78a136 2402
mjarvisal 0:e6fcdb78a136 2403 SignalRate = VL53L0X_FIXPOINT97TOFIXPOINT1616(
mjarvisal 0:e6fcdb78a136 2404 VL53L0X_MAKEUINT16(localBuffer[7], localBuffer[6]));
mjarvisal 0:e6fcdb78a136 2405 /* peak_signal_count_rate_rtn_mcps */
mjarvisal 0:e6fcdb78a136 2406 pRangingMeasurementData->SignalRateRtnMegaCps = SignalRate;
mjarvisal 0:e6fcdb78a136 2407
mjarvisal 0:e6fcdb78a136 2408 AmbientRate = VL53L0X_MAKEUINT16(localBuffer[9], localBuffer[8]);
mjarvisal 0:e6fcdb78a136 2409 pRangingMeasurementData->AmbientRateRtnMegaCps =
mjarvisal 0:e6fcdb78a136 2410 VL53L0X_FIXPOINT97TOFIXPOINT1616(AmbientRate);
mjarvisal 0:e6fcdb78a136 2411
mjarvisal 0:e6fcdb78a136 2412 EffectiveSpadRtnCount = VL53L0X_MAKEUINT16(localBuffer[3],
mjarvisal 0:e6fcdb78a136 2413 localBuffer[2]);
mjarvisal 0:e6fcdb78a136 2414 /* EffectiveSpadRtnCount is 8.8 format */
mjarvisal 0:e6fcdb78a136 2415 pRangingMeasurementData->EffectiveSpadRtnCount =
mjarvisal 0:e6fcdb78a136 2416 EffectiveSpadRtnCount;
mjarvisal 0:e6fcdb78a136 2417
mjarvisal 0:e6fcdb78a136 2418 DeviceRangeStatus = localBuffer[0];
mjarvisal 0:e6fcdb78a136 2419
mjarvisal 0:e6fcdb78a136 2420 /* Get Linearity Corrective Gain */
mjarvisal 0:e6fcdb78a136 2421 LinearityCorrectiveGain = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 2422 LinearityCorrectiveGain);
mjarvisal 0:e6fcdb78a136 2423
mjarvisal 0:e6fcdb78a136 2424 /* Get ranging configuration */
mjarvisal 0:e6fcdb78a136 2425 RangeFractionalEnable = PALDevDataGet(Dev,
mjarvisal 0:e6fcdb78a136 2426 RangeFractionalEnable);
mjarvisal 0:e6fcdb78a136 2427
mjarvisal 0:e6fcdb78a136 2428 if (LinearityCorrectiveGain != 1000) {
mjarvisal 0:e6fcdb78a136 2429
mjarvisal 0:e6fcdb78a136 2430 tmpuint16 = (uint16_t)((LinearityCorrectiveGain
mjarvisal 0:e6fcdb78a136 2431 * tmpuint16 + 500) / 1000);
mjarvisal 0:e6fcdb78a136 2432
mjarvisal 0:e6fcdb78a136 2433 /* Implement Xtalk */
mjarvisal 0:e6fcdb78a136 2434 VL53L0X_GETPARAMETERFIELD(Dev,
mjarvisal 0:e6fcdb78a136 2435 XTalkCompensationRateMegaCps,
mjarvisal 0:e6fcdb78a136 2436 XTalkCompensationRateMegaCps);
mjarvisal 0:e6fcdb78a136 2437 VL53L0X_GETPARAMETERFIELD(Dev, XTalkCompensationEnable,
mjarvisal 0:e6fcdb78a136 2438 XTalkCompensationEnable);
mjarvisal 0:e6fcdb78a136 2439
mjarvisal 0:e6fcdb78a136 2440 if (XTalkCompensationEnable) {
mjarvisal 0:e6fcdb78a136 2441
mjarvisal 0:e6fcdb78a136 2442 if ((SignalRate
mjarvisal 0:e6fcdb78a136 2443 - ((XTalkCompensationRateMegaCps
mjarvisal 0:e6fcdb78a136 2444 * EffectiveSpadRtnCount) >> 8))
mjarvisal 0:e6fcdb78a136 2445 <= 0) {
mjarvisal 0:e6fcdb78a136 2446 if (RangeFractionalEnable)
mjarvisal 0:e6fcdb78a136 2447 XtalkRangeMilliMeter = 8888;
mjarvisal 0:e6fcdb78a136 2448 else
mjarvisal 0:e6fcdb78a136 2449 XtalkRangeMilliMeter = 8888
mjarvisal 0:e6fcdb78a136 2450 << 2;
mjarvisal 0:e6fcdb78a136 2451 } else {
mjarvisal 0:e6fcdb78a136 2452 XtalkRangeMilliMeter =
mjarvisal 0:e6fcdb78a136 2453 (tmpuint16 * SignalRate)
mjarvisal 0:e6fcdb78a136 2454 / (SignalRate
mjarvisal 0:e6fcdb78a136 2455 - ((XTalkCompensationRateMegaCps
mjarvisal 0:e6fcdb78a136 2456 * EffectiveSpadRtnCount)
mjarvisal 0:e6fcdb78a136 2457 >> 8));
mjarvisal 0:e6fcdb78a136 2458 }
mjarvisal 0:e6fcdb78a136 2459
mjarvisal 0:e6fcdb78a136 2460 tmpuint16 = XtalkRangeMilliMeter;
mjarvisal 0:e6fcdb78a136 2461 }
mjarvisal 0:e6fcdb78a136 2462
mjarvisal 0:e6fcdb78a136 2463 }
mjarvisal 0:e6fcdb78a136 2464
mjarvisal 0:e6fcdb78a136 2465 if (RangeFractionalEnable) {
mjarvisal 0:e6fcdb78a136 2466 pRangingMeasurementData->RangeMilliMeter =
mjarvisal 0:e6fcdb78a136 2467 (uint16_t)((tmpuint16) >> 2);
mjarvisal 0:e6fcdb78a136 2468 pRangingMeasurementData->RangeFractionalPart =
mjarvisal 0:e6fcdb78a136 2469 (uint8_t)((tmpuint16 & 0x03) << 6);
mjarvisal 0:e6fcdb78a136 2470 } else {
mjarvisal 0:e6fcdb78a136 2471 pRangingMeasurementData->RangeMilliMeter = tmpuint16;
mjarvisal 0:e6fcdb78a136 2472 pRangingMeasurementData->RangeFractionalPart = 0;
mjarvisal 0:e6fcdb78a136 2473 }
mjarvisal 0:e6fcdb78a136 2474
mjarvisal 0:e6fcdb78a136 2475 /*
mjarvisal 0:e6fcdb78a136 2476 * For a standard definition of RangeStatus, this should
mjarvisal 0:e6fcdb78a136 2477 * return 0 in case of good result after a ranging
mjarvisal 0:e6fcdb78a136 2478 * The range status depends on the device so call a device
mjarvisal 0:e6fcdb78a136 2479 * specific function to obtain the right Status.
mjarvisal 0:e6fcdb78a136 2480 */
mjarvisal 0:e6fcdb78a136 2481 Status |= VL53L0X_get_pal_range_status(Dev, DeviceRangeStatus,
mjarvisal 0:e6fcdb78a136 2482 SignalRate, EffectiveSpadRtnCount,
mjarvisal 0:e6fcdb78a136 2483 pRangingMeasurementData, &PalRangeStatus);
mjarvisal 0:e6fcdb78a136 2484
mjarvisal 0:e6fcdb78a136 2485 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2486 pRangingMeasurementData->RangeStatus = PalRangeStatus;
mjarvisal 0:e6fcdb78a136 2487
mjarvisal 0:e6fcdb78a136 2488 }
mjarvisal 0:e6fcdb78a136 2489
mjarvisal 0:e6fcdb78a136 2490 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2491 /* Copy last read data into Dev buffer */
mjarvisal 0:e6fcdb78a136 2492 LastRangeDataBuffer = PALDevDataGet(Dev, LastRangeMeasure);
mjarvisal 0:e6fcdb78a136 2493
mjarvisal 0:e6fcdb78a136 2494 LastRangeDataBuffer.RangeMilliMeter =
mjarvisal 0:e6fcdb78a136 2495 pRangingMeasurementData->RangeMilliMeter;
mjarvisal 0:e6fcdb78a136 2496 LastRangeDataBuffer.RangeFractionalPart =
mjarvisal 0:e6fcdb78a136 2497 pRangingMeasurementData->RangeFractionalPart;
mjarvisal 0:e6fcdb78a136 2498 LastRangeDataBuffer.RangeDMaxMilliMeter =
mjarvisal 0:e6fcdb78a136 2499 pRangingMeasurementData->RangeDMaxMilliMeter;
mjarvisal 0:e6fcdb78a136 2500 LastRangeDataBuffer.MeasurementTimeUsec =
mjarvisal 0:e6fcdb78a136 2501 pRangingMeasurementData->MeasurementTimeUsec;
mjarvisal 0:e6fcdb78a136 2502 LastRangeDataBuffer.SignalRateRtnMegaCps =
mjarvisal 0:e6fcdb78a136 2503 pRangingMeasurementData->SignalRateRtnMegaCps;
mjarvisal 0:e6fcdb78a136 2504 LastRangeDataBuffer.AmbientRateRtnMegaCps =
mjarvisal 0:e6fcdb78a136 2505 pRangingMeasurementData->AmbientRateRtnMegaCps;
mjarvisal 0:e6fcdb78a136 2506 LastRangeDataBuffer.EffectiveSpadRtnCount =
mjarvisal 0:e6fcdb78a136 2507 pRangingMeasurementData->EffectiveSpadRtnCount;
mjarvisal 0:e6fcdb78a136 2508 LastRangeDataBuffer.RangeStatus =
mjarvisal 0:e6fcdb78a136 2509 pRangingMeasurementData->RangeStatus;
mjarvisal 0:e6fcdb78a136 2510
mjarvisal 0:e6fcdb78a136 2511 PALDevDataSet(Dev, LastRangeMeasure, LastRangeDataBuffer);
mjarvisal 0:e6fcdb78a136 2512 }
mjarvisal 0:e6fcdb78a136 2513
mjarvisal 0:e6fcdb78a136 2514 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2515 return Status;
mjarvisal 0:e6fcdb78a136 2516 }
mjarvisal 0:e6fcdb78a136 2517
mjarvisal 0:e6fcdb78a136 2518 VL53L0X_Error VL53L0X_GetMeasurementRefSignal(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2519 FixPoint1616_t *pMeasurementRefSignal)
mjarvisal 0:e6fcdb78a136 2520 {
mjarvisal 0:e6fcdb78a136 2521 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2522 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2523
mjarvisal 0:e6fcdb78a136 2524 *pMeasurementRefSignal = PALDevDataGet(Dev, LastSignalRefMcps);
mjarvisal 0:e6fcdb78a136 2525
mjarvisal 0:e6fcdb78a136 2526 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2527 return Status;
mjarvisal 0:e6fcdb78a136 2528
mjarvisal 0:e6fcdb78a136 2529 }
mjarvisal 0:e6fcdb78a136 2530
mjarvisal 0:e6fcdb78a136 2531 VL53L0X_Error VL53L0X_GetHistogramMeasurementData(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2532 VL53L0X_HistogramMeasurementData_t *pHistogramMeasurementData)
mjarvisal 0:e6fcdb78a136 2533 {
mjarvisal 0:e6fcdb78a136 2534 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 2535 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2536
mjarvisal 0:e6fcdb78a136 2537 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2538 return Status;
mjarvisal 0:e6fcdb78a136 2539 }
mjarvisal 0:e6fcdb78a136 2540
mjarvisal 0:e6fcdb78a136 2541 VL53L0X_Error VL53L0X_PerformSingleRangingMeasurement(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2542 VL53L0X_RangingMeasurementData_t *pRangingMeasurementData)
mjarvisal 0:e6fcdb78a136 2543 {
mjarvisal 0:e6fcdb78a136 2544 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2545
mjarvisal 0:e6fcdb78a136 2546 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2547
mjarvisal 0:e6fcdb78a136 2548 /* This function will do a complete single ranging
mjarvisal 0:e6fcdb78a136 2549 * Here we fix the mode! */
mjarvisal 0:e6fcdb78a136 2550 Status = VL53L0X_SetDeviceMode(Dev, VL53L0X_DEVICEMODE_SINGLE_RANGING);
mjarvisal 0:e6fcdb78a136 2551
mjarvisal 0:e6fcdb78a136 2552 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2553 Status = VL53L0X_PerformSingleMeasurement(Dev);
mjarvisal 0:e6fcdb78a136 2554
mjarvisal 0:e6fcdb78a136 2555
mjarvisal 0:e6fcdb78a136 2556 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2557 Status = VL53L0X_GetRangingMeasurementData(Dev,
mjarvisal 0:e6fcdb78a136 2558 pRangingMeasurementData);
mjarvisal 0:e6fcdb78a136 2559
mjarvisal 0:e6fcdb78a136 2560
mjarvisal 0:e6fcdb78a136 2561 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2562 Status = VL53L0X_ClearInterruptMask(Dev, 0);
mjarvisal 0:e6fcdb78a136 2563
mjarvisal 0:e6fcdb78a136 2564
mjarvisal 0:e6fcdb78a136 2565 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2566 return Status;
mjarvisal 0:e6fcdb78a136 2567 }
mjarvisal 0:e6fcdb78a136 2568
mjarvisal 0:e6fcdb78a136 2569 VL53L0X_Error VL53L0X_SetNumberOfROIZones(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2570 uint8_t NumberOfROIZones)
mjarvisal 0:e6fcdb78a136 2571 {
mjarvisal 0:e6fcdb78a136 2572 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2573
mjarvisal 0:e6fcdb78a136 2574 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2575
mjarvisal 0:e6fcdb78a136 2576 if (NumberOfROIZones != 1)
mjarvisal 0:e6fcdb78a136 2577 Status = VL53L0X_ERROR_INVALID_PARAMS;
mjarvisal 0:e6fcdb78a136 2578
mjarvisal 0:e6fcdb78a136 2579
mjarvisal 0:e6fcdb78a136 2580 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2581 return Status;
mjarvisal 0:e6fcdb78a136 2582 }
mjarvisal 0:e6fcdb78a136 2583
mjarvisal 0:e6fcdb78a136 2584 VL53L0X_Error VL53L0X_GetNumberOfROIZones(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2585 uint8_t *pNumberOfROIZones)
mjarvisal 0:e6fcdb78a136 2586 {
mjarvisal 0:e6fcdb78a136 2587 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2588
mjarvisal 0:e6fcdb78a136 2589 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2590
mjarvisal 0:e6fcdb78a136 2591 *pNumberOfROIZones = 1;
mjarvisal 0:e6fcdb78a136 2592
mjarvisal 0:e6fcdb78a136 2593 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2594 return Status;
mjarvisal 0:e6fcdb78a136 2595 }
mjarvisal 0:e6fcdb78a136 2596
mjarvisal 0:e6fcdb78a136 2597 VL53L0X_Error VL53L0X_GetMaxNumberOfROIZones(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2598 uint8_t *pMaxNumberOfROIZones)
mjarvisal 0:e6fcdb78a136 2599 {
mjarvisal 0:e6fcdb78a136 2600 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2601
mjarvisal 0:e6fcdb78a136 2602 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2603
mjarvisal 0:e6fcdb78a136 2604 *pMaxNumberOfROIZones = 1;
mjarvisal 0:e6fcdb78a136 2605
mjarvisal 0:e6fcdb78a136 2606 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2607 return Status;
mjarvisal 0:e6fcdb78a136 2608 }
mjarvisal 0:e6fcdb78a136 2609
mjarvisal 0:e6fcdb78a136 2610 /* End Group PAL Measurement Functions */
mjarvisal 0:e6fcdb78a136 2611
mjarvisal 0:e6fcdb78a136 2612 VL53L0X_Error VL53L0X_SetGpioConfig(VL53L0X_DEV Dev, uint8_t Pin,
mjarvisal 0:e6fcdb78a136 2613 VL53L0X_DeviceModes DeviceMode, VL53L0X_GpioFunctionality Functionality,
mjarvisal 0:e6fcdb78a136 2614 VL53L0X_InterruptPolarity Polarity)
mjarvisal 0:e6fcdb78a136 2615 {
mjarvisal 0:e6fcdb78a136 2616 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2617 uint8_t data;
mjarvisal 0:e6fcdb78a136 2618
mjarvisal 0:e6fcdb78a136 2619 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2620
mjarvisal 0:e6fcdb78a136 2621 if (Pin != 0) {
mjarvisal 0:e6fcdb78a136 2622 Status = VL53L0X_ERROR_GPIO_NOT_EXISTING;
mjarvisal 0:e6fcdb78a136 2623 } else if (DeviceMode == VL53L0X_DEVICEMODE_GPIO_DRIVE) {
mjarvisal 0:e6fcdb78a136 2624 if (Polarity == VL53L0X_INTERRUPTPOLARITY_LOW)
mjarvisal 0:e6fcdb78a136 2625 data = 0x10;
mjarvisal 0:e6fcdb78a136 2626 else
mjarvisal 0:e6fcdb78a136 2627 data = 1;
mjarvisal 0:e6fcdb78a136 2628
mjarvisal 0:e6fcdb78a136 2629 Status = VL53L0X_WrByte(Dev,
mjarvisal 0:e6fcdb78a136 2630 VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH, data);
mjarvisal 0:e6fcdb78a136 2631
mjarvisal 0:e6fcdb78a136 2632 } else if (DeviceMode == VL53L0X_DEVICEMODE_GPIO_OSC) {
mjarvisal 0:e6fcdb78a136 2633
mjarvisal 0:e6fcdb78a136 2634 Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
mjarvisal 0:e6fcdb78a136 2635 Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
mjarvisal 0:e6fcdb78a136 2636
mjarvisal 0:e6fcdb78a136 2637 Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
mjarvisal 0:e6fcdb78a136 2638 Status |= VL53L0X_WrByte(Dev, 0x80, 0x01);
mjarvisal 0:e6fcdb78a136 2639 Status |= VL53L0X_WrByte(Dev, 0x85, 0x02);
mjarvisal 0:e6fcdb78a136 2640
mjarvisal 0:e6fcdb78a136 2641 Status |= VL53L0X_WrByte(Dev, 0xff, 0x04);
mjarvisal 0:e6fcdb78a136 2642 Status |= VL53L0X_WrByte(Dev, 0xcd, 0x00);
mjarvisal 0:e6fcdb78a136 2643 Status |= VL53L0X_WrByte(Dev, 0xcc, 0x11);
mjarvisal 0:e6fcdb78a136 2644
mjarvisal 0:e6fcdb78a136 2645 Status |= VL53L0X_WrByte(Dev, 0xff, 0x07);
mjarvisal 0:e6fcdb78a136 2646 Status |= VL53L0X_WrByte(Dev, 0xbe, 0x00);
mjarvisal 0:e6fcdb78a136 2647
mjarvisal 0:e6fcdb78a136 2648 Status |= VL53L0X_WrByte(Dev, 0xff, 0x06);
mjarvisal 0:e6fcdb78a136 2649 Status |= VL53L0X_WrByte(Dev, 0xcc, 0x09);
mjarvisal 0:e6fcdb78a136 2650
mjarvisal 0:e6fcdb78a136 2651 Status |= VL53L0X_WrByte(Dev, 0xff, 0x00);
mjarvisal 0:e6fcdb78a136 2652 Status |= VL53L0X_WrByte(Dev, 0xff, 0x01);
mjarvisal 0:e6fcdb78a136 2653 Status |= VL53L0X_WrByte(Dev, 0x00, 0x00);
mjarvisal 0:e6fcdb78a136 2654
mjarvisal 0:e6fcdb78a136 2655 } else {
mjarvisal 0:e6fcdb78a136 2656
mjarvisal 0:e6fcdb78a136 2657 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2658 switch (Functionality) {
mjarvisal 0:e6fcdb78a136 2659 case VL53L0X_GPIOFUNCTIONALITY_OFF:
mjarvisal 0:e6fcdb78a136 2660 data = 0x00;
mjarvisal 0:e6fcdb78a136 2661 break;
mjarvisal 0:e6fcdb78a136 2662 case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW:
mjarvisal 0:e6fcdb78a136 2663 data = 0x01;
mjarvisal 0:e6fcdb78a136 2664 break;
mjarvisal 0:e6fcdb78a136 2665 case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH:
mjarvisal 0:e6fcdb78a136 2666 data = 0x02;
mjarvisal 0:e6fcdb78a136 2667 break;
mjarvisal 0:e6fcdb78a136 2668 case VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT:
mjarvisal 0:e6fcdb78a136 2669 data = 0x03;
mjarvisal 0:e6fcdb78a136 2670 break;
mjarvisal 0:e6fcdb78a136 2671 case VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY:
mjarvisal 0:e6fcdb78a136 2672 data = 0x04;
mjarvisal 0:e6fcdb78a136 2673 break;
mjarvisal 0:e6fcdb78a136 2674 default:
mjarvisal 0:e6fcdb78a136 2675 Status =
mjarvisal 0:e6fcdb78a136 2676 VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
mjarvisal 0:e6fcdb78a136 2677 }
mjarvisal 0:e6fcdb78a136 2678 }
mjarvisal 0:e6fcdb78a136 2679
mjarvisal 0:e6fcdb78a136 2680 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2681 Status = VL53L0X_WrByte(Dev,
mjarvisal 0:e6fcdb78a136 2682 VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, data);
mjarvisal 0:e6fcdb78a136 2683
mjarvisal 0:e6fcdb78a136 2684 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2685 if (Polarity == VL53L0X_INTERRUPTPOLARITY_LOW)
mjarvisal 0:e6fcdb78a136 2686 data = 0;
mjarvisal 0:e6fcdb78a136 2687 else
mjarvisal 0:e6fcdb78a136 2688 data = (uint8_t)(1 << 4);
mjarvisal 0:e6fcdb78a136 2689
mjarvisal 0:e6fcdb78a136 2690 Status = VL53L0X_UpdateByte(Dev,
mjarvisal 0:e6fcdb78a136 2691 VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH, 0xEF, data);
mjarvisal 0:e6fcdb78a136 2692 }
mjarvisal 0:e6fcdb78a136 2693
mjarvisal 0:e6fcdb78a136 2694 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2695 VL53L0X_SETDEVICESPECIFICPARAMETER(Dev,
mjarvisal 0:e6fcdb78a136 2696 Pin0GpioFunctionality, Functionality);
mjarvisal 0:e6fcdb78a136 2697
mjarvisal 0:e6fcdb78a136 2698 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2699 Status = VL53L0X_ClearInterruptMask(Dev, 0);
mjarvisal 0:e6fcdb78a136 2700
mjarvisal 0:e6fcdb78a136 2701 }
mjarvisal 0:e6fcdb78a136 2702
mjarvisal 0:e6fcdb78a136 2703 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2704 return Status;
mjarvisal 0:e6fcdb78a136 2705 }
mjarvisal 0:e6fcdb78a136 2706
mjarvisal 0:e6fcdb78a136 2707 VL53L0X_Error VL53L0X_GetGpioConfig(VL53L0X_DEV Dev, uint8_t Pin,
mjarvisal 0:e6fcdb78a136 2708 VL53L0X_DeviceModes *pDeviceMode,
mjarvisal 0:e6fcdb78a136 2709 VL53L0X_GpioFunctionality *pFunctionality,
mjarvisal 0:e6fcdb78a136 2710 VL53L0X_InterruptPolarity *pPolarity)
mjarvisal 0:e6fcdb78a136 2711 {
mjarvisal 0:e6fcdb78a136 2712 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2713 VL53L0X_GpioFunctionality GpioFunctionality;
mjarvisal 0:e6fcdb78a136 2714 uint8_t data;
mjarvisal 0:e6fcdb78a136 2715
mjarvisal 0:e6fcdb78a136 2716 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2717
mjarvisal 0:e6fcdb78a136 2718 /* pDeviceMode not managed by Ewok it return the current mode */
mjarvisal 0:e6fcdb78a136 2719
mjarvisal 0:e6fcdb78a136 2720 Status = VL53L0X_GetDeviceMode(Dev, pDeviceMode);
mjarvisal 0:e6fcdb78a136 2721
mjarvisal 0:e6fcdb78a136 2722 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2723 if (Pin != 0) {
mjarvisal 0:e6fcdb78a136 2724 Status = VL53L0X_ERROR_GPIO_NOT_EXISTING;
mjarvisal 0:e6fcdb78a136 2725 } else {
mjarvisal 0:e6fcdb78a136 2726 Status = VL53L0X_RdByte(Dev,
mjarvisal 0:e6fcdb78a136 2727 VL53L0X_REG_SYSTEM_INTERRUPT_CONFIG_GPIO, &data);
mjarvisal 0:e6fcdb78a136 2728 }
mjarvisal 0:e6fcdb78a136 2729 }
mjarvisal 0:e6fcdb78a136 2730
mjarvisal 0:e6fcdb78a136 2731 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2732 switch (data & 0x07) {
mjarvisal 0:e6fcdb78a136 2733 case 0x00:
mjarvisal 0:e6fcdb78a136 2734 GpioFunctionality = VL53L0X_GPIOFUNCTIONALITY_OFF;
mjarvisal 0:e6fcdb78a136 2735 break;
mjarvisal 0:e6fcdb78a136 2736 case 0x01:
mjarvisal 0:e6fcdb78a136 2737 GpioFunctionality =
mjarvisal 0:e6fcdb78a136 2738 VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_LOW;
mjarvisal 0:e6fcdb78a136 2739 break;
mjarvisal 0:e6fcdb78a136 2740 case 0x02:
mjarvisal 0:e6fcdb78a136 2741 GpioFunctionality =
mjarvisal 0:e6fcdb78a136 2742 VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_HIGH;
mjarvisal 0:e6fcdb78a136 2743 break;
mjarvisal 0:e6fcdb78a136 2744 case 0x03:
mjarvisal 0:e6fcdb78a136 2745 GpioFunctionality =
mjarvisal 0:e6fcdb78a136 2746 VL53L0X_GPIOFUNCTIONALITY_THRESHOLD_CROSSED_OUT;
mjarvisal 0:e6fcdb78a136 2747 break;
mjarvisal 0:e6fcdb78a136 2748 case 0x04:
mjarvisal 0:e6fcdb78a136 2749 GpioFunctionality =
mjarvisal 0:e6fcdb78a136 2750 VL53L0X_GPIOFUNCTIONALITY_NEW_MEASURE_READY;
mjarvisal 0:e6fcdb78a136 2751 break;
mjarvisal 0:e6fcdb78a136 2752 default:
mjarvisal 0:e6fcdb78a136 2753 Status = VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED;
mjarvisal 0:e6fcdb78a136 2754 }
mjarvisal 0:e6fcdb78a136 2755 }
mjarvisal 0:e6fcdb78a136 2756
mjarvisal 0:e6fcdb78a136 2757 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2758 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_GPIO_HV_MUX_ACTIVE_HIGH,
mjarvisal 0:e6fcdb78a136 2759 &data);
mjarvisal 0:e6fcdb78a136 2760
mjarvisal 0:e6fcdb78a136 2761 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2762 if ((data & (uint8_t)(1 << 4)) == 0)
mjarvisal 0:e6fcdb78a136 2763 *pPolarity = VL53L0X_INTERRUPTPOLARITY_LOW;
mjarvisal 0:e6fcdb78a136 2764 else
mjarvisal 0:e6fcdb78a136 2765 *pPolarity = VL53L0X_INTERRUPTPOLARITY_HIGH;
mjarvisal 0:e6fcdb78a136 2766 }
mjarvisal 0:e6fcdb78a136 2767
mjarvisal 0:e6fcdb78a136 2768 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2769 *pFunctionality = GpioFunctionality;
mjarvisal 0:e6fcdb78a136 2770 VL53L0X_SETDEVICESPECIFICPARAMETER(Dev, Pin0GpioFunctionality,
mjarvisal 0:e6fcdb78a136 2771 GpioFunctionality);
mjarvisal 0:e6fcdb78a136 2772 }
mjarvisal 0:e6fcdb78a136 2773
mjarvisal 0:e6fcdb78a136 2774 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2775 return Status;
mjarvisal 0:e6fcdb78a136 2776 }
mjarvisal 0:e6fcdb78a136 2777
mjarvisal 0:e6fcdb78a136 2778 VL53L0X_Error VL53L0X_SetInterruptThresholds(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2779 VL53L0X_DeviceModes DeviceMode, FixPoint1616_t ThresholdLow,
mjarvisal 0:e6fcdb78a136 2780 FixPoint1616_t ThresholdHigh)
mjarvisal 0:e6fcdb78a136 2781 {
mjarvisal 0:e6fcdb78a136 2782 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2783 uint16_t Threshold16;
mjarvisal 0:e6fcdb78a136 2784 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2785
mjarvisal 0:e6fcdb78a136 2786 /* no dependency on DeviceMode for Ewok */
mjarvisal 0:e6fcdb78a136 2787 /* Need to divide by 2 because the FW will apply a x2 */
mjarvisal 0:e6fcdb78a136 2788 Threshold16 = (uint16_t)((ThresholdLow >> 17) & 0x00fff);
mjarvisal 0:e6fcdb78a136 2789 Status = VL53L0X_WrWord(Dev, VL53L0X_REG_SYSTEM_THRESH_LOW, Threshold16);
mjarvisal 0:e6fcdb78a136 2790
mjarvisal 0:e6fcdb78a136 2791 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2792 /* Need to divide by 2 because the FW will apply a x2 */
mjarvisal 0:e6fcdb78a136 2793 Threshold16 = (uint16_t)((ThresholdHigh >> 17) & 0x00fff);
mjarvisal 0:e6fcdb78a136 2794 Status = VL53L0X_WrWord(Dev, VL53L0X_REG_SYSTEM_THRESH_HIGH,
mjarvisal 0:e6fcdb78a136 2795 Threshold16);
mjarvisal 0:e6fcdb78a136 2796 }
mjarvisal 0:e6fcdb78a136 2797
mjarvisal 0:e6fcdb78a136 2798 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2799 return Status;
mjarvisal 0:e6fcdb78a136 2800 }
mjarvisal 0:e6fcdb78a136 2801
mjarvisal 0:e6fcdb78a136 2802 VL53L0X_Error VL53L0X_GetInterruptThresholds(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2803 VL53L0X_DeviceModes DeviceMode, FixPoint1616_t *pThresholdLow,
mjarvisal 0:e6fcdb78a136 2804 FixPoint1616_t *pThresholdHigh)
mjarvisal 0:e6fcdb78a136 2805 {
mjarvisal 0:e6fcdb78a136 2806 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2807 uint16_t Threshold16;
mjarvisal 0:e6fcdb78a136 2808 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2809
mjarvisal 0:e6fcdb78a136 2810 /* no dependency on DeviceMode for Ewok */
mjarvisal 0:e6fcdb78a136 2811
mjarvisal 0:e6fcdb78a136 2812 Status = VL53L0X_RdWord(Dev, VL53L0X_REG_SYSTEM_THRESH_LOW, &Threshold16);
mjarvisal 0:e6fcdb78a136 2813 /* Need to multiply by 2 because the FW will apply a x2 */
mjarvisal 0:e6fcdb78a136 2814 *pThresholdLow = (FixPoint1616_t)((0x00fff & Threshold16) << 17);
mjarvisal 0:e6fcdb78a136 2815
mjarvisal 0:e6fcdb78a136 2816 if (Status == VL53L0X_ERROR_NONE) {
mjarvisal 0:e6fcdb78a136 2817 Status = VL53L0X_RdWord(Dev, VL53L0X_REG_SYSTEM_THRESH_HIGH,
mjarvisal 0:e6fcdb78a136 2818 &Threshold16);
mjarvisal 0:e6fcdb78a136 2819 /* Need to multiply by 2 because the FW will apply a x2 */
mjarvisal 0:e6fcdb78a136 2820 *pThresholdHigh =
mjarvisal 0:e6fcdb78a136 2821 (FixPoint1616_t)((0x00fff & Threshold16) << 17);
mjarvisal 0:e6fcdb78a136 2822 }
mjarvisal 0:e6fcdb78a136 2823
mjarvisal 0:e6fcdb78a136 2824 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2825 return Status;
mjarvisal 0:e6fcdb78a136 2826 }
mjarvisal 0:e6fcdb78a136 2827
mjarvisal 0:e6fcdb78a136 2828 VL53L0X_Error VL53L0X_GetStopCompletedStatus(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2829 uint32_t *pStopStatus)
mjarvisal 0:e6fcdb78a136 2830 {
mjarvisal 0:e6fcdb78a136 2831 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2832 uint8_t Byte = 0;
mjarvisal 0:e6fcdb78a136 2833 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2834
mjarvisal 0:e6fcdb78a136 2835 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2836
mjarvisal 0:e6fcdb78a136 2837 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2838 Status = VL53L0X_RdByte(Dev, 0x04, &Byte);
mjarvisal 0:e6fcdb78a136 2839
mjarvisal 0:e6fcdb78a136 2840 if (Status == VL53L0X_ERROR_NONE)
mjarvisal 0:e6fcdb78a136 2841 Status = VL53L0X_WrByte(Dev, 0xFF, 0x0);
mjarvisal 0:e6fcdb78a136 2842
mjarvisal 0:e6fcdb78a136 2843 *pStopStatus = Byte;
mjarvisal 0:e6fcdb78a136 2844
mjarvisal 0:e6fcdb78a136 2845 if (Byte == 0) {
mjarvisal 0:e6fcdb78a136 2846 Status = VL53L0X_WrByte(Dev, 0x80, 0x01);
mjarvisal 0:e6fcdb78a136 2847 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2848 Status = VL53L0X_WrByte(Dev, 0x00, 0x00);
mjarvisal 0:e6fcdb78a136 2849 Status = VL53L0X_WrByte(Dev, 0x91,
mjarvisal 0:e6fcdb78a136 2850 PALDevDataGet(Dev, StopVariable));
mjarvisal 0:e6fcdb78a136 2851 Status = VL53L0X_WrByte(Dev, 0x00, 0x01);
mjarvisal 0:e6fcdb78a136 2852 Status = VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2853 Status = VL53L0X_WrByte(Dev, 0x80, 0x00);
mjarvisal 0:e6fcdb78a136 2854 }
mjarvisal 0:e6fcdb78a136 2855
mjarvisal 0:e6fcdb78a136 2856 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2857 return Status;
mjarvisal 0:e6fcdb78a136 2858 }
mjarvisal 0:e6fcdb78a136 2859
mjarvisal 0:e6fcdb78a136 2860 /* Group PAL Interrupt Functions */
mjarvisal 0:e6fcdb78a136 2861 VL53L0X_Error VL53L0X_ClearInterruptMask(VL53L0X_DEV Dev, uint32_t InterruptMask)
mjarvisal 0:e6fcdb78a136 2862 {
mjarvisal 0:e6fcdb78a136 2863 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2864 uint8_t LoopCount;
mjarvisal 0:e6fcdb78a136 2865 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 2866 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2867
mjarvisal 0:e6fcdb78a136 2868 /* clear bit 0 range interrupt, bit 1 error interrupt */
mjarvisal 0:e6fcdb78a136 2869 LoopCount = 0;
mjarvisal 0:e6fcdb78a136 2870 do {
mjarvisal 0:e6fcdb78a136 2871 Status = VL53L0X_WrByte(Dev,
mjarvisal 0:e6fcdb78a136 2872 VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, 0x01);
mjarvisal 0:e6fcdb78a136 2873 Status |= VL53L0X_WrByte(Dev,
mjarvisal 0:e6fcdb78a136 2874 VL53L0X_REG_SYSTEM_INTERRUPT_CLEAR, 0x00);
mjarvisal 0:e6fcdb78a136 2875 Status |= VL53L0X_RdByte(Dev,
mjarvisal 0:e6fcdb78a136 2876 VL53L0X_REG_RESULT_INTERRUPT_STATUS, &Byte);
mjarvisal 0:e6fcdb78a136 2877 LoopCount++;
mjarvisal 0:e6fcdb78a136 2878 } while (((Byte & 0x07) != 0x00)
mjarvisal 0:e6fcdb78a136 2879 && (LoopCount < 3)
mjarvisal 0:e6fcdb78a136 2880 && (Status == VL53L0X_ERROR_NONE));
mjarvisal 0:e6fcdb78a136 2881
mjarvisal 0:e6fcdb78a136 2882
mjarvisal 0:e6fcdb78a136 2883 if (LoopCount >= 3)
mjarvisal 0:e6fcdb78a136 2884 Status = VL53L0X_ERROR_INTERRUPT_NOT_CLEARED;
mjarvisal 0:e6fcdb78a136 2885
mjarvisal 0:e6fcdb78a136 2886 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2887 return Status;
mjarvisal 0:e6fcdb78a136 2888 }
mjarvisal 0:e6fcdb78a136 2889
mjarvisal 0:e6fcdb78a136 2890 VL53L0X_Error VL53L0X_GetInterruptMaskStatus(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2891 uint32_t *pInterruptMaskStatus)
mjarvisal 0:e6fcdb78a136 2892 {
mjarvisal 0:e6fcdb78a136 2893 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2894 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 2895 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2896
mjarvisal 0:e6fcdb78a136 2897 Status = VL53L0X_RdByte(Dev, VL53L0X_REG_RESULT_INTERRUPT_STATUS, &Byte);
mjarvisal 0:e6fcdb78a136 2898 *pInterruptMaskStatus = Byte & 0x07;
mjarvisal 0:e6fcdb78a136 2899
mjarvisal 0:e6fcdb78a136 2900 if (Byte & 0x18)
mjarvisal 0:e6fcdb78a136 2901 Status = VL53L0X_ERROR_RANGE_ERROR;
mjarvisal 0:e6fcdb78a136 2902
mjarvisal 0:e6fcdb78a136 2903 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2904 return Status;
mjarvisal 0:e6fcdb78a136 2905 }
mjarvisal 0:e6fcdb78a136 2906
mjarvisal 0:e6fcdb78a136 2907 VL53L0X_Error VL53L0X_EnableInterruptMask(VL53L0X_DEV Dev, uint32_t InterruptMask)
mjarvisal 0:e6fcdb78a136 2908 {
mjarvisal 0:e6fcdb78a136 2909 VL53L0X_Error Status = VL53L0X_ERROR_NOT_IMPLEMENTED;
mjarvisal 0:e6fcdb78a136 2910 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2911
mjarvisal 0:e6fcdb78a136 2912 /* not implemented for VL53L0X */
mjarvisal 0:e6fcdb78a136 2913
mjarvisal 0:e6fcdb78a136 2914 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2915 return Status;
mjarvisal 0:e6fcdb78a136 2916 }
mjarvisal 0:e6fcdb78a136 2917
mjarvisal 0:e6fcdb78a136 2918 /* End Group PAL Interrupt Functions */
mjarvisal 0:e6fcdb78a136 2919
mjarvisal 0:e6fcdb78a136 2920 /* Group SPAD functions */
mjarvisal 0:e6fcdb78a136 2921
mjarvisal 0:e6fcdb78a136 2922 VL53L0X_Error VL53L0X_SetSpadAmbientDamperThreshold(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2923 uint16_t SpadAmbientDamperThreshold)
mjarvisal 0:e6fcdb78a136 2924 {
mjarvisal 0:e6fcdb78a136 2925 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2926 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2927
mjarvisal 0:e6fcdb78a136 2928 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2929 Status |= VL53L0X_WrWord(Dev, 0x40, SpadAmbientDamperThreshold);
mjarvisal 0:e6fcdb78a136 2930 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2931
mjarvisal 0:e6fcdb78a136 2932 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2933 return Status;
mjarvisal 0:e6fcdb78a136 2934 }
mjarvisal 0:e6fcdb78a136 2935
mjarvisal 0:e6fcdb78a136 2936 VL53L0X_Error VL53L0X_GetSpadAmbientDamperThreshold(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2937 uint16_t *pSpadAmbientDamperThreshold)
mjarvisal 0:e6fcdb78a136 2938 {
mjarvisal 0:e6fcdb78a136 2939 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2940 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2941
mjarvisal 0:e6fcdb78a136 2942 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2943 Status |= VL53L0X_RdWord(Dev, 0x40, pSpadAmbientDamperThreshold);
mjarvisal 0:e6fcdb78a136 2944 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2945
mjarvisal 0:e6fcdb78a136 2946 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2947 return Status;
mjarvisal 0:e6fcdb78a136 2948 }
mjarvisal 0:e6fcdb78a136 2949
mjarvisal 0:e6fcdb78a136 2950 VL53L0X_Error VL53L0X_SetSpadAmbientDamperFactor(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2951 uint16_t SpadAmbientDamperFactor)
mjarvisal 0:e6fcdb78a136 2952 {
mjarvisal 0:e6fcdb78a136 2953 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2954 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 2955 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2956
mjarvisal 0:e6fcdb78a136 2957 Byte = (uint8_t)(SpadAmbientDamperFactor & 0x00FF);
mjarvisal 0:e6fcdb78a136 2958
mjarvisal 0:e6fcdb78a136 2959 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2960 Status |= VL53L0X_WrByte(Dev, 0x42, Byte);
mjarvisal 0:e6fcdb78a136 2961 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2962
mjarvisal 0:e6fcdb78a136 2963 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2964 return Status;
mjarvisal 0:e6fcdb78a136 2965 }
mjarvisal 0:e6fcdb78a136 2966
mjarvisal 0:e6fcdb78a136 2967 VL53L0X_Error VL53L0X_GetSpadAmbientDamperFactor(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 2968 uint16_t *pSpadAmbientDamperFactor)
mjarvisal 0:e6fcdb78a136 2969 {
mjarvisal 0:e6fcdb78a136 2970 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2971 uint8_t Byte;
mjarvisal 0:e6fcdb78a136 2972 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2973
mjarvisal 0:e6fcdb78a136 2974 Status = VL53L0X_WrByte(Dev, 0xFF, 0x01);
mjarvisal 0:e6fcdb78a136 2975 Status |= VL53L0X_RdByte(Dev, 0x42, &Byte);
mjarvisal 0:e6fcdb78a136 2976 Status |= VL53L0X_WrByte(Dev, 0xFF, 0x00);
mjarvisal 0:e6fcdb78a136 2977 *pSpadAmbientDamperFactor = (uint16_t)Byte;
mjarvisal 0:e6fcdb78a136 2978
mjarvisal 0:e6fcdb78a136 2979 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2980 return Status;
mjarvisal 0:e6fcdb78a136 2981 }
mjarvisal 0:e6fcdb78a136 2982
mjarvisal 0:e6fcdb78a136 2983 /* END Group SPAD functions */
mjarvisal 0:e6fcdb78a136 2984
mjarvisal 0:e6fcdb78a136 2985 /*****************************************************************************
mjarvisal 0:e6fcdb78a136 2986 * Internal functions
mjarvisal 0:e6fcdb78a136 2987 *****************************************************************************/
mjarvisal 0:e6fcdb78a136 2988
mjarvisal 0:e6fcdb78a136 2989 VL53L0X_Error VL53L0X_SetReferenceSpads(VL53L0X_DEV Dev, uint32_t count,
mjarvisal 0:e6fcdb78a136 2990 uint8_t isApertureSpads)
mjarvisal 0:e6fcdb78a136 2991 {
mjarvisal 0:e6fcdb78a136 2992 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 2993 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 2994
mjarvisal 0:e6fcdb78a136 2995 Status = VL53L0X_set_reference_spads(Dev, count, isApertureSpads);
mjarvisal 0:e6fcdb78a136 2996
mjarvisal 0:e6fcdb78a136 2997 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 2998
mjarvisal 0:e6fcdb78a136 2999 return Status;
mjarvisal 0:e6fcdb78a136 3000 }
mjarvisal 0:e6fcdb78a136 3001
mjarvisal 0:e6fcdb78a136 3002 VL53L0X_Error VL53L0X_GetReferenceSpads(VL53L0X_DEV Dev, uint32_t *pSpadCount,
mjarvisal 0:e6fcdb78a136 3003 uint8_t *pIsApertureSpads)
mjarvisal 0:e6fcdb78a136 3004 {
mjarvisal 0:e6fcdb78a136 3005 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 3006 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 3007
mjarvisal 0:e6fcdb78a136 3008 Status = VL53L0X_get_reference_spads(Dev, pSpadCount, pIsApertureSpads);
mjarvisal 0:e6fcdb78a136 3009
mjarvisal 0:e6fcdb78a136 3010 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 3011
mjarvisal 0:e6fcdb78a136 3012 return Status;
mjarvisal 0:e6fcdb78a136 3013 }
mjarvisal 0:e6fcdb78a136 3014
mjarvisal 0:e6fcdb78a136 3015 VL53L0X_Error VL53L0X_PerformRefSpadManagement(VL53L0X_DEV Dev,
mjarvisal 0:e6fcdb78a136 3016 uint32_t *refSpadCount, uint8_t *isApertureSpads)
mjarvisal 0:e6fcdb78a136 3017 {
mjarvisal 0:e6fcdb78a136 3018 VL53L0X_Error Status = VL53L0X_ERROR_NONE;
mjarvisal 0:e6fcdb78a136 3019 LOG_FUNCTION_START("");
mjarvisal 0:e6fcdb78a136 3020
mjarvisal 0:e6fcdb78a136 3021 Status = VL53L0X_perform_ref_spad_management(Dev, refSpadCount,
mjarvisal 0:e6fcdb78a136 3022 isApertureSpads);
mjarvisal 0:e6fcdb78a136 3023
mjarvisal 0:e6fcdb78a136 3024 LOG_FUNCTION_END(Status);
mjarvisal 0:e6fcdb78a136 3025
mjarvisal 0:e6fcdb78a136 3026 return Status;
mjarvisal 0:e6fcdb78a136 3027 }