PN532 NFC library for Seeed Studio's NFC Shield
Fork of PN532 by
PN532Interface.h@0:9c6b9280c0e1, 2013-10-08 (annotated)
- Committer:
- yihui
- Date:
- Tue Oct 08 08:33:22 2013 +0000
- Revision:
- 0:9c6b9280c0e1
- Child:
- 1:b8cab5222fd0
initial, ported from https://github.com/Seeed-Studio/PN532
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:9c6b9280c0e1 | 6 | #define PN532_PREAMBLE (0x00) |
yihui | 0:9c6b9280c0e1 | 7 | #define PN532_STARTCODE1 (0x00) |
yihui | 0:9c6b9280c0e1 | 8 | #define PN532_STARTCODE2 (0xFF) |
yihui | 0:9c6b9280c0e1 | 9 | #define PN532_POSTAMBLE (0x00) |
yihui | 0:9c6b9280c0e1 | 10 | |
yihui | 0:9c6b9280c0e1 | 11 | #define PN532_HOSTTOPN532 (0xD4) |
yihui | 0:9c6b9280c0e1 | 12 | #define PN532_PN532TOHOST (0xD5) |
yihui | 0:9c6b9280c0e1 | 13 | |
yihui | 0:9c6b9280c0e1 | 14 | #define PN532_ACK_WAIT_TIME (10) // ms, timeout of waiting for ACK |
yihui | 0:9c6b9280c0e1 | 15 | |
yihui | 0:9c6b9280c0e1 | 16 | #define PN532_INVALID_ACK (-1) |
yihui | 0:9c6b9280c0e1 | 17 | #define PN532_TIMEOUT (-2) |
yihui | 0:9c6b9280c0e1 | 18 | #define PN532_INVALID_FRAME (-3) |
yihui | 0:9c6b9280c0e1 | 19 | #define PN532_NO_SPACE (-4) |
yihui | 0:9c6b9280c0e1 | 20 | |
yihui | 0:9c6b9280c0e1 | 21 | #define REVERSE_BITS_ORDER(b) b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; \ |
yihui | 0:9c6b9280c0e1 | 22 | b = (b & 0xCC) >> 2 | (b & 0x33) << 2; \ |
yihui | 0:9c6b9280c0e1 | 23 | b = (b & 0xAA) >> 1 | (b & 0x55) << 1 |
yihui | 0:9c6b9280c0e1 | 24 | |
yihui | 0:9c6b9280c0e1 | 25 | class PN532Interface { |
yihui | 0:9c6b9280c0e1 | 26 | public: |
yihui | 0:9c6b9280c0e1 | 27 | virtual void begin() = 0; |
yihui | 0:9c6b9280c0e1 | 28 | virtual void wakeup() = 0; |
yihui | 0:9c6b9280c0e1 | 29 | |
yihui | 0:9c6b9280c0e1 | 30 | /** |
yihui | 0:9c6b9280c0e1 | 31 | * @brief write a command and check ack |
yihui | 0:9c6b9280c0e1 | 32 | * @param buf command to write, not contain prefix and suffix |
yihui | 0:9c6b9280c0e1 | 33 | * @param len lenght of command |
yihui | 0:9c6b9280c0e1 | 34 | * @return 0 success |
yihui | 0:9c6b9280c0e1 | 35 | * not 0 failed |
yihui | 0:9c6b9280c0e1 | 36 | */ |
yihui | 0:9c6b9280c0e1 | 37 | virtual int8_t writeCommand(const uint8_t buf[], uint8_t len) = 0; |
yihui | 0:9c6b9280c0e1 | 38 | |
yihui | 0:9c6b9280c0e1 | 39 | /** |
yihui | 0:9c6b9280c0e1 | 40 | * @brief read the response of a command, strip prefix and suffix |
yihui | 0:9c6b9280c0e1 | 41 | * @param buf to contain the response data |
yihui | 0:9c6b9280c0e1 | 42 | * @param len lenght to read |
yihui | 0:9c6b9280c0e1 | 43 | * @param timeout max time to wait, 0 means no timeout |
yihui | 0:9c6b9280c0e1 | 44 | * @return >=0 length of response without prefix and suffix |
yihui | 0:9c6b9280c0e1 | 45 | * <0 failed to read response |
yihui | 0:9c6b9280c0e1 | 46 | */ |
yihui | 0:9c6b9280c0e1 | 47 | virtual int16_t readResponse(uint8_t buf[], uint8_t len, uint16_t timeout = 1000) = 0; |
yihui | 0:9c6b9280c0e1 | 48 | }; |
yihui | 0:9c6b9280c0e1 | 49 | |
yihui | 0:9c6b9280c0e1 | 50 | #endif |
yihui | 0:9c6b9280c0e1 | 51 |