cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
Loading...
Searching...
No Matches
PN532Adapter Class Reference

Self-contained CW_NfcTransport that owns its pn532_t instance. More...

#include <pn532_adapter.h>

Inheritance diagram for PN532Adapter:
[legend]
Collaboration diagram for PN532Adapter:
[legend]

Public Member Functions

 PN532Adapter (const pn532_config_t &config, CW_Logger &logger)
 Construct the adapter with the given PN532 configuration.
bool begin () override
 Initialise the PN532 driver and configure the SAM.
bool inListPassiveTarget () override
 Scan for a passive ISO 14443-A card.
bool sendAPDU (const uint8_t *apdu, uint8_t apduLen, uint8_t *response, uint8_t &responseLen) override
 Exchange one ISO-DEP APDU with the selected card (short response).
bool sendAPDULarge (const uint8_t *apdu, uint8_t apduLen, uint8_t *response, uint16_t &responseLen) override
 Exchange one ISO-DEP APDU with the selected card (large response).
void resetReader () override
 Release the currently selected NFC target.
bool printFirmwareVersion () override
 Query and log the PN532 firmware version.

Private Attributes

pn532_config_t _config
 Stored configuration forwarded to pn532_init.
pn532_t _dev
 PN532 device state (owned by this adapter).
CW_Logger & _logger
 Logger reference for printFirmwareVersion.
bool _initialized
 true after a successful pn532_init call.

Detailed Description

Self-contained CW_NfcTransport that owns its pn532_t instance.

Unlike Pn532NfcTransport (which takes a pre-initialised pn532_t pointer), PN532Adapter accepts a pn532_config_t at construction time and calls pn532_init internally on the first begin() call. This is convenient when the NFC reader is the only SPI/I²C device and the application does not need to manage the bus lifetime separately.

Example
pn532_config_t cfg = {};
cfg.spi_host = SPI2_HOST;
cfg.pin_cs = 10;
ESP32Logger logger;
PN532Adapter transport(cfg, logger);
CryptnoxWallet wallet(transport, logger, crypto, platform);
CW_Logger backed by ESP32 UART0.
Definition ESP32Logger.h:48
Self-contained CW_NfcTransport that owns its pn532_t instance.
@ PN532_TRANSPORT_SPI
Definition pn532.h:77
Compile-time configuration passed to pn532_init.
Definition pn532.h:111
spi_host_device_t spi_host
Definition pn532.h:115
pn532_transport_t transport
Definition pn532.h:112
Note
Non-copyable: _dev holds raw SPI/I²C handles that cannot be duplicated.
See also
Pn532NfcTransport
CW_NfcTransport

Definition at line 54 of file pn532_adapter.h.

Constructor & Destructor Documentation

◆ PN532Adapter()

PN532Adapter::PN532Adapter ( const pn532_config_t & config,
CW_Logger & logger )

Construct the adapter with the given PN532 configuration.

Stores the configuration and logger for use during begin(). The PN532 driver is not initialised at this point.

Parameters
[in]configTransport and pin configuration forwarded to pn532_init on the first begin() call.
[in]loggerLogger used by printFirmwareVersion.

Definition at line 27 of file pn532_adapter.cpp.

References _config, _dev, _initialized, and _logger.

Member Function Documentation

◆ begin()

bool PN532Adapter::begin ( )
override

Initialise the PN532 driver and configure the SAM.

Calls pn532_init (if not already done) followed by pn532_sam_config. Idempotent — repeated calls after a successful init are no-ops that return true.

Returns
true on success, false if pn532_init or pn532_sam_config fails.

Definition at line 32 of file pn532_adapter.cpp.

References _config, _dev, _initialized, pn532_init(), and TAG.

◆ inListPassiveTarget()

bool PN532Adapter::inListPassiveTarget ( )
override

Scan for a passive ISO 14443-A card.

