PN532 NFC radio device driver. More...
PN532 NFC radio device driver.
Modules | |
PN532 NFC Radio driver compile configuration | |
Files | |
file | pn532.h |
PN532 driver. | |
Data Structures | |
struct | pn532_params_t |
Data structure with the configuration parameters. More... | |
struct | pn532_t |
Device descriptor for the PN532. More... | |
struct | nfc_iso14443a_t |
ISO14443A tag description. More... | |
Macros | |
#define | PN532_ISO14443A_4_LEN_FROM_BUFFER(b) ((b[0] << 8) | b[1]) |
Obtain Tag 4 data length from buffer. More... | |
Enumerations | |
enum | pn532_mode_t { PN532_I2C, PN532_SPI } |
Working mode of the PN532. | |
enum | pn532_sam_conf_mode_t { PN532_SAM_NORMAL = 1, PN532_SAM_VIRTUAL, PN532_SAM_WIRED, PN532_SAM_DUAL } |
Possible SAM configurations. | |
enum | pn532_target_t { PN532_BR_106_ISO_14443_A = 0, PN532_BR_212_FELICA, PN532_BR_424_FELICA, PN532_BR_106_ISO_14443_B, PN532_BR_106_JEWEL } |
PN532 supported targets. | |
enum | nfc_iso14443a_type_t { ISO14443A_UNKNOWN, ISO14443A_MIFARE, ISO14443A_TYPE4 } |
ISO14443A Card types. | |
enum | pn532_mifare_key_t { PN532_MIFARE_KEY_A = 0x60, PN532_MIFARE_KEY_B = 0x61 } |
Mifare keys. | |
Functions | |
void | pn532_reset (const pn532_t *dev) |
Hard reset the chipset. More... | |
int | pn532_init (pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode) |
Initialize the module and peripherals. More... | |
static int | pn532_init_i2c (pn532_t *dev, const pn532_params_t *params) |
Initialization of PN532 using i2c. More... | |
static int | pn532_init_spi (pn532_t *dev, const pn532_params_t *params) |
Initialization of PN532 using spi. More... | |
int | pn532_fw_version (pn532_t *dev, uint32_t *fw_ver) |
Get the firmware version of the pn532. More... | |
int | pn532_read_reg (pn532_t *dev, char *out, unsigned addr) |
Read register of the pn532. More... | |
int | pn532_write_reg (pn532_t *dev, unsigned addr, char val) |
Write register of the pn532. More... | |
int | pn532_sam_configuration (pn532_t *dev, pn532_sam_conf_mode_t mode, unsigned timeout) |
Set new settings for the Security Access Module. More... | |
int | pn532_get_passive_iso14443a (pn532_t *dev, nfc_iso14443a_t *out, unsigned max_retries) |
Get one ISO14443-A passive target. More... | |
int | pn532_mifareclassic_authenticate (pn532_t *dev, nfc_iso14443a_t *card, pn532_mifare_key_t keyid, char *key, unsigned block) |
Authenticate a Mifare classic card. More... | |
int | pn532_mifareclassic_read (pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned block) |
Read a block of a Mifare classic card. More... | |
int | pn532_mifareclassic_write (pn532_t *dev, char *idata, nfc_iso14443a_t *card, unsigned block) |
Write a block of a Mifare classic card. More... | |
int | pn532_mifareulight_read (pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned page) |
Read a block of a Mifare Ultralight card. More... | |
int | pn532_iso14443a_4_activate (pn532_t *dev, nfc_iso14443a_t *card) |
Activate the NDEF file of a ISO14443-A Type 4 tag. More... | |
int | pn532_iso14443a_4_read (pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned offset, char len) |
Read data from the NDEF file of a ISO14443-A Type 4 tag. More... | |
void | pn532_deselect_passive (pn532_t *dev, unsigned target_id) |
Deselect a previously selected passive card. More... | |
void | pn532_release_passive (pn532_t *dev, unsigned target_id) |
Release an active passive card. More... | |
#define PN532_ISO14443A_4_LEN_FROM_BUFFER | ( | b | ) | ((b[0] << 8) | b[1]) |
void pn532_deselect_passive | ( | pn532_t * | dev, |
unsigned | target_id | ||
) |
Deselect a previously selected passive card.
[in] | dev | target device |
[in] | target_id | id of the target to deselect (0x00 for all) |
int pn532_fw_version | ( | pn532_t * | dev, |
uint32_t * | fw_ver | ||
) |
Get the firmware version of the pn532.
The firmware version returned is a 4 byte long value:
[in] | dev | target device |
[out] | fw_ver | encoded firmware version |
int pn532_get_passive_iso14443a | ( | pn532_t * | dev, |
nfc_iso14443a_t * | out, | ||
unsigned | max_retries | ||
) |
Get one ISO14443-A passive target.
This method blocks until a target is detected.
[in] | dev | target device |
[out] | out | target to be stored |
[in] | max_retries | maximum number of attempts to activate a target (0xff blocks indefinitely) |
int pn532_init | ( | pn532_t * | dev, |
const pn532_params_t * | params, | ||
pn532_mode_t | mode | ||
) |
Initialize the module and peripherals.
This is the first method to be called in order to interact with the pn532. It configures the GPIOs and the i2c/spi interface (depending on mode
).
[in] | dev | target device |
[in] | params | configuration parameters |
[in] | mode | initialization mode |
|
inlinestatic |
Initialization of PN532 using i2c.
|
inlinestatic |
Initialization of PN532 using spi.
int pn532_iso14443a_4_activate | ( | pn532_t * | dev, |
nfc_iso14443a_t * | card | ||
) |
Activate the NDEF file of a ISO14443-A Type 4 tag.
[in] | dev | target device |
[in] | card | card to activate |
int pn532_iso14443a_4_read | ( | pn532_t * | dev, |
char * | odata, | ||
nfc_iso14443a_t * | card, | ||
unsigned | offset, | ||
char | len | ||
) |
Read data from the NDEF file of a ISO14443-A Type 4 tag.
The first two bytes of an NDEF file are the length of the data. Afterwards, at offset 0x02 starts the data itself. If one tries to read further than the end of the data no data is returned.
[in] | dev | target device |
[out] | odata | buffer where to store the data |
[in] | card | card to activate |
[in] | offset | offset where to start reading |
[in] | len | length to read |
int pn532_mifareclassic_authenticate | ( | pn532_t * | dev, |
nfc_iso14443a_t * | card, | ||
pn532_mifare_key_t | keyid, | ||
char * | key, | ||
unsigned | block | ||
) |
Authenticate a Mifare classic card.
This operation must be done before reading or writing the segment.
[in] | dev | target device |
[in] | card | card to use |
[in] | keyid | which key to use |
[in] | key | buffer containing the key |
[in] | block | which block to authenticate |
int pn532_mifareclassic_read | ( | pn532_t * | dev, |
char * | odata, | ||
nfc_iso14443a_t * | card, | ||
unsigned | block | ||
) |
Read a block of a Mifare classic card.
The block size is 16 bytes and it must be authenticated before read.
[in] | dev | target device |
[out] | odata | buffer where to store the data |
[in] | card | card to use |
[in] | block | which block to read |
int pn532_mifareclassic_write | ( | pn532_t * | dev, |
char * | idata, | ||
nfc_iso14443a_t * | card, | ||
unsigned | block | ||
) |
Write a block of a Mifare classic card.
The block size is 16 bytes and it must be authenticated before written.
[in] | dev | target device |
[in] | idata | buffer containing the data to write |
[in] | card | card to use |
[in] | block | which block to write to |
int pn532_mifareulight_read | ( | pn532_t * | dev, |
char * | odata, | ||
nfc_iso14443a_t * | card, | ||
unsigned | page | ||
) |
Read a block of a Mifare Ultralight card.
The block size is 32 bytes and it must be authenticated before read.
[in] | dev | target device |
[out] | odata | buffer where to store the data |
[in] | card | card to use |
[in] | page | which block to read |
int pn532_read_reg | ( | pn532_t * | dev, |
char * | out, | ||
unsigned | addr | ||
) |
Read register of the pn532.
Refer to the datasheet for a comprehensive list of registers and meanings. For SFR registers the high byte must be set to 0xff.
http://www.nxp.com/documents/user_manual/141520.pdf
[in] | dev | target device |
[out] | out | value of the register |
[in] | addr | address of the register to read |
void pn532_release_passive | ( | pn532_t * | dev, |
unsigned | target_id | ||
) |
Release an active passive card.
[in] | dev | target device |
[in] | target_id | id of the target to release (0x00 for all) |
void pn532_reset | ( | const pn532_t * | dev | ) |
Hard reset the chipset.
The chipset is reset by toggling the reset pins
[in] | dev | target device |
int pn532_sam_configuration | ( | pn532_t * | dev, |
pn532_sam_conf_mode_t | mode, | ||
unsigned | timeout | ||
) |
Set new settings for the Security Access Module.
[in] | dev | target device |
[in] | mode | new mode for the SAM |
[in] | timeout | timeout for Virtual Card mode with LSB of 50ms. (0 = infinite and 0xFF = 12.75s) |
int pn532_write_reg | ( | pn532_t * | dev, |
unsigned | addr, | ||
char | val | ||
) |
Write register of the pn532.
Refer to the datasheet for a comprehensive list of registers and meanings.
http://www.nxp.com/documents/user_manual/141520.pdf
[in] | dev | target device |
[in] | addr | address of the register to read |
[in] | val | value to write in the register |