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:
charlesmn
Date:
Fri Nov 06 10:06:37 2020 +0000
Revision:
0:3ac96e360672
Child:
7:1add29d51e72
Library for ST Vl53L1A1 time of flight sensor.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charlesmn 0:3ac96e360672 1
charlesmn 0:3ac96e360672 2 /*******************************************************************************
charlesmn 0:3ac96e360672 3 * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
charlesmn 0:3ac96e360672 4
charlesmn 0:3ac96e360672 5 This file is part of VL53L1 Core and is dual licensed,
charlesmn 0:3ac96e360672 6 either 'STMicroelectronics
charlesmn 0:3ac96e360672 7 Proprietary license'
charlesmn 0:3ac96e360672 8 or 'BSD 3-clause "New" or "Revised" License' , at your option.
charlesmn 0:3ac96e360672 9
charlesmn 0:3ac96e360672 10 ********************************************************************************
charlesmn 0:3ac96e360672 11
charlesmn 0:3ac96e360672 12 'STMicroelectronics Proprietary license'
charlesmn 0:3ac96e360672 13
charlesmn 0:3ac96e360672 14 ********************************************************************************
charlesmn 0:3ac96e360672 15
charlesmn 0:3ac96e360672 16 License terms: STMicroelectronics Proprietary in accordance with licensing
charlesmn 0:3ac96e360672 17 terms at www.st.com/sla0081
charlesmn 0:3ac96e360672 18
charlesmn 0:3ac96e360672 19 STMicroelectronics confidential
charlesmn 0:3ac96e360672 20 Reproduction and Communication of this document is strictly prohibited unless
charlesmn 0:3ac96e360672 21 specifically authorized in writing by STMicroelectronics.
charlesmn 0:3ac96e360672 22
charlesmn 0:3ac96e360672 23
charlesmn 0:3ac96e360672 24 ********************************************************************************
charlesmn 0:3ac96e360672 25
charlesmn 0:3ac96e360672 26 Alternatively, VL53L1 Core may be distributed under the terms of
charlesmn 0:3ac96e360672 27 'BSD 3-clause "New" or "Revised" License', in which case the following
charlesmn 0:3ac96e360672 28 provisions apply instead of the ones
charlesmn 0:3ac96e360672 29 mentioned above :
charlesmn 0:3ac96e360672 30
charlesmn 0:3ac96e360672 31 ********************************************************************************
charlesmn 0:3ac96e360672 32
charlesmn 0:3ac96e360672 33 License terms: BSD 3-clause "New" or "Revised" License.
charlesmn 0:3ac96e360672 34
charlesmn 0:3ac96e360672 35 Redistribution and use in source and binary forms, with or without
charlesmn 0:3ac96e360672 36 modification, are permitted provided that the following conditions are met:
charlesmn 0:3ac96e360672 37
charlesmn 0:3ac96e360672 38 1. Redistributions of source code must retain the above copyright notice, this
charlesmn 0:3ac96e360672 39 list of conditions and the following disclaimer.
charlesmn 0:3ac96e360672 40
charlesmn 0:3ac96e360672 41 2. Redistributions in binary form must reproduce the above copyright notice,
charlesmn 0:3ac96e360672 42 this list of conditions and the following disclaimer in the documentation
charlesmn 0:3ac96e360672 43 and/or other materials provided with the distribution.
charlesmn 0:3ac96e360672 44
charlesmn 0:3ac96e360672 45 3. Neither the name of the copyright holder nor the names of its contributors
charlesmn 0:3ac96e360672 46 may be used to endorse or promote products derived from this software
charlesmn 0:3ac96e360672 47 without specific prior written permission.
charlesmn 0:3ac96e360672 48
charlesmn 0:3ac96e360672 49 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
charlesmn 0:3ac96e360672 50 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
charlesmn 0:3ac96e360672 51 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
charlesmn 0:3ac96e360672 52 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
charlesmn 0:3ac96e360672 53 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
charlesmn 0:3ac96e360672 54 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
charlesmn 0:3ac96e360672 55 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
charlesmn 0:3ac96e360672 56 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
charlesmn 0:3ac96e360672 57 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
charlesmn 0:3ac96e360672 58 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
charlesmn 0:3ac96e360672 59
charlesmn 0:3ac96e360672 60
charlesmn 0:3ac96e360672 61 ********************************************************************************
charlesmn 0:3ac96e360672 62
charlesmn 0:3ac96e360672 63 */
charlesmn 0:3ac96e360672 64
charlesmn 0:3ac96e360672 65
charlesmn 0:3ac96e360672 66
charlesmn 0:3ac96e360672 67
charlesmn 0:3ac96e360672 68
charlesmn 0:3ac96e360672 69 #include "vl53l1_api_core.h"
charlesmn 0:3ac96e360672 70 #include "vl53l1_api_strings.h"
charlesmn 0:3ac96e360672 71 #include "vl53l1_error_codes.h"
charlesmn 0:3ac96e360672 72 #include "vl53l1_error_strings.h"
charlesmn 0:3ac96e360672 73
charlesmn 0:3ac96e360672 74 #define LOG_FUNCTION_START(fmt, ...) \
charlesmn 0:3ac96e360672 75 _LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 76 #define LOG_FUNCTION_END(status, ...) \
charlesmn 0:3ac96e360672 77 _LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
charlesmn 0:3ac96e360672 78 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
charlesmn 0:3ac96e360672 79 _LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, \
charlesmn 0:3ac96e360672 80 ##__VA_ARGS__)
charlesmn 0:3ac96e360672 81
charlesmn 0:3ac96e360672 82
charlesmn 0:3ac96e360672 83 VL53L1_Error VL53L1_get_range_status_string(
charlesmn 0:3ac96e360672 84 uint8_t RangeStatus,
charlesmn 0:3ac96e360672 85 char *pRangeStatusString)
charlesmn 0:3ac96e360672 86 {
charlesmn 0:3ac96e360672 87 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 88
charlesmn 0:3ac96e360672 89 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 90
charlesmn 0:3ac96e360672 91 #ifdef VL53L1_USE_EMPTY_STRING
charlesmn 0:3ac96e360672 92 SUPPRESS_UNUSED_WARNING(RangeStatus);
charlesmn 0:3ac96e360672 93 VL53L1_COPYSTRING(pRangeStatusString, "");
charlesmn 0:3ac96e360672 94 #else
charlesmn 0:3ac96e360672 95 switch (RangeStatus) {
charlesmn 0:3ac96e360672 96 case 0:
charlesmn 0:3ac96e360672 97 VL53L1_COPYSTRING(pRangeStatusString,
charlesmn 0:3ac96e360672 98 VL53L1_STRING_RANGESTATUS_RANGEVALID);
charlesmn 0:3ac96e360672 99 break;
charlesmn 0:3ac96e360672 100 case 1:
charlesmn 0:3ac96e360672 101 VL53L1_COPYSTRING(pRangeStatusString,
charlesmn 0:3ac96e360672 102 VL53L1_STRING_RANGESTATUS_SIGMA);
charlesmn 0:3ac96e360672 103 break;
charlesmn 0:3ac96e360672 104 case 2:
charlesmn 0:3ac96e360672 105 VL53L1_COPYSTRING(pRangeStatusString,
charlesmn 0:3ac96e360672 106 VL53L1_STRING_RANGESTATUS_SIGNAL);
charlesmn 0:3ac96e360672 107 break;
charlesmn 0:3ac96e360672 108 case 3:
charlesmn 0:3ac96e360672 109 VL53L1_COPYSTRING(pRangeStatusString,
charlesmn 0:3ac96e360672 110 VL53L1_STRING_RANGESTATUS_MINRANGE);
charlesmn 0:3ac96e360672 111 break;
charlesmn 0:3ac96e360672 112 case 4:
charlesmn 0:3ac96e360672 113 VL53L1_COPYSTRING(pRangeStatusString,
charlesmn 0:3ac96e360672 114 VL53L1_STRING_RANGESTATUS_PHASE);
charlesmn 0:3ac96e360672 115 break;
charlesmn 0:3ac96e360672 116 case 5:
charlesmn 0:3ac96e360672 117 VL53L1_COPYSTRING(pRangeStatusString,
charlesmn 0:3ac96e360672 118 VL53L1_STRING_RANGESTATUS_HW);
charlesmn 0:3ac96e360672 119 break;
charlesmn 0:3ac96e360672 120
charlesmn 0:3ac96e360672 121 default:
charlesmn 0:3ac96e360672 122 VL53L1_COPYSTRING(pRangeStatusString,
charlesmn 0:3ac96e360672 123 VL53L1_STRING_RANGESTATUS_NONE);
charlesmn 0:3ac96e360672 124 }
charlesmn 0:3ac96e360672 125 #endif
charlesmn 0:3ac96e360672 126
charlesmn 0:3ac96e360672 127 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 128 return status;
charlesmn 0:3ac96e360672 129 }
charlesmn 0:3ac96e360672 130
charlesmn 0:3ac96e360672 131
charlesmn 0:3ac96e360672 132 VL53L1_Error VL53L1_get_pal_state_string(
charlesmn 0:3ac96e360672 133 VL53L1_State PalStateCode,
charlesmn 0:3ac96e360672 134 char *pPalStateString)
charlesmn 0:3ac96e360672 135 {
charlesmn 0:3ac96e360672 136 VL53L1_Error status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 137
charlesmn 0:3ac96e360672 138 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 139
charlesmn 0:3ac96e360672 140 #ifdef VL53L1_USE_EMPTY_STRING
charlesmn 0:3ac96e360672 141 SUPPRESS_UNUSED_WARNING(PalStateCode);
charlesmn 0:3ac96e360672 142 VL53L1_COPYSTRING(pPalStateString, "");
charlesmn 0:3ac96e360672 143 #else
charlesmn 0:3ac96e360672 144 switch (PalStateCode) {
charlesmn 0:3ac96e360672 145 case VL53L1_STATE_POWERDOWN:
charlesmn 0:3ac96e360672 146 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 147 VL53L1_STRING_STATE_POWERDOWN);
charlesmn 0:3ac96e360672 148 break;
charlesmn 0:3ac96e360672 149 case VL53L1_STATE_WAIT_STATICINIT:
charlesmn 0:3ac96e360672 150 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 151 VL53L1_STRING_STATE_WAIT_STATICINIT);
charlesmn 0:3ac96e360672 152 break;
charlesmn 0:3ac96e360672 153 case VL53L1_STATE_STANDBY:
charlesmn 0:3ac96e360672 154 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 155 VL53L1_STRING_STATE_STANDBY);
charlesmn 0:3ac96e360672 156 break;
charlesmn 0:3ac96e360672 157 case VL53L1_STATE_IDLE:
charlesmn 0:3ac96e360672 158 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 159 VL53L1_STRING_STATE_IDLE);
charlesmn 0:3ac96e360672 160 break;
charlesmn 0:3ac96e360672 161 case VL53L1_STATE_RUNNING:
charlesmn 0:3ac96e360672 162 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 163 VL53L1_STRING_STATE_RUNNING);
charlesmn 0:3ac96e360672 164 break;
charlesmn 0:3ac96e360672 165 case VL53L1_STATE_RESET:
charlesmn 0:3ac96e360672 166 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 167 VL53L1_STRING_STATE_RESET);
charlesmn 0:3ac96e360672 168 break;
charlesmn 0:3ac96e360672 169 case VL53L1_STATE_UNKNOWN:
charlesmn 0:3ac96e360672 170 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 171 VL53L1_STRING_STATE_UNKNOWN);
charlesmn 0:3ac96e360672 172 break;
charlesmn 0:3ac96e360672 173 case VL53L1_STATE_ERROR:
charlesmn 0:3ac96e360672 174 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 175 VL53L1_STRING_STATE_ERROR);
charlesmn 0:3ac96e360672 176 break;
charlesmn 0:3ac96e360672 177
charlesmn 0:3ac96e360672 178 default:
charlesmn 0:3ac96e360672 179 VL53L1_COPYSTRING(pPalStateString,
charlesmn 0:3ac96e360672 180 VL53L1_STRING_STATE_UNKNOWN);
charlesmn 0:3ac96e360672 181 }
charlesmn 0:3ac96e360672 182 #endif
charlesmn 0:3ac96e360672 183
charlesmn 0:3ac96e360672 184 LOG_FUNCTION_END(status);
charlesmn 0:3ac96e360672 185 return status;
charlesmn 0:3ac96e360672 186 }
charlesmn 0:3ac96e360672 187
charlesmn 0:3ac96e360672 188 VL53L1_Error VL53L1_get_sequence_steps_info(
charlesmn 0:3ac96e360672 189 VL53L1_SequenceStepId SequenceStepId,
charlesmn 0:3ac96e360672 190 char *pSequenceStepsString)
charlesmn 0:3ac96e360672 191 {
charlesmn 0:3ac96e360672 192 VL53L1_Error Status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 193
charlesmn 0:3ac96e360672 194 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 195
charlesmn 0:3ac96e360672 196 #ifdef VL53L1_USE_EMPTY_STRING
charlesmn 0:3ac96e360672 197 SUPPRESS_UNUSED_WARNING(SequenceStepId);
charlesmn 0:3ac96e360672 198 VL53L1_COPYSTRING(pSequenceStepsString, "");
charlesmn 0:3ac96e360672 199 #else
charlesmn 0:3ac96e360672 200 switch (SequenceStepId) {
charlesmn 0:3ac96e360672 201 case VL53L1_SEQUENCESTEP_VHV:
charlesmn 0:3ac96e360672 202 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 203 VL53L1_STRING_SEQUENCESTEP_VHV);
charlesmn 0:3ac96e360672 204 break;
charlesmn 0:3ac96e360672 205 case VL53L1_SEQUENCESTEP_PHASECAL:
charlesmn 0:3ac96e360672 206 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 207 VL53L1_STRING_SEQUENCESTEP_PHASECAL);
charlesmn 0:3ac96e360672 208 break;
charlesmn 0:3ac96e360672 209 case VL53L1_SEQUENCESTEP_REFPHASE:
charlesmn 0:3ac96e360672 210 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 211 VL53L1_STRING_SEQUENCESTEP_DSS1);
charlesmn 0:3ac96e360672 212 break;
charlesmn 0:3ac96e360672 213 case VL53L1_SEQUENCESTEP_DSS1:
charlesmn 0:3ac96e360672 214 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 215 VL53L1_STRING_SEQUENCESTEP_DSS1);
charlesmn 0:3ac96e360672 216 break;
charlesmn 0:3ac96e360672 217 case VL53L1_SEQUENCESTEP_DSS2:
charlesmn 0:3ac96e360672 218 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 219 VL53L1_STRING_SEQUENCESTEP_DSS2);
charlesmn 0:3ac96e360672 220 break;
charlesmn 0:3ac96e360672 221 case VL53L1_SEQUENCESTEP_MM1:
charlesmn 0:3ac96e360672 222 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 223 VL53L1_STRING_SEQUENCESTEP_MM1);
charlesmn 0:3ac96e360672 224 break;
charlesmn 0:3ac96e360672 225 case VL53L1_SEQUENCESTEP_MM2:
charlesmn 0:3ac96e360672 226 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 227 VL53L1_STRING_SEQUENCESTEP_MM2);
charlesmn 0:3ac96e360672 228 break;
charlesmn 0:3ac96e360672 229 case VL53L1_SEQUENCESTEP_RANGE:
charlesmn 0:3ac96e360672 230 VL53L1_COPYSTRING(pSequenceStepsString,
charlesmn 0:3ac96e360672 231 VL53L1_STRING_SEQUENCESTEP_RANGE);
charlesmn 0:3ac96e360672 232 break;
charlesmn 0:3ac96e360672 233 default:
charlesmn 0:3ac96e360672 234 Status = VL53L1_ERROR_INVALID_PARAMS;
charlesmn 0:3ac96e360672 235 }
charlesmn 0:3ac96e360672 236 #endif
charlesmn 0:3ac96e360672 237
charlesmn 0:3ac96e360672 238 LOG_FUNCTION_END(Status);
charlesmn 0:3ac96e360672 239
charlesmn 0:3ac96e360672 240 return Status;
charlesmn 0:3ac96e360672 241 }
charlesmn 0:3ac96e360672 242
charlesmn 0:3ac96e360672 243 VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
charlesmn 0:3ac96e360672 244 char *pLimitCheckString)
charlesmn 0:3ac96e360672 245 {
charlesmn 0:3ac96e360672 246 VL53L1_Error Status = VL53L1_ERROR_NONE;
charlesmn 0:3ac96e360672 247
charlesmn 0:3ac96e360672 248 LOG_FUNCTION_START("");
charlesmn 0:3ac96e360672 249
charlesmn 0:3ac96e360672 250 #ifdef VL53L1_USE_EMPTY_STRING
charlesmn 0:3ac96e360672 251 SUPPRESS_UNUSED_WARNING(LimitCheckId);
charlesmn 0:3ac96e360672 252 VL53L1_COPYSTRING(pLimitCheckString, "");
charlesmn 0:3ac96e360672 253 #else
charlesmn 0:3ac96e360672 254 switch (LimitCheckId) {
charlesmn 0:3ac96e360672 255 case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
charlesmn 0:3ac96e360672 256 VL53L1_COPYSTRING(pLimitCheckString,
charlesmn 0:3ac96e360672 257 VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
charlesmn 0:3ac96e360672 258 break;
charlesmn 0:3ac96e360672 259 case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
charlesmn 0:3ac96e360672 260 VL53L1_COPYSTRING(pLimitCheckString,
charlesmn 0:3ac96e360672 261 VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
charlesmn 0:3ac96e360672 262 break;
charlesmn 0:3ac96e360672 263 default:
charlesmn 0:3ac96e360672 264 VL53L1_COPYSTRING(pLimitCheckString,
charlesmn 0:3ac96e360672 265 VL53L1_STRING_UNKNOW_ERROR_CODE);
charlesmn 0:3ac96e360672 266 }
charlesmn 0:3ac96e360672 267 #endif
charlesmn 0:3ac96e360672 268
charlesmn 0:3ac96e360672 269 LOG_FUNCTION_END(Status);
charlesmn 0:3ac96e360672 270 return Status;
charlesmn 0:3ac96e360672 271 }
charlesmn 0:3ac96e360672 272
charlesmn 0:3ac96e360672 273
charlesmn 0:3ac96e360672 274