Returns
true if a card was detected in the RF field, false if no card is present or a communication error occurred.

Definition at line 48 of file pn532_adapter.cpp.

References _dev, _initialized, PN532_MIFARE_ISO14443A, and pn532_read_passive_target_id().

◆ printFirmwareVersion()

bool PN532Adapter::printFirmwareVersion ( )
override

Query and log the PN532 firmware version.

Prints "PN5xx firmware vX.Y" via the injected logger.

Returns
true if the PN532 returned a valid version, false on communication failure or if the adapter has not been initialised.

Definition at line 95 of file pn532_adapter.cpp.

References _dev, _initialized, _logger, FW_BYTE_MASK, FW_IC_SHIFT, FW_REV_SHIFT, FW_VER_SHIFT, and pn532_get_firmware_version().

◆ resetReader()

void PN532Adapter::resetReader ( )
override

Release the currently selected NFC target.

Calls pn532_release_target to drop the logical link so the PN532 can list a new target on the next inListPassiveTarget call.

Definition at line 88 of file pn532_adapter.cpp.

References _dev, _initialized, and pn532_release_target().

◆ sendAPDU()

bool PN532Adapter::sendAPDU ( const uint8_t * apdu,
uint8_t apduLen,
uint8_t * response,
uint8_t & responseLen )
override

Exchange one ISO-DEP APDU with the selected card (short response).

Parameters
[in]apduAPDU command bytes (must not be NULL).
[in]apduLenLength of apdu (≤ PN532_MAX_APDU_LEN).
[out]responseCaller-allocated buffer for the DataOut bytes.
[in,out]responseLenIn: capacity of response. Out: number of DataOut bytes written, capped at UINT8_MAX on overflow.
Returns
true on success, false on transport or card error.
See also
sendAPDULarge

Definition at line 61 of file pn532_adapter.cpp.

References _dev, _initialized, and pn532_send_apdu().

◆ sendAPDULarge()

bool PN532Adapter::sendAPDULarge ( const uint8_t * apdu,
uint8_t apduLen,
uint8_t * response,
uint16_t & responseLen )
override

Exchange one ISO-DEP APDU with the selected card (large response).

Use when the card's DataOut may exceed 255 bytes (e.g. GET_MANUFACTURER_CERTIFICATE).

Parameters
[in]apduAPDU command bytes (must not be NULL).
[in]apduLenLength of apdu (≤ PN532_MAX_APDU_LEN).
[out]responseCaller-allocated buffer for the DataOut bytes.
[in,out]responseLenIn: capacity of response in bytes. Out: number of DataOut bytes actually written.
Returns
true on success, false on transport or card error.
See also
sendAPDU

Definition at line 76 of file pn532_adapter.cpp.

References _dev, _initialized, and pn532_send_apdu().

Member Data Documentation

◆ _config

pn532_config_t PN532Adapter::_config
private

Stored configuration forwarded to pn532_init.

Definition at line 141 of file pn532_adapter.h.

Referenced by begin(), and PN532Adapter().

◆ _dev

pn532_t PN532Adapter::_dev
private

PN532 device state (owned by this adapter).

Definition at line 142 of file pn532_adapter.h.

Referenced by begin(), inListPassiveTarget(), PN532Adapter(), printFirmwareVersion(), resetReader(), sendAPDU(), and sendAPDULarge().

◆ _initialized

bool PN532Adapter::_initialized
private

true after a successful pn532_init call.

Definition at line 144 of file pn532_adapter.h.

Referenced by begin(), inListPassiveTarget(), PN532Adapter(), printFirmwareVersion(), resetReader(), sendAPDU(), and sendAPDULarge().

◆ _logger

CW_Logger& PN532Adapter::_logger
private

Logger reference for printFirmwareVersion.

Definition at line 143 of file pn532_adapter.h.

Referenced by PN532Adapter(), and printFirmwareVersion().


The documentation for this class was generated from the following files: