Revision ded1ded7 test/periphery-lld/VL53L1X_v1/aos_test_VL53L1X.c
test/periphery-lld/VL53L1X_v1/aos_test_VL53L1X.c | ||
---|---|---|
56 | 56 |
*/ |
57 | 57 |
aos_testresult_t aosTestVL53L1XFunc(BaseSequentialStream* stream, const aos_test_t* test) |
58 | 58 |
{ |
59 |
// aosDbgCheck(test->data != NULL && ((aos_test_leddata_t*)test->data)->led != NULL); |
|
60 |
|
|
61 |
chprintf(stream, "Peter Wurst\n"); |
|
59 |
aosDbgCheck(test->data != NULL && ((aos_test_vl53l1xdata_t*)test->data)->vl53l1x != NULL); |
|
62 | 60 |
|
63 | 61 |
// local variables |
64 |
aos_testresult_t result = {0,0}; |
|
65 |
// int32_t status; |
|
66 |
// chprintf(stream, "Hello World!\n"); |
|
67 |
// // aosTestResultInit(&result); |
|
68 |
|
|
69 |
// VL53L1_Dev_t dev; |
|
70 |
// dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x); |
|
71 |
|
|
72 |
// chprintf(stream, "Toggle PC2...\n"); |
|
73 |
// chprintf(stream, "On...\n"); |
|
74 |
/* vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_ON); */ |
|
75 |
// aosThdSSleep(5); |
|
76 |
// chprintf(stream, "off...\n"); |
|
77 |
// status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_OFF); |
|
78 |
// aosThdSSleep(5); |
|
79 |
// chprintf(stream, "On...\n"); |
|
80 |
// status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_ON); |
|
81 |
// aosThdSSleep(5); |
|
82 |
// chprintf(stream, "Off...\n"); |
|
83 |
// status |= vl53l1x_GPIO1_set(((aos_test_vl53l1x_bus*)test->data)->vl53l1x, GPIO_LLD_STATE_OFF); |
|
84 |
// // status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state); |
|
85 |
// if (status == APAL_STATUS_OK) { |
|
86 |
// aosTestPassed(stream, &result); |
|
87 |
// } else { |
|
88 |
// aosTestFailed(stream, &result); |
|
89 |
// }p |
|
90 |
|
|
91 |
// chprintf(stream, "turning off for two seconds...\n"); |
|
92 |
// state = LED_LLD_STATE_OFF; |
|
93 |
// status = led_lld_set(((aos_test_leddata_t*)test->data)->led, state); |
|
94 |
// aosThdSSleep(2); |
|
95 |
// status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state); |
|
96 |
// if (status == APAL_STATUS_OK && state == LED_LLD_STATE_OFF) { |
|
97 |
// aosTestPassed(stream, &result); |
|
98 |
// } else { |
|
99 |
// aosTestFailed(stream, &result); |
|
100 |
// } |
|
101 |
|
|
102 |
// chprintf(stream, "toggling for two seconds...\n"); |
|
103 |
// status = led_lld_set(((aos_test_leddata_t*)test->data)->led, LED_LLD_STATE_ON); |
|
104 |
// for (uint32_t i = 0; i < 2000/100; ++i) { |
|
105 |
// status |= led_lld_toggle(((aos_test_leddata_t*)test->data)->led); |
|
106 |
// status |= led_lld_get(((aos_test_leddata_t*)test->data)->led, &state); |
|
107 |
// status |= ((uint8_t)state != (i & 0x01u)) ? APAL_STATUS_ERROR : APAL_STATUS_OK; |
|
108 |
// aosThdMSleep(100); |
|
109 |
// } |
|
110 |
// status = led_lld_set(((aos_test_leddata_t*)test->data)->led, LED_LLD_STATE_OFF); |
|
111 |
// if (status == APAL_STATUS_OK) { |
|
112 |
// aosTestPassed(stream, &result); |
|
113 |
// } else { |
|
114 |
// aosTestFailed(stream, &result); |
|
115 |
// } |
|
116 |
|
|
117 |
// aosTestInfoMsg(stream,"driver object memory footprint: %u bytes\n", sizeof(LEDDriver)); |
|
118 |
|
|
119 |
/* |
|
120 |
uint8_t byteData, sensorState=0; |
|
121 |
uint16_t wordData; |
|
122 |
uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right |
|
123 |
uint16_t Distance; |
|
124 |
uint16_t SignalRate; |
|
125 |
uint16_t AmbientRate; |
|
126 |
uint8_t RangeStatus; |
|
127 |
uint8_t dataReady; |
|
62 |
aos_testresult_t result; |
|
128 | 63 |
int32_t status; |
129 |
*/ |
|
130 |
|
|
131 |
|
|
132 |
// aosTestResultInit(&result); |
|
133 |
|
|
134 |
VL53L1_Dev_t dev; |
|
135 |
dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x); |
|
136 |
/* vl53l1x_GPIO1_set(&dev.vl53l1x, GPIO_LLD_STATE_ON); */ |
|
137 |
|
|
138 |
// status = VL53L1_RdByte(&dev, 0x010F, &byteData); |
|
139 |
// printf("VL53L1X Model_ID: %X\n", byteData); |
|
140 |
// status = VL53L1_RdByte(&dev, 0x0110, &byteData); |
|
141 |
// printf("VL53L1X Module_Type: %X\n", byteData); |
|
142 |
// status = VL53L1_RdWord(&dev, 0x010F, &wordData); |
|
143 |
// printf("VL53L1X: %X\n", wordData); |
|
144 |
|
|
145 |
// activate device |
|
146 |
apalControlGpioState_t xshut_state; |
|
147 |
apalControlGpioState_t gpio_state; |
|
148 |
apalControlGpioGet(dev.vl53l1x.xshut, &xshut_state); |
|
149 |
apalControlGpioGet(dev.vl53l1x.gpio1, &gpio_state); |
|
150 |
if (xshut_state == APAL_GPIO_OFF) { |
|
151 |
chprintf(stream, "XSHUT OFF -> activating\n"); |
|
152 |
apalControlGpioSet(dev.vl53l1x.xshut, APAL_GPIO_ON); |
|
153 |
aosThdSSleep(1); |
|
154 |
aosThdUSleep(2 * VL53L1X_LLD_BOOTDURATION); |
|
155 |
} else { |
|
156 |
chprintf(stream, "XSHUT ON\n"); |
|
157 |
} |
|
158 |
chprintf(stream, "0x%08X | 0x%08X\n", (uint32_t)dev.vl53l1x.i2cd, (uint32_t)(&I2CD3)); |
|
159 |
chprintf(stream, "0x%02X\n", dev.vl53l1x.xshut); |
|
160 |
if (gpio_state == APAL_GPIO_OFF) { |
|
161 |
chprintf(stream, "Gpio OFF \n"); |
|
64 |
VL53L1_Error error; |
|
65 |
|
|
66 |
aosTestResultInit(&result); |
|
67 |
|
|
68 |
{ |
|
69 |
chprintf(stream, "Checking XSHUT signal...\n"); |
|
70 |
vl53l1x_lld_state_t device_state = VL53L1X_LLD_STATE_ON; |
|
71 |
status = vl53l1x_lld_getState(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x, &device_state); |
|
72 |
if (status == APAL_STATUS_OK) { |
|
73 |
chprintf(stream, "\tXSHUT signal is %s.\n", (device_state == VL53L1X_LLD_STATE_ON) ? "on" : "off"); |
|
74 |
aosTestPassed(stream, &result); |
|
75 |
} else { |
|
76 |
aosTestFailed(stream, &result); |
|
77 |
} |
|
78 |
|
|
79 |
if (device_state != VL53L1X_LLD_STATE_ON) { |
|
80 |
chprintf(stream, "Initilaizing device...\n"); |
|
81 |
status = vl53l1x_lld_init(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x); |
|
82 |
if (status == APAL_STATUS_OK) { |
|
83 |
aosTestPassed(stream, &result); |
|
84 |
} else { |
|
85 |
aosTestFailedMsg(stream, &result, "%d\t%u\n", status, i2cGetErrors(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x->Interface.i2cd)); |
|
86 |
} |
|
87 |
} |
|
162 | 88 |
} |
163 | 89 |
|
164 |
uint8_t testBuf[49] = {0}; |
|
165 |
// Reste device |
|
166 |
|
|
167 |
// printf("Resetting device! \n"); |
|
168 |
/* chprintf(stream, "Testif broken!\n"); */ |
|
169 |
|
|
170 |
uint8_t data[4] = {0}; |
|
171 |
/* Status = VL53L1_RdByte(Dev, VL53L1_PAD_I2C_HV__EXTSUP_CONFIG, &i); */ |
|
172 |
/* apalI2CMasterReceive(dev.vl53l1x.i2cd, dev.vl53l1x.addr, testBuf, 3, 10); */ |
|
173 |
/* aosThdMSleep(1000); */ |
|
174 |
/* chprintf(stream, "Start reset!\n"); */ |
|
175 |
/* apalI2CMasterTransmit(dev.vl53l1x.i2cd, dev.vl53l1x.addr, data, 3, testBuf, 0, 10); */ |
|
176 |
chprintf(stream, "Before sleep!\n"); |
|
177 |
/* apalI2CMasterTransmit() */ |
|
178 |
/* aosThdMSleep(1000); */ |
|
179 |
aosThdUSleep(2 * VL53L1X_LLD_BOOTDURATION); |
|
180 |
/* 0x002E */ |
|
181 |
|
|
182 |
data[0] = 0x01; |
|
183 |
data[1] = 0x0f; |
|
184 |
uint8_t stuff[4] = { 0 }; |
|
185 |
/* data[3] = 0x01; */ |
|
186 |
chprintf(stream, "End reset!\n"); |
|
187 |
|
|
188 |
apalExitStatus_t res = apalI2CMasterTransmit(dev.vl53l1x.i2cd, dev.vl53l1x.addr, data, 2, stuff , 0, 10); |
|
189 |
|
|
190 |
|
|
191 |
chprintf(stream, "Res: %d\n", res); |
|
192 |
aosThdMSleep(100); |
|
193 |
i2cflags_t err = i2cGetErrors(dev.vl53l1x.i2cd); |
|
194 |
chprintf(stream, "Error: %08x\n", err); |
|
195 |
aosThdMSleep(100); |
|
196 |
/* apalI2CMasterReceive(dev.vl53l1x.i2cd, dev.vl53l1x.addr, testBuf, 4, 10); */ |
|
197 |
/* apalI2CMasterTransmit(dev.vl53l1x.i2cd, dev.vl53l1x.addr, data, 3, testBuf, 0, 10); */ |
|
198 |
/* /\* VL53L1_RdByte(&dev, VL53L1_IDENTIFICATION__MODEL_ID, &data); *\/ */ |
|
199 |
chprintf(stream, "0x%02\n", stuff[0]); |
|
200 |
chprintf(stream, "0x%02\n", stuff[1]); |
|
201 |
chprintf(stream, "0x%02\n", data[0]); |
|
202 |
chprintf(stream, "0x%02\n", data[1]); |
|
203 |
for(int i = 0; i < 49 ; i++){ |
|
204 |
chprintf(stream, "0x%02 ", testBuf[i]); |
|
90 |
{ |
|
91 |
chprintf(stream, "Read device info...\n"); |
|
92 |
VL53L1_DeviceInfo_t device_info; |
|
93 |
error = VL53L1_GetDeviceInfo(((aos_test_vl53l1xdata_t*)test->data)->vl53l1x, &device_info); |
|
94 |
if (error == VL53L1_ERROR_NONE) { |
|
95 |
chprintf(stream, "\tname: %s\n", device_info.Name); |
|
96 |
chprintf(stream, "\ttype: %s\n", device_info.Type); |
|
97 |
chprintf(stream, "\tproduct id: %s\n", device_info.ProductId); |
|
98 |
chprintf(stream, "\tproduct tpye: %u\n", device_info.ProductType); |
|
99 |
chprintf(stream, "\trevision: %u.%u\n", device_info.ProductRevisionMajor, device_info.ProductRevisionMinor); |
|
100 |
aosTestPassed(stream, &result); |
|
101 |
} else { |
|
102 |
aosTestFailedMsg(stream, &result, "%d", error); |
|
103 |
} |
|
205 | 104 |
} |
206 |
chprintf(stream, "\n"); |
|
207 |
|
|
208 |
/* VL53L1_WrByte(&dev, 0x0000, 0x00); */ |
|
209 |
/* aosThdSSleep(2); */ |
|
210 |
/* vl53l1_WrByte(&dev, 0x0000, 0x01); */ |
|
211 |
|
|
212 |
|
|
213 |
aosTestPassed(stream, &result); |
|
214 |
|
|
215 |
|
|
216 |
return result; |
|
217 |
} |
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
/** |
|
222 |
* @brief Test if I2C was initialized correctly. |
|
223 |
* |
|
224 |
* @param[in] stream Stream for input/output. |
|
225 |
* @param[in] test Test object. |
|
226 |
* |
|
227 |
* @return Test result value. |
|
228 |
*/ |
|
229 |
aos_testresult_t aosTestVL53L1Xi2cInit(BaseSequentialStream* stream, const aos_test_t* test) |
|
230 |
{ |
|
231 |
// aosDbgCheck(test->data != NULL && ((aos_test_leddata_t*)test->data)->led != NULL); |
|
232 |
|
|
233 |
// local variables |
|
234 |
aos_testresult_t result = {0,0}; |
|
235 |
uint8_t byteData, sensorState=0; |
|
236 |
uint16_t wordData; |
|
237 |
uint8_t ToFSensor = 1; // 0=Left, 1=Center(default), 2=Right |
|
238 |
uint16_t Distance; |
|
239 |
uint16_t SignalRate; |
|
240 |
uint16_t AmbientRate; |
|
241 |
uint8_t RangeStatus; |
|
242 |
uint8_t dataReady; |
|
243 |
int32_t status; |
|
244 |
chprintf(stream, "Hello World!\n"); |
|
245 |
// aosTestResultInit(&result); |
|
246 |
|
|
247 |
VL53L1_Dev_t dev; |
|
248 |
dev.vl53l1x = *(((aos_test_vl53l1x_bus*)test->data)->vl53l1x); |
|
249 |
// status = VL53L1_RdByte(&dev, 0x010F, &byteData); |
|
250 |
// printf("VL53L1X Model_ID: %X\n", byteData); |
|
251 |
// status = VL53L1_RdByte(&dev, 0x0110, &byteData); |
|
252 |
// printf("VL53L1X Module_Type: %X\n", byteData); |
|
253 |
// status = VL53L1_RdWord(&dev, 0x010F, &wordData); |
|
254 |
// printf("VL53L1X: %X\n", wordData); |
|
255 |
uint8_t testBuf[2] = {0}; |
|
256 |
// Reste device |
|
257 |
printf("Resetting device! \n"); |
|
258 |
VL53L1_WrByte(&dev, 0x0000, 0x00); |
|
259 |
aosThdSSleep(2); |
|
260 |
VL53L1_WrByte(&dev, 0x0000, 0x01); |
|
261 |
|
|
262 |
|
|
263 |
aosTestPassed(stream, &result); |
|
264 | 105 |
|
265 | 106 |
return result; |
266 | 107 |
} |
Also available in: Unified diff