Skip to content
Browse files

License text, fixed baud rate, rename

  • Loading branch information...
1 parent 18d7144 commit ecff1ce3e60fec390ad67a7d890940b8ed1ec3dd @ladyada ladyada committed
View
80 PN532.cpp → Adafruit_PN532.cpp
@@ -1,11 +1,23 @@
/**************************************************************************/
/*!
- @file PN532.cpp
+ @file Adafruit_PN532.cpp
@author Adafruit Industries
@license BSD (see license.txt)
SPI Driver for NXP's PN532 NFC/13.56MHz RFID Transceiver
-
+
+ This is a library for the Adafruit PN532 NFC/RFID breakout boards
+ This library works with the Adafruit NFC breakout
+ ----> https://www.adafruit.com/products/364
+
+ Check out the links above for our tutorials and wiring diagrams
+ These chips use SPI to communicate, 4 required to interface
+
+ Adafruit invests time and resources providing this open source code,
+ please support Adafruit and open-source hardware by purchasing
+ products from Adafruit!
+
+
@section HISTORY
v1.2 - Added writeGPIO()
@@ -26,7 +38,7 @@
*/
/**************************************************************************/
#include <WProgram.h>
-#include "PN532.h"
+#include "Adafruit_PN532.h"
byte pn532ack[] = {0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00};
byte pn532response_firmwarevers[] = {0x00, 0xFF, 0x06, 0xFA, 0xD5, 0x03};
@@ -48,7 +60,7 @@ byte pn532_packetbuffer[PN532_PACKBUFFSIZ];
@param ss SPI chip select pin (CS/SSEL)
*/
/**************************************************************************/
-PN532::PN532(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss) {
+Adafruit_PN532::Adafruit_PN532(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss) {
_clk = clk;
_miso = miso;
_mosi = mosi;
@@ -65,7 +77,7 @@ PN532::PN532(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss) {
@brief Setups the HW
*/
/**************************************************************************/
-void PN532::begin() {
+void Adafruit_PN532::begin() {
digitalWrite(_ss, LOW);
delay(1000);
@@ -85,7 +97,7 @@ void PN532::begin() {
@param numBytes Data length in bytes
*/
/**************************************************************************/
-void PN532::PrintHex(const byte * data, const uint32_t numBytes)
+void Adafruit_PN532::PrintHex(const byte * data, const uint32_t numBytes)
{
uint32_t szPos;
for (szPos=0; szPos < numBytes; szPos++)
@@ -114,7 +126,7 @@ void PN532::PrintHex(const byte * data, const uint32_t numBytes)
@param numBytes Data length in bytes
*/
/**************************************************************************/
-void PN532::PrintHexChar(const byte * data, const uint32_t numBytes)
+void Adafruit_PN532::PrintHexChar(const byte * data, const uint32_t numBytes)
{
uint32_t szPos;
for (szPos=0; szPos < numBytes; szPos++)
@@ -146,7 +158,7 @@ void PN532::PrintHexChar(const byte * data, const uint32_t numBytes)
@returns The chip's firmware version and ID
*/
/**************************************************************************/
-uint32_t PN532::getFirmwareVersion(void) {
+uint32_t Adafruit_PN532::getFirmwareVersion(void) {
uint32_t response;
pn532_packetbuffer[0] = PN532_COMMAND_GETFIRMWAREVERSION;
@@ -187,7 +199,7 @@ uint32_t PN532::getFirmwareVersion(void) {
*/
/**************************************************************************/
// default timeout of one second
-boolean PN532::sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout) {
+boolean Adafruit_PN532::sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout) {
uint16_t timer = 0;
// write the command
@@ -243,7 +255,7 @@ boolean PN532::sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeou
@returns 1 if everything executed properly, 0 for an error
*/
/**************************************************************************/
-boolean PN532::writeGPIO(uint8_t pinstate) {
+boolean Adafruit_PN532::writeGPIO(uint8_t pinstate) {
uint8_t errorbit;
// Make sure pinstate does not try to toggle P32 or P34
@@ -288,7 +300,7 @@ boolean PN532::writeGPIO(uint8_t pinstate) {
pinState[5] = P35
*/
/**************************************************************************/
-uint8_t PN532::readGPIO(void) {
+uint8_t Adafruit_PN532::readGPIO(void) {
pn532_packetbuffer[0] = PN532_COMMAND_READGPIO;
// Send the READGPIO command (0x0C)
@@ -338,7 +350,7 @@ uint8_t PN532::readGPIO(void) {
@brief Configures the SAM (Secure Access Module)
*/
/**************************************************************************/
-boolean PN532::SAMConfig(void) {
+boolean Adafruit_PN532::SAMConfig(void) {
pn532_packetbuffer[0] = PN532_COMMAND_SAMCONFIGURATION;
pn532_packetbuffer[1] = 0x01; // normal mode;
pn532_packetbuffer[2] = 0x14; // timeout 50ms * 20 = 1 second
@@ -368,7 +380,7 @@ boolean PN532::SAMConfig(void) {
@returns 1 if everything executed properly, 0 for an error
*/
/**************************************************************************/
-boolean PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t * uidLength) {
+boolean Adafruit_PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t * uidLength) {
pn532_packetbuffer[0] = PN532_COMMAND_INLISTPASSIVETARGET;
pn532_packetbuffer[1] = 1; // max 1 cards at once (we can set this to 2 later)
pn532_packetbuffer[2] = cardbaudrate;
@@ -434,7 +446,7 @@ boolean PN532::readPassiveTargetID(uint8_t cardbaudrate, uint8_t * uid, uint8_t
in the sector (block 0 relative to the current sector)
*/
/**************************************************************************/
-bool PN532::mifareclassic_IsFirstBlock (uint32_t uiBlock)
+bool Adafruit_PN532::mifareclassic_IsFirstBlock (uint32_t uiBlock)
{
// Test if we are in the small or big sectors
if (uiBlock < 128)
@@ -448,7 +460,7 @@ bool PN532::mifareclassic_IsFirstBlock (uint32_t uiBlock)
Indicates whether the specified block number is the sector trailer
*/
/**************************************************************************/
-bool PN532::mifareclassic_IsTrailerBlock (uint32_t uiBlock)
+bool Adafruit_PN532::mifareclassic_IsTrailerBlock (uint32_t uiBlock)
{
// Test if we are in the small or big sectors
if (uiBlock < 128)
@@ -476,7 +488,7 @@ bool PN532::mifareclassic_IsTrailerBlock (uint32_t uiBlock)
@returns 1 if everything executed properly, 0 for an error
*/
/**************************************************************************/
-uint8_t PN532::mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t * keyData)
+uint8_t Adafruit_PN532::mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t * keyData)
{
uint8_t len;
uint8_t i;
@@ -488,9 +500,9 @@ uint8_t PN532::mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t uidLen, u
#ifdef MIFAREDEBUG
Serial.print("Trying to authenticate card ");
- PN532::PrintHex(_uid, _uidLen);
+ Adafruit_PN532::PrintHex(_uid, _uidLen);
Serial.print("Using authentication KEY ");Serial.print(keyNumber ? 'B' : 'A');Serial.print(": ");
- PN532::PrintHex(_key, 6);
+ Adafruit_PN532::PrintHex(_key, 6);
#endif
// Prepare the authentication command //
@@ -531,7 +543,7 @@ uint8_t PN532::mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t uidLen, u
@returns 1 if everything executed properly, 0 for an error
*/
/**************************************************************************/
-uint8_t PN532::mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t * data)
+uint8_t Adafruit_PN532::mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t * data)
{
#ifdef MIFAREDEBUG
Serial.print("Trying to read 16 bytes from block ");Serial.println(blockNumber);
@@ -560,7 +572,7 @@ uint8_t PN532::mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t * data)
{
//#ifdef MIFAREDEBUG
Serial.println("Unexpected response");
- PN532::PrintHexChar(pn532_packetbuffer, 26);
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 26);
//#endif
return 0;
}
@@ -573,7 +585,7 @@ uint8_t PN532::mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t * data)
#ifdef MIFAREDEBUG
Serial.print("Block ");
Serial.println(blockNumber);
- PN532::PrintHexChar(data, 16);
+ Adafruit_PN532::PrintHexChar(data, 16);
#endif
return 1;
@@ -591,7 +603,7 @@ uint8_t PN532::mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t * data)
@returns 1 if everything executed properly, 0 for an error
*/
/**************************************************************************/
-uint8_t PN532::mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t * data)
+uint8_t Adafruit_PN532::mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t * data)
{
#ifdef MIFAREDEBUG
Serial.print("Trying to write 16 bytes to block ");Serial.println(blockNumber);
@@ -627,7 +639,7 @@ uint8_t PN532::mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t * data
@returns 1 if everything executed properly, 0 for an error
*/
/**************************************************************************/
-uint8_t PN532::mifareclassic_FormatNDEF (void)
+uint8_t Adafruit_PN532::mifareclassic_FormatNDEF (void)
{
uint8_t sectorbuffer1[16] = {0x14, 0x01, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1};
uint8_t sectorbuffer2[16] = {0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1, 0x03, 0xE1};
@@ -664,7 +676,7 @@ uint8_t PN532::mifareclassic_FormatNDEF (void)
@returns 1 if everything executed properly, 0 for an error
*/
/**************************************************************************/
-uint8_t PN532::mifareclassic_WriteNDEFURI (uint8_t sectorNumber, uint8_t uriIdentifier, const char * url)
+uint8_t Adafruit_PN532::mifareclassic_WriteNDEFURI (uint8_t sectorNumber, uint8_t uriIdentifier, const char * url)
{
// Figure out how long the string is
uint8_t len = strlen(url);
@@ -742,7 +754,7 @@ uint8_t PN532::mifareclassic_WriteNDEFURI (uint8_t sectorNumber, uint8_t uriIden
retrieved data (if any)
*/
/**************************************************************************/
-uint8_t PN532::mifareultralight_ReadPage (uint8_t page, uint8_t * buffer)
+uint8_t Adafruit_PN532::mifareultralight_ReadPage (uint8_t page, uint8_t * buffer)
{
if (page >= 64)
{
@@ -775,7 +787,7 @@ uint8_t PN532::mifareultralight_ReadPage (uint8_t page, uint8_t * buffer)
readspidata(pn532_packetbuffer, 26);
#ifdef MIFAREDEBUG
Serial.println("Received: ");
- PN532::PrintHexChar(pn532_packetbuffer, 26);
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 26);
#endif
/* If byte 8 isn't 0x00 we probably have an error */
@@ -792,7 +804,7 @@ uint8_t PN532::mifareultralight_ReadPage (uint8_t page, uint8_t * buffer)
{
#ifdef MIFAREDEBUG
Serial.println("Unexpected response reading block: ");
- PN532::PrintHexChar(pn532_packetbuffer, 26);
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 26);
#endif
return 0;
}
@@ -800,7 +812,7 @@ uint8_t PN532::mifareultralight_ReadPage (uint8_t page, uint8_t * buffer)
/* Display data for debug if requested */
#ifdef MIFAREDEBUG
Serial.print("Page ");Serial.print(page);Serial.println(":");
- PN532::PrintHexChar(buffer, 4);
+ Adafruit_PN532::PrintHexChar(buffer, 4);
#endif
// Return OK signal
@@ -817,7 +829,7 @@ uint8_t PN532::mifareultralight_ReadPage (uint8_t page, uint8_t * buffer)
@brief Tries to read the SPI ACK signal
*/
/**************************************************************************/
-boolean PN532::spi_readack() {
+boolean Adafruit_PN532::spi_readack() {
uint8_t ackbuff[6];
readspidata(ackbuff, 6);
@@ -832,7 +844,7 @@ boolean PN532::spi_readack() {
@brief Reads the SPI status register (to know if the PN532 is ready)
*/
/**************************************************************************/
-uint8_t PN532::readspistatus(void) {
+uint8_t Adafruit_PN532::readspistatus(void) {
digitalWrite(_ss, LOW);
delay(2);
spiwrite(PN532_SPI_STATREAD);
@@ -851,7 +863,7 @@ uint8_t PN532::readspistatus(void) {
@param n Number of bytes to be read
*/
/**************************************************************************/
-void PN532::readspidata(uint8_t* buff, uint8_t n) {
+void Adafruit_PN532::readspidata(uint8_t* buff, uint8_t n) {
digitalWrite(_ss, LOW);
delay(2);
spiwrite(PN532_SPI_DATAREAD);
@@ -884,7 +896,7 @@ void PN532::readspidata(uint8_t* buff, uint8_t n) {
@param cmdlen Command length in bytes
*/
/**************************************************************************/
-void PN532::spiwritecommand(uint8_t* cmd, uint8_t cmdlen) {
+void Adafruit_PN532::spiwritecommand(uint8_t* cmd, uint8_t cmdlen) {
uint8_t checksum;
cmdlen++;
@@ -944,7 +956,7 @@ void PN532::spiwritecommand(uint8_t* cmd, uint8_t cmdlen) {
@param c 8-bit command to write to the SPI bus
*/
/**************************************************************************/
-void PN532::spiwrite(uint8_t c) {
+void Adafruit_PN532::spiwrite(uint8_t c) {
int8_t i;
digitalWrite(_clk, HIGH);
@@ -966,7 +978,7 @@ void PN532::spiwrite(uint8_t c) {
@returns The 8-bit value that was read from the SPI bus
*/
/**************************************************************************/
-uint8_t PN532::spiread(void) {
+uint8_t Adafruit_PN532::spiread(void) {
int8_t i, x;
x = 0;
digitalWrite(_clk, HIGH);
View
18 PN532.h → Adafruit_PN532.h
@@ -1,9 +1,21 @@
/**************************************************************************/
/*!
- @file PN532.h
+ @file Adafruit_PN532.h
@author Adafruit Industries
@license BSD (see license.txt)
+
+ This is a library for the Adafruit PN532 NFC/RFID breakout boards
+ This library works with the Adafruit NFC breakout
+ ----> https://www.adafruit.com/products/364
+
+ Check out the links above for our tutorials and wiring diagrams
+ These chips use SPI to communicate, 4 required to interface
+
+ Adafruit invests time and resources providing this open source code,
+ please support Adafruit and open-source hardware by purchasing
+ products from Adafruit!
+
@section HISTORY
v1.1 - Added full command list
@@ -121,9 +133,9 @@
#define PN532_GPIO_P34 (4)
#define PN532_GPIO_P35 (5)
-class PN532{
+class Adafruit_PN532{
public:
- PN532(uint8_t cs, uint8_t clk, uint8_t mosi, uint8_t miso);
+ Adafruit_PN532(uint8_t cs, uint8_t clk, uint8_t mosi, uint8_t miso);
void begin(void);
// Generic PN532 functions
View
16 examples/iso14443a_uid/iso14443a_uid.pde
@@ -10,17 +10,29 @@
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
+
+This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
+This library works with the Adafruit NFC breakout
+ ----> https://www.adafruit.com/products/364
+
+Check out the links above for our tutorials and wiring diagrams
+These chips use SPI to communicate, 4 required to interface
+
+Adafruit invests time and resources providing this open source code,
+please support Adafruit and open-source hardware by purchasing
+products from Adafruit!
+
*/
/**************************************************************************/
-#include <PN532.h>
+#include <Adafruit_PN532.h>
#define SCK (2)
#define MOSI (3)
#define SS (4)
#define MISO (5)
-PN532 nfc(SCK, MISO, MOSI, SS);
+Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
void setup(void) {
Serial.begin(115200);
View
15 examples/mifareclassic_formatndef/mifareclassic_formatndef.pde
@@ -9,17 +9,28 @@
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
+
+This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
+This library works with the Adafruit NFC breakout
+ ----> https://www.adafruit.com/products/364
+
+Check out the links above for our tutorials and wiring diagrams
+These chips use SPI to communicate, 4 required to interface
+
+Adafruit invests time and resources providing this open source code,
+please support Adafruit and open-source hardware by purchasing
+products from Adafruit!
*/
/**************************************************************************/
-#include <PN532.h>
+#include <Adafruit_PN532.h>
#define SCK (2)
#define MOSI (3)
#define SS (4)
#define MISO (5)
-PN532 nfc(SCK, MISO, MOSI, SS);
+Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
const char * url = "adafruit.com";
View
17 examples/mifareclassic_memdump/mifareclassic_memdump.pde
@@ -8,19 +8,32 @@
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
+
+This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
+This library works with the Adafruit NFC breakout
+ ----> https://www.adafruit.com/products/364
+
+Check out the links above for our tutorials and wiring diagrams
+These chips use SPI to communicate, 4 required to interface
+
+Adafruit invests time and resources providing this open source code,
+please support Adafruit and open-source hardware by purchasing
+products from Adafruit!
+
*/
/**************************************************************************/
-#include <PN532.h>
+#include <Adafruit_PN532.h>
#define SCK (2)
#define MOSI (3)
#define SS (4)
#define MISO (5)
-PN532 nfc(SCK, MISO, MOSI, SS);
+Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
void setup(void) {
+ // has to be fast to dump the entire memory contents!
Serial.begin(115200);
Serial.println("Looking for PN532...");
View
17 examples/readMifare/readMifare.pde
@@ -19,17 +19,30 @@
Ultralight card, and the 4 byte pages can be read directly.
Page 4 is read by default since this is the first 'general-
purpose' page on the tags.
+
+
+This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
+This library works with the Adafruit NFC breakout
+ ----> https://www.adafruit.com/products/364
+
+Check out the links above for our tutorials and wiring diagrams
+These chips use SPI to communicate, 4 required to interface
+
+Adafruit invests time and resources providing this open source code,
+please support Adafruit and open-source hardware by purchasing
+products from Adafruit!
+
*/
/**************************************************************************/
-#include <PN532.h>
+#include <Adafruit_PN532.h>
#define SCK (2)
#define MOSI (3)
#define SS (4)
#define MISO (5)
-PN532 nfc(SCK, MISO, MOSI, SS);
+Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
void setup(void) {
Serial.begin(9600);
View
15 examples/readMifareClassic/readMifareClassic.pde
@@ -18,17 +18,28 @@
Note that you need the baud rate to be 115200 because we need to
print out the data and read from the card at the same time!
+
+This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
+This library works with the Adafruit NFC breakout
+ ----> https://www.adafruit.com/products/364
+
+Check out the links above for our tutorials and wiring diagrams
+These chips use SPI to communicate, 4 required to interface
+
+Adafruit invests time and resources providing this open source code,
+please support Adafruit and open-source hardware by purchasing
+products from Adafruit!
*/
/**************************************************************************/
-#include <PN532.h>
+#include <Adafruit_PN532.h>
#define SCK (2)
#define MOSI (3)
#define SS (4)
#define MISO (5)
-PN532 nfc(SCK, MISO, MOSI, SS);
+Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
void setup(void) {
Serial.begin(115200);

0 comments on commit ecff1ce

Please sign in to comment.
Something went wrong with that request. Please try again.