1 /**************************************************************************/
5 /**************************************************************************/
10 #include "projectconfig.h"
12 // Comment out this line to disable debug output
13 // #define PN532_DEBUGMODE
14 #define PN532_DEBUG(fmt, args...) printf(fmt, ##args)
16 /* Error messages generated by the stack */
17 /* Not to be confused with app level errors from the PN532 */
18 /* These are the errors that are returned by the PN532 driver */
19 typedef enum pn532_error_e
21 PN532_ERROR_NONE
= 0x00,
22 PN532_ERROR_UNABLETOINIT
= 0x01, // Unable to initialise or wakeup the device
23 PN532_ERROR_APPLEVELERROR
= 0x02, // Application level error detected
24 PN532_ERROR_BUSY
= 0x03, // Busy executing a previous command
25 PN532_ERROR_NOACK
= 0x04, // No ack message received
26 PN532_ERROR_INVALIDACK
= 0x05, // Ack != 00 00 FF 00 FF 00
27 PN532_ERROR_PREAMBLEMISMATCH
= 0x06, // Frame preamble + start code mismatch
28 PN532_ERROR_EXTENDEDFRAME
= 0x07, // Extended frames currently unsupported
29 PN532_ERROR_LENCHECKSUMMISMATCH
= 0x08,
30 PN532_ERROR_RESPONSEBUFFEREMPTY
= 0x09, // No response data received
31 PN532_ERROR_SPIREADYSTATUSTIMEOUT
= 0x0A, // Timeout waiting for 'ready' status (SPI only)
32 PN532_ERROR_TIMEOUTWAITINGFORCARD
= 0x0B, // No card detected in field with the specified timeout
33 PN532_ERROR_BLOCKREADFAILED
= 0x0C, // Unexpected response to block read request
34 PN532_ERROR_WRONGCARDTYPE
= 0x0D, // Card is not the expected format (based on SENS_RES/ATQA value)
35 PN532_ERROR_ADDRESSOUTOFRANGE
= 0x0E // Specified block and page is out of range
38 typedef enum pn532_modulation_e
40 PN532_MODULATION_ISO14443A_106KBPS
= 0x00,
41 PN532_MODULATION_FELICA_212KBPS
= 0x01,
42 PN532_MODULATION_FELICA_424KBPS
= 0x02,
43 PN532_MODULATION_ISO14443B_106KBPS
= 0x03,
44 PN532_MODULATION_JEWEL_106KBPS
= 0x04
47 /* HW Commands for the PN532. */
48 /* See UM0701-02 - PN532 User Manual */
51 PN532_COMMAND_DIAGNOSE
= 0x00,
52 PN532_COMMAND_GETFIRMWAREVERSION
= 0x02,
53 PN532_COMMAND_GETGENERALSTATUS
= 0x04,
54 PN532_COMMAND_READREGISTER
= 0x06,
55 PN532_COMMAND_WRITEREGISTER
= 0x08,
56 PN532_COMMAND_READGPIO
= 0x0C,
57 PN532_COMMAND_WRITEGPIO
= 0x0E,
58 PN532_COMMAND_SETSERIALBAUDRATE
= 0x10,
59 PN532_COMMAND_SETPARAMETERS
= 0x12,
60 PN532_COMMAND_SAMCONFIGURATION
= 0x14,
61 PN532_COMMAND_POWERDOWN
= 0x16,
62 PN532_COMMAND_RFCONFIGURATION
= 0x32,
63 PN532_COMMAND_RFREGULATIONTEST
= 0x58,
64 PN532_COMMAND_INJUMPFORDEP
= 0x56,
65 PN532_COMMAND_INJUMPFORPSL
= 0x46,
66 PN532_COMMAND_INLISTPASSIVETARGET
= 0x4A,
67 PN532_COMMAND_INATR
= 0x50,
68 PN532_COMMAND_INPSL
= 0x4E,
69 PN532_COMMAND_INDATAEXCHANGE
= 0x40,
70 PN532_COMMAND_INCOMMUNICATETHRU
= 0x42,
71 PN532_COMMAND_INDESELECT
= 0x44,
72 PN532_COMMAND_INRELEASE
= 0x52,
73 PN532_COMMAND_INSELECT
= 0x54,
74 PN532_COMMAND_INAUTOPOLL
= 0x60,
75 PN532_COMMAND_TGINITASTARGET
= 0x8C,
76 PN532_COMMAND_TGSETGENERALBYTES
= 0x92,
77 PN532_COMMAND_TGGETDATA
= 0x86,
78 PN532_COMMAND_TGSETDATA
= 0x8E,
79 PN532_COMMAND_TGSETMETADATA
= 0x94,
80 PN532_COMMAND_TGGETINITIATORCOMMAND
= 0x88,
81 PN532_COMMAND_TGRESPONSETOINITIATOR
= 0x90,
82 PN532_COMMAND_TGGETTARGETSTATUS
= 0x8A
85 /* Application level errors generated by the PN532 chip */
86 /* See UM0701-02 - PN532 User Manual */
89 PN532_APPERROR_NONE
= 0x00,
90 PN532_APPERROR_TIMEOUT
= 0x01,
91 PN532_APPERROR_CRCERROR
= 0x02,
92 PN532_APPERROR_PARITYERROR
= 0x04,
93 PN532_APPERROR_FRAMINGERROR
= 0x05,
94 PN532_APPERROR_BITCOLLISION
= 0x06,
95 PN532_APPERROR_INSUFFICIENTBUFFER
= 0x07,
96 PN532_APPERROR_RFBUFFEROVERFLOW
= 0x09,
97 PN532_APPERROR_RFFIELDTIMEOUT
= 0x0A,
98 PN532_APPERROR_RFPROTOCOLERROR
= 0x0B,
99 PN532_APPERROR_TEMPERROR
= 0x0D,
100 PN532_APPERROR_INTERNBUFFEROVERFLOW
= 0x0E,
101 PN532_APPERROR_INVALIDPARAMETER
= 0x10,
102 PN532_APPERROR_DEP_UNSUPPORTEDCMD
= 0x12,
103 PN532_APPERROR_DEP_INVALIDOFORMAT
= 0x13,
104 PN532_APPERROR_AUTHENTERR
= 0x14,
105 PN532_APPERROR_UIDCCHECKERROR
= 0x23,
106 PN532_APPERROR_DEP_INVALIDDEVSTATE
= 0x25,
107 PN532_APPERROR_OPERATIONNOTALLOWED
= 0x26,
108 PN532_APPERROR_CMDNOTACCEPTABLE
= 0x27,
109 PN532_APPERROR_TARGETRELEASED
= 0x29,
110 PN532_APPERROR_IDMISMATCH
= 0x2A,
111 PN532_APPERROR_CARDDISAPPEARED
= 0x2B,
112 PN532_APPERROR_NFCID3MISMATCH
= 0x2C,
113 PN532_APPERROR_OVERCURRENTEVENT
= 0x2D,
114 PN532_APPERROR_NADMISSINGINDEP
= 0x2E
117 /* Possible states for the PN532 SW Stack */
118 typedef enum pn532_state_e
126 /* PN532 Protocol control block */
131 pn532_modulation_t modulation
;
132 uint32_t lastCommand
;
136 void pn532PrintHex(const byte_t
* pbtData
, const size_t szBytes
);
137 void pn532PrintHexChar(const byte_t
* pbtData
, const size_t szBytes
);
138 pn532_pcb_t
* pn532GetPCB();
140 pn532_error_t
pn532Read(byte_t
*pbtResponse
, size_t * pszLen
);
141 pn532_error_t
pn532Write(byte_t
*abtCommand
, size_t szLen
);