Skip to content

Commit

Permalink
refactor: tml_Rx
Browse files Browse the repository at this point in the history
  • Loading branch information
REGIOIGER committed Nov 19, 2024
1 parent 3c79dd4 commit afe1a87
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions dev/test_nci2_pn7160_send_receive/test_nci2_pn7160_send_receive.ino
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,48 @@ Status tml_Tx(uint8_t *pBuff, uint16_t buffLen) {
}

Status tml_Rx(uint8_t *pBuff, uint16_t buffLen, uint16_t *pBytesRead) {
Wire.requestFrom(I2C_ADDRESS, buffLen);
uint16_t bytesRead = 0;

while (Wire.available() > 0 && bytesRead < buffLen) {
pBuff[bytesRead++] = Wire.read();
Wire.requestFrom(I2C_ADDRESS, 3);
uint16_t headerRead = 0;
while (Wire.available() > 0 && headerRead < 3) {
pBuff[headerRead++] = Wire.read();
}

if (bytesRead == 0) {
if (headerRead != 3) {
return ERROR;
}

*pBytesRead = bytesRead;
uint16_t totalLength = pBuff[2] + 3;
if (totalLength > buffLen) {
return ERROR;
}
if (pBuff[2] > 0) {
Wire.requestFrom(I2C_ADDRESS, pBuff[2]);
uint16_t dataRead = 0;
while (Wire.available() > 0 && dataRead < pBuff[2]) {
pBuff[3 + dataRead++] = Wire.read();
}
if (dataRead != pBuff[2]) {
return ERROR;
}
}
*pBytesRead = totalLength;
return SUCCESS;
}

//Status tml_Rx(uint8_t *pBuff, uint16_t buffLen, uint16_t *pBytesRead) {
// Wire.requestFrom(I2C_ADDRESS, buffLen);
// uint16_t bytesRead = 0;
//
// while (Wire.available() > 0 && bytesRead < buffLen) {
// pBuff[bytesRead++] = Wire.read();
// }
//
// if (bytesRead == 0) {
// return ERROR;
// }
//
// *pBytesRead = bytesRead;
// return SUCCESS;
//}

Status tml_WaitForRx(uint32_t timeout) {
if (timeout == 0) {
while (digitalRead(IRQ_PIN) == LOW);
Expand Down Expand Up @@ -250,7 +277,7 @@ static bool NxpNci_CheckDevPres(void)
gNfcController_fw_version[0] = Answer[9];
gNfcController_fw_version[1] = Answer[10];
gNfcController_fw_version[2] = Answer[11];
Serial.println("Dispositivo NFC encontrado y listo.");
Serial.println("Dispositivo NFC encontrado");
Serial.print("Versión de firmware: ");
Serial.print(gNfcController_fw_version[0], HEX);
Serial.print(".");
Expand Down

0 comments on commit afe1a87

Please sign in to comment.