Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pn7150/60 #62

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
fb56104
chore: new test branch
REGIOIGER Dec 10, 2024
99a6afc
feat: added chipmodel to constructor
REGIOIGER Dec 12, 2024
22bcbee
feat: added chipmodel to examples
REGIOIGER Dec 12, 2024
7bd9037
feat: added configureSettings_PN7160 function
REGIOIGER Dec 12, 2024
5ea73e4
feat: added configureSettings_PN7160 UID
REGIOIGER Dec 13, 2024
7449103
docs: update reference to PN7160
sabas1080 Dec 17, 2024
ddd4571
feat: PN7160 support, DetectTags example OK
REGIOIGER Dec 17, 2024
af46883
feat: add pre-commit files
sabas1080 Dec 17, 2024
0b379ba
feat: passed pre-commit
sabas1080 Dec 17, 2024
32b43cc
feat: fix set emulation mode
REGIOIGER Dec 20, 2024
71421fa
feat: update examples
REGIOIGER Dec 21, 2024
ac4c51e
chore: unnecessary comments were removed
REGIOIGER Dec 23, 2024
c22a022
feat: unified connectNCI()
REGIOIGER Dec 23, 2024
c51e80f
fix: remove old connectNCI function
REGIOIGER Dec 23, 2024
93aedac
fix: using correct connectNCI function
REGIOIGER Dec 23, 2024
9d76097
feat: unified configureSettings
REGIOIGER Dec 26, 2024
a95cb20
chore: added chip model enum
REGIOIGER Dec 26, 2024
9c3cde6
fix: remove I2C set pins
REGIOIGER Dec 26, 2024
8a53d19
feat: PN7120 default value in constructor
REGIOIGER Dec 26, 2024
a464faf
chore: precommit passed
REGIOIGER Dec 26, 2024
766be1a
chore: restore examples
REGIOIGER Dec 26, 2024
fd30da9
feat: unified configureSettings mod ID
REGIOIGER Dec 27, 2024
615947d
feat: example DetectTags for chip model PN7160
REGIOIGER Dec 27, 2024
770de53
chore: added Makefile for DetectTagsPN7160
REGIOIGER Dec 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 Electronic Cats
#
# SPDX-License-Identifier: MIT

name: pre-commit

on:
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- name: Set up repository
uses: actions/checkout@v4
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-yaml
- id: trailing-whitespace # Elimina los espacios en blanco al final de las líneas
files: \.(cpp|h|ino)$ # Aplica a archivos .cpp, .h y .ino
- id: end-of-file-fixer # Asegura que haya una nueva línea al final de los archivos
files: \.(cpp|h|ino)$ # Aplica a archivos .cpp, .h y .ino
- id: no-commit-to-branch # This hook prevents direct commits to main branch
- id: check-added-large-files # Evita que se suban archivos grandes innecesarios
args: ['--maxkb=500'] # Puedes ajustar el tamaño máximo permitido
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.2 # Use the sha / tag you want to point at
hooks:
- id: clang-format # Formateo de código con clang-format
files: \.(cpp|h)$ # Solo se aplica a archivos .cpp y .h
exclude: ^examples/ # Excluye la carpeta 'examples'
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Electroniccats_PN7150 API Reference

The `Electroniccats_PN7150` class enables Arduino library for I2C access to the PN7150 RFID/Near Field Communication chip.
The `Electroniccats_PN7150` class enables Arduino library for I2C access to the PN7150 and PN7160 RFID/Near Field Communication chip.

