Loading...
Searching...
No Matches
pn532.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 TriaGnoSys GmbH
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
21#ifndef PN532_H
22#define PN532_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#include "kernel_defines.h"
29#include "mutex.h"
30#include "periph/i2c.h"
31#include "periph/spi.h"
32#include "periph/gpio.h"
33#include <stdint.h>
34
35#if !IS_USED(MODULE_PN532_I2C) && !IS_USED(MODULE_PN532_SPI)
36#error Please use either pn532_i2c and/or pn532_spi module to enable \
37 the functionality on this device
38#endif
39
43typedef struct {
44 union {
45#if IS_USED(MODULE_PN532_I2C) || DOXYGEN
47#endif
48#if IS_USED(MODULE_PN532_SPI) || DOXYGEN
49 spi_t spi;
50#endif
51 };
52 gpio_t reset;
53 gpio_t irq;
54#if IS_USED(MODULE_PN532_SPI) || DOXYGEN
55 gpio_t nss;
56#endif
58
62typedef enum {
63 PN532_I2C,
64 PN532_SPI
66
75
88#ifndef CONFIG_PN532_BUFFER_LEN
89#define CONFIG_PN532_BUFFER_LEN (64)
90#endif
97#define PN532_IC_VERSION(fwver) ((fwver >> 24) & 0xff)
98#define PN532_FW_VERSION(fwver) ((fwver >> 16) & 0xff)
99#define PN532_FW_REVISION(fwver) ((fwver >> 8) & 0xff)
100#define PN532_FW_FEATURES(fwver) ((fwver) & 0xff)
106typedef enum {
107 PN532_SAM_NORMAL = 1,
108 PN532_SAM_VIRTUAL,
109 PN532_SAM_WIRED,
110 PN532_SAM_DUAL
112
116typedef enum {
117 PN532_BR_106_ISO_14443_A = 0,
118 PN532_BR_212_FELICA,
119 PN532_BR_424_FELICA,
120 PN532_BR_106_ISO_14443_B,
121 PN532_BR_106_JEWEL
123
127typedef enum {
128 ISO14443A_UNKNOWN,
129 ISO14443A_MIFARE,
130 ISO14443A_TYPE4
132
136typedef struct {
137 char target;
138 char auth;
139 char id_len;
140 char sel_res;
141 unsigned sns_res;
143 char id[8];
145
149typedef enum {
150 PN532_MIFARE_KEY_A = 0x60,
151 PN532_MIFARE_KEY_B = 0x61
153
160#define PN532_ISO14443A_4_LEN_FROM_BUFFER(b) ((b[0] << 8) | b[1])
161
170void pn532_reset(const pn532_t *dev);
171
186int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode);
187
188#if IS_USED(MODULE_PN532_I2C) || DOXYGEN
195static inline int pn532_init_i2c(pn532_t *dev, const pn532_params_t *params)
196{
197 return pn532_init(dev, params, PN532_I2C);
198}
199#endif
200
201#if IS_USED(MODULE_PN532_SPI) || DOXYGEN
208static inline int pn532_init_spi(pn532_t *dev, const pn532_params_t *params)
209{
210 return pn532_init(dev, params, PN532_SPI);
211}
212#endif
213
228int pn532_fw_version(pn532_t *dev, uint32_t *fw_ver);
229
244int pn532_read_reg(pn532_t *dev, char *out, unsigned addr);
245
259int pn532_write_reg(pn532_t *dev, unsigned addr, char val);
260
271int pn532_sam_configuration(pn532_t *dev, pn532_sam_conf_mode_t mode, unsigned timeout);
272
286int pn532_get_passive_iso14443a(pn532_t *dev, nfc_iso14443a_t *out, unsigned max_retries);
287
302 pn532_mifare_key_t keyid, char *key, unsigned block);
303
316int pn532_mifareclassic_read(pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned block);
317
330int pn532_mifareclassic_write(pn532_t *dev, char *idata, nfc_iso14443a_t *card, unsigned block);
331
344int pn532_mifareulight_read(pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned page);
345
355
371int pn532_iso14443a_4_read(pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned offset,
372 char len);
373
380void pn532_deselect_passive(pn532_t *dev, unsigned target_id);
381
388void pn532_release_passive(pn532_t *dev, unsigned target_id);
389
390#ifdef __cplusplus
391}
392#endif
393
394#endif /* PN532_H */
Low-level GPIO peripheral driver interface definitions.
uint_fast8_t i2c_t
Default i2c_t type definition.
Definition i2c.h:151
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.
void pn532_deselect_passive(pn532_t *dev, unsigned target_id)
Deselect a previously selected passive card.
int pn532_iso14443a_4_activate(pn532_t *dev, nfc_iso14443a_t *card)
Activate the NDEF file of a ISO14443-A Type 4 tag.
int pn532_fw_version(pn532_t *dev, uint32_t *fw_ver)
Get the firmware version of the pn532.
int pn532_init(pn532_t *dev, const pn532_params_t *params, pn532_mode_t mode)
Initialize the module and peripherals.
pn532_sam_conf_mode_t
Possible SAM configurations.
Definition pn532.h:106
pn532_mifare_key_t
Mifare keys.
Definition pn532.h:149
int pn532_sam_configuration(pn532_t *dev, pn532_sam_conf_mode_t mode, unsigned timeout)
Set new settings for the Security Access Module.
pn532_mode_t
Working mode of the PN532.
Definition pn532.h:62
int pn532_mifareclassic_write(pn532_t *dev, char *idata, nfc_iso14443a_t *card, unsigned block)
Write a block of a Mifare classic card.
void pn532_release_passive(pn532_t *dev, unsigned target_id)
Release an active passive card.
int pn532_get_passive_iso14443a(pn532_t *dev, nfc_iso14443a_t *out, unsigned max_retries)
Get one ISO14443-A passive target.
pn532_target_t
PN532 supported targets.
Definition pn532.h:116
nfc_iso14443a_type_t
ISO14443A Card types.
Definition pn532.h:127
int pn532_mifareclassic_read(pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned block)
Read a block of a Mifare classic card.
void pn532_reset(const pn532_t *dev)
Hard reset the chipset.
int pn532_mifareulight_read(pn532_t *dev, char *odata, nfc_iso14443a_t *card, unsigned page)
Read a block of a Mifare Ultralight card.
static int pn532_init_i2c(pn532_t *dev, const pn532_params_t *params)
Initialization of PN532 using i2c.
Definition pn532.h:195
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.
int pn532_read_reg(pn532_t *dev, char *out, unsigned addr)
Read register of the pn532.
static int pn532_init_spi(pn532_t *dev, const pn532_params_t *params)
Initialization of PN532 using spi.
Definition pn532.h:208
int pn532_write_reg(pn532_t *dev, unsigned addr, char val)
Write register of the pn532.
Low-level I2C peripheral driver interface definition.
Common macros and compiler attributes/pragmas configuration.
Mutex for thread synchronization.
Low-level SPI peripheral driver interface definition.
Mutex structure.
Definition mutex.h:146
ISO14443A tag description.
Definition pn532.h:136
char target
Target.
Definition pn532.h:137
char auth
Card has been authenticated.
Definition pn532.h:138
char sel_res
SEL_RES.
Definition pn532.h:140
unsigned sns_res
SNS_RES.
Definition pn532.h:141
nfc_iso14443a_type_t type
Type of ISO14443A card.
Definition pn532.h:142
char id_len
Length of the ID field.
Definition pn532.h:139
Data structure with the configuration parameters.
Definition pn532.h:43
gpio_t nss
Chip Select pin (only SPI)
Definition pn532.h:55
gpio_t reset
Reset pin.
Definition pn532.h:52
i2c_t i2c
I2C device.
Definition pn532.h:46
spi_t spi
SPI device.
Definition pn532.h:49
gpio_t irq
Interrupt pin.
Definition pn532.h:53
Device descriptor for the PN532.
Definition pn532.h:70
const pn532_params_t * conf
Configuration struct.
Definition pn532.h:71
pn532_mode_t mode
Working mode (i2c, spi)
Definition pn532.h:72
mutex_t trap
Mutex to wait for chip response.
Definition pn532.h:73