cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
pn532.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: LGPL-3.0-or-later AND BSD-3-Clause
3 *
4 * Public PN532 driver header. Portions derive from Adafruit_PN532
5 * (Copyright (c) 2012, Adafruit Industries; BSD-3-Clause). See
6 * NOTICES.md at the repo root for the full notice.
7 */
8
33
34#pragma once
35
36#include <stdint.h>
37#include <stdbool.h>
38#include "driver/spi_master.h"
39#include "driver/i2c_master.h" /* new IDF v5.x master API */
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
48
49/* ── Card / protocol constants ──────────────────────────────────── */
50
53/* cppcheck-suppress misra-c2012-2.5 */
54#define PN532_MIFARE_ISO14443A (0x00U)
55
60#define PN532_MAX_APDU_LEN (252U)
61
63#define PN532_I2C_ADDRESS (0x24U)
64
65/* ── Transport selector ─────────────────────────────────────────── */
66
80
81/* ── Configuration structure ────────────────────────────────────── */
82
111typedef struct {
113
114 /* ── SPI fields (used when transport == PN532_TRANSPORT_SPI) ── */
115 spi_host_device_t spi_host;
119 int pin_cs;
121
122 /* ── I²C fields (used when transport == PN532_TRANSPORT_I2C) ── */
128 uint32_t i2c_clock_hz;
130
131/* ── Runtime device state ───────────────────────────────────────── */
132
141typedef struct {
143
144 /* ── SPI state ── */
145 spi_device_handle_t spi;
146 int pin_cs;
147
148 /* ── I²C state ── */
149 i2c_master_bus_handle_t i2c_bus;
150 i2c_master_dev_handle_t i2c_dev;
153} pn532_t;
154
155/* ── Public API ─────────────────────────────────────────────────── */
156
178esp_err_t pn532_init(pn532_t *dev, const pn532_config_t *config);
179
195
210bool pn532_sam_config(pn532_t *dev);
211
226uint32_t pn532_read_passive_target_id(pn532_t *dev, uint8_t cardbaudrate);
227
250bool pn532_send_apdu(pn532_t *dev, const uint8_t *apdu, uint8_t apdu_len,
251 uint8_t *response, uint16_t *response_len);
252
265 /* end of pn532_driver group */
267
268#ifdef __cplusplus
269}
270#endif
esp_err_t pn532_init(pn532_t *dev, const pn532_config_t *config)
Initialise the PN532 and bring it to a ready state.
Definition pn532.c:657
uint32_t pn532_read_passive_target_id(pn532_t *dev, uint8_t cardbaudrate)
Scan for a passive ISO 14443-A card and return its UID.
Definition pn532.c:775
bool pn532_send_apdu(pn532_t *dev, const uint8_t *apdu, uint8_t apdu_len, uint8_t *response, uint16_t *response_len)
Exchange a single ISO-DEP APDU with the currently selected card.
Definition pn532.c:805
uint32_t pn532_get_firmware_version(pn532_t *dev)
Query the PN532 firmware version.
Definition pn532.c:718
bool pn532_sam_config(pn532_t *dev)
Configure the PN532's Security Access Module (SAM).
Definition pn532.c:752
pn532_transport_t
Physical bus used to communicate with the PN532.
Definition pn532.h:76
bool pn532_release_target(pn532_t *dev)
Release the currently selected NFC target.
Definition pn532.c:875
@ PN532_TRANSPORT_SPI
Definition pn532.h:77
@ PN532_TRANSPORT_I2C
Definition pn532.h:78
Compile-time configuration passed to pn532_init.
Definition pn532.h:111
uint32_t i2c_clock_hz
Definition pn532.h:128
spi_host_device_t spi_host
Definition pn532.h:115
pn532_transport_t transport
Definition pn532.h:112
bool skip_bus_init
Definition pn532.h:120
Opaque-like runtime state for a single PN532 instance.
Definition pn532.h:141
i2c_master_dev_handle_t i2c_dev
Definition pn532.h:150
int pin_irq
Definition pn532.h:151
i2c_master_bus_handle_t i2c_bus
Definition pn532.h:149
spi_device_handle_t spi
Definition pn532.h:145
int pin_cs
Definition pn532.h:146
pn532_transport_t transport
Definition pn532.h:142
int pin_rst
Definition pn532.h:152