## Class: `Electroniccats_PN7150`

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![LibraryBuild](https://github.com/ElectronicCats/ElectronicCats-PN7150/workflows/LibraryBuild/badge.svg?branch=master)

# Electronic Cats PN7150
# Electronic Cats PN7150 and PN7160

<p align="center">
<img src="https://github.com/ElectronicCats/ElectronicCats-PN7150/assets/122187221/e2285142-2924-4075-80d5-c9397a16178c" />
Expand All @@ -12,11 +12,15 @@
</a>
</p>

Library/Driver for NXP PN7150 NFC device
Library/Driver for NXP PN7150 and PN7160 NFC device

Optimized for fast design-in, NXP's PN7150 NFC solutions fully comply with the NFC Forum, including Linux®, AndroidTM, and WinIoT drivers, and support NCI 1.0 host communication.
Optimized for fast design-in, NXP's PN7150 and PN7160 NFC solutions fully comply with the NFC Forum, including Linux®, AndroidTM, and WinIoT drivers, and support NCI 1.0 host communication.

PN7150 is the high-performance version of PN7120, the plug-and-play NFC solution for easy integration into any OS environment, reducing Bill of Material (BOM) size and cost. PN71xx controllers are ideal for home automation applications such as gateways and work seamlessly with NFC-connected tags.
PN7150 is the high-performance version of PN7120, the plug-and-play NFC solution for easy integration into any OS environment, reducing Bill of Material (BOM) size and cost.

PN7160 is compatible with popular MCUs, including LPC, Kinetis and i.MX. The PN7161 version adds support for Apple ECP.

PN71xx controllers are ideal for home automation applications such as gateways and work seamlessly with NFC-connected tags.

## API Documentation

Expand Down
9 changes: 5 additions & 4 deletions examples/DetectTags/DetectTags.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Authors:
* Salvador Mendoza - @Netxing - salmg.net
* For Electronic Cats - electroniccats.com
*
*
* Updated by Francisco Torres - Electronic Cats - electroniccats.com
*
* March 2020
Expand All @@ -19,7 +19,8 @@
#define PN7150_VEN (13)
#define PN7150_ADDR (0x28)

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28
Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR);
// creates a global NFC device interface object, attached to pins 11 (IRQ) and 13 (VEN) and using the default I2C address 0x28

