1 /*
2 * Copyright (c) 2017, STMicroelectronics - All Rights Reserved
3 *
4 * This file is part of VL53L1 Core and is dual licensed,
5 * either 'STMicroelectronics
6 * Proprietary license'
7 * or 'BSD 3-clause "New" or "Revised" License' , at your option.
8 *
9 ********************************************************************************
10 *
11 * 'STMicroelectronics Proprietary license'
12 *
13 ********************************************************************************
14 *
15 * License terms: STMicroelectronics Proprietary in accordance with licensing
16 * terms at www.st.com/sla0081
17 *
18 * STMicroelectronics confidential
19 * Reproduction and Communication of this document is strictly prohibited unless
20 * specifically authorized in writing by STMicroelectronics.
21 *
22 *
23 ********************************************************************************
24 *
25 * Alternatively, VL53L1 Core may be distributed under the terms of
26 * 'BSD 3-clause "New" or "Revised" License', in which case the following
27 * provisions apply instead of the ones mentioned above :
28 *
29 ********************************************************************************
30 *
31 * License terms: BSD 3-clause "New" or "Revised" License.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions are met:
35 *
36 * 1. Redistributions of source code must retain the above copyright notice, this
37 * list of conditions and the following disclaimer.
38 *
39 * 2. Redistributions in binary form must reproduce the above copyright notice,
40 * this list of conditions and the following disclaimer in the documentation
41 * and/or other materials provided with the distribution.
42 *
43 * 3. Neither the name of the copyright holder nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
48 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
50 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
54 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
55 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 *
58 *
59 ********************************************************************************
60 *
61 */
62 
63 /**
64  * @file   vl53l1_error_strings.c
65  * @brief  VL53L1 API functions for decoding error codes to a text string
66  */
67 
68 #include "vl53l1_error_codes.h"
69 #include "vl53l1_error_strings.h"
70 #include "vl53l1_platform_log.h"
71 #include "vl53l1_ll_def.h"
72 
73 #define LOG_FUNCTION_START(fmt, ...) \
74 	_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
75 #define LOG_FUNCTION_END(status, ...) \
76 	_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
77 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
78 	_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, \
79 		status, fmt, ##__VA_ARGS__)
80 
81 
82 #ifndef VL53L1_DEBUG
83 	#define VL53L1_USE_EMPTY_STRING
84 #endif
85 
VL53L1_get_pal_error_string(VL53L1_Error PalErrorCode,char * pPalErrorString)86 VL53L1_Error VL53L1_get_pal_error_string(
87 	VL53L1_Error   PalErrorCode,
88 	char          *pPalErrorString)
89 {
90 	VL53L1_Error Status = VL53L1_ERROR_NONE;
91 
92 #ifdef VL53L1_USE_EMPTY_STRING
93 	SUPPRESS_UNUSED_WARNING(PalErrorCode);
94 #endif
95 
96 	LOG_FUNCTION_START("");
97 
98 #ifdef VL53L1_USE_EMPTY_STRING
99 	VL53L1_COPYSTRING(pPalErrorString, "");
100 #else
101 
102 	switch (PalErrorCode) {
103 	case VL53L1_ERROR_NONE:
104 		VL53L1_COPYSTRING(pPalErrorString,
105 			VL53L1_STRING_ERROR_NONE);
106 		break;
107 	case VL53L1_ERROR_CALIBRATION_WARNING:
108 		VL53L1_COPYSTRING(pPalErrorString,
109 			VL53L1_STRING_ERROR_CALIBRATION_WARNING);
110 		break;
111 	case VL53L1_ERROR_MIN_CLIPPED:
112 		VL53L1_COPYSTRING(pPalErrorString,
113 			VL53L1_STRING_ERROR_MIN_CLIPPED);
114 		break;
115 	case VL53L1_ERROR_UNDEFINED:
116 		VL53L1_COPYSTRING(pPalErrorString,
117 			VL53L1_STRING_ERROR_UNDEFINED);
118 		break;
119 	case VL53L1_ERROR_INVALID_PARAMS:
120 		VL53L1_COPYSTRING(pPalErrorString,
121 			VL53L1_STRING_ERROR_INVALID_PARAMS);
122 		break;
123 	case VL53L1_ERROR_NOT_SUPPORTED:
124 		VL53L1_COPYSTRING(pPalErrorString,
125 			VL53L1_STRING_ERROR_NOT_SUPPORTED);
126 		break;
127 	case VL53L1_ERROR_RANGE_ERROR:
128 		VL53L1_COPYSTRING(pPalErrorString,
129 			VL53L1_STRING_ERROR_RANGE_ERROR);
130 		break;
131 	case VL53L1_ERROR_TIME_OUT:
132 		VL53L1_COPYSTRING(pPalErrorString,
133 			VL53L1_STRING_ERROR_TIME_OUT);
134 		break;
135 	case VL53L1_ERROR_MODE_NOT_SUPPORTED:
136 		VL53L1_COPYSTRING(pPalErrorString,
137 			VL53L1_STRING_ERROR_MODE_NOT_SUPPORTED);
138 		break;
139 	case VL53L1_ERROR_BUFFER_TOO_SMALL:
140 		VL53L1_COPYSTRING(pPalErrorString,
141 			VL53L1_STRING_ERROR_BUFFER_TOO_SMALL);
142 		break;
143 	case VL53L1_ERROR_COMMS_BUFFER_TOO_SMALL:
144 		VL53L1_COPYSTRING(pPalErrorString,
145 			VL53L1_STRING_ERROR_COMMS_BUFFER_TOO_SMALL);
146 		break;
147 	case VL53L1_ERROR_GPIO_NOT_EXISTING:
148 		VL53L1_COPYSTRING(pPalErrorString,
149 			VL53L1_STRING_ERROR_GPIO_NOT_EXISTING);
150 		break;
151 	case VL53L1_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED:
152 		VL53L1_COPYSTRING(pPalErrorString,
153 			VL53L1_STRING_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED);
154 		break;
155 	case VL53L1_ERROR_CONTROL_INTERFACE:
156 		VL53L1_COPYSTRING(pPalErrorString,
157 			VL53L1_STRING_ERROR_CONTROL_INTERFACE);
158 		break;
159 	case VL53L1_ERROR_INVALID_COMMAND:
160 		VL53L1_COPYSTRING(pPalErrorString,
161 			VL53L1_STRING_ERROR_INVALID_COMMAND);
162 		break;
163 	case VL53L1_ERROR_DIVISION_BY_ZERO:
164 		VL53L1_COPYSTRING(pPalErrorString,
165 			VL53L1_STRING_ERROR_DIVISION_BY_ZERO);
166 		break;
167 	case VL53L1_ERROR_REF_SPAD_INIT:
168 		VL53L1_COPYSTRING(pPalErrorString,
169 			VL53L1_STRING_ERROR_REF_SPAD_INIT);
170 		break;
171 	case VL53L1_ERROR_GPH_SYNC_CHECK_FAIL:
172 		VL53L1_COPYSTRING(pPalErrorString,
173 			VL53L1_STRING_ERROR_GPH_SYNC_CHECK_FAIL);
174 		break;
175 	case VL53L1_ERROR_STREAM_COUNT_CHECK_FAIL:
176 		VL53L1_COPYSTRING(pPalErrorString,
177 			VL53L1_STRING_ERROR_STREAM_COUNT_CHECK_FAIL);
178 		break;
179 	case VL53L1_ERROR_GPH_ID_CHECK_FAIL:
180 		VL53L1_COPYSTRING(pPalErrorString,
181 			VL53L1_STRING_ERROR_GPH_ID_CHECK_FAIL);
182 		break;
183 	case VL53L1_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL:
184 		VL53L1_COPYSTRING(pPalErrorString,
185 			VL53L1_STRING_ERROR_ZONE_STREAM_COUNT_CHECK_FAIL);
186 		break;
187 	case VL53L1_ERROR_ZONE_GPH_ID_CHECK_FAIL:
188 		VL53L1_COPYSTRING(pPalErrorString,
189 			VL53L1_STRING_ERROR_ZONE_GPH_ID_CHECK_FAIL);
190 		break;
191 
192 	case VL53L1_ERROR_XTALK_EXTRACTION_NO_SAMPLE_FAIL:
193 		VL53L1_COPYSTRING(pPalErrorString,
194 			VL53L1_STRING_ERROR_XTALK_EXTRACTION_NO_SAMPLES_FAIL);
195 		break;
196 	case VL53L1_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL:
197 		VL53L1_COPYSTRING(pPalErrorString,
198 			VL53L1_STRING_ERROR_XTALK_EXTRACTION_SIGMA_LIMIT_FAIL);
199 		break;
200 
201 	case VL53L1_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL:
202 		VL53L1_COPYSTRING(pPalErrorString,
203 			VL53L1_STRING_ERROR_OFFSET_CAL_NO_SAMPLE_FAIL);
204 		break;
205 	case VL53L1_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL:
206 		VL53L1_COPYSTRING(pPalErrorString,
207 			VL53L1_STRING_ERROR_OFFSET_CAL_NO_SPADS_ENABLED_FAIL);
208 		break;
209 	case VL53L1_ERROR_ZONE_CAL_NO_SAMPLE_FAIL:
210 		VL53L1_COPYSTRING(pPalErrorString,
211 			VL53L1_STRING_ERROR_ZONE_CAL_NO_SAMPLE_FAIL);
212 		break;
213 
214 	case VL53L1_WARNING_OFFSET_CAL_MISSING_SAMPLES:
215 		VL53L1_COPYSTRING(pPalErrorString,
216 			VL53L1_STRING_WARNING_OFFSET_CAL_MISSING_SAMPLES);
217 		break;
218 	case VL53L1_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH:
219 		VL53L1_COPYSTRING(pPalErrorString,
220 			VL53L1_STRING_WARNING_OFFSET_CAL_SIGMA_TOO_HIGH);
221 		break;
222 	case VL53L1_WARNING_OFFSET_CAL_RATE_TOO_HIGH:
223 		VL53L1_COPYSTRING(pPalErrorString,
224 			VL53L1_STRING_WARNING_OFFSET_CAL_RATE_TOO_HIGH);
225 		break;
226 	case VL53L1_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW:
227 		VL53L1_COPYSTRING(pPalErrorString,
228 			VL53L1_STRING_WARNING_OFFSET_CAL_SPAD_COUNT_TOO_LOW);
229 		break;
230 
231 	case VL53L1_WARNING_ZONE_CAL_MISSING_SAMPLES:
232 		VL53L1_COPYSTRING(pPalErrorString,
233 			VL53L1_STRING_WARNING_ZONE_CAL_MISSING_SAMPLES);
234 		break;
235 	case VL53L1_WARNING_ZONE_CAL_SIGMA_TOO_HIGH:
236 		VL53L1_COPYSTRING(pPalErrorString,
237 			VL53L1_STRING_WARNING_ZONE_CAL_SIGMA_TOO_HIGH);
238 		break;
239 	case VL53L1_WARNING_ZONE_CAL_RATE_TOO_HIGH:
240 		VL53L1_COPYSTRING(pPalErrorString,
241 			VL53L1_STRING_WARNING_ZONE_CAL_RATE_TOO_HIGH);
242 		break;
243 
244 	case VL53L1_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS:
245 		VL53L1_COPYSTRING(pPalErrorString,
246 			VL53L1_STRING_WARNING_REF_SPAD_CHAR_NOT_ENOUGH_SPADS);
247 		break;
248 	case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH:
249 		VL53L1_COPYSTRING(pPalErrorString,
250 			VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_HIGH);
251 		break;
252 	case VL53L1_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW:
253 		VL53L1_COPYSTRING(pPalErrorString,
254 			VL53L1_STRING_WARNING_REF_SPAD_CHAR_RATE_TOO_LOW);
255 		break;
256 
257 	case VL53L1_WARNING_XTALK_MISSING_SAMPLES:
258 			VL53L1_COPYSTRING(pPalErrorString,
259 				VL53L1_STRING_WARNING_XTALK_MISSING_SAMPLES);
260 			break;
261 	case VL53L1_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT:
262 			VL53L1_COPYSTRING(pPalErrorString,
263 				VL53L1_STRING_WARNING_XTALK_NO_SAMPLES_FOR_GRADIENT);
264 			break;
265 	case VL53L1_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT:
266 			VL53L1_COPYSTRING(pPalErrorString,
267 				VL53L1_STRING_WARNING_XTALK_SIGMA_LIMIT_FOR_GRADIENT);
268 			break;
269 
270 	case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_OLD:
271 		VL53L1_COPYSTRING(pPalErrorString,
272 			VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_OLD);
273 		break;
274 	case VL53L1_ERROR_DEVICE_FIRMWARE_TOO_NEW:
275 		VL53L1_COPYSTRING(pPalErrorString,
276 			VL53L1_STRING_ERROR_DEVICE_FIRMWARE_TOO_NEW);
277 		break;
278 	case VL53L1_ERROR_UNIT_TEST_FAIL:
279 		VL53L1_COPYSTRING(pPalErrorString,
280 			VL53L1_STRING_ERROR_UNIT_TEST_FAIL);
281 		break;
282 	case VL53L1_ERROR_FILE_READ_FAIL:
283 		VL53L1_COPYSTRING(pPalErrorString,
284 			VL53L1_STRING_ERROR_FILE_READ_FAIL);
285 		break;
286 	case VL53L1_ERROR_FILE_WRITE_FAIL:
287 		VL53L1_COPYSTRING(pPalErrorString,
288 			VL53L1_STRING_ERROR_FILE_WRITE_FAIL);
289 		break;
290 	case VL53L1_ERROR_NOT_IMPLEMENTED:
291 		VL53L1_COPYSTRING(pPalErrorString,
292 			VL53L1_STRING_ERROR_NOT_IMPLEMENTED);
293 		break;
294 	default:
295 		VL53L1_COPYSTRING(pPalErrorString,
296 				VL53L1_STRING_UNKNOW_ERROR_CODE);
297 	}
298 
299 #endif
300 
301 	LOG_FUNCTION_END(Status);
302 
303 	return Status;
304 }
305