LibDriver TCS34725
Loading...
Searching...
No Matches
driver_tcs34725_read_test.c
Go to the documentation of this file.
1
37
39
40static tcs34725_handle_t gs_handle;
41
50uint8_t tcs34725_read_test(uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 tcs34725_info_t info;
55
56 /* link interface function */
64
65 /* get chip information */
66 res = tcs34725_info(&info);
67 if (res != 0)
68 {
69 tcs34725_interface_debug_print("tcs34725: get info failed.\n");
70
71 return 1;
72 }
73 else
74 {
75 /* print chip information */
76 tcs34725_interface_debug_print("tcs34725: chip is %s.\n", info.chip_name);
77 tcs34725_interface_debug_print("tcs34725: manufacturer is %s.\n", info.manufacturer_name);
78 tcs34725_interface_debug_print("tcs34725: interface is %s.\n", info.interface);
79 tcs34725_interface_debug_print("tcs34725: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80 tcs34725_interface_debug_print("tcs34725: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81 tcs34725_interface_debug_print("tcs34725: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82 tcs34725_interface_debug_print("tcs34725: max current is %0.2fmA.\n", info.max_current_ma);
83 tcs34725_interface_debug_print("tcs34725: max temperature is %0.1fC.\n", info.temperature_max);
84 tcs34725_interface_debug_print("tcs34725: min temperature is %0.1fC.\n", info.temperature_min);
85 }
86
87 /* tcs34725 init */
88 res = tcs34725_init(&gs_handle);
89 if (res != 0)
90 {
91 tcs34725_interface_debug_print("tcs34725: init failed.\n");
92
93 return 1;
94 }
95
96 /* start read test */
97 tcs34725_interface_debug_print("tcs34725: start read test.\n");
98
99 /* disable rgbc interrupt */
101 if (res != 0)
102 {
103 tcs34725_interface_debug_print("tcs34725: set rgbc interrupt failed.\n");
104 (void)tcs34725_deinit(&gs_handle);
105
106 return 1;
107 }
108
109 /* enable wait */
110 res = tcs34725_set_wait(&gs_handle, TCS34725_BOOL_TRUE);
111 if (res != 0)
112 {
113 tcs34725_interface_debug_print("tcs34725: set wait failed.\n");
114 (void)tcs34725_deinit(&gs_handle);
115
116 return 1;
117 }
118
119 /* enable rgbc */
120 res = tcs34725_set_rgbc(&gs_handle, TCS34725_BOOL_TRUE);
121 if (res != 0)
122 {
123 tcs34725_interface_debug_print("tcs34725: set rgbc failed.\n");
124 (void)tcs34725_deinit(&gs_handle);
125
126 return 1;
127 }
128
129 /* set rgbc integration 50 ms */
131 if (res != 0)
132 {
133 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
134 (void)tcs34725_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* set wait time 2.4 ms */
141 if (res != 0)
142 {
143 tcs34725_interface_debug_print("tcs34725: set wait time failed.\n");
144 (void)tcs34725_deinit(&gs_handle);
145
146 return 1;
147 }
148
149 /* set rgbc clear low interrupt threshold 0x0000 */
150 res = tcs34725_set_rgbc_clear_low_interrupt_threshold(&gs_handle, 0x0000);
151 if (res != 0)
152 {
153 tcs34725_interface_debug_print("tcs34725: set rgbc clear low interrupt threshold failed.\n");
154 (void)tcs34725_deinit(&gs_handle);
155
156 return 1;
157 }
158
159 /* set rgbc clear high interrupt threshold 0xFFFF */
160 res = tcs34725_set_rgbc_clear_high_interrupt_threshold(&gs_handle, 0xFFFFU);
161 if (res != 0)
162 {
163 tcs34725_interface_debug_print("tcs34725: set rgbc clear high interrupt threshold failed.\n");
164 (void)tcs34725_deinit(&gs_handle);
165
166 return 1;
167 }
168
169 /* set 1x gain */
170 res = tcs34725_set_gain(&gs_handle, TCS34725_GAIN_1X);
171 if (res != 0)
172 {
173 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
174 (void)tcs34725_deinit(&gs_handle);
175
176 return 1;
177 }
178
179 /* set interrupt mode */
181 if (res != 0)
182 {
183 tcs34725_interface_debug_print("tcs34725: set interrupt mode failed.\n");
184 (void)tcs34725_deinit(&gs_handle);
185
186 return 1;
187 }
188
189 /* enable power on */
190 res = tcs34725_set_power_on(&gs_handle, TCS34725_BOOL_TRUE);
191 if (res != 0)
192 {
193 tcs34725_interface_debug_print("tcs34725: set power on failed.\n");
194 (void)tcs34725_deinit(&gs_handle);
195
196 return 1;
197 }
198
199 /* set gain 1x */
200 tcs34725_interface_debug_print("tcs34725: set 1x gain.\n");
201 res = tcs34725_set_gain(&gs_handle, TCS34725_GAIN_1X);
202 if (res != 0)
203 {
204 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
205 (void)tcs34725_deinit(&gs_handle);
206
207 return 1;
208 }
209
210 /* delay 1000 ms */
212 for (i = 0; i < times; i++)
213 {
214 uint16_t red, green, blue, clear;
215
216 /* read data */
217 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
218 {
219 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
220 (void)tcs34725_deinit(&gs_handle);
221
222 return 1;
223 }
224 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
225 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
226 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
227 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
229 }
231
232 /* set 4x gain */
233 tcs34725_interface_debug_print("tcs34725: set 4x gain.\n");
234 res = tcs34725_set_gain(&gs_handle, TCS34725_GAIN_4X);
235 if (res != 0)
236 {
237 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
238 (void)tcs34725_deinit(&gs_handle);
239
240 return 1;
241 }
242 for (i = 0; i < times; i++)
243 {
244 uint16_t red, green, blue, clear;
245
246 /* read data */
247 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
248 {
249 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
250 (void)tcs34725_deinit(&gs_handle);
251
252 return 1;
253 }
254 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
255 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
256 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
257 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
259 }
261
262 /* set 16x gain */
263 tcs34725_interface_debug_print("tcs34725: set 16x gain.\n");
264 res = tcs34725_set_gain(&gs_handle, TCS34725_GAIN_16X);
265 if (res != 0)
266 {
267 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
268 (void)tcs34725_deinit(&gs_handle);
269
270 return 1;
271 }
272 for (i = 0; i < times; i++)
273 {
274 uint16_t red, green, blue, clear;
275
276 /* read data */
277 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
278 {
279 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
280 (void)tcs34725_deinit(&gs_handle);
281
282 return 1;
283 }
284 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
285 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
286 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
287 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
289 }
291
292 /* set 60x gain */
293 tcs34725_interface_debug_print("tcs34725: set 60x gain.\n");
294 res = tcs34725_set_gain(&gs_handle, TCS34725_GAIN_60X);
295 if (res != 0)
296 {
297 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
298 (void)tcs34725_deinit(&gs_handle);
299
300 return 1;
301 }
302 for (i = 0; i < times; i++)
303 {
304 uint16_t red, green, blue, clear;
305
306 /* read data */
307 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
308 {
309 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
310 (void)tcs34725_deinit(&gs_handle);
311
312 return 1;
313 }
314 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
315 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
316 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
317 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
319 }
321
322 /* set 16x gain */
323 tcs34725_interface_debug_print("tcs34725: set rgbc integration time 2.4ms.\n");
324 res = tcs34725_set_gain(&gs_handle, TCS34725_GAIN_16X);
325 if (res != 0)
326 {
327 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
328 (void)tcs34725_deinit(&gs_handle);
329
330 return 1;
331 }
332
333 /* set integration time 2.4ms */
335 if (res != 0)
336 {
337 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
338 (void)tcs34725_deinit(&gs_handle);
339
340 return 1;
341 }
343 for (i = 0; i < times; i++)
344 {
345 uint16_t red, green, blue, clear;
346
347 /* read data */
348 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
349 {
350 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
351 (void)tcs34725_deinit(&gs_handle);
352
353 return 1;
354 }
355 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
356 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
357 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
358 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
360 }
361
362 /* set integration time 24ms */
363 tcs34725_interface_debug_print("tcs34725: set rgbc integration time 24ms.\n");
365 if (res != 0)
366 {
367 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
368 (void)tcs34725_deinit(&gs_handle);
369
370 return 1;
371 }
373 for (i = 0; i < times; i++)
374 {
375 uint16_t red, green, blue, clear;
376
377 /* read data */
378 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
379 {
380 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
381 (void)tcs34725_deinit(&gs_handle);
382
383 return 1;
384 }
385 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
386 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
387 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
388 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
390 }
391
392 /* set integration time 50ms */
393 tcs34725_interface_debug_print("tcs34725: set rgbc integration time 50ms.\n");
395 if (res != 0)
396 {
397 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
398 (void)tcs34725_deinit(&gs_handle);
399
400 return 1;
401 }
403 for (i = 0; i < times; i++)
404 {
405 uint16_t red, green, blue, clear;
406
407 /* read data */
408 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
409 {
410 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
411 (void)tcs34725_deinit(&gs_handle);
412
413 return 1;
414 }
415 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
416 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
417 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
418 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
420 }
421
422 /* set integration time 101ms */
423 tcs34725_interface_debug_print("tcs34725: set rgbc integration time 101ms.\n");
425 if (res != 0)
426 {
427 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
428 (void)tcs34725_deinit(&gs_handle);
429
430 return 1;
431 }
433 for (i = 0; i < times; i++)
434 {
435 uint16_t red, green, blue, clear;
436
437 /* read data */
438 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
439 {
440 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
441 (void)tcs34725_deinit(&gs_handle);
442
443 return 1;
444 }
445 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
446 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
447 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
448 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
450 }
451
452 /* set integration time 154ms */
453 tcs34725_interface_debug_print("tcs34725: set rgbc integration time 154ms.\n");
455 if (res != 0)
456 {
457 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
458 (void)tcs34725_deinit(&gs_handle);
459
460 return 1;
461 }
463 for (i = 0; i < times; i++)
464 {
465 uint16_t red, green, blue, clear;
466
467 /* read data */
468 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
469 {
470 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
471 (void)tcs34725_deinit(&gs_handle);
472
473 return 1;
474 }
475 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
476 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
477 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
478 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
480 }
481
482 /* set integration time 700ms */
483 tcs34725_interface_debug_print("tcs34725: set rgbc integration time 700ms.\n");
485 if (res != 0)
486 {
487 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
488 (void)tcs34725_deinit(&gs_handle);
489
490 return 1;
491 }
493 for (i = 0; i < times; i++)
494 {
495 uint16_t red, green, blue, clear;
496
497 /* read data */
498 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
499 {
500 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
501 (void)tcs34725_deinit(&gs_handle);
502
503 return 1;
504 }
505 tcs34725_interface_debug_print("tcs34725: red is %d.\n", red);
506 tcs34725_interface_debug_print("tcs34725: green is %d.\n", green);
507 tcs34725_interface_debug_print("tcs34725: blue is %d.\n", blue);
508 tcs34725_interface_debug_print("tcs34725: clear is %d.\n", clear);
510 }
511
512 /* finish read test */
513 tcs34725_interface_debug_print("tcs34725: finish read test.\n");
514 (void)tcs34725_deinit(&gs_handle);
515
516 return 0;
517}
driver tcs34725 read test header file
uint8_t tcs34725_set_rgbc_integration_time(tcs34725_handle_t *handle, tcs34725_integration_time_t t)
set the rgbc adc integration time
uint8_t tcs34725_deinit(tcs34725_handle_t *handle)
close the chip
struct tcs34725_info_s tcs34725_info_t
tcs34725 information structure definition
uint8_t tcs34725_set_gain(tcs34725_handle_t *handle, tcs34725_gain_t gain)
set the adc gain
uint8_t tcs34725_set_rgbc(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the rgbc adc
uint8_t tcs34725_set_wait_time(tcs34725_handle_t *handle, tcs34725_wait_time_t t)
set the wait time
uint8_t tcs34725_set_power_on(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the power
uint8_t tcs34725_info(tcs34725_info_t *info)
get chip information
struct tcs34725_handle_s tcs34725_handle_t
tcs34725 handle structure definition
uint8_t tcs34725_init(tcs34725_handle_t *handle)
initialize the chip
uint8_t tcs34725_read_rgbc(tcs34725_handle_t *handle, uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *clear)
read the rgbc data
uint8_t tcs34725_set_wait(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the wait time
@ TCS34725_BOOL_TRUE
@ TCS34725_BOOL_FALSE
@ TCS34725_WAIT_TIME_2P4MS
@ TCS34725_GAIN_16X
@ TCS34725_GAIN_4X
@ TCS34725_GAIN_1X
@ TCS34725_GAIN_60X
@ TCS34725_INTEGRATION_TIME_700MS
@ TCS34725_INTEGRATION_TIME_50MS
@ TCS34725_INTEGRATION_TIME_24MS
@ TCS34725_INTEGRATION_TIME_101MS
@ TCS34725_INTEGRATION_TIME_2P4MS
@ TCS34725_INTEGRATION_TIME_154MS
void tcs34725_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tcs34725_interface_iic_init(void)
interface iic bus init
uint8_t tcs34725_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t tcs34725_interface_iic_deinit(void)
interface iic bus deinit
uint8_t tcs34725_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void tcs34725_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tcs34725_set_rgbc_clear_high_interrupt_threshold(tcs34725_handle_t *handle, uint16_t threshold)
set the rgbc clear high interrupt threshold
uint8_t tcs34725_set_rgbc_interrupt(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the rgbc interrupt
uint8_t tcs34725_set_rgbc_clear_low_interrupt_threshold(tcs34725_handle_t *handle, uint16_t threshold)
set the rgbc clear low interrupt threshold
uint8_t tcs34725_set_interrupt_mode(tcs34725_handle_t *handle, tcs34725_interrupt_mode_t mode)
set the interrupt mode
@ TCS34725_INTERRUPT_MODE_1_CLEAR_CHANNEL_OUT_OF_THRESHOLD
uint8_t tcs34725_read_test(uint32_t times)
read test
char manufacturer_name[32]