DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
pn532.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file pn532.h
6 * @brief PN532 NFC frame codec (DETWS_ENABLE_PN532) - NXP PN532 NFC/RFID controller.
7 *
8 * The command-frame protocol of the NXP PN532 (the ubiquitous NFC reader on I2C / SPI /
9 * HSU breakouts): a tag read/write bridged to an HTTP / MQTT event. The host and the chip
10 * exchange **normal information frames**:
11 *
12 * 00 | 00 FF | LEN | LCS | TFI | PD0..PDn | DCS | 00
13 *
14 * where TFI is 0xD4 (host -> PN532) or 0xD5 (PN532 -> host), LEN counts TFI + PData, LCS is
15 * the length checksum (LEN + LCS == 0), and DCS is the data checksum (TFI + sum(PData) + DCS
16 * == 0). A short 6-byte **ACK frame** (00 00 FF 00 FF 00) confirms each command.
17 *
18 * pn532_build_frame() assembles a frame carrying a command + parameters, pn532_parse_frame()
19 * frames + verifies a response, and pn532_is_ack() detects the ACK. The per-command PData
20 * (GetFirmwareVersion, InListPassiveTarget, InDataExchange, ...) is the application's. Pure -
21 * you carry the bytes over your I2C / SPI / UART - so it is fully host-testable.
22 *
23 * @author Douglas Quigg (dstroy0)
24 * @date 2026
25 */
26
27#ifndef DETERMINISTICESPASYNCWEBSERVER_PN532_H
28#define DETERMINISTICESPASYNCWEBSERVER_PN532_H
29
30#include "ServerConfig.h"
31
32#if DETWS_ENABLE_PN532
33
34#include <stddef.h>
35#include <stdint.h>
36
37/** @brief Frame identifier: host -> PN532. */
38#define PN532_TFI_HOST 0xD4
39/** @brief Frame identifier: PN532 -> host. */
40#define PN532_TFI_PN532 0xD5
41
42/**
43 * @brief Assemble a normal information frame carrying @p tfi + @p data into @p out.
44 * @return the total frame length, or 0 if it would not fit @p cap or @p len exceeds
45 * DETWS_PN532_MAX_DATA.
46 */
47uint16_t pn532_build_frame(uint8_t tfi, const uint8_t *data, uint8_t len, uint8_t *out, uint16_t cap);
48
49/**
50 * @brief Frame one normal information frame from the front of @p raw and verify LCS + DCS.
51 * @param[out] tfi set to the frame identifier.
52 * @param[out] pdata set to the first PData byte (points into @p raw).
53 * @param[out] pdata_len set to the PData length (LEN - 1).
54 * @return the frame length consumed (> 0), 0 if more bytes are needed, or -1 if @p raw[0]
55 * does not start a valid frame (wrong preamble / start / LCS / DCS / over-length).
56 */
57int pn532_parse_frame(const uint8_t *raw, uint16_t len, uint8_t *tfi, const uint8_t **pdata, uint8_t *pdata_len);
58
59/** @brief True if @p raw starts with a PN532 ACK frame (00 00 FF 00 FF 00). */
60bool pn532_is_ack(const uint8_t *raw, uint16_t len);
61
62/** @brief Write the 6-byte ACK frame into @p out. @return 6, or 0 if @p cap < 6. */
63uint16_t pn532_build_ack(uint8_t *out, uint16_t cap);
64
65#endif // DETWS_ENABLE_PN532
66
67#endif // DETERMINISTICESPASYNCWEBSERVER_PN532_H
User-facing configuration for DeterministicESPAsyncWebServer.