PN532 NFC library for Seeed Studio's NFC Shield

Fork of PN532 by Yihui Xiong

Committer:
screamer
Date:
Tue Mar 25 16:00:44 2014 +0000
Revision:
6:418ee8924317
Parent:
3:4189a10038e6
Improved documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:9c6b9280c0e1 1
yihui 0:9c6b9280c0e1 2
yihui 0:9c6b9280c0e1 3 #ifndef __PN532_INTERFACE_H__
yihui 0:9c6b9280c0e1 4 #define __PN532_INTERFACE_H__
yihui 0:9c6b9280c0e1 5
yihui 1:b8cab5222fd0 6 #include <stdint.h>
yihui 1:b8cab5222fd0 7
yihui 3:4189a10038e6 8 #define PN532_PREAMBLE (0x00)
yihui 3:4189a10038e6 9 #define PN532_STARTCODE1 (0x00)
yihui 3:4189a10038e6 10 #define PN532_STARTCODE2 (0xFF)
yihui 3:4189a10038e6 11 #define PN532_POSTAMBLE (0x00)
yihui 0:9c6b9280c0e1 12
yihui 3:4189a10038e6 13 #define PN532_HOSTTOPN532 (0xD4)
yihui 3:4189a10038e6 14 #define PN532_PN532TOHOST (0xD5)
yihui 0:9c6b9280c0e1 15
yihui 3:4189a10038e6 16 #define PN532_ACK_WAIT_TIME (10) // ms, timeout of waiting for ACK
yihui 0:9c6b9280c0e1 17
yihui 0:9c6b9280c0e1 18 #define PN532_INVALID_ACK (-1)
yihui 0:9c6b9280c0e1 19 #define PN532_TIMEOUT (-2)
yihui 0:9c6b9280c0e1 20 #define PN532_INVALID_FRAME (-3)
yihui 0:9c6b9280c0e1 21 #define PN532_NO_SPACE (-4)
yihui 0:9c6b9280c0e1 22
yihui 0:9c6b9280c0e1 23 #define REVERSE_BITS_ORDER(b) b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; \
yihui 3:4189a10038e6 24 b = (b & 0xCC) >> 2 | (b & 0x33) << 2; \
yihui 3:4189a10038e6 25 b = (b & 0xAA) >> 1 | (b & 0x55) << 1
yihui 0:9c6b9280c0e1 26
screamer 6:418ee8924317 27 /**
screamer 6:418ee8924317 28 * The PN532Interface class
screamer 6:418ee8924317 29 */
yihui 1:b8cab5222fd0 30 class PN532Interface
yihui 1:b8cab5222fd0 31 {
yihui 0:9c6b9280c0e1 32 public:
yihui 0:9c6b9280c0e1 33 virtual void begin() = 0;
yihui 0:9c6b9280c0e1 34 virtual void wakeup() = 0;
yihui 1:b8cab5222fd0 35
yihui 0:9c6b9280c0e1 36 /**
screamer 6:418ee8924317 37 * @brief write a command and check ack
screamer 6:418ee8924317 38 * @param header packet header
screamer 6:418ee8924317 39 * @param hlen length of header
screamer 6:418ee8924317 40 * @param body packet body
screamer 6:418ee8924317 41 * @param blen length of body
screamer 6:418ee8924317 42 * @return 0 success
screamer 6:418ee8924317 43 * not 0 failed
screamer 6:418ee8924317 44 */
yihui 3:4189a10038e6 45 virtual int8_t writeCommand(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0) = 0;
yihui 1:b8cab5222fd0 46
yihui 0:9c6b9280c0e1 47 /**
screamer 6:418ee8924317 48 * @brief read the response of a command, strip prefix and suffix
screamer 6:418ee8924317 49 * @param buf to contain the response data
screamer 6:418ee8924317 50 * @param len lenght to read
screamer 6:418ee8924317 51 * @param timeout max time to wait, 0 means no timeout
screamer 6:418ee8924317 52 * @return >=0 length of response without prefix and suffix
screamer 6:418ee8924317 53 * <0 failed to read response
screamer 6:418ee8924317 54 */
yihui 1:b8cab5222fd0 55 virtual int16_t readResponse(uint8_t buf[], uint8_t len, uint16_t timeout = 1000) = 0;
yihui 0:9c6b9280c0e1 56 };
yihui 0:9c6b9280c0e1 57
yihui 0:9c6b9280c0e1 58 #endif
yihui 0:9c6b9280c0e1 59