pn53x_get_firmware_version() returns now 0 on success and libnfc error code on failure..

This commit is contained in:
Audrey Diacre 2012-01-04 16:07:57 +00:00
parent c1faa48f54
commit d4c5476652
2 changed files with 12 additions and 11 deletions

View file

@ -64,8 +64,8 @@ pn53x_init(struct nfc_device *pnd)
int res = 0;
// GetFirmwareVersion command is used to set PN53x chips type (PN531, PN532 or PN533)
char abtFirmwareText[22];
if (!pn53x_get_firmware_version (pnd, abtFirmwareText)) {
return NFC_ECHIP;
if ((res = pn53x_get_firmware_version (pnd, abtFirmwareText)) < 0) {
return res;
}
// CRC handling should be enabled by default as declared in nfc_device_new
@ -600,14 +600,15 @@ pn53x_writeback_register (struct nfc_device *pnd)
return true;
}
bool
int
pn53x_get_firmware_version (struct nfc_device *pnd, char abtFirmwareText[22])
{
const uint8_t abtCmd[] = { GetFirmwareVersion };
uint8_t abtFw[4];
size_t szFwLen = sizeof (abtFw);
if (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, -1) < 0) {
return false;
int res = 0;
if ((res = pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, -1)) < 0) {
return res;
}
// Determine which version of chip it is: PN531 will return only 2 bytes, while others return 4 bytes and have the first to tell the version IC
if (szFwLen == 2) {
@ -623,11 +624,11 @@ pn53x_get_firmware_version (struct nfc_device *pnd, char abtFirmwareText[22])
}
} else {
// Unknown version IC
return false;
return NFC_ENOTIMPL;
}
} else {
// Unknown chip
return false;
return NFC_ENOTIMPL;
}
// Convert firmware info in text, PN531 gives 2 bytes info, but PN532 and PN533 gives 4
switch (CHIP_DATA(pnd)->type) {
@ -648,7 +649,7 @@ pn53x_get_firmware_version (struct nfc_device *pnd, char abtFirmwareText[22])
// Could not happend
break;
}
return true;
return NFC_SUCCESS;
}
uint8_t

View file

@ -275,7 +275,7 @@ bool pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData,
nfc_target_info *pnti);
int pn53x_read_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Value);
int pn53x_write_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
bool pn53x_get_firmware_version (struct nfc_device *pnd, char abtFirmwareText[22]);
int pn53x_get_firmware_version (struct nfc_device *pnd, char abtFirmwareText[22]);
int pn53x_set_property_int (struct nfc_device *pnd, const nfc_property property, const int value);
int pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, const bool bEnable);