chip/pn53x: handle PN532 "power down" and "low VBat" power mode instead of a simple "sleep" mode. (Fixes Issue 167)

This commit is contained in:
Romuald Conty 2011-04-27 13:16:36 +00:00
parent 09b18bf6b8
commit 1198a71d64
6 changed files with 73 additions and 31 deletions

View file

@ -136,6 +136,12 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, b
// Call the send/receice callback functions of the current driver
if (!CHIP_DATA(pnd)->io->send (pnd, pbtTx, szTx))
return false;
// Handle power mode for PN532
if ((CHIP_DATA(pnd)->type == PN532) && (TgInitAsTarget == pbtTx[0])) { // PN532 automatically goes into PowerDown mode when TgInitAsTarget command will be sent
CHIP_DATA(pnd)->power_mode = POWERDOWN;
}
int res = CHIP_DATA(pnd)->io->receive (pnd, pbtRx, *pszRx);
if (res < 0) {
return false;
@ -144,6 +150,10 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, b
if (pnd->iLastError)
return false;
if ((CHIP_DATA(pnd)->type == PN532) && (TgInitAsTarget == pbtTx[0])) { // PN532 automatically wakeup on external RF field
CHIP_DATA(pnd)->power_mode = NORMAL; // When TgInitAsTarget reply that means an external RF have waken up the chip
}
*pszRx = (size_t) res;
switch (pbtTx[0]) {
@ -678,6 +688,15 @@ pn53x_InDeselect (nfc_device_t * pnd, const uint8_t ui8Target)
return (pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL));
}
/*
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)
{

View file

@ -137,10 +137,10 @@ typedef enum {
} pn53x_type;
typedef enum {
SLEEP = 0x00, // Need to be wake up to process commands
NORMAL = 0x01, // Ready to process command
EXECUTE = 0x02, // Need to cancel the running command to process new one
} pn53x_state;
NORMAL, // In that case, there is no power saved but the PN53x reacts as fast as possible on the host controller interface.
POWERDOWN, // Only on PN532, need to be wake up to process commands with a long preamble
LOWVBAT // Only on PN532, need to be wake up to process commands with a long preamble and SAMConfiguration command
} pn53x_power_mode;
struct pn53x_io {
bool (*send)(nfc_device_t * pnd, const byte_t * pbtData, const size_t szData);
@ -149,7 +149,7 @@ struct pn53x_io {
struct pn53x_data {
pn53x_type type;
pn53x_state state;
pn53x_power_mode power_mode;
const struct pn53x_io * io;
/** Register cache for REG_CIU_BIT_FRAMING, SYMBOL_TX_LAST_BITS: The last TX bits setting, we need to reset this if it does not apply anymore */
uint8_t ui8TxBits;