LibDriver MFRC522  1.0.0
MFRC522 full-featured driver
driver_mfrc522.c
Go to the documentation of this file.
1 
37 #include "driver_mfrc522.h"
38 
42 #define CHIP_NAME "NXP MFRC522"
43 #define MANUFACTURER_NAME "NXP"
44 #define SUPPLY_VOLTAGE_MIN 2.5f
45 #define SUPPLY_VOLTAGE_MAX 3.6f
46 #define MAX_CURRENT 100.0f
47 #define TEMPERATURE_MIN -25.0f
48 #define TEMPERATURE_MAX 85.0f
49 #define DRIVER_VERSION 1000
54 #define MFRC522_REG_COMMAND 0x01
55 #define MFRC522_REG_COMIEN 0x02
56 #define MFRC522_REG_DIVIEN 0x03
57 #define MFRC522_REG_COMIRQ 0x04
58 #define MFRC522_REG_DIVIRQ 0x05
59 #define MFRC522_REG_ERROR 0x06
60 #define MFRC522_REG_STATUS1 0x07
61 #define MFRC522_REG_STATUS2 0x08
62 #define MFRC522_REG_FIFO_DATA 0x09
63 #define MFRC522_REG_FIFO_LEVEL 0x0A
64 #define MFRC522_REG_WATER_LEVEL 0x0B
65 #define MFRC522_REG_CONTROL 0x0C
66 #define MFRC522_REG_BIT_FRAMING 0x0D
67 #define MFRC522_REG_COLL 0x0E
68 #define MFRC522_REG_MODE 0x11
69 #define MFRC522_REG_TX_MODE 0x12
70 #define MFRC522_REG_RX_MODE 0x13
71 #define MFRC522_REG_TX_CONTROL 0x14
72 #define MFRC522_REG_TX_ASK 0x15
73 #define MFRC522_REG_TX_SEL 0x16
74 #define MFRC522_REG_RX_SEL 0x17
75 #define MFRC522_REG_RX_THRESHOLD 0x18
76 #define MFRC522_REG_DEMOD 0x19
77 #define MFRC522_REG_MFTX 0x1C
78 #define MFRC522_REG_MFRX 0x1D
79 #define MFRC522_REG_SERIAL_SPEED 0x1F
80 #define MFRC522_REG_CRC_RESULT_H 0x21
81 #define MFRC522_REG_CRC_RESULT_L 0x22
82 #define MFRC522_REG_MOD_WIDTH 0x24
83 #define MFRC522_REG_RFCFG 0x26
84 #define MFRC522_REG_GSN 0x27
85 #define MFRC522_REG_CWGSP 0x28
86 #define MFRC522_REG_MODGSP 0x29
87 #define MFRC522_REG_TMODE 0x2A
88 #define MFRC522_REG_TPRESCALER 0x2B
89 #define MFRC522_REG_TRELOAD_H 0x2C
90 #define MFRC522_REG_TRELOAD_L 0x2D
91 #define MFRC522_REG_TCOUNTER_VAL_H 0x2E
92 #define MFRC522_REG_TCOUNTER_VAL_L 0x2F
93 #define MFRC522_REG_TEST_SEL1 0x31
94 #define MFRC522_REG_TEST_SEL2 0x32
95 #define MFRC522_REG_TEST_PIN_EN 0x33
96 #define MFRC522_REG_TEST_PIN_VALUE 0x34
97 #define MFRC522_REG_TEST_BUS 0x35
98 #define MFRC522_REG_AUTO_TEST 0x36
99 #define MFRC522_REG_VERSION 0x37
100 #define MFRC522_REG_ANALOG_TEST 0x38
101 #define MFRC522_REG_TEST_DAC1 0x39
102 #define MFRC522_REG_TEST_DAC2 0x3A
103 #define MFRC522_REG_TEST_ADC 0x3B
116 static uint8_t a_mfrc522_read(mfrc522_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
117 {
118  uint16_t i;
119 
120  if (handle->iic_spi_uart == MFRC522_INTERFACE_IIC) /* if iic interface */
121  {
122  uint8_t addr;
123 
124  for (i = 0; i< len; i++) /* len times */
125  {
126  addr = reg + i; /* set the address */
127  if (handle->iic_read(handle->iic_addr, addr, buf + i, 1) != 0) /* check the result */
128  {
129  return 1; /* return error */
130  }
131  }
132 
133  return 0; /* success return 0 */
134  }
135  else if (handle->iic_spi_uart == MFRC522_INTERFACE_SPI) /* if spi interface */
136  {
137  uint8_t addr;
138 
139  for (i = 0; i< len; i++) /* len times */
140  {
141  addr = (uint8_t)((1 << 7) | (((reg + i) & 0x3F) << 1)); /* set the address */
142  if (handle->spi_read(addr, buf + i, 1) != 0) /* check the result */
143  {
144  return 1; /* return error */
145  }
146  }
147 
148  return 0; /* success return 0 */
149  }
150  else if (handle->iic_spi_uart == MFRC522_INTERFACE_UART) /* if uart interface */
151  {
152  uint8_t addr;
153 
154  for (i = 0; i< len; i++) /* len times */
155  {
156  addr = (uint8_t)((1 << 7) | (((reg + i) & 0x3F) << 0)); /* set the address */
157  if (handle->uart_flush() != 0) /* uart flush */
158  {
159  return 1; /* return error */
160  }
161  if (handle->uart_write(&addr, 1) != 0) /* uart write */
162  {
163  return 1; /* return error */
164  }
165  if (handle->uart_read(buf + i, 1) != 1) /* uart read */
166  {
167  return 1; /* return error */
168  }
169  handle->delay_ms(2); /* uart delay 2 ms */
170  }
171 
172  return 0; /* success return 0 */
173  }
174  else
175  { /* return error */
176  return 1;
177  }
178 }
179 
191 static uint8_t a_mfrc522_write(mfrc522_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
192 {
193  uint16_t i;
194 
195  if (handle->iic_spi_uart == MFRC522_INTERFACE_IIC) /* if iic interface */
196  {
197  uint8_t addr;
198 
199  for (i = 0; i< len; i++) /* len times */
200  {
201  addr = reg + i; /* set the address */
202  if (handle->iic_write(handle->iic_addr, addr,
203  buf + i, 1) != 0) /* check the result */
204  {
205  return 1; /* return error */
206  }
207  }
208 
209  return 0; /* success return 0 */
210  }
211  else if (handle->iic_spi_uart == MFRC522_INTERFACE_SPI) /* if spi interface */
212  {
213  uint8_t addr;
214 
215  for (i = 0; i< len; i++) /* len times */
216  {
217  addr = (uint8_t)((0 << 7) | (((reg + i) & 0x3F) << 1)); /* set the address */
218  if (handle->spi_write(addr, buf + i, 1) != 0) /* check the result */
219  {
220  return 1; /* return error */
221  }
222  }
223 
224  return 0; /* success return 0 */
225  }
226  else if (handle->iic_spi_uart == MFRC522_INTERFACE_UART) /* if uart interface */
227  {
228  uint8_t addr;
229  uint8_t b[2];
230 
231  for (i = 0; i< len; i++) /* len times */
232  {
233  addr = ((reg + i) & 0x3F) << 0; /* set the addr */
234  b[0] = addr; /* set to buffer */
235  b[1] = buf[i]; /* set buffer */
236  if (handle->uart_write(b, 2) != 0) /* uart write */
237  {
238  return 1; /* return error */
239  }
240  handle->delay_ms(5); /* uart delay 5 ms */
241  }
242 
243  return 0; /* success return 0 */
244  }
245  else
246  {
247  return 1; /* return error */
248  }
249 }
250 
261 {
262  if (handle == NULL) /* check handle */
263  {
264  return 2; /* return error */
265  }
266 
267  handle->iic_spi_uart = (uint8_t)interface; /* set interface */
268 
269  return 0; /* success return 0 */
270 }
271 
282 {
283  if (handle == NULL) /* check handle */
284  {
285  return 2; /* return error */
286  }
287 
288  *interface = (mfrc522_interface_t)(handle->iic_spi_uart); /* get interface */
289 
290  return 0; /* success return 0 */
291 }
292 
302 uint8_t mfrc522_set_addr_pin(mfrc522_handle_t *handle, uint8_t addr_pin)
303 {
304  if (handle == NULL) /* check handle */
305  {
306  return 2; /* return error */
307  }
308 
309  handle->iic_addr = (uint8_t)addr_pin; /* set pin */
310 
311  return 0; /* success return 0 */
312 }
313 
323 uint8_t mfrc522_get_addr_pin(mfrc522_handle_t *handle, uint8_t *addr_pin)
324 {
325  if (handle == NULL) /* check handle */
326  {
327  return 2; /* return error */
328  }
329 
330  *addr_pin = (uint8_t)(handle->iic_addr); /* get pin */
331 
332  return 0; /* success return 0 */
333 }
334 
349 {
350  uint8_t res;
351  uint8_t prev;
352  uint8_t id;
353  uint32_t timeout;
354 
355  if (handle == NULL) /* check handle */
356  {
357  return 2; /* return error */
358  }
359  if (handle->debug_print == NULL) /* check debug_print */
360  {
361  return 3; /* return error */
362  }
363  if (handle->reset_gpio_init == NULL) /* check reset_gpio_init */
364  {
365  handle->debug_print("mfrc522: reset_gpio_init is null.\n"); /* reset_gpio_init is null */
366 
367  return 3; /* return error */
368  }
369  if (handle->reset_gpio_deinit == NULL) /* check reset_gpio_deinit */
370  {
371  handle->debug_print("mfrc522: reset_gpio_deinit is null.\n"); /* reset_gpio_deinit is null */
372 
373  return 3; /* return error */
374  }
375  if (handle->reset_gpio_write == NULL) /* check reset_gpio_write */
376  {
377  handle->debug_print("mfrc522: reset_gpio_write is null.\n"); /* reset_gpio_write is null */
378 
379  return 3; /* return error */
380  }
381  if (handle->iic_init == NULL) /* check iic_init */
382  {
383  handle->debug_print("mfrc522: iic_init is null.\n"); /* iic_init is null */
384 
385  return 3; /* return error */
386  }
387  if (handle->iic_deinit == NULL) /* check iic_deinit */
388  {
389  handle->debug_print("mfrc522: iic_deinit is null.\n"); /* iic_deinit is null */
390 
391  return 3; /* return error */
392  }
393  if (handle->iic_read == NULL) /* check iic_read */
394  {
395  handle->debug_print("mfrc522: iic_read is null.\n"); /* iic_read is null */
396 
397  return 3; /* return error */
398  }
399  if (handle->iic_write == NULL) /* check iic_write */
400  {
401  handle->debug_print("mfrc522: iic_write is null.\n"); /* iic_write is null */
402 
403  return 3; /* return error */
404  }
405  if (handle->uart_init == NULL) /* check uart_init */
406  {
407  handle->debug_print("mfrc522: uart_init is null.\n"); /* uart_init is null */
408 
409  return 3; /* return error */
410  }
411  if (handle->uart_deinit == NULL) /* check uart_deinit */
412  {
413  handle->debug_print("mfrc522: uart_deinit is null.\n"); /* uart_deinit is null */
414 
415  return 3; /* return error */
416  }
417  if (handle->uart_read == NULL) /* check uart_read */
418  {
419  handle->debug_print("mfrc522: uart_read is null.\n"); /* uart_read is null */
420 
421  return 3; /* return error */
422  }
423  if (handle->uart_write == NULL) /* check uart_write */
424  {
425  handle->debug_print("mfrc522: uart_write is null.\n"); /* uart_write is null */
426 
427  return 3; /* return error */
428  }
429  if (handle->uart_flush == NULL) /* check uart_flush */
430  {
431  handle->debug_print("mfrc522: uart_flush is null.\n"); /* uart_flush is null */
432 
433  return 3; /* return error */
434  }
435  if (handle->spi_init == NULL) /* check spi_init */
436  {
437  handle->debug_print("mfrc522: spi_init is null.\n"); /* spi_init is null */
438 
439  return 3; /* return error */
440  }
441  if (handle->spi_deinit == NULL) /* check spi_deinit */
442  {
443  handle->debug_print("mfrc522: spi_deinit is null.\n"); /* spi_deinit is null */
444 
445  return 3; /* return error */
446  }
447  if (handle->spi_read == NULL) /* check spi_read */
448  {
449  handle->debug_print("mfrc522: spi_read is null.\n"); /* spi_read is null */
450 
451  return 3; /* return error */
452  }
453  if (handle->spi_write == NULL) /* check spi_write */
454  {
455  handle->debug_print("mfrc522: spi_write is null.\n"); /* spi_read_spi_write is null */
456 
457  return 3; /* return error */
458  }
459  if (handle->delay_ms == NULL) /* check delay_ms */
460  {
461  handle->debug_print("mfrc522: delay_ms is null.\n"); /* delay_ms is null */
462 
463  return 3; /* return error */
464  }
465  if (handle->receive_callback == NULL) /* check receive_callback */
466  {
467  handle->debug_print("mfrc522: receive_callback is null.\n"); /* receive_callback is null */
468 
469  return 3; /* return error */
470  }
471 
472  if (handle->reset_gpio_init() != 0) /* reset gpio init */
473  {
474  handle->debug_print("mfrc522: reset gpio init failed.\n"); /* reset gpio init failed */
475 
476  return 1; /* return error */
477  }
478  if (handle->iic_spi_uart == MFRC522_INTERFACE_IIC) /* if iic interface */
479  {
480  if (handle->iic_init() != 0) /* iic init */
481  {
482  handle->debug_print("mfrc522: iic init failed.\n"); /* iic init failed */
483  (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
484 
485  return 1; /* return error */
486  }
487  }
488  else if (handle->iic_spi_uart == MFRC522_INTERFACE_SPI) /* if spi interface */
489  {
490  if (handle->spi_init() != 0) /* spi init */
491  {
492  handle->debug_print("mfrc522: spi init failed.\n"); /* spi init failed */
493  (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
494 
495  return 1; /* return error */
496  }
497  }
498  else if (handle->iic_spi_uart == MFRC522_INTERFACE_UART) /* if uart interface */
499  {
500  if (handle->uart_init() != 0) /* uart init */
501  {
502  handle->debug_print("mfrc522: uart init failed.\n"); /* uart init failed */
503  (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
504 
505  return 1; /* return error */
506  }
507  }
508  else
509  {
510  handle->debug_print("mfrc522: interface is invalid.\n"); /* interface is invalid */
511 
512  return 4; /* return error */
513  }
514 
515  if (handle->reset_gpio_write(0) != 0) /* set 0 */
516  {
517  handle->debug_print("mfrc522: reset gpio write failed.\n"); /* reset gpio write failed */
518  res = 1; /* set the exit code */
519 
520  goto exit_code; /* goto the exit code */
521  }
522  handle->delay_ms(10); /* delay 10 ms */
523  if (handle->reset_gpio_write(1) != 0) /* set 1 */
524  {
525  handle->debug_print("mfrc522: reset gpio write failed.\n"); /* reset gpio write failed */
526  res = 1; /* set the exit code */
527 
528  goto exit_code; /* goto the exit code */
529  }
530 
531  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
532  if (res != 0) /* check the result */
533  {
534  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
535  res = 1; /* set the exit code */
536 
537  goto exit_code; /* goto the exit code */
538  }
539  prev &= ~(0xF << 0); /* clear the settings */
540  prev |= MFRC522_COMMAND_SOFT_RESET; /* set the idle */
541  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
542  if (res != 0) /* check the result */
543  {
544  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
545  res = 1; /* set the exit code */
546 
547  goto exit_code; /* goto the exit code */
548  }
549  handle->delay_ms(1); /* delay 1 ms */
550  timeout = 1000; /* set 1000 ms */
551  while (timeout != 0) /* check the timeout */
552  {
553  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
554  if (res != 0) /* check the result */
555  {
556  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
557  res = 1; /* set the exit code */
558 
559  goto exit_code; /* goto the exit code */
560  }
561  timeout--; /* timeout-- */
562  handle->delay_ms(1); /* delay 1 ms */
563  if ((prev & (1 << 4)) == 0) /* check the power on bit */
564  {
565  break; /* break */
566  }
567  if (timeout == 0) /* check the timeout */
568  {
569  handle->debug_print("mfrc522: read timeout.\n"); /* read timeout */
570  res = 1; /* set the exit code */
571 
572  goto exit_code; /* goto the exit code */
573  }
574  }
575 
576  if (a_mfrc522_read(handle, MFRC522_REG_VERSION, &id, 1) != 0) /* get the id */
577  {
578  handle->debug_print("mfrc522: get id failed.\n"); /* get id failed */
579  res = 5; /* set the exit code */
580 
581  goto exit_code; /* goto the exit code */
582  }
583  if (((id >> 4) & 0xF) != 9) /* check the id */
584  {
585  handle->debug_print("mfrc522: check id failed.\n"); /* check id failed */
586  res = 6; /* set the exit code */
587 
588  goto exit_code; /* goto the exit code */
589  }
590 
591  handle->inited = 1; /* flag inited */
592  handle->irq_flag = 0x0000; /* set 0x0000 */
593 
594  return 0; /* success return 0 */
595 
596  exit_code:
597 
598  if (handle->iic_spi_uart == MFRC522_INTERFACE_IIC) /* if iic interface */
599  {
600  (void)handle->iic_deinit(); /* iic deinit */
601  }
602  else if (handle->iic_spi_uart == MFRC522_INTERFACE_SPI) /* if spi interface */
603  {
604  (void)handle->spi_deinit(); /* spi deinit */
605  }
606  else /* if uart interface */
607  {
608  (void)handle->uart_deinit(); /* uart deinit */
609  }
610  (void)handle->reset_gpio_deinit(); /* reset gpio deinit */
611 
612  return res; /* return error */
613 }
614 
628 {
629  uint8_t res;
630  uint8_t prev;
631 
632  if (handle == NULL) /* check handle */
633  {
634  return 2; /* return error */
635  }
636  if (handle->inited != 1) /* check handle initialization */
637  {
638  return 3; /* return error */
639  }
640 
641  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
642  if (res != 0) /* check the result */
643  {
644  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
645 
646  return 1; /* return error */
647  }
648  prev &= ~(0xF << 0); /* clear the settings */
649  prev |= MFRC522_COMMAND_SOFT_RESET; /* set the idle */
650  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
651  if (res != 0) /* check the result */
652  {
653  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
654 
655  return 1; /* return error */
656  }
657  handle->delay_ms(10); /* delay 10 ms */
658  if (handle->reset_gpio_write(0) != 0) /* power down */
659  {
660  handle->debug_print("mfrc522: reset gpio write failed.\n"); /* reset gpio write failed */
661 
662  return 5; /* return error */
663  }
664  if (handle->iic_spi_uart == MFRC522_INTERFACE_IIC) /* if iic interface */
665  {
666  if (handle->iic_deinit() != 0) /* iic deinit */
667  {
668  handle->debug_print("mfrc522: iic deinit failed.\n"); /* iic deinit failed */
669 
670  return 1; /* return error */
671  }
672  }
673  else if (handle->iic_spi_uart == MFRC522_INTERFACE_SPI) /* if spi interface */
674  {
675  if (handle->spi_deinit() != 0) /* spi deinit */
676  {
677  handle->debug_print("mfrc522: spi deinit failed.\n"); /* spi deinit failed */
678 
679  return 1; /* return error */
680  }
681  }
682  else if (handle->iic_spi_uart == MFRC522_INTERFACE_UART) /* if uart interface */
683  {
684  if (handle->uart_deinit() != 0) /* uart deinit */
685  {
686  handle->debug_print("mfrc522: uart deinit failed.\n"); /* uart deinit failed */
687 
688  return 1; /* return error */
689  }
690  }
691  else
692  {
693  handle->debug_print("mfrc522: interface is invalid.\n"); /* interface is invalid */
694 
695  return 4; /* return error */
696  }
697  if (handle->reset_gpio_deinit() != 0) /* reset gpio deinit */
698  {
699  handle->debug_print("mfrc522: reset gpio deinit failed.\n"); /* reset gpio deinit failed */
700 
701  return 1; /* return error */
702  }
703 
704  handle->inited = 0; /* flag closed */
705 
706  return 0; /* success return 0 */
707 }
708 
720 {
721  uint8_t res;
722  uint8_t prev;
723  uint8_t prev1;
724  uint8_t prev2;
725 
726  if (handle == NULL) /* check handle */
727  {
728  return 2; /* return error */
729  }
730  if (handle->inited != 1) /* check handle initialization */
731  {
732  return 3; /* return error */
733  }
734 
735  if (handle->iic_spi_uart == MFRC522_INTERFACE_UART) /* if uart interface */
736  {
737  handle->delay_ms(2); /* for uart interface delay 2 ms */
738  }
739  res = a_mfrc522_read(handle, MFRC522_REG_STATUS1, &prev, 1); /* read status1 */
740  if (res != 0) /* check the result */
741  {
742  return 1; /* return error */
743  }
744  res = a_mfrc522_read(handle, MFRC522_REG_COMIRQ, &prev1, 1); /* read comirq */
745  if (res != 0) /* check the result */
746  {
747  handle->debug_print("mfrc522: read comirq failed.\n"); /* read comirq failed */
748 
749  return 1; /* return error */
750  }
751  res = a_mfrc522_read(handle, MFRC522_REG_DIVIRQ, &prev2, 1); /* read divirq */
752  if (res != 0) /* check the result */
753  {
754  handle->debug_print("mfrc522: read divirq failed.\n"); /* read divirq failed */
755 
756  return 1; /* return error */
757  }
758 
759  if ((prev & (1 << 4)) != 0) /* if set */
760  {
761  res = a_mfrc522_read(handle, MFRC522_REG_COMIRQ, &prev, 1); /* read config */
762  if (res != 0) /* check the result */
763  {
764  handle->debug_print("mfrc522: read comirq failed.\n"); /* read comirq failed */
765 
766  return 1; /* return error */
767  }
768  prev &= ~(1 << 7); /* clear the settings */
769  res = a_mfrc522_write(handle, MFRC522_REG_COMIRQ, &prev, 1); /* write config */
770  if (res != 0) /* check the result */
771  {
772  handle->debug_print("mfrc522: write comirq failed.\n"); /* write comirq failed */
773 
774  return 1; /* return error */
775  }
776  res = a_mfrc522_read(handle, MFRC522_REG_DIVIRQ, &prev, 1); /* read config */
777  if (res != 0) /* check the result */
778  {
779  handle->debug_print("mfrc522: read divirq failed.\n"); /* read divirq failed */
780 
781  return 1; /* return error */
782  }
783  prev &= ~(1 << 7); /* clear the settings */
784  res = a_mfrc522_write(handle, MFRC522_REG_DIVIRQ, &prev, 1); /* write config */
785  if (res != 0) /* check the result */
786  {
787  handle->debug_print("mfrc522: write divirq failed.\n"); /* write divirq failed */
788 
789  return 1; /* return error */
790  }
791 
792  if ((prev1 & (1 << MFRC522_INTERRUPT_TIMER)) != 0) /* timer */
793  {
794  handle->irq_flag |= 1 << MFRC522_INTERRUPT_TIMER; /* set the irq flag */
795  if (handle->receive_callback != NULL) /* if receive callback */
796  {
797  handle->receive_callback(MFRC522_INTERRUPT_TIMER); /* run callback */
798  }
799  }
800  if ((prev1 & (1 << MFRC522_INTERRUPT_ERR)) != 0) /* err */
801  {
802  handle->irq_flag |= 1 << MFRC522_INTERRUPT_ERR; /* set the irq flag */
803  if (handle->receive_callback != NULL) /* if receive callback */
804  {
805  handle->receive_callback(MFRC522_INTERRUPT_ERR); /* run callback */
806  }
807  }
808  if ((prev1 & (1 << MFRC522_INTERRUPT_LO_ALERT)) != 0) /* lo alert */
809  {
810  handle->irq_flag |= 1 << MFRC522_INTERRUPT_LO_ALERT; /* set the irq flag */
811  if (handle->receive_callback != NULL) /* if receive callback */
812  {
813  handle->receive_callback(MFRC522_INTERRUPT_LO_ALERT); /* run callback */
814  }
815  }
816  if ((prev1 & (1 << MFRC522_INTERRUPT_HI_ALERT)) != 0) /* hi alert */
817  {
818  handle->irq_flag |= 1 << MFRC522_INTERRUPT_HI_ALERT; /* set the irq flag */
819  if (handle->receive_callback != NULL) /* if receive callback */
820  {
821  handle->receive_callback(MFRC522_INTERRUPT_HI_ALERT); /* run callback */
822  }
823  }
824  if ((prev1 & (1 << MFRC522_INTERRUPT_IDLE)) != 0) /* idle */
825  {
826  handle->irq_flag |= 1 << MFRC522_INTERRUPT_IDLE; /* set the irq flag */
827  if (handle->receive_callback != NULL) /* if receive callback */
828  {
829  handle->receive_callback(MFRC522_INTERRUPT_IDLE); /* run callback */
830  }
831  }
832  if ((prev1 & (1 << MFRC522_INTERRUPT_RX)) != 0) /* rx */
833  {
834  handle->irq_flag |= 1 << MFRC522_INTERRUPT_RX; /* set the irq flag */
835  if (handle->receive_callback != NULL) /* if receive callback */
836  {
837  handle->receive_callback(MFRC522_INTERRUPT_RX); /* run callback */
838  }
839  }
840  if ((prev1 & (1 << MFRC522_INTERRUPT_TX)) != 0) /* tx */
841  {
842  handle->irq_flag |= 1 << MFRC522_INTERRUPT_TX; /* set the irq flag */
843  if (handle->receive_callback != NULL) /* if receive callback */
844  {
845  handle->receive_callback(MFRC522_INTERRUPT_TX); /* run callback */
846  }
847  }
848  if ((prev2 & (1 << MFRC522_INTERRUPT2_CRC)) != 0) /* crc */
849  {
850  handle->irq_flag |= 1 << MFRC522_INTERRUPT_CRC; /* set the irq flag */
851  if (handle->receive_callback != NULL) /* if receive callback */
852  {
853  handle->receive_callback(MFRC522_INTERRUPT_CRC); /* run callback */
854  }
855  }
856  if ((prev2 & (1 << MFRC522_INTERRUPT2_MFIN_ACT)) != 0) /* mfin act */
857  {
858  handle->irq_flag |= 1 << MFRC522_INTERRUPT_MFIN_ACT; /* set the irq flag */
859  if (handle->receive_callback != NULL) /* if receive callback */
860  {
861  handle->receive_callback(MFRC522_INTERRUPT_MFIN_ACT); /* run callback */
862  }
863  }
864  }
865 
866  return 0; /* success return 0 */
867 }
868 
892  mfrc522_command_t command,
893  uint8_t *in_buf, uint8_t in_len,
894  uint8_t *out_buf, uint8_t *out_len,
895  uint8_t *err, uint32_t ms)
896 {
897  uint8_t res;
898  uint8_t prev;
899  uint8_t i;
900  uint16_t wait_for;
901  uint32_t timeout;
902 
903  if (handle == NULL) /* check handle */
904  {
905  return 2; /* return error */
906  }
907  if (handle->inited != 1) /* check handle initialization */
908  {
909  return 3; /* return error */
910  }
911  if ((in_buf == NULL) || (out_buf == NULL)) /* check the buffer */
912  {
913  handle->debug_print("mfrc522: buffer is NULL.\n"); /* buffer is NULL */
914 
915  return 4; /* return error */
916  }
917  if (in_len > 64) /* check the length */
918  {
919  handle->debug_print("mfrc522: in_len is over 64.\n"); /* in_len is over 64 */
920 
921  return 5; /* return error */
922  }
923 
924  /* set idle */
925  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
926  if (res != 0) /* check the result */
927  {
928  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
929 
930  return 1; /* return error */
931  }
932  prev &= ~(0xF << 0); /* clear the settings */
933  prev |= MFRC522_COMMAND_IDLE; /* set the idle */
934  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
935  if (res != 0) /* check the result */
936  {
937  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
938 
939  return 1; /* return error */
940  }
941 
942  /* flush the fifo */
943  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_LEVEL, &prev, 1); /* read level */
944  if (res != 0) /* check the result */
945  {
946  handle->debug_print("mfrc522: read fifo level failed.\n"); /* read fifo level failed */
947 
948  return 1; /* return error */
949  }
950  prev |= 1 << 7; /* set the flush bit */
951  res = a_mfrc522_write(handle, MFRC522_REG_FIFO_LEVEL, &prev, 1); /* write level */
952  if (res != 0) /* check the result */
953  {
954  handle->debug_print("mfrc522: write fifo level failed.\n"); /* write fifo level failed */
955 
956  return 1; /* return error */
957  }
958 
959  /* write fifo */
960  for (i = 0; i < in_len; i++) /* loop */
961  {
962  res = a_mfrc522_write(handle, MFRC522_REG_FIFO_DATA, in_buf + i, 1); /* write data */
963  if (res != 0) /* check the result */
964  {
965  handle->debug_print("mfrc522: write fifo data failed.\n"); /* write fifo data failed */
966 
967  return 1; /* return error */
968  }
969  }
970 
971  /* clear the flag */
972  handle->irq_flag = 0; /* clear the irq flag */
973  res = a_mfrc522_read(handle, MFRC522_REG_COMIRQ, &prev, 1); /* read config */
974  if (res != 0) /* check the result */
975  {
976  handle->debug_print("mfrc522: read comirq failed.\n"); /* read comirq failed */
977 
978  return 1; /* return error */
979  }
980  prev &= ~(1 << 7); /* clear the settings */
981  res = a_mfrc522_write(handle, MFRC522_REG_COMIRQ, &prev, 1); /* write config */
982  if (res != 0) /* check the result */
983  {
984  handle->debug_print("mfrc522: write comirq failed.\n"); /* write comirq failed */
985 
986  return 1; /* return error */
987  }
988  res = a_mfrc522_read(handle, MFRC522_REG_DIVIRQ, &prev, 1); /* read config */
989  if (res != 0) /* check the result */
990  {
991  handle->debug_print("mfrc522: read divirq failed.\n"); /* read divirq failed */
992 
993  return 1; /* return error */
994  }
995  prev &= ~(1 << 7); /* clear the settings */
996  res = a_mfrc522_write(handle, MFRC522_REG_DIVIRQ, &prev, 1); /* write config */
997  if (res != 0) /* check the result */
998  {
999  handle->debug_print("mfrc522: write divirq failed.\n"); /* write divirq failed */
1000 
1001  return 1; /* return error */
1002  }
1003 
1004  /* set the command */
1005  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1006  if (res != 0) /* check the result */
1007  {
1008  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1009 
1010  return 1; /* return error */
1011  }
1012  prev &= ~(0xF << 0); /* clear the settings */
1013  prev |= command; /* set the command */
1014  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
1015  if (res != 0) /* check the result */
1016  {
1017  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
1018 
1019  return 1; /* return error */
1020  }
1021 
1022  /* set the bit framing */
1023  if (command == MFRC522_COMMAND_TRANSCEIVE) /* if transceiver */
1024  {
1025  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
1026  if (res != 0) /* check the result */
1027  {
1028  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
1029 
1030  return 1; /* return error */
1031  }
1032  prev |= 1 << 7; /* set the start bit */
1033  res = a_mfrc522_write(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* write the bit framing */
1034  if (res != 0) /* check the result */
1035  {
1036  handle->debug_print("mfrc522: write bit framing failed.\n"); /* write the bit framing failed */
1037 
1038  return 1; /* return error */
1039  }
1040  }
1041 
1042  /* set the wait bit */
1043  if (command == MFRC522_COMMAND_MF_AUTHENT) /* if authentic */
1044  {
1045  wait_for = (1 << MFRC522_INTERRUPT_IDLE) |
1046  (1 << MFRC522_INTERRUPT_TIMER); /* if idle && timer */
1047  }
1048  else if (command == MFRC522_COMMAND_TRANSCEIVE) /* if transceiver */
1049  {
1050  wait_for = (1 << MFRC522_INTERRUPT_RX) |
1051  (1 << MFRC522_INTERRUPT_TIMER); /* if rx && timer */
1052  }
1053  else if (command == MFRC522_COMMAND_CALC_CRC) /* if crc */
1054  {
1055  wait_for = (1 << MFRC522_INTERRUPT_CRC) |
1056  (1 << MFRC522_INTERRUPT_TIMER); /* if crc && timer */
1057  }
1058  else
1059  {
1060  wait_for = (1 << MFRC522_INTERRUPT_IDLE) |
1061  (1 << MFRC522_INTERRUPT_TIMER); /* if idle && timer */
1062  }
1063  timeout = ms; /* set timeout */
1064  while (timeout != 0) /* check the timeout */
1065  {
1066  handle->delay_ms(1); /* delay 1ms */
1067  timeout--; /* timeout-- */
1068  if ((handle->irq_flag & wait_for) != 0) /* check the wait for */
1069  {
1070  break; /* break */
1071  }
1072  if (timeout == 0) /* if timeout == 0 */
1073  {
1074  handle->debug_print("mfrc522: read timeout.\n"); /* read timeout */
1075 
1076  return 6; /* return error */
1077  }
1078  }
1079 
1080  /* end */
1081  if (command == MFRC522_COMMAND_TRANSCEIVE) /* if transceiver */
1082  {
1083  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
1084  if (res != 0) /* check the result */
1085  {
1086  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
1087 
1088  return 1; /* return error */
1089  }
1090  prev &= ~(1 << 7); /* clear the settings */
1091  res = a_mfrc522_write(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* write the bit framing */
1092  if (res != 0) /* check the result */
1093  {
1094  handle->debug_print("mfrc522: write bit framing failed.\n"); /* write the bit framing failed */
1095 
1096  return 1; /* return error */
1097  }
1098  }
1099 
1100  /* check timer timeout */
1101  if ((handle->irq_flag & ((1 << MFRC522_INTERRUPT_TIMER))) != 0) /* check the timer */
1102  {
1103  handle->debug_print("mfrc522: timer timeout.\n"); /* timer timeout */
1104 
1105  return 7; /* return error */
1106  }
1107 
1108  /* check error */
1109  if ((handle->irq_flag & ((1 << MFRC522_INTERRUPT_ERR))) != 0) /* check the error */
1110  {
1111  res = a_mfrc522_read(handle, MFRC522_REG_ERROR, err, 1); /* read config */
1112  if (res != 0) /* check the result */
1113  {
1114  handle->debug_print("mfrc522: read error failed.\n"); /* read error failed */
1115 
1116  return 1; /* return error */
1117  }
1118  handle->debug_print("mfrc522: find error.\n"); /* find error */
1119 
1120  return 8; /* return error */
1121  }
1122 
1123  /* get the fifo */
1124  if ((command == MFRC522_COMMAND_TRANSCEIVE) && ((*out_len) != 0)) /* if transceiver and need get from fifo */
1125  {
1126  uint8_t level;
1127 
1128  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_LEVEL, &level, 1); /* read level */
1129  if (res != 0) /* check the result */
1130  {
1131  handle->debug_print("mfrc522: read fifo level failed.\n"); /* read fifo level failed */
1132 
1133  return 1; /* return error */
1134  }
1135 
1136  *out_len = level > (*out_len) ? (*out_len) : level; /* set the output length */
1137  for (i = 0; i < (*out_len); i++) /* loop */
1138  {
1139  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_DATA, out_buf + i, 1); /* read data */
1140  if (res != 0) /* check the result */
1141  {
1142  handle->debug_print("mfrc522: read fifo data failed.\n"); /* read fifo data failed */
1143 
1144  return 1; /* return error */
1145  }
1146  }
1147  }
1148  if ((command == MFRC522_COMMAND_MEM) && ((*out_len) != 0)) /* if mem and need get from fifo */
1149  {
1150  uint8_t level;
1151 
1152  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_LEVEL, &level, 1); /* read level */
1153  if (res != 0) /* check the result */
1154  {
1155  handle->debug_print("mfrc522: read fifo level failed.\n"); /* read fifo level failed */
1156 
1157  return 1; /* return error */
1158  }
1159  *out_len = level > (*out_len) ? (*out_len) : level; /* set the output length */
1160  for (i = 0; i < (*out_len); i++) /* loop */
1161  {
1162  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_DATA, out_buf + i, 1); /* read data */
1163  if (res != 0) /* check the result */
1164  {
1165  handle->debug_print("mfrc522: read fifo data failed.\n"); /* read fifo data failed */
1166 
1167  return 1; /* return error */
1168  }
1169  }
1170  }
1171 
1172  /* stop the timer */
1173  res = a_mfrc522_read(handle, MFRC522_REG_CONTROL, &prev, 1); /* read control */
1174  if (res != 0) /* check the result */
1175  {
1176  handle->debug_print("mfrc522: read control failed.\n"); /* read control failed */
1177 
1178  return 1; /* return error */
1179  }
1180  prev |= 1 << 7; /* set the stop bit */
1181  res = a_mfrc522_write(handle, MFRC522_REG_CONTROL, &prev, 1); /* write control */
1182  if (res != 0) /* check the result */
1183  {
1184  handle->debug_print("mfrc522: write control failed.\n"); /* write control failed */
1185 
1186  return 1; /* return error */
1187  }
1188 
1189  /* set the idle */
1190  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1191  if (res != 0) /* check the result */
1192  {
1193  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1194 
1195  return 1; /* return error */
1196  }
1197  prev &= ~(0xF << 0); /* clear the settings */
1198  prev |= MFRC522_COMMAND_IDLE; /* set the idle */
1199  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
1200  if (res != 0) /* check the result */
1201  {
1202  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
1203 
1204  return 1; /* return error */
1205  }
1206  *err = prev; /* set the 0 */
1207 
1208  return 0; /* success return 0 */
1209 }
1210 
1223 {
1224  uint8_t res;
1225  uint8_t prev;
1226 
1227  if (handle == NULL) /* check handle */
1228  {
1229  return 2; /* return error */
1230  }
1231  if (handle->inited != 1) /* check handle initialization */
1232  {
1233  return 3; /* return error */
1234  }
1235 
1236  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1237  if (res != 0) /* check the result */
1238  {
1239  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1240 
1241  return 1; /* return error */
1242  }
1243  prev &= ~(1 << 5); /* clear the settings */
1244  prev |= ((!enable) << 5) | MFRC522_COMMAND_NO_CHANGE; /* set the bool */
1245  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
1246  if (res != 0) /* check the result */
1247  {
1248  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
1249 
1250  return 1; /* return error */
1251  }
1252 
1253  return 0; /* success return 0 */
1254 }
1255 
1268 {
1269  uint8_t res;
1270  uint8_t prev;
1271 
1272  if (handle == NULL) /* check handle */
1273  {
1274  return 2; /* return error */
1275  }
1276  if (handle->inited != 1) /* check handle initialization */
1277  {
1278  return 3; /* return error */
1279  }
1280 
1281  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1282  if (res != 0) /* check the result */
1283  {
1284  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1285 
1286  return 1; /* return error */
1287  }
1288  *enable = (mfrc522_bool_t)(!((prev >> 5) & 0x01)); /* get the bool */
1289 
1290  return 0; /* success return 0 */
1291 }
1292 
1305 {
1306  uint8_t res;
1307  uint8_t prev;
1308 
1309  if (handle == NULL) /* check handle */
1310  {
1311  return 2; /* return error */
1312  }
1313  if (handle->inited != 1) /* check handle initialization */
1314  {
1315  return 3; /* return error */
1316  }
1317 
1318  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1319  if (res != 0) /* check the result */
1320  {
1321  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1322 
1323  return 1; /* return error */
1324  }
1325  prev &= ~(1 << 4); /* clear the settings */
1326  prev |= (enable << 4) | MFRC522_COMMAND_NO_CHANGE; /* set the bool */
1327  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
1328  if (res != 0) /* check the result */
1329  {
1330  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
1331 
1332  return 1; /* return error */
1333  }
1334 
1335  return 0; /* success return 0 */
1336 }
1337 
1350 {
1351  uint8_t res;
1352  uint8_t prev;
1353 
1354  if (handle == NULL) /* check handle */
1355  {
1356  return 2; /* return error */
1357  }
1358  if (handle->inited != 1) /* check handle initialization */
1359  {
1360  return 3; /* return error */
1361  }
1362 
1363  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1364  if (res != 0) /* check the result */
1365  {
1366  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1367 
1368  return 1; /* return error */
1369  }
1370  *enable = (mfrc522_bool_t)((prev >> 4) & 0x01); /* get the bool */
1371 
1372  return 0; /* success return 0 */
1373 }
1374 
1387 {
1388  uint8_t res;
1389  uint8_t prev;
1390 
1391  if (handle == NULL) /* check handle */
1392  {
1393  return 2; /* return error */
1394  }
1395  if (handle->inited != 1) /* check handle initialization */
1396  {
1397  return 3; /* return error */
1398  }
1399 
1400  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1401  if (res != 0) /* check the result */
1402  {
1403  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1404 
1405  return 1; /* return error */
1406  }
1407  prev &= ~(0xF << 0); /* clear the settings */
1408  prev |= command; /* set the command */
1409  res = a_mfrc522_write(handle, MFRC522_REG_COMMAND, &prev, 1); /* write config */
1410  if (res != 0) /* check the result */
1411  {
1412  handle->debug_print("mfrc522: write command failed.\n"); /* write command failed */
1413 
1414  return 1; /* return error */
1415  }
1416 
1417  return 0; /* success return 0 */
1418 }
1419 
1432 {
1433  uint8_t res;
1434  uint8_t prev;
1435 
1436  if (handle == NULL) /* check handle */
1437  {
1438  return 2; /* return error */
1439  }
1440  if (handle->inited != 1) /* check handle initialization */
1441  {
1442  return 3; /* return error */
1443  }
1444 
1445  res = a_mfrc522_read(handle, MFRC522_REG_COMMAND, &prev, 1); /* read config */
1446  if (res != 0) /* check the result */
1447  {
1448  handle->debug_print("mfrc522: read command failed.\n"); /* read command failed */
1449 
1450  return 1; /* return error */
1451  }
1452  *command = (mfrc522_command_t)((prev >> 0) & 0x0F); /* get the command */
1453 
1454  return 0; /* success return 0 */
1455 }
1456 
1470 {
1471  uint8_t res;
1472  uint8_t prev;
1473 
1474  if (handle == NULL) /* check handle */
1475  {
1476  return 2; /* return error */
1477  }
1478  if (handle->inited != 1) /* check handle initialization */
1479  {
1480  return 3; /* return error */
1481  }
1482 
1483  res = a_mfrc522_read(handle, MFRC522_REG_COMIEN, &prev, 1); /* read config */
1484  if (res != 0) /* check the result */
1485  {
1486  handle->debug_print("mfrc522: read comien failed.\n"); /* read comien failed */
1487 
1488  return 1; /* return error */
1489  }
1490  prev &= ~(1 << type); /* clear the settings */
1491  prev |= (enable << type); /* set the type */
1492  res = a_mfrc522_write(handle, MFRC522_REG_COMIEN, &prev, 1); /* write config */
1493  if (res != 0) /* check the result */
1494  {
1495  handle->debug_print("mfrc522: write comien failed.\n"); /* write comien failed */
1496 
1497  return 1; /* return error */
1498  }
1499 
1500  return 0; /* success return 0 */
1501 }
1502 
1516 {
1517  uint8_t res;
1518  uint8_t prev;
1519 
1520  if (handle == NULL) /* check handle */
1521  {
1522  return 2; /* return error */
1523  }
1524  if (handle->inited != 1) /* check handle initialization */
1525  {
1526  return 3; /* return error */
1527  }
1528 
1529  res = a_mfrc522_read(handle, MFRC522_REG_COMIEN, &prev, 1); /* read config */
1530  if (res != 0) /* check the result */
1531  {
1532  handle->debug_print("mfrc522: read comien failed.\n"); /* read comien failed */
1533 
1534  return 1; /* return error */
1535  }
1536  *enable = (mfrc522_bool_t)((prev >> type) & 0x01); /* set the bool */
1537 
1538  return 0; /* success return 0 */
1539 }
1540 
1553 {
1554  uint8_t res;
1555  uint8_t prev;
1556 
1557  if (handle == NULL) /* check handle */
1558  {
1559  return 2; /* return error */
1560  }
1561  if (handle->inited != 1) /* check handle initialization */
1562  {
1563  return 3; /* return error */
1564  }
1565 
1566  res = a_mfrc522_read(handle, MFRC522_REG_COMIEN, &prev, 1); /* read config */
1567  if (res != 0) /* check the result */
1568  {
1569  handle->debug_print("mfrc522: read comien failed.\n"); /* read comien failed */
1570 
1571  return 1; /* return error */
1572  }
1573  prev &= ~(1 << 7); /* clear the settings */
1574  prev |= (enable << 7); /* set the bool */
1575  res = a_mfrc522_write(handle, MFRC522_REG_COMIEN, &prev, 1); /* write config */
1576  if (res != 0) /* check the result */
1577  {
1578  handle->debug_print("mfrc522: write comien failed.\n"); /* write comien failed */
1579 
1580  return 1; /* return error */
1581  }
1582 
1583  return 0; /* success return 0 */
1584 }
1585 
1598 {
1599  uint8_t res;
1600  uint8_t prev;
1601 
1602  if (handle == NULL) /* check handle */
1603  {
1604  return 2; /* return error */
1605  }
1606  if (handle->inited != 1) /* check handle initialization */
1607  {
1608  return 3; /* return error */
1609  }
1610 
1611  res = a_mfrc522_read(handle, MFRC522_REG_COMIEN, &prev, 1); /* read config */
1612  if (res != 0) /* check the result */
1613  {
1614  handle->debug_print("mfrc522: read comien failed.\n"); /* read comien failed */
1615 
1616  return 1; /* return error */
1617  }
1618  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
1619 
1620  return 0; /* success return 0 */
1621 }
1622 
1635 {
1636  uint8_t res;
1637  uint8_t prev;
1638 
1639  if (handle == NULL) /* check handle */
1640  {
1641  return 2; /* return error */
1642  }
1643  if (handle->inited != 1) /* check handle initialization */
1644  {
1645  return 3; /* return error */
1646  }
1647 
1648  res = a_mfrc522_read(handle, MFRC522_REG_COMIRQ, &prev, 1); /* read config */
1649  if (res != 0) /* check the result */
1650  {
1651  handle->debug_print("mfrc522: read comirq failed.\n"); /* read comirq failed */
1652 
1653  return 1; /* return error */
1654  }
1655  prev &= ~(1 << 7); /* clear the settings */
1656  prev |= (mark << 7); /* set the mark */
1657  res = a_mfrc522_write(handle, MFRC522_REG_COMIRQ, &prev, 1); /* write config */
1658  if (res != 0) /* check the result */
1659  {
1660  handle->debug_print("mfrc522: write comirq failed.\n"); /* write comirq failed */
1661 
1662  return 1; /* return error */
1663  }
1664 
1665  return 0; /* success return 0 */
1666 }
1667 
1681 {
1682  uint8_t res;
1683  uint8_t prev;
1684 
1685  if (handle == NULL) /* check handle */
1686  {
1687  return 2; /* return error */
1688  }
1689  if (handle->inited != 1) /* check handle initialization */
1690  {
1691  return 3; /* return error */
1692  }
1693 
1694  res = a_mfrc522_read(handle, MFRC522_REG_DIVIEN, &prev, 1); /* read config */
1695  if (res != 0) /* check the result */
1696  {
1697  handle->debug_print("mfrc522: read divien failed.\n"); /* read divien failed */
1698 
1699  return 1; /* return error */
1700  }
1701  prev &= ~(1 << type); /* clear the settings */
1702  prev |= (enable << type); /* set the type */
1703  res = a_mfrc522_write(handle, MFRC522_REG_DIVIEN, &prev, 1); /* write config */
1704  if (res != 0) /* check the result */
1705  {
1706  handle->debug_print("mfrc522: write divien failed.\n"); /* write divien failed */
1707 
1708  return 1; /* return error */
1709  }
1710 
1711  return 0; /* success return 0 */
1712 }
1713 
1727 {
1728  uint8_t res;
1729  uint8_t prev;
1730 
1731  if (handle == NULL) /* check handle */
1732  {
1733  return 2; /* return error */
1734  }
1735  if (handle->inited != 1) /* check handle initialization */
1736  {
1737  return 3; /* return error */
1738  }
1739 
1740  res = a_mfrc522_read(handle, MFRC522_REG_DIVIEN, &prev, 1); /* read config */
1741  if (res != 0) /* check the result */
1742  {
1743  handle->debug_print("mfrc522: read divien failed.\n"); /* read divien failed */
1744 
1745  return 1; /* return error */
1746  }
1747  *enable = (mfrc522_bool_t)((prev >> type) & 0x01); /* get the bool */
1748 
1749  return 0; /* success return 0 */
1750 }
1751 
1764 {
1765  uint8_t res;
1766  uint8_t prev;
1767 
1768  if (handle == NULL) /* check handle */
1769  {
1770  return 2; /* return error */
1771  }
1772  if (handle->inited != 1) /* check handle initialization */
1773  {
1774  return 3; /* return error */
1775  }
1776 
1777  res = a_mfrc522_read(handle, MFRC522_REG_DIVIEN, &prev, 1); /* read config */
1778  if (res != 0) /* check the result */
1779  {
1780  handle->debug_print("mfrc522: read divien failed.\n"); /* read divien failed */
1781 
1782  return 1; /* return error */
1783  }
1784  prev &= ~(1 << 7); /* clear the settings */
1785  prev |= (type << 7); /* set the type */
1786  res = a_mfrc522_write(handle, MFRC522_REG_DIVIEN, &prev, 1); /* write config */
1787  if (res != 0) /* check the result */
1788  {
1789  handle->debug_print("mfrc522: write divien failed.\n"); /* write divien failed */
1790 
1791  return 1; /* return error */
1792  }
1793 
1794  return 0; /* success return 0 */
1795 }
1796 
1809 {
1810  uint8_t res;
1811  uint8_t prev;
1812 
1813  if (handle == NULL) /* check handle */
1814  {
1815  return 2; /* return error */
1816  }
1817  if (handle->inited != 1) /* check handle initialization */
1818  {
1819  return 3; /* return error */
1820  }
1821 
1822  res = a_mfrc522_read(handle, MFRC522_REG_DIVIEN, &prev, 1); /* read config */
1823  if (res != 0) /* check the result */
1824  {
1825  handle->debug_print("mfrc522: read divien failed.\n"); /* read divien failed */
1826 
1827  return 1; /* return error */
1828  }
1829  *type = (mfrc522_interrupt_pin_type_t)((prev >> 7) & 0x01); /* get the type */
1830 
1831  return 0; /* success return 0 */
1832 }
1833 
1846 {
1847  uint8_t res;
1848  uint8_t prev;
1849 
1850  if (handle == NULL) /* check handle */
1851  {
1852  return 2; /* return error */
1853  }
1854  if (handle->inited != 1) /* check handle initialization */
1855  {
1856  return 3; /* return error */
1857  }
1858 
1859  res = a_mfrc522_read(handle, MFRC522_REG_DIVIRQ, &prev, 1); /* read config */
1860  if (res != 0) /* check the result */
1861  {
1862  handle->debug_print("mfrc522: read divirq failed.\n"); /* read divirq failed */
1863 
1864  return 1; /* return error */
1865  }
1866  prev &= ~(1 << 7); /* clear the settings */
1867  prev |= (mark << 7); /* set the mark */
1868  res = a_mfrc522_write(handle, MFRC522_REG_DIVIRQ, &prev, 1); /* write config */
1869  if (res != 0) /* check the result */
1870  {
1871  handle->debug_print("mfrc522: write divirq failed.\n"); /* write divirq failed */
1872 
1873  return 1; /* return error */
1874  }
1875 
1876  return 0; /* success return 0 */
1877 }
1878 
1890 uint8_t mfrc522_get_interrupt1_status(mfrc522_handle_t *handle, uint8_t *status)
1891 {
1892  uint8_t res;
1893  uint8_t prev;
1894 
1895  if (handle == NULL) /* check handle */
1896  {
1897  return 2; /* return error */
1898  }
1899  if (handle->inited != 1) /* check handle initialization */
1900  {
1901  return 3; /* return error */
1902  }
1903 
1904  res = a_mfrc522_read(handle, MFRC522_REG_COMIRQ, &prev, 1); /* read config */
1905  if (res != 0) /* check the result */
1906  {
1907  handle->debug_print("mfrc522: read comirq failed.\n"); /* read comirq failed */
1908 
1909  return 1; /* return error */
1910  }
1911  *status = prev & (~(1 << 7)); /* get the status */
1912 
1913  return 0; /* success return 0 */
1914 }
1915 
1927 uint8_t mfrc522_get_interrupt2_status(mfrc522_handle_t *handle, uint8_t *status)
1928 {
1929  uint8_t res;
1930  uint8_t prev;
1931 
1932  if (handle == NULL) /* check handle */
1933  {
1934  return 2; /* return error */
1935  }
1936  if (handle->inited != 1) /* check handle initialization */
1937  {
1938  return 3; /* return error */
1939  }
1940 
1941  res = a_mfrc522_read(handle, MFRC522_REG_DIVIRQ, &prev, 1); /* read config */
1942  if (res != 0) /* check the result */
1943  {
1944  handle->debug_print("mfrc522: read divirq failed.\n"); /* read divirq failed */
1945 
1946  return 1; /* return error */
1947  }
1948  *status = prev & (~(1 << 7)); /* get the status */
1949 
1950  return 0; /* success return 0 */
1951 }
1952 
1964 uint8_t mfrc522_get_error(mfrc522_handle_t *handle, uint8_t *err)
1965 {
1966  uint8_t res;
1967  uint8_t prev;
1968 
1969  if (handle == NULL) /* check handle */
1970  {
1971  return 2; /* return error */
1972  }
1973  if (handle->inited != 1) /* check handle initialization */
1974  {
1975  return 3; /* return error */
1976  }
1977 
1978  res = a_mfrc522_read(handle, MFRC522_REG_ERROR, &prev, 1); /* read config */
1979  if (res != 0) /* check the result */
1980  {
1981  handle->debug_print("mfrc522: read error failed.\n"); /* read error failed */
1982 
1983  return 1; /* return error */
1984  }
1985  *err = prev; /* set the error */
1986 
1987  return 0; /* success return 0 */
1988 }
1989 
2001 uint8_t mfrc522_get_status1(mfrc522_handle_t *handle, uint8_t *status)
2002 {
2003  uint8_t res;
2004  uint8_t prev;
2005 
2006  if (handle == NULL) /* check handle */
2007  {
2008  return 2; /* return error */
2009  }
2010  if (handle->inited != 1) /* check handle initialization */
2011  {
2012  return 3; /* return error */
2013  }
2014 
2015  res = a_mfrc522_read(handle, MFRC522_REG_STATUS1, &prev, 1); /* read config */
2016  if (res != 0) /* check the result */
2017  {
2018  handle->debug_print("mfrc522: read status1 failed.\n"); /* read status1 failed */
2019 
2020  return 1; /* return error */
2021  }
2022  *status = prev; /* set the status */
2023 
2024  return 0; /* success return 0 */
2025 }
2026 
2038 uint8_t mfrc522_get_status2(mfrc522_handle_t *handle, uint8_t *status)
2039 {
2040  uint8_t res;
2041  uint8_t prev;
2042 
2043  if (handle == NULL) /* check handle */
2044  {
2045  return 2; /* return error */
2046  }
2047  if (handle->inited != 1) /* check handle initialization */
2048  {
2049  return 3; /* return error */
2050  }
2051 
2052  res = a_mfrc522_read(handle, MFRC522_REG_STATUS2, &prev, 1); /* read config */
2053  if (res != 0) /* check the result */
2054  {
2055  handle->debug_print("mfrc522: read status2 failed.\n"); /* read status2 failed */
2056 
2057  return 1; /* return error */
2058  }
2059  *status = prev & (1 << 3); /* set the status */
2060 
2061  return 0; /* success return 0 */
2062 }
2063 
2076 {
2077  uint8_t res;
2078  uint8_t prev;
2079 
2080  if (handle == NULL) /* check handle */
2081  {
2082  return 2; /* return error */
2083  }
2084  if (handle->inited != 1) /* check handle initialization */
2085  {
2086  return 3; /* return error */
2087  }
2088 
2089  res = a_mfrc522_read(handle, MFRC522_REG_STATUS2, &prev, 1); /* read config */
2090  if (res != 0) /* check the result */
2091  {
2092  handle->debug_print("mfrc522: read status2 failed.\n"); /* read status2 failed */
2093 
2094  return 1; /* return error */
2095  }
2096  *state = (mfrc522_modem_state_t)(prev & 0x7); /* set the modem state */
2097 
2098  return 0; /* success return 0 */
2099 }
2100 
2113 {
2114  uint8_t res;
2115  uint8_t prev;
2116 
2117  if (handle == NULL) /* check handle */
2118  {
2119  return 2; /* return error */
2120  }
2121  if (handle->inited != 1) /* check handle initialization */
2122  {
2123  return 3; /* return error */
2124  }
2125 
2126  res = a_mfrc522_read(handle, MFRC522_REG_STATUS2, &prev, 1); /* read config */
2127  if (res != 0) /* check the result */
2128  {
2129  handle->debug_print("mfrc522: read status2 failed.\n"); /* read status2 failed */
2130 
2131  return 1; /* return error */
2132  }
2133  prev &= ~(1 << 3); /* clear the settings */
2134  prev |= (enable << 3); /* set the bool */
2135  res = a_mfrc522_write(handle, MFRC522_REG_STATUS2, &prev, 1); /* write config */
2136  if (res != 0) /* check the result */
2137  {
2138  handle->debug_print("mfrc522: write status2 failed.\n"); /* write status2 failed */
2139 
2140  return 1; /* return error */
2141  }
2142 
2143  return 0; /* success return 0 */
2144 }
2145 
2158 {
2159  uint8_t res;
2160  uint8_t prev;
2161 
2162  if (handle == NULL) /* check handle */
2163  {
2164  return 2; /* return error */
2165  }
2166  if (handle->inited != 1) /* check handle initialization */
2167  {
2168  return 3; /* return error */
2169  }
2170 
2171  res = a_mfrc522_read(handle, MFRC522_REG_STATUS2, &prev, 1); /* read config */
2172  if (res != 0) /* check the result */
2173  {
2174  handle->debug_print("mfrc522: read status2 failed.\n"); /* read status2 failed */
2175 
2176  return 1; /* return error */
2177  }
2178  prev &= ~(1 << 6); /* clear the settings */
2179  prev |= (enable << 6); /* set the bool */
2180  res = a_mfrc522_write(handle, MFRC522_REG_STATUS2, &prev, 1); /* write config */
2181  if (res != 0) /* check the result */
2182  {
2183  handle->debug_print("mfrc522: write status2 failed.\n"); /* write status2 failed */
2184 
2185  return 1; /* return error */
2186  }
2187 
2188  return 0; /* success return 0 */
2189 }
2190 
2203 {
2204  uint8_t res;
2205  uint8_t prev;
2206 
2207  if (handle == NULL) /* check handle */
2208  {
2209  return 2; /* return error */
2210  }
2211  if (handle->inited != 1) /* check handle initialization */
2212  {
2213  return 3; /* return error */
2214  }
2215 
2216  res = a_mfrc522_read(handle, MFRC522_REG_STATUS2, &prev, 1); /* read config */
2217  if (res != 0) /* check the result */
2218  {
2219  handle->debug_print("mfrc522: read status2 failed.\n"); /* read status2 failed */
2220 
2221  return 1; /* return error */
2222  }
2223  *enable = (mfrc522_bool_t)((prev >> 6) & 0x01); /* get the bool */
2224 
2225  return 0; /* success return 0 */
2226 }
2227 
2240 {
2241  uint8_t res;
2242  uint8_t prev;
2243 
2244  if (handle == NULL) /* check handle */
2245  {
2246  return 2; /* return error */
2247  }
2248  if (handle->inited != 1) /* check handle initialization */
2249  {
2250  return 3; /* return error */
2251  }
2252 
2253  res = a_mfrc522_read(handle, MFRC522_REG_STATUS2, &prev, 1); /* read config */
2254  if (res != 0) /* check the result */
2255  {
2256  handle->debug_print("mfrc522: read status2 failed.\n"); /* read status2 failed */
2257 
2258  return 1; /* return error */
2259  }
2260  prev &= ~(1 << 7); /* clear the settings */
2261  prev |= (enable << 7); /* set the bool */
2262  res = a_mfrc522_write(handle, MFRC522_REG_STATUS2, &prev, 1); /* write config */
2263  if (res != 0) /* check the result */
2264  {
2265  handle->debug_print("mfrc522: write status2 failed.\n"); /* write status2 failed */
2266 
2267  return 1; /* return error */
2268  }
2269 
2270  return 0; /* success return 0 */
2271 }
2272 
2285 {
2286  uint8_t res;
2287  uint8_t prev;
2288 
2289  if (handle == NULL) /* check handle */
2290  {
2291  return 2; /* return error */
2292  }
2293  if (handle->inited != 1) /* check handle initialization */
2294  {
2295  return 3; /* return error */
2296  }
2297 
2298  res = a_mfrc522_read(handle, MFRC522_REG_STATUS2, &prev, 1); /* read config */
2299  if (res != 0) /* check the result */
2300  {
2301  handle->debug_print("mfrc522: read status2 failed.\n"); /* read status2 failed */
2302 
2303  return 1; /* return error */
2304  }
2305  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
2306 
2307  return 0; /* success return 0 */
2308 }
2309 
2323 uint8_t mfrc522_set_fifo_data(mfrc522_handle_t *handle, uint8_t *data, uint8_t len)
2324 {
2325  uint8_t res;
2326  uint8_t i;
2327 
2328  if (handle == NULL) /* check handle */
2329  {
2330  return 2; /* return error */
2331  }
2332  if (handle->inited != 1) /* check handle initialization */
2333  {
2334  return 3; /* return error */
2335  }
2336  if (len > 64) /* check the length */
2337  {
2338  handle->debug_print("mfrc522: len is over 64.\n"); /* len is over 64 */
2339 
2340  return 4; /* return error */
2341  }
2342 
2343  for (i = 0; i < len; i++) /* loop */
2344  {
2345  res = a_mfrc522_write(handle, MFRC522_REG_FIFO_DATA, data + i, 1); /* write data */
2346  if (res != 0) /* check the result */
2347  {
2348  handle->debug_print("mfrc522: write fifo data failed.\n"); /* write fifo data failed */
2349 
2350  return 1; /* return error */
2351  }
2352  }
2353 
2354  return 0; /* success return 0 */
2355 }
2356 
2370 uint8_t mfrc522_get_fifo_data(mfrc522_handle_t *handle, uint8_t *data, uint8_t len)
2371 {
2372  uint8_t res;
2373  uint8_t i;
2374 
2375  if (handle == NULL) /* check handle */
2376  {
2377  return 2; /* return error */
2378  }
2379  if (handle->inited != 1) /* check handle initialization */
2380  {
2381  return 3; /* return error */
2382  }
2383  if (len > 64) /* check the length */
2384  {
2385  handle->debug_print("mfrc522: len is over 64.\n"); /* len is over 64 */
2386 
2387  return 4; /* return error */
2388  }
2389 
2390  for (i = 0; i < len; i++) /* loop */
2391  {
2392  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_DATA, data + i, 1); /* read data */
2393  if (res != 0) /* check the result */
2394  {
2395  handle->debug_print("mfrc522: read fifo data failed.\n"); /* read fifo data failed */
2396 
2397  return 1; /* return error */
2398  }
2399  }
2400 
2401  return 0; /* success return 0 */
2402 }
2403 
2415 uint8_t mfrc522_get_fifo_level(mfrc522_handle_t *handle, uint8_t *level)
2416 {
2417  uint8_t res;
2418 
2419  if (handle == NULL) /* check handle */
2420  {
2421  return 2; /* return error */
2422  }
2423  if (handle->inited != 1) /* check handle initialization */
2424  {
2425  return 3; /* return error */
2426  }
2427 
2428  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_LEVEL, level, 1); /* read level */
2429  if (res != 0) /* check the result */
2430  {
2431  handle->debug_print("mfrc522: read fifo level failed.\n"); /* read fifo level failed */
2432 
2433  return 1; /* return error */
2434  }
2435 
2436  return 0; /* success return 0 */
2437 }
2438 
2450 {
2451  uint8_t res;
2452  uint8_t prev;
2453 
2454  if (handle == NULL) /* check handle */
2455  {
2456  return 2; /* return error */
2457  }
2458  if (handle->inited != 1) /* check handle initialization */
2459  {
2460  return 3; /* return error */
2461  }
2462 
2463  res = a_mfrc522_read(handle, MFRC522_REG_FIFO_LEVEL, &prev, 1); /* read level */
2464  if (res != 0) /* check the result */
2465  {
2466  handle->debug_print("mfrc522: read fifo level failed.\n"); /* read fifo level failed */
2467 
2468  return 1; /* return error */
2469  }
2470  prev |= 1 << 7; /* set the flush bit */
2471  res = a_mfrc522_write(handle, MFRC522_REG_FIFO_LEVEL, &prev, 1); /* write level */
2472  if (res != 0) /* check the result */
2473  {
2474  handle->debug_print("mfrc522: write fifo level failed.\n"); /* write fifo level failed */
2475 
2476  return 1; /* return error */
2477  }
2478 
2479  return 0; /* success return 0 */
2480 }
2481 
2493 uint8_t mfrc522_get_water_level(mfrc522_handle_t *handle, uint8_t *level)
2494 {
2495  uint8_t res;
2496 
2497  if (handle == NULL) /* check handle */
2498  {
2499  return 2; /* return error */
2500  }
2501  if (handle->inited != 1) /* check handle initialization */
2502  {
2503  return 3; /* return error */
2504  }
2505 
2506  res = a_mfrc522_read(handle, MFRC522_REG_WATER_LEVEL, level, 1); /* read level */
2507  if (res != 0) /* check the result */
2508  {
2509  handle->debug_print("mfrc522: read water level failed.\n"); /* read water level failed */
2510 
2511  return 1; /* return error */
2512  }
2513  *level &= ~(3 << 6); /* clear the bits */
2514 
2515  return 0; /* success return 0 */
2516 }
2517 
2530 uint8_t mfrc522_set_water_level(mfrc522_handle_t *handle, uint8_t level)
2531 {
2532  uint8_t res;
2533 
2534  if (handle == NULL) /* check handle */
2535  {
2536  return 2; /* return error */
2537  }
2538  if (handle->inited != 1) /* check handle initialization */
2539  {
2540  return 3; /* return error */
2541  }
2542  if (level > 0x3F) /* check the level */
2543  {
2544  handle->debug_print("mfrc522: level is over 0x3F.\n"); /* level is over 0x3F */
2545 
2546  return 4; /* return error */
2547  }
2548 
2549  res = a_mfrc522_write(handle, MFRC522_REG_WATER_LEVEL, &level, 1); /* write level */
2550  if (res != 0) /* check the result */
2551  {
2552  handle->debug_print("mfrc522: write water level failed.\n"); /* write water level failed */
2553 
2554  return 1; /* return error */
2555  }
2556 
2557  return 0; /* success return 0 */
2558 }
2559 
2571 {
2572  uint8_t res;
2573  uint8_t prev;
2574 
2575  if (handle == NULL) /* check handle */
2576  {
2577  return 2; /* return error */
2578  }
2579  if (handle->inited != 1) /* check handle initialization */
2580  {
2581  return 3; /* return error */
2582  }
2583 
2584  res = a_mfrc522_read(handle, MFRC522_REG_CONTROL, &prev, 1); /* read control */
2585  if (res != 0) /* check the result */
2586  {
2587  handle->debug_print("mfrc522: read control failed.\n"); /* read control failed */
2588 
2589  return 1; /* return error */
2590  }
2591  prev |= 1 << 7; /* set the stop bit */
2592  res = a_mfrc522_write(handle, MFRC522_REG_CONTROL, &prev, 1); /* write control */
2593  if (res != 0) /* check the result */
2594  {
2595  handle->debug_print("mfrc522: write control failed.\n"); /* write control failed */
2596 
2597  return 1; /* return error */
2598  }
2599 
2600  return 0; /* success return 0 */
2601 }
2602 
2614 {
2615  uint8_t res;
2616  uint8_t prev;
2617 
2618  if (handle == NULL) /* check handle */
2619  {
2620  return 2; /* return error */
2621  }
2622  if (handle->inited != 1) /* check handle initialization */
2623  {
2624  return 3; /* return error */
2625  }
2626 
2627  res = a_mfrc522_read(handle, MFRC522_REG_CONTROL, &prev, 1); /* read control */
2628  if (res != 0) /* check the result */
2629  {
2630  handle->debug_print("mfrc522: read control failed.\n"); /* read control failed */
2631 
2632  return 1; /* return error */
2633  }
2634  prev |= 1 << 6; /* set the start bit */
2635  res = a_mfrc522_write(handle, MFRC522_REG_CONTROL, &prev, 1); /* write control */
2636  if (res != 0) /* check the result */
2637  {
2638  handle->debug_print("mfrc522: write control failed.\n"); /* write control failed */
2639 
2640  return 1; /* return error */
2641  }
2642 
2643  return 0; /* success return 0 */
2644 }
2645 
2657 uint8_t mfrc522_get_rx_last_bits(mfrc522_handle_t *handle, uint8_t *bits)
2658 {
2659  uint8_t res;
2660  uint8_t prev;
2661 
2662  if (handle == NULL) /* check handle */
2663  {
2664  return 2; /* return error */
2665  }
2666  if (handle->inited != 1) /* check handle initialization */
2667  {
2668  return 3; /* return error */
2669  }
2670 
2671  res = a_mfrc522_read(handle, MFRC522_REG_CONTROL, &prev, 1); /* read control */
2672  if (res != 0) /* check the result */
2673  {
2674  handle->debug_print("mfrc522: read control failed.\n"); /* read control failed */
2675 
2676  return 1; /* return error */
2677  }
2678  *bits = prev & (0x7 << 0); /* set bits */
2679 
2680  return 0; /* success return 0 */
2681 }
2682 
2694 {
2695  uint8_t res;
2696  uint8_t prev;
2697 
2698  if (handle == NULL) /* check handle */
2699  {
2700  return 2; /* return error */
2701  }
2702  if (handle->inited != 1) /* check handle initialization */
2703  {
2704  return 3; /* return error */
2705  }
2706 
2707  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
2708  if (res != 0) /* check the result */
2709  {
2710  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
2711 
2712  return 1; /* return error */
2713  }
2714  prev &= ~(1 << 7); /* clear the settings */
2715  prev |= 1 << 7; /* set the start bit */
2716  res = a_mfrc522_write(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* write the bit framing */
2717  if (res != 0) /* check the result */
2718  {
2719  handle->debug_print("mfrc522: write bit framing failed.\n"); /* write the bit framing failed */
2720 
2721  return 1; /* return error */
2722  }
2723 
2724  return 0; /* success return 0 */
2725 }
2726 
2738 {
2739  uint8_t res;
2740  uint8_t prev;
2741 
2742  if (handle == NULL) /* check handle */
2743  {
2744  return 2; /* return error */
2745  }
2746  if (handle->inited != 1) /* check handle initialization */
2747  {
2748  return 3; /* return error */
2749  }
2750 
2751  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
2752  if (res != 0) /* check the result */
2753  {
2754  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
2755 
2756  return 1; /* return error */
2757  }
2758  prev &= ~(1 << 7); /* clear the settings */
2759  res = a_mfrc522_write(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* write the bit framing */
2760  if (res != 0) /* check the result */
2761  {
2762  handle->debug_print("mfrc522: write bit framing failed.\n"); /* write the bit framing failed */
2763 
2764  return 1; /* return error */
2765  }
2766 
2767  return 0; /* success return 0 */
2768 }
2769 
2781 uint8_t mfrc522_get_tx_last_bits(mfrc522_handle_t *handle, uint8_t *bits)
2782 {
2783  uint8_t res;
2784  uint8_t prev;
2785 
2786  if (handle == NULL) /* check handle */
2787  {
2788  return 2; /* return error */
2789  }
2790  if (handle->inited != 1) /* check handle initialization */
2791  {
2792  return 3; /* return error */
2793  }
2794 
2795  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
2796  if (res != 0) /* check the result */
2797  {
2798  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
2799 
2800  return 1; /* return error */
2801  }
2802  *bits = prev & (0x7 << 0); /* set bits */
2803 
2804  return 0; /* success return 0 */
2805 }
2806 
2819 uint8_t mfrc522_set_tx_last_bits(mfrc522_handle_t *handle, uint8_t bits)
2820 {
2821  uint8_t res;
2822  uint8_t prev;
2823 
2824  if (handle == NULL) /* check handle */
2825  {
2826  return 2; /* return error */
2827  }
2828  if (handle->inited != 1) /* check handle initialization */
2829  {
2830  return 3; /* return error */
2831  }
2832  if (bits > 7) /* check the length */
2833  {
2834  handle->debug_print("mfrc522: bits is over 7.\n"); /* bits are over 7 */
2835 
2836  return 4; /* return error */
2837  }
2838 
2839  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
2840  if (res != 0) /* check the result */
2841  {
2842  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
2843 
2844  return 1; /* return error */
2845  }
2846  prev &= ~(7 << 0); /* clear the settings */
2847  prev |= bits << 0; /* set the bits */
2848  res = a_mfrc522_write(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* write the bit framing */
2849  if (res != 0) /* check the result */
2850  {
2851  handle->debug_print("mfrc522: write bit framing failed.\n"); /* write the bit framing failed */
2852 
2853  return 1; /* return error */
2854  }
2855 
2856  return 0; /* success return 0 */
2857 }
2858 
2871 {
2872  uint8_t res;
2873  uint8_t prev;
2874 
2875  if (handle == NULL) /* check handle */
2876  {
2877  return 2; /* return error */
2878  }
2879  if (handle->inited != 1) /* check handle initialization */
2880  {
2881  return 3; /* return error */
2882  }
2883 
2884  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
2885  if (res != 0) /* check the result */
2886  {
2887  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
2888 
2889  return 1; /* return error */
2890  }
2891  prev &= ~(7 << 4); /* clear the settings */
2892  prev |= align << 4; /* set align */
2893  res = a_mfrc522_write(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* write the bit framing */
2894  if (res != 0) /* check the result */
2895  {
2896  handle->debug_print("mfrc522: write bit framing failed.\n"); /* write the bit framing failed */
2897 
2898  return 1; /* return error */
2899  }
2900 
2901  return 0; /* success return 0 */
2902 }
2903 
2916 {
2917  uint8_t res;
2918  uint8_t prev;
2919 
2920  if (handle == NULL) /* check handle */
2921  {
2922  return 2; /* return error */
2923  }
2924  if (handle->inited != 1) /* check handle initialization */
2925  {
2926  return 3; /* return error */
2927  }
2928 
2929  res = a_mfrc522_read(handle, MFRC522_REG_BIT_FRAMING, &prev, 1); /* read the bit framing */
2930  if (res != 0) /* check the result */
2931  {
2932  handle->debug_print("mfrc522: read bit framing failed.\n"); /* read the bit framing failed */
2933 
2934  return 1; /* return error */
2935  }
2936  *align = (mfrc522_rx_align_t)((prev >> 4) & 0x07); /* get align */
2937 
2938  return 0; /* success return 0 */
2939 }
2940 
2953 {
2954  uint8_t res;
2955  uint8_t prev;
2956 
2957  if (handle == NULL) /* check handle */
2958  {
2959  return 2; /* return error */
2960  }
2961  if (handle->inited != 1) /* check handle initialization */
2962  {
2963  return 3; /* return error */
2964  }
2965 
2966  res = a_mfrc522_read(handle, MFRC522_REG_COLL, &prev, 1); /* read coll */
2967  if (res != 0) /* check the result */
2968  {
2969  handle->debug_print("mfrc522: read coll failed.\n"); /* read coll failed */
2970 
2971  return 1; /* return error */
2972  }
2973  prev &= ~(1 << 7); /* clear the settings */
2974  prev |= (!enable) << 7; /* set the bool */
2975  res = a_mfrc522_write(handle, MFRC522_REG_COLL, &prev, 1); /* write coll */
2976  if (res != 0) /* check the result */
2977  {
2978  handle->debug_print("mfrc522: write coll failed.\n"); /* write coll failed */
2979 
2980  return 1; /* return error */
2981  }
2982 
2983  return 0; /* success return 0 */
2984 }
2985 
2998 {
2999  uint8_t res;
3000  uint8_t prev;
3001 
3002  if (handle == NULL) /* check handle */
3003  {
3004  return 2; /* return error */
3005  }
3006  if (handle->inited != 1) /* check handle initialization */
3007  {
3008  return 3; /* return error */
3009  }
3010 
3011  res = a_mfrc522_read(handle, MFRC522_REG_COLL, &prev, 1); /* read coll */
3012  if (res != 0) /* check the result */
3013  {
3014  handle->debug_print("mfrc522: read coll failed.\n"); /* read coll failed */
3015 
3016  return 1; /* return error */
3017  }
3018  *enable = (mfrc522_bool_t)(!((prev >> 7) & 0x01)); /* get the bool */
3019 
3020  return 0; /* success return 0 */
3021 }
3022 
3035 {
3036  uint8_t res;
3037  uint8_t prev;
3038 
3039  if (handle == NULL) /* check handle */
3040  {
3041  return 2; /* return error */
3042  }
3043  if (handle->inited != 1) /* check handle initialization */
3044  {
3045  return 3; /* return error */
3046  }
3047 
3048  res = a_mfrc522_read(handle, MFRC522_REG_COLL, &prev, 1); /* read coll */
3049  if (res != 0) /* check the result */
3050  {
3051  handle->debug_print("mfrc522: read coll failed.\n"); /* read coll failed */
3052 
3053  return 1; /* return error */
3054  }
3055  *enable = (mfrc522_bool_t)((prev >> 5) & 0x01); /* get the bool */
3056 
3057  return 0; /* success return 0 */
3058 }
3059 
3071 uint8_t mfrc522_get_collision_position(mfrc522_handle_t *handle, uint8_t *pos)
3072 {
3073  uint8_t res;
3074  uint8_t prev;
3075 
3076  if (handle == NULL) /* check handle */
3077  {
3078  return 2; /* return error */
3079  }
3080  if (handle->inited != 1) /* check handle initialization */
3081  {
3082  return 3; /* return error */
3083  }
3084 
3085  res = a_mfrc522_read(handle, MFRC522_REG_COLL, &prev, 1); /* read coll */
3086  if (res != 0) /* check the result */
3087  {
3088  handle->debug_print("mfrc522: read coll failed.\n"); /* read coll failed */
3089 
3090  return 1; /* return error */
3091  }
3092  *pos = prev & 0x1F; /* get the pos */
3093 
3094  return 0; /* success return 0 */
3095 }
3096 
3109 {
3110  uint8_t res;
3111  uint8_t prev;
3112 
3113  if (handle == NULL) /* check handle */
3114  {
3115  return 2; /* return error */
3116  }
3117  if (handle->inited != 1) /* check handle initialization */
3118  {
3119  return 3; /* return error */
3120  }
3121 
3122  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3123  if (res != 0) /* check the result */
3124  {
3125  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3126 
3127  return 1; /* return error */
3128  }
3129  prev &= ~(1 << 7); /* clear the settings */
3130  prev |= enable << 7; /* set the bool */
3131  res = a_mfrc522_write(handle, MFRC522_REG_MODE, &prev, 1); /* write mode */
3132  if (res != 0) /* check the result */
3133  {
3134  handle->debug_print("mfrc522: write mode failed.\n"); /* write mode failed */
3135 
3136  return 1; /* return error */
3137  }
3138 
3139  return 0; /* success return 0 */
3140 }
3141 
3154 {
3155  uint8_t res;
3156  uint8_t prev;
3157 
3158  if (handle == NULL) /* check handle */
3159  {
3160  return 2; /* return error */
3161  }
3162  if (handle->inited != 1) /* check handle initialization */
3163  {
3164  return 3; /* return error */
3165  }
3166 
3167  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3168  if (res != 0) /* check the result */
3169  {
3170  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3171 
3172  return 1; /* return error */
3173  }
3174  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
3175 
3176  return 0; /* success return 0 */
3177 }
3178 
3191 {
3192  uint8_t res;
3193  uint8_t prev;
3194 
3195  if (handle == NULL) /* check handle */
3196  {
3197  return 2; /* return error */
3198  }
3199  if (handle->inited != 1) /* check handle initialization */
3200  {
3201  return 3; /* return error */
3202  }
3203 
3204  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3205  if (res != 0) /* check the result */
3206  {
3207  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3208 
3209  return 1; /* return error */
3210  }
3211  prev &= ~(1 << 5); /* clear the settings */
3212  prev |= enable << 5; /* set the bool */
3213  res = a_mfrc522_write(handle, MFRC522_REG_MODE, &prev, 1); /* write mode */
3214  if (res != 0) /* check the result */
3215  {
3216  handle->debug_print("mfrc522: write mode failed.\n"); /* write mode failed */
3217 
3218  return 1; /* return error */
3219  }
3220 
3221  return 0; /* success return 0 */
3222 }
3223 
3236 {
3237  uint8_t res;
3238  uint8_t prev;
3239 
3240  if (handle == NULL) /* check handle */
3241  {
3242  return 2; /* return error */
3243  }
3244  if (handle->inited != 1) /* check handle initialization */
3245  {
3246  return 3; /* return error */
3247  }
3248 
3249  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3250  if (res != 0) /* check the result */
3251  {
3252  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3253 
3254  return 1; /* return error */
3255  }
3256  *enable = (mfrc522_bool_t)((prev >> 5) & 0x01); /* get the bool */
3257 
3258  return 0; /* success return 0 */
3259 }
3260 
3273 {
3274  uint8_t res;
3275  uint8_t prev;
3276 
3277  if (handle == NULL) /* check handle */
3278  {
3279  return 2; /* return error */
3280  }
3281  if (handle->inited != 1) /* check handle initialization */
3282  {
3283  return 3; /* return error */
3284  }
3285 
3286  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3287  if (res != 0) /* check the result */
3288  {
3289  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3290 
3291  return 1; /* return error */
3292  }
3293  prev &= ~(1 << 3); /* clear the settings */
3294  prev |= polarity << 3; /* set the polarity */
3295  res = a_mfrc522_write(handle, MFRC522_REG_MODE, &prev, 1); /* write mode */
3296  if (res != 0) /* check the result */
3297  {
3298  handle->debug_print("mfrc522: write mode failed.\n"); /* write mode failed */
3299 
3300  return 1; /* return error */
3301  }
3302 
3303  return 0; /* success return 0 */
3304 }
3305 
3318 {
3319  uint8_t res;
3320  uint8_t prev;
3321 
3322  if (handle == NULL) /* check handle */
3323  {
3324  return 2; /* return error */
3325  }
3326  if (handle->inited != 1) /* check handle initialization */
3327  {
3328  return 3; /* return error */
3329  }
3330 
3331  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3332  if (res != 0) /* check the result */
3333  {
3334  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3335 
3336  return 1; /* return error */
3337  }
3338  *polarity = (mfrc522_mfin_polarity_t)((prev >> 3) & 0x01); /* get the polarity */
3339 
3340  return 0; /* success return 0 */
3341 }
3342 
3355 {
3356  uint8_t res;
3357  uint8_t prev;
3358 
3359  if (handle == NULL) /* check handle */
3360  {
3361  return 2; /* return error */
3362  }
3363  if (handle->inited != 1) /* check handle initialization */
3364  {
3365  return 3; /* return error */
3366  }
3367 
3368  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3369  if (res != 0) /* check the result */
3370  {
3371  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3372 
3373  return 1; /* return error */
3374  }
3375  prev &= ~(3 << 0); /* clear the settings */
3376  prev |= preset << 0; /* set the preset */
3377  res = a_mfrc522_write(handle, MFRC522_REG_MODE, &prev, 1); /* write mode */
3378  if (res != 0) /* check the result */
3379  {
3380  handle->debug_print("mfrc522: write mode failed.\n"); /* write mode failed */
3381 
3382  return 1; /* return error */
3383  }
3384 
3385  return 0; /* success return 0 */
3386 }
3387 
3400 {
3401  uint8_t res;
3402  uint8_t prev;
3403 
3404  if (handle == NULL) /* check handle */
3405  {
3406  return 2; /* return error */
3407  }
3408  if (handle->inited != 1) /* check handle initialization */
3409  {
3410  return 3; /* return error */
3411  }
3412 
3413  res = a_mfrc522_read(handle, MFRC522_REG_MODE, &prev, 1); /* read mode */
3414  if (res != 0) /* check the result */
3415  {
3416  handle->debug_print("mfrc522: read mode failed.\n"); /* read mode failed */
3417 
3418  return 1; /* return error */
3419  }
3420  *preset = (mfrc522_crc_preset_t)(prev & 0x3); /* get the preset */
3421 
3422  return 0; /* success return 0 */
3423 }
3424 
3437 {
3438  uint8_t res;
3439  uint8_t prev;
3440 
3441  if (handle == NULL) /* check handle */
3442  {
3443  return 2; /* return error */
3444  }
3445  if (handle->inited != 1) /* check handle initialization */
3446  {
3447  return 3; /* return error */
3448  }
3449 
3450  res = a_mfrc522_read(handle, MFRC522_REG_TX_MODE, &prev, 1); /* read tx mode */
3451  if (res != 0) /* check the result */
3452  {
3453  handle->debug_print("mfrc522: read tx mode failed.\n"); /* read tx mode failed */
3454 
3455  return 1; /* return error */
3456  }
3457  prev &= ~(1 << 7); /* clear the settings */
3458  prev |= enable << 7; /* set the bool */
3459  res = a_mfrc522_write(handle, MFRC522_REG_TX_MODE, &prev, 1); /* write tx mode */
3460  if (res != 0) /* check the result */
3461  {
3462  handle->debug_print("mfrc522: write tx mode failed.\n"); /* write tx mode failed */
3463 
3464  return 1; /* return error */
3465  }
3466 
3467  return 0; /* success return 0 */
3468 }
3469 
3482 {
3483  uint8_t res;
3484  uint8_t prev;
3485 
3486  if (handle == NULL) /* check handle */
3487  {
3488  return 2; /* return error */
3489  }
3490  if (handle->inited != 1) /* check handle initialization */
3491  {
3492  return 3; /* return error */
3493  }
3494 
3495  res = a_mfrc522_read(handle, MFRC522_REG_TX_MODE, &prev, 1); /* read tx mode */
3496  if (res != 0) /* check the result */
3497  {
3498  handle->debug_print("mfrc522: read tx mode failed.\n"); /* read tx mode failed */
3499 
3500  return 1; /* return error */
3501  }
3502  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
3503 
3504  return 0; /* success return 0 */
3505 }
3506 
3519 {
3520  uint8_t res;
3521  uint8_t prev;
3522 
3523  if (handle == NULL) /* check handle */
3524  {
3525  return 2; /* return error */
3526  }
3527  if (handle->inited != 1) /* check handle initialization */
3528  {
3529  return 3; /* return error */
3530  }
3531 
3532  res = a_mfrc522_read(handle, MFRC522_REG_TX_MODE, &prev, 1); /* read tx mode */
3533  if (res != 0) /* check the result */
3534  {
3535  handle->debug_print("mfrc522: read tx mode failed.\n"); /* read tx mode failed */
3536 
3537  return 1; /* return error */
3538  }
3539  prev &= ~(7 << 4); /* clear the settings */
3540  prev |= speed << 4; /* set the speed */
3541  res = a_mfrc522_write(handle, MFRC522_REG_TX_MODE, &prev, 1); /* write tx mode */
3542  if (res != 0) /* check the result */
3543  {
3544  handle->debug_print("mfrc522: write tx mode failed.\n"); /* write tx mode failed */
3545 
3546  return 1; /* return error */
3547  }
3548 
3549  return 0; /* success return 0 */
3550 }
3551 
3564 {
3565  uint8_t res;
3566  uint8_t prev;
3567 
3568  if (handle == NULL) /* check handle */
3569  {
3570  return 2; /* return error */
3571  }
3572  if (handle->inited != 1) /* check handle initialization */
3573  {
3574  return 3; /* return error */
3575  }
3576 
3577  res = a_mfrc522_read(handle, MFRC522_REG_TX_MODE, &prev, 1); /* read tx mode */
3578  if (res != 0) /* check the result */
3579  {
3580  handle->debug_print("mfrc522: read tx mode failed.\n"); /* read tx mode failed */
3581 
3582  return 1; /* return error */
3583  }
3584  *speed = (mfrc522_speed_t)((prev >> 4) & 0x7); /* get the bool */
3585 
3586  return 0; /* success return 0 */
3587 }
3588 
3601 {
3602  uint8_t res;
3603  uint8_t prev;
3604 
3605  if (handle == NULL) /* check handle */
3606  {
3607  return 2; /* return error */
3608  }
3609  if (handle->inited != 1) /* check handle initialization */
3610  {
3611  return 3; /* return error */
3612  }
3613 
3614  res = a_mfrc522_read(handle, MFRC522_REG_TX_MODE, &prev, 1); /* read tx mode */
3615  if (res != 0) /* check the result */
3616  {
3617  handle->debug_print("mfrc522: read tx mode failed.\n"); /* read tx mode failed */
3618 
3619  return 1; /* return error */
3620  }
3621  prev &= ~(1 << 3); /* clear the settings */
3622  prev |= enable << 3; /* set the bool */
3623  res = a_mfrc522_write(handle, MFRC522_REG_TX_MODE, &prev, 1); /* write tx mode */
3624  if (res != 0) /* check the result */
3625  {
3626  handle->debug_print("mfrc522: write tx mode failed.\n"); /* write tx mode failed */
3627 
3628  return 1; /* return error */
3629  }
3630 
3631  return 0; /* success return 0 */
3632 }
3633 
3646 {
3647  uint8_t res;
3648  uint8_t prev;
3649 
3650  if (handle == NULL) /* check handle */
3651  {
3652  return 2; /* return error */
3653  }
3654  if (handle->inited != 1) /* check handle initialization */
3655  {
3656  return 3; /* return error */
3657  }
3658 
3659  res = a_mfrc522_read(handle, MFRC522_REG_TX_MODE, &prev, 1); /* read tx mode */
3660  if (res != 0) /* check the result */
3661  {
3662  handle->debug_print("mfrc522: read tx mode failed.\n"); /* read tx mode failed */
3663 
3664  return 1; /* return error */
3665  }
3666  *enable = (mfrc522_bool_t)((prev >> 3) & 0x01); /* get the bool */
3667 
3668  return 0; /* success return 0 */
3669 }
3670 
3683 {
3684  uint8_t res;
3685  uint8_t prev;
3686 
3687  if (handle == NULL) /* check handle */
3688  {
3689  return 2; /* return error */
3690  }
3691  if (handle->inited != 1) /* check handle initialization */
3692  {
3693  return 3; /* return error */
3694  }
3695 
3696  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3697  if (res != 0) /* check the result */
3698  {
3699  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3700 
3701  return 1; /* return error */
3702  }
3703  prev &= ~(1 << 7); /* clear the settings */
3704  prev |= enable << 7; /* set the bool */
3705  res = a_mfrc522_write(handle, MFRC522_REG_RX_MODE, &prev, 1); /* write rx mode */
3706  if (res != 0) /* check the result */
3707  {
3708  handle->debug_print("mfrc522: write rx mode failed.\n"); /* write rx mode failed */
3709 
3710  return 1; /* return error */
3711  }
3712 
3713  return 0; /* success return 0 */
3714 }
3715 
3728 {
3729  uint8_t res;
3730  uint8_t prev;
3731 
3732  if (handle == NULL) /* check handle */
3733  {
3734  return 2; /* return error */
3735  }
3736  if (handle->inited != 1) /* check handle initialization */
3737  {
3738  return 3; /* return error */
3739  }
3740 
3741  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3742  if (res != 0) /* check the result */
3743  {
3744  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3745 
3746  return 1; /* return error */
3747  }
3748  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
3749 
3750  return 0; /* success return 0 */
3751 }
3752 
3765 {
3766  uint8_t res;
3767  uint8_t prev;
3768 
3769  if (handle == NULL) /* check handle */
3770  {
3771  return 2; /* return error */
3772  }
3773  if (handle->inited != 1) /* check handle initialization */
3774  {
3775  return 3; /* return error */
3776  }
3777 
3778  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3779  if (res != 0) /* check the result */
3780  {
3781  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3782 
3783  return 1; /* return error */
3784  }
3785  prev &= ~(7 << 4); /* clear the settings */
3786  prev |= speed << 4; /* set the speed */
3787  res = a_mfrc522_write(handle, MFRC522_REG_RX_MODE, &prev, 1); /* write rx mode */
3788  if (res != 0) /* check the result */
3789  {
3790  handle->debug_print("mfrc522: write rx mode failed.\n"); /* write rx mode failed */
3791 
3792  return 1; /* return error */
3793  }
3794 
3795  return 0; /* success return 0 */
3796 }
3797 
3810 {
3811  uint8_t res;
3812  uint8_t prev;
3813 
3814  if (handle == NULL) /* check handle */
3815  {
3816  return 2; /* return error */
3817  }
3818  if (handle->inited != 1) /* check handle initialization */
3819  {
3820  return 3; /* return error */
3821  }
3822 
3823  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3824  if (res != 0) /* check the result */
3825  {
3826  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3827 
3828  return 1; /* return error */
3829  }
3830  *speed = (mfrc522_speed_t)((prev >> 4) & 0x07); /* get the speed */
3831 
3832  return 0; /* success return 0 */
3833 }
3834 
3847 {
3848  uint8_t res;
3849  uint8_t prev;
3850 
3851  if (handle == NULL) /* check handle */
3852  {
3853  return 2; /* return error */
3854  }
3855  if (handle->inited != 1) /* check handle initialization */
3856  {
3857  return 3; /* return error */
3858  }
3859 
3860  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3861  if (res != 0) /* check the result */
3862  {
3863  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3864 
3865  return 1; /* return error */
3866  }
3867  prev &= ~(1 << 3); /* clear the settings */
3868  prev |= enable << 3; /* set the bool */
3869  res = a_mfrc522_write(handle, MFRC522_REG_RX_MODE, &prev, 1); /* write rx mode */
3870  if (res != 0) /* check the result */
3871  {
3872  handle->debug_print("mfrc522: write rx mode failed.\n"); /* write rx mode failed */
3873 
3874  return 1; /* return error */
3875  }
3876 
3877  return 0; /* success return 0 */
3878 }
3879 
3892 {
3893  uint8_t res;
3894  uint8_t prev;
3895 
3896  if (handle == NULL) /* check handle */
3897  {
3898  return 2; /* return error */
3899  }
3900  if (handle->inited != 1) /* check handle initialization */
3901  {
3902  return 3; /* return error */
3903  }
3904 
3905  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3906  if (res != 0) /* check the result */
3907  {
3908  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3909 
3910  return 1; /* return error */
3911  }
3912  *enable = (mfrc522_bool_t)((prev >> 3) & 0x01); /* get the bool */
3913 
3914  return 0; /* success return 0 */
3915 }
3916 
3929 {
3930  uint8_t res;
3931  uint8_t prev;
3932 
3933  if (handle == NULL) /* check handle */
3934  {
3935  return 2; /* return error */
3936  }
3937  if (handle->inited != 1) /* check handle initialization */
3938  {
3939  return 3; /* return error */
3940  }
3941 
3942  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3943  if (res != 0) /* check the result */
3944  {
3945  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3946 
3947  return 1; /* return error */
3948  }
3949  prev &= ~(1 << 2); /* clear the settings */
3950  prev |= enable << 2; /* set the bool */
3951  res = a_mfrc522_write(handle, MFRC522_REG_RX_MODE, &prev, 1); /* write rx mode */
3952  if (res != 0) /* check the result */
3953  {
3954  handle->debug_print("mfrc522: write rx mode failed.\n"); /* write rx mode failed */
3955 
3956  return 1; /* return error */
3957  }
3958 
3959  return 0; /* success return 0 */
3960 }
3961 
3974 {
3975  uint8_t res;
3976  uint8_t prev;
3977 
3978  if (handle == NULL) /* check handle */
3979  {
3980  return 2; /* return error */
3981  }
3982  if (handle->inited != 1) /* check handle initialization */
3983  {
3984  return 3; /* return error */
3985  }
3986 
3987  res = a_mfrc522_read(handle, MFRC522_REG_RX_MODE, &prev, 1); /* read rx mode */
3988  if (res != 0) /* check the result */
3989  {
3990  handle->debug_print("mfrc522: read rx mode failed.\n"); /* read rx mode failed */
3991 
3992  return 1; /* return error */
3993  }
3994  *enable = (mfrc522_bool_t)((prev >> 2) & 0x01); /* get the bool */
3995 
3996  return 0; /* success return 0 */
3997 }
3998 
4012 {
4013  uint8_t res;
4014  uint8_t prev;
4015 
4016  if (handle == NULL) /* check handle */
4017  {
4018  return 2; /* return error */
4019  }
4020  if (handle->inited != 1) /* check handle initialization */
4021  {
4022  return 3; /* return error */
4023  }
4024 
4025  res = a_mfrc522_read(handle, MFRC522_REG_TX_CONTROL, &prev, 1); /* read tx control */
4026  if (res != 0) /* check the result */
4027  {
4028  handle->debug_print("mfrc522: read tx control failed.\n"); /* read tx control failed */
4029 
4030  return 1; /* return error */
4031  }
4032  prev &= ~(1 << driver); /* clear the settings */
4033  prev |= enable << driver; /* set the driver */
4034  res = a_mfrc522_write(handle, MFRC522_REG_TX_CONTROL, &prev, 1); /* write tx control */
4035  if (res != 0) /* check the result */
4036  {
4037  handle->debug_print("mfrc522: write tx control failed.\n"); /* write tx control failed */
4038 
4039  return 1; /* return error */
4040  }
4041 
4042  return 0; /* success return 0 */
4043 }
4044 
4058 {
4059  uint8_t res;
4060  uint8_t prev;
4061 
4062  if (handle == NULL) /* check handle */
4063  {
4064  return 2; /* return error */
4065  }
4066  if (handle->inited != 1) /* check handle initialization */
4067  {
4068  return 3; /* return error */
4069  }
4070 
4071  res = a_mfrc522_read(handle, MFRC522_REG_TX_CONTROL, &prev, 1); /* read tx control */
4072  if (res != 0) /* check the result */
4073  {
4074  handle->debug_print("mfrc522: read tx control failed.\n"); /* read tx control failed */
4075 
4076  return 1; /* return error */
4077  }
4078  *enable = (mfrc522_bool_t)((prev >> driver) & 0x01); /* get the bool */
4079 
4080  return 0; /* success return 0 */
4081 }
4082 
4095 {
4096  uint8_t res;
4097  uint8_t prev;
4098 
4099  if (handle == NULL) /* check handle */
4100  {
4101  return 2; /* return error */
4102  }
4103  if (handle->inited != 1) /* check handle initialization */
4104  {
4105  return 3; /* return error */
4106  }
4107 
4108  res = a_mfrc522_read(handle, MFRC522_REG_TX_ASK, &prev, 1); /* read tx ask */
4109  if (res != 0) /* check the result */
4110  {
4111  handle->debug_print("mfrc522: read tx ask failed.\n"); /* read tx ask failed */
4112 
4113  return 1; /* return error */
4114  }
4115  prev &= ~(1 << 6); /* clear the settings */
4116  prev |= enable << 6; /* set the bool */
4117  res = a_mfrc522_write(handle, MFRC522_REG_TX_ASK, &prev, 1); /* write tx ask */
4118  if (res != 0) /* check the result */
4119  {
4120  handle->debug_print("mfrc522: write tx ask failed.\n"); /* write tx ask failed */
4121 
4122  return 1; /* return error */
4123  }
4124 
4125  return 0; /* success return 0 */
4126 }
4127 
4140 {
4141  uint8_t res;
4142  uint8_t prev;
4143 
4144  if (handle == NULL) /* check handle */
4145  {
4146  return 2; /* return error */
4147  }
4148  if (handle->inited != 1) /* check handle initialization */
4149  {
4150  return 3; /* return error */
4151  }
4152 
4153  res = a_mfrc522_read(handle, MFRC522_REG_TX_ASK, &prev, 1); /* read tx ask */
4154  if (res != 0) /* check the result */
4155  {
4156  handle->debug_print("mfrc522: read tx ask failed.\n"); /* read tx ask failed */
4157 
4158  return 1; /* return error */
4159  }
4160  *enable = (mfrc522_bool_t)((prev >> 6) & 0x1); /* get the bool */
4161 
4162  return 0; /* success return 0 */
4163 }
4164 
4177 {
4178  uint8_t res;
4179  uint8_t prev;
4180 
4181  if (handle == NULL) /* check handle */
4182  {
4183  return 2; /* return error */
4184  }
4185  if (handle->inited != 1) /* check handle initialization */
4186  {
4187  return 3; /* return error */
4188  }
4189 
4190  res = a_mfrc522_read(handle, MFRC522_REG_TX_SEL, &prev, 1); /* read tx sel */
4191  if (res != 0) /* check the result */
4192  {
4193  handle->debug_print("mfrc522: read tx sel failed.\n"); /* read tx sel failed */
4194 
4195  return 1; /* return error */
4196  }
4197  prev &= ~(3 << 4); /* clear the settings */
4198  prev |= input << 4; /* set the input */
4199  res = a_mfrc522_write(handle, MFRC522_REG_TX_SEL, &prev, 1); /* write tx sel */
4200  if (res != 0) /* check the result */
4201  {
4202  handle->debug_print("mfrc522: write tx sel failed.\n"); /* write tx sel failed */
4203 
4204  return 1; /* return error */
4205  }
4206 
4207  return 0; /* success return 0 */
4208 }
4209 
4222 {
4223  uint8_t res;
4224  uint8_t prev;
4225 
4226  if (handle == NULL) /* check handle */
4227  {
4228  return 2; /* return error */
4229  }
4230  if (handle->inited != 1) /* check handle initialization */
4231  {
4232  return 3; /* return error */
4233  }
4234 
4235  res = a_mfrc522_read(handle, MFRC522_REG_TX_SEL, &prev, 1); /* read tx sel */
4236  if (res != 0) /* check the result */
4237  {
4238  handle->debug_print("mfrc522: read tx sel failed.\n"); /* read tx sel failed */
4239 
4240  return 1; /* return error */
4241  }
4242  *input = (mfrc522_tx_input_t)((prev >> 4) & 0x3); /* get the input */
4243 
4244  return 0; /* success return 0 */
4245 }
4246 
4259 {
4260  uint8_t res;
4261  uint8_t prev;
4262 
4263  if (handle == NULL) /* check handle */
4264  {
4265  return 2; /* return error */
4266  }
4267  if (handle->inited != 1) /* check handle initialization */
4268  {
4269  return 3; /* return error */
4270  }
4271 
4272  res = a_mfrc522_read(handle, MFRC522_REG_TX_SEL, &prev, 1); /* read tx sel */
4273  if (res != 0) /* check the result */
4274  {
4275  handle->debug_print("mfrc522: read tx sel failed.\n"); /* read tx sel failed */
4276 
4277  return 1; /* return error */
4278  }
4279  prev &= ~(0xF << 0); /* clear the settings */
4280  prev |= input << 0; /* set the input */
4281  res = a_mfrc522_write(handle, MFRC522_REG_TX_SEL, &prev, 1); /* write tx sel */
4282  if (res != 0) /* check the result */
4283  {
4284  handle->debug_print("mfrc522: write tx sel failed.\n"); /* write tx sel failed */
4285 
4286  return 1; /* return error */
4287  }
4288 
4289  return 0; /* success return 0 */
4290 }
4291 
4304 {
4305  uint8_t res;
4306  uint8_t prev;
4307 
4308  if (handle == NULL) /* check handle */
4309  {
4310  return 2; /* return error */
4311  }
4312  if (handle->inited != 1) /* check handle initialization */
4313  {
4314  return 3; /* return error */
4315  }
4316 
4317  res = a_mfrc522_read(handle, MFRC522_REG_TX_SEL, &prev, 1); /* read tx sel */
4318  if (res != 0) /* check the result */
4319  {
4320  handle->debug_print("mfrc522: read tx sel failed.\n"); /* read tx sel failed */
4321 
4322  return 1; /* return error */
4323  }
4324  *input = (mfrc522_mfout_input_t)(prev & 0x0F); /* get the input */
4325 
4326  return 0; /* success return 0 */
4327 }
4328 
4341 {
4342  uint8_t res;
4343  uint8_t prev;
4344 
4345  if (handle == NULL) /* check handle */
4346  {
4347  return 2; /* return error */
4348  }
4349  if (handle->inited != 1) /* check handle initialization */
4350  {
4351  return 3; /* return error */
4352  }
4353 
4354  res = a_mfrc522_read(handle, MFRC522_REG_RX_SEL, &prev, 1); /* read rx sel */
4355  if (res != 0) /* check the result */
4356  {
4357  handle->debug_print("mfrc522: read rx sel failed.\n"); /* read rx sel failed */
4358 
4359  return 1; /* return error */
4360  }
4361  prev &= ~(3 << 6); /* clear the settings */
4362  prev |= input << 6; /* set the input */
4363  res = a_mfrc522_write(handle, MFRC522_REG_RX_SEL, &prev, 1); /* write rx sel */
4364  if (res != 0) /* check the result */
4365  {
4366  handle->debug_print("mfrc522: write rx sel failed.\n"); /* write rx sel failed */
4367 
4368  return 1; /* return error */
4369  }
4370 
4371  return 0; /* success return 0 */
4372 }
4373 
4386 {
4387  uint8_t res;
4388  uint8_t prev;
4389 
4390  if (handle == NULL) /* check handle */
4391  {
4392  return 2; /* return error */
4393  }
4394  if (handle->inited != 1) /* check handle initialization */
4395  {
4396  return 3; /* return error */
4397  }
4398 
4399  res = a_mfrc522_read(handle, MFRC522_REG_RX_SEL, &prev, 1); /* read rx sel */
4400  if (res != 0) /* check the result */
4401  {
4402  handle->debug_print("mfrc522: read rx sel failed.\n"); /* read rx sel failed */
4403 
4404  return 1; /* return error */
4405  }
4406  *input = (mfrc522_contactless_uart_input_t)((prev >> 6) & 0x3); /* get th input */
4407 
4408  return 0; /* success return 0 */
4409 }
4410 
4423 uint8_t mfrc522_set_rx_wait(mfrc522_handle_t *handle, uint8_t t)
4424 {
4425  uint8_t res;
4426  uint8_t prev;
4427 
4428  if (handle == NULL) /* check handle */
4429  {
4430  return 2; /* return error */
4431  }
4432  if (handle->inited != 1) /* check handle initialization */
4433  {
4434  return 3; /* return error */
4435  }
4436  if (t > 0x3F) /* check t */
4437  {
4438  handle->debug_print("mfrc522: t is over 0x3F.\n"); /* t is over 0x3F */
4439 
4440  return 4; /* return error */
4441  }
4442 
4443  res = a_mfrc522_read(handle, MFRC522_REG_RX_SEL, &prev, 1); /* read rx sel */
4444  if (res != 0) /* check the result */
4445  {
4446  handle->debug_print("mfrc522: read rx sel failed.\n"); /* read rx sel failed */
4447 
4448  return 1; /* return error */
4449  }
4450  prev &= ~(0x3F << 0); /* clear the settings */
4451  prev |= t << 0; /* set the input */
4452  res = a_mfrc522_write(handle, MFRC522_REG_RX_SEL, &prev, 1); /* write rx sel */
4453  if (res != 0) /* check the result */
4454  {
4455  handle->debug_print("mfrc522: write rx sel failed.\n"); /* write rx sel failed */
4456 
4457  return 1; /* return error */
4458  }
4459 
4460  return 0; /* success return 0 */
4461 }
4462 
4474 uint8_t mfrc522_get_rx_wait(mfrc522_handle_t *handle, uint8_t *t)
4475 {
4476  uint8_t res;
4477  uint8_t prev;
4478 
4479  if (handle == NULL) /* check handle */
4480  {
4481  return 2; /* return error */
4482  }
4483  if (handle->inited != 1) /* check handle initialization */
4484  {
4485  return 3; /* return error */
4486  }
4487 
4488  res = a_mfrc522_read(handle, MFRC522_REG_RX_SEL, &prev, 1); /* read rx sel */
4489  if (res != 0) /* check the result */
4490  {
4491  handle->debug_print("mfrc522: read rx sel failed.\n"); /* read rx sel failed */
4492 
4493  return 1; /* return error */
4494  }
4495  *t = prev & 0x3F; /* get the rx wait */
4496 
4497  return 0; /* success return 0 */
4498 }
4499 
4512 uint8_t mfrc522_set_min_level(mfrc522_handle_t *handle, uint8_t level)
4513 {
4514  uint8_t res;
4515  uint8_t prev;
4516 
4517  if (handle == NULL) /* check handle */
4518  {
4519  return 2; /* return error */
4520  }
4521  if (handle->inited != 1) /* check handle initialization */
4522  {
4523  return 3; /* return error */
4524  }
4525  if (level > 0xF) /* check the level */
4526  {
4527  handle->debug_print("mfrc522: level is over 0xF.\n"); /* level is over 0xF */
4528 
4529  return 4; /* return error */
4530  }
4531 
4532  res = a_mfrc522_read(handle, MFRC522_REG_RX_THRESHOLD, &prev, 1); /* read rx threshold */
4533  if (res != 0) /* check the result */
4534  {
4535  handle->debug_print("mfrc522: read rx threshold failed.\n"); /* read rx threshold failed */
4536 
4537  return 1; /* return error */
4538  }
4539  prev &= ~(0xF << 4); /* clear the settings */
4540  prev |= level << 4; /* set the level */
4541  res = a_mfrc522_write(handle, MFRC522_REG_RX_THRESHOLD, &prev, 1); /* write rx threshold */
4542  if (res != 0) /* check the result */
4543  {
4544  handle->debug_print("mfrc522: write rx threshold failed.\n"); /* write rx threshold failed */
4545 
4546  return 1; /* return error */
4547  }
4548 
4549  return 0; /* success return 0 */
4550 }
4551 
4563 uint8_t mfrc522_get_min_level(mfrc522_handle_t *handle, uint8_t *level)
4564 {
4565  uint8_t res;
4566  uint8_t prev;
4567 
4568  if (handle == NULL) /* check handle */
4569  {
4570  return 2; /* return error */
4571  }
4572  if (handle->inited != 1) /* check handle initialization */
4573  {
4574  return 3; /* return error */
4575  }
4576 
4577  res = a_mfrc522_read(handle, MFRC522_REG_RX_THRESHOLD, &prev, 1); /* read rx threshold */
4578  if (res != 0) /* check the result */
4579  {
4580  handle->debug_print("mfrc522: read rx threshold failed.\n"); /* read rx threshold failed */
4581 
4582  return 1; /* return error */
4583  }
4584  *level = (prev >> 4) & 0xF; /* get the level */
4585 
4586  return 0; /* success return 0 */
4587 }
4588 
4601 uint8_t mfrc522_set_collision_level(mfrc522_handle_t *handle, uint8_t level)
4602 {
4603  uint8_t res;
4604  uint8_t prev;
4605 
4606  if (handle == NULL) /* check handle */
4607  {
4608  return 2; /* return error */
4609  }
4610  if (handle->inited != 1) /* check handle initialization */
4611  {
4612  return 3; /* return error */
4613  }
4614  if (level > 7) /* check the level */
4615  {
4616  handle->debug_print("mfrc522: level is over 7.\n"); /* level is over 7 */
4617 
4618  return 4; /* return error */
4619  }
4620 
4621  res = a_mfrc522_read(handle, MFRC522_REG_RX_THRESHOLD, &prev, 1); /* read rx threshold */
4622  if (res != 0) /* check the result */
4623  {
4624  handle->debug_print("mfrc522: read rx threshold failed.\n"); /* read rx threshold failed */
4625 
4626  return 1; /* return error */
4627  }
4628  prev &= ~(0x7 << 0); /* clear the settings */
4629  prev |= level << 0; /* set the level */
4630  res = a_mfrc522_write(handle, MFRC522_REG_RX_THRESHOLD, &prev, 1); /* write rx threshold */
4631  if (res != 0) /* check the result */
4632  {
4633  handle->debug_print("mfrc522: write rx threshold failed.\n"); /* write rx threshold failed */
4634 
4635  return 1; /* return error */
4636  }
4637 
4638  return 0; /* success return 0 */
4639 }
4640 
4652 uint8_t mfrc522_get_collision_level(mfrc522_handle_t *handle, uint8_t *level)
4653 {
4654  uint8_t res;
4655  uint8_t prev;
4656 
4657  if (handle == NULL) /* check handle */
4658  {
4659  return 2; /* return error */
4660  }
4661  if (handle->inited != 1) /* check handle initialization */
4662  {
4663  return 3; /* return error */
4664  }
4665 
4666  res = a_mfrc522_read(handle, MFRC522_REG_RX_THRESHOLD, &prev, 1); /* read rx threshold */
4667  if (res != 0) /* check the result */
4668  {
4669  handle->debug_print("mfrc522: read rx threshold failed.\n"); /* read rx threshold failed */
4670 
4671  return 1; /* return error */
4672  }
4673  *level = prev & 0x07; /* get the level */
4674 
4675  return 0; /* success return 0 */
4676 }
4677 
4690 {
4691  uint8_t res;
4692  uint8_t prev;
4693 
4694  if (handle == NULL) /* check handle */
4695  {
4696  return 2; /* return error */
4697  }
4698  if (handle->inited != 1) /* check handle initialization */
4699  {
4700  return 3; /* return error */
4701  }
4702 
4703  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
4704  if (res != 0) /* check the result */
4705  {
4706  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
4707 
4708  return 1; /* return error */
4709  }
4710  prev &= ~(0x3 << 6); /* clear the settings */
4711  prev |= reception << 6; /* set the reception */
4712  res = a_mfrc522_write(handle, MFRC522_REG_DEMOD, &prev, 1); /* write demod */
4713  if (res != 0) /* check the result */
4714  {
4715  handle->debug_print("mfrc522: write demod failed.\n"); /* write demod failed */
4716 
4717  return 1; /* return error */
4718  }
4719 
4720  return 0; /* success return 0 */
4721 }
4722 
4735 {
4736  uint8_t res;
4737  uint8_t prev;
4738 
4739  if (handle == NULL) /* check handle */
4740  {
4741  return 2; /* return error */
4742  }
4743  if (handle->inited != 1) /* check handle initialization */
4744  {
4745  return 3; /* return error */
4746  }
4747 
4748  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
4749  if (res != 0) /* check the result */
4750  {
4751  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
4752 
4753  return 1; /* return error */
4754  }
4755  *reception = (mfrc522_channel_reception_t)((prev >> 6) & 0x03); /* get the reception */
4756 
4757  return 0; /* success return 0 */
4758 }
4759 
4772 {
4773  uint8_t res;
4774  uint8_t prev;
4775 
4776  if (handle == NULL) /* check handle */
4777  {
4778  return 2; /* return error */
4779  }
4780  if (handle->inited != 1) /* check handle initialization */
4781  {
4782  return 3; /* return error */
4783  }
4784 
4785  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
4786  if (res != 0) /* check the result */
4787  {
4788  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
4789 
4790  return 1; /* return error */
4791  }
4792  prev &= ~(1 << 5); /* clear the settings */
4793  prev |= enable << 5; /* set the bool */
4794  res = a_mfrc522_write(handle, MFRC522_REG_DEMOD, &prev, 1); /* write demod */
4795  if (res != 0) /* check the result */
4796  {
4797  handle->debug_print("mfrc522: write demod failed.\n"); /* write demod failed */
4798 
4799  return 1; /* return error */
4800  }
4801 
4802  return 0; /* success return 0 */
4803 }
4804 
4817 {
4818  uint8_t res;
4819  uint8_t prev;
4820 
4821  if (handle == NULL) /* check handle */
4822  {
4823  return 2; /* return error */
4824  }
4825  if (handle->inited != 1) /* check handle initialization */
4826  {
4827  return 3; /* return error */
4828  }
4829 
4830  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
4831  if (res != 0) /* check the result */
4832  {
4833  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
4834 
4835  return 1; /* return error */
4836  }
4837  *enable = (mfrc522_bool_t)((prev >> 5) & 0x01); /* set the bool */
4838 
4839  return 0; /* success return 0 */
4840 }
4841 
4854 {
4855  uint8_t res;
4856  uint8_t prev;
4857 
4858  if (handle == NULL) /* check handle */
4859  {
4860  return 2; /* return error */
4861  }
4862  if (handle->inited != 1) /* check handle initialization */
4863  {
4864  return 3; /* return error */
4865  }
4866 
4867  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
4868  if (res != 0) /* check the result */
4869  {
4870  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
4871 
4872  return 1; /* return error */
4873  }
4874  prev &= ~(1 << 4); /* clear the settings */
4875  prev |= enable << 4; /* set the bool */
4876  res = a_mfrc522_write(handle, MFRC522_REG_DEMOD, &prev, 1); /* write demod */
4877  if (res != 0) /* check the result */
4878  {
4879  handle->debug_print("mfrc522: write demod failed.\n"); /* write demod failed */
4880 
4881  return 1; /* return error */
4882  }
4883 
4884  return 0; /* success return 0 */
4885 }
4886 
4899 {
4900  uint8_t res;
4901  uint8_t prev;
4902 
4903  if (handle == NULL) /* check handle */
4904  {
4905  return 2; /* return error */
4906  }
4907  if (handle->inited != 1) /* check handle initialization */
4908  {
4909  return 3; /* return error */
4910  }
4911 
4912  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
4913  if (res != 0) /* check the result */
4914  {
4915  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
4916 
4917  return 1; /* return error */
4918  }
4919  *enable = (mfrc522_bool_t)((prev >> 4) & 0x01); /* get the bool */
4920 
4921  return 0; /* success return 0 */
4922 }
4923 
4937 {
4938  uint8_t res;
4939  uint8_t prev;
4940 
4941  if (handle == NULL) /* check handle */
4942  {
4943  return 2; /* return error */
4944  }
4945  if (handle->inited != 1) /* check handle initialization */
4946  {
4947  return 3; /* return error */
4948  }
4949  if (t > 3) /* check the t */
4950  {
4951  handle->debug_print("mfrc522: t is over 3.\n"); /* t is over 3 */
4952 
4953  return 4; /* return error */
4954  }
4955 
4956  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
4957  if (res != 0) /* check the result */
4958  {
4959  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
4960 
4961  return 1; /* return error */
4962  }
4963  prev &= ~(3 << 2); /* clear the settings */
4964  prev |= t << 2; /* set the pll */
4965  res = a_mfrc522_write(handle, MFRC522_REG_DEMOD, &prev, 1); /* write demod */
4966  if (res != 0) /* check the result */
4967  {
4968  handle->debug_print("mfrc522: write demod failed.\n"); /* write demod failed */
4969 
4970  return 1; /* return error */
4971  }
4972 
4973  return 0; /* success return 0 */
4974 }
4975 
4988 {
4989  uint8_t res;
4990  uint8_t prev;
4991 
4992  if (handle == NULL) /* check handle */
4993  {
4994  return 2; /* return error */
4995  }
4996  if (handle->inited != 1) /* check handle initialization */
4997  {
4998  return 3; /* return error */
4999  }
5000 
5001  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
5002  if (res != 0) /* check the result */
5003  {
5004  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
5005 
5006  return 1; /* return error */
5007  }
5008  *t = (prev >> 2) & 0x3; /* get the pll */
5009 
5010  return 0; /* success return 0 */
5011 }
5012 
5026 {
5027  uint8_t res;
5028  uint8_t prev;
5029 
5030  if (handle == NULL) /* check handle */
5031  {
5032  return 2; /* return error */
5033  }
5034  if (handle->inited != 1) /* check handle initialization */
5035  {
5036  return 3; /* return error */
5037  }
5038  if (t > 3) /* check the t */
5039  {
5040  handle->debug_print("mfrc522: t is over 3.\n"); /* t is over 3 */
5041 
5042  return 4; /* return error */
5043  }
5044 
5045  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
5046  if (res != 0) /* check the result */
5047  {
5048  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
5049 
5050  return 1; /* return error */
5051  }
5052  prev &= ~(3 << 0); /* clear the settings */
5053  prev |= t << 0; /* set the pll */
5054  res = a_mfrc522_write(handle, MFRC522_REG_DEMOD, &prev, 1); /* write demod */
5055  if (res != 0) /* check the result */
5056  {
5057  handle->debug_print("mfrc522: write demod failed.\n"); /* write demod failed */
5058 
5059  return 1; /* return error */
5060  }
5061 
5062  return 0; /* success return 0 */
5063 }
5064 
5077 {
5078  uint8_t res;
5079  uint8_t prev;
5080 
5081  if (handle == NULL) /* check handle */
5082  {
5083  return 2; /* return error */
5084  }
5085  if (handle->inited != 1) /* check handle initialization */
5086  {
5087  return 3; /* return error */
5088  }
5089 
5090  res = a_mfrc522_read(handle, MFRC522_REG_DEMOD, &prev, 1); /* read demod */
5091  if (res != 0) /* check the result */
5092  {
5093  handle->debug_print("mfrc522: read demod failed.\n"); /* read demod failed */
5094 
5095  return 1; /* return error */
5096  }
5097  *t = (prev >> 0) & 0x3; /* get the pll */
5098 
5099  return 0; /* success return 0 */
5100 }
5101 
5114 uint8_t mfrc522_set_tx_wait(mfrc522_handle_t *handle, uint8_t t)
5115 {
5116  uint8_t res;
5117  uint8_t prev;
5118 
5119  if (handle == NULL) /* check handle */
5120  {
5121  return 2; /* return error */
5122  }
5123  if (handle->inited != 1) /* check handle initialization */
5124  {
5125  return 3; /* return error */
5126  }
5127  if (t > 3) /* check the t */
5128  {
5129  handle->debug_print("mfrc522: t is over 3.\n"); /* t is over 3 */
5130 
5131  return 4; /* return error */
5132  }
5133 
5134  res = a_mfrc522_read(handle, MFRC522_REG_MFTX, &prev, 1); /* read mftx */
5135  if (res != 0) /* check the result */
5136  {
5137  handle->debug_print("mfrc522: read mftx failed.\n"); /* read mftx failed */
5138 
5139  return 1; /* return error */
5140  }
5141  prev &= ~(3 << 0); /* clear the settings */
5142  prev |= t << 0; /* set the wait */
5143  res = a_mfrc522_write(handle, MFRC522_REG_MFTX, &prev, 1); /* write mftx */
5144  if (res != 0) /* check the result */
5145  {
5146  handle->debug_print("mfrc522: write mftx failed.\n"); /* write mftx failed */
5147 
5148  return 1; /* return error */
5149  }
5150 
5151  return 0; /* success return 0 */
5152 }
5153 
5165 uint8_t mfrc522_get_tx_wait(mfrc522_handle_t *handle, uint8_t *t)
5166 {
5167  uint8_t res;
5168  uint8_t prev;
5169 
5170  if (handle == NULL) /* check handle */
5171  {
5172  return 2; /* return error */
5173  }
5174  if (handle->inited != 1) /* check handle initialization */
5175  {
5176  return 3; /* return error */
5177  }
5178 
5179  res = a_mfrc522_read(handle, MFRC522_REG_MFTX, &prev, 1); /* read mftx */
5180  if (res != 0) /* check the result */
5181  {
5182  handle->debug_print("mfrc522: read mftx failed.\n"); /* read mftx failed */
5183 
5184  return 1; /* return error */
5185  }
5186  *t = prev & 0x03; /* set the wait */
5187 
5188  return 0; /* success return 0 */
5189 }
5190 
5203 {
5204  uint8_t res;
5205  uint8_t prev;
5206 
5207  if (handle == NULL) /* check handle */
5208  {
5209  return 2; /* return error */
5210  }
5211  if (handle->inited != 1) /* check handle initialization */
5212  {
5213  return 3; /* return error */
5214  }
5215 
5216  res = a_mfrc522_read(handle, MFRC522_REG_MFRX, &prev, 1); /* read mfrx */
5217  if (res != 0) /* check the result */
5218  {
5219  handle->debug_print("mfrc522: read mfrx failed.\n"); /* read mfrx failed */
5220 
5221  return 1; /* return error */
5222  }
5223  prev &= ~(1 << 4); /* clear the settings */
5224  prev |= enable << 4; /* set enable */
5225  res = a_mfrc522_write(handle, MFRC522_REG_MFRX, &prev, 1); /* write mfrx */
5226  if (res != 0) /* check the result */
5227  {
5228  handle->debug_print("mfrc522: write mfrx failed.\n"); /* write mfrx failed */
5229 
5230  return 1; /* return error */
5231  }
5232 
5233  return 0; /* success return 0 */
5234 }
5235 
5248 {
5249  uint8_t res;
5250  uint8_t prev;
5251 
5252  if (handle == NULL) /* check handle */
5253  {
5254  return 2; /* return error */
5255  }
5256  if (handle->inited != 1) /* check handle initialization */
5257  {
5258  return 3; /* return error */
5259  }
5260 
5261  res = a_mfrc522_read(handle, MFRC522_REG_MFRX, &prev, 1); /* read mfrx */
5262  if (res != 0) /* check the result */
5263  {
5264  handle->debug_print("mfrc522: read mfrx failed.\n"); /* read mfrx failed */
5265 
5266  return 1; /* return error */
5267  }
5268  *enable = (mfrc522_bool_t)((prev >> 4) & 0x01); /* get the bool */
5269 
5270  return 0; /* success return 0 */
5271 }
5272 
5299 uint8_t mfrc522_set_serial_speed(mfrc522_handle_t *handle, uint8_t t0, uint8_t t1)
5300 {
5301  uint8_t res;
5302  uint8_t prev;
5303 
5304  if (handle == NULL) /* check handle */
5305  {
5306  return 2; /* return error */
5307  }
5308  if (handle->inited != 1) /* check handle initialization */
5309  {
5310  return 3; /* return error */
5311  }
5312  if (t0 > 0x7) /* check the t0 */
5313  {
5314  handle->debug_print("mfrc522: t0 is over 0x7.\n"); /* t0 is over 0x7 */
5315 
5316  return 4; /* return error */
5317  }
5318  if (t1 > 0x1F) /* check the t1 */
5319  {
5320  handle->debug_print("mfrc522: t1 is over 0x1F.\n"); /* t1 is over 0x1F */
5321 
5322  return 5; /* return error */
5323  }
5324 
5325  res = a_mfrc522_read(handle, MFRC522_REG_SERIAL_SPEED, &prev, 1); /* read serial speed */
5326  if (res != 0) /* check the result */
5327  {
5328  handle->debug_print("mfrc522: read serial speed failed.\n"); /* read serial speed failed */
5329 
5330  return 1; /* return error */
5331  }
5332  prev = ((t0 & 0x7) << 5) | (t1 & 0x1F); /* set the speed */
5333  res = a_mfrc522_write(handle, MFRC522_REG_SERIAL_SPEED, &prev, 1); /* write serial speed */
5334  if (res != 0) /* check the result */
5335  {
5336  handle->debug_print("mfrc522: write serial speed failed.\n"); /* write serial speed failed */
5337 
5338  return 1; /* return error */
5339  }
5340 
5341  return 0; /* success return 0 */
5342 }
5343 
5356 uint8_t mfrc522_get_serial_speed(mfrc522_handle_t *handle, uint8_t *t0, uint8_t *t1)
5357 {
5358  uint8_t res;
5359  uint8_t prev;
5360 
5361  if (handle == NULL) /* check handle */
5362  {
5363  return 2; /* return error */
5364  }
5365  if (handle->inited != 1) /* check handle initialization */
5366  {
5367  return 3; /* return error */
5368  }
5369 
5370  res = a_mfrc522_read(handle, MFRC522_REG_SERIAL_SPEED, &prev, 1); /* read serial speed */
5371  if (res != 0) /* check the result */
5372  {
5373  handle->debug_print("mfrc522: read serial speed failed.\n"); /* read serial speed failed */
5374 
5375  return 1; /* return error */
5376  }
5377  *t0 = (prev >> 5) & 0xF; /* set the t0 */
5378  *t1 = (prev >> 0) & 0x1F; /* set the t1 */
5379 
5380  return 0; /* success return 0 */
5381 }
5382 
5394 uint8_t mfrc522_get_crc(mfrc522_handle_t *handle, uint16_t *crc)
5395 {
5396  uint8_t res;
5397  uint8_t buf[2];
5398 
5399  if (handle == NULL) /* check handle */
5400  {
5401  return 2; /* return error */
5402  }
5403  if (handle->inited != 1) /* check handle initialization */
5404  {
5405  return 3; /* return error */
5406  }
5407 
5408  res = a_mfrc522_read(handle, MFRC522_REG_CRC_RESULT_H, buf, 2); /* read crc result */
5409  if (res != 0) /* check the result */
5410  {
5411  handle->debug_print("mfrc522: read crc result failed.\n"); /* read crc result failed */
5412 
5413  return 1; /* return error */
5414  }
5415  *crc = ((uint16_t)buf[0] << 8) | buf[1]; /* get the result */
5416 
5417  return 0; /* success return 0 */
5418 }
5419 
5431 uint8_t mfrc522_set_modulation_width(mfrc522_handle_t *handle, uint8_t width)
5432 {
5433  uint8_t res;
5434 
5435  if (handle == NULL) /* check handle */
5436  {
5437  return 2; /* return error */
5438  }
5439  if (handle->inited != 1) /* check handle initialization */
5440  {
5441  return 3; /* return error */
5442  }
5443 
5444  res = a_mfrc522_write(handle, MFRC522_REG_MOD_WIDTH, &width, 1); /* write mod width */
5445  if (res != 0) /* check the result */
5446  {
5447  handle->debug_print("mfrc522: write mod width failed.\n"); /* write mod width failed */
5448 
5449  return 1; /* return error */
5450  }
5451 
5452  return 0; /* success return 0 */
5453 }
5454 
5466 uint8_t mfrc522_get_modulation_width(mfrc522_handle_t *handle, uint8_t *width)
5467 {
5468  uint8_t res;
5469 
5470  if (handle == NULL) /* check handle */
5471  {
5472  return 2; /* return error */
5473  }
5474  if (handle->inited != 1) /* check handle initialization */
5475  {
5476  return 3; /* return error */
5477  }
5478 
5479  res = a_mfrc522_read(handle, MFRC522_REG_MOD_WIDTH, width, 1); /* read mod width */
5480  if (res != 0) /* check the result */
5481  {
5482  handle->debug_print("mfrc522: read mod width failed.\n"); /* read mod width failed */
5483 
5484  return 1; /* return error */
5485  }
5486 
5487  return 0; /* success return 0 */
5488 }
5489 
5502 {
5503  uint8_t res;
5504  uint8_t prev;
5505 
5506  if (handle == NULL) /* check handle */
5507  {
5508  return 2; /* return error */
5509  }
5510  if (handle->inited != 1) /* check handle initialization */
5511  {
5512  return 3; /* return error */
5513  }
5514 
5515  res = a_mfrc522_read(handle, MFRC522_REG_RFCFG, &prev, 1); /* read rf cfg */
5516  if (res != 0) /* check the result */
5517  {
5518  handle->debug_print("mfrc522: read rf cfg failed.\n"); /* read rf cfg failed */
5519 
5520  return 1; /* return error */
5521  }
5522  prev &= ~(7 << 4); /* clear the settings */
5523  prev |= gain <<4; /* set the gain */
5524  res = a_mfrc522_write(handle, MFRC522_REG_RFCFG, &prev, 1); /* write rf cfg */
5525  if (res != 0) /* check the result */
5526  {
5527  handle->debug_print("mfrc522: write rf cfg failed.\n"); /* write rf cfg failed */
5528 
5529  return 1; /* return error */
5530  }
5531 
5532  return 0; /* success return 0 */
5533 }
5534 
5547 {
5548  uint8_t res;
5549  uint8_t prev;
5550 
5551  if (handle == NULL) /* check handle */
5552  {
5553  return 2; /* return error */
5554  }
5555  if (handle->inited != 1) /* check handle initialization */
5556  {
5557  return 3; /* return error */
5558  }
5559 
5560  res = a_mfrc522_read(handle, MFRC522_REG_RFCFG, &prev, 1); /* read rf cfg */
5561  if (res != 0) /* check the result */
5562  {
5563  handle->debug_print("mfrc522: read rf cfg failed.\n"); /* read rf cfg failed */
5564 
5565  return 1; /* return error */
5566  }
5567  *gain = (mfrc522_rx_gain_t)((prev >> 4) & 0x7); /* get the gain */
5568 
5569  return 0; /* success return 0 */
5570 }
5571 
5584 uint8_t mfrc522_set_cwgsn(mfrc522_handle_t *handle, uint8_t n)
5585 {
5586  uint8_t res;
5587  uint8_t prev;
5588 
5589  if (handle == NULL) /* check handle */
5590  {
5591  return 2; /* return error */
5592  }
5593  if (handle->inited != 1) /* check handle initialization */
5594  {
5595  return 3; /* return error */
5596  }
5597  if (n > 0xF) /* check n */
5598  {
5599  handle->debug_print("mfrc522: n is over 0xF.\n"); /* n is over 0xF */
5600 
5601  return 4; /* return error */
5602  }
5603 
5604  res = a_mfrc522_read(handle, MFRC522_REG_GSN, &prev, 1); /* read gsn */
5605  if (res != 0) /* check the result */
5606  {
5607  handle->debug_print("mfrc522: read gsn failed.\n"); /* read gsn failed */
5608 
5609  return 1; /* return error */
5610  }
5611  prev &= ~(0xF << 4); /* clear the settings */
5612  prev |= n <<4; /* set the param */
5613  res = a_mfrc522_write(handle, MFRC522_REG_GSN, &prev, 1); /* write gsn */
5614  if (res != 0) /* check the result */
5615  {
5616  handle->debug_print("mfrc522: write gsn failed.\n"); /* write gsn failed */
5617 
5618  return 1; /* return error */
5619  }
5620 
5621  return 0; /* success return 0 */
5622 }
5623 
5635 uint8_t mfrc522_get_cwgsn(mfrc522_handle_t *handle, uint8_t *n)
5636 {
5637  uint8_t res;
5638  uint8_t prev;
5639 
5640  if (handle == NULL) /* check handle */
5641  {
5642  return 2; /* return error */
5643  }
5644  if (handle->inited != 1) /* check handle initialization */
5645  {
5646  return 3; /* return error */
5647  }
5648 
5649  res = a_mfrc522_read(handle, MFRC522_REG_GSN, &prev, 1); /* read gsn */
5650  if (res != 0) /* check the result */
5651  {
5652  handle->debug_print("mfrc522: read gsn failed.\n"); /* read gsn failed */
5653 
5654  return 1; /* return error */
5655  }
5656  *n = (prev >> 4) & 0xF; /* get the param */
5657 
5658  return 0; /* success return 0 */
5659 }
5660 
5673 uint8_t mfrc522_set_modgsn(mfrc522_handle_t *handle, uint8_t n)
5674 {
5675  uint8_t res;
5676  uint8_t prev;
5677 
5678  if (handle == NULL) /* check handle */
5679  {
5680  return 2; /* return error */
5681  }
5682  if (handle->inited != 1) /* check handle initialization */
5683  {
5684  return 3; /* return error */
5685  }
5686  if (n > 0xF) /* check n */
5687  {
5688  handle->debug_print("mfrc522: n is over 0xF.\n"); /* n is over 0xF */
5689 
5690  return 4; /* return error */
5691  }
5692 
5693  res = a_mfrc522_read(handle, MFRC522_REG_GSN, &prev, 1); /* read gsn */
5694  if (res != 0) /* check the result */
5695  {
5696  handle->debug_print("mfrc522: read gsn failed.\n"); /* read gsn failed */
5697 
5698  return 1; /* return error */
5699  }
5700  prev &= ~(0xF << 0); /* clear the settings */
5701  prev |= n <<0; /* set the param */
5702  res = a_mfrc522_write(handle, MFRC522_REG_GSN, &prev, 1); /* write gsn */
5703  if (res != 0) /* check the result */
5704  {
5705  handle->debug_print("mfrc522: write gsn failed.\n"); /* write gsn failed */
5706 
5707  return 1; /* return error */
5708  }
5709 
5710  return 0; /* success return 0 */
5711 }
5712 
5724 uint8_t mfrc522_get_modgsn(mfrc522_handle_t *handle, uint8_t *n)
5725 {
5726  uint8_t res;
5727  uint8_t prev;
5728 
5729  if (handle == NULL) /* check handle */
5730  {
5731  return 2; /* return error */
5732  }
5733  if (handle->inited != 1) /* check handle initialization */
5734  {
5735  return 3; /* return error */
5736  }
5737 
5738  res = a_mfrc522_read(handle, MFRC522_REG_GSN, &prev, 1); /* read gsn */
5739  if (res != 0) /* check the result */
5740  {
5741  handle->debug_print("mfrc522: read gsn failed.\n"); /* read gsn failed */
5742 
5743  return 1; /* return error */
5744  }
5745  *n = (prev >> 0) & 0xF; /* get the param */
5746 
5747  return 0; /* success return 0 */
5748 }
5749 
5762 uint8_t mfrc522_set_cwgsp(mfrc522_handle_t *handle, uint8_t n)
5763 {
5764  uint8_t res;
5765  uint8_t prev;
5766 
5767  if (handle == NULL) /* check handle */
5768  {
5769  return 2; /* return error */
5770  }
5771  if (handle->inited != 1) /* check handle initialization */
5772  {
5773  return 3; /* return error */
5774  }
5775  if (n > 0x3F) /* check n */
5776  {
5777  handle->debug_print("mfrc522: n is over 0x3F.\n"); /* n is over 0xF3 */
5778 
5779  return 4; /* return error */
5780  }
5781 
5782  res = a_mfrc522_read(handle, MFRC522_REG_CWGSP, &prev, 1); /* read cwgsp */
5783  if (res != 0) /* check the result */
5784  {
5785  handle->debug_print("mfrc522: read cwgsp failed.\n"); /* read cwgsp failed */
5786 
5787  return 1; /* return error */
5788  }
5789  prev &= ~(0x3F << 0); /* clear the settings */
5790  prev |= n <<0; /* set the param */
5791  res = a_mfrc522_write(handle, MFRC522_REG_CWGSP, &prev, 1); /* write cwgsp */
5792  if (res != 0) /* check the result */
5793  {
5794  handle->debug_print("mfrc522: write cwgsp failed.\n"); /* write cwgsp failed */
5795 
5796  return 1; /* return error */
5797  }
5798 
5799  return 0; /* success return 0 */
5800 }
5801 
5813 uint8_t mfrc522_get_cwgsp(mfrc522_handle_t *handle, uint8_t *n)
5814 {
5815  uint8_t res;
5816  uint8_t prev;
5817 
5818  if (handle == NULL) /* check handle */
5819  {
5820  return 2; /* return error */
5821  }
5822  if (handle->inited != 1) /* check handle initialization */
5823  {
5824  return 3; /* return error */
5825  }
5826 
5827  res = a_mfrc522_read(handle, MFRC522_REG_CWGSP, &prev, 1); /* read cwgsp */
5828  if (res != 0) /* check the result */
5829  {
5830  handle->debug_print("mfrc522: read cwgsp failed.\n"); /* read cwgsp failed */
5831 
5832  return 1; /* return error */
5833  }
5834  *n = prev & 0x3F; /* get the cwgsp */
5835 
5836  return 0; /* success return 0 */
5837 }
5838 
5851 uint8_t mfrc522_set_modgsp(mfrc522_handle_t *handle, uint8_t n)
5852 {
5853  uint8_t res;
5854  uint8_t prev;
5855 
5856  if (handle == NULL) /* check handle */
5857  {
5858  return 2; /* return error */
5859  }
5860  if (handle->inited != 1) /* check handle initialization */
5861  {
5862  return 3; /* return error */
5863  }
5864  if (n > 0x3F) /* check n */
5865  {
5866  handle->debug_print("mfrc522: n is over 0x3F.\n"); /* n is over 0xF3 */
5867 
5868  return 4; /* return error */
5869  }
5870 
5871  res = a_mfrc522_read(handle, MFRC522_REG_MODGSP, &prev, 1); /* read modgsp */
5872  if (res != 0) /* check the result */
5873  {
5874  handle->debug_print("mfrc522: read modgsp failed.\n"); /* read modgsp failed */
5875 
5876  return 1; /* return error */
5877  }
5878  prev &= ~(0x3F << 0); /* clear the settings */
5879  prev |= n <<0; /* set the param */
5880  res = a_mfrc522_write(handle, MFRC522_REG_MODGSP, &prev, 1); /* write modgsp */
5881  if (res != 0) /* check the result */
5882  {
5883  handle->debug_print("mfrc522: write modgsp failed.\n"); /* write modgsp failed */
5884 
5885  return 1; /* return error */
5886  }
5887 
5888  return 0; /* success return 0 */
5889 }
5890 
5902 uint8_t mfrc522_get_modgsp(mfrc522_handle_t *handle, uint8_t *n)
5903 {
5904  uint8_t res;
5905  uint8_t prev;
5906 
5907  if (handle == NULL) /* check handle */
5908  {
5909  return 2; /* return error */
5910  }
5911  if (handle->inited != 1) /* check handle initialization */
5912  {
5913  return 3; /* return error */
5914  }
5915 
5916  res = a_mfrc522_read(handle, MFRC522_REG_MODGSP, &prev, 1); /* read modgsp */
5917  if (res != 0) /* check the result */
5918  {
5919  handle->debug_print("mfrc522: read modgsp failed.\n"); /* read modgsp failed */
5920 
5921  return 1; /* return error */
5922  }
5923  *n = prev & 0x3F; /* get the modgsp */
5924 
5925  return 0; /* success return 0 */
5926 }
5927 
5940 {
5941  uint8_t res;
5942  uint8_t prev;
5943 
5944  if (handle == NULL) /* check handle */
5945  {
5946  return 2; /* return error */
5947  }
5948  if (handle->inited != 1) /* check handle initialization */
5949  {
5950  return 3; /* return error */
5951  }
5952 
5953  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev, 1); /* read tmode */
5954  if (res != 0) /* check the result */
5955  {
5956  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
5957 
5958  return 1; /* return error */
5959  }
5960  prev &= ~(1 << 7); /* clear the settings */
5961  prev |= enable << 7; /* set the bool */
5962  res = a_mfrc522_write(handle, MFRC522_REG_TMODE, &prev, 1); /* write tmode */
5963  if (res != 0) /* check the result */
5964  {
5965  handle->debug_print("mfrc522: write tmode failed.\n"); /* write tmode failed */
5966 
5967  return 1; /* return error */
5968  }
5969 
5970  return 0; /* success return 0 */
5971 }
5972 
5985 {
5986  uint8_t res;
5987  uint8_t prev;
5988 
5989  if (handle == NULL) /* check handle */
5990  {
5991  return 2; /* return error */
5992  }
5993  if (handle->inited != 1) /* check handle initialization */
5994  {
5995  return 3; /* return error */
5996  }
5997 
5998  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev, 1); /* read tmode */
5999  if (res != 0) /* check the result */
6000  {
6001  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
6002 
6003  return 1; /* return error */
6004  }
6005  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
6006 
6007  return 0; /* success return 0 */
6008 }
6009 
6022 {
6023  uint8_t res;
6024  uint8_t prev;
6025 
6026  if (handle == NULL) /* check handle */
6027  {
6028  return 2; /* return error */
6029  }
6030  if (handle->inited != 1) /* check handle initialization */
6031  {
6032  return 3; /* return error */
6033  }
6034 
6035  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev, 1); /* read tmode */
6036  if (res != 0) /* check the result */
6037  {
6038  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
6039 
6040  return 1; /* return error */
6041  }
6042  prev &= ~(3 << 5); /* clear the settings */
6043  prev |= mode << 5; /* set the bool */
6044  res = a_mfrc522_write(handle, MFRC522_REG_TMODE, &prev, 1); /* write tmode */
6045  if (res != 0) /* check the result */
6046  {
6047  handle->debug_print("mfrc522: write tmode failed.\n"); /* write tmode failed */
6048 
6049  return 1; /* return error */
6050  }
6051 
6052  return 0; /* success return 0 */
6053 }
6054 
6067 {
6068  uint8_t res;
6069  uint8_t prev;
6070 
6071  if (handle == NULL) /* check handle */
6072  {
6073  return 2; /* return error */
6074  }
6075  if (handle->inited != 1) /* check handle initialization */
6076  {
6077  return 3; /* return error */
6078  }
6079 
6080  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev, 1); /* read tmode */
6081  if (res != 0) /* check the result */
6082  {
6083  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
6084 
6085  return 1; /* return error */
6086  }
6087  *mode = (mfrc522_timer_gated_mode_t)((prev >> 5) & 0x03); /* get the mode */
6088 
6089  return 0; /* success return 0 */
6090 }
6091 
6104 {
6105  uint8_t res;
6106  uint8_t prev;
6107 
6108  if (handle == NULL) /* check handle */
6109  {
6110  return 2; /* return error */
6111  }
6112  if (handle->inited != 1) /* check handle initialization */
6113  {
6114  return 3; /* return error */
6115  }
6116 
6117  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev, 1); /* read tmode */
6118  if (res != 0) /* check the result */
6119  {
6120  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
6121 
6122  return 1; /* return error */
6123  }
6124  prev &= ~(1 << 4); /* clear the settings */
6125  prev |= enable << 4; /* set the bool */
6126  res = a_mfrc522_write(handle, MFRC522_REG_TMODE, &prev, 1); /* write tmode */
6127  if (res != 0) /* check the result */
6128  {
6129  handle->debug_print("mfrc522: write tmode failed.\n"); /* write tmode failed */
6130 
6131  return 1; /* return error */
6132  }
6133 
6134  return 0; /* success return 0 */
6135 }
6136 
6149 {
6150  uint8_t res;
6151  uint8_t prev;
6152 
6153  if (handle == NULL) /* check handle */
6154  {
6155  return 2; /* return error */
6156  }
6157  if (handle->inited != 1) /* check handle initialization */
6158  {
6159  return 3; /* return error */
6160  }
6161 
6162  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev, 1); /* read tmode */
6163  if (res != 0) /* check the result */
6164  {
6165  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
6166 
6167  return 1; /* return error */
6168  }
6169  *enable = (mfrc522_bool_t)((prev >> 4) & 0x01); /* get the bool */
6170 
6171  return 0; /* success return 0 */
6172 }
6173 
6186 uint8_t mfrc522_set_timer_prescaler(mfrc522_handle_t *handle, uint16_t t)
6187 {
6188  uint8_t res;
6189  uint8_t prev;
6190 
6191  if (handle == NULL) /* check handle */
6192  {
6193  return 2; /* return error */
6194  }
6195  if (handle->inited != 1) /* check handle initialization */
6196  {
6197  return 3; /* return error */
6198  }
6199  if (t > 0xFFF) /* check t */
6200  {
6201  handle->debug_print("mfrc522: t is over 0xFFF.\n"); /* t is over 0xFFF */
6202 
6203  return 4; /* return error */
6204  }
6205 
6206  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev, 1); /* read tmode */
6207  if (res != 0) /* check the result */
6208  {
6209  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
6210 
6211  return 1; /* return error */
6212  }
6213  prev &= ~(0xF << 0); /* clear the settings */
6214  prev |= ((t >> 8) & 0xF) << 0; /* set the param */
6215  res = a_mfrc522_write(handle, MFRC522_REG_TMODE, &prev, 1); /* write tmode */
6216  if (res != 0) /* check the result */
6217  {
6218  handle->debug_print("mfrc522: write tmode failed.\n"); /* write tmode failed */
6219 
6220  return 1; /* return error */
6221  }
6222  prev = t & 0xFF; /* set the t */
6223  res = a_mfrc522_write(handle, MFRC522_REG_TPRESCALER, &prev, 1); /* write tprescaler */
6224  if (res != 0) /* check the result */
6225  {
6226  handle->debug_print("mfrc522: write tprescaler failed.\n"); /* write tprescaler failed */
6227 
6228  return 1; /* return error */
6229  }
6230 
6231  return 0; /* success return 0 */
6232 }
6233 
6245 uint8_t mfrc522_get_timer_prescaler(mfrc522_handle_t *handle, uint16_t *t)
6246 {
6247  uint8_t res;
6248  uint8_t prev1, prev2;
6249 
6250  if (handle == NULL) /* check handle */
6251  {
6252  return 2; /* return error */
6253  }
6254  if (handle->inited != 1) /* check handle initialization */
6255  {
6256  return 3; /* return error */
6257  }
6258 
6259  res = a_mfrc522_read(handle, MFRC522_REG_TMODE, &prev1, 1); /* read tmode */
6260  if (res != 0) /* check the result */
6261  {
6262  handle->debug_print("mfrc522: read tmode failed.\n"); /* read tmode failed */
6263 
6264  return 1; /* return error */
6265  }
6266  res = a_mfrc522_read(handle, MFRC522_REG_TPRESCALER, &prev2, 1); /* read tprescaler */
6267  if (res != 0) /* check the result */
6268  {
6269  handle->debug_print("mfrc522: read tprescaler failed.\n"); /* read tprescaler failed */
6270 
6271  return 1; /* return error */
6272  }
6273  *t = (uint16_t)((prev1 >> 0) & 0xF) << 8 | prev2; /* set the param */
6274 
6275  return 0; /* success return 0 */
6276 }
6277 
6289 uint8_t mfrc522_set_timer_reload(mfrc522_handle_t *handle, uint16_t reload)
6290 {
6291  uint8_t res;
6292  uint8_t buf[2];
6293 
6294  if (handle == NULL) /* check handle */
6295  {
6296  return 2; /* return error */
6297  }
6298  if (handle->inited != 1) /* check handle initialization */
6299  {
6300  return 3; /* return error */
6301  }
6302 
6303  buf[0] = (reload >> 8) & 0xFF; /* set high */
6304  buf[1] = (reload >> 0) & 0xFF; /* set low */
6305  res = a_mfrc522_write(handle, MFRC522_REG_TRELOAD_H, buf, 2); /* write treload */
6306  if (res != 0) /* check the result */
6307  {
6308  handle->debug_print("mfrc522: write treload failed.\n"); /* write treload failed */
6309 
6310  return 1; /* return error */
6311  }
6312 
6313  return 0; /* success return 0 */
6314 }
6315 
6327 uint8_t mfrc522_get_timer_reload(mfrc522_handle_t *handle, uint16_t *reload)
6328 {
6329  uint8_t res;
6330  uint8_t buf[2];
6331 
6332  if (handle == NULL) /* check handle */
6333  {
6334  return 2; /* return error */
6335  }
6336  if (handle->inited != 1) /* check handle initialization */
6337  {
6338  return 3; /* return error */
6339  }
6340 
6341  res = a_mfrc522_read(handle, MFRC522_REG_TRELOAD_H, buf, 2); /* read treload */
6342  if (res != 0) /* check the result */
6343  {
6344  handle->debug_print("mfrc522: read treload failed.\n"); /* read treload failed */
6345 
6346  return 1; /* return error */
6347  }
6348  *reload = (uint16_t)buf[0] << 8 | buf[1]; /* set the reload */
6349 
6350  return 0; /* success return 0 */
6351 }
6352 
6364 uint8_t mfrc522_get_timer_counter(mfrc522_handle_t *handle, uint16_t *cnt)
6365 {
6366  uint8_t res;
6367  uint8_t buf[2];
6368 
6369  if (handle == NULL) /* check handle */
6370  {
6371  return 2; /* return error */
6372  }
6373  if (handle->inited != 1) /* check handle initialization */
6374  {
6375  return 3; /* return error */
6376  }
6377 
6378  res = a_mfrc522_read(handle, MFRC522_REG_TCOUNTER_VAL_H, buf, 2); /* read tcounter */
6379  if (res != 0) /* check the result */
6380  {
6381  handle->debug_print("mfrc522: read tcounter failed.\n"); /* read tcounter failed */
6382 
6383  return 1; /* return error */
6384  }
6385  *cnt = (uint16_t)buf[0] << 8 | buf[1]; /* set the reload */
6386 
6387  return 0; /* success return 0 */
6388 }
6389 
6403 {
6404  uint8_t res;
6405  uint8_t prev;
6406 
6407  if (handle == NULL) /* check handle */
6408  {
6409  return 2; /* return error */
6410  }
6411  if (handle->inited != 1) /* check handle initialization */
6412  {
6413  return 3; /* return error */
6414  }
6415  if (s > 7) /* check s */
6416  {
6417  handle->debug_print("mfrc522: s is over 7.\n"); /* s is over 7 */
6418 
6419  return 4; /* return error */
6420  }
6421 
6422  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL1, &prev, 1); /* read test sel 1 */
6423  if (res != 0) /* check the result */
6424  {
6425  handle->debug_print("mfrc522: read test sel 1 failed.\n"); /* read test sel 1 failed */
6426 
6427  return 1; /* return error */
6428  }
6429  prev &= ~(0x7 << 0); /* clear the settings */
6430  prev |= s << 0; /* set the signal */
6431  res = a_mfrc522_write(handle, MFRC522_REG_TEST_SEL1, &prev, 1); /* write test sel 1 */
6432  if (res != 0) /* check the result */
6433  {
6434  handle->debug_print("mfrc522: write test sel 1 failed.\n"); /* write test sel 1 failed */
6435 
6436  return 1; /* return error */
6437  }
6438 
6439  return 0; /* success return 0 */
6440 }
6441 
6454 {
6455  uint8_t res;
6456  uint8_t prev;
6457 
6458  if (handle == NULL) /* check handle */
6459  {
6460  return 2; /* return error */
6461  }
6462  if (handle->inited != 1) /* check handle initialization */
6463  {
6464  return 3; /* return error */
6465  }
6466 
6467  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL1, &prev, 1); /* read test sel 1 */
6468  if (res != 0) /* check the result */
6469  {
6470  handle->debug_print("mfrc522: read test sel 1 failed.\n"); /* read test sel 1 failed */
6471 
6472  return 1; /* return error */
6473  }
6474  *s = (prev >> 0) & 0x7; /* get the signal */
6475 
6476  return 0; /* success return 0 */
6477 }
6478 
6492 {
6493  uint8_t res;
6494  uint8_t prev;
6495 
6496  if (handle == NULL) /* check handle */
6497  {
6498  return 2; /* return error */
6499  }
6500  if (handle->inited != 1) /* check handle initialization */
6501  {
6502  return 3; /* return error */
6503  }
6504  if (s > 0x1F) /* check s */
6505  {
6506  handle->debug_print("mfrc522: s is over 0x1F.\n"); /* s is over 0x1F */
6507 
6508  return 4; /* return error */
6509  }
6510 
6511  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6512  if (res != 0) /* check the result */
6513  {
6514  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6515 
6516  return 1; /* return error */
6517  }
6518  prev &= ~(0x1F << 0); /* clear the settings */
6519  prev |= s << 0; /* set the signal */
6520  res = a_mfrc522_write(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* write test sel 2 */
6521  if (res != 0) /* check the result */
6522  {
6523  handle->debug_print("mfrc522: write test sel 2 failed.\n"); /* write test sel 2 failed */
6524 
6525  return 1; /* return error */
6526  }
6527 
6528  return 0; /* success return 0 */
6529 }
6530 
6543 {
6544  uint8_t res;
6545  uint8_t prev;
6546 
6547  if (handle == NULL) /* check handle */
6548  {
6549  return 2; /* return error */
6550  }
6551  if (handle->inited != 1) /* check handle initialization */
6552  {
6553  return 3; /* return error */
6554  }
6555 
6556  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6557  if (res != 0) /* check the result */
6558  {
6559  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6560 
6561  return 1; /* return error */
6562  }
6563  *s = (prev >> 0) & 0x1F; /* set the signal */
6564 
6565  return 0; /* success return 0 */
6566 }
6567 
6580 {
6581  uint8_t res;
6582  uint8_t prev;
6583 
6584  if (handle == NULL) /* check handle */
6585  {
6586  return 2; /* return error */
6587  }
6588  if (handle->inited != 1) /* check handle initialization */
6589  {
6590  return 3; /* return error */
6591  }
6592 
6593  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6594  if (res != 0) /* check the result */
6595  {
6596  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6597 
6598  return 1; /* return error */
6599  }
6600  prev &= ~(1 << 7); /* clear the settings */
6601  prev |= enable << 7; /* set the bool */
6602  res = a_mfrc522_write(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* write test sel 2 */
6603  if (res != 0) /* check the result */
6604  {
6605  handle->debug_print("mfrc522: write test sel 2 failed.\n"); /* write test sel 2 failed */
6606 
6607  return 1; /* return error */
6608  }
6609 
6610  return 0; /* success return 0 */
6611 }
6612 
6625 {
6626  uint8_t res;
6627  uint8_t prev;
6628 
6629  if (handle == NULL) /* check handle */
6630  {
6631  return 2; /* return error */
6632  }
6633  if (handle->inited != 1) /* check handle initialization */
6634  {
6635  return 3; /* return error */
6636  }
6637 
6638  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6639  if (res != 0) /* check the result */
6640  {
6641  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6642 
6643  return 1; /* return error */
6644  }
6645  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
6646 
6647  return 0; /* success return 0 */
6648 }
6649 
6662 {
6663  uint8_t res;
6664  uint8_t prev;
6665 
6666  if (handle == NULL) /* check handle */
6667  {
6668  return 2; /* return error */
6669  }
6670  if (handle->inited != 1) /* check handle initialization */
6671  {
6672  return 3; /* return error */
6673  }
6674 
6675  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6676  if (res != 0) /* check the result */
6677  {
6678  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6679 
6680  return 1; /* return error */
6681  }
6682  prev &= ~(1 << 6); /* clear the settings */
6683  prev |= enable << 6; /* set the bool */
6684  res = a_mfrc522_write(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* write test sel 2 */
6685  if (res != 0) /* check the result */
6686  {
6687  handle->debug_print("mfrc522: write test sel 2 failed.\n"); /* write test sel 2 failed */
6688 
6689  return 1; /* return error */
6690  }
6691 
6692  return 0; /* success return 0 */
6693 }
6694 
6707 {
6708  uint8_t res;
6709  uint8_t prev;
6710 
6711  if (handle == NULL) /* check handle */
6712  {
6713  return 2; /* return error */
6714  }
6715  if (handle->inited != 1) /* check handle initialization */
6716  {
6717  return 3; /* return error */
6718  }
6719 
6720  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6721  if (res != 0) /* check the result */
6722  {
6723  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6724 
6725  return 1; /* return error */
6726  }
6727  *enable = (mfrc522_bool_t)((prev >> 6) & 0x01); /* get the bool */
6728 
6729  return 0; /* success return 0 */
6730 }
6731 
6744 {
6745  uint8_t res;
6746  uint8_t prev;
6747 
6748  if (handle == NULL) /* check handle */
6749  {
6750  return 2; /* return error */
6751  }
6752  if (handle->inited != 1) /* check handle initialization */
6753  {
6754  return 3; /* return error */
6755  }
6756 
6757  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6758  if (res != 0) /* check the result */
6759  {
6760  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6761 
6762  return 1; /* return error */
6763  }
6764  prev &= ~(1 << 5); /* clear the settings */
6765  prev |= enable << 5; /* set the bool */
6766  res = a_mfrc522_write(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* write test sel 2 */
6767  if (res != 0) /* check the result */
6768  {
6769  handle->debug_print("mfrc522: write test sel 2 failed.\n"); /* write test sel 2 failed */
6770 
6771  return 1; /* return error */
6772  }
6773 
6774  return 0; /* success return 0 */
6775 }
6776 
6789 {
6790  uint8_t res;
6791  uint8_t prev;
6792 
6793  if (handle == NULL) /* check handle */
6794  {
6795  return 2; /* return error */
6796  }
6797  if (handle->inited != 1) /* check handle initialization */
6798  {
6799  return 3; /* return error */
6800  }
6801 
6802  res = a_mfrc522_read(handle, MFRC522_REG_TEST_SEL2, &prev, 1); /* read test sel 2 */
6803  if (res != 0) /* check the result */
6804  {
6805  handle->debug_print("mfrc522: read test sel 2 failed.\n"); /* read test sel 2 failed */
6806 
6807  return 1; /* return error */
6808  }
6809  *enable = (mfrc522_bool_t)((prev >> 5) & 0x01); /* get the bool */
6810 
6811  return 0; /* success return 0 */
6812 }
6813 
6826 {
6827  uint8_t res;
6828  uint8_t prev;
6829 
6830  if (handle == NULL) /* check handle */
6831  {
6832  return 2; /* return error */
6833  }
6834  if (handle->inited != 1) /* check handle initialization */
6835  {
6836  return 3; /* return error */
6837  }
6838 
6839  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_EN, &prev, 1); /* read test pin en */
6840  if (res != 0) /* check the result */
6841  {
6842  handle->debug_print("mfrc522: read test pin en failed.\n"); /* read test pin en failed */
6843 
6844  return 1; /* return error */
6845  }
6846  prev &= ~(1 << 7); /* clear the settings */
6847  prev |= enable << 7; /* set the bool */
6848  res = a_mfrc522_write(handle, MFRC522_REG_TEST_PIN_EN, &prev, 1); /* write test pin en */
6849  if (res != 0) /* check the result */
6850  {
6851  handle->debug_print("mfrc522: write test pin en failed.\n"); /* write test pin en failed */
6852 
6853  return 1; /* return error */
6854  }
6855 
6856  return 0; /* success return 0 */
6857 }
6858 
6871 {
6872  uint8_t res;
6873  uint8_t prev;
6874 
6875  if (handle == NULL) /* check handle */
6876  {
6877  return 2; /* return error */
6878  }
6879  if (handle->inited != 1) /* check handle initialization */
6880  {
6881  return 3; /* return error */
6882  }
6883 
6884  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_EN, &prev, 1); /* read test pin en */
6885  if (res != 0) /* check the result */
6886  {
6887  handle->debug_print("mfrc522: read test pin en failed.\n"); /* read test pin en failed */
6888 
6889  return 1; /* return error */
6890  }
6891  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
6892 
6893  return 0; /* success return 0 */
6894 }
6895 
6908 uint8_t mfrc522_set_test_pin_enable(mfrc522_handle_t *handle, uint8_t pin)
6909 {
6910  uint8_t res;
6911  uint8_t prev;
6912 
6913  if (handle == NULL) /* check handle */
6914  {
6915  return 2; /* return error */
6916  }
6917  if (handle->inited != 1) /* check handle initialization */
6918  {
6919  return 3; /* return error */
6920  }
6921  if (pin > 0x3F) /* check pin */
6922  {
6923  handle->debug_print("mfrc522: pin is over 0x3F.\n"); /* pin is over 0x3F */
6924 
6925  return 4; /* return error */
6926  }
6927 
6928  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_EN, &prev, 1); /* read test pin en */
6929  if (res != 0) /* check the result */
6930  {
6931  handle->debug_print("mfrc522: read test pin en failed.\n"); /* read test pin en failed */
6932 
6933  return 1; /* return error */
6934  }
6935  prev &= ~(0x3F << 1); /* clear the settings */
6936  prev |= pin << 1; /* set the pin */
6937  res = a_mfrc522_write(handle, MFRC522_REG_TEST_PIN_EN, &prev, 1); /* write test pin en */
6938  if (res != 0) /* check the result */
6939  {
6940  handle->debug_print("mfrc522: write test pin en failed.\n"); /* write test pin en failed */
6941 
6942  return 1; /* return error */
6943  }
6944 
6945  return 0; /* success return 0 */
6946 }
6947 
6959 uint8_t mfrc522_get_test_pin_enable(mfrc522_handle_t *handle, uint8_t *pin)
6960 {
6961  uint8_t res;
6962  uint8_t prev;
6963 
6964  if (handle == NULL) /* check handle */
6965  {
6966  return 2; /* return error */
6967  }
6968  if (handle->inited != 1) /* check handle initialization */
6969  {
6970  return 3; /* return error */
6971  }
6972 
6973  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_EN, &prev, 1); /* read test pin en */
6974  if (res != 0) /* check the result */
6975  {
6976  handle->debug_print("mfrc522: read test pin en failed.\n"); /* read test pin en failed */
6977 
6978  return 1; /* return error */
6979  }
6980  *pin = (prev >> 1) & 0x3F; /* get the pin */
6981 
6982  return 0; /* success return 0 */
6983 }
6984 
6997 {
6998  uint8_t res;
6999  uint8_t prev;
7000 
7001  if (handle == NULL) /* check handle */
7002  {
7003  return 2; /* return error */
7004  }
7005  if (handle->inited != 1) /* check handle initialization */
7006  {
7007  return 3; /* return error */
7008  }
7009 
7010  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_VALUE, &prev, 1); /* read test pin value */
7011  if (res != 0) /* check the result */
7012  {
7013  handle->debug_print("mfrc522: read test pin value failed.\n"); /* read test pin value failed */
7014 
7015  return 1; /* return error */
7016  }
7017  prev &= ~(1 << 7); /* clear the settings */
7018  prev |= enable << 7; /* set the bool */
7019  res = a_mfrc522_write(handle, MFRC522_REG_TEST_PIN_VALUE, &prev, 1); /* write test pin value */
7020  if (res != 0) /* check the result */
7021  {
7022  handle->debug_print("mfrc522: write test pin value failed.\n"); /* write test pin value failed */
7023 
7024  return 1; /* return error */
7025  }
7026 
7027  return 0; /* success return 0 */
7028 }
7029 
7042 {
7043  uint8_t res;
7044  uint8_t prev;
7045 
7046  if (handle == NULL) /* check handle */
7047  {
7048  return 2; /* return error */
7049  }
7050  if (handle->inited != 1) /* check handle initialization */
7051  {
7052  return 3; /* return error */
7053  }
7054 
7055  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_VALUE, &prev, 1); /* read test pin value */
7056  if (res != 0) /* check the result */
7057  {
7058  handle->debug_print("mfrc522: read test pin value failed.\n"); /* read test pin value failed */
7059 
7060  return 1; /* return error */
7061  }
7062  *enable = (mfrc522_bool_t)((prev >> 7) & 0x01); /* get the bool */
7063 
7064  return 0; /* success return 0 */
7065 }
7066 
7079 uint8_t mfrc522_set_test_pin_value(mfrc522_handle_t *handle, uint8_t value)
7080 {
7081  uint8_t res;
7082  uint8_t prev;
7083 
7084  if (handle == NULL) /* check handle */
7085  {
7086  return 2; /* return error */
7087  }
7088  if (handle->inited != 1) /* check handle initialization */
7089  {
7090  return 3; /* return error */
7091  }
7092  if (value > 0x3F) /* check the value */
7093  {
7094  handle->debug_print("mfrc522: value is over 0x3F.\n"); /* value is over 0x3F */
7095 
7096  return 4; /* return error */
7097  }
7098 
7099  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_VALUE, &prev, 1); /* read test pin value */
7100  if (res != 0) /* check the result */
7101  {
7102  handle->debug_print("mfrc522: read test pin value failed.\n"); /* read test pin value failed */
7103 
7104  return 1; /* return error */
7105  }
7106  prev &= ~(0x3F << 1); /* clear the settings */
7107  prev |= value << 1; /* set the value */
7108  res = a_mfrc522_write(handle, MFRC522_REG_TEST_PIN_VALUE, &prev, 1); /* write test pin value */
7109  if (res != 0) /* check the result */
7110  {
7111  handle->debug_print("mfrc522: write test pin value failed.\n"); /* write test pin value failed */
7112 
7113  return 1; /* return error */
7114  }
7115 
7116  return 0; /* success return 0 */
7117 }
7118 
7130 uint8_t mfrc522_get_test_pin_value(mfrc522_handle_t *handle, uint8_t *value)
7131 {
7132  uint8_t res;
7133  uint8_t prev;
7134 
7135  if (handle == NULL) /* check handle */
7136  {
7137  return 2; /* return error */
7138  }
7139  if (handle->inited != 1) /* check handle initialization */
7140  {
7141  return 3; /* return error */
7142  }
7143 
7144  res = a_mfrc522_read(handle, MFRC522_REG_TEST_PIN_VALUE, &prev, 1); /* read test pin value */
7145  if (res != 0) /* check the result */
7146  {
7147  handle->debug_print("mfrc522: read test pin value failed.\n"); /* read test pin value failed */
7148 
7149  return 1; /* return error */
7150  }
7151  *value = (prev >> 1) & 0x3F; /* get the value */
7152 
7153  return 0; /* success return 0 */
7154 }
7155 
7167 uint8_t mfrc522_get_test_bus(mfrc522_handle_t *handle, uint8_t *bus)
7168 {
7169  uint8_t res;
7170 
7171  if (handle == NULL) /* check handle */
7172  {
7173  return 2; /* return error */
7174  }
7175  if (handle->inited != 1) /* check handle initialization */
7176  {
7177  return 3; /* return error */
7178  }
7179 
7180  res = a_mfrc522_read(handle, MFRC522_REG_TEST_BUS, bus, 1); /* read test bus */
7181  if (res != 0) /* check the result */
7182  {
7183  handle->debug_print("mfrc522: read test bus failed.\n"); /* read test bus failed */
7184 
7185  return 1; /* return error */
7186  }
7187 
7188  return 0; /* success return 0 */
7189 }
7190 
7203 {
7204  uint8_t res;
7205  uint8_t prev;
7206 
7207  if (handle == NULL) /* check handle */
7208  {
7209  return 2; /* return error */
7210  }
7211  if (handle->inited != 1) /* check handle initialization */
7212  {
7213  return 3; /* return error */
7214  }
7215 
7216  res = a_mfrc522_read(handle, MFRC522_REG_AUTO_TEST, &prev, 1); /* read auto test */
7217  if (res != 0) /* check the result */
7218  {
7219  handle->debug_print("mfrc522: read auto test failed.\n"); /* read auto test failed */
7220 
7221  return 1; /* return error */
7222  }
7223  prev &= ~(1 << 6); /* clear the settings */
7224  prev |= enable << 6; /* set the bool */
7225  res = a_mfrc522_write(handle, MFRC522_REG_AUTO_TEST, &prev, 1); /* write auto test */
7226  if (res != 0) /* check the result */
7227  {
7228  handle->debug_print("mfrc522: write auto test failed.\n"); /* write auto test failed */
7229 
7230  return 1; /* return error */
7231  }
7232 
7233  return 0; /* success return 0 */
7234 }
7235 
7248 {
7249  uint8_t res;
7250  uint8_t prev;
7251 
7252  if (handle == NULL) /* check handle */
7253  {
7254  return 2; /* return error */
7255  }
7256  if (handle->inited != 1) /* check handle initialization */
7257  {
7258  return 3; /* return error */
7259  }
7260 
7261  res = a_mfrc522_read(handle, MFRC522_REG_AUTO_TEST, &prev, 1); /* read auto test */
7262  if (res != 0) /* check the result */
7263  {
7264  handle->debug_print("mfrc522: read auto test failed.\n"); /* read auto test failed */
7265 
7266  return 1; /* return error */
7267  }
7268  *enable = (mfrc522_bool_t)((prev >> 6) & 0x01); /* get the bool */
7269 
7270  return 0; /* success return 0 */
7271 }
7272 
7285 uint8_t mfrc522_set_self_test(mfrc522_handle_t *handle, uint8_t test)
7286 {
7287  uint8_t res;
7288  uint8_t prev;
7289 
7290  if (handle == NULL) /* check handle */
7291  {
7292  return 2; /* return error */
7293  }
7294  if (handle->inited != 1) /* check handle initialization */
7295  {
7296  return 3; /* return error */
7297  }
7298  if (test > 0xF) /* check the test */
7299  {
7300  handle->debug_print("mfrc522: test is over 0xF.\n"); /* test is over 0xF */
7301 
7302  return 4; /* return error */
7303  }
7304 
7305  res = a_mfrc522_read(handle, MFRC522_REG_AUTO_TEST, &prev, 1); /* read auto test */
7306  if (res != 0) /* check the result */
7307  {
7308  handle->debug_print("mfrc522: read auto test failed.\n"); /* read auto test failed */
7309 
7310  return 1; /* return error */
7311  }
7312  prev &= ~(0xF << 0); /* clear the settings */
7313  prev |= test << 0; /* set the test */
7314  res = a_mfrc522_write(handle, MFRC522_REG_AUTO_TEST, &prev, 1); /* write auto test */
7315  if (res != 0) /* check the result */
7316  {
7317  handle->debug_print("mfrc522: write auto test failed.\n"); /* write auto test failed */
7318 
7319  return 1; /* return error */
7320  }
7321 
7322  return 0; /* success return 0 */
7323 }
7324 
7336 uint8_t mfrc522_get_self_test(mfrc522_handle_t *handle, uint8_t *test)
7337 {
7338  uint8_t res;
7339  uint8_t prev;
7340 
7341  if (handle == NULL) /* check handle */
7342  {
7343  return 2; /* return error */
7344  }
7345  if (handle->inited != 1) /* check handle initialization */
7346  {
7347  return 3; /* return error */
7348  }
7349 
7350  res = a_mfrc522_read(handle, MFRC522_REG_AUTO_TEST, &prev, 1); /* read auto test */
7351  if (res != 0) /* check the result */
7352  {
7353  handle->debug_print("mfrc522: read auto test failed.\n"); /* read auto test failed */
7354 
7355  return 1; /* return error */
7356  }
7357  *test = prev & 0xF; /* get the test */
7358 
7359  return 0; /* success return 0 */
7360 }
7361 
7374 uint8_t mfrc522_get_version(mfrc522_handle_t *handle, uint8_t *id, uint8_t *version)
7375 {
7376  uint8_t res;
7377  uint8_t prev;
7378 
7379  if (handle == NULL) /* check handle */
7380  {
7381  return 2; /* return error */
7382  }
7383  if (handle->inited != 1) /* check handle initialization */
7384  {
7385  return 3; /* return error */
7386  }
7387 
7388  res = a_mfrc522_read(handle, MFRC522_REG_VERSION, &prev, 1); /* read version */
7389  if (res != 0) /* check the result */
7390  {
7391  handle->debug_print("mfrc522: read version failed.\n"); /* read version failed */
7392 
7393  return 1; /* return error */
7394  }
7395  *id = (prev >> 4) & 0xF; /* get the id */
7396  *version= (prev >> 0) & 0xF; /* get the version */
7397 
7398  return 0; /* success return 0 */
7399 }
7400 
7413 {
7414  uint8_t res;
7415  uint8_t prev;
7416 
7417  if (handle == NULL) /* check handle */
7418  {
7419  return 2; /* return error */
7420  }
7421  if (handle->inited != 1) /* check handle initialization */
7422  {
7423  return 3; /* return error */
7424  }
7425 
7426  res = a_mfrc522_read(handle, MFRC522_REG_ANALOG_TEST, &prev, 1); /* read analog test */
7427  if (res != 0) /* check the result */
7428  {
7429  handle->debug_print("mfrc522: read analog test failed.\n"); /* read analog test failed */
7430 
7431  return 1; /* return error */
7432  }
7433  prev &= ~(0xF << 4); /* clear the settings */
7434  prev |= control << 4; /* set the control */
7435  res = a_mfrc522_write(handle, MFRC522_REG_ANALOG_TEST, &prev, 1); /* write analog test */
7436  if (res != 0) /* check the result */
7437  {
7438  handle->debug_print("mfrc522: write analog test failed.\n"); /* write analog test failed */
7439 
7440  return 1; /* return error */
7441  }
7442 
7443  return 0; /* success return 0 */
7444 }
7445 
7458 {
7459  uint8_t res;
7460  uint8_t prev;
7461 
7462  if (handle == NULL) /* check handle */
7463  {
7464  return 2; /* return error */
7465  }
7466  if (handle->inited != 1) /* check handle initialization */
7467  {
7468  return 3; /* return error */
7469  }
7470 
7471  res = a_mfrc522_read(handle, MFRC522_REG_ANALOG_TEST, &prev, 1); /* read analog test */
7472  if (res != 0) /* check the result */
7473  {
7474  handle->debug_print("mfrc522: read analog test failed.\n"); /* read analog test failed */
7475 
7476  return 1; /* return error */
7477  }
7478  *control = (mfrc522_test_analog_control_t)((prev >> 4) & 0xF); /* get the control */
7479 
7480  return 0; /* success return 0 */
7481 }
7482 
7495 {
7496  uint8_t res;
7497  uint8_t prev;
7498 
7499  if (handle == NULL) /* check handle */
7500  {
7501  return 2; /* return error */
7502  }
7503  if (handle->inited != 1) /* check handle initialization */
7504  {
7505  return 3; /* return error */
7506  }
7507 
7508  res = a_mfrc522_read(handle, MFRC522_REG_ANALOG_TEST, &prev, 1); /* read analog test */
7509  if (res != 0) /* check the result */
7510  {
7511  handle->debug_print("mfrc522: read analog test failed.\n"); /* read analog test failed */
7512 
7513  return 1; /* return error */
7514  }
7515  prev &= ~(0xF << 0); /* clear the settings */
7516  prev |= control << 0; /* set the control */
7517  res = a_mfrc522_write(handle, MFRC522_REG_ANALOG_TEST, &prev, 1); /* write analog test */
7518  if (res != 0) /* check the result */
7519  {
7520  handle->debug_print("mfrc522: write analog test failed.\n"); /* write analog test failed */
7521 
7522  return 1; /* return error */
7523  }
7524 
7525  return 0; /* success return 0 */
7526 }
7527 
7540 {
7541  uint8_t res;
7542  uint8_t prev;
7543 
7544  if (handle == NULL) /* check handle */
7545  {
7546  return 2; /* return error */
7547  }
7548  if (handle->inited != 1) /* check handle initialization */
7549  {
7550  return 3; /* return error */
7551  }
7552 
7553  res = a_mfrc522_read(handle, MFRC522_REG_ANALOG_TEST, &prev, 1); /* read analog test */
7554  if (res != 0) /* check the result */
7555  {
7556  handle->debug_print("mfrc522: read analog test failed.\n"); /* read analog test failed */
7557 
7558  return 1; /* return error */
7559  }
7560  *control = (mfrc522_test_analog_control_t)((prev >> 0) & 0xF); /* get the control */
7561 
7562  return 0; /* success return 0 */
7563 }
7564 
7577 uint8_t mfrc522_set_test_dac_1(mfrc522_handle_t *handle, uint8_t dac)
7578 {
7579  uint8_t res;
7580  uint8_t prev;
7581 
7582  if (handle == NULL) /* check handle */
7583  {
7584  return 2; /* return error */
7585  }
7586  if (handle->inited != 1) /* check handle initialization */
7587  {
7588  return 3; /* return error */
7589  }
7590  if (dac > 0x3F) /* check the dac */
7591  {
7592  handle->debug_print("mfrc522: dac is over 0x3F.\n"); /* dac is over 0x3F */
7593 
7594  return 4; /* return error */
7595  }
7596 
7597  prev = dac & 0x3F; /* set the dac */
7598  res = a_mfrc522_write(handle, MFRC522_REG_TEST_DAC1, &prev, 1); /* write test dac1 */
7599  if (res != 0) /* check the result */
7600  {
7601  handle->debug_print("mfrc522: write test dac1 failed.\n"); /* write test dac1 failed */
7602 
7603  return 1; /* return error */
7604  }
7605 
7606  return 0; /* success return 0 */
7607 }
7608 
7620 uint8_t mfrc522_get_test_dac_1(mfrc522_handle_t *handle, uint8_t *dac)
7621 {
7622  uint8_t res;
7623  uint8_t prev;
7624 
7625  if (handle == NULL) /* check handle */
7626  {
7627  return 2; /* return error */
7628  }
7629  if (handle->inited != 1) /* check handle initialization */
7630  {
7631  return 3; /* return error */
7632  }
7633 
7634  res = a_mfrc522_read(handle, MFRC522_REG_TEST_DAC1, &prev, 1); /* read test dac1 */
7635  if (res != 0) /* check the result */
7636  {
7637  handle->debug_print("mfrc522: read test dac1 failed.\n"); /* read test dac1 failed */
7638 
7639  return 1; /* return error */
7640  }
7641  *dac = prev & 0x3F; /* get the dac */
7642 
7643  return 0; /* success return 0 */
7644 }
7645 
7658 uint8_t mfrc522_set_test_dac_2(mfrc522_handle_t *handle, uint8_t dac)
7659 {
7660  uint8_t res;
7661  uint8_t prev;
7662 
7663  if (handle == NULL) /* check handle */
7664  {
7665  return 2; /* return error */
7666  }
7667  if (handle->inited != 1) /* check handle initialization */
7668  {
7669  return 3; /* return error */
7670  }
7671  if (dac > 0x3F) /* check the dac */
7672  {
7673  handle->debug_print("mfrc522: dac is over 0x3F.\n"); /* dac is over 0x3F */
7674 
7675  return 4; /* return error */
7676  }
7677 
7678  prev = dac & 0x3F; /* set the dac */
7679  res = a_mfrc522_write(handle, MFRC522_REG_TEST_DAC2, &prev, 1); /* write test dac2 */
7680  if (res != 0) /* check the result */
7681  {
7682  handle->debug_print("mfrc522: write test dac2 failed.\n"); /* write test dac2 failed */
7683 
7684  return 1; /* return error */
7685  }
7686 
7687  return 0; /* success return 0 */
7688 }
7689 
7701 uint8_t mfrc522_get_test_dac_2(mfrc522_handle_t *handle, uint8_t *dac)
7702 {
7703  uint8_t res;
7704  uint8_t prev;
7705 
7706  if (handle == NULL) /* check handle */
7707  {
7708  return 2; /* return error */
7709  }
7710  if (handle->inited != 1) /* check handle initialization */
7711  {
7712  return 3; /* return error */
7713  }
7714 
7715  res = a_mfrc522_read(handle, MFRC522_REG_TEST_DAC2, &prev, 1); /* read test dac2 */
7716  if (res != 0) /* check the result */
7717  {
7718  handle->debug_print("mfrc522: read test dac2 failed.\n"); /* read test dac2 failed */
7719 
7720  return 1; /* return error */
7721  }
7722  *dac = prev & 0x3F; /* get the dac */
7723 
7724  return 0; /* success return 0 */
7725 }
7726 
7739 uint8_t mfrc522_get_test_adc(mfrc522_handle_t *handle, uint8_t *adc_i, uint8_t *adc_q)
7740 {
7741  uint8_t res;
7742  uint8_t prev;
7743 
7744  if (handle == NULL) /* check handle */
7745  {
7746  return 2; /* return error */
7747  }
7748  if (handle->inited != 1) /* check handle initialization */
7749  {
7750  return 3; /* return error */
7751  }
7752 
7753  res = a_mfrc522_read(handle, MFRC522_REG_TEST_ADC, &prev, 1); /* read test dac2 */
7754  if (res != 0) /* check the result */
7755  {
7756  handle->debug_print("mfrc522: read test dac2 failed.\n"); /* read test dac2 failed */
7757 
7758  return 1; /* return error */
7759  }
7760  *adc_i = (prev >> 4) & 0xF; /* get adc i */
7761  *adc_q = (prev >> 0) & 0xF; /* get adc q */
7762 
7763  return 0; /* success return 0 */
7764 }
7765 
7779 uint8_t mfrc522_set_reg(mfrc522_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
7780 {
7781  if (handle == NULL) /* check handle */
7782  {
7783  return 2; /* return error */
7784  }
7785  if (handle->inited != 1) /* check handle initialization */
7786  {
7787  return 3; /* return error */
7788  }
7789 
7790  return a_mfrc522_write(handle, reg, buf, len); /* write data */
7791 }
7792 
7806 uint8_t mfrc522_get_reg(mfrc522_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
7807 {
7808  if (handle == NULL) /* check handle */
7809  {
7810  return 2; /* return error */
7811  }
7812  if (handle->inited != 1) /* check handle initialization */
7813  {
7814  return 3; /* return error */
7815  }
7816 
7817  return a_mfrc522_read(handle, reg, buf, len); /* read data */
7818 }
7819 
7829 {
7830  if (info == NULL) /* check handle */
7831  {
7832  return 2; /* return error */
7833  }
7834 
7835  memset(info, 0, sizeof(mfrc522_info_t)); /* initialize mfrc522 info structure */
7836  strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
7837  strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
7838  strncpy(info->interface, "IIC SPI UART", 32); /* copy interface name */
7839  info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
7840  info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
7841  info->max_current_ma = MAX_CURRENT; /* set maximum current */
7842  info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
7843  info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
7844  info->driver_version = DRIVER_VERSION; /* set driver version */
7845 
7846  return 0; /* success return 0 */
7847 }
#define MFRC522_REG_TMODE
#define MFRC522_REG_TX_MODE
#define MFRC522_REG_TX_SEL
#define MFRC522_REG_TEST_SEL1
#define MFRC522_REG_DIVIRQ
#define MFRC522_REG_CWGSP
#define MFRC522_REG_TCOUNTER_VAL_H
#define MAX_CURRENT
#define MFRC522_REG_TX_ASK
#define MFRC522_REG_FIFO_DATA
#define MFRC522_REG_RX_MODE
#define MFRC522_REG_SERIAL_SPEED
#define MFRC522_REG_DEMOD
#define MFRC522_REG_TEST_ADC
#define MFRC522_REG_TEST_DAC2
#define MFRC522_REG_GSN
#define MFRC522_REG_TEST_BUS
#define MFRC522_REG_STATUS2
#define MFRC522_REG_ANALOG_TEST
#define MFRC522_REG_MFTX
#define MFRC522_REG_FIFO_LEVEL
#define SUPPLY_VOLTAGE_MAX
#define MFRC522_REG_TEST_PIN_VALUE
#define MFRC522_REG_RX_SEL
#define MFRC522_REG_TPRESCALER
#define MFRC522_REG_CRC_RESULT_H
#define MFRC522_REG_MODE
#define TEMPERATURE_MAX
#define MFRC522_REG_COMIRQ
#define MFRC522_REG_RFCFG
#define MFRC522_REG_BIT_FRAMING
#define MFRC522_REG_VERSION
#define MFRC522_REG_MOD_WIDTH
#define MFRC522_REG_COMMAND
chip register definition
#define MFRC522_REG_TEST_PIN_EN
#define MFRC522_REG_STATUS1
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define MFRC522_REG_TX_CONTROL
#define MFRC522_REG_TRELOAD_H
#define MFRC522_REG_TEST_DAC1
#define MFRC522_REG_AUTO_TEST
#define MFRC522_REG_MFRX
#define MFRC522_REG_RX_THRESHOLD
#define MFRC522_REG_DIVIEN
#define MFRC522_REG_WATER_LEVEL
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define MFRC522_REG_CONTROL
#define MFRC522_REG_COMIEN
#define MFRC522_REG_MODGSP
#define MFRC522_REG_TEST_SEL2
#define MFRC522_REG_ERROR
#define MFRC522_REG_COLL
driver mfrc522 header file
uint8_t mfrc522_get_timer_auto(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the timer auto status
mfrc522_interface_t
mfrc522 interface enumeration definition
uint8_t mfrc522_get_force_100_ask(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the force 100 ask status
uint8_t mfrc522_get_water_level(mfrc522_handle_t *handle, uint8_t *level)
get the water level
mfrc522_command_t
mfrc522 command 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_get_collision_level(mfrc522_handle_t *handle, uint8_t *level)
get the collision level
uint8_t mfrc522_get_modulation_invert(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the modulation invert status
uint8_t mfrc522_get_interrupt2(mfrc522_handle_t *handle, mfrc522_interrupt2_t type, mfrc522_bool_t *enable)
get the interrupt2 status
uint8_t mfrc522_get_timer_constant_sync(mfrc522_handle_t *handle, uint8_t *t)
get the timer constant sync
uint8_t mfrc522_get_timer_counter(mfrc522_handle_t *handle, uint16_t *cnt)
get the timer counter
mfrc522_test_analog_control_t
mfrc522 test analog control enumeration definition
mfrc522_bool_t
mfrc522 bool enumeration definition
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_get_clear_temperature_error(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the clear temperature error status
uint8_t mfrc522_set_rx_multiple(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable rx multiple
uint8_t mfrc522_get_modulation_width(mfrc522_handle_t *handle, uint8_t *width)
get the modulation width
uint8_t mfrc522_get_timer_prescal_even(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the timer prescal even status
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_get_serial_speed(mfrc522_handle_t *handle, uint8_t *t0, uint8_t *t1)
get the serial speed
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_get_crc_preset(mfrc522_handle_t *handle, mfrc522_crc_preset_t *preset)
get the crc preset
uint8_t mfrc522_get_tx_wait_rf(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the rf tx wait status
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
mfrc522_timer_gated_mode_t
mfrc522 timer gated mode enumeration definition
uint8_t mfrc522_irq_handler(mfrc522_handle_t *handle)
irq handler
uint8_t mfrc522_get_mfout_input(mfrc522_handle_t *handle, mfrc522_mfout_input_t *input)
get the mfout input
uint8_t mfrc522_set_force_100_ask(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable force 100 ask
uint8_t mfrc522_get_rx_no_error(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the rx no error status
uint8_t mfrc522_get_status2(mfrc522_handle_t *handle, uint8_t *status)
get the status2
uint8_t mfrc522_get_error(mfrc522_handle_t *handle, uint8_t *err)
get the error
uint8_t mfrc522_flush_fifo(mfrc522_handle_t *handle)
flush the fifo
uint8_t mfrc522_get_fix_iq(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the fix iq status
uint8_t mfrc522_get_collision_position_not_valid(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the collision position not valid bit status
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_get_tx_last_bits(mfrc522_handle_t *handle, uint8_t *bits)
get the tx last bits
uint8_t mfrc522_get_tx_input(mfrc522_handle_t *handle, mfrc522_tx_input_t *input)
get the tx input
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
mfrc522_tx_input_t
mfrc522 tx input enumeration definition
uint8_t mfrc522_get_interrupt1_pin_invert(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the interrupt1 pin invert status
uint8_t mfrc522_get_rx_align(mfrc522_handle_t *handle, mfrc522_rx_align_t *align)
get the rx align
uint8_t mfrc522_get_rx_last_bits(mfrc522_handle_t *handle, uint8_t *bits)
get the rx last bits
mfrc522_channel_reception_t
mfrc522 channel reception enumeration definition
mfrc522_interrupt_pin_type_t
mfrc522 interrupt pin type enumeration definition
uint8_t mfrc522_info(mfrc522_info_t *info)
get chip information
uint8_t mfrc522_get_timer_reload(mfrc522_handle_t *handle, uint16_t *reload)
get the timer reload
uint8_t mfrc522_set_mfin_polarity(mfrc522_handle_t *handle, mfrc522_mfin_polarity_t polarity)
set the mfin polarity
uint8_t mfrc522_get_rx_multiple(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the rx multiple status
uint8_t mfrc522_start_timer(mfrc522_handle_t *handle)
start the timer
mfrc522_crc_preset_t
mfrc522 crc preset enumeration definition
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_get_rx_gain(mfrc522_handle_t *handle, mfrc522_rx_gain_t *gain)
get the rx gain
uint8_t mfrc522_get_timer_auto_restart(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the timer auto restart status
uint8_t mfrc522_set_modulation_invert(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable the modulation invert
uint8_t mfrc522_set_interrupt2_mark(mfrc522_handle_t *handle, mfrc522_interrupt_mark_t mark)
set the interrupt2 mark
uint8_t mfrc522_set_modulation_width(mfrc522_handle_t *handle, uint8_t width)
set the modulation width
mfrc522_modem_state_t
mfrc522 modem state enumeration definition
uint8_t mfrc522_get_modgsn(mfrc522_handle_t *handle, uint8_t *n)
get the modgsn
uint8_t mfrc522_set_value_clear_after_coll(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable value clear after coll
mfrc522_contactless_uart_input_t
mfrc522 contactless uart input enumeration definition
uint8_t mfrc522_get_status1(mfrc522_handle_t *handle, uint8_t *status)
get the status1
mfrc522_rx_gain_t
mfrc522 rx gain enumeration definition
mfrc522_antenna_driver_t
mfrc522 antenna driver enumeration definition
uint8_t mfrc522_set_fifo_data(mfrc522_handle_t *handle, uint8_t *data, uint8_t len)
set the fifo data
uint8_t mfrc522_get_collision_position(mfrc522_handle_t *handle, uint8_t *pos)
get the collision position
uint8_t mfrc522_get_tx_crc_generation(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the tx crc generation status
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_get_tx_speed(mfrc522_handle_t *handle, mfrc522_speed_t *speed)
get the tx speed
uint8_t mfrc522_get_interface(mfrc522_handle_t *handle, mfrc522_interface_t *interface)
get the chip interface
uint8_t mfrc522_set_cwgsn(mfrc522_handle_t *handle, uint8_t n)
set the cwgsn
uint8_t mfrc522_get_value_clear_after_coll(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the value clear after coll status
mfrc522_rx_align_t
mfrc522 rx align enumeration definition
uint8_t mfrc522_get_parity_disable(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the parity disable status
uint8_t mfrc522_get_addr_pin(mfrc522_handle_t *handle, uint8_t *addr_pin)
get the iic address pin
uint8_t mfrc522_get_command(mfrc522_handle_t *handle, mfrc522_command_t *command)
get the command
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_get_interrupt1_status(mfrc522_handle_t *handle, uint8_t *status)
get the interrupt1 status
mfrc522_interrupt2_t
mfrc522 interrupt2 enumeration definition
uint8_t mfrc522_get_min_level(mfrc522_handle_t *handle, uint8_t *level)
get the min level
uint8_t mfrc522_get_mfin_polarity(mfrc522_handle_t *handle, mfrc522_mfin_polarity_t *polarity)
get the mfin polarity
uint8_t mfrc522_get_rx_wait(mfrc522_handle_t *handle, uint8_t *t)
get the rx wait
uint8_t mfrc522_get_timer_gated_mode(mfrc522_handle_t *handle, mfrc522_timer_gated_mode_t *mode)
get the timer gated mode
uint8_t mfrc522_get_cwgsn(mfrc522_handle_t *handle, uint8_t *n)
get the cwgsn
uint8_t mfrc522_set_addr_pin(mfrc522_handle_t *handle, uint8_t addr_pin)
set the iic address pin
uint8_t mfrc522_get_crc_msb_first(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the crc msb first
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_get_timer_prescaler(mfrc522_handle_t *handle, uint16_t *t)
get the timer prescaler
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
mfrc522_interrupt1_t
mfrc522 interrupt1 enumeration definition
uint8_t mfrc522_get_contactless_uart_input(mfrc522_handle_t *handle, mfrc522_contactless_uart_input_t *input)
get the contactless uart input
uint8_t mfrc522_set_command(mfrc522_handle_t *handle, mfrc522_command_t command)
set the command
uint8_t mfrc522_get_interrupt_pin_type(mfrc522_handle_t *handle, mfrc522_interrupt_pin_type_t *type)
get the interrupt pin type
uint8_t mfrc522_get_channel_reception(mfrc522_handle_t *handle, mfrc522_channel_reception_t *reception)
get the channel reception
uint8_t mfrc522_get_modem_state(mfrc522_handle_t *handle, mfrc522_modem_state_t *state)
get the modem state
uint8_t mfrc522_get_cwgsp(mfrc522_handle_t *handle, uint8_t *n)
get the cwgsp
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_get_fifo_data(mfrc522_handle_t *handle, uint8_t *data, uint8_t len)
get the fifo data
uint8_t mfrc522_get_interrupt1(mfrc522_handle_t *handle, mfrc522_interrupt1_t type, mfrc522_bool_t *enable)
get the interrupt1 status
uint8_t mfrc522_set_serial_speed(mfrc522_handle_t *handle, uint8_t t0, uint8_t t1)
set the serial speed
uint8_t mfrc522_get_antenna_driver(mfrc522_handle_t *handle, mfrc522_antenna_driver_t driver, mfrc522_bool_t *enable)
get the antenna driver status
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_get_fifo_level(mfrc522_handle_t *handle, uint8_t *level)
get the fifo level
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_get_interrupt2_status(mfrc522_handle_t *handle, uint8_t *status)
get the interrupt2 status
uint8_t mfrc522_get_rx_crc_generation(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the rx crc generation status
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_get_modgsp(mfrc522_handle_t *handle, uint8_t *n)
get the modgsp
uint8_t mfrc522_get_receiver_analog(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the analog part of the receiver status
uint8_t mfrc522_get_force_iic_high_speed(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the iic high speed status
uint8_t mfrc522_start_send(mfrc522_handle_t *handle)
start the transmission of data
uint8_t mfrc522_get_rx_speed(mfrc522_handle_t *handle, mfrc522_speed_t *speed)
get the rx speed
uint8_t mfrc522_set_interrupt1_mark(mfrc522_handle_t *handle, mfrc522_interrupt_mark_t mark)
set the interrupt1 mark
uint8_t mfrc522_set_timer_prescaler(mfrc522_handle_t *handle, uint16_t t)
set the timer prescaler
mfrc522_speed_t
mfrc522 speed enumeration definition
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
mfrc522_mfin_polarity_t
mfrc522 mfin polarity enumeration definition
uint8_t mfrc522_get_power_down(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get power down status
uint8_t mfrc522_get_tx_wait(mfrc522_handle_t *handle, uint8_t *t)
get the tx wait
mfrc522_mfout_input_t
mfrc522 mfout input enumeration definition
uint8_t mfrc522_set_contactless_uart_input(mfrc522_handle_t *handle, mfrc522_contactless_uart_input_t input)
set the contactless uart input
uint8_t mfrc522_get_timer_constant_reception(mfrc522_handle_t *handle, uint8_t *t)
get the timer constant reception
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_power_down(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable power down
mfrc522_interrupt_mark_t
mfrc522 interrupt mark enumeration definition
uint8_t mfrc522_set_mfout_input(mfrc522_handle_t *handle, mfrc522_mfout_input_t input)
set the mfout input
@ MFRC522_INTERFACE_SPI
@ MFRC522_INTERFACE_UART
@ MFRC522_INTERFACE_IIC
@ MFRC522_COMMAND_IDLE
@ MFRC522_COMMAND_MF_AUTHENT
@ MFRC522_COMMAND_TRANSCEIVE
@ MFRC522_COMMAND_NO_CHANGE
@ MFRC522_COMMAND_SOFT_RESET
@ MFRC522_COMMAND_MEM
@ MFRC522_COMMAND_CALC_CRC
@ MFRC522_INTERRUPT2_CRC
@ MFRC522_INTERRUPT2_MFIN_ACT
@ MFRC522_INTERRUPT_IDLE
@ MFRC522_INTERRUPT_MFIN_ACT
@ MFRC522_INTERRUPT_TX
@ MFRC522_INTERRUPT_CRC
@ MFRC522_INTERRUPT_LO_ALERT
@ MFRC522_INTERRUPT_TIMER
@ MFRC522_INTERRUPT_RX
@ MFRC522_INTERRUPT_HI_ALERT
@ MFRC522_INTERRUPT_ERR
uint8_t mfrc522_set_test_port_io(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable test port io
uint8_t mfrc522_set_test_bus_signal_1(mfrc522_handle_t *handle, uint8_t s)
set the test bus signal 1
uint8_t mfrc522_get_test_bus_signal_1(mfrc522_handle_t *handle, uint8_t *s)
get the test bus signal 1
uint8_t mfrc522_set_test_dac_2(mfrc522_handle_t *handle, uint8_t dac)
set the test dac 2
uint8_t mfrc522_set_test_prbs15(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable test prbs15
uint8_t mfrc522_get_test_prbs9(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the test prbs9 status
uint8_t mfrc522_get_test_dac_2(mfrc522_handle_t *handle, uint8_t *dac)
get the test dac 2
uint8_t mfrc522_get_self_test(mfrc522_handle_t *handle, uint8_t *test)
get the self test
uint8_t mfrc522_get_test_pin_enable(mfrc522_handle_t *handle, uint8_t *pin)
get the test pin enable
uint8_t mfrc522_get_test_adc(mfrc522_handle_t *handle, uint8_t *adc_i, uint8_t *adc_q)
get the test adc
uint8_t mfrc522_get_test_port_io(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the test port io status
uint8_t mfrc522_get_test_analog_control_aux_1(mfrc522_handle_t *handle, mfrc522_test_analog_control_t *control)
get the test analog control aux 1
uint8_t mfrc522_set_test_bus_signal_2(mfrc522_handle_t *handle, uint8_t s)
set the test bus signal 2
uint8_t mfrc522_set_test_analog_control_aux_2(mfrc522_handle_t *handle, mfrc522_test_analog_control_t control)
set the test analog control aux 2
uint8_t mfrc522_get_test_pin_value(mfrc522_handle_t *handle, uint8_t *value)
get the test pin value
uint8_t mfrc522_get_test_analog_control_aux_2(mfrc522_handle_t *handle, mfrc522_test_analog_control_t *control)
get the test analog control aux 2
uint8_t mfrc522_set_test_analog_control_aux_1(mfrc522_handle_t *handle, mfrc522_test_analog_control_t control)
set the test analog control aux 1
uint8_t mfrc522_get_test_amp_rcv(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the test amp rcv status
uint8_t mfrc522_get_test_bus(mfrc522_handle_t *handle, uint8_t *bus)
get the test bus
uint8_t mfrc522_get_test_prbs15(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the test prbs15 status
uint8_t mfrc522_set_test_amp_rcv(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable test amp rcv
uint8_t mfrc522_get_test_bus_flip(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the test bus flip status
uint8_t mfrc522_set_self_test(mfrc522_handle_t *handle, uint8_t test)
set the self test
uint8_t mfrc522_get_version(mfrc522_handle_t *handle, uint8_t *id, uint8_t *version)
get the version
uint8_t mfrc522_get_test_dac_1(mfrc522_handle_t *handle, uint8_t *dac)
get the test dac 1
uint8_t mfrc522_set_test_prbs9(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable test prbs9
uint8_t mfrc522_set_test_pin_enable(mfrc522_handle_t *handle, uint8_t pin)
set the test pin enable
uint8_t mfrc522_get_test_bus_signal_2(mfrc522_handle_t *handle, uint8_t *s)
get the test bus signal 2
uint8_t mfrc522_set_test_dac_1(mfrc522_handle_t *handle, uint8_t dac)
set the test dac 1
uint8_t mfrc522_set_test_rs232_line(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable test rs232 line
uint8_t mfrc522_set_test_pin_value(mfrc522_handle_t *handle, uint8_t value)
set the test pin value
uint8_t mfrc522_set_test_bus_flip(mfrc522_handle_t *handle, mfrc522_bool_t enable)
enable or disable test bus flip
uint8_t mfrc522_get_test_rs232_line(mfrc522_handle_t *handle, mfrc522_bool_t *enable)
get the test rs232 line status
uint8_t mfrc522_set_reg(mfrc522_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t mfrc522_get_reg(mfrc522_handle_t *handle, uint8_t reg, uint8_t *buf, uint16_t len)
get the chip register
mfrc522 handle structure definition
uint8_t(* uart_flush)(void)
uint8_t(* uart_write)(uint8_t *buf, uint16_t len)
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* spi_read)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* spi_write)(uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* uart_deinit)(void)
uint8_t(* reset_gpio_deinit)(void)
void(* debug_print)(const char *const fmt,...)
void(* receive_callback)(uint16_t type)
uint8_t(* iic_init)(void)
uint8_t(* spi_deinit)(void)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* reset_gpio_init)(void)
uint8_t(* uart_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* reset_gpio_write)(uint8_t data)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
mfrc522 information structure definition
float supply_voltage_max_v
uint32_t driver_version
char interface[32]
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]