some additional fixes

Fork of PN532 by Seeed

Revision:
3:4189a10038e6
Parent:
2:f618fb2169c4
Child:
5:51f820fbd18a
Child:
6:418ee8924317
--- a/PN532.h	Thu Oct 17 06:51:32 2013 +0000
+++ b/PN532.h	Thu Nov 21 04:30:49 2013 +0000
@@ -1,37 +1,17 @@
 /**************************************************************************/
 /*!
     @file     PN532.h
-    @author   Adafruit Industries & Seeed Technology Inc.
-
-    NXP's PN532 NFC/13.56MHz RFID Transceiver
-
-    @section  HISTORY
-    v1.6 - Ported to mbed
-
-    v1.3  - Modified to work with I2C
-
-    v1.1  - Added full command list
-          - Added 'verbose' mode flag to constructor to toggle debug output
-          - Changed readPassiveTargetID() to return variable length values
-
+    @author   Adafruit Industries & Seeed Studio
+    @license  BSD
 */
 /**************************************************************************/
 
-#ifndef PN532_h
-#define PN532_h
+#ifndef __PN532_H__
+#define __PN532_H__
 
 #include <stdint.h>
-#include "mbed.h"
 #include "PN532Interface.h"
 
-#define PN532_PREAMBLE                      (0x00)
-#define PN532_STARTCODE1                    (0x00)
-#define PN532_STARTCODE2                    (0xFF)
-#define PN532_POSTAMBLE                     (0x00)
-
-#define PN532_HOSTTOPN532                   (0xD4)
-#define PN532_PN532TOHOST                   (0xD5)
-
 // PN532 Commands
 #define PN532_COMMAND_DIAGNOSE              (0x00)
 #define PN532_COMMAND_GETFIRMWAREVERSION    (0x02)
@@ -70,14 +50,6 @@
 #define PN532_RESPONSE_INLISTPASSIVETARGET  (0x4B)
 
 
-#define PN532_WAKEUP                        (0x55)
-
-#define PN532_I2C_ADDRESS                   (0x48 >> 1)
-#define PN532_I2C_READBIT                   (0x01)
-#define PN532_I2C_BUSY                      (0x00)
-#define PN532_I2C_READY                     (0x01)
-#define PN532_I2C_READYTIMEOUT              (20)
-
 #define PN532_MIFARE_ISO14443A              (0x00)
 
 // Mifare Commands
@@ -136,15 +108,10 @@
 #define PN532_GPIO_P34                      (4)
 #define PN532_GPIO_P35                      (5)
 
-//#define PN532DEBUG
-
 class PN532
 {
 public:
     PN532(PN532Interface &interface);
-    PN532(PinName mosi, PinName miso, PinName sclk, PinName cs);
-
-    ~PN532();
 
     void begin(void);
 
@@ -155,9 +122,20 @@
     uint8_t readGPIO(void);
     bool setPassiveActivationRetries(uint8_t maxRetries);
 
-    int8_t tgInitAsTarget();
-    int16_t tgGetData(uint8_t *buf, uint16_t len);
-    bool tgSetData(const uint8_t *buf, uint16_t len);
+    /**
+    * @brief    Init PN532 as a target
+    * @param    timeout max time to wait, 0 means no timeout
+    * @return   > 0     success
+    *           = 0     timeout
+    *           < 0     failed
+    */
+    int8_t tgInitAsTarget(uint16_t timeout = 0);
+    int8_t tgInitAsTarget(const uint8_t* command, const uint8_t len, const uint16_t timeout = 0);
+
+    int16_t tgGetData(uint8_t *buf, uint8_t len);
+    bool tgSetData(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0);
+
+    int16_t inRelease(const uint8_t relevantTarget = 0);
 
     // ISO14443A functions
     bool inListPassiveTarget();
@@ -180,14 +158,20 @@
     static void PrintHex(const uint8_t *data, const uint32_t numBytes);
     static void PrintHexChar(const uint8_t *pbtData, const uint32_t numBytes);
 
+    uint8_t *getBuffer(uint8_t *len) {
+        *len = sizeof(pn532_packetbuffer) - 4;
+        return pn532_packetbuffer;
+    };
+
 private:
     uint8_t _uid[7];  // ISO14443A uid
     uint8_t _uidLen;  // uid len
     uint8_t _key[6];  // Mifare Classic key
     uint8_t inListedTag; // Tg number of inlisted tag.
 
+    uint8_t pn532_packetbuffer[64];
+
     PN532Interface *_interface;
-    SPI *_spi;
 };
 
 #endif