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

tests/drivers/pn532: fix init error handling and increase verbosity #20750

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Changes from all commits
Commits
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
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
Loading