PN532 NFC library for Seeed Studio's NFC Shield

Fork of PN532 by Yihui Xiong

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PN532Interface.h Source File

PN532Interface.h

00001 
00002 
00003 #ifndef __PN532_INTERFACE_H__
00004 #define __PN532_INTERFACE_H__
00005 
00006 #include <stdint.h>
00007 
00008 #define PN532_PREAMBLE                (0x00)
00009 #define PN532_STARTCODE1              (0x00)
00010 #define PN532_STARTCODE2              (0xFF)
00011 #define PN532_POSTAMBLE               (0x00)
00012 
00013 #define PN532_HOSTTOPN532             (0xD4)
00014 #define PN532_PN532TOHOST             (0xD5)
00015 
00016 #define PN532_ACK_WAIT_TIME           (10)  // ms, timeout of waiting for ACK
00017 
00018 #define PN532_INVALID_ACK             (-1)
00019 #define PN532_TIMEOUT                 (-2)
00020 #define PN532_INVALID_FRAME           (-3)
00021 #define PN532_NO_SPACE                (-4)
00022 
00023 #define REVERSE_BITS_ORDER(b)         b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; \
00024                                       b = (b & 0xCC) >> 2 | (b & 0x33) << 2; \
00025                                       b = (b & 0xAA) >> 1 | (b & 0x55) << 1
00026 
00027 /**
00028  * The PN532Interface class
00029  */
00030 class PN532Interface
00031 {
00032 public:
00033     virtual void begin() = 0;
00034     virtual void wakeup() = 0;
00035 
00036     /**
00037      * @brief    write a command and check ack
00038      * @param    header  packet header
00039      * @param    hlen    length of header
00040      * @param    body    packet body
00041      * @param    blen    length of body
00042      * @return   0       success
00043      *           not 0   failed
00044      */
00045     virtual int8_t writeCommand(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0) = 0;
00046 
00047     /**
00048      * @brief    read the response of a command, strip prefix and suffix
00049      * @param    buf     to contain the response data
00050      * @param    len     lenght to read
00051      * @param    timeout max time to wait, 0 means no timeout
00052      * @return   >=0     length of response without prefix and suffix
00053      *           <0      failed to read response
00054      */
00055     virtual int16_t readResponse(uint8_t buf[], uint8_t len, uint16_t timeout = 1000) = 0;
00056 };
00057 
00058 #endif
00059