New internal API function: pn53x_get_firmware_version().
This commit is contained in:
parent
fbcf966d20
commit
71b3a1ad6e
3 changed files with 30 additions and 21 deletions
|
@ -590,3 +590,28 @@ pn53x_strerror (const nfc_device_t *pnd)
|
||||||
return pcRes;
|
return pcRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pn53x_get_firmware_version (nfc_device_t *pnd)
|
||||||
|
{
|
||||||
|
byte_t abtFw[4];
|
||||||
|
size_t szFwLen = sizeof(abtFw);
|
||||||
|
char* pcName;
|
||||||
|
|
||||||
|
if (!pn53x_transceive(pnd,pncmd_get_firmware_version,2,abtFw,&szFwLen))
|
||||||
|
{
|
||||||
|
// Failed to get firmware revision??, whatever...let's disconnect and clean up and return err
|
||||||
|
DBG("Failed to get firmware revision for: %s", pnd->acName);
|
||||||
|
pnd->pdc->disconnect(pnd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the firmware revision to the device name, PN531 gives 2 bytes info, but PN532 and PN533 gives 4
|
||||||
|
pcName = strdup(pnd->acName);
|
||||||
|
switch(pnd->nc) {
|
||||||
|
case NC_PN531: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN531 v%d.%d",pcName,abtFw[0],abtFw[1]); break;
|
||||||
|
case NC_PN532: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN532 v%d.%d (0x%02x)",pcName,abtFw[1],abtFw[2],abtFw[3]); break;
|
||||||
|
case NC_PN533: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN533 v%d.%d (0x%02x)",pcName,abtFw[1],abtFw[2],abtFw[3]); break;
|
||||||
|
}
|
||||||
|
free(pcName);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -94,6 +94,8 @@ bool pn53x_InDeselect(nfc_device_t* pnd, const uint8_t ui8Target);
|
||||||
bool pn53x_InRelease(nfc_device_t* pnd, const uint8_t ui8Target);
|
bool pn53x_InRelease(nfc_device_t* pnd, const uint8_t ui8Target);
|
||||||
bool pn53x_InAutoPoll(nfc_device_t* pnd, const nfc_target_type_t* pnttTargetTypes, const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod, nfc_target_t* pntTargets, size_t* pszTargetFound);
|
bool pn53x_InAutoPoll(nfc_device_t* pnd, const nfc_target_type_t* pnttTargetTypes, const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod, nfc_target_t* pntTargets, size_t* pszTargetFound);
|
||||||
|
|
||||||
|
bool pn53x_get_firmware_version (nfc_device_t *pnd);
|
||||||
|
|
||||||
const char *pn53x_strerror (const nfc_device_t *pnd);
|
const char *pn53x_strerror (const nfc_device_t *pnd);
|
||||||
|
|
||||||
static const struct chip_callbacks pn53x_callbacks_list = {
|
static const struct chip_callbacks pn53x_callbacks_list = {
|
||||||
|
|
22
libnfc/nfc.c
22
libnfc/nfc.c
|
@ -49,7 +49,7 @@ nfc_device_desc_t * nfc_pick_device (void);
|
||||||
|
|
||||||
/// @TODO Remove all PN53x related command from this file (should be in pn53x)
|
/// @TODO Remove all PN53x related command from this file (should be in pn53x)
|
||||||
// // PN53X configuration
|
// // PN53X configuration
|
||||||
extern const byte_t pncmd_get_firmware_version [ 2];
|
// extern const byte_t pncmd_get_firmware_version [ 2];
|
||||||
// extern const byte_t pncmd_get_general_status [ 2];
|
// extern const byte_t pncmd_get_general_status [ 2];
|
||||||
// extern const byte_t pncmd_get_register [ 4];
|
// extern const byte_t pncmd_get_register [ 4];
|
||||||
// extern const byte_t pncmd_set_register [ 5];
|
// extern const byte_t pncmd_set_register [ 5];
|
||||||
|
@ -147,8 +147,6 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd)
|
||||||
{
|
{
|
||||||
nfc_device_t* pnd = NULL;
|
nfc_device_t* pnd = NULL;
|
||||||
uint32_t uiDriver;
|
uint32_t uiDriver;
|
||||||
byte_t abtFw[4];
|
|
||||||
size_t szFwLen = sizeof(abtFw);
|
|
||||||
|
|
||||||
// Search through the device list for an available device
|
// Search through the device list for an available device
|
||||||
for (uiDriver=0; uiDriver<sizeof(drivers_callbacks_list)/sizeof(drivers_callbacks_list[0]); uiDriver++)
|
for (uiDriver=0; uiDriver<sizeof(drivers_callbacks_list)/sizeof(drivers_callbacks_list[0]); uiDriver++)
|
||||||
|
@ -183,28 +181,12 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd)
|
||||||
// Test if the connection was successful
|
// Test if the connection was successful
|
||||||
if (pnd != NULL)
|
if (pnd != NULL)
|
||||||
{
|
{
|
||||||
char* pcName;
|
|
||||||
DBG("[%s] has been claimed.", pnd->acName);
|
DBG("[%s] has been claimed.", pnd->acName);
|
||||||
// Great we have claimed a device
|
// Great we have claimed a device
|
||||||
pnd->pdc = &(drivers_callbacks_list[uiDriver]);
|
pnd->pdc = &(drivers_callbacks_list[uiDriver]);
|
||||||
|
|
||||||
// Try to retrieve PN53x chip revision
|
if (!pn53x_get_firmware_version(pnd))
|
||||||
if (!pn53x_transceive(pnd,pncmd_get_firmware_version,2,abtFw,&szFwLen))
|
|
||||||
{
|
|
||||||
// Failed to get firmware revision??, whatever...let's disconnect and clean up and return err
|
|
||||||
DBG("Failed to get firmware revision for: %s", pnd->acName);
|
|
||||||
pnd->pdc->disconnect(pnd);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
// Add the firmware revision to the device name, PN531 gives 2 bytes info, but PN532 and PN533 gives 4
|
|
||||||
pcName = strdup(pnd->acName);
|
|
||||||
switch(pnd->nc) {
|
|
||||||
case NC_PN531: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN531 v%d.%d",pcName,abtFw[0],abtFw[1]); break;
|
|
||||||
case NC_PN532: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN532 v%d.%d (0x%02x)",pcName,abtFw[1],abtFw[2],abtFw[3]); break;
|
|
||||||
case NC_PN533: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN533 v%d.%d (0x%02x)",pcName,abtFw[1],abtFw[2],abtFw[3]); break;
|
|
||||||
}
|
|
||||||
free(pcName);
|
|
||||||
|
|
||||||
// Reset the ending transmission bits register, it is unknown what the last tranmission used there
|
// Reset the ending transmission bits register, it is unknown what the last tranmission used there
|
||||||
if (!pn53x_set_reg(pnd,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,0x00)) return NULL;
|
if (!pn53x_set_reg(pnd,REG_CIU_BIT_FRAMING,SYMBOL_TX_LAST_BITS,0x00)) return NULL;
|
||||||
|
|
Loading…
Add table
Reference in a new issue