Guest User

PN352.H

a guest
Mar 17th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.66 KB | None | 0 0
  1. // PN532 library by adafruit/ladyada
  2. // MIT license
  3.  
  4. // authenticateBlock, readMemoryBlock, writeMemoryBlock contributed
  5. // by Seeed Technology Inc (www.seeedstudio.com)
  6.  
  7. #ifndef __PN532_H__
  8. #define __PN532_H__
  9.  
  10. #include <Arduino.h>
  11. #include <SPI.h>
  12.  
  13. //#define PN532DEBUG 1
  14.  
  15. /*If define PN532_P2P_DEBUG, all the data that initiator and target received */
  16. /*in the peer to peer communication, will be printed in the serial port tool window*/
  17. //#define PN532_P2P_DEBUG 1
  18.  
  19. #define PN532_PREAMBLE 0x00
  20. #define PN532_STARTCODE1 0x00
  21. #define PN532_STARTCODE2 0xFF
  22. #define PN532_POSTAMBLE 0x00
  23.  
  24. #define PN532_HOSTTOPN532 0xD4
  25.  
  26. #define PN532_FIRMWAREVERSION 0x02
  27. #define PN532_GETGENERALSTATUS 0x04
  28. #define PN532_SAMCONFIGURATION  0x14
  29. #define PN532_INLISTPASSIVETARGET 0x4A
  30. #define PN532_INDATAEXCHANGE 0x40
  31. #define PN532_INJUMPFORDEP 0x56
  32. #define PN532_TGINITASTARGET 0x8C
  33. #define PN532_TGGETDATA 0x86
  34. #define PN532_TGSETDATA 0x8E
  35.  
  36. #define PN532_MIFARE_READ 0x30
  37. #define PN532_MIFARE_WRITE 0xA0
  38.  
  39. #define PN532_AUTH_WITH_KEYA 0x60
  40. #define PN532_AUTH_WITH_KEYB 0x61
  41.  
  42.  
  43. #define PN532_WAKEUP 0x55
  44.  
  45. #define  PN532_SPI_STATREAD  0x02
  46. #define  PN532_SPI_DATAWRITE 0x01
  47. #define  PN532_SPI_DATAREAD  0x03
  48.  
  49. #define  PN532_SPI_READY  0x01
  50.  
  51. #define PN532_MIFARE_ISO14443A 0x0
  52.  
  53. #define KEY_A   1
  54. #define KEY_B   2
  55.  
  56. #define PN532_BAUDRATE_201K 1
  57. #define PN532_BAUDRATE_424K 2
  58.  
  59. class PN532{
  60. public:
  61.   PN532(uint8_t cs);
  62.   void begin(void);        
  63.   boolean SAMConfig(void);
  64.   uint32_t getFirmwareVersion(void);
  65.   uint32_t readPassiveTargetID(uint8_t cardbaudrate);
  66.   uint32_t authenticateBlock(   uint8_t cardnumber /*1 or 2*/,
  67.   uint32_t cid /*Card NUID*/,
  68.   uint8_t blockaddress /*0 to 63*/,
  69.   uint8_t authtype /*Either KEY_A or KEY_B */,
  70.   uint8_t* keys);
  71.   boolean readMemoryBlock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 to 63*/, uint8_t * block);
  72.   boolean writeMemoryBlock(uint8_t cardnumber /*1 or 2*/,uint8_t blockaddress /*0 to 63*/, uint8_t * block);
  73.  
  74.   uint32_t configurePeerAsInitiator(uint8_t baudrate /* Any number from 0-2. 0 for 106kbps or 1 for 201kbps or 2 for 424kbps */); //106kps is not supported
  75.   uint32_t configurePeerAsTarget();
  76.   boolean initiatorTxRx(char* dataOut,char* dataIn);
  77.   uint32_t targetTxRx(char* dataOut,char* dataIn);
  78.  
  79.   boolean sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout = 1000);
  80.  
  81. private:
  82.   uint8_t _cs;//Chip seclect pin for PN532 is optional.
  83.   SPIClass pn532_SPI;
  84.  
  85.   void write(uint8_t _data);
  86.   uint8_t read(void);
  87.   uint8_t readSpiStatus(void);
  88.   boolean checkSpiAck();
  89.   void read(uint8_t* buff, uint8_t n);
  90.   void writeCommand(uint8_t* cmd, uint8_t cmdlen);
  91. };
  92.  
  93. #endif
Add Comment
Please, Sign In to add comment