1 /**************************************************************************/
5 /**************************************************************************/
9 #include "pn532_drvr.h"
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 PN532_DEBUG("%02x ", pbtData
[szPos
]);
30 PN532_DEBUG(CFG_PRINTF_NEWLINE
);
33 /**************************************************************************/
35 @brief Gets a reference to the PN532 peripheral control block,
36 which can be used to determine that state of the PN532
39 /**************************************************************************/
40 pn532_pcb_t
* pn532GetPCB()
45 /**************************************************************************/
47 @brief Initialises the appropriate serial bus (UART, etc.),and
48 sets up any buffers or peripherals required by the PN532.
50 /**************************************************************************/
53 // Clear protocol control blocks
54 memset(&pcb
, 0, sizeof(pn532_pcb_t
));
56 // Initialise the underlying HW
59 // Set the PCB flags to an appropriate state
60 pcb
.initialised
= TRUE
;
63 /**************************************************************************/
65 @brief Configures the PN532 for a specific modulation and
68 /**************************************************************************/
69 pn532_error_t
pn532Configure(pn532_modulation_t mod
)
73 return PN532_ERROR_NONE
;
76 /**************************************************************************/
78 @brief Reads the response buffer from the PN532
81 The byte array containg the command and any
84 The number of bytes in abtCommand
86 /**************************************************************************/
87 pn532_error_t
pn532Read(byte_t
* abtResponse
, size_t * pszLen
)
89 if (!pcb
.initialised
) pn532Init();
91 // Try to wake the device up if it's in sleep mode
92 if (pcb
.state
== PN532_STATE_SLEEP
)
94 pn532_error_t wakeupError
= pn532Wakeup();
101 // Read the response if the device is in an appropriate state
102 if (pcb
.state
== PN532_STATE_READY
)
104 return pn532ReadResponse(abtResponse
, pszLen
);
108 PN532_DEBUG("Init Failed%s", CFG_PRINTF_NEWLINE
);
109 return PN532_ERROR_UNABLETOINIT
;
113 /**************************************************************************/
115 @brief Sends a byte array of command and parameter data to the
116 PN532, starting with the command byte. The frame's
117 preamble, checksums, postamble and frame identifier (0xD4)
118 will all be automatically added.
121 The byte array containg the command and any
124 The number of bytes in abtCommand
126 /**************************************************************************/
127 pn532_error_t
pn532Write(byte_t
* abtCommand
, size_t szLen
)
129 if (!pcb
.initialised
) pn532Init();
131 // Try to wake the device up if it's in sleep mode
132 if (pcb
.state
== PN532_STATE_SLEEP
)
134 pn532_error_t wakeupError
= pn532Wakeup();
141 // Send the command if the device is in an appropriate state
142 if (pcb
.state
== PN532_STATE_READY
)
144 return pn532SendCommand(abtCommand
, szLen
);
148 PN532_DEBUG("Init Failed%s", CFG_PRINTF_NEWLINE
);
149 return PN532_ERROR_UNABLETOINIT
;