Skip to content

Commit

Permalink
Merge pull request #20750 from mguetschow/tests-pn532
Browse files Browse the repository at this point in the history
tests/drivers/pn532: fix init error handling and increase verbosity
  • Loading branch information
benpicco authored Jun 14, 2024
2 parents b879bbd + 81494ba commit 5096c24
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions tests/drivers/pn532/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,25 @@ int main(void)

if (ret != 0) {
LOG_INFO("init error %d\n", ret);
return -1;
}

ztimer_sleep(ZTIMER_MSEC, 200);
LOG_INFO("awake\n");

uint32_t fwver;
pn532_fw_version(&pn532, &fwver);
ret = pn532_fw_version(&pn532, &fwver);
if (ret != 0) {
LOG_INFO("ver error %d\n", ret);
return -1;
}
LOG_INFO("ver %d.%d\n", (unsigned)PN532_FW_VERSION(fwver), (unsigned)PN532_FW_REVISION(fwver));

ret = pn532_sam_configuration(&pn532, PN532_SAM_NORMAL, 1000);
LOG_INFO("set sam %d\n", ret);
if (ret != 0) {
LOG_INFO("set sam error %d\n", ret);
return -1;
}

while (1) {
/* Delay not to be always polling the interface */
Expand All @@ -73,20 +81,20 @@ int main(void)

if (card.type == ISO14443A_TYPE4) {
if (pn532_iso14443a_4_activate(&pn532, &card) != 0) {
LOG_ERROR("act\n");
LOG_ERROR("act error\n");
continue;

}
else if (pn532_iso14443a_4_read(&pn532, data, &card, 0x00, 2) != 0) {
LOG_ERROR("len\n");
LOG_ERROR("len error\n");
continue;
}

len = PN532_ISO14443A_4_LEN_FROM_BUFFER(data);
len = MIN(len, sizeof(data));

if (pn532_iso14443a_4_read(&pn532, data, &card, 0x02, len) != 0) {
LOG_ERROR("read\n");
LOG_ERROR("read error\n");
continue;
}

Expand All @@ -105,7 +113,7 @@ int main(void)
ret = pn532_mifareclassic_authenticate(&pn532, &card,
PN532_MIFARE_KEY_A, key, i);
if (ret != 0) {
LOG_ERROR("auth\n");
LOG_ERROR("auth error\n");
break;
}
}
Expand All @@ -115,14 +123,14 @@ int main(void)
printbuff(data, 16);
}
else {
LOG_ERROR("read\n");
LOG_ERROR("read error\n");
break;
}
}

}
else {
LOG_ERROR("unknown\n");
LOG_ERROR("unknown card type\n");
}
}

Expand Down

0 comments on commit 5096c24

Please sign in to comment.