LibDriver MAX30102
Loading...
Searching...
No Matches
driver_max30102_register_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static max30102_handle_t gs_handle;
41
50{
51 uint8_t res;
52 uint8_t pointer;
53 uint8_t pointer_check;
54 uint8_t value;
55 uint8_t value_check;
56 uint8_t revision_id;
57 uint8_t part_id;
58 max30102_info_t info;
59 max30102_bool_t enable;
62 max30102_mode_t mode;
66
67 /* link interface function */
76
77 /* get information */
78 res = max30102_info(&info);
79 if (res != 0)
80 {
81 max30102_interface_debug_print("max30102: get info failed.\n");
82
83 return 1;
84 }
85 else
86 {
87 /* print chip info */
88 max30102_interface_debug_print("max30102: chip is %s.\n", info.chip_name);
89 max30102_interface_debug_print("max30102: manufacturer is %s.\n", info.manufacturer_name);
90 max30102_interface_debug_print("max30102: interface is %s.\n", info.interface);
91 max30102_interface_debug_print("max30102: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
92 max30102_interface_debug_print("max30102: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
93 max30102_interface_debug_print("max30102: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
94 max30102_interface_debug_print("max30102: max current is %0.2fmA.\n", info.max_current_ma);
95 max30102_interface_debug_print("max30102: max temperature is %0.1fC.\n", info.temperature_max);
96 max30102_interface_debug_print("max30102: min temperature is %0.1fC.\n", info.temperature_min);
97 }
98
99 /* start register test */
100 max30102_interface_debug_print("max30102: start register test.\n");
101
102 /* init the max30102 */
103 res = max30102_init(&gs_handle);
104 if (res != 0)
105 {
106 max30102_interface_debug_print("max30102: init failed.\n");
107
108 return 1;
109 }
110
111 /* max30102_set_interrupt/max30102_get_interrupt test */
112 max30102_interface_debug_print("max30102: max30102_set_interrupt/max30102_get_interrupt test.\n");
113
114 /* enable fifo full */
116 if (res != 0)
117 {
118 max30102_interface_debug_print("max30102: set interrupt failed.\n");
119 (void)max30102_deinit(&gs_handle);
120
121 return 1;
122 }
123 max30102_interface_debug_print("max30102: enable fifo full.\n");
125 if (res != 0)
126 {
127 max30102_interface_debug_print("max30102: get interrupt failed.\n");
128 (void)max30102_deinit(&gs_handle);
129
130 return 1;
131 }
132 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_TRUE ? "ok" : "error");
133
134 /* disable fifo full */
136 if (res != 0)
137 {
138 max30102_interface_debug_print("max30102: set interrupt failed.\n");
139 (void)max30102_deinit(&gs_handle);
140
141 return 1;
142 }
143 max30102_interface_debug_print("max30102: disable fifo full.\n");
145 if (res != 0)
146 {
147 max30102_interface_debug_print("max30102: get interrupt failed.\n");
148 (void)max30102_deinit(&gs_handle);
149
150 return 1;
151 }
152 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_FALSE ? "ok" : "error");
153
154 /* enable ppg ready */
156 if (res != 0)
157 {
158 max30102_interface_debug_print("max30102: set interrupt failed.\n");
159 (void)max30102_deinit(&gs_handle);
160
161 return 1;
162 }
163 max30102_interface_debug_print("max30102: enable ppg ready.\n");
164 res = max30102_get_interrupt(&gs_handle, MAX30102_INTERRUPT_PPG_RDY_EN, &enable);
165 if (res != 0)
166 {
167 max30102_interface_debug_print("max30102: get interrupt failed.\n");
168 (void)max30102_deinit(&gs_handle);
169
170 return 1;
171 }
172 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_TRUE ? "ok" : "error");
173
174 /* disable ppg ready */
176 if (res != 0)
177 {
178 max30102_interface_debug_print("max30102: set interrupt failed.\n");
179 (void)max30102_deinit(&gs_handle);
180
181 return 1;
182 }
183 max30102_interface_debug_print("max30102: disable ppg ready.\n");
184 res = max30102_get_interrupt(&gs_handle, MAX30102_INTERRUPT_PPG_RDY_EN, &enable);
185 if (res != 0)
186 {
187 max30102_interface_debug_print("max30102: get interrupt failed.\n");
188 (void)max30102_deinit(&gs_handle);
189
190 return 1;
191 }
192 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_FALSE ? "ok" : "error");
193
194 /* enable alc ovf */
196 if (res != 0)
197 {
198 max30102_interface_debug_print("max30102: set interrupt failed.\n");
199 (void)max30102_deinit(&gs_handle);
200
201 return 1;
202 }
203 max30102_interface_debug_print("max30102: enable alc ovf.\n");
204 res = max30102_get_interrupt(&gs_handle, MAX30102_INTERRUPT_ALC_OVF_EN, &enable);
205 if (res != 0)
206 {
207 max30102_interface_debug_print("max30102: get interrupt failed.\n");
208 (void)max30102_deinit(&gs_handle);
209
210 return 1;
211 }
212 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_TRUE ? "ok" : "error");
213
214 /* disable alc ovf */
216 if (res != 0)
217 {
218 max30102_interface_debug_print("max30102: set interrupt failed.\n");
219 (void)max30102_deinit(&gs_handle);
220
221 return 1;
222 }
223 max30102_interface_debug_print("max30102: disable alc ovf.\n");
224 res = max30102_get_interrupt(&gs_handle, MAX30102_INTERRUPT_ALC_OVF_EN, &enable);
225 if (res != 0)
226 {
227 max30102_interface_debug_print("max30102: get interrupt failed.\n");
228 (void)max30102_deinit(&gs_handle);
229
230 return 1;
231 }
232 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_FALSE ? "ok" : "error");
233
234 /* enable die temp ready */
236 if (res != 0)
237 {
238 max30102_interface_debug_print("max30102: set interrupt failed.\n");
239 (void)max30102_deinit(&gs_handle);
240
241 return 1;
242 }
243 max30102_interface_debug_print("max30102: enable die temp ready.\n");
245 if (res != 0)
246 {
247 max30102_interface_debug_print("max30102: get interrupt failed.\n");
248 (void)max30102_deinit(&gs_handle);
249
250 return 1;
251 }
252 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_TRUE ? "ok" : "error");
253
254 /* disable die temp ready */
256 if (res != 0)
257 {
258 max30102_interface_debug_print("max30102: set interrupt failed.\n");
259 (void)max30102_deinit(&gs_handle);
260
261 return 1;
262 }
263 max30102_interface_debug_print("max30102: disable die temp ready.\n");
265 if (res != 0)
266 {
267 max30102_interface_debug_print("max30102: get interrupt failed.\n");
268 (void)max30102_deinit(&gs_handle);
269
270 return 1;
271 }
272 max30102_interface_debug_print("max30102: check interrupt %s.\n", enable == MAX30102_BOOL_FALSE ? "ok" : "error");
273
274 /* max30102_set_fifo_write_pointer/max30102_get_fifo_write_pointer test */
275 max30102_interface_debug_print("max30102: max30102_set_fifo_write_pointer/max30102_get_fifo_write_pointer test.\n");
276
277 pointer = rand() % 0x1F;
278 res = max30102_set_fifo_write_pointer(&gs_handle, pointer);
279 if (res != 0)
280 {
281 max30102_interface_debug_print("max30102: set fifo write pointer failed.\n");
282 (void)max30102_deinit(&gs_handle);
283
284 return 1;
285 }
286 max30102_interface_debug_print("max30102: set fifo write pointer %d.\n", pointer);
287 res = max30102_get_fifo_write_pointer(&gs_handle, (uint8_t *)&pointer_check);
288 if (res != 0)
289 {
290 max30102_interface_debug_print("max30102: get fifo write pointer failed.\n");
291 (void)max30102_deinit(&gs_handle);
292
293 return 1;
294 }
295
296 /* max30102_set_fifo_overflow_counter/max30102_get_fifo_overflow_counter test */
297 max30102_interface_debug_print("max30102: max30102_set_fifo_overflow_counter/max30102_get_fifo_overflow_counter test.\n");
298
299 pointer = rand() % 0x1F;
300 res = max30102_set_fifo_overflow_counter(&gs_handle, pointer);
301 if (res != 0)
302 {
303 max30102_interface_debug_print("max30102: set fifo overflow counter failed.\n");
304 (void)max30102_deinit(&gs_handle);
305
306 return 1;
307 }
308 max30102_interface_debug_print("max30102: set fifo overflow counter %d.\n", pointer);
309 res = max30102_get_fifo_overflow_counter(&gs_handle, (uint8_t *)&pointer_check);
310 if (res != 0)
311 {
312 max30102_interface_debug_print("max30102: get fifo overflow counter failed.\n");
313 (void)max30102_deinit(&gs_handle);
314
315 return 1;
316 }
317
318 /* max30102_set_fifo_read_pointer/max30102_get_fifo_read_pointer test */
319 max30102_interface_debug_print("max30102: max30102_set_fifo_read_pointer/max30102_get_fifo_read_pointer test.\n");
320
321 pointer = rand() % 0x1F;
322 res = max30102_set_fifo_read_pointer(&gs_handle, pointer);
323 if (res != 0)
324 {
325 max30102_interface_debug_print("max30102: set fifo read pointer failed.\n");
326 (void)max30102_deinit(&gs_handle);
327
328 return 1;
329 }
330 max30102_interface_debug_print("max30102: set fifo read pointer %d.\n", pointer);
331 res = max30102_get_fifo_read_pointer(&gs_handle, (uint8_t *)&pointer_check);
332 if (res != 0)
333 {
334 max30102_interface_debug_print("max30102: get fifo read pointer failed.\n");
335 (void)max30102_deinit(&gs_handle);
336
337 return 1;
338 }
339
340 /* max30102_set_fifo_data/max30102_get_fifo_data test */
341 max30102_interface_debug_print("max30102: max30102_set_fifo_data/max30102_get_fifo_data test.\n");
342
343 pointer = rand() % 0x1F;
344 res = max30102_set_fifo_data(&gs_handle, pointer);
345 if (res != 0)
346 {
347 max30102_interface_debug_print("max30102: set fifo data failed.\n");
348 (void)max30102_deinit(&gs_handle);
349
350 return 1;
351 }
352 max30102_interface_debug_print("max30102: set fifo data %d.\n", pointer);
353 res = max30102_get_fifo_data(&gs_handle, (uint8_t *)&pointer_check);
354 if (res != 0)
355 {
356 max30102_interface_debug_print("max30102: get fifo data failed.\n");
357 (void)max30102_deinit(&gs_handle);
358
359 return 1;
360 }
361
362 /* max30102_set_fifo_sample_averaging/max30102_get_fifo_sample_averaging test */
363 max30102_interface_debug_print("max30102: max30102_set_fifo_sample_averaging/max30102_get_fifo_sample_averaging test.\n");
364
365 /* set sample averaging 1 */
367 if (res != 0)
368 {
369 max30102_interface_debug_print("max30102: set fifo sample averaging failed.\n");
370 (void)max30102_deinit(&gs_handle);
371
372 return 1;
373 }
374 max30102_interface_debug_print("max30102: set sample averaging 1.\n");
375 res = max30102_get_fifo_sample_averaging(&gs_handle, &sample);
376 if (res != 0)
377 {
378 max30102_interface_debug_print("max30102: get fifo sample averaging failed.\n");
379 (void)max30102_deinit(&gs_handle);
380
381 return 1;
382 }
383 max30102_interface_debug_print("max30102: check sample %s.\n", sample == MAX30102_SAMPLE_AVERAGING_1 ? "ok" : "error");
384
385 /* set sample averaging 2 */
387 if (res != 0)
388 {
389 max30102_interface_debug_print("max30102: set fifo sample averaging failed.\n");
390 (void)max30102_deinit(&gs_handle);
391
392 return 1;
393 }
394 max30102_interface_debug_print("max30102: set sample averaging 2.\n");
395 res = max30102_get_fifo_sample_averaging(&gs_handle, &sample);
396 if (res != 0)
397 {
398 max30102_interface_debug_print("max30102: get fifo sample averaging failed.\n");
399 (void)max30102_deinit(&gs_handle);
400
401 return 1;
402 }
403 max30102_interface_debug_print("max30102: check sample %s.\n", sample == MAX30102_SAMPLE_AVERAGING_2 ? "ok" : "error");
404
405 /* set sample averaging 4 */
407 if (res != 0)
408 {
409 max30102_interface_debug_print("max30102: set fifo sample averaging failed.\n");
410 (void)max30102_deinit(&gs_handle);
411
412 return 1;
413 }
414 max30102_interface_debug_print("max30102: set sample averaging 4.\n");
415 res = max30102_get_fifo_sample_averaging(&gs_handle, &sample);
416 if (res != 0)
417 {
418 max30102_interface_debug_print("max30102: get fifo sample averaging failed.\n");
419 (void)max30102_deinit(&gs_handle);
420
421 return 1;
422 }
423 max30102_interface_debug_print("max30102: check sample %s.\n", sample == MAX30102_SAMPLE_AVERAGING_4 ? "ok" : "error");
424
425 /* set sample averaging 8 */
427 if (res != 0)
428 {
429 max30102_interface_debug_print("max30102: set fifo sample averaging failed.\n");
430 (void)max30102_deinit(&gs_handle);
431
432 return 1;
433 }
434 max30102_interface_debug_print("max30102: set sample averaging 8.\n");
435 res = max30102_get_fifo_sample_averaging(&gs_handle, &sample);
436 if (res != 0)
437 {
438 max30102_interface_debug_print("max30102: get fifo sample averaging failed.\n");
439 (void)max30102_deinit(&gs_handle);
440
441 return 1;
442 }
443 max30102_interface_debug_print("max30102: check sample %s.\n", sample == MAX30102_SAMPLE_AVERAGING_8 ? "ok" : "error");
444
445 /* set sample averaging 16 */
447 if (res != 0)
448 {
449 max30102_interface_debug_print("max30102: set fifo sample averaging failed.\n");
450 (void)max30102_deinit(&gs_handle);
451
452 return 1;
453 }
454 max30102_interface_debug_print("max30102: set sample averaging 16.\n");
455 res = max30102_get_fifo_sample_averaging(&gs_handle, &sample);
456 if (res != 0)
457 {
458 max30102_interface_debug_print("max30102: get fifo sample averaging failed.\n");
459 (void)max30102_deinit(&gs_handle);
460
461 return 1;
462 }
463 max30102_interface_debug_print("max30102: check sample %s.\n", sample == MAX30102_SAMPLE_AVERAGING_16 ? "ok" : "error");
464
465 /* set sample averaging 32 */
467 if (res != 0)
468 {
469 max30102_interface_debug_print("max30102: set fifo sample averaging failed.\n");
470 (void)max30102_deinit(&gs_handle);
471
472 return 1;
473 }
474 max30102_interface_debug_print("max30102: set sample averaging 32.\n");
475 res = max30102_get_fifo_sample_averaging(&gs_handle, &sample);
476 if (res != 0)
477 {
478 max30102_interface_debug_print("max30102: get fifo sample averaging failed.\n");
479 (void)max30102_deinit(&gs_handle);
480
481 return 1;
482 }
483 max30102_interface_debug_print("max30102: check sample %s.\n", sample == MAX30102_SAMPLE_AVERAGING_32 ? "ok" : "error");
484
485 /* max30102_set_fifo_roll/max30102_get_fifo_roll test */
486 max30102_interface_debug_print("max30102: max30102_set_fifo_roll/max30102_get_fifo_roll test.\n");
487
488 /* enable fifo roll */
490 if (res != 0)
491 {
492 max30102_interface_debug_print("max30102: set fifo roll failed.\n");
493 (void)max30102_deinit(&gs_handle);
494
495 return 1;
496 }
497 max30102_interface_debug_print("max30102: enable fifo roll.\n");
498 res = max30102_get_fifo_roll(&gs_handle, &enable);
499 if (res != 0)
500 {
501 max30102_interface_debug_print("max30102: get fifo roll failed.\n");
502 (void)max30102_deinit(&gs_handle);
503
504 return 1;
505 }
506 max30102_interface_debug_print("max30102: check roll %s.\n", enable == MAX30102_BOOL_TRUE ? "ok" : "error");
507
508 /* disable fifo roll */
510 if (res != 0)
511 {
512 max30102_interface_debug_print("max30102: set fifo roll failed.\n");
513 (void)max30102_deinit(&gs_handle);
514
515 return 1;
516 }
517 max30102_interface_debug_print("max30102: disable fifo roll.\n");
518 res = max30102_get_fifo_roll(&gs_handle, &enable);
519 if (res != 0)
520 {
521 max30102_interface_debug_print("max30102: get fifo roll failed.\n");
522 (void)max30102_deinit(&gs_handle);
523
524 return 1;
525 }
526 max30102_interface_debug_print("max30102: check roll %s.\n", enable == MAX30102_BOOL_FALSE ? "ok" : "error");
527
528 /* max30102_set_fifo_almost_full/max30102_get_fifo_almost_full test */
529 max30102_interface_debug_print("max30102: max30102_set_fifo_almost_full/max30102_get_fifo_almost_full test.\n");
530
531 value = rand() % 0xF;
532 res = max30102_set_fifo_almost_full(&gs_handle, value);
533 if (res != 0)
534 {
535 max30102_interface_debug_print("max30102: set fifo almost full failed.\n");
536 (void)max30102_deinit(&gs_handle);
537
538 return 1;
539 }
540 max30102_interface_debug_print("max30102: set fifo almost full %d.\n", value);
541 res = max30102_get_fifo_almost_full(&gs_handle, (uint8_t *)&value_check);
542 if (res != 0)
543 {
544 max30102_interface_debug_print("max30102: get fifo almost full failed.\n");
545 (void)max30102_deinit(&gs_handle);
546
547 return 1;
548 }
549 max30102_interface_debug_print("max30102: check fifo almost full %s.\n", value_check == value ? "ok" : "error");
550
551 /* max30102_set_shutdown/max30102_get_shutdown test */
552 max30102_interface_debug_print("max30102: max30102_set_shutdown/max30102_get_shutdown test.\n");
553
554 /* enable shutdown */
555 res = max30102_set_shutdown(&gs_handle, MAX30102_BOOL_TRUE);
556 if (res != 0)
557 {
558 max30102_interface_debug_print("max30102: set shutdown failed.\n");
559 (void)max30102_deinit(&gs_handle);
560
561 return 1;
562 }
563 max30102_interface_debug_print("max30102: enable shutdown.\n");
564 res = max30102_get_shutdown(&gs_handle, &enable);
565 if (res != 0)
566 {
567 max30102_interface_debug_print("max30102: get shutdown failed.\n");
568 (void)max30102_deinit(&gs_handle);
569
570 return 1;
571 }
572 max30102_interface_debug_print("max30102: check shutdown %s.\n", enable == MAX30102_BOOL_TRUE ? "ok" : "error");
573
574 /* disable shutdown */
576 if (res != 0)
577 {
578 max30102_interface_debug_print("max30102: set shutdown failed.\n");
579 (void)max30102_deinit(&gs_handle);
580
581 return 1;
582 }
583 max30102_interface_debug_print("max30102: disable shutdown.\n");
584 res = max30102_get_shutdown(&gs_handle, &enable);
585 if (res != 0)
586 {
587 max30102_interface_debug_print("max30102: get shutdown failed.\n");
588 (void)max30102_deinit(&gs_handle);
589
590 return 1;
591 }
592 max30102_interface_debug_print("max30102: check shutdown %s.\n", enable == MAX30102_BOOL_FALSE ? "ok" : "error");
593
594 /* max30102_set_mode/max30102_get_mode test */
595 max30102_interface_debug_print("max30102: max30102_set_mode/max30102_get_mode test.\n");
596
597 /* heart rate */
599 if (res != 0)
600 {
601 max30102_interface_debug_print("max30102: set mode failed.\n");
602 (void)max30102_deinit(&gs_handle);
603
604 return 1;
605 }
606 max30102_interface_debug_print("max30102: set heart rate mode.\n");
607 res = max30102_get_mode(&gs_handle, &mode);
608 if (res != 0)
609 {
610 max30102_interface_debug_print("max30102: get mode failed.\n");
611 (void)max30102_deinit(&gs_handle);
612
613 return 1;
614 }
615 max30102_interface_debug_print("max30102: check mode %s.\n", mode == MAX30102_MODE_HEART_RATE ? "ok" : "error");
616
617 /* spo2 */
618 res = max30102_set_mode(&gs_handle, MAX30102_MODE_SPO2);
619 if (res != 0)
620 {
621 max30102_interface_debug_print("max30102: set mode failed.\n");
622 (void)max30102_deinit(&gs_handle);
623
624 return 1;
625 }
626 max30102_interface_debug_print("max30102: set spo2 mode.\n");
627 res = max30102_get_mode(&gs_handle, &mode);
628 if (res != 0)
629 {
630 max30102_interface_debug_print("max30102: get mode failed.\n");
631 (void)max30102_deinit(&gs_handle);
632
633 return 1;
634 }
635 max30102_interface_debug_print("max30102: check mode %s.\n", mode == MAX30102_MODE_SPO2 ? "ok" : "error");
636
637 /* multi led */
639 if (res != 0)
640 {
641 max30102_interface_debug_print("max30102: set mode failed.\n");
642 (void)max30102_deinit(&gs_handle);
643
644 return 1;
645 }
646 max30102_interface_debug_print("max30102: set multi led mode.\n");
647 res = max30102_get_mode(&gs_handle, &mode);
648 if (res != 0)
649 {
650 max30102_interface_debug_print("max30102: get mode failed.\n");
651 (void)max30102_deinit(&gs_handle);
652
653 return 1;
654 }
655 max30102_interface_debug_print("max30102: check mode %s.\n", mode == MAX30102_MODE_MULTI_LED ? "ok" : "error");
656
657 /* max30102_set_spo2_adc_range/max30102_get_spo2_adc_range test */
658 max30102_interface_debug_print("max30102: max30102_set_spo2_adc_range/max30102_get_spo2_adc_range test.\n");
659
660 /* 2048 */
662 if (res != 0)
663 {
664 max30102_interface_debug_print("max30102: set spo2 adc range failed.\n");
665 (void)max30102_deinit(&gs_handle);
666
667 return 1;
668 }
669 max30102_interface_debug_print("max30102: set spo2 adc range 2048.\n");
670 res = max30102_get_spo2_adc_range(&gs_handle, &range);
671 if (res != 0)
672 {
673 max30102_interface_debug_print("max30102: get spo2 adc range failed.\n");
674 (void)max30102_deinit(&gs_handle);
675
676 return 1;
677 }
678 max30102_interface_debug_print("max30102: check spo2 adc range %s.\n", range == MAX30102_SPO2_ADC_RANGE_2048 ? "ok" : "error");
679
680 /* 4096 */
682 if (res != 0)
683 {
684 max30102_interface_debug_print("max30102: set spo2 adc range failed.\n");
685 (void)max30102_deinit(&gs_handle);
686
687 return 1;
688 }
689 max30102_interface_debug_print("max30102: set spo2 adc range 4096.\n");
690 res = max30102_get_spo2_adc_range(&gs_handle, &range);
691 if (res != 0)
692 {
693 max30102_interface_debug_print("max30102: get spo2 adc range failed.\n");
694 (void)max30102_deinit(&gs_handle);
695
696 return 1;
697 }
698 max30102_interface_debug_print("max30102: check spo2 adc range %s.\n", range == MAX30102_SPO2_ADC_RANGE_4096 ? "ok" : "error");
699
700 /* 8192 */
702 if (res != 0)
703 {
704 max30102_interface_debug_print("max30102: set spo2 adc range failed.\n");
705 (void)max30102_deinit(&gs_handle);
706
707 return 1;
708 }
709 max30102_interface_debug_print("max30102: set spo2 adc range 8192.\n");
710 res = max30102_get_spo2_adc_range(&gs_handle, &range);
711 if (res != 0)
712 {
713 max30102_interface_debug_print("max30102: get spo2 adc range failed.\n");
714 (void)max30102_deinit(&gs_handle);
715
716 return 1;
717 }
718 max30102_interface_debug_print("max30102: check spo2 adc range %s.\n", range == MAX30102_SPO2_ADC_RANGE_8192 ? "ok" : "error");
719
720 /* 16384 */
722 if (res != 0)
723 {
724 max30102_interface_debug_print("max30102: set spo2 adc range failed.\n");
725 (void)max30102_deinit(&gs_handle);
726
727 return 1;
728 }
729 max30102_interface_debug_print("max30102: set spo2 adc range 16384.\n");
730 res = max30102_get_spo2_adc_range(&gs_handle, &range);
731 if (res != 0)
732 {
733 max30102_interface_debug_print("max30102: get spo2 adc range failed.\n");
734 (void)max30102_deinit(&gs_handle);
735
736 return 1;
737 }
738 max30102_interface_debug_print("max30102: check spo2 adc range %s.\n", range == MAX30102_SPO2_ADC_RANGE_16384 ? "ok" : "error");
739
740 /* max30102_set_spo2_sample_rate/max30102_get_spo2_sample_rate test */
741 max30102_interface_debug_print("max30102: max30102_set_spo2_sample_rate/max30102_get_spo2_sample_rate test.\n");
742
743 /* 50Hz */
745 if (res != 0)
746 {
747 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
748 (void)max30102_deinit(&gs_handle);
749
750 return 1;
751 }
752 max30102_interface_debug_print("max30102: set spo2 sample rate 50Hz.\n");
753 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
754 if (res != 0)
755 {
756 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
757 (void)max30102_deinit(&gs_handle);
758
759 return 1;
760 }
761 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_50_HZ ? "ok" : "error");
762
763 /* 100Hz */
765 if (res != 0)
766 {
767 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
768 (void)max30102_deinit(&gs_handle);
769
770 return 1;
771 }
772 max30102_interface_debug_print("max30102: set spo2 sample rate 100Hz.\n");
773 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
774 if (res != 0)
775 {
776 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
777 (void)max30102_deinit(&gs_handle);
778
779 return 1;
780 }
781 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_100_HZ ? "ok" : "error");
782
783 /* 200Hz */
785 if (res != 0)
786 {
787 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
788 (void)max30102_deinit(&gs_handle);
789
790 return 1;
791 }
792 max30102_interface_debug_print("max30102: set spo2 sample rate 200Hz.\n");
793 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
794 if (res != 0)
795 {
796 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
797 (void)max30102_deinit(&gs_handle);
798
799 return 1;
800 }
801 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_200_HZ ? "ok" : "error");
802
803 /* 400Hz */
805 if (res != 0)
806 {
807 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
808 (void)max30102_deinit(&gs_handle);
809
810 return 1;
811 }
812 max30102_interface_debug_print("max30102: set spo2 sample rate 400Hz.\n");
813 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
814 if (res != 0)
815 {
816 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
817 (void)max30102_deinit(&gs_handle);
818
819 return 1;
820 }
821 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_400_HZ ? "ok" : "error");
822
823 /* 800Hz */
825 if (res != 0)
826 {
827 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
828 (void)max30102_deinit(&gs_handle);
829
830 return 1;
831 }
832 max30102_interface_debug_print("max30102: set spo2 sample rate 800Hz.\n");
833 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
834 if (res != 0)
835 {
836 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
837 (void)max30102_deinit(&gs_handle);
838
839 return 1;
840 }
841 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_800_HZ ? "ok" : "error");
842
843 /* 1000Hz */
845 if (res != 0)
846 {
847 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
848 (void)max30102_deinit(&gs_handle);
849
850 return 1;
851 }
852 max30102_interface_debug_print("max30102: set spo2 sample rate 1000Hz.\n");
853 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
854 if (res != 0)
855 {
856 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
857 (void)max30102_deinit(&gs_handle);
858
859 return 1;
860 }
861 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_1000_HZ ? "ok" : "error");
862
863 /* 1600Hz */
865 if (res != 0)
866 {
867 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
868 (void)max30102_deinit(&gs_handle);
869
870 return 1;
871 }
872 max30102_interface_debug_print("max30102: set spo2 sample rate 1600Hz.\n");
873 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
874 if (res != 0)
875 {
876 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
877 (void)max30102_deinit(&gs_handle);
878
879 return 1;
880 }
881 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_1600_HZ ? "ok" : "error");
882
883 /* 3200Hz */
885 if (res != 0)
886 {
887 max30102_interface_debug_print("max30102: set spo2 sample rate failed.\n");
888 (void)max30102_deinit(&gs_handle);
889
890 return 1;
891 }
892 max30102_interface_debug_print("max30102: set spo2 sample rate 3200Hz.\n");
893 res = max30102_get_spo2_sample_rate(&gs_handle, &rate);
894 if (res != 0)
895 {
896 max30102_interface_debug_print("max30102: get spo2 sample rate failed.\n");
897 (void)max30102_deinit(&gs_handle);
898
899 return 1;
900 }
901 max30102_interface_debug_print("max30102: check spo2 sample rate %s.\n", rate == MAX30102_SPO2_SAMPLE_RATE_3200_HZ ? "ok" : "error");
902
903 /* max30102_set_adc_resolution/max30102_get_adc_resolution test */
904 max30102_interface_debug_print("max30102: max30102_set_adc_resolution/max30102_get_adc_resolution test.\n");
905
906 /* 15 bits */
908 if (res != 0)
909 {
910 max30102_interface_debug_print("max30102: set adc resolution failed.\n");
911 (void)max30102_deinit(&gs_handle);
912
913 return 1;
914 }
915 max30102_interface_debug_print("max30102: set adc resolution 15 bits.\n");
916 res = max30102_get_adc_resolution(&gs_handle, &resolution);
917 if (res != 0)
918 {
919 max30102_interface_debug_print("max30102: get adc resolution failed.\n");
920 (void)max30102_deinit(&gs_handle);
921
922 return 1;
923 }
924 max30102_interface_debug_print("max30102: check adc resolution %s.\n", resolution == MAX30102_ADC_RESOLUTION_15_BIT ? "ok" : "error");
925
926 /* 16 bits */
928 if (res != 0)
929 {
930 max30102_interface_debug_print("max30102: set adc resolution failed.\n");
931 (void)max30102_deinit(&gs_handle);
932
933 return 1;
934 }
935 max30102_interface_debug_print("max30102: set adc resolution 16 bits.\n");
936 res = max30102_get_adc_resolution(&gs_handle, &resolution);
937 if (res != 0)
938 {
939 max30102_interface_debug_print("max30102: get adc resolution failed.\n");
940 (void)max30102_deinit(&gs_handle);
941
942 return 1;
943 }
944 max30102_interface_debug_print("max30102: check adc resolution %s.\n", resolution == MAX30102_ADC_RESOLUTION_16_BIT ? "ok" : "error");
945
946 /* 17 bits */
948 if (res != 0)
949 {
950 max30102_interface_debug_print("max30102: set adc resolution failed.\n");
951 (void)max30102_deinit(&gs_handle);
952
953 return 1;
954 }
955 max30102_interface_debug_print("max30102: set adc resolution 17 bits.\n");
956 res = max30102_get_adc_resolution(&gs_handle, &resolution);
957 if (res != 0)
958 {
959 max30102_interface_debug_print("max30102: get adc resolution failed.\n");
960 (void)max30102_deinit(&gs_handle);
961
962 return 1;
963 }
964 max30102_interface_debug_print("max30102: check adc resolution %s.\n", resolution == MAX30102_ADC_RESOLUTION_17_BIT ? "ok" : "error");
965
966 /* 18 bits */
968 if (res != 0)
969 {
970 max30102_interface_debug_print("max30102: set adc resolution failed.\n");
971 (void)max30102_deinit(&gs_handle);
972
973 return 1;
974 }
975 max30102_interface_debug_print("max30102: set adc resolution 18 bits.\n");
976 res = max30102_get_adc_resolution(&gs_handle, &resolution);
977 if (res != 0)
978 {
979 max30102_interface_debug_print("max30102: get adc resolution failed.\n");
980 (void)max30102_deinit(&gs_handle);
981
982 return 1;
983 }
984 max30102_interface_debug_print("max30102: check adc resolution %s.\n", resolution == MAX30102_ADC_RESOLUTION_18_BIT ? "ok" : "error");
985
986 /* max30102_set_led_red_pulse_amplitude/max30102_get_led_red_pulse_amplitude test */
987 max30102_interface_debug_print("max30102: max30102_set_led_red_pulse_amplitude/max30102_get_led_red_pulse_amplitude test.\n");
988
989 value = rand() % 256;
990 res = max30102_set_led_red_pulse_amplitude(&gs_handle, value);
991 if (res != 0)
992 {
993 max30102_interface_debug_print("max30102: set led red pulse amplitude failed.\n");
994 (void)max30102_deinit(&gs_handle);
995
996 return 1;
997 }
998 max30102_interface_debug_print("max30102: set led red pulse amplitude %d.\n", value);
999 res = max30102_get_led_red_pulse_amplitude(&gs_handle, (uint8_t *)&value_check);
1000 if (res != 0)
1001 {
1002 max30102_interface_debug_print("max30102: get led red pulse amplitude failed.\n");
1003 (void)max30102_deinit(&gs_handle);
1004
1005 return 1;
1006 }
1007 max30102_interface_debug_print("max30102: check led red pulse amplitude %s.\n", value_check == value ? "ok" : "error");
1008
1009 /* max30102_set_led_ir_pulse_amplitude/max30102_get_led_ir_pulse_amplitude test */
1010 max30102_interface_debug_print("max30102: max30102_set_led_ir_pulse_amplitude/max30102_get_led_ir_pulse_amplitude test.\n");
1011
1012 value = rand() % 256;
1013 res = max30102_set_led_ir_pulse_amplitude(&gs_handle, value);
1014 if (res != 0)
1015 {
1016 max30102_interface_debug_print("max30102: set led ir pulse amplitude failed.\n");
1017 (void)max30102_deinit(&gs_handle);
1018
1019 return 1;
1020 }
1021 max30102_interface_debug_print("max30102: set led ir pulse amplitude %d.\n", value);
1022 res = max30102_get_led_ir_pulse_amplitude(&gs_handle, (uint8_t *)&value_check);
1023 if (res != 0)
1024 {
1025 max30102_interface_debug_print("max30102: get led ir pulse amplitude failed.\n");
1026 (void)max30102_deinit(&gs_handle);
1027
1028 return 1;
1029 }
1030 max30102_interface_debug_print("max30102: check led ir pulse amplitude %s.\n", value_check == value ? "ok" : "error");
1031
1032 /* max30102_set_slot/max30102_get_slot test */
1033 max30102_interface_debug_print("max30102: max30102_set_slot/max30102_get_slot test.\n");
1034
1035 /* slot1 led none */
1037 if (res != 0)
1038 {
1039 max30102_interface_debug_print("max30102: set slot failed.\n");
1040 (void)max30102_deinit(&gs_handle);
1041
1042 return 1;
1043 }
1044 max30102_interface_debug_print("max30102: set slot1 led none.\n");
1045 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_1, &led);
1046 if (res != 0)
1047 {
1048 max30102_interface_debug_print("max30102: get slot failed.\n");
1049 (void)max30102_deinit(&gs_handle);
1050
1051 return 1;
1052 }
1053 max30102_interface_debug_print("max30102: check slot1 %s.\n", led == MAX30102_LED_NONE ? "ok" : "error");
1054
1055 /* slot1 led red */
1057 if (res != 0)
1058 {
1059 max30102_interface_debug_print("max30102: set slot failed.\n");
1060 (void)max30102_deinit(&gs_handle);
1061
1062 return 1;
1063 }
1064 max30102_interface_debug_print("max30102: set slot1 led red.\n");
1065 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_1, &led);
1066 if (res != 0)
1067 {
1068 max30102_interface_debug_print("max30102: get slot failed.\n");
1069 (void)max30102_deinit(&gs_handle);
1070
1071 return 1;
1072 }
1073 max30102_interface_debug_print("max30102: check slot1 %s.\n", led == MAX30102_LED_RED ? "ok" : "error");
1074
1075 /* slot1 led ir */
1077 if (res != 0)
1078 {
1079 max30102_interface_debug_print("max30102: set slot failed.\n");
1080 (void)max30102_deinit(&gs_handle);
1081
1082 return 1;
1083 }
1084 max30102_interface_debug_print("max30102: set slot1 led ir.\n");
1085 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_1, &led);
1086 if (res != 0)
1087 {
1088 max30102_interface_debug_print("max30102: get slot failed.\n");
1089 (void)max30102_deinit(&gs_handle);
1090
1091 return 1;
1092 }
1093 max30102_interface_debug_print("max30102: check slot1 %s.\n", led == MAX30102_LED_IR ? "ok" : "error");
1094
1095 /* slot2 led none */
1097 if (res != 0)
1098 {
1099 max30102_interface_debug_print("max30102: set slot failed.\n");
1100 (void)max30102_deinit(&gs_handle);
1101
1102 return 1;
1103 }
1104 max30102_interface_debug_print("max30102: set slot2 led none.\n");
1105 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_2, &led);
1106 if (res != 0)
1107 {
1108 max30102_interface_debug_print("max30102: get slot failed.\n");
1109 (void)max30102_deinit(&gs_handle);
1110
1111 return 1;
1112 }
1113 max30102_interface_debug_print("max30102: check slot2 %s.\n", led == MAX30102_LED_NONE ? "ok" : "error");
1114
1115 /* slot2 led red */
1117 if (res != 0)
1118 {
1119 max30102_interface_debug_print("max30102: set slot failed.\n");
1120 (void)max30102_deinit(&gs_handle);
1121
1122 return 1;
1123 }
1124 max30102_interface_debug_print("max30102: set slot2 led red.\n");
1125 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_2, &led);
1126 if (res != 0)
1127 {
1128 max30102_interface_debug_print("max30102: get slot failed.\n");
1129 (void)max30102_deinit(&gs_handle);
1130
1131 return 1;
1132 }
1133 max30102_interface_debug_print("max30102: check slot2 %s.\n", led == MAX30102_LED_RED ? "ok" : "error");
1134
1135 /* slot2 led ir */
1137 if (res != 0)
1138 {
1139 max30102_interface_debug_print("max30102: set slot failed.\n");
1140 (void)max30102_deinit(&gs_handle);
1141
1142 return 1;
1143 }
1144 max30102_interface_debug_print("max30102: set slot2 led ir.\n");
1145 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_2, &led);
1146 if (res != 0)
1147 {
1148 max30102_interface_debug_print("max30102: get slot failed.\n");
1149 (void)max30102_deinit(&gs_handle);
1150
1151 return 1;
1152 }
1153 max30102_interface_debug_print("max30102: check slot2 %s.\n", led == MAX30102_LED_IR ? "ok" : "error");
1154
1155 /* slot3 led none */
1157 if (res != 0)
1158 {
1159 max30102_interface_debug_print("max30102: set slot failed.\n");
1160 (void)max30102_deinit(&gs_handle);
1161
1162 return 1;
1163 }
1164 max30102_interface_debug_print("max30102: set slot3 led none.\n");
1165 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_3, &led);
1166 if (res != 0)
1167 {
1168 max30102_interface_debug_print("max30102: get slot failed.\n");
1169 (void)max30102_deinit(&gs_handle);
1170
1171 return 1;
1172 }
1173 max30102_interface_debug_print("max30102: check slot3 %s.\n", led == MAX30102_LED_NONE ? "ok" : "error");
1174
1175 /* slot3 led red */
1177 if (res != 0)
1178 {
1179 max30102_interface_debug_print("max30102: set slot failed.\n");
1180 (void)max30102_deinit(&gs_handle);
1181
1182 return 1;
1183 }
1184 max30102_interface_debug_print("max30102: set slot3 led red.\n");
1185 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_3, &led);
1186 if (res != 0)
1187 {
1188 max30102_interface_debug_print("max30102: get slot failed.\n");
1189 (void)max30102_deinit(&gs_handle);
1190
1191 return 1;
1192 }
1193 max30102_interface_debug_print("max30102: check slot3 %s.\n", led == MAX30102_LED_RED ? "ok" : "error");
1194
1195 /* slot3 led ir */
1197 if (res != 0)
1198 {
1199 max30102_interface_debug_print("max30102: set slot failed.\n");
1200 (void)max30102_deinit(&gs_handle);
1201
1202 return 1;
1203 }
1204 max30102_interface_debug_print("max30102: set slot3 led ir.\n");
1205 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_3, &led);
1206 if (res != 0)
1207 {
1208 max30102_interface_debug_print("max30102: get slot failed.\n");
1209 (void)max30102_deinit(&gs_handle);
1210
1211 return 1;
1212 }
1213 max30102_interface_debug_print("max30102: check slot3 %s.\n", led == MAX30102_LED_IR ? "ok" : "error");
1214
1215 /* slot4 led none */
1217 if (res != 0)
1218 {
1219 max30102_interface_debug_print("max30102: set slot failed.\n");
1220 (void)max30102_deinit(&gs_handle);
1221
1222 return 1;
1223 }
1224 max30102_interface_debug_print("max30102: set slot4 led none.\n");
1225 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_4, &led);
1226 if (res != 0)
1227 {
1228 max30102_interface_debug_print("max30102: get slot failed.\n");
1229 (void)max30102_deinit(&gs_handle);
1230
1231 return 1;
1232 }
1233 max30102_interface_debug_print("max30102: check slot4 %s.\n", led == MAX30102_LED_NONE ? "ok" : "error");
1234
1235 /* slot4 led red */
1237 if (res != 0)
1238 {
1239 max30102_interface_debug_print("max30102: set slot failed.\n");
1240 (void)max30102_deinit(&gs_handle);
1241
1242 return 1;
1243 }
1244 max30102_interface_debug_print("max30102: set slot4 led red.\n");
1245 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_4, &led);
1246 if (res != 0)
1247 {
1248 max30102_interface_debug_print("max30102: get slot failed.\n");
1249 (void)max30102_deinit(&gs_handle);
1250
1251 return 1;
1252 }
1253 max30102_interface_debug_print("max30102: check slot4 %s.\n", led == MAX30102_LED_RED ? "ok" : "error");
1254
1255 /* slot4 led ir */
1257 if (res != 0)
1258 {
1259 max30102_interface_debug_print("max30102: set slot failed.\n");
1260 (void)max30102_deinit(&gs_handle);
1261
1262 return 1;
1263 }
1264 max30102_interface_debug_print("max30102: set slot4 led ir.\n");
1265 res = max30102_get_slot(&gs_handle, MAX30102_SLOT_4, &led);
1266 if (res != 0)
1267 {
1268 max30102_interface_debug_print("max30102: get slot failed.\n");
1269 (void)max30102_deinit(&gs_handle);
1270
1271 return 1;
1272 }
1273 max30102_interface_debug_print("max30102: check slot4 %s.\n", led == MAX30102_LED_IR ? "ok" : "error");
1274
1275 /* max30102_set_die_temperature/max30102_get_die_temperature test */
1276 max30102_interface_debug_print("max30102: max30102_set_die_temperature/max30102_get_die_temperature test.\n");
1277
1278 /* disable */
1280 if (res != 0)
1281 {
1282 max30102_interface_debug_print("max30102: set die temperature failed.\n");
1283 (void)max30102_deinit(&gs_handle);
1284
1285 return 1;
1286 }
1287 max30102_interface_debug_print("max30102: disable die temperature.\n");
1288 res = max30102_get_die_temperature(&gs_handle, &enable);
1289 if (res != 0)
1290 {
1291 max30102_interface_debug_print("max30102: get die temperature failed.\n");
1292 (void)max30102_deinit(&gs_handle);
1293
1294 return 1;
1295 }
1296 max30102_interface_debug_print("max30102: check die temperature %s.\n", enable == MAX30102_BOOL_FALSE ? "ok" : "error");
1297
1298 /* enable */
1300 if (res != 0)
1301 {
1302 max30102_interface_debug_print("max30102: set die temperature failed.\n");
1303 (void)max30102_deinit(&gs_handle);
1304
1305 return 1;
1306 }
1307 max30102_interface_debug_print("max30102: enable die temperature.\n");
1308 res = max30102_get_die_temperature(&gs_handle, &enable);
1309 if (res != 0)
1310 {
1311 max30102_interface_debug_print("max30102: get die temperature failed.\n");
1312 (void)max30102_deinit(&gs_handle);
1313
1314 return 1;
1315 }
1316 max30102_interface_debug_print("max30102: check die temperature %s.\n", res == 0 ? "ok" : "error");
1317
1318 /* max30102_get_id test */
1319 max30102_interface_debug_print("max30102: max30102_get_id test.\n");
1320
1321 /* get id */
1322 res = max30102_get_id(&gs_handle, (uint8_t *)&revision_id, (uint8_t *)&part_id);
1323 if (res != 0)
1324 {
1325 max30102_interface_debug_print("max30102: get id failed.\n");
1326 (void)max30102_deinit(&gs_handle);
1327
1328 return 1;
1329 }
1330 max30102_interface_debug_print("max30102: revision id is 0x%02X part id is 0x%02X.\n", revision_id, part_id);
1331
1332 /* max30102_get_interrupt_status test */
1333 max30102_interface_debug_print("max30102: max30102_get_interrupt_status test.\n");
1334
1335 /* get fifo full */
1337 if (res != 0)
1338 {
1339 max30102_interface_debug_print("max30102: get interrupt status failed.\n");
1340 (void)max30102_deinit(&gs_handle);
1341
1342 return 1;
1343 }
1344 max30102_interface_debug_print("max30102: interrupt status fifo full is %d.\n", enable);
1345
1346 /* get ppg ready */
1348 if (res != 0)
1349 {
1350 max30102_interface_debug_print("max30102: get interrupt status failed.\n");
1351 (void)max30102_deinit(&gs_handle);
1352
1353 return 1;
1354 }
1355 max30102_interface_debug_print("max30102: interrupt status ppg ready is %d.\n", enable);
1356
1357 /* get alc ovf */
1359 if (res != 0)
1360 {
1361 max30102_interface_debug_print("max30102: get interrupt status failed.\n");
1362 (void)max30102_deinit(&gs_handle);
1363
1364 return 1;
1365 }
1366 max30102_interface_debug_print("max30102: interrupt status alc ovf is %d.\n", enable);
1367
1368 /* get pwr ready */
1370 if (res != 0)
1371 {
1372 max30102_interface_debug_print("max30102: get interrupt status failed.\n");
1373 (void)max30102_deinit(&gs_handle);
1374
1375 return 1;
1376 }
1377 max30102_interface_debug_print("max30102: interrupt status pwr ready is %d.\n", enable);
1378
1379 /* get die temp ready */
1381 if (res != 0)
1382 {
1383 max30102_interface_debug_print("max30102: get interrupt status failed.\n");
1384 (void)max30102_deinit(&gs_handle);
1385
1386 return 1;
1387 }
1388 max30102_interface_debug_print("max30102: interrupt status die temp ready is %d.\n", enable);
1389
1390 /* max30102_reset test */
1391 max30102_interface_debug_print("max30102: max30102_reset test.\n");
1392
1393 /* reset */
1394 res = max30102_reset(&gs_handle);
1395 if (res != 0)
1396 {
1397 max30102_interface_debug_print("max30102: reset failed.\n");
1398 (void)max30102_deinit(&gs_handle);
1399
1400 return 1;
1401 }
1402 max30102_interface_debug_print("max30102: check reset %s.\n", res == 0 ? "ok" : "error");
1404
1405 /* finish register test */
1406 max30102_interface_debug_print("max30102: finish register test.\n");
1407 (void)max30102_deinit(&gs_handle);
1408
1409 return 0;
1410}
driver max30102 register test header file
uint8_t max30102_set_slot(max30102_handle_t *handle, max30102_slot_t slot, max30102_led_t led)
set the led slot
uint8_t max30102_get_slot(max30102_handle_t *handle, max30102_slot_t slot, max30102_led_t *led)
get the led slot
uint8_t max30102_set_fifo_read_pointer(max30102_handle_t *handle, uint8_t pointer)
set the fifo read pointer
uint8_t max30102_set_die_temperature(max30102_handle_t *handle, max30102_bool_t enable)
enable or disable die temperature
max30102_bool_t
max30102 bool enumeration definition
uint8_t max30102_get_fifo_write_pointer(max30102_handle_t *handle, uint8_t *pointer)
get the fifo write pointer
uint8_t max30102_set_fifo_roll(max30102_handle_t *handle, max30102_bool_t enable)
enable or disable the fifo roll
uint8_t max30102_get_interrupt(max30102_handle_t *handle, max30102_interrupt_t type, max30102_bool_t *enable)
get the interrupt bool
uint8_t max30102_reset(max30102_handle_t *handle)
reset the chip
uint8_t max30102_get_mode(max30102_handle_t *handle, max30102_mode_t *mode)
get the mode
uint8_t max30102_get_fifo_roll(max30102_handle_t *handle, max30102_bool_t *enable)
get the fifo roll status
uint8_t max30102_get_fifo_data(max30102_handle_t *handle, uint8_t *data)
get the fifo data
uint8_t max30102_get_interrupt_status(max30102_handle_t *handle, max30102_interrupt_status_t status, max30102_bool_t *enable)
get the interrupt status
uint8_t max30102_set_fifo_almost_full(max30102_handle_t *handle, uint8_t value)
set the fifo almost full value
uint8_t max30102_get_led_red_pulse_amplitude(max30102_handle_t *handle, uint8_t *amp)
get the red led pulse amplitude
uint8_t max30102_info(max30102_info_t *info)
get chip's information
uint8_t max30102_set_fifo_sample_averaging(max30102_handle_t *handle, max30102_sample_averaging_t sample)
set the fifo sample averaging
uint8_t max30102_set_led_red_pulse_amplitude(max30102_handle_t *handle, uint8_t amp)
set the red led pulse amplitude
uint8_t max30102_get_fifo_sample_averaging(max30102_handle_t *handle, max30102_sample_averaging_t *sample)
get the fifo sample averaging
uint8_t max30102_set_mode(max30102_handle_t *handle, max30102_mode_t mode)
set the mode
uint8_t max30102_get_spo2_adc_range(max30102_handle_t *handle, max30102_spo2_adc_range_t *range)
get the spo2 adc range
uint8_t max30102_set_shutdown(max30102_handle_t *handle, max30102_bool_t enable)
set the shutdown
uint8_t max30102_get_led_ir_pulse_amplitude(max30102_handle_t *handle, uint8_t *amp)
get the ir led pulse amplitude
uint8_t max30102_deinit(max30102_handle_t *handle)
close the chip
uint8_t max30102_set_spo2_adc_range(max30102_handle_t *handle, max30102_spo2_adc_range_t range)
set the spo2 adc range
uint8_t max30102_get_fifo_read_pointer(max30102_handle_t *handle, uint8_t *pointer)
get the fifo read pointer
max30102_spo2_adc_range_t
max30102 spo2 adc range enumeration definition
uint8_t max30102_set_spo2_sample_rate(max30102_handle_t *handle, max30102_spo2_sample_rate_t rate)
set the spo2 sample rate
uint8_t max30102_get_fifo_overflow_counter(max30102_handle_t *handle, uint8_t *counter)
get the fifo overflow counter
uint8_t max30102_set_interrupt(max30102_handle_t *handle, max30102_interrupt_t type, max30102_bool_t enable)
set the interrupt bool
uint8_t max30102_get_die_temperature(max30102_handle_t *handle, max30102_bool_t *enable)
get the die temperature status
uint8_t max30102_set_led_ir_pulse_amplitude(max30102_handle_t *handle, uint8_t amp)
set the ir led pulse amplitude
uint8_t max30102_get_id(max30102_handle_t *handle, uint8_t *revision_id, uint8_t *part_id)
get the chip id
struct max30102_info_s max30102_info_t
max30102 information structure definition
uint8_t max30102_init(max30102_handle_t *handle)
initialize the chip
max30102_spo2_sample_rate_t
max30102 spo2 sample rate enumeration definition
uint8_t max30102_set_fifo_data(max30102_handle_t *handle, uint8_t data)
set the fifo data
uint8_t max30102_get_spo2_sample_rate(max30102_handle_t *handle, max30102_spo2_sample_rate_t *rate)
get the spo2 sample rate
max30102_sample_averaging_t
max30102 sample averaging enumeration definition
struct max30102_handle_s max30102_handle_t
max30102 handle structure definition
uint8_t max30102_set_adc_resolution(max30102_handle_t *handle, max30102_adc_resolution_t resolution)
set the adc resolution
uint8_t max30102_get_fifo_almost_full(max30102_handle_t *handle, uint8_t *value)
get the fifo almost full value
uint8_t max30102_set_fifo_write_pointer(max30102_handle_t *handle, uint8_t pointer)
set the fifo write pointer
uint8_t max30102_set_fifo_overflow_counter(max30102_handle_t *handle, uint8_t counter)
set the fifo overflow counter
max30102_led_t
max30102 led enumeration definition
max30102_adc_resolution_t
max30102 adc resolution enumeration definition
uint8_t max30102_get_adc_resolution(max30102_handle_t *handle, max30102_adc_resolution_t *resolution)
get the adc resolution
max30102_mode_t
max30102 mode enumeration definition
uint8_t max30102_get_shutdown(max30102_handle_t *handle, max30102_bool_t *enable)
get the shutdown
@ MAX30102_SLOT_1
@ MAX30102_SLOT_4
@ MAX30102_SLOT_2
@ MAX30102_SLOT_3
@ MAX30102_BOOL_FALSE
@ MAX30102_BOOL_TRUE
@ MAX30102_SPO2_ADC_RANGE_16384
@ MAX30102_SPO2_ADC_RANGE_2048
@ MAX30102_SPO2_ADC_RANGE_4096
@ MAX30102_SPO2_ADC_RANGE_8192
@ MAX30102_INTERRUPT_DIE_TEMP_RDY_EN
@ MAX30102_INTERRUPT_PPG_RDY_EN
@ MAX30102_INTERRUPT_FIFO_FULL_EN
@ MAX30102_INTERRUPT_ALC_OVF_EN
@ MAX30102_SPO2_SAMPLE_RATE_1600_HZ
@ MAX30102_SPO2_SAMPLE_RATE_3200_HZ
@ MAX30102_SPO2_SAMPLE_RATE_50_HZ
@ MAX30102_SPO2_SAMPLE_RATE_1000_HZ
@ MAX30102_SPO2_SAMPLE_RATE_100_HZ
@ MAX30102_SPO2_SAMPLE_RATE_200_HZ
@ MAX30102_SPO2_SAMPLE_RATE_800_HZ
@ MAX30102_SPO2_SAMPLE_RATE_400_HZ
@ MAX30102_SAMPLE_AVERAGING_16
@ MAX30102_SAMPLE_AVERAGING_32
@ MAX30102_SAMPLE_AVERAGING_4
@ MAX30102_SAMPLE_AVERAGING_1
@ MAX30102_SAMPLE_AVERAGING_2
@ MAX30102_SAMPLE_AVERAGING_8
@ MAX30102_INTERRUPT_STATUS_FIFO_FULL
@ MAX30102_INTERRUPT_STATUS_ALC_OVF
@ MAX30102_INTERRUPT_STATUS_DIE_TEMP_RDY
@ MAX30102_INTERRUPT_STATUS_PPG_RDY
@ MAX30102_INTERRUPT_STATUS_PWR_RDY
@ MAX30102_LED_RED
@ MAX30102_LED_NONE
@ MAX30102_LED_IR
@ MAX30102_ADC_RESOLUTION_17_BIT
@ MAX30102_ADC_RESOLUTION_16_BIT
@ MAX30102_ADC_RESOLUTION_15_BIT
@ MAX30102_ADC_RESOLUTION_18_BIT
@ MAX30102_MODE_HEART_RATE
@ MAX30102_MODE_SPO2
@ MAX30102_MODE_MULTI_LED
uint8_t max30102_interface_iic_init(void)
interface iic bus init
void max30102_interface_receive_callback(uint8_t type)
interface receive callback
void max30102_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t max30102_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t max30102_interface_iic_deinit(void)
interface iic bus deinit
void max30102_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t max30102_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t max30102_register_test(void)
register test
char manufacturer_name[32]