1 
2 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 /******************************************************************************
4  * Copyright (c) 2020, STMicroelectronics - All Rights Reserved
5 
6  This file is part of VL53L1 and is dual licensed,
7  either GPL-2.0+
8  or 'BSD 3-clause "New" or "Revised" License' , at your option.
9  ******************************************************************************
10  */
11 
12 /**
13  * @file   vl53l1_api_strings.c
14  * @brief  VL53L1 API functions for decoding error codes to a text string
15  */
16 
17 #include "vl53l1_api_core.h"
18 #include "vl53l1_api_strings.h"
19 #include "vl53l1_error_codes.h"
20 #include "vl53l1_error_strings.h"
21 
22 #define LOG_FUNCTION_START(fmt, ...) \
23 	_LOG_FUNCTION_START(VL53L1_TRACE_MODULE_API, fmt, ##__VA_ARGS__)
24 #define LOG_FUNCTION_END(status, ...) \
25 	_LOG_FUNCTION_END(VL53L1_TRACE_MODULE_API, status, ##__VA_ARGS__)
26 #define LOG_FUNCTION_END_FMT(status, fmt, ...) \
27 	_LOG_FUNCTION_END_FMT(VL53L1_TRACE_MODULE_API, status, fmt, \
28 			##__VA_ARGS__)
29 
30 
VL53L1_get_range_status_string(uint8_t RangeStatus,char * pRangeStatusString)31 VL53L1_Error VL53L1_get_range_status_string(
32 	uint8_t   RangeStatus,
33 	char    *pRangeStatusString)
34 {
35 	VL53L1_Error status = VL53L1_ERROR_NONE;
36 
37 	LOG_FUNCTION_START("");
38 
39 #ifdef VL53L1_USE_EMPTY_STRING
40 	SUPPRESS_UNUSED_WARNING(RangeStatus);
41 	VL53L1_COPYSTRING(pRangeStatusString, "");
42 #else
43 	switch (RangeStatus) {
44 	case 0:
45 		VL53L1_COPYSTRING(pRangeStatusString,
46 			VL53L1_STRING_RANGESTATUS_RANGEVALID);
47 	break;
48 	case 1:
49 		VL53L1_COPYSTRING(pRangeStatusString,
50 			VL53L1_STRING_RANGESTATUS_SIGMA);
51 	break;
52 	case 2:
53 		VL53L1_COPYSTRING(pRangeStatusString,
54 			VL53L1_STRING_RANGESTATUS_SIGNAL);
55 	break;
56 	case 3:
57 		VL53L1_COPYSTRING(pRangeStatusString,
58 			VL53L1_STRING_RANGESTATUS_MINRANGE);
59 	break;
60 	case 4:
61 		VL53L1_COPYSTRING(pRangeStatusString,
62 			VL53L1_STRING_RANGESTATUS_PHASE);
63 	break;
64 	case 5:
65 		VL53L1_COPYSTRING(pRangeStatusString,
66 			VL53L1_STRING_RANGESTATUS_HW);
67 	break;
68 
69 	default: /**/
70 		VL53L1_COPYSTRING(pRangeStatusString,
71 			VL53L1_STRING_RANGESTATUS_NONE);
72 	}
73 #endif
74 
75 	LOG_FUNCTION_END(status);
76 	return status;
77 }
78 
79 
VL53L1_get_pal_state_string(VL53L1_State PalStateCode,char * pPalStateString)80 VL53L1_Error VL53L1_get_pal_state_string(
81 	VL53L1_State PalStateCode,
82 	char *pPalStateString)
83 {
84 	VL53L1_Error status = VL53L1_ERROR_NONE;
85 
86 	LOG_FUNCTION_START("");
87 
88 #ifdef VL53L1_USE_EMPTY_STRING
89 	SUPPRESS_UNUSED_WARNING(PalStateCode);
90 	VL53L1_COPYSTRING(pPalStateString, "");
91 #else
92 	switch (PalStateCode) {
93 	case VL53L1_STATE_POWERDOWN:
94 		VL53L1_COPYSTRING(pPalStateString,
95 			VL53L1_STRING_STATE_POWERDOWN);
96 	break;
97 	case VL53L1_STATE_WAIT_STATICINIT:
98 		VL53L1_COPYSTRING(pPalStateString,
99 			VL53L1_STRING_STATE_WAIT_STATICINIT);
100 	break;
101 	case VL53L1_STATE_STANDBY:
102 		VL53L1_COPYSTRING(pPalStateString,
103 			VL53L1_STRING_STATE_STANDBY);
104 	break;
105 	case VL53L1_STATE_IDLE:
106 		VL53L1_COPYSTRING(pPalStateString,
107 			VL53L1_STRING_STATE_IDLE);
108 	break;
109 	case VL53L1_STATE_RUNNING:
110 		VL53L1_COPYSTRING(pPalStateString,
111 			VL53L1_STRING_STATE_RUNNING);
112 	break;
113 	case VL53L1_STATE_RESET:
114 		VL53L1_COPYSTRING(pPalStateString,
115 			VL53L1_STRING_STATE_RESET);
116 	break;
117 	case VL53L1_STATE_UNKNOWN:
118 		VL53L1_COPYSTRING(pPalStateString,
119 			VL53L1_STRING_STATE_UNKNOWN);
120 	break;
121 	case VL53L1_STATE_ERROR:
122 		VL53L1_COPYSTRING(pPalStateString,
123 			VL53L1_STRING_STATE_ERROR);
124 	break;
125 
126 	default:
127 		VL53L1_COPYSTRING(pPalStateString,
128 			VL53L1_STRING_STATE_UNKNOWN);
129 	}
130 #endif
131 
132 	LOG_FUNCTION_END(status);
133 	return status;
134 }
135 
VL53L1_get_sequence_steps_info(VL53L1_SequenceStepId SequenceStepId,char * pSequenceStepsString)136 VL53L1_Error VL53L1_get_sequence_steps_info(
137 		VL53L1_SequenceStepId SequenceStepId,
138 		char *pSequenceStepsString)
139 {
140 	VL53L1_Error Status = VL53L1_ERROR_NONE;
141 
142 	LOG_FUNCTION_START("");
143 
144 #ifdef VL53L1_USE_EMPTY_STRING
145 	SUPPRESS_UNUSED_WARNING(SequenceStepId);
146 	VL53L1_COPYSTRING(pSequenceStepsString, "");
147 #else
148 	switch (SequenceStepId) {
149 	case VL53L1_SEQUENCESTEP_VHV:
150 		VL53L1_COPYSTRING(pSequenceStepsString,
151 				VL53L1_STRING_SEQUENCESTEP_VHV);
152 	break;
153 	case VL53L1_SEQUENCESTEP_PHASECAL:
154 		VL53L1_COPYSTRING(pSequenceStepsString,
155 				VL53L1_STRING_SEQUENCESTEP_PHASECAL);
156 	break;
157 	case VL53L1_SEQUENCESTEP_REFPHASE:
158 		VL53L1_COPYSTRING(pSequenceStepsString,
159 				VL53L1_STRING_SEQUENCESTEP_DSS1);
160 	break;
161 	case VL53L1_SEQUENCESTEP_DSS1:
162 		VL53L1_COPYSTRING(pSequenceStepsString,
163 				VL53L1_STRING_SEQUENCESTEP_DSS1);
164 	break;
165 	case VL53L1_SEQUENCESTEP_DSS2:
166 		VL53L1_COPYSTRING(pSequenceStepsString,
167 				VL53L1_STRING_SEQUENCESTEP_DSS2);
168 	break;
169 	case VL53L1_SEQUENCESTEP_MM1:
170 		VL53L1_COPYSTRING(pSequenceStepsString,
171 				VL53L1_STRING_SEQUENCESTEP_MM1);
172 	break;
173 	case VL53L1_SEQUENCESTEP_MM2:
174 		VL53L1_COPYSTRING(pSequenceStepsString,
175 				VL53L1_STRING_SEQUENCESTEP_MM2);
176 	break;
177 	case VL53L1_SEQUENCESTEP_RANGE:
178 		VL53L1_COPYSTRING(pSequenceStepsString,
179 				VL53L1_STRING_SEQUENCESTEP_RANGE);
180 	break;
181 	default:
182 		Status = VL53L1_ERROR_INVALID_PARAMS;
183 	}
184 #endif
185 
186 	LOG_FUNCTION_END(Status);
187 
188 	return Status;
189 }
190 
VL53L1_get_limit_check_info(uint16_t LimitCheckId,char * pLimitCheckString)191 VL53L1_Error VL53L1_get_limit_check_info(uint16_t LimitCheckId,
192 	char *pLimitCheckString)
193 {
194 	VL53L1_Error Status = VL53L1_ERROR_NONE;
195 
196 	LOG_FUNCTION_START("");
197 
198 #ifdef VL53L1_USE_EMPTY_STRING
199 	SUPPRESS_UNUSED_WARNING(LimitCheckId);
200 	VL53L1_COPYSTRING(pLimitCheckString, "");
201 #else
202 	switch (LimitCheckId) {
203 	case VL53L1_CHECKENABLE_SIGMA_FINAL_RANGE:
204 		VL53L1_COPYSTRING(pLimitCheckString,
205 			VL53L1_STRING_CHECKENABLE_SIGMA_FINAL_RANGE);
206 	break;
207 	case VL53L1_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE:
208 		VL53L1_COPYSTRING(pLimitCheckString,
209 			VL53L1_STRING_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE);
210 	break;
211 	default:
212 		VL53L1_COPYSTRING(pLimitCheckString,
213 			VL53L1_STRING_UNKNOW_ERROR_CODE);
214 	}
215 #endif
216 
217 	LOG_FUNCTION_END(Status);
218 	return Status;
219 }
220 
221