ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
pn7160_spi.cpp
Go to the documentation of this file.
1#include "pn7160_spi.h"
2#include "esphome/core/log.h"
3
5
6static const char *const TAG = "pn7160_spi";
7
9 this->spi_setup();
10 this->cs_->digital_write(false);
11 PN7160::setup();
12}
13
14uint8_t PN7160Spi::read_nfcc(nfc::NciMessage &rx, const uint16_t timeout) {
15 if (this->wait_for_irq_(timeout) != nfc::STATUS_OK) {
16 ESP_LOGW(TAG, "read_nfcc_() timeout waiting for IRQ");
17 return nfc::STATUS_FAILED;
18 }
19
20 rx.get_message().resize(nfc::NCI_PKT_HEADER_SIZE);
21 this->enable();
22 this->write_byte(TDD_SPI_READ); // send "transfer direction detector"
23 this->read_array(rx.get_message().data(), nfc::NCI_PKT_HEADER_SIZE);
24
25 uint8_t length = rx.get_payload_size();
26 if (length > 0) {
27 rx.get_message().resize(length + nfc::NCI_PKT_HEADER_SIZE);
28 this->read_array(rx.get_message().data() + nfc::NCI_PKT_HEADER_SIZE, length);
29 }
30 this->disable();
31 // semaphore to ensure transaction is complete before returning
32 if (this->wait_for_irq_(pn7160::NFCC_DEFAULT_TIMEOUT, false) != nfc::STATUS_OK) {
33 ESP_LOGW(TAG, "read_nfcc_() post-read timeout waiting for IRQ line to clear");
34 return nfc::STATUS_FAILED;
35 }
36 return nfc::STATUS_OK;
37}
38
40 this->enable();
41 this->write_byte(TDD_SPI_WRITE); // send "transfer direction detector"
42 this->write_array(tx.encode().data(), tx.encode().size());
43 this->disable();
44 return nfc::STATUS_OK;
45}
46
48 PN7160::dump_config();
49 LOG_PIN(" CS Pin: ", this->cs_);
50}
51
52} // namespace esphome::pn7160_spi
virtual void digital_write(bool value)=0
uint8_t get_payload_size(bool recompute=false)
std::vector< uint8_t > encode()
std::vector< uint8_t > & get_message()
uint8_t wait_for_irq_(uint16_t timeout=NFCC_DEFAULT_TIMEOUT, bool pin_state=true)
Definition pn7160.cpp:1176
uint8_t read_nfcc(nfc::NciMessage &rx, uint16_t timeout) override
uint8_t write_nfcc(nfc::NciMessage &tx) override
uint16_t length
Definition tt21100.cpp:0