LibDriver MFRC522
Loading...
Searching...
No Matches
driver_mfrc522_mifare_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static mfrc522_handle_t gs_handle;
41
50{
51 if (mfrc522_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55 else
56 {
57 return 0;
58 }
59}
60
70uint8_t mfrc522_mifare_test(mfrc522_interface_t interface, uint8_t addr)
71{
72 uint8_t res;
73 uint8_t i;
74 uint8_t err;
75 uint8_t out_len;
76 uint8_t number[4];
77 uint8_t in_buf[16];
78 uint8_t out_buf[64];
79 uint16_t crc16;
80 uint16_t type;
81 mfrc522_info_t info;
82
83 /* link interface function */
104
105 /* get information */
106 res = mfrc522_info(&info);
107 if (res != 0)
108 {
109 mfrc522_interface_debug_print("mfrc522: get info failed.\n");
110
111 return 1;
112 }
113 else
114 {
115 /* print chip info */
116 mfrc522_interface_debug_print("mfrc522: chip is %s.\n", info.chip_name);
117 mfrc522_interface_debug_print("mfrc522: manufacturer is %s.\n", info.manufacturer_name);
118 mfrc522_interface_debug_print("mfrc522: interface is %s.\n", info.interface);
119 mfrc522_interface_debug_print("mfrc522: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
120 mfrc522_interface_debug_print("mfrc522: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
121 mfrc522_interface_debug_print("mfrc522: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
122 mfrc522_interface_debug_print("mfrc522: max current is %0.2fmA.\n", info.max_current_ma);
123 mfrc522_interface_debug_print("mfrc522: max temperature is %0.1fC.\n", info.temperature_max);
124 mfrc522_interface_debug_print("mfrc522: min temperature is %0.1fC.\n", info.temperature_min);
125 }
126
127 /* start mifare test */
128 mfrc522_interface_debug_print("mfrc522: start mifare test.\n");
129
130 /* set the interface */
131 res = mfrc522_set_interface(&gs_handle, interface);
132 if (res != 0)
133 {
134 mfrc522_interface_debug_print("mfrc522: set interface failed.\n");
135
136 return 1;
137 }
138
139 /* set the addr pin */
140 res = mfrc522_set_addr_pin(&gs_handle, addr);
141 if (res != 0)
142 {
143 mfrc522_interface_debug_print("mfrc522: set addr pin failed.\n");
144
145 return 1;
146 }
147
148 /* init failed */
149 res = mfrc522_init(&gs_handle);
150 if (res != 0)
151 {
152 mfrc522_interface_debug_print("mfrc522: init failed.\n");
153
154 return 1;
155 }
156
157 /* enable set_receiver analog */
159 if (res != 0)
160 {
161 mfrc522_interface_debug_print("mfrc522: set receiver analog failed.\n");
162 (void)mfrc522_deinit(&gs_handle);
163
164 return 1;
165 }
166
167 /* set the invert */
169 if (res != 0)
170 {
171 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
172 (void)mfrc522_deinit(&gs_handle);
173
174 return 1;
175 }
176
177 /* standard cmos */
179 if (res != 0)
180 {
181 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
182 (void)mfrc522_deinit(&gs_handle);
183
184 return 1;
185 }
186
187 /* disable iic high speed */
189 if (res != 0)
190 {
191 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
192 (void)mfrc522_deinit(&gs_handle);
193
194 return 1;
195 }
196
197 /* disable clear temperature error */
199 if (res != 0)
200 {
201 mfrc522_interface_debug_print("mfrc522: set clear temperature error failed.\n");
202 (void)mfrc522_deinit(&gs_handle);
203
204 return 1;
205 }
206
207 /* set water level 8 */
208 res = mfrc522_set_water_level(&gs_handle, 8);
209 if (res != 0)
210 {
211 mfrc522_interface_debug_print("mfrc522: set water level failed.\n");
212 (void)mfrc522_deinit(&gs_handle);
213
214 return 1;
215 }
216
217 /* stop timer */
218 res = mfrc522_stop_timer(&gs_handle);
219 if (res != 0)
220 {
221 mfrc522_interface_debug_print("mfrc522: stop timer failed.\n");
222 (void)mfrc522_deinit(&gs_handle);
223
224 return 1;
225 }
226
227 /* set rx align 0 */
228 res = mfrc522_set_rx_align(&gs_handle, MFRC522_RX_ALIGN_0);
229 if (res != 0)
230 {
231 mfrc522_interface_debug_print("mfrc522: set rx align failed.\n");
232 (void)mfrc522_deinit(&gs_handle);
233
234 return 1;
235 }
236
237 /* disable value clear after coll */
239 if (res != 0)
240 {
241 mfrc522_interface_debug_print("mfrc522: set value clear after coll failed.\n");
242 (void)mfrc522_deinit(&gs_handle);
243
244 return 1;
245 }
246
247 /* disable tx crc generation */
249 if (res != 0)
250 {
251 mfrc522_interface_debug_print("mfrc522: set tx crc generation failed.\n");
252 (void)mfrc522_deinit(&gs_handle);
253
254 return 1;
255 }
256
257 /* tx 106 kBd */
259 if (res != 0)
260 {
261 mfrc522_interface_debug_print("mfrc522: set tx speed failed.\n");
262 (void)mfrc522_deinit(&gs_handle);
263
264 return 1;
265 }
266
267 /* disable modulation invert */
269 if (res != 0)
270 {
271 mfrc522_interface_debug_print("mfrc522: set modulation invert failed.\n");
272 (void)mfrc522_deinit(&gs_handle);
273
274 return 1;
275 }
276
277 /* disable rx crc generation */
279 if (res != 0)
280 {
281 mfrc522_interface_debug_print("mfrc522: set rx crc generation failed.\n");
282 (void)mfrc522_deinit(&gs_handle);
283
284 return 1;
285 }
286
287 /* rx 106 kBd */
289 if (res != 0)
290 {
291 mfrc522_interface_debug_print("mfrc522: set rx speed failed.\n");
292 (void)mfrc522_deinit(&gs_handle);
293
294 return 1;
295 }
296
297 /* enable rx no error */
299 if (res != 0)
300 {
301 mfrc522_interface_debug_print("mfrc522: set rx no error failed.\n");
302 (void)mfrc522_deinit(&gs_handle);
303
304 return 1;
305 }
306
307 /* stop send */
308 res = mfrc522_stop_send(&gs_handle);
309 if (res != 0)
310 {
311 mfrc522_interface_debug_print("mfrc522: stop send failed.\n");
312 (void)mfrc522_deinit(&gs_handle);
313
314 return 1;
315 }
316
317 /* disable rx multiple */
319 if (res != 0)
320 {
321 mfrc522_interface_debug_print("mfrc522: set rx multiple failed.\n");
322 (void)mfrc522_deinit(&gs_handle);
323
324 return 1;
325 }
326
327 /* tx input internal encoder */
329 if (res != 0)
330 {
331 mfrc522_interface_debug_print("mfrc522: set tx input failed.\n");
332 (void)mfrc522_deinit(&gs_handle);
333
334 return 1;
335 }
336
337 /* 3 state */
339 if (res != 0)
340 {
341 mfrc522_interface_debug_print("mfrc522: set mfout input failed.\n");
342 (void)mfrc522_deinit(&gs_handle);
343
344 return 1;
345 }
346
347 /* set min level 8 */
348 res = mfrc522_set_min_level(&gs_handle, 0x8);
349 if (res != 0)
350 {
351 mfrc522_interface_debug_print("mfrc522: set min level failed.\n");
352 (void)mfrc522_deinit(&gs_handle);
353
354 return 1;
355 }
356
357 /* set collision level 4 */
358 res = mfrc522_set_collision_level(&gs_handle, 0x4);
359 if (res != 0)
360 {
361 mfrc522_interface_debug_print("mfrc522: set collision level failed.\n");
362 (void)mfrc522_deinit(&gs_handle);
363
364 return 1;
365 }
366
367 /* set the param */
369 if (res != 0)
370 {
371 mfrc522_interface_debug_print("mfrc522: set channel reception failed.\n");
372 (void)mfrc522_deinit(&gs_handle);
373
374 return 1;
375 }
376
377 /* disable fix iq */
378 res = mfrc522_set_fix_iq(&gs_handle, MFRC522_BOOL_FALSE);
379 if (res != 0)
380 {
381 mfrc522_interface_debug_print("mfrc522: set fix iq failed.\n");
382 (void)mfrc522_deinit(&gs_handle);
383
384 return 1;
385 }
386
387 /* disable timer prescal even */
389 if (res != 0)
390 {
391 mfrc522_interface_debug_print("mfrc522: set timer prescal even failed.\n");
392 (void)mfrc522_deinit(&gs_handle);
393
394 return 1;
395 }
396
397 /* set timer constant reception 3 */
398 res = mfrc522_set_timer_constant_reception(&gs_handle, 0x3);
399 if (res != 0)
400 {
401 mfrc522_interface_debug_print("mfrc522: set timer constant reception failed.\n");
402 (void)mfrc522_deinit(&gs_handle);
403
404 return 1;
405 }
406
407 /* set timer constant sync 1 */
408 res = mfrc522_set_timer_constant_sync(&gs_handle, 0x1);
409 if (res != 0)
410 {
411 mfrc522_interface_debug_print("mfrc522: set timer constant sync failed.\n");
412 (void)mfrc522_deinit(&gs_handle);
413
414 return 1;
415 }
416
417 /* set tx wait 2 */
418 res = mfrc522_set_tx_wait(&gs_handle, 0x2);
419 if (res != 0)
420 {
421 mfrc522_interface_debug_print("mfrc522: set tx wait failed.\n");
422 (void)mfrc522_deinit(&gs_handle);
423
424 return 1;
425 }
426
427 /* disable */
429 if (res != 0)
430 {
431 mfrc522_interface_debug_print("mfrc522: set parity disable failed.\n");
432 (void)mfrc522_deinit(&gs_handle);
433
434 return 1;
435 }
436
437 /* 9600 */
438 res = mfrc522_set_serial_speed(&gs_handle, 0x07, 0x0B);
439 if (res != 0)
440 {
441 mfrc522_interface_debug_print("mfrc522: set serial speed failed.\n");
442 (void)mfrc522_deinit(&gs_handle);
443
444 return 1;
445 }
446
447 /* set modulation width 0x26 */
448 res = mfrc522_set_modulation_width(&gs_handle, 0x26);
449 if (res != 0)
450 {
451 mfrc522_interface_debug_print("mfrc522: set modulation width failed.\n");
452 (void)mfrc522_deinit(&gs_handle);
453
454 return 1;
455 }
456
457 /* set cwgsn 8 */
458 res = mfrc522_set_cwgsn(&gs_handle, 0x8);
459 if (res != 0)
460 {
461 mfrc522_interface_debug_print("mfrc522: set cwgsn failed.\n");
462 (void)mfrc522_deinit(&gs_handle);
463
464 return 1;
465 }
466
467 /* set modgsn 8 */
468 res = mfrc522_set_modgsn(&gs_handle, 0x8);
469 if (res != 0)
470 {
471 mfrc522_interface_debug_print("mfrc522: set modgsn failed.\n");
472 (void)mfrc522_deinit(&gs_handle);
473
474 return 1;
475 }
476
477 /* set cwgsp 0x20 */
478 res = mfrc522_set_cwgsp(&gs_handle, 0x20);
479 if (res != 0)
480 {
481 mfrc522_interface_debug_print("mfrc522: set cwgsp failed.\n");
482 (void)mfrc522_deinit(&gs_handle);
483
484 return 1;
485 }
486
487 /* set modgsp 0x20 */
488 res = mfrc522_set_modgsp(&gs_handle, 0x20);
489 if (res != 0)
490 {
491 mfrc522_interface_debug_print("mfrc522: set modgsp failed.\n");
492 (void)mfrc522_deinit(&gs_handle);
493
494 return 1;
495 }
496
497 /* tx disable */
499 if (res != 0)
500 {
501 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
502 (void)mfrc522_deinit(&gs_handle);
503
504 return 1;
505 }
506
507 /* rx enable */
509 if (res != 0)
510 {
511 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
512 (void)mfrc522_deinit(&gs_handle);
513
514 return 1;
515 }
516
517 /* idle enable */
519 if (res != 0)
520 {
521 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
522 (void)mfrc522_deinit(&gs_handle);
523
524 return 1;
525 }
526
527 /* hi alert disable */
529 if (res != 0)
530 {
531 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
532 (void)mfrc522_deinit(&gs_handle);
533
534 return 1;
535 }
536
537 /* lo alert disable */
539 if (res != 0)
540 {
541 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
542 (void)mfrc522_deinit(&gs_handle);
543
544 return 1;
545 }
546
547 /* err enable */
549 if (res != 0)
550 {
551 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
552 (void)mfrc522_deinit(&gs_handle);
553
554 return 1;
555 }
556
557 /* timer enable */
559 if (res != 0)
560 {
561 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
562 (void)mfrc522_deinit(&gs_handle);
563
564 return 1;
565 }
566
567 /* mfin act disable */
569 if (res != 0)
570 {
571 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
572 (void)mfrc522_deinit(&gs_handle);
573
574 return 1;
575 }
576
577 /* crc enable */
579 if (res != 0)
580 {
581 mfrc522_interface_debug_print("mfrc522: set interrupt1 failed.\n");
582 (void)mfrc522_deinit(&gs_handle);
583
584 return 1;
585 }
586
587 /* disable crc msb first */
589 if (res != 0)
590 {
591 mfrc522_interface_debug_print("mfrc522: set crc msb first failed.\n");
592 (void)mfrc522_deinit(&gs_handle);
593
594 return 1;
595 }
596
597 /* enable tx wait rf */
598 res = mfrc522_set_tx_wait_rf(&gs_handle, MFRC522_BOOL_TRUE);
599 if (res != 0)
600 {
601 mfrc522_interface_debug_print("mfrc522: set tx wait rf failed.\n");
602 (void)mfrc522_deinit(&gs_handle);
603
604 return 1;
605 }
606
607 /* set mfin polarity high */
609 if (res != 0)
610 {
611 mfrc522_interface_debug_print("mfrc522: set tx wait rf failed.\n");
612 (void)mfrc522_deinit(&gs_handle);
613
614 return 1;
615 }
616
617 /* preset 0x6363 */
619 if (res != 0)
620 {
621 mfrc522_interface_debug_print("mfrc522: set crc preset failed.\n");
622 (void)mfrc522_deinit(&gs_handle);
623
624 return 1;
625 }
626
627 /* enable */
629 if (res != 0)
630 {
631 mfrc522_interface_debug_print("mfrc522: set force 100 ask failed.\n");
632 (void)mfrc522_deinit(&gs_handle);
633
634 return 1;
635 }
636
637 /* set analog module */
639 if (res != 0)
640 {
641 mfrc522_interface_debug_print("mfrc522: set contactless uart input failed.\n");
642 (void)mfrc522_deinit(&gs_handle);
643
644 return 1;
645 }
646
647 /* set rx wait */
648 res = mfrc522_set_rx_wait(&gs_handle, 0x6);
649 if (res != 0)
650 {
651 mfrc522_interface_debug_print("mfrc522: set rx wait failed.\n");
652 (void)mfrc522_deinit(&gs_handle);
653
654 return 1;
655 }
656
657 /* set 48 db */
659 if (res != 0)
660 {
661 mfrc522_interface_debug_print("mfrc522: set rx gain failed.\n");
662 (void)mfrc522_deinit(&gs_handle);
663
664 return 1;
665 }
666
667 /* enable timer auto */
668 res = mfrc522_set_timer_auto(&gs_handle, MFRC522_BOOL_TRUE);
669 if (res != 0)
670 {
671 mfrc522_interface_debug_print("mfrc522: set auto failed.\n");
672 (void)mfrc522_deinit(&gs_handle);
673
674 return 1;
675 }
676
677 /* set gated mode none */
679 if (res != 0)
680 {
681 mfrc522_interface_debug_print("mfrc522: set timer gated mode failed.\n");
682 (void)mfrc522_deinit(&gs_handle);
683
684 return 1;
685 }
686
687 /* disable auto restart */
689 if (res != 0)
690 {
691 mfrc522_interface_debug_print("mfrc522: set timer auto restart failed.\n");
692 (void)mfrc522_deinit(&gs_handle);
693
694 return 1;
695 }
696
697 /* set the timer prescaler */
698 res = mfrc522_set_timer_prescaler(&gs_handle, 0xD3E);
699 if (res != 0)
700 {
701 mfrc522_interface_debug_print("mfrc522: set timer prescaler failed.\n");
702 (void)mfrc522_deinit(&gs_handle);
703
704 return 1;
705 }
706
707 /* set the reload */
708 res = mfrc522_set_timer_reload(&gs_handle, 0x001E);
709 if (res != 0)
710 {
711 mfrc522_interface_debug_print("mfrc522: set timer reload failed.\n");
712 (void)mfrc522_deinit(&gs_handle);
713
714 return 1;
715 }
716
717 /* antenna on */
719 if (res != 0)
720 {
721 mfrc522_interface_debug_print("mfrc522: set antenna driver failed.\n");
722 (void)mfrc522_deinit(&gs_handle);
723
724 return 1;
725 }
726
727 /* antenna on */
729 if (res != 0)
730 {
731 mfrc522_interface_debug_print("mfrc522: set antenna driver failed.\n");
732 (void)mfrc522_deinit(&gs_handle);
733
734 return 1;
735 }
736
737 /* mifare random test */
738 mfrc522_interface_debug_print("mfrc522: mifare random test.\n");
739
740 /* generate the random */
741 out_len = 0;
742 res = mfrc522_transceiver(&gs_handle, MFRC522_COMMAND_RANDOM_ID, in_buf, 0, out_buf, &out_len, &err, 1000);
743 if (res != 0)
744 {
745 mfrc522_interface_debug_print("mfrc522: transceiver failed.\n");
746 (void)mfrc522_deinit(&gs_handle);
747
748 return 1;
749 }
750
751 /* copy from mem to fifo to buffer */
752 out_len = 64;
753 res = mfrc522_transceiver(&gs_handle, MFRC522_COMMAND_MEM, in_buf, 0, out_buf, &out_len, &err, 1000);
754 if (res != 0)
755 {
756 mfrc522_interface_debug_print("mfrc522: transceiver failed.\n");
757 (void)mfrc522_deinit(&gs_handle);
758
759 return 1;
760 }
761 for (i = 0; i < out_len; i++)
762 {
763 mfrc522_interface_debug_print("0x%02X ", out_buf[i]);
764 }
766
767 /* mifare crc test */
768 mfrc522_interface_debug_print("mfrc522: mifare crc test.\n");
769 out_len = 0;
770 in_buf[0] = 'm';
771 in_buf[1] = 'f';
772 in_buf[2] = 'r';
773 in_buf[3] = 'c';
774 in_buf[4] = '5';
775 in_buf[5] = '2';
776 in_buf[6] = '2';
777 res = mfrc522_transceiver(&gs_handle, MFRC522_COMMAND_CALC_CRC, in_buf, 7, out_buf, &out_len, &err, 1000);
778 if (res != 0)
779 {
780 mfrc522_interface_debug_print("mfrc522: transceiver failed.\n");
781 (void)mfrc522_deinit(&gs_handle);
782
783 return 1;
784 }
785 res = mfrc522_get_crc(&gs_handle, &crc16);
786 if (res != 0)
787 {
788 mfrc522_interface_debug_print("mfrc522: get crc failed.\n");
789 (void)mfrc522_deinit(&gs_handle);
790
791 return 1;
792 }
793 mfrc522_interface_debug_print("mfrc522: mfrc522 crc is 0x%04X and checked %s.\n", crc16,
794 crc16 == 0x0564 ? "ok" : "error");
795
796 /* mifare find card test */
797 mfrc522_interface_debug_print("mfrc522: mifare find card test.\n");
798
799 /* disable cypto1 on */
801 if (res != 0)
802 {
803 mfrc522_interface_debug_print("mfrc522: set mifare crypto1 on failed.\n");
804 (void)mfrc522_deinit(&gs_handle);
805
806 return 1;
807 }
808
809 /* set tx last bits 7 */
810 res = mfrc522_set_tx_last_bits(&gs_handle, 7);
811 if (res != 0)
812 {
813 mfrc522_interface_debug_print("mfrc522: set tx last bits failed.\n");
814 (void)mfrc522_deinit(&gs_handle);
815
816 return 1;
817 }
818
819 /* mifare find card */
820 out_len = 64;
821 in_buf[0] = 0x26;
822 res = mfrc522_transceiver(&gs_handle, MFRC522_COMMAND_TRANSCEIVE, in_buf, 1, out_buf, &out_len, &err, 1000);
823 if (res != 0)
824 {
825 mfrc522_interface_debug_print("mfrc522: transceiver failed.\n");
826 (void)mfrc522_deinit(&gs_handle);
827
828 return 1;
829 }
830 type = (uint16_t)out_buf[0] << 8 | out_buf[1];
831 if (type == 0x4400)
832 {
833 mfrc522_interface_debug_print("mfrc522: find mifare ultralight.\n");
834 }
835 else if (type == 0x0400)
836 {
837 mfrc522_interface_debug_print("mfrc522: find mifare S50.\n");
838 }
839 else if (type == 0x0200)
840 {
841 mfrc522_interface_debug_print("mfrc522: find mifare S70.\n");
842 }
843 else if (type == 0x0800)
844 {
845 mfrc522_interface_debug_print("mfrc522: find mifare pro(x).\n");
846 }
847 else if (type == 0x4403)
848 {
849 mfrc522_interface_debug_print("mfrc522: find mifare desfire.\n");
850 }
851 else
852 {
853 mfrc522_interface_debug_print("mfrc522: unknown type.\n");
854 }
855
856 /* mifare anti-coll test */
857 mfrc522_interface_debug_print("mfrc522: mifare anti-coll test.\n");
858
859 /* disable cypto1 on */
861 if (res != 0)
862 {
863 mfrc522_interface_debug_print("mfrc522: set mifare crypto1 on failed.\n");
864 (void)mfrc522_deinit(&gs_handle);
865
866 return 1;
867 }
868
869 /* set tx last bits 0 */
870 res = mfrc522_set_tx_last_bits(&gs_handle, 0);
871 if (res != 0)
872 {
873 mfrc522_interface_debug_print("mfrc522: set tx last bits failed.\n");
874 (void)mfrc522_deinit(&gs_handle);
875
876 return 1;
877 }
878
879 /* enable value clear after coll */
881 if (res != 0)
882 {
883 mfrc522_interface_debug_print("mfrc522: set value clear after coll failed.\n");
884 (void)mfrc522_deinit(&gs_handle);
885
886 return 1;
887 }
888
889 /* mifare anti-coll */
890 out_len = 64;
891 in_buf[0] = 0x93;
892 in_buf[1] = 0x20;
893 res = mfrc522_transceiver(&gs_handle, MFRC522_COMMAND_TRANSCEIVE, in_buf, 2, out_buf, &out_len, &err, 1000);
894 if (res != 0)
895 {
896 mfrc522_interface_debug_print("mfrc522: transceiver failed.\n");
897 (void)mfrc522_deinit(&gs_handle);
898
899 return 1;
900 }
901 number[0] = out_buf[0];
902 number[1] = out_buf[1];
903 number[2] = out_buf[2];
904 number[3] = out_buf[3];
905 err = 0;
906 err ^= out_buf[0];
907 err ^= out_buf[1];
908 err ^= out_buf[2];
909 err ^= out_buf[3];
910 if (err == out_buf[4])
911 {
912 mfrc522_interface_debug_print("mfrc522: id is 0x%02X 0x%02X 0x%02X 0x%02X.\n",
913 number[0], number[1], number[2], number[3]);
914 }
915 else
916 {
917 mfrc522_interface_debug_print("mfrc522: id check failed.\n");
918 }
919
920 /* disable value clear after coll */
922 if (res != 0)
923 {
924 mfrc522_interface_debug_print("mfrc522: set value clear after coll failed.\n");
925 (void)mfrc522_deinit(&gs_handle);
926
927 return 1;
928 }
929
930 /* finish mifare test */
931 mfrc522_interface_debug_print("mfrc522: finish mifare test.\n");
932 (void)mfrc522_deinit(&gs_handle);
933
934 return 0;
935}
driver mfrc522 mifare test header file
mfrc522_interface_t
mfrc522 interface enumeration definition
uint8_t mfrc522_set_interrupt2(mfrc522_handle_t *handle, mfrc522_interrupt2_t type, mfrc522_bool_t enable)
enable or disable the interrupt2
uint8_t mfrc522_set_fix_iq(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable fix iq
uint8_t mfrc522_init(mfrc522_handle_t *handle)
initialize the chip
uint8_t mfrc522_set_mifare_crypto1_on(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable mifare crypto1 on
uint8_t mfrc522_set_rx_multiple(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable rx multiple
uint8_t mfrc522_set_timer_constant_sync(mfrc522_handle_t *handle, uint8_t t)
set the timer constant sync
uint8_t mfrc522_set_interface(mfrc522_handle_t *handle, mfrc522_interface_t interface)
set the chip interface
uint8_t mfrc522_set_interrupt_pin_type(mfrc522_handle_t *handle, mfrc522_interrupt_pin_type_t type)
set the interrupt pin type
uint8_t mfrc522_set_force_iic_high_speed(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable force iic high speed
uint8_t mfrc522_set_channel_reception(mfrc522_handle_t *handle, mfrc522_channel_reception_t reception)
set the channel reception
uint8_t mfrc522_set_rx_wait(mfrc522_handle_t *handle, uint8_t t)
set the rx wait
uint8_t mfrc522_irq_handler(mfrc522_handle_t *handle)
irq handler
uint8_t mfrc522_set_force_100_ask(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable force 100 ask
uint8_t mfrc522_set_interrupt1(mfrc522_handle_t *handle, mfrc522_interrupt1_t type, mfrc522_bool_t enable)
enable or disable the interrupt1
uint8_t mfrc522_set_rx_speed(mfrc522_handle_t *handle, mfrc522_speed_t speed)
set the rx speed
uint8_t mfrc522_set_parity_disable(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable parity disable
uint8_t mfrc522_set_crc_preset(mfrc522_handle_t *handle, mfrc522_crc_preset_t preset)
set the crc preset
uint8_t mfrc522_get_crc(mfrc522_handle_t *handle, uint16_t *crc)
get the crc
uint8_t mfrc522_set_water_level(mfrc522_handle_t *handle, uint8_t level)
set the water level
uint8_t mfrc522_set_tx_last_bits(mfrc522_handle_t *handle, uint8_t bits)
set the tx last bits
uint8_t mfrc522_set_interrupt1_pin_invert(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable interrupt1 pin invert
uint8_t mfrc522_transceiver(mfrc522_handle_t *handle, mfrc522_command_t command, uint8_t *in_buf, uint8_t in_len, uint8_t *out_buf, uint8_t *out_len, uint8_t *err, uint32_t ms)
mfrc522 transceiver
uint8_t mfrc522_set_rx_align(mfrc522_handle_t *handle, mfrc522_rx_align_t align)
set the rx align
uint8_t mfrc522_set_antenna_driver(mfrc522_handle_t *handle, mfrc522_antenna_driver_t driver, mfrc522_bool_t enable)
enable or disable the antenna driver
uint8_t mfrc522_set_modgsp(mfrc522_handle_t *handle, uint8_t n)
set the modgsp
uint8_t mfrc522_info(mfrc522_info_t *info)
get chip information
uint8_t mfrc522_set_mfin_polarity(mfrc522_handle_t *handle, mfrc522_mfin_polarity_t polarity)
set the mfin polarity
uint8_t mfrc522_set_timer_auto_restart(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable timer auto restart
uint8_t mfrc522_set_clear_temperature_error(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable clear temperature error
uint8_t mfrc522_set_modulation_invert(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable the modulation invert
uint8_t mfrc522_set_modulation_width(mfrc522_handle_t *handle, uint8_t width)
set the modulation width
uint8_t mfrc522_set_value_clear_after_coll(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable value clear after coll
uint8_t mfrc522_set_tx_input(mfrc522_handle_t *handle, mfrc522_tx_input_t input)
set the tx input
uint8_t mfrc522_set_rx_crc_generation(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable the rx crc generation
uint8_t mfrc522_set_tx_wait(mfrc522_handle_t *handle, uint8_t t)
set the tx wait
uint8_t mfrc522_stop_timer(mfrc522_handle_t *handle)
stop the timer
uint8_t mfrc522_set_cwgsn(mfrc522_handle_t *handle, uint8_t n)
set the cwgsn
uint8_t mfrc522_set_cwgsp(mfrc522_handle_t *handle, uint8_t n)
set the cwgsp
uint8_t mfrc522_set_timer_gated_mode(mfrc522_handle_t *handle, mfrc522_timer_gated_mode_t mode)
set the timer gated mode
uint8_t mfrc522_set_tx_speed(mfrc522_handle_t *handle, mfrc522_speed_t speed)
set the tx speed
uint8_t mfrc522_set_addr_pin(mfrc522_handle_t *handle, uint8_t addr_pin)
set the iic address pin
uint8_t mfrc522_set_tx_crc_generation(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable tx crc generation
uint8_t mfrc522_set_rx_gain(mfrc522_handle_t *handle, mfrc522_rx_gain_t gain)
set the rx gain
uint8_t mfrc522_set_timer_auto(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable timer auto
uint8_t mfrc522_set_timer_reload(mfrc522_handle_t *handle, uint16_t reload)
set the timer reload
struct mfrc522_handle_s mfrc522_handle_t
mfrc522 handle structure definition
uint8_t mfrc522_set_tx_wait_rf(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable the rf tx wait
uint8_t mfrc522_set_serial_speed(mfrc522_handle_t *handle, uint8_t t0, uint8_t t1)
set the serial speed
uint8_t mfrc522_set_receiver_analog(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable the analog part of the receiver
uint8_t mfrc522_set_crc_msb_first(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable the crc msb first
uint8_t mfrc522_set_rx_no_error(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable rx no error
uint8_t mfrc522_set_collision_level(mfrc522_handle_t *handle, uint8_t level)
set the collision level
uint8_t mfrc522_set_min_level(mfrc522_handle_t *handle, uint8_t level)
set the min level
uint8_t mfrc522_deinit(mfrc522_handle_t *handle)
close the chip
uint8_t mfrc522_set_modgsn(mfrc522_handle_t *handle, uint8_t n)
set the modgsn
uint8_t mfrc522_set_timer_prescaler(mfrc522_handle_t *handle, uint16_t t)
set the timer prescaler
uint8_t mfrc522_set_timer_constant_reception(mfrc522_handle_t *handle, uint8_t t)
set the timer constant reception
uint8_t mfrc522_stop_send(mfrc522_handle_t *handle)
stop the transmission of data
uint8_t mfrc522_set_contactless_uart_input(mfrc522_handle_t *handle, mfrc522_contactless_uart_input_t input)
set the contactless uart input
struct mfrc522_info_s mfrc522_info_t
mfrc522 information structure definition
uint8_t mfrc522_set_timer_prescal_even(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable timer prescal even
uint8_t mfrc522_set_mfout_input(mfrc522_handle_t *handle, mfrc522_mfout_input_t input)
set the mfout input
@ MFRC522_COMMAND_TRANSCEIVE
@ MFRC522_COMMAND_RANDOM_ID
@ MFRC522_COMMAND_MEM
@ MFRC522_COMMAND_CALC_CRC
@ MFRC522_BOOL_TRUE
@ MFRC522_BOOL_FALSE
@ MFRC522_TIMER_GATED_MODE_NONE
@ MFRC522_TX_INPUT_INTERNAL_ENCODER
@ MFRC522_CHANNEL_RECEPTION_STRONGER_FREEZE_SELECTED
@ MFRC522_INTERRUPT_PIN_TYPE_STANDARD_CMOS
@ MFRC522_CRC_PRESET_6363
@ MFRC522_CONTACTLESS_UART_INTERNAL_ANALOG_MODULE
@ MFRC522_RX_GAIN_48_DB
@ MFRC522_ANTENNA_DRIVER_TX2_RF
@ MFRC522_ANTENNA_DRIVER_TX1_RF
@ MFRC522_RX_ALIGN_0
@ MFRC522_INTERRUPT2_CRC
@ MFRC522_INTERRUPT2_MFIN_ACT
@ MFRC522_INTERRUPT1_LO_ALERT
@ MFRC522_INTERRUPT1_IDLE
@ MFRC522_INTERRUPT1_TX
@ MFRC522_INTERRUPT1_TIMER
@ MFRC522_INTERRUPT1_HI_ALERT
@ MFRC522_INTERRUPT1_RX
@ MFRC522_INTERRUPT1_ERR
@ MFRC522_SPEED_106_KBD
@ MFRC522_MFIN_POLARITY_HIGH
@ MFRC522_MFOUT_INPUT_3_STATE
uint8_t mfrc522_interface_uart_deinit(void)
interface uart deinit
void mfrc522_interface_receive_callback(uint16_t type)
interface receive callback
uint8_t mfrc522_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t mfrc522_interface_reset_gpio_deinit(void)
interface reset gpio deinit
uint8_t mfrc522_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t mfrc522_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
void mfrc522_interface_delay_ms(uint32_t ms)
interface delay ms
uint16_t mfrc522_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t mfrc522_interface_reset_gpio_init(void)
interface reset gpio init
uint8_t mfrc522_interface_spi_deinit(void)
interface spi bus deinit
uint8_t mfrc522_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t mfrc522_interface_spi_init(void)
interface spi bus init
uint8_t mfrc522_interface_uart_flush(void)
interface uart flush
uint8_t mfrc522_interface_reset_gpio_write(uint8_t value)
interface reset gpio write
uint8_t mfrc522_interface_iic_deinit(void)
interface iic bus deinit
uint8_t mfrc522_interface_iic_init(void)
interface iic bus init
void mfrc522_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t mfrc522_interface_uart_init(void)
interface uart init
uint8_t mfrc522_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t mfrc522_mifare_test_irq_handler(void)
mifare test irq
uint8_t mfrc522_mifare_test(mfrc522_interface_t interface, uint8_t addr)
mifare test
uint32_t driver_version
char manufacturer_name[32]