Skip to content

Commit

Permalink
feat: begin function calls all needed configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
DeimosHall committed Aug 18, 2023
1 parent 2febce4 commit 27317c0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion examples/NDEFRead/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ clean:
wait:
sleep 2

all: compile upload
all: compile upload wait monitor
21 changes: 4 additions & 17 deletions examples/NDEFRead/NDEFRead.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,15 @@ void setup() {
nfc.setSendMsgCallback(customNdefCallback);

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

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

if (nfc.begin()) {
Serial.println("Error initializing PN7150");
while (1)
;
}

nfc.setReaderWriterMode();

if (nfc.configMode()) { // Set up the configuration mode
Serial.println("The Configure Mode is failed!!");
while (true)
;
}
nfc.startDiscovery(); // NCI Discovery mode
Serial.println("Waiting for a Card...");
}

Expand Down Expand Up @@ -158,10 +147,8 @@ String getHexRepresentation(const byte *data, const uint32_t numBytes) {
}

for (uint32_t szPos = 0; szPos < numBytes; szPos++) {
// hexString += "0x";
if (data[szPos] <= 0xF)
hexString += "0";
// hexString += String(data[szPos] & 0xFF, HEX);
String hexValue = String(data[szPos] & 0xFF, HEX);
hexValue.toUpperCase(); // Convierte a mayúsculas
hexString += hexValue;
Expand Down
20 changes: 0 additions & 20 deletions examples/NDEFSend/NDEFSend.ino
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,9 @@ void setup() {
;
}

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 failed!");
while (1)
;
}

// Needed to detect readers
nfc.setEmulationMode();

if (nfc.configMode()) {
Serial.println("The Configure Mode failed!");
while (1)
;
}

nfc.startDiscovery();

Serial.print("Waiting for an NDEF device");
}

Expand Down
41 changes: 40 additions & 1 deletion src/Electroniccats_PN7150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Electroniccats_PN7150::Electroniccats_PN7150(uint8_t IRQpin, uint8_t VENpin,
pinMode(_IRQpin, INPUT);
if (_VENpin != 255)
pinMode(_VENpin, OUTPUT);

this->_hasBeenInitialized = false;
}

uint8_t Electroniccats_PN7150::begin() {
Expand All @@ -62,6 +64,25 @@ uint8_t Electroniccats_PN7150::begin() {
digitalWrite(_VENpin, HIGH);
delay(3);
}

if (connectNCI()) {
return ERROR;
}

if (configureSettings()) {
return ERROR;
}

if (configMode()) {
return ERROR;
}

if (startDiscovery()) {
return ERROR;
}

this->_hasBeenInitialized = true;

return SUCCESS;
}

Expand Down Expand Up @@ -1048,8 +1069,22 @@ uint8_t Electroniccats_PN7150::connectNCI() {
uint8_t i = 2;
uint8_t NCICoreInit[] = {0x20, 0x01, 0x00};

// Check if begin function has been called
if (this->_hasBeenInitialized) {
return SUCCESS;
}

// Open connection to NXPNCI
begin();
_wire->begin();
if (_VENpin != 255) {
digitalWrite(_VENpin, HIGH);
delay(1);
digitalWrite(_VENpin, LOW);
delay(1);
digitalWrite(_VENpin, HIGH);
delay(3);
}

// Loop until NXPNCI answers
while (wakeupNCI() != SUCCESS) {
if (i-- == 0)
Expand Down Expand Up @@ -1686,6 +1721,10 @@ bool Electroniccats_PN7150::reset() {
return false;
}

if (configureSettings()) {
return false;
}

if (Electroniccats_PN7150::configMode()) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/Electroniccats_PN7150.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ typedef enum {

class Electroniccats_PN7150 : public Mode {
private:
bool _hasBeenInitialized;
uint8_t _IRQpin, _VENpin, _I2Caddress;
TwoWire *_wire;
RfIntf_t dummyRfInterface;
Expand Down

0 comments on commit 27317c0

Please sign in to comment.