Generic library for working with PN532-like chips
Fork of PN532 by
PN532Interface.h@3:4189a10038e6, 2013-11-21 (annotated)
- Committer:
- yihui
- Date:
- Thu Nov 21 04:30:49 2013 +0000
- Revision:
- 3:4189a10038e6
- Parent:
- 1:b8cab5222fd0
- Child:
- 6:418ee8924317
sync with https://github.com/Seeed-Studio/PN532/releases/tag/v0.9.
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 | 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 | |
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 | 3:4189a10038e6 | 35 | * @param header packet header |
yihui | 3:4189a10038e6 | 36 | * @param hlen length of header |
yihui | 3:4189a10038e6 | 37 | * @param body packet body |
yihui | 3:4189a10038e6 | 38 | * @param blen length of body |
yihui | 0:9c6b9280c0e1 | 39 | * @return 0 success |
yihui | 0:9c6b9280c0e1 | 40 | * not 0 failed |
yihui | 0:9c6b9280c0e1 | 41 | */ |
yihui | 3:4189a10038e6 | 42 | virtual int8_t writeCommand(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0) = 0; |
yihui | 1:b8cab5222fd0 | 43 | |
yihui | 0:9c6b9280c0e1 | 44 | /** |
yihui | 0:9c6b9280c0e1 | 45 | * @brief read the response of a command, strip prefix and suffix |
yihui | 0:9c6b9280c0e1 | 46 | * @param buf to contain the response data |
yihui | 0:9c6b9280c0e1 | 47 | * @param len lenght to read |
yihui | 0:9c6b9280c0e1 | 48 | * @param timeout max time to wait, 0 means no timeout |
yihui | 0:9c6b9280c0e1 | 49 | * @return >=0 length of response without prefix and suffix |
yihui | 0:9c6b9280c0e1 | 50 | * <0 failed to read response |
yihui | 0:9c6b9280c0e1 | 51 | */ |
yihui | 1:b8cab5222fd0 | 52 | virtual int16_t readResponse(uint8_t buf[], uint8_t len, uint16_t timeout = 1000) = 0; |
yihui | 0:9c6b9280c0e1 | 53 | }; |
yihui | 0:9c6b9280c0e1 | 54 | |
yihui | 0:9c6b9280c0e1 | 55 | #endif |
yihui | 0:9c6b9280c0e1 | 56 |