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

View file

@ -275,9 +275,9 @@ bool pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData,
nfc_target_info *pnti); nfc_target_info *pnti);
int pn53x_read_register (struct nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Value); 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); 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_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); int pn53x_set_property_bool (struct nfc_device *pnd, const nfc_property property, const bool bEnable);
bool pn53x_check_communication (struct nfc_device *pnd); bool pn53x_check_communication (struct nfc_device *pnd);
bool pn53x_idle (struct nfc_device *pnd); bool pn53x_idle (struct nfc_device *pnd);