30 if (
len + 1 > pn532::PN532_FRAME_MAX_SIZE) {
45 ESP_LOGV(TAG,
"Reading response");
51 ESP_LOGV(TAG,
"Reading response of length %d",
len);
53 ESP_LOGD(TAG,
"No response data");
57 if (data[1] != 0x00 || data[2] != 0x00 || data[3] != 0xFF) {
59 ESP_LOGV(TAG,
"read data invalid preamble!");
63 bool valid_header = (
static_cast<uint8_t
>(data[4] + data[5]) == 0 &&
65 data[7] == command + 1);
68 ESP_LOGV(TAG,
"read data invalid header!");
73 constexpr size_t tfi_offset = 6;
77 ESP_LOGV(TAG,
"read data invalid checksum! %02X != %02X", data[tfi_offset +
len + 1],
checksum);
81 if (data[tfi_offset +
len + 2] != 0x00) {
82 ESP_LOGV(TAG,
"read data invalid postamble!");
87 std::copy(data.begin() + tfi_offset + 2, data.begin() + tfi_offset +
len + 1, data.begin());
99 if (data[1] != 0x00 || data[2] != 0x00 || data[3] != 0xFF) {
101 ESP_LOGV(TAG,
"read data invalid preamble!");
105 bool valid_header = (
static_cast<uint8_t
>(data[4] + data[5]) == 0 &&
109 ESP_LOGV(TAG,
"read data invalid header!");
116 uint8_t full_len = data[4];
118 uint8_t
len = full_len - 1;
125 PN532::dump_config();
126 LOG_I2C_DEVICE(
this);
Minimal static vector - saves memory by avoiding std::vector overhead.
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
optional< std::array< uint8_t, N > > read_bytes_raw()
enum PN532ReadReady read_ready_(bool block)
uint8_t read_response_length_()
bool read_data(pn532::PN532Frame &data, size_t len) override
bool write_data(std::span< const uint8_t > data) override
bool read_response(uint8_t command, pn532::PN532Frame &data) override
void dump_config() override
bool is_read_ready() override
@ ERROR_OK
No error found during execution of method.
ESPHOME_LOG_TAG(TAG, "pn532_i2c")
constexpr uint8_t sum_bytes(const uint8_t *data, size_t len, uint8_t sum=0)
Add up the bytes of data with size len, truncated to 8 bits: the checksum many serial and IR protocol...
void HOT delay(uint32_t ms)