12 static const char *
const TAG =
"pn532_spi";
15 ESP_LOGI(TAG,
"PN532Spi setup started!");
20 ESP_LOGI(TAG,
"SPI setup finished!");
54 ESP_LOGV(TAG,
"Reading data...");
59 data.insert(data.begin(), 0x01);
65 ESP_LOGV(TAG,
"Reading response");
75 std::vector<uint8_t> header(7);
80 if (header[0] != 0x00 && header[1] != 0x00 && header[2] != 0xFF) {
82 ESP_LOGV(TAG,
"read data invalid preamble!");
86 bool valid_header = (
static_cast<uint8_t
>(header[3] + header[4]) == 0 &&
88 header[6] == command + 1);
91 ESP_LOGV(TAG,
"read data invalid header!");
96 uint8_t full_len = header[3];
98 uint8_t
len = full_len - 1;
102 ESP_LOGV(TAG,
"Reading response of length %d", len);
104 data.resize(len + 1);
110 uint8_t
checksum = header[5] + header[6];
111 for (
int i = 0; i < len - 1; i++) {
112 uint8_t dat = data[i];
115 checksum = ~checksum + 1;
117 if (data[len - 1] != checksum) {
118 ESP_LOGV(TAG,
"read data invalid checksum! %02X != %02X", data[len - 1], checksum);
122 if (data[len] != 0x00) {
123 ESP_LOGV(TAG,
"read data invalid postamble!");
127 data.erase(data.end() - 2, data.end());
133 PN532::dump_config();
134 LOG_PIN(
" CS Pin: ", this->
cs_);
virtual void digital_write(bool value)=0
std::string format_hex_pretty(const uint8_t *data, size_t length)
Format the byte array data of length len in pretty-printed, human-readable hex.
void spi_setup() override
void dump_config() override
bool read_response(uint8_t command, std::vector< uint8_t > &data) override
bool read_data(std::vector< uint8_t > &data, uint8_t len) override
void write_byte(uint8_t data)
enum PN532ReadReady read_ready_(bool block)
bool write_data(const std::vector< uint8_t > &data) override
void read_array(uint8_t *data, size_t length)
void write_array(const uint8_t *data, size_t length)
Implementation of SPI Controller mode.
bool is_read_ready() override
void IRAM_ATTR HOT delay(uint32_t ms)