PN532 NFC library for Seeed Studio's NFC Shield

Fork of PN532 by Yihui Xiong

Committer:
yihui
Date:
Thu Oct 17 06:37:26 2013 +0000
Revision:
1:b8cab5222fd0
Parent:
0:9c6b9280c0e1
Child:
3:4189a10038e6
format code

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 0:9c6b9280c0e1 8 #define PN532_PREAMBLE (0x00)
yihui 0:9c6b9280c0e1 9 #define PN532_STARTCODE1 (0x00)
yihui 0:9c6b9280c0e1 10 #define PN532_STARTCODE2 (0xFF)
yihui 0:9c6b9280c0e1 11 #define PN532_POSTAMBLE (0x00)
yihui 0:9c6b9280c0e1 12
yihui 0:9c6b9280c0e1 13 #define PN532_HOSTTOPN532 (0xD4)
yihui 0:9c6b9280c0e1 14 #define PN532_PN532TOHOST (0xD5)
yihui 0:9c6b9280c0e1 15
yihui 0:9c6b9280c0e1 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 1:b8cab5222fd0 24 b = (b & 0xCC) >> 2 | (b & 0x33) << 2; \
yihui 1:b8cab5222fd0 25 b = (b & 0xAA) >> 1 | (b & 0x55) << 1
yihui 0:9c6b9280c0e1 26
yihui 1:b8cab5222fd0 27 class PN532Interface
yihui 1:b8cab5222fd0 28 {
yihui 0:9c6b9280c0e1 29 public:
yihui 0:9c6b9280c0e1 30 virtual void begin() = 0;
yihui 0:9c6b9280c0e1 31 virtual void wakeup() = 0;
yihui 1:b8cab5222fd0 32
yihui 0:9c6b9280c0e1 33 /**
yihui 0:9c6b9280c0e1 34 * @brief write a command and check ack
yihui 0:9c6b9280c0e1 35 * @param buf command to write, not contain prefix and suffix
yihui 0:9c6b9280c0e1 36 * @param len lenght of command
yihui 0:9c6b9280c0e1 37 * @return 0 success
yihui 0:9c6b9280c0e1 38 * not 0 failed
yihui 0:9c6b9280c0e1 39 */
yihui 0:9c6b9280c0e1 40 virtual int8_t writeCommand(const uint8_t buf[], uint8_t len) = 0;
yihui 1:b8cab5222fd0 41
yihui 0:9c6b9280c0e1 42 /**
yihui 0:9c6b9280c0e1 43 * @brief read the response of a command, strip prefix and suffix
yihui 0:9c6b9280c0e1 44 * @param buf to contain the response data
yihui 0:9c6b9280c0e1 45 * @param len lenght to read
yihui 0:9c6b9280c0e1 46 * @param timeout max time to wait, 0 means no timeout
yihui 0:9c6b9280c0e1 47 * @return >=0 length of response without prefix and suffix
yihui 0:9c6b9280c0e1 48 * <0 failed to read response
yihui 0:9c6b9280c0e1 49 */
yihui 1:b8cab5222fd0 50 virtual int16_t readResponse(uint8_t buf[], uint8_t len, uint16_t timeout = 1000) = 0;
yihui 0:9c6b9280c0e1 51 };
yihui 0:9c6b9280c0e1 52
yihui 0:9c6b9280c0e1 53 #endif
yihui 0:9c6b9280c0e1 54