|
cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
|
#include "pn532.h"#include "driver/gpio.h"#include "driver/i2c_master.h"#include "esp_log.h"#include "freertos/FreeRTOS.h"#include "freertos/task.h"#include <string.h>Go to the source code of this file.
Functions | |
| static bool | pn532_buffer_equal (const uint8_t *lhs, const uint8_t *rhs, uint8_t len) |
| static void | spi_write_byte (pn532_t *dev, uint8_t data) |
| static uint8_t | spi_read_byte (pn532_t *dev) |
| static uint8_t | i2c_read_ready (pn532_t *dev) |
| static uint8_t | read_ready (pn532_t *dev) |
| static void | read_data (pn532_t *dev, uint8_t *buff, uint8_t n) |
| static bool | check_ack (pn532_t *dev) |
| static void | write_command (pn532_t *dev, const uint8_t *cmd, uint8_t cmd_len) |
| static bool | send_command_check_ack (pn532_t *dev, const uint8_t *cmd, uint8_t cmd_len, uint16_t timeout) |
| static uint16_t | read_data_apdu_frame (pn532_t *dev, uint8_t *buff, uint16_t max_len) |
| static esp_err_t | pn532_init_spi (pn532_t *dev, const pn532_config_t *config) |
| static esp_err_t | pn532_init_i2c (pn532_t *dev, const pn532_config_t *config) |
| esp_err_t | pn532_init (pn532_t *dev, const pn532_config_t *config) |
| Initialise the PN532 and bring it to a ready state. | |
| uint32_t | pn532_get_firmware_version (pn532_t *dev) |
| Query the PN532 firmware version. | |
| bool | pn532_sam_config (pn532_t *dev) |
| Configure the PN532's Security Access Module (SAM). | |
| 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. | |
| 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. | |
| bool | pn532_release_target (pn532_t *dev) |
| Release the currently selected NFC target. | |
Variables | |
| static const char *const | PN532_LOG_TAG = "pn532" |
| static const uint8_t | pn532_ack [PN532_ACK_LEN] |
| static const uint8_t | pn532_response_fw [PN532_FIRMWARE_HDR_LEN] |
| #define GPIO_LEVEL_HIGH (1U) /* drive pin high */ |
Definition at line 90 of file pn532.c.
Referenced by pn532_init_i2c(), pn532_init_spi(), read_data(), read_data_apdu_frame(), read_ready(), and write_command().
| #define GPIO_LEVEL_LOW (0U) /* drive pin low */ |
Definition at line 89 of file pn532.c.
Referenced by pn532_init_i2c(), pn532_init_spi(), read_data(), read_data_apdu_frame(), read_ready(), and write_command().
| #define GPIO_PIN_BITMASK_BASE (1ULL) /* base bit for gpio_config_t.pin_bit_mask */ |
Definition at line 91 of file pn532.c.
Referenced by pn532_init_i2c(), and pn532_init_spi().
| #define PN532_ACK_LEN (6U) |
Definition at line 103 of file pn532.c.
Referenced by check_ack().
| #define PN532_APDU_TIMEOUT_MS (5000U) |
Definition at line 82 of file pn532.c.
Referenced by pn532_send_apdu().
| #define PN532_BYTE_DELAY_MS (1U) |
Definition at line 83 of file pn532.c.
Referenced by read_data(), and read_data_apdu_frame().
| #define PN532_BYTE_SHIFT_BITS (8U) |
Definition at line 147 of file pn532.c.
Referenced by pn532_get_firmware_version(), and pn532_read_passive_target_id().
| #define PN532_CMD_TIMEOUT_MS (1000U) |
Definition at line 80 of file pn532.c.
Referenced by pn532_get_firmware_version(), pn532_read_passive_target_id(), pn532_release_target(), and pn532_sam_config().
| #define PN532_CS_TOGGLE_DELAY_MS (2U) |
Definition at line 76 of file pn532.c.
Referenced by pn532_init_spi(), read_data(), read_data_apdu_frame(), read_ready(), and write_command().
| #define PN532_EXCHANGE_CMD_OVERHEAD (2U) |
Definition at line 153 of file pn532.c.
Referenced by pn532_send_apdu().
| #define PN532_EXCHANGE_DATA_OFFSET (8U) /* frame[8] = first DataOut byte for normal frames */ |
Definition at line 159 of file pn532.c.
Referenced by pn532_send_apdu().
| #define PN532_EXCHANGE_FRAME_MAX (440U) |
Definition at line 156 of file pn532.c.
Referenced by pn532_send_apdu(), and read_data_apdu_frame().
| #define PN532_EXCHANGE_LEN_BIAS (3U) /* LEN covers D5 + CMD + ERR; DataOut = LEN - 3 */ |
Definition at line 160 of file pn532.c.
Referenced by pn532_send_apdu().
| #define PN532_EXCHANGE_LEN_OFFSET (3U) |
Definition at line 157 of file pn532.c.
Referenced by pn532_send_apdu(), and read_data_apdu_frame().
| #define PN532_EXCHANGE_STATUS_OFFSET (7U) |
Definition at line 158 of file pn532.c.
Referenced by pn532_release_target(), and pn532_send_apdu().
| #define PN532_EXCHANGE_STATUS_OK (0x00U) |
Definition at line 161 of file pn532.c.
Referenced by pn532_release_target(), and pn532_send_apdu().
| #define PN532_EXCHANGE_TG (0x01U) |
Definition at line 154 of file pn532.c.
Referenced by pn532_release_target(), and pn532_send_apdu().
| #define PN532_EXT_EXCHANGE_DATA_OFFSET (11U) |
Definition at line 177 of file pn532.c.
Referenced by pn532_send_apdu().
| #define PN532_EXT_EXCHANGE_ERR_OFFSET (10U) |
Definition at line 176 of file pn532.c.
Referenced by pn532_send_apdu().
| #define PN532_EXT_FRAME_HDR_LEN (8U) |
Definition at line 173 of file pn532.c.
Referenced by read_data_apdu_frame().
| #define PN532_EXT_FRAME_INDICATOR (0xFFU) |
Definition at line 172 of file pn532.c.
Referenced by pn532_send_apdu(), and read_data_apdu_frame().
| #define PN532_EXT_FRAME_LENHI_OFFSET (5U) |
Definition at line 174 of file pn532.c.
Referenced by pn532_send_apdu(), and read_data_apdu_frame().
| #define PN532_EXT_FRAME_LENLO_OFFSET (6U) |
Definition at line 175 of file pn532.c.
Referenced by pn532_send_apdu(), and read_data_apdu_frame().
| #define PN532_FIRMWARE_CMD_LEN (1U) |
Definition at line 116 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_FIRMWARE_HDR_LEN (7U) |
Definition at line 118 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_FIRMWARE_RESP_LEN (13U) /* matches Adafruit_PN532::getFirmwareVersion */ |
Definition at line 117 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_FIRMWAREVERSION (0x02U) |
Definition at line 42 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_FRAME_HDR_LEN (5U) |
Definition at line 165 of file pn532.c.
Referenced by read_data_apdu_frame().
| #define PN532_FRAME_TAIL_LEN (2U) |
Definition at line 166 of file pn532.c.
Referenced by read_data_apdu_frame().
| #define PN532_FRAME_TFI_OVERHEAD (1U) |
Definition at line 110 of file pn532.c.
Referenced by write_command().
| #define PN532_FW_IC_OFFSET (7U) |
Definition at line 119 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_FW_REV_OFFSET (9U) |
Definition at line 121 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_FW_SUPPORT_OFFSET (10U) |
Definition at line 122 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_FW_VER_OFFSET (8U) |
Definition at line 120 of file pn532.c.
Referenced by pn532_get_firmware_version().
| #define PN532_HOSTTOPN532 (0xD4U) |
Definition at line 36 of file pn532.c.
Referenced by write_command().
| #define PN532_I2C_RX_MAX (200U) |
Definition at line 70 of file pn532.c.
Referenced by read_data().
| #define PN532_I2C_TIMEOUT_MS (100) |
Definition at line 66 of file pn532.c.
Referenced by i2c_read_ready(), read_data(), read_data_apdu_frame(), and write_command().
| #define PN532_I2C_TX_MAX (PN532_MAX_APDU_LEN + 16U) |
Definition at line 68 of file pn532.c.
Referenced by write_command().
| #define PN532_INDATAEXCHANGE (0x40U) |
Definition at line 45 of file pn532.c.
Referenced by pn532_send_apdu().
| #define PN532_INLISTPASSIVETARGET (0x4AU) |
Definition at line 44 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_INRELEASE (0x52U) |
Definition at line 46 of file pn532.c.
Referenced by pn532_release_target().
| #define PN532_INRELEASE_CMD_LEN (2U) |
Definition at line 184 of file pn532.c.
Referenced by pn532_release_target().
| #define PN532_INRELEASE_RESP_LEN (10U) |
Definition at line 185 of file pn532.c.
Referenced by pn532_release_target().
| #define PN532_PASSIVE_CMD_LEN (3U) |
Definition at line 140 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_PASSIVE_EXPECTED_TARGETS (1U) |
Definition at line 144 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_PASSIVE_MAX_TARGETS (1U) |
Definition at line 142 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_PASSIVE_NUM_TARGETS_OFFSET (7U) |
Definition at line 143 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_PASSIVE_RESP_LEN (64U) |
Definition at line 141 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_PASSIVE_UID_DATA_OFFSET (13U) |
Definition at line 146 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_PASSIVE_UID_LEN_OFFSET (12U) |
Definition at line 145 of file pn532.c.
Referenced by pn532_read_passive_target_id().
| #define PN532_POLL_INTERVAL_MS (10U) |
Definition at line 79 of file pn532.c.
Referenced by send_command_check_ack().
| #define PN532_POSTAMBLE (0x00U) |
Definition at line 35 of file pn532.c.
Referenced by write_command().
| #define PN532_PREAMBLE (0x00U) |
Definition at line 31 of file pn532.c.
Referenced by pn532_init_spi(), and write_command().
| #define PN532_SAM_CMD_LEN (4U) |
Definition at line 128 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SAM_NORMAL_MODE (0x01U) |
Definition at line 132 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SAM_RESP_CODE (0x15U) /* SAMCONFIGURATION + 1 */ |
Definition at line 131 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SAM_RESP_CODE_OFFSET (6U) |
Definition at line 130 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SAM_RESP_LEN (9U) |
Definition at line 129 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SAM_TIMEOUT (0x14U) /* 50 ms x 20 = 1 s */ |
Definition at line 133 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SAM_USE_IRQ (0x01U) |
Definition at line 134 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SAMCONFIGURATION (0x14U) |
Definition at line 43 of file pn532.c.
Referenced by pn532_sam_config().
| #define PN532_SPI_BITS (8U) |
Definition at line 60 of file pn532.c.
Referenced by spi_read_byte(), and spi_write_byte().
| #define PN532_SPI_CLOCK_HZ (1000000U) |
Definition at line 56 of file pn532.c.
Referenced by pn532_init_spi().
| #define PN532_SPI_DATAREAD (0x03U) |
Definition at line 54 of file pn532.c.
Referenced by read_data(), and read_data_apdu_frame().
| #define PN532_SPI_DATAWRITE (0x01U) |
Definition at line 53 of file pn532.c.
Referenced by write_command().
| #define PN532_SPI_MODE (0U) |
Definition at line 57 of file pn532.c.
Referenced by pn532_init_spi().
| #define PN532_SPI_NO_PIN (-1) |
Definition at line 58 of file pn532.c.
Referenced by pn532_init_spi().
| #define PN532_SPI_QUEUE_SIZE (1U) |
Definition at line 59 of file pn532.c.
Referenced by pn532_init_spi().
| #define PN532_SPI_READY (0x01U) |
Definition at line 55 of file pn532.c.
Referenced by send_command_check_ack().
| #define PN532_SPI_STATREAD (0x02U) |
Definition at line 52 of file pn532.c.
Referenced by read_ready().
| #define PN532_STARTCODE2 (0xFFU) |
Definition at line 34 of file pn532.c.
Referenced by write_command().
| #define PN532_SYNC_DELAY_MS (100U) |
Definition at line 78 of file pn532.c.
Referenced by pn532_init().
| #define PN532_WAKEUP_BYTE (0x55U) |
Definition at line 97 of file pn532.c.
Referenced by pn532_init_spi().
| #define PN532_WAKEUP_DELAY_MS (1000U) |
Definition at line 77 of file pn532.c.
Referenced by pn532_init_spi().
|
static |
Definition at line 291 of file pn532.c.
References pn532_ack, PN532_ACK_LEN, pn532_buffer_equal(), and read_data().
Referenced by send_command_check_ack().
|
static |
Definition at line 238 of file pn532.c.
References pn532_t::i2c_dev, and PN532_I2C_TIMEOUT_MS.
Referenced by read_ready().
|
static |
Definition at line 301 of file pn532.c.
Referenced by check_ack(), and pn532_get_firmware_version().
|
static |
Definition at line 579 of file pn532.c.
References GPIO_LEVEL_HIGH, GPIO_LEVEL_LOW, GPIO_PIN_BITMASK_BASE, pn532_t::i2c_bus, pn532_config_t::i2c_clock_hz, pn532_t::i2c_dev, pn532_config_t::i2c_port, pn532_config_t::pin_irq, pn532_t::pin_irq, pn532_config_t::pin_rst, pn532_t::pin_rst, pn532_config_t::pin_scl, pn532_config_t::pin_sda, PN532_I2C_ADDRESS, and PN532_LOG_TAG.
Referenced by pn532_init().
|
static |
Definition at line 519 of file pn532.c.
References GPIO_LEVEL_HIGH, GPIO_LEVEL_LOW, GPIO_PIN_BITMASK_BASE, pn532_config_t::pin_cs, pn532_t::pin_cs, pn532_config_t::pin_miso, pn532_config_t::pin_mosi, pn532_config_t::pin_sclk, PN532_CS_TOGGLE_DELAY_MS, PN532_PREAMBLE, PN532_SPI_CLOCK_HZ, PN532_SPI_MODE, PN532_SPI_NO_PIN, PN532_SPI_QUEUE_SIZE, PN532_WAKEUP_BYTE, PN532_WAKEUP_DELAY_MS, pn532_config_t::skip_bus_init, pn532_t::spi, pn532_config_t::spi_host, and spi_write_byte().
Referenced by pn532_init().
|
static |
Definition at line 266 of file pn532.c.
References GPIO_LEVEL_HIGH, GPIO_LEVEL_LOW, pn532_t::i2c_dev, pn532_t::pin_cs, PN532_BYTE_DELAY_MS, PN532_CS_TOGGLE_DELAY_MS, PN532_I2C_RX_MAX, PN532_I2C_TIMEOUT_MS, PN532_SPI_DATAREAD, PN532_TRANSPORT_I2C, spi_read_byte(), spi_write_byte(), and pn532_t::transport.
Referenced by check_ack(), pn532_get_firmware_version(), pn532_read_passive_target_id(), pn532_release_target(), and pn532_sam_config().
|
static |
Definition at line 428 of file pn532.c.
References GPIO_LEVEL_HIGH, GPIO_LEVEL_LOW, pn532_t::i2c_dev, pn532_t::pin_cs, PN532_BYTE_DELAY_MS, PN532_CS_TOGGLE_DELAY_MS, PN532_EXCHANGE_FRAME_MAX, PN532_EXCHANGE_LEN_OFFSET, PN532_EXT_FRAME_HDR_LEN, PN532_EXT_FRAME_INDICATOR, PN532_EXT_FRAME_LENHI_OFFSET, PN532_EXT_FRAME_LENLO_OFFSET, PN532_FRAME_HDR_LEN, PN532_FRAME_TAIL_LEN, PN532_I2C_TIMEOUT_MS, PN532_SPI_DATAREAD, PN532_TRANSPORT_I2C, spi_read_byte(), spi_write_byte(), and pn532_t::transport.
Referenced by pn532_send_apdu().
|
static |
Definition at line 249 of file pn532.c.
References GPIO_LEVEL_HIGH, GPIO_LEVEL_LOW, i2c_read_ready(), pn532_t::pin_cs, PN532_CS_TOGGLE_DELAY_MS, PN532_SPI_STATREAD, PN532_TRANSPORT_I2C, spi_read_byte(), spi_write_byte(), and pn532_t::transport.
Referenced by send_command_check_ack().
|
static |
Definition at line 367 of file pn532.c.
References check_ack(), PN532_LOG_TAG, PN532_POLL_INTERVAL_MS, PN532_SPI_READY, read_ready(), and write_command().
Referenced by pn532_get_firmware_version(), pn532_read_passive_target_id(), pn532_release_target(), pn532_sam_config(), and pn532_send_apdu().
|
static |
Definition at line 220 of file pn532.c.
References PN532_SPI_BITS, and pn532_t::spi.
Referenced by read_data(), read_data_apdu_frame(), and read_ready().
|
static |
Definition at line 211 of file pn532.c.
References PN532_SPI_BITS, and pn532_t::spi.
Referenced by pn532_init_spi(), read_data(), read_data_apdu_frame(), read_ready(), and write_command().
|
static |
Definition at line 315 of file pn532.c.
References GPIO_LEVEL_HIGH, GPIO_LEVEL_LOW, pn532_t::i2c_dev, pn532_t::pin_cs, PN532_CS_TOGGLE_DELAY_MS, PN532_FRAME_TFI_OVERHEAD, PN532_HOSTTOPN532, PN532_I2C_TIMEOUT_MS, PN532_I2C_TX_MAX, PN532_POSTAMBLE, PN532_PREAMBLE, PN532_SPI_DATAWRITE, PN532_STARTCODE2, PN532_TRANSPORT_I2C, spi_write_byte(), and pn532_t::transport.
Referenced by send_command_check_ack().
|
static |
Definition at line 192 of file pn532.c.
Referenced by check_ack().
|
static |
Definition at line 25 of file pn532.c.
Referenced by pn532_get_firmware_version(), pn532_init(), pn532_init_i2c(), pn532_send_apdu(), and send_command_check_ack().
|
static |
Definition at line 197 of file pn532.c.
Referenced by pn532_get_firmware_version().