chip/pn53x: clean up SAMConfiguration usage.

This commit is contained in:
Romuald Conty 2011-06-27 17:12:25 +00:00
parent eb70f3842e
commit e6051ceca4
4 changed files with 48 additions and 82 deletions

View file

@ -1861,28 +1861,27 @@ pn53x_SetParameters (nfc_device_t * pnd, const uint8_t ui8Value)
return true;
}
/*
typedef enum {
NORMAL = 0x01,
VIRTUAL_CARD = 0x02,
WIRED_MODE = 0x03,
DUAL_CARD = 0x04
} pn532_sam_mode;
*/
bool
pn53x_SAMConfiguration (nfc_device_t * pnd, const uint8_t ui8Mode)
pn53x_SAMConfiguration (nfc_device_t * pnd, const pn532_sam_mode ui8Mode)
{
byte_t abtCmd[] = { SAMConfiguration, ui8Mode, 0x00, 0x00 };
size_t szCmd = sizeof(abtCmd);
if (CHIP_DATA(pnd)->type != PN532) {
// This function is not supported by pn531 neither pn533
pnd->iLastError = EDEVNOTSUP;
return false;
}
switch (ui8Mode) {
case 0x01: // Normal mode
case PSM_NORMAL: // Normal mode
szCmd = 2;
break;
case 0x02: // Virtual card mode
case 0x03: // Wired card mode
case 0x04: // Dual card mode
// TODO: Handle these SAM mode
case PSM_VIRTUAL_CARD: // Virtual card mode
case PSM_WIRED_CARD: // Wired card mode
case PSM_DUAL_CARD: // Dual card mode
// TODO Implement timeout handling
szCmd = 3;
break;
default:
pnd->iLastError = EINVALARG;

View file

@ -230,6 +230,13 @@ typedef enum {
PTT_DEP_ACTIVE_424 = 0x82,
} pn53x_target_type_t;
typedef enum {
PSM_NORMAL = 0x01,
PSM_VIRTUAL_CARD = 0x02,
PSM_WIRED_CARD = 0x03,
PSM_DUAL_CARD = 0x04
} pn532_sam_mode;
/**
* @enum pn53x_target_mode_t
* @brief PN53x target mode enumeration
@ -306,7 +313,7 @@ const char *pn53x_strerror (const nfc_device_t * pnd);
// C wrappers for PN53x commands
bool pn53x_SetParameters (nfc_device_t * pnd, const uint8_t ui8Value);
bool pn53x_SAMConfiguration (nfc_device_t * pnd, const uint8_t ui8Mode);
bool pn53x_SAMConfiguration (nfc_device_t * pnd, const pn532_sam_mode mode);
bool pn53x_PowerDown (nfc_device_t * pnd);
bool pn53x_InListPassiveTarget (nfc_device_t * pnd, const pn53x_modulation_t pmInitModulation,
const byte_t szMaxTargets, const byte_t * pbtInitiatorData,

View file

@ -93,13 +93,14 @@ pn532_uart_probe (nfc_device_desc_t pnddDevices[], size_t szDevices, size_t * ps
uart_set_speed (sp, PN532_UART_DEFAULT_SPEED);
nfc_device_t *pnd = nfc_device_new ();
pnd->iLastError = 0;
pnd->driver = &pn532_uart_driver;
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
DRIVER_DATA (pnd)->port = sp;
// Alloc and init chip's data
pn53x_data_new (pnd, &pn532_uart_io);
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
CHIP_DATA (pnd)->type = PN532;
// This device starts in LowVBat power mode
CHIP_DATA (pnd)->power_mode = LOWVBAT;
@ -166,6 +167,8 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
DRIVER_DATA(pnd)->port = sp;
// Alloc and init chip's data
pn53x_data_new (pnd, &pn532_uart_io);
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
CHIP_DATA (pnd)->type = PN532;
// This device starts in LowVBat mode
CHIP_DATA(pnd)->power_mode = LOWVBAT;