The VL53L1CB proximity sensor, based on ST’s FlightSense™, Time-of-Flight technology.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   VL53L1CB_noshield_1sensor_polls_auton VL53L1CB_noshield_1sensor_interrupt_auton X_NUCLEO_53L1A2

Based on VL53L1 library, this is a library for the VL53L1CB ToF chip.

Committer:
Charles MacNeill
Date:
Tue Jun 08 13:25:15 2021 +0100
Revision:
8:c07c8a53bfbd
Parent:
7:1add29d51e72
Child:
18:0696efe39d08
Update to v6.6.5 of bare_driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Charles MacNeill 7:1add29d51e72 1
Charles MacNeill 7:1add29d51e72 2 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
Charles MacNeill 7:1add29d51e72 3 /******************************************************************************
Charles MacNeill 7:1add29d51e72 4 * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
Charles MacNeill 7:1add29d51e72 5
Charles MacNeill 7:1add29d51e72 6 This file is part of VL53L1 and is dual licensed,
Charles MacNeill 7:1add29d51e72 7 either GPL-2.0+
Charles MacNeill 7:1add29d51e72 8 or 'BSD 3-clause "New" or "Revised" License' , at your option.
Charles MacNeill 7:1add29d51e72 9 ******************************************************************************
Charles MacNeill 7:1add29d51e72 10 */
Charles MacNeill 7:1add29d51e72 11
Charles MacNeill 7:1add29d51e72 12
Charles MacNeill 7:1add29d51e72 13
Charles MacNeill 7:1add29d51e72 14
Charles MacNeill 7:1add29d51e72 15
Charles MacNeill 7:1add29d51e72 16 #include "vl53l1_ll_def.h"
Charles MacNeill 7:1add29d51e72 17 #include "vl53l1_ll_device.h"
Charles MacNeill 7:1add29d51e72 18 #include "vl53l1_platform.h"
Charles MacNeill 7:1add29d51e72 19 #include "vl53l1_core.h"
Charles MacNeill 7:1add29d51e72 20 #include "vl53l1_silicon_core.h"
Charles MacNeill 7:1add29d51e72 21 #include "vl53l1_wait.h"
Charles MacNeill 7:1add29d51e72 22 #include "vl53l1_register_settings.h"
Charles MacNeill 7:1add29d51e72 23
Charles MacNeill 7:1add29d51e72 24
Charles MacNeill 7:1add29d51e72 25 #define LOG_FUNCTION_START(fmt, ...) \
Charles MacNeill 7:1add29d51e72 26 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_CORE, fmt, ##__VA_ARGS__)
Charles MacNeill 7:1add29d51e72 27 #define LOG_FUNCTION_END(status, ...) \
Charles MacNeill 7:1add29d51e72 28 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_CORE, status, ##__VA_ARGS__)
Charles MacNeill 7:1add29d51e72 29 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
Charles MacNeill 7:1add29d51e72 30 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_CORE, status, \
Charles MacNeill 7:1add29d51e72 31 fmt, ##__VA_ARGS__)
Charles MacNeill 7:1add29d51e72 32
Charles MacNeill 7:1add29d51e72 33
Charles MacNeill 7:1add29d51e72 34 VL53L1_Error VL53L1_wait_for_boot_completion(
Charles MacNeill 7:1add29d51e72 35 VL53L1_DEV Dev)
Charles MacNeill 7:1add29d51e72 36 {
Charles MacNeill 7:1add29d51e72 37
Charles MacNeill 7:1add29d51e72 38
Charles MacNeill 7:1add29d51e72 39
Charles MacNeill 7:1add29d51e72 40 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 41 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 42
Charles MacNeill 7:1add29d51e72 43 uint8_t fw_ready = 0;
Charles MacNeill 7:1add29d51e72 44
Charles MacNeill 7:1add29d51e72 45 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 46
Charles MacNeill 7:1add29d51e72 47 if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
Charles MacNeill 7:1add29d51e72 48
Charles MacNeill 7:1add29d51e72 49
Charles MacNeill 7:1add29d51e72 50
Charles MacNeill 7:1add29d51e72 51 status =
Charles MacNeill 7:1add29d51e72 52 VL53L1_poll_for_boot_completion(
Charles MacNeill 7:1add29d51e72 53 Dev,
Charles MacNeill 7:1add29d51e72 54 VL53L1_BOOT_COMPLETION_POLLING_TIMEOUT_MS);
Charles MacNeill 7:1add29d51e72 55
Charles MacNeill 7:1add29d51e72 56 } else {
Charles MacNeill 7:1add29d51e72 57
Charles MacNeill 7:1add29d51e72 58
Charles MacNeill 7:1add29d51e72 59
Charles MacNeill 7:1add29d51e72 60 fw_ready = 0;
Charles MacNeill 7:1add29d51e72 61 while (fw_ready == 0x00 && status == VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 62 status = VL53L1_is_boot_complete(
Charles MacNeill 7:1add29d51e72 63 Dev,
Charles MacNeill 7:1add29d51e72 64 &fw_ready);
Charles MacNeill 7:1add29d51e72 65
Charles MacNeill 7:1add29d51e72 66 if (status == VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 67 status = VL53L1_WaitMs(
Charles MacNeill 7:1add29d51e72 68 Dev,
Charles MacNeill 7:1add29d51e72 69 VL53L1_POLLING_DELAY_MS);
Charles MacNeill 7:1add29d51e72 70 }
Charles MacNeill 7:1add29d51e72 71 }
Charles MacNeill 7:1add29d51e72 72 }
Charles MacNeill 7:1add29d51e72 73
Charles MacNeill 7:1add29d51e72 74 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 75
Charles MacNeill 7:1add29d51e72 76 return status;
Charles MacNeill 7:1add29d51e72 77
Charles MacNeill 7:1add29d51e72 78 }
Charles MacNeill 7:1add29d51e72 79
Charles MacNeill 7:1add29d51e72 80
Charles MacNeill 7:1add29d51e72 81 VL53L1_Error VL53L1_wait_for_firmware_ready(
Charles MacNeill 7:1add29d51e72 82 VL53L1_DEV Dev)
Charles MacNeill 7:1add29d51e72 83 {
Charles MacNeill 7:1add29d51e72 84
Charles MacNeill 7:1add29d51e72 85
Charles MacNeill 7:1add29d51e72 86
Charles MacNeill 7:1add29d51e72 87 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 88 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 89
Charles MacNeill 7:1add29d51e72 90 uint8_t fw_ready = 0;
Charles MacNeill 7:1add29d51e72 91 uint8_t mode_start = 0;
Charles MacNeill 7:1add29d51e72 92
Charles MacNeill 7:1add29d51e72 93 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 94
Charles MacNeill 7:1add29d51e72 95
Charles MacNeill 7:1add29d51e72 96 mode_start =
Charles MacNeill 7:1add29d51e72 97 pdev->sys_ctrl.system__mode_start &
Charles MacNeill 7:1add29d51e72 98 VL53L1_DEVICEMEASUREMENTMODE_MODE_MASK;
Charles MacNeill 7:1add29d51e72 99
Charles MacNeill 7:1add29d51e72 100
Charles MacNeill 7:1add29d51e72 101
Charles MacNeill 7:1add29d51e72 102 if ((mode_start == VL53L1_DEVICEMEASUREMENTMODE_TIMED) ||
Charles MacNeill 7:1add29d51e72 103 (mode_start == VL53L1_DEVICEMEASUREMENTMODE_SINGLESHOT)) {
Charles MacNeill 7:1add29d51e72 104
Charles MacNeill 7:1add29d51e72 105 if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
Charles MacNeill 7:1add29d51e72 106
Charles MacNeill 7:1add29d51e72 107
Charles MacNeill 7:1add29d51e72 108
Charles MacNeill 7:1add29d51e72 109 status =
Charles MacNeill 7:1add29d51e72 110 VL53L1_poll_for_firmware_ready(
Charles MacNeill 7:1add29d51e72 111 Dev,
Charles MacNeill 7:1add29d51e72 112 VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
Charles MacNeill 7:1add29d51e72 113
Charles MacNeill 7:1add29d51e72 114 } else {
Charles MacNeill 7:1add29d51e72 115
Charles MacNeill 7:1add29d51e72 116
Charles MacNeill 7:1add29d51e72 117
Charles MacNeill 7:1add29d51e72 118 fw_ready = 0;
Charles MacNeill 7:1add29d51e72 119 while (fw_ready == 0x00 && status ==
Charles MacNeill 7:1add29d51e72 120 VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 121 status = VL53L1_is_firmware_ready(
Charles MacNeill 7:1add29d51e72 122 Dev,
Charles MacNeill 7:1add29d51e72 123 &fw_ready);
Charles MacNeill 7:1add29d51e72 124
Charles MacNeill 7:1add29d51e72 125 if (status == VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 126 status = VL53L1_WaitMs(
Charles MacNeill 7:1add29d51e72 127 Dev,
Charles MacNeill 7:1add29d51e72 128 VL53L1_POLLING_DELAY_MS);
Charles MacNeill 7:1add29d51e72 129 }
Charles MacNeill 7:1add29d51e72 130 }
Charles MacNeill 7:1add29d51e72 131 }
Charles MacNeill 7:1add29d51e72 132 }
Charles MacNeill 7:1add29d51e72 133
Charles MacNeill 7:1add29d51e72 134 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 135
Charles MacNeill 7:1add29d51e72 136 return status;
Charles MacNeill 7:1add29d51e72 137 }
Charles MacNeill 7:1add29d51e72 138
Charles MacNeill 7:1add29d51e72 139
Charles MacNeill 7:1add29d51e72 140 VL53L1_Error VL53L1_wait_for_range_completion(
Charles MacNeill 7:1add29d51e72 141 VL53L1_DEV Dev)
Charles MacNeill 7:1add29d51e72 142 {
Charles MacNeill 7:1add29d51e72 143
Charles MacNeill 7:1add29d51e72 144
Charles MacNeill 7:1add29d51e72 145
Charles MacNeill 7:1add29d51e72 146 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 147 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 148
Charles MacNeill 7:1add29d51e72 149 uint8_t data_ready = 0;
Charles MacNeill 7:1add29d51e72 150
Charles MacNeill 7:1add29d51e72 151 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 152
Charles MacNeill 7:1add29d51e72 153 if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
Charles MacNeill 7:1add29d51e72 154
Charles MacNeill 7:1add29d51e72 155
Charles MacNeill 7:1add29d51e72 156
Charles MacNeill 7:1add29d51e72 157 status =
Charles MacNeill 7:1add29d51e72 158 VL53L1_poll_for_range_completion(
Charles MacNeill 7:1add29d51e72 159 Dev,
Charles MacNeill 7:1add29d51e72 160 VL53L1_RANGE_COMPLETION_POLLING_TIMEOUT_MS);
Charles MacNeill 7:1add29d51e72 161
Charles MacNeill 7:1add29d51e72 162 } else {
Charles MacNeill 7:1add29d51e72 163
Charles MacNeill 7:1add29d51e72 164
Charles MacNeill 7:1add29d51e72 165
Charles MacNeill 7:1add29d51e72 166 data_ready = 0;
Charles MacNeill 7:1add29d51e72 167 while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 168 status = VL53L1_is_new_data_ready(
Charles MacNeill 7:1add29d51e72 169 Dev,
Charles MacNeill 7:1add29d51e72 170 &data_ready);
Charles MacNeill 7:1add29d51e72 171
Charles MacNeill 7:1add29d51e72 172 if (status == VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 173 status = VL53L1_WaitMs(
Charles MacNeill 7:1add29d51e72 174 Dev,
Charles MacNeill 7:1add29d51e72 175 VL53L1_POLLING_DELAY_MS);
Charles MacNeill 7:1add29d51e72 176 }
Charles MacNeill 7:1add29d51e72 177 }
Charles MacNeill 7:1add29d51e72 178 }
Charles MacNeill 7:1add29d51e72 179
Charles MacNeill 7:1add29d51e72 180 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 181
Charles MacNeill 7:1add29d51e72 182 return status;
Charles MacNeill 7:1add29d51e72 183 }
Charles MacNeill 7:1add29d51e72 184
Charles MacNeill 7:1add29d51e72 185
Charles MacNeill 7:1add29d51e72 186 VL53L1_Error VL53L1_wait_for_test_completion(
Charles MacNeill 7:1add29d51e72 187 VL53L1_DEV Dev)
Charles MacNeill 7:1add29d51e72 188 {
Charles MacNeill 7:1add29d51e72 189
Charles MacNeill 7:1add29d51e72 190
Charles MacNeill 7:1add29d51e72 191
Charles MacNeill 7:1add29d51e72 192 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 193 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 194
Charles MacNeill 7:1add29d51e72 195 uint8_t data_ready = 0;
Charles MacNeill 7:1add29d51e72 196
Charles MacNeill 7:1add29d51e72 197 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 198
Charles MacNeill 7:1add29d51e72 199 if (pdev->wait_method == VL53L1_WAIT_METHOD_BLOCKING) {
Charles MacNeill 7:1add29d51e72 200
Charles MacNeill 7:1add29d51e72 201
Charles MacNeill 7:1add29d51e72 202
Charles MacNeill 7:1add29d51e72 203 status =
Charles MacNeill 7:1add29d51e72 204 VL53L1_poll_for_range_completion(
Charles MacNeill 7:1add29d51e72 205 Dev,
Charles MacNeill 7:1add29d51e72 206 VL53L1_TEST_COMPLETION_POLLING_TIMEOUT_MS);
Charles MacNeill 7:1add29d51e72 207
Charles MacNeill 7:1add29d51e72 208 } else {
Charles MacNeill 7:1add29d51e72 209
Charles MacNeill 7:1add29d51e72 210
Charles MacNeill 7:1add29d51e72 211
Charles MacNeill 7:1add29d51e72 212 data_ready = 0;
Charles MacNeill 7:1add29d51e72 213 while (data_ready == 0x00 && status == VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 214 status = VL53L1_is_new_data_ready(
Charles MacNeill 7:1add29d51e72 215 Dev,
Charles MacNeill 7:1add29d51e72 216 &data_ready);
Charles MacNeill 7:1add29d51e72 217
Charles MacNeill 7:1add29d51e72 218 if (status == VL53L1_ERROR_NONE) {
Charles MacNeill 7:1add29d51e72 219 status = VL53L1_WaitMs(
Charles MacNeill 7:1add29d51e72 220 Dev,
Charles MacNeill 7:1add29d51e72 221 VL53L1_POLLING_DELAY_MS);
Charles MacNeill 7:1add29d51e72 222 }
Charles MacNeill 7:1add29d51e72 223 }
Charles MacNeill 7:1add29d51e72 224 }
Charles MacNeill 7:1add29d51e72 225
Charles MacNeill 7:1add29d51e72 226 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 227
Charles MacNeill 7:1add29d51e72 228 return status;
Charles MacNeill 7:1add29d51e72 229 }
Charles MacNeill 7:1add29d51e72 230
Charles MacNeill 7:1add29d51e72 231
Charles MacNeill 7:1add29d51e72 232
Charles MacNeill 7:1add29d51e72 233
Charles MacNeill 7:1add29d51e72 234 VL53L1_Error VL53L1_is_boot_complete(
Charles MacNeill 7:1add29d51e72 235 VL53L1_DEV Dev,
Charles MacNeill 7:1add29d51e72 236 uint8_t *pready)
Charles MacNeill 7:1add29d51e72 237 {
Charles MacNeill 7:1add29d51e72 238
Charles MacNeill 7:1add29d51e72 239
Charles MacNeill 7:1add29d51e72 240 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 241 uint8_t firmware__system_status = 0;
Charles MacNeill 7:1add29d51e72 242
Charles MacNeill 7:1add29d51e72 243 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 244
Charles MacNeill 7:1add29d51e72 245
Charles MacNeill 7:1add29d51e72 246
Charles MacNeill 7:1add29d51e72 247 status =
Charles MacNeill 7:1add29d51e72 248 VL53L1_RdByte(
Charles MacNeill 7:1add29d51e72 249 Dev,
Charles MacNeill 7:1add29d51e72 250 VL53L1_FIRMWARE__SYSTEM_STATUS,
Charles MacNeill 7:1add29d51e72 251 &firmware__system_status);
Charles MacNeill 7:1add29d51e72 252
Charles MacNeill 7:1add29d51e72 253
Charles MacNeill 7:1add29d51e72 254
Charles MacNeill 7:1add29d51e72 255 if ((firmware__system_status & 0x01) == 0x01) {
Charles MacNeill 7:1add29d51e72 256 *pready = 0x01;
Charles MacNeill 7:1add29d51e72 257 VL53L1_init_ll_driver_state(
Charles MacNeill 7:1add29d51e72 258 Dev,
Charles MacNeill 7:1add29d51e72 259 VL53L1_DEVICESTATE_SW_STANDBY);
Charles MacNeill 7:1add29d51e72 260 } else {
Charles MacNeill 7:1add29d51e72 261 *pready = 0x00;
Charles MacNeill 7:1add29d51e72 262 VL53L1_init_ll_driver_state(
Charles MacNeill 7:1add29d51e72 263 Dev,
Charles MacNeill 7:1add29d51e72 264 VL53L1_DEVICESTATE_FW_COLDBOOT);
Charles MacNeill 7:1add29d51e72 265 }
Charles MacNeill 7:1add29d51e72 266
Charles MacNeill 7:1add29d51e72 267 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 268
Charles MacNeill 7:1add29d51e72 269 return status;
Charles MacNeill 7:1add29d51e72 270 }
Charles MacNeill 7:1add29d51e72 271
Charles MacNeill 7:1add29d51e72 272
Charles MacNeill 7:1add29d51e72 273 VL53L1_Error VL53L1_is_firmware_ready(
Charles MacNeill 7:1add29d51e72 274 VL53L1_DEV Dev,
Charles MacNeill 7:1add29d51e72 275 uint8_t *pready)
Charles MacNeill 7:1add29d51e72 276 {
Charles MacNeill 7:1add29d51e72 277
Charles MacNeill 7:1add29d51e72 278
Charles MacNeill 7:1add29d51e72 279 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 280 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 281
Charles MacNeill 7:1add29d51e72 282 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 283
Charles MacNeill 7:1add29d51e72 284 status = VL53L1_is_firmware_ready_silicon(
Charles MacNeill 7:1add29d51e72 285 Dev,
Charles MacNeill 7:1add29d51e72 286 pready);
Charles MacNeill 7:1add29d51e72 287
Charles MacNeill 7:1add29d51e72 288 pdev->fw_ready = *pready;
Charles MacNeill 7:1add29d51e72 289
Charles MacNeill 7:1add29d51e72 290 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 291
Charles MacNeill 7:1add29d51e72 292 return status;
Charles MacNeill 7:1add29d51e72 293 }
Charles MacNeill 7:1add29d51e72 294
Charles MacNeill 7:1add29d51e72 295
Charles MacNeill 7:1add29d51e72 296 VL53L1_Error VL53L1_is_new_data_ready(
Charles MacNeill 7:1add29d51e72 297 VL53L1_DEV Dev,
Charles MacNeill 7:1add29d51e72 298 uint8_t *pready)
Charles MacNeill 7:1add29d51e72 299 {
Charles MacNeill 7:1add29d51e72 300
Charles MacNeill 7:1add29d51e72 301
Charles MacNeill 7:1add29d51e72 302 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 303 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 304
Charles MacNeill 7:1add29d51e72 305 uint8_t gpio__mux_active_high_hv = 0;
Charles MacNeill 7:1add29d51e72 306 uint8_t gpio__tio_hv_status = 0;
Charles MacNeill 7:1add29d51e72 307 uint8_t interrupt_ready = 0;
Charles MacNeill 7:1add29d51e72 308
Charles MacNeill 7:1add29d51e72 309 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 310
Charles MacNeill 7:1add29d51e72 311 gpio__mux_active_high_hv =
Charles MacNeill 7:1add29d51e72 312 pdev->stat_cfg.gpio_hv_mux__ctrl &
Charles MacNeill 7:1add29d51e72 313 VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
Charles MacNeill 7:1add29d51e72 314
Charles MacNeill 7:1add29d51e72 315 if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
Charles MacNeill 7:1add29d51e72 316 interrupt_ready = 0x01;
Charles MacNeill 7:1add29d51e72 317 else
Charles MacNeill 7:1add29d51e72 318 interrupt_ready = 0x00;
Charles MacNeill 7:1add29d51e72 319
Charles MacNeill 7:1add29d51e72 320
Charles MacNeill 7:1add29d51e72 321
Charles MacNeill 7:1add29d51e72 322 status = VL53L1_RdByte(
Charles MacNeill 7:1add29d51e72 323 Dev,
Charles MacNeill 7:1add29d51e72 324 VL53L1_GPIO__TIO_HV_STATUS,
Charles MacNeill 7:1add29d51e72 325 &gpio__tio_hv_status);
Charles MacNeill 7:1add29d51e72 326
Charles MacNeill 7:1add29d51e72 327
Charles MacNeill 7:1add29d51e72 328
Charles MacNeill 7:1add29d51e72 329 if ((gpio__tio_hv_status & 0x01) == interrupt_ready)
Charles MacNeill 7:1add29d51e72 330 *pready = 0x01;
Charles MacNeill 7:1add29d51e72 331 else
Charles MacNeill 7:1add29d51e72 332 *pready = 0x00;
Charles MacNeill 7:1add29d51e72 333
Charles MacNeill 7:1add29d51e72 334 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 335
Charles MacNeill 7:1add29d51e72 336 return status;
Charles MacNeill 7:1add29d51e72 337 }
Charles MacNeill 7:1add29d51e72 338
Charles MacNeill 7:1add29d51e72 339
Charles MacNeill 7:1add29d51e72 340
Charles MacNeill 7:1add29d51e72 341
Charles MacNeill 7:1add29d51e72 342 VL53L1_Error VL53L1_poll_for_boot_completion(
Charles MacNeill 7:1add29d51e72 343 VL53L1_DEV Dev,
Charles MacNeill 7:1add29d51e72 344 uint32_t timeout_ms)
Charles MacNeill 7:1add29d51e72 345 {
Charles MacNeill 7:1add29d51e72 346
Charles MacNeill 7:1add29d51e72 347
Charles MacNeill 7:1add29d51e72 348 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 349
Charles MacNeill 7:1add29d51e72 350 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 351
Charles MacNeill 7:1add29d51e72 352
Charles MacNeill 7:1add29d51e72 353
Charles MacNeill 7:1add29d51e72 354 status = VL53L1_WaitUs(
Charles MacNeill 7:1add29d51e72 355 Dev,
Charles MacNeill 7:1add29d51e72 356 VL53L1_FIRMWARE_BOOT_TIME_US);
Charles MacNeill 7:1add29d51e72 357
Charles MacNeill 7:1add29d51e72 358 if (status == VL53L1_ERROR_NONE)
Charles MacNeill 7:1add29d51e72 359 status =
Charles MacNeill 7:1add29d51e72 360 VL53L1_WaitValueMaskEx(
Charles MacNeill 7:1add29d51e72 361 Dev,
Charles MacNeill 7:1add29d51e72 362 timeout_ms,
Charles MacNeill 7:1add29d51e72 363 VL53L1_FIRMWARE__SYSTEM_STATUS,
Charles MacNeill 7:1add29d51e72 364 0x01,
Charles MacNeill 7:1add29d51e72 365 0x01,
Charles MacNeill 7:1add29d51e72 366 VL53L1_POLLING_DELAY_MS);
Charles MacNeill 7:1add29d51e72 367
Charles MacNeill 7:1add29d51e72 368 if (status == VL53L1_ERROR_NONE)
Charles MacNeill 7:1add29d51e72 369 VL53L1_init_ll_driver_state(Dev, VL53L1_DEVICESTATE_SW_STANDBY);
Charles MacNeill 7:1add29d51e72 370
Charles MacNeill 7:1add29d51e72 371 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 372
Charles MacNeill 7:1add29d51e72 373 return status;
Charles MacNeill 7:1add29d51e72 374 }
Charles MacNeill 7:1add29d51e72 375
Charles MacNeill 7:1add29d51e72 376
Charles MacNeill 7:1add29d51e72 377 VL53L1_Error VL53L1_poll_for_firmware_ready(
Charles MacNeill 7:1add29d51e72 378 VL53L1_DEV Dev,
Charles MacNeill 7:1add29d51e72 379 uint32_t timeout_ms)
Charles MacNeill 7:1add29d51e72 380 {
Charles MacNeill 7:1add29d51e72 381
Charles MacNeill 7:1add29d51e72 382
Charles MacNeill 7:1add29d51e72 383 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 384 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 385
Charles MacNeill 7:1add29d51e72 386 uint32_t start_time_ms = 0;
Charles MacNeill 7:1add29d51e72 387 uint32_t current_time_ms = 0;
Charles MacNeill 7:1add29d51e72 388 int32_t poll_delay_ms = VL53L1_POLLING_DELAY_MS;
Charles MacNeill 7:1add29d51e72 389 uint8_t fw_ready = 0;
Charles MacNeill 7:1add29d51e72 390
Charles MacNeill 7:1add29d51e72 391
Charles MacNeill 7:1add29d51e72 392
Charles MacNeill 8:c07c8a53bfbd 393 VL53L1_GetTickCount(&start_time_ms);
Charles MacNeill 7:1add29d51e72 394 pdev->fw_ready_poll_duration_ms = 0;
Charles MacNeill 7:1add29d51e72 395
Charles MacNeill 7:1add29d51e72 396
Charles MacNeill 7:1add29d51e72 397
Charles MacNeill 7:1add29d51e72 398 while ((status == VL53L1_ERROR_NONE) &&
Charles MacNeill 7:1add29d51e72 399 (pdev->fw_ready_poll_duration_ms < timeout_ms) &&
Charles MacNeill 7:1add29d51e72 400 (fw_ready == 0)) {
Charles MacNeill 7:1add29d51e72 401
Charles MacNeill 7:1add29d51e72 402 status = VL53L1_is_firmware_ready(
Charles MacNeill 7:1add29d51e72 403 Dev,
Charles MacNeill 7:1add29d51e72 404 &fw_ready);
Charles MacNeill 7:1add29d51e72 405
Charles MacNeill 7:1add29d51e72 406 if (status == VL53L1_ERROR_NONE &&
Charles MacNeill 7:1add29d51e72 407 fw_ready == 0 &&
Charles MacNeill 7:1add29d51e72 408 poll_delay_ms > 0) {
Charles MacNeill 7:1add29d51e72 409 status = VL53L1_WaitMs(
Charles MacNeill 7:1add29d51e72 410 Dev,
Charles MacNeill 7:1add29d51e72 411 poll_delay_ms);
Charles MacNeill 7:1add29d51e72 412 }
Charles MacNeill 7:1add29d51e72 413
Charles MacNeill 7:1add29d51e72 414
Charles MacNeill 8:c07c8a53bfbd 415 VL53L1_GetTickCount(&current_time_ms);
Charles MacNeill 7:1add29d51e72 416 pdev->fw_ready_poll_duration_ms =
Charles MacNeill 7:1add29d51e72 417 current_time_ms - start_time_ms;
Charles MacNeill 7:1add29d51e72 418 }
Charles MacNeill 7:1add29d51e72 419
Charles MacNeill 7:1add29d51e72 420 if (fw_ready == 0 && status == VL53L1_ERROR_NONE)
Charles MacNeill 7:1add29d51e72 421 status = VL53L1_ERROR_TIME_OUT;
Charles MacNeill 7:1add29d51e72 422
Charles MacNeill 7:1add29d51e72 423 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 424
Charles MacNeill 7:1add29d51e72 425 return status;
Charles MacNeill 7:1add29d51e72 426 }
Charles MacNeill 7:1add29d51e72 427
Charles MacNeill 7:1add29d51e72 428
Charles MacNeill 7:1add29d51e72 429 VL53L1_Error VL53L1_poll_for_range_completion(
Charles MacNeill 7:1add29d51e72 430 VL53L1_DEV Dev,
Charles MacNeill 7:1add29d51e72 431 uint32_t timeout_ms)
Charles MacNeill 7:1add29d51e72 432 {
Charles MacNeill 7:1add29d51e72 433
Charles MacNeill 7:1add29d51e72 434
Charles MacNeill 7:1add29d51e72 435 VL53L1_Error status = VL53L1_ERROR_NONE;
Charles MacNeill 7:1add29d51e72 436 VL53L1_LLDriverData_t *pdev = VL53L1DevStructGetLLDriverHandle(Dev);
Charles MacNeill 7:1add29d51e72 437
Charles MacNeill 7:1add29d51e72 438 uint8_t gpio__mux_active_high_hv = 0;
Charles MacNeill 7:1add29d51e72 439 uint8_t interrupt_ready = 0;
Charles MacNeill 7:1add29d51e72 440
Charles MacNeill 7:1add29d51e72 441 LOG_FUNCTION_START("");
Charles MacNeill 7:1add29d51e72 442
Charles MacNeill 7:1add29d51e72 443 gpio__mux_active_high_hv =
Charles MacNeill 7:1add29d51e72 444 pdev->stat_cfg.gpio_hv_mux__ctrl &
Charles MacNeill 7:1add29d51e72 445 VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_MASK;
Charles MacNeill 7:1add29d51e72 446
Charles MacNeill 7:1add29d51e72 447 if (gpio__mux_active_high_hv == VL53L1_DEVICEINTERRUPTLEVEL_ACTIVE_HIGH)
Charles MacNeill 7:1add29d51e72 448 interrupt_ready = 0x01;
Charles MacNeill 7:1add29d51e72 449 else
Charles MacNeill 7:1add29d51e72 450 interrupt_ready = 0x00;
Charles MacNeill 7:1add29d51e72 451
Charles MacNeill 7:1add29d51e72 452 status =
Charles MacNeill 7:1add29d51e72 453 VL53L1_WaitValueMaskEx(
Charles MacNeill 7:1add29d51e72 454 Dev,
Charles MacNeill 7:1add29d51e72 455 timeout_ms,
Charles MacNeill 7:1add29d51e72 456 VL53L1_GPIO__TIO_HV_STATUS,
Charles MacNeill 7:1add29d51e72 457 interrupt_ready,
Charles MacNeill 7:1add29d51e72 458 0x01,
Charles MacNeill 7:1add29d51e72 459 VL53L1_POLLING_DELAY_MS);
Charles MacNeill 7:1add29d51e72 460
Charles MacNeill 7:1add29d51e72 461 LOG_FUNCTION_END(status);
Charles MacNeill 7:1add29d51e72 462
Charles MacNeill 7:1add29d51e72 463 return status;
Charles MacNeill 7:1add29d51e72 464 }
Charles MacNeill 7:1add29d51e72 465
Charles MacNeill 7:1add29d51e72 466