12#include <initializer_list>
17static const uint8_t PN532_COMMAND_VERSION_DATA = 0x02;
18static const uint8_t PN532_COMMAND_SAMCONFIGURATION = 0x14;
19static const uint8_t PN532_COMMAND_RFCONFIGURATION = 0x32;
20static const uint8_t PN532_COMMAND_INDATAEXCHANGE = 0x40;
21static const uint8_t PN532_COMMAND_INLISTPASSIVETARGET = 0x4A;
22static const uint8_t PN532_COMMAND_POWERDOWN = 0x16;
31static constexpr uint8_t SEL_RES_MIFARE_CLASSIC = 0x08;
32static constexpr uint8_t SEL_RES_ISO_DEP = 0x20;
33static constexpr uint8_t SEL_RES_TNP3XXX = 0x01;
37 if ((sel_res & SEL_RES_MIFARE_CLASSIC) || sel_res == SEL_RES_TNP3XXX)
38 return nfc::TAG_TYPE_MIFARE_CLASSIC;
39 if (sel_res & SEL_RES_ISO_DEP)
40 return nfc::TAG_TYPE_4;
42 return nfc::TAG_TYPE_2;
43 return nfc::TAG_TYPE_UNKNOWN;
47static constexpr size_t PN532_FRAME_MAX_DATA_SIZE = 254;
50static constexpr size_t PN532_FRAME_MAX_SIZE = 1 + 6 + PN532_FRAME_MAX_DATA_SIZE + 2;
54static constexpr uint32_t MIFARE_ULTRALIGHT_MAX_NDEF_SIZE = 888;
56static constexpr uint32_t MIFARE_CLASSIC_MAX_NDEF_SIZE = 3440;
58static constexpr size_t MIFARE_READ_SIZE = 16;
67 void setup()
override;
76#ifdef PN532_BINARY_SENSOR_COUNT
79#ifdef PN532_ON_TAG_TRIGGER_COUNT
82#ifdef PN532_ON_TAG_REMOVED_TRIGGER_COUNT
102 return this->
write_command_(std::span<const uint8_t>(data.begin(), data.size()));
125 return this->
in_data_exchange_(std::span<const uint8_t>(command.begin(), command.size()), response);
144 uint8_t &message_start_index);
158#ifdef PN532_BINARY_SENSOR_COUNT
161#ifdef PN532_ON_TAG_TRIGGER_COUNT
164#ifdef PN532_ON_TAG_REMOVED_TRIGGER_COUNT
This class simplifies creating components that periodically check a state.
Minimal static vector - saves memory by avoiding std::vector overhead.
Base class for all binary_sensor-type classes.
void publish_state(bool new_state)
Publish a new state to the front-end.
Fires with the formatted UID and the tag itself; the tag is passed by reference so no copy is made pe...
bool process(const nfc::NfcTagUid &data)
void set_uid(const nfc::NfcTagUid &uid)
bool find_mifare_ultralight_ndef_(std::span< const uint8_t > page_3_to_6, uint32_t &message_length, uint8_t &message_start_index)
bool in_data_exchange_(std::initializer_list< uint8_t > command, PN532Frame &response)
StaticVector< nfc::NfcOnTagTrigger *, PN532_ON_TAG_REMOVED_TRIGGER_COUNT > triggers_ontagremoved_
nfc::NfcTagUid current_uid_
void add_on_finished_write_callback(F &&callback)
virtual bool read_data(PN532Frame &data, size_t len)=0
Reads len frame bytes into data behind a leading status byte, so every bus presents the I2C layout.
enum PN532ReadReady read_ready_(bool block)
bool auth_mifare_classic_block_(nfc::NfcTagUid &uid, uint8_t block_num, uint8_t key_num, const uint8_t *key)
uint16_t read_mifare_ultralight_capacity_()
virtual bool is_read_ready()=0
bool mifare_read_(uint8_t address, MifareReadData &data)
Sends MIFARE READ for address and returns the 16 bytes the tag answers with.
LazyCallbackManager< void()> on_finished_write_callback_
bool format_mifare_classic_mifare_(nfc::NfcTagUid &uid)
std::unique_ptr< nfc::NfcTag > read_mifare_ultralight_tag_(nfc::NfcTagUid &uid)
bool write_command_(std::initializer_list< uint8_t > data)
StaticVector< PN532BinarySensor *, PN532_BINARY_SENSOR_COUNT > binary_sensors_
bool write_command_(std::span< const uint8_t > data)
bool format_mifare_classic_ndef_(nfc::NfcTagUid &uid)
bool read_mifare_classic_block_(uint8_t block_num, MifareReadData &data)
virtual bool read_response(uint8_t command, PN532Frame &data)=0
Reads the response to command; on success data holds only the bytes that follow the response code.
void dump_config() override
bool write_mifare_ultralight_page_(uint8_t page_num, std::span< const uint8_t > write_data)
bool write_mifare_classic_tag_(nfc::NfcTagUid &uid, nfc::NdefMessage *message)
std::unique_ptr< nfc::NfcTag > read_mifare_classic_tag_(nfc::NfcTagUid &uid)
void register_ontagremoved_trigger(nfc::NfcOnTagTrigger *trig)
void register_tag(PN532BinarySensor *tag)
void on_powerdown() override
std::unique_ptr< nfc::NdefMessage > next_task_message_to_write_
bool clean_mifare_ultralight_()
void write_mode(nfc::NdefMessage *message)
bool write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, nfc::NdefMessage *message)
bool read_mifare_ultralight_bytes_(uint8_t start_page, std::span< uint8_t > data)
Fills data with the bytes from start_page onward.
std::unique_ptr< nfc::NfcTag > read_tag_(nfc::NfcTagUid &uid, uint8_t tag_type)
bool write_mifare_classic_block_(uint8_t block_num, std::span< const uint8_t > data)
virtual bool write_data(std::span< const uint8_t > data)=0
void register_ontag_trigger(nfc::NfcOnTagTrigger *trig)
bool in_data_exchange_(std::span< const uint8_t > command, PN532Frame &response)
Sends an InDataExchange command and reads the response; returns false unless the status byte reports ...
StaticVector< nfc::NfcOnTagTrigger *, PN532_ON_TAG_TRIGGER_COUNT > triggers_ontag_
bool clean_tag_(nfc::NfcTagUid &uid, uint8_t tag_type)
bool write_tag_(nfc::NfcTagUid &uid, uint8_t tag_type, nfc::NdefMessage *message)
bool is_mifare_ultralight_formatted_(std::span< const uint8_t > page_3_to_6)
bool format_tag_(nfc::NfcTagUid &uid, uint8_t tag_type)
const LogString * message
uint8_t tag_type_from_sel_res(uint8_t sel_res)
Tag type (nfc::TAG_TYPE_*) from a type A target's SEL_RES byte.
std::array< uint8_t, MIFARE_READ_SIZE > MifareReadData
std::array< uint8_t, MIFARE_READ_SIZE > UltralightHeader
Pages 3 to 6, read in one go: the capability container and the start of the NDEF TLV.