1 /**************************************************************************/
5 /**************************************************************************/
10 #include "core/systick/systick.h"
11 #include "core/uart/uart.h"
13 static pn532_pcb_t pcb
;
15 /**************************************************************************/
17 @brief Prints a hexadecimal value in plain characters
19 @param pbtData Pointer to the byte data
20 @param szBytes Data length in bytes
22 /**************************************************************************/
23 void pn532PrintHex(const byte_t
* pbtData
, const size_t szBytes
)
26 for (szPos
=0; szPos
< szBytes
; szPos
++)
28 printf("%02x ", pbtData
[szPos
]);
30 printf(CFG_PRINTF_NEWLINE
);
33 /**************************************************************************/
35 @brief Prints a hexadecimal value in plain characters, along with
36 the char equivalents in the following format
38 AA BB CC DD EE FF ......
40 @param pbtData Pointer to the byte data
41 @param szBytes Data length in bytes
43 /**************************************************************************/
44 void pn532PrintHexChar(const byte_t
* pbtData
, const size_t szBytes
)
47 for (szPos
=0; szPos
< szBytes
; szPos
++)
49 printf("%02x", pbtData
[szPos
]);
52 for (szPos
=0; szPos
< szBytes
; szPos
++)
54 printf("%c", pbtData
[szPos
] <= 0x1F ? '.' : pbtData
[szPos
]);
56 printf(CFG_PRINTF_NEWLINE
);
59 /**************************************************************************/
61 @brief Gets a reference to the PN532 peripheral control block,
62 which can be used to determine that state of the PN532
65 /**************************************************************************/
66 pn532_pcb_t
* pn532GetPCB()
71 /**************************************************************************/
73 @brief Initialises the appropriate serial bus (UART, etc.),and
74 sets up any buffers or peripherals required by the PN532.
76 /**************************************************************************/
79 // Clear protocol control blocks
80 memset(&pcb
, 0, sizeof(pn532_pcb_t
));
82 // Initialise the underlying HW
85 // Set the PCB flags to an appropriate state
86 pcb
.initialised
= TRUE
;
89 /**************************************************************************/
91 @brief Reads the response buffer from the PN532
94 The byte array that will hold the response data
96 Pointer to the number of bytes in pbtCommand
98 /**************************************************************************/
99 pn532_error_t
pn532Read(byte_t
* pbtResponse
, size_t * pszLen
)
101 if (!pcb
.initialised
) pn532Init();
103 // Try to wake the device up if it's in sleep mode
104 if (pcb
.state
== PN532_STATE_SLEEP
)
106 pn532_error_t wakeupError
= pn532_bus_Wakeup();
111 // Read the response if the device is in an appropriate state
112 if (pcb
.state
== PN532_STATE_READY
)
114 return pn532_bus_ReadResponse(pbtResponse
, pszLen
);
118 #ifdef PN532_DEBUGMODE
119 PN532_DEBUG("Init Failed%s", CFG_PRINTF_NEWLINE
);
121 return PN532_ERROR_UNABLETOINIT
;
125 /**************************************************************************/
127 @brief Sends a byte array of command and parameter data to the
128 PN532, starting with the command byte. The frame's
129 preamble, checksums, postamble and frame identifier (0xD4)
130 will all be automatically added.
133 The byte array containg the command and any
136 The number of bytes in abtCommand
138 /**************************************************************************/
139 pn532_error_t
pn532Write(byte_t
* abtCommand
, size_t szLen
)
141 if (!pcb
.initialised
) pn532Init();
143 // Try to wake the device up if it's in sleep mode
144 if (pcb
.state
== PN532_STATE_SLEEP
)
146 pn532_error_t wakeupError
= pn532_bus_Wakeup();
151 // Send the command if the device is in an appropriate state
152 if (pcb
.state
== PN532_STATE_READY
)
154 return pn532_bus_SendCommand(abtCommand
, szLen
);
158 #ifdef PN532_DEBUGMODE
159 PN532_DEBUG("Init Failed%s", CFG_PRINTF_NEWLINE
);
161 return PN532_ERROR_UNABLETOINIT
;