// Function prototypes
String getHexRepresentation(const byte* data, const uint32_t numBytes);
Expand All @@ -29,7 +30,7 @@ void setup() {
Serial.begin(9600);
while (!Serial)
;
Serial.println("Detect NFC tags with PN7150");
Serial.println("Detect NFC tags with PN7150/60");

Serial.println("Initializing...");
if (nfc.connectNCI()) { // Wake up the board
Expand Down Expand Up @@ -63,7 +64,7 @@ void loop() {
nfc.activateNextTagDiscovery();
Serial.println("Multiple cards are detected!");
}

Serial.println("Remove the Card");
nfc.waitForTagRemoval();
Serial.println("Card removed!");
Expand Down
181 changes: 181 additions & 0 deletions examples/DetectTagsPN7160/DetectTagsPN7160.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/**
* Example detect tags and show their unique ID
* Authors:
* Salvador Mendoza - @Netxing - salmg.net
* For Electronic Cats - electroniccats.com
*
* Updated by Francisco Torres - Electronic Cats - electroniccats.com
*
* March 2020
*
* This code is beerware; if you see me (or any other collaborator
* member) at the local, and you've found our code helpful,
* please buy us a round!
* Distributed as-is; no warranty is given.
*/

#include "Electroniccats_PN7150.h"
#define PN7160_IRQ (11)
#define PN7160_VEN (13)
#define PN7160_ADDR (0x28)

Electroniccats_PN7150 nfc(PN7160_IRQ, PN7160_VEN, PN7160_ADDR, PN7160); // fourth additional argument for chip model PN7150 or PN7160
// creates a global NFC device interface object, attached to pins 11 (IRQ) and 13 (VEN) and using the default I2C address 0x28

// Function prototypes
String getHexRepresentation(const byte* data, const uint32_t numBytes);
void displayCardInfo();

void setup() {
Serial.begin(9600);
while (!Serial)
;
Serial.println("Detect NFC tags with PN7160");

Serial.println("Initializing...");
if (nfc.connectNCI()) { // Wake up the board
Serial.println("Error while setting up the mode, check connections!");
while (1)
;
}

if (nfc.configureSettings()) {
Serial.println("The Configure Settings is failed!");
while (1)
;
}

// Read/Write mode as default
if (nfc.configMode()) { // Set up the configuration mode
Serial.println("The Configure Mode is failed!!");
while (1)
;
}
nfc.startDiscovery(); // NCI Discovery mode
Serial.println("Waiting for an Card ...");
}

void loop() {
if (nfc.isTagDetected()) {
displayCardInfo();

// It can detect multiple cards at the same time if they use the same protocol
if (nfc.remoteDevice.hasMoreTags()) {
nfc.activateNextTagDiscovery();
Serial.println("Multiple cards are detected!");
}

Serial.println("Remove the Card");
nfc.waitForTagRemoval();
Serial.println("Card removed!");
}

Serial.println("Restarting...");
nfc.reset();
Serial.println("Waiting for a Card...");
delay(500);
}

String getHexRepresentation(const byte* data, const uint32_t numBytes) {
String hexString;

if (numBytes == 0) {
hexString = "null";
}

for (uint32_t szPos = 0; szPos < numBytes; szPos++) {
hexString += "0x";
if (data[szPos] <= 0xF)
hexString += "0";
hexString += String(data[szPos] & 0xFF, HEX);
if ((numBytes > 1) && (szPos != numBytes - 1)) {
hexString += " ";
}
}
return hexString;
}

void displayCardInfo() { // Funtion in charge to show the card/s in te field
char tmp[16];

while (true) {
switch (nfc.remoteDevice.getProtocol()) { // Indetify card protocol
case nfc.protocol.T1T:
case nfc.protocol.T2T:
case nfc.protocol.T3T:
case nfc.protocol.ISODEP:
Serial.print(" - POLL MODE: Remote activated tag type: ");
Serial.println(nfc.remoteDevice.getProtocol());
break;
case nfc.protocol.ISO15693:
Serial.println(" - POLL MODE: Remote ISO15693 card activated");
break;
case nfc.protocol.MIFARE:
Serial.println(" - POLL MODE: Remote MIFARE card activated");
break;
default:
Serial.println(" - POLL MODE: Undetermined target");
return;
}

switch (nfc.remoteDevice.getModeTech()) { // Indetify card technology
case (nfc.tech.PASSIVE_NFCA):
Serial.println("\tTechnology: NFC-A");
Serial.print("\tSENS RES = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getSensRes(), nfc.remoteDevice.getSensResLen()));

Serial.print("\tNFC ID = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getNFCID(), nfc.remoteDevice.getNFCIDLen()));

Serial.print("\tSEL RES = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getSelRes(), nfc.remoteDevice.getSelResLen()));

break;

case (nfc.tech.PASSIVE_NFCB):
Serial.println("\tTechnology: NFC-B");
Serial.print("\tSENS RES = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getSensRes(), nfc.remoteDevice.getSensResLen()));

Serial.println("\tAttrib RES = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getAttribRes(), nfc.remoteDevice.getAttribResLen()));

break;

case (nfc.tech.PASSIVE_NFCF):
Serial.println("\tTechnology: NFC-F");
Serial.print("\tSENS RES = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getSensRes(), nfc.remoteDevice.getSensResLen()));

Serial.print("\tBitrate = ");
Serial.println((nfc.remoteDevice.getBitRate() == 1) ? "212" : "424");

break;

case (nfc.tech.PASSIVE_NFCV):
Serial.println("\tTechnology: NFC-V");
Serial.print("\tID = ");
Serial.println(getHexRepresentation(nfc.remoteDevice.getID(), sizeof(nfc.remoteDevice.getID())));

Serial.print("\tAFI = ");
Serial.println(nfc.remoteDevice.getAFI());

Serial.print("\tDSF ID = ");
Serial.println(nfc.remoteDevice.getDSFID(), HEX);
break;

default:
break;
}

// It can detect multiple cards at the same time if they are the same technology
if (nfc.remoteDevice.hasMoreTags()) {
Serial.println("Multiple cards are detected!");
if (!nfc.activateNextTagDiscovery()) {
break; // Can't activate next tag
}
} else {
break;
}
}
}
19 changes: 19 additions & 0 deletions examples/DetectTagsPN7160/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BOARD_TAG = electroniccats:mbed_rp2040:bombercat
MONITOR_PORT = /dev/cu.usbmodem1101

compile:
arduino-cli compile --fqbn $(BOARD_TAG)

upload:
arduino-cli upload -p $(MONITOR_PORT) --fqbn $(BOARD_TAG) --verbose

monitor:
arduino-cli monitor -p $(MONITOR_PORT)

clean:
arduino-cli cache clean

wait:
sleep 2

all: compile upload wait monitor
19 changes: 11 additions & 8 deletions examples/DetectingReaders/DetectingReaders.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Example detect tags and show their unique ID
* Authors:
* Example detect tags and show their unique ID
* Authors:
* Salvador Mendoza - @Netxing - salmg.net
* For Electronic Cats - electroniccats.com
*
*
* March 2020
*
* This code is beerware; if you see me (or any other collaborator
* member) at the local, and you've found our code helpful,
*
* This code is beerware; if you see me (or any other collaborator
* member) at the local, and you've found our code helpful,
* please buy us a round!
* Distributed as-is; no warranty is given.
*/
Expand All @@ -18,13 +18,16 @@
#define PN7150_VEN (13)
#define PN7150_ADDR (0x28)

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // Creates a global NFC device interface object, attached to pins 11 (IRQ) and 13 (VEN) and using the default I2C address 0x28
Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR);
// Creates a global NFC device interface object, attached to pins 11 (IRQ) and 13 (VEN) and using the default I2C address 0x28



void setup() {
Serial.begin(9600);
while (!Serial)
;
Serial.println("Detect NFC readers with PN7150");
Serial.println("Detect NFC readers with PN7150/60");
Serial.println("Initializing...");

if (nfc.begin()) {
Expand Down
5 changes: 3 additions & 2 deletions examples/ISO14443-3A_read_block/ISO14443-3A_read_block.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

#define BLK_NB_ISO14443_3A (5) // Block to be read it

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28
Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR);
// creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28

void PrintBuf(const byte* data, const uint32_t numBytes) { // Print hex data buffer in format
uint32_t szPos;
Expand Down Expand Up @@ -60,7 +61,7 @@ void setup() {
Serial.begin(9600);
while (!Serial)
;
Serial.println("Read ISO14443-3A(T2T) data block 5 with PN7150");
Serial.println("Read ISO14443-3A(T2T) data block 5 with PN7150/60");

Serial.println("Initializing...");
if (nfc.connectNCI()) { // Wake up the board
Expand Down
5 changes: 3 additions & 2 deletions examples/ISO14443-3A_write_block/ISO14443-3A_write_block.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#define BLK_NB_ISO14443_3A (5) // Block to be read it
#define DATA_WRITE_ISO14443_3A 0x11, 0x22, 0x33, 0x44 // Data to write

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28
Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR);
// creates a global NFC device interface object, attached to pins 11 (IRQ) and 13 (VEN) and using the default I2C address 0x28

void PrintBuf(const byte* data, const uint32_t numBytes) { // Print hex data buffer in format
uint32_t szPos;
Expand Down Expand Up @@ -76,7 +77,7 @@ void setup() {
Serial.begin(9600);
while (!Serial)
;
Serial.println("Write ISO14443-3A(T2T) data block 5 with PN7150");
Serial.println("Write ISO14443-3A(T2T) data block 5 with PN7150/60");

Serial.println("Initializing...");
if (nfc.connectNCI()) { // Wake up the board
Expand Down
Loading
Loading