mfrc522.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /****************************************************************************
  2. * drivers/contactless/mfrc522.h
  3. *
  4. * Copyright(C) 2016 Uniquix Ltda. All rights reserved.
  5. * Authors: Alan Carvalho de Assis <acassis@gmail.com>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __DRIVERS_CONTACTLESS_MFRC522_H
  36. #define __DRIVERS_CONTACTLESS_MFRC522_H 1
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <stdint.h>
  42. #include <nuttx/spi/spi.h>
  43. #include <nuttx/wqueue.h>
  44. /****************************************************************************
  45. * Pre-Processor Definitions
  46. ****************************************************************************/
  47. /* The commands used by the PCD to manage communication with several PICCs
  48. * (ISO 14443-3, Type A, section 6.4)
  49. */
  50. #define PICC_CMD_REQA 0x26 /* REQuest command, Type A */
  51. #define PICC_CMD_WUPA 0x52 /* Wake-UP command, Type A */
  52. #define PICC_CMD_CT 0x88 /* Cascade Tag, used during anti collision. */
  53. #define PICC_CMD_SEL_CL1 0x93 /* Anti collision/Select, Cascade Level 1 */
  54. #define PICC_CMD_SEL_CL2 0x95 /* Anti collision/Select, Cascade Level 2 */
  55. #define PICC_CMD_SEL_CL3 0x97 /* Anti collision/Select, Cascade Level 3 */
  56. #define PICC_CMD_HLTA 0x50 /* HaLT command, Type A */
  57. /* The commands used for MIFARE Classic
  58. * (from http://www.mouser.com/ds/2/302/MF1S503x-89574.pdf, Section 9)
  59. * Use PCD_MFAuthent to authenticate access to a sector, then use these
  60. * commands to read/write/modify the blocks on the sector.
  61. * The read/write commands can also be used for MIFARE Ultralight.
  62. */
  63. #define PICC_CMD_MF_AUTH_KEY_A 0x60 /* Perform authentication with Key A */
  64. #define PICC_CMD_MF_AUTH_KEY_B 0x61 /* Perform authentication with Key B */
  65. #define PICC_CMD_MF_READ 0x30 /* Reads one 16 byte block from auth sector */
  66. #define PICC_CMD_MF_WRITE 0xA0 /* Writes one 16 byte block to auth senctor */
  67. #define PICC_CMD_MF_DECREMENT 0xC0 /* Decrements contents of a block */
  68. #define PICC_CMD_MF_INCREMENT 0xC1 /* Increments contents of a block */
  69. #define PICC_CMD_MF_RESTORE 0xC2 /* Reads the contents of a block */
  70. #define PICC_CMD_MF_TRANSFER 0xB0 /* Writes the contents of a block */
  71. /* The commands used for MIFARE Ultralight
  72. * (from http://www.nxp.com/documents/data_sheet/MF0ICU1.pdf, Section 8.6)
  73. * The PICC_CMD_MF_READ/_MF_WRITE can also be used for MIFARE Ultralight.
  74. */
  75. #define PICC_CMD_UL_WRITE 0xA2 /* Writes one 4 byte page to the PICC. */
  76. /* MFRC522 Registers */
  77. /* NOTE: All SPI addresses are shifted one bit left in the SPI address byte
  78. * See section 8.1.2.3 from MFRC522 datasheet
  79. */
  80. /* Page 0: Commands and status */
  81. /* 0x00 - reserved for future use */
  82. #define MFRC522_COMMAND_REG (0x01 << 1) /* starts/stops command execution */
  83. #define MFRC522_COM_IEN_REG (0x02 << 1) /* dis/enable int. req. ctrl bits */
  84. #define MFRC522_DIV_IEN_REG (0x03 << 1) /* dis/enable int. req. ctrl bits */
  85. #define MFRC522_COM_IRQ_REG (0x04 << 1) /* interrupt request bits */
  86. #define MFRC522_DIV_IRQ_REG (0x05 << 1) /* interrupt request bits */
  87. #define MFRC522_ERROR_REG (0x06 << 1) /* error bits status of last cmd */
  88. #define MFRC522_STATUS1_REG (0x07 << 1) /* communication status bits */
  89. #define MFRC522_STATUS2_REG (0x08 << 1) /* rcvr and transmitter status */
  90. #define MFRC522_FIFO_DATA_REG (0x09 << 1) /* input/output of FIFO buffer */
  91. #define MFRC522_FIFO_LEVEL_REG (0x0A << 1) /* number of bytes stored in the FIFO */
  92. #define MFRC522_WATER_LEVEL_REG (0x0B << 1) /* level for FIFO under/overflow */
  93. #define MFRC522_CONTROL_REG (0x0C << 1) /* miscellaneos control register */
  94. #define MFRC522_BIT_FRAMING_REG (0x0D << 1) /* adjustments for bit-oriented frames */
  95. #define MFRC522_COLL_REG (0x0E << 1) /* bit position of first bit-collision detected */
  96. /* 0x0F - reserved for future use */
  97. /* Page 1: Commands */
  98. /* 0x10 - reserved for future use */
  99. #define MFRC522_MODE_REG (0x11 << 1) /* defines general modes for transmit/receive */
  100. #define MFRC522_TX_MODE_REG (0x12 << 1) /* defines transmission data rate and framing */
  101. #define MFRC522_RX_MODE_REG (0x13 << 1) /* defines reception data rate and framing */
  102. #define MFRC522_TX_CTRL_REG (0x14 << 1) /* controls antenna driver pins TX1 and TX2 */
  103. #define MFRC522_TX_ASK_REG (0x15 << 1) /* controls the setting of transmission modulation */
  104. #define MFRC522_TX_SEL_REG (0x16 << 1) /* selects the internal sources for antenna driver */
  105. #define MFRC522_RX_SEL_REG (0x17 << 1) /* selects the internal receiver settings */
  106. #define MFRC522_RX_THLD_REG (0x18 << 1) /* selects the thresholds for bit decoder */
  107. #define MFRC522_DEMOD_REG (0x19 << 1) /* defines demodulator settings */
  108. /* 0x1A - reserved for future use */
  109. /* 0x1B - reserved for future use */
  110. #define MFRC522_MF_TX_REG (0x1C << 1) /* controls some MIFARE comm tx param */
  111. #define MFRC522_MF_RX_REG (0x1D << 1) /* controls some MIFARE comm rx param */
  112. /* 0x1E - reserved for future use */
  113. #define MFRC522_SERIAL_SPD_REG (0x1F << 1) /* selects the speed of the serial UART */
  114. /* Page 2: Configuration */
  115. /* 0x20 - reserved for future use */
  116. #define MFRC522_CRC_RESULT_REGH (0x21 << 1) /* shows the MSB values of CRC calc. */
  117. #define MFRC522_CRC_RESULT_REGL (0x22 << 1) /* shows the LSB values of CRC calc. */
  118. /* 0x23 - reserved for future use */
  119. #define MFRC522_MOD_WIDTH_REG (0x24 << 1) /* controls the ModWidth setting */
  120. /* 0x25 - reserved for future use */
  121. #define MFRC522_RF_CFG_REG (0x26 << 1) /* configures the receiver gain */
  122. #define MFRC522_GSN_REG (0x27 << 1) /* selects the conductance of n-driver TX1/2 */
  123. #define MFRC522_CW_GSP_REG (0x28 << 1) /* defines the conductance of p-driver during no modulation */
  124. #define MFRC522_MOD_GSP_REG (0x29 << 1) /* defines the conductance of p-driver during modulation */
  125. #define MFRC522_TMODE_REG (0x2A << 1) /* defines settings for the internal timer */
  126. #define MFRC522_TPRESCALER_REG (0x2B << 1) /* the lower 8 bits of TPrescaler value */
  127. #define MFRC522_TRELOAD_REGH (0x2C << 1) /* defines the 16-bit timer reload value */
  128. #define MFRC522_TRELOAD_REGL (0x2D << 1) /* defines the 16-bit timer reload value */
  129. #define MFRC522_TCOUNT_VAL_REGH (0x2E << 1) /* shows the 16-bit timer value */
  130. #define MFRC522_TCOUNT_VAL_REGL (0x2F << 1) /* shows the 16-bit timer value */
  131. /* Page 3: Test Registers */
  132. /* 0x30 - reserved for future use */
  133. #define MFRC522_TEST_SEL1_REG (0x31 << 1) /* general test signal configuration */
  134. #define MFRC522_TEST_SEL2_REG (0x32 << 1) /* general test signal configuration */
  135. #define MFRC522_TEST_PIN_EN_REG (0x33 << 1) /* enables pin output driver on pins D1 to D7 */
  136. #define MFRC522_TEST_PIN_VAL_REG (0x34 << 1) /* defines the values to D1 to D7 */
  137. #define MFRC522_TEST_BUS_REG (0x35 << 1) /* shows the status of the internal test bus */
  138. #define MFRC522_AUTOTEST_REG (0x36 << 1) /* controls the digital self test */
  139. #define MFRC522_VERSION_REG (0x37 << 1) /* shows the software version */
  140. #define MFRC522_ANALOG_TEST_REG (0x38 << 1) /* controls the pins AUX1 and AUX2 */
  141. #define MFRC522_TEST_DAC1_REG (0x39 << 1) /* defines the test value for TestDAC1 */
  142. #define MFRC522_TEST_DAC2_REG (0x3A << 1) /* defines the test value for TestDAC2 */
  143. #define MFRC522_TEST_ADC_REG (0x3B << 1) /* show the value of ADC I and Q channels */
  144. /* Section 9.3.1.2: MFRC522 Command Register */
  145. #define MFRC522_CMD_MASK 0x0F
  146. # define MFRC522_IDLE_CMD 0x00 /* no action, cancels current command execution */
  147. # define MFRC522_MEM_CMD 0x01 /* stores 25 bytes into the internal buffer */
  148. # define MFRC522_GEN_RND_ID_CMD 0x02 /* generates a 10-bytes random ID number */
  149. # define MFRC522_CALC_CRC_CMD 0x03 /* activates the CRC coprocessor or self test */
  150. # define MFRC522_TRANSMIT_CMD 0x04 /* transmits data from the FIFO buffer */
  151. # define MFRC522_NO_CHANGE_CMD 0x07 /* no command change, used to modify CommandReg */
  152. # define MFRC522_RECEIVE_CMD 0x08 /* activates the receiver circuits */
  153. # define MFRC522_TRANSCV_CMD 0x0C /* transmits data from FIFO and receive automatically */
  154. # define MFRC522_MF_AUTH_CMD 0x0E /* performs the MIFARE stand authentication as a reader */
  155. # define MFRC522_SOFTRST_CMD 0x0F /* resets the MFRC522 */
  156. #define MFRC522_POWER_DOWN (1 << 4) /* soft power-down mode entered */
  157. #define MFRC522_RCV_OFF (1 << 5) /* turns off analog part of receiver */
  158. /* Section 9.3.1.3: ComIEnReg register */
  159. #define MFRC522_TIMER_IEN (1 << 0) /* allows the timer interrupt request on pin IRQ */
  160. #define MFRC522_ERR_IEN (1 << 1) /* allows the error interrupt request on pin IRQ */
  161. #define MFRC522_LO_ALERT_IEN (1 << 2) /* allows the low alert interrupt request on pin IRQ */
  162. #define MFRC522_HI_ALERT_IEN (1 << 3) /* allows the high alert interrupt request on pin IRQ */
  163. #define MFRC522_IDLE_IEN (1 << 4) /* allows the idle interrupt request on pin IRQ */
  164. #define MFRC522_RX_IEN (1 << 5) /* allows the receiver interrupt request on pin IRQ */
  165. #define MFRC522_TX_IEN (1 << 6) /* allows the transmitter interrupt request on pin IRQ */
  166. #define MFRC522_IRQ_INV (1 << 7) /* signal on pin IRQ is inverse of IRq bit from Status1Reg */
  167. /* Section 9.3.1.4: DivIEnReg register */
  168. #define MFRC522_CRC_IEN (1 << 2) /* allows the CRC interrupt request on pin IRQ */
  169. #define MFRC522_MFIN_ACT_IEN (1 << 4) /* allows the MFIN active interrupt request on pin IRQ */
  170. #define MFRC522_IRQ_PUSH_PULL (1 << 7) /* 1 = IRQ pin is a standard CMOS output pin, 0 = open-drain */
  171. /* Section 9.3.1.5: ComIrqReg register */
  172. #define MFRC522_COM_IRQ_MASK (0x7F)
  173. #define MFRC522_TIMER_IRQ (1 << 0) /* enabled when TCounterValReg reaches value 0 */
  174. #define MFRC522_ERR_IRQ (1 << 1) /* any error bit in the ErrorReg register is set */
  175. #define MFRC522_LO_ALERT_IRQ (1 << 2) /* Status1Reg register’s LoAlert bit is set */
  176. #define MFRC522_HI_ALERT_IRQ (1 << 3) /* Status1Reg register’s HiAlert bit is set */
  177. #define MFRC522_IDLE_IRQ (1 << 4) /* if a command terminates this bit is set */
  178. #define MFRC522_RX_IRQ (1 << 5) /* receiver has detected the end of a valid data stream */
  179. #define MFRC522_TX_IRQ (1 << 6) /* set immediately after the last data bit was transmitted */
  180. #define MFRC522_SET1 (1 << 7) /* indicate the status of ComIrqReg bits */
  181. /* Section 9.3.1.6: DivIrqReg register */
  182. #define MFRC522_CRC_IRQ (1 << 2) /* the CalcCRC command is active and all data is processed */
  183. #define MFRC522_MFIN_ACT_IRQ (1 << 4) /* MFIN is active, int is set on rising/falling signal edge */
  184. #define MFRC522_SET2 (1 << 7) /* indicates the status of the marked bits in the DivIrqReg */
  185. /* Section 9.3.1.7: ErrorReg register */
  186. #define MFRC522_PROTO_ERR (1 << 0) /* set if the SOF is incorrect or during MFAuthent if data is incorrect */
  187. #define MFRC522_PARITY_ERR (1 << 1) /* parity check failed */
  188. #define MFRC522_CRC_ERR (1 << 2) /* the RxCRCEn bit is set and the CRC calculation fails */
  189. #define MFRC522_COLL_ERR (1 << 3) /* a bit-collision is detected */
  190. #define MFRC522_BUF_OVFL_ERR (1 << 4) /* FIFO is full and the host or internal state machine try to write data */
  191. #define MFRC522_TEMP_ERR (1 << 6) /* internal temperature sensor detects overheating */
  192. #define MFRC522_WR_ERR (1 << 7) /* data write error in the FIFO, host writing to FIFO at the wrong time */
  193. /* Section 9.3.1.8: Status1Reg register */
  194. #define MFRC522_LO_ALERT (1 << 0) /* number of bytes on FIFO lower than the water-mark */
  195. #define MFRC522_HI_ALERT (1 << 1) /* number of bytes on FIFO higher than the water-mark */
  196. #define MFRC522_TRUNNING (1 << 3) /* timer is running */
  197. #define MFRC522_IRQ (1 << 4) /* indicates if any interrupt source requests attention */
  198. #define MFRC522_CRC_READY (1 << 5) /* the CRC calculation has finished */
  199. #define MFRC522_CRC_OK (1 << 6) /* when the calculation is done correctly this bit change to 1 */
  200. /* Section 9.3.1.9: Status2Reg register */
  201. #define MFRC522_MODEM_STATE_MASK (7 << 0) /* shows the state of the transmitter and receiver state machine */
  202. #define MFRC522_MODEM_IDLE (0) /* idle */
  203. #define MFRC522_MODEM_WAIT_BFR (1) /* wait for the BitFramingReg register’s StartSend bit */
  204. #define MFRC522_MODEM_TXWAIT (2) /* wait until RF field is present if TxWaitRF bit is set to 1 */
  205. #define MFRC522_MODEM_TXING (3) /* transmitting */
  206. #define MFRC522_MODEM_RXWAIT (4) /* wait until RF field is present if TxWaitRF bit is set to 1 */
  207. #define MFRC522_MODEM_WAIT_DATA (5) /* wait for data */
  208. #define MFRC522_MODEM_RXING (6) /* receiving */
  209. #define MFRC522_MF_CRYPTO1_ON (1 << 3) /* MIFARE Crypto1 unit is switched on */
  210. #define MFRC522_I2C_FORCE_HS (1 << 6) /* set the I2C to high-speed mode (R/W bit) */
  211. #define MFRC522_TEMP_SENS_CLEAR (1 << 7) /* clears the temperature error if it is below 125C (R/W bit) */
  212. /* Section 9.3.1.10: FIFODataReg register */
  213. #define MFRC522_FIFO_DATA_MASK (0xFF) /* Input and output of 64 byte FIFO buffer */
  214. /* Section 9.3.1.11: FIFOLevelReg register */
  215. #define MFRC522_FIFOLEVEL_MASK (0x7F) /* indicates the number of bytes stored in the FIFO buffer */
  216. #define MFRC522_FLUSH_BUFFER (1 << 7) /* immediately clears the internal FIFO buffer */
  217. /* Section 9.3.1.12: WaterLevelReg register */
  218. #define MFRC522_WATER_LEVEL_MASK (0x3F) /* level for FIFO under- and overflow warning */
  219. /* Section 9.3.1.13: ControlReg register */
  220. #define MFRC522_RX_LAST_BITS_MASK (7 << 0) /* indicates the number of valid bits in the last received byte */
  221. #define MFRC522_TSTART_NOW (1 << 6) /* timer starts immediately */
  222. #define MFRC522_TSTOP_NOW (1 << 7) /* timer stops immediately */
  223. /* Section 9.3.1.14: BitFramingReg register */
  224. #define MFRC522_TX_LAST_BITS_MASK (7 << 0) /* defines the number of bits of the last byte that will be transmitted */
  225. #define MFRC522_RX_ALIGN_MASK (7 << 4) /* used for reception of bit-oriented frames */
  226. #define MFRC522_START_SEND (1 << 7) /* starts the transmission of data */
  227. /* Section 9.3.1.15: CollReg register */
  228. #define MFRC522_COLL_POS_MASK (0x1F) /* shows the bit position of the first detected collision */
  229. #define MFRC522_COLL_POS_NOT_VALID (1 << 5) /* no collision detected or it is out of the range of CollPos[4:0] */
  230. #define MFRC522_VALUES_AFTER_COLL (1 << 7) /* 0 means: all received bits will be cleared after a collision */
  231. /* Section 9.3.2.2: ModeReg register */
  232. #define MFRC522_CRC_PRESET_MASK (0x3) /* defines the preset value for the CalcCRC */
  233. #define MFRC522_CRC_PRESET_0000 (0x0) /* 0000h CRC preset value */
  234. #define MFRC522_CRC_PRESET_6363 (0x1) /* 6363h CRC preset value */
  235. #define MFRC522_CRC_PRESET_A671 (0x2) /* A671h CRC preset value */
  236. #define MFRC522_CRC_PRESET_FFFF (0x3) /* FFFFh CRC preset value */
  237. #define MFRC522_POL_MFIN (1 << 3) /* defines the polarity of pin MFIN */
  238. #define MFRC522_TX_WAIT_RF (1 << 5) /* transmitter can only be started if an RF field is generated */
  239. #define MFRC522_MSB_FIRST (1 << 7) /* CRC coprocessor calculates the CRC with MSB first */
  240. /* Section 9.3.2.3: TxModeReg register */
  241. #define MFRC522_INV_MOD (1 << 3) /* modulation of transmitted data is inverted */
  242. #define MFRC522_TX_SPEED_MASK (7 << 4) /* defines the bit rate during data transmission */
  243. #define MFRC522_TX_106KBD (0 << 4) /* 106 kBd */
  244. #define MFRC522_TX_212KBD (1 << 4) /* 212 kBd */
  245. #define MFRC522_TX_424KBD (2 << 4) /* 424 kBd */
  246. #define MFRC522_TX_848KBD (3 << 4) /* 848 kBd */
  247. /* 4-7 << 4 - reserved */
  248. #define MFRC522_TX_CRC_EN (1 << 7) /* enables CRC generation during data transmission */
  249. /* Section 9.3.2.4: RxModeReg register */
  250. #define MFRC522_RX_MULTIPLE (1 << 2) /* enable to receive more than one data frame, only at 106kBd */
  251. #define MFRC522_RX_NO_ERR (1 << 3) /* ignore invalid data stream error (less than 4 bits received) */
  252. #define MFRC522_RX_SPEED_MASK (7 << 4) /* defines the bit rate during data reception */
  253. #define MFRC522_RX_106KBD (0 << 4) /* 106 kBd */
  254. #define MFRC522_RX_212KBD (1 << 4) /* 212 kBd */
  255. #define MFRC522_RX_424KBD (2 << 4) /* 424 kBd */
  256. #define MFRC522_RX_848KBD (3 << 4) /* 848 kBd */
  257. /* 4-7 << 4 - reserved */
  258. #define MFRC522_RX_CRC_EN (1 << 7) /* enables CRC generation during data reception */
  259. /* Section 9.3.2.5: TxControlReg register */
  260. #define MFRC522_TX1_RF_EN (1 << 0) /* output signal on pin TX1 delivers 13.56MHz */
  261. #define MFRC522_TX2_RF_EN (1 << 1) /* output signal on pin TX2 delivers 13.56MHz */
  262. /* bit 2 - reserved */
  263. #define MFRC522_TX2_CW (1 << 3) /* output signal on pin TX2 delivers (un)modulated 13.56MHz */
  264. #define MFRC522_INV_TX1_RF_OFF (1 << 4) /* output signal on pin TX1 is inverted when driver TX1 is disabled */
  265. #define MFRC522_INV_TX2_RF_OFF (1 << 5) /* output signal on pin TX2 is inverted when driver TX2 is disabled */
  266. #define MFRC522_INV_TX1_RF_ON (1 << 6) /* output signal on pin TX1 is inverted when driver TX1 is enabled */
  267. #define MFRC522_INV_TX2_RF_ON (1 << 7) /* output signal on pin TX2 is inverted when driver TX2 is enabled */
  268. /* Section 9.3.2.6: TxASKReg register */
  269. #define MFRC522_FORCE_100ASK (1 << 6) /* forces a 100% ASK modulation independent of the ModGsPReg setting */
  270. /* Section 9.3.2.7: TxSelReg register */
  271. #define MFRC522_MFOUT_SEL_MASK (0xF) /* selects the input for pin MFOUT */
  272. #define MFRC522_MFOUT_3STATE (0) /* 3-state */
  273. #define MFRC522_MFOUT_LOW (1) /* constant Low */
  274. #define MFRC522_MFOUT_HIGH (2) /* constant High */
  275. #define MFRC522_MFOUT_TEST_BUS (3) /* test bus signal as defined by the TstBusBitSel[2:0] value */
  276. #define MFRC522_MFOUT_INT_ENV (4) /* modulation signal (envelope) from the internal encoder */
  277. #define MFRC522_MFOUT_TX_STREAM (5) /* serial data stream to be transmitted, data stream before Miller encoder */
  278. /* 6 - reserved */
  279. #define MFRC522_MFOUT_RX_STREAM (7) /* serial data stream received, data stream after Manchester decoder */
  280. /* 8-15 - reserved */
  281. #define MFRC522_DRV_SEL_MASK (3 << 4) /* selects the input of drivers TX1 and TX2 */
  282. #define MFRC522_DRV_SEL_3STATE (0 << 4) /* 3-state */
  283. #define MFRC522_DRV_SEL_INT_ENV (1 << 4) /* modulation signal (envelope) from the internal encoder */
  284. #define MFRC522_DVR_SEL_ENV_MFIN (2 << 4) /* modulation signal (envelope) from pin MFIN */
  285. #define MFRC522_DVR_SEL_HIGH (3 << 4) /* High: depends on InvTx1RFOn/InvTx1RFOff and InvTx2RFOn/InvTx2RFOff */
  286. /* Section 9.3.2.8: RxSelReg register */
  287. #define MFRC522_RX_WAIT_MASK (0x3F) /* delay the receiver RxWait bit-clocks after transmission */
  288. #define MFRC522_UART_SEL_MASK (3 << 6) /* selects the input of the contactless UART */
  289. #define MFRC522_UART_LOW (0 << 6) /* constant Low */
  290. #define MFRC522_UART_MANCHESTER (1 << 6) /* Manchester with subcarrier from pin MFIN */
  291. #define MFRC522_UART_INT_MOD (2 << 6) /* modulated signal from the internal analog module, default */
  292. #define MFRC522_UART_NRZ_CODE (3 << 6) /* NRZ coding without subcarrier from pin MFIN */
  293. /* Section 9.3.2.9: RxThresholdReg register */
  294. #define MFRC522_COLL_LEVEL_MASK (7) /* the minimum signal strength to generate a bit-collision */
  295. #define MFRC522_MIN_LEVEL_MASK (0xF << 4) /* the minimum signal strength that will be accepted */
  296. /* Section 9.3.2.10: DemodReg register */
  297. #define MFRC522_TAU_SYNC_MASK (3 << 0) /* changes the time-constant of the internal PLL during burst */
  298. #define MFRC522_TAU_RCV_MASK (3 << 2) /* changes the time-constant of the internal PLL during data reception */
  299. #define MFRC522_TPRESCAL_EVEN (1 << 4) /* defines the Timer Prescaler formula to use */
  300. #define MFRC522_FIX_IQ (1 << 5) /* defines if reception will be fixed at channel I or Q based on AddIQ[1:0] */
  301. #define MFRC522_ADD_IQ_MASK (3 << 6) /* defines the use of I and Q channel during reception */
  302. /* Section 9.3.2.13: MfTxReg register */
  303. #define MFRC522_MF_TX_WAIT_MASK (3 << 0) /* defines the additional response time */
  304. /* Section 9.3.2.14 MfRxReg register */
  305. #define MFRC522_MF_RX_PARITY_DIS (1 << 4 ) /* disable parity bit to transmittion and reception */
  306. /* Section 9.3.2.16: SerialSpeedReg register */
  307. #define MFRC522_BR_T1_MASK (0x1F) /* factor BR_T1 adjusts the transfer speed */
  308. #define MFRC522_BR_T0_MASK (7 << 5) /* factor BR_T0 adjusts the transfer speed */
  309. /* Section 9.3.3.6: RFCfgReg register */
  310. #define MFRC522_RX_GAIN_MASK (0x7 << 4)
  311. #define MFRC522_RX_GAIN_18DB (0x0 << 4)
  312. #define MFRC522_RX_GAIN_23DB (0x1 << 4)
  313. #define MFRC522_RX_GAIN_18DB_2 (0x2 << 4)
  314. #define MFRC522_RX_GAIN_23DB_2 (0x3 << 4)
  315. #define MFRC522_RX_GAIN_33DB (0x4 << 4)
  316. #define MFRC522_RX_GAIN_38DB (0x5 << 4)
  317. #define MFRC522_RX_GAIN_43DB (0x6 << 4)
  318. #define MFRC522_RX_GAIN_48DB (0x7 << 4)
  319. /* MFRC522 TModeReg and TPrescalerReg registers */
  320. #define MFRC522_TPRESCALER_HI_MASK (0xF)
  321. #define MFRC522_TAUTO_RESTART (1 << 4)
  322. #define MFRC522_TGATED_MASK (3 << 5)
  323. #define MFRC522_TGATED_NONGATED (0 << 5) /* non-gated mode */
  324. #define MFRC522_TGATED_MFIN (1 << 5) /* gated by pin MFIN */
  325. #define MFRC522_TGATED_AUX1 (2 << 5) /* gated by pin AUX1 */
  326. #define MFRC522_TAUTO (1 << 7) /* timer starts automatically at the end of the transmission */
  327. /* MFRC522 AutoTestReg register */
  328. #define MFRC522_SELFTEST_MASK (0xF) /* for default operation the self test must be disabled by value 0000b */
  329. #define MFRC522_RFT_MASK (3 << 4) /* reserved for production tests */
  330. #define MFRC522_AMP_RCV (1 << 6) /* non-linear signal processing mode, increase range distance at 106kBd */
  331. #define MFRC522_SELFTEST_EN 9 /* the self test is enabled by value 1001b */
  332. #ifndef CONFIG_MFRC522_SPI_FREQ
  333. # define CONFIG_MFRC522_SPI_FREQ (5000000)
  334. #endif
  335. /****************************************************************************
  336. * Public Types
  337. ****************************************************************************/
  338. struct mfrc522_dev_s
  339. {
  340. uint8_t state;
  341. FAR struct spi_dev_s *spi; /* SPI interface */
  342. };
  343. /****************************************************************************
  344. * Public Function Prototypes
  345. ****************************************************************************/
  346. bool mfrc522_set_config(struct mfrc522_dev_s *dev, uint8_t flags);
  347. #endif /* __DRIVERS_CONTACTLESS_MFRC522_H */