ESPHome 2025.5.0
Loading...
Searching...
No Matches
pn7150_i2c.cpp
Go to the documentation of this file.
1#include "pn7150_i2c.h"
2#include "esphome/core/log.h"
3#include "esphome/core/hal.h"
4
5namespace esphome {
6namespace pn7150_i2c {
7
8static const char *const TAG = "pn7150_i2c";
9
10uint8_t PN7150I2C::read_nfcc(nfc::NciMessage &rx, const uint16_t timeout) {
11 if (this->wait_for_irq_(timeout) != nfc::STATUS_OK) {
12 ESP_LOGW(TAG, "read_nfcc_() timeout waiting for IRQ");
13 return nfc::STATUS_FAILED;
14 }
15
16 rx.get_message().resize(nfc::NCI_PKT_HEADER_SIZE);
17 if (!this->read_bytes_raw(rx.get_message().data(), nfc::NCI_PKT_HEADER_SIZE)) {
18 return nfc::STATUS_FAILED;
19 }
20
21 uint8_t length = rx.get_payload_size();
22 if (length > 0) {
23 rx.get_message().resize(length + nfc::NCI_PKT_HEADER_SIZE);
24 if (!this->read_bytes_raw(rx.get_message().data() + nfc::NCI_PKT_HEADER_SIZE, length)) {
25 return nfc::STATUS_FAILED;
26 }
27 }
28 // semaphore to ensure transaction is complete before returning
29 if (this->wait_for_irq_(pn7150::NFCC_DEFAULT_TIMEOUT, false) != nfc::STATUS_OK) {
30 ESP_LOGW(TAG, "read_nfcc_() post-read timeout waiting for IRQ line to clear");
31 return nfc::STATUS_FAILED;
32 }
33 return nfc::STATUS_OK;
34}
35
37 if (this->write(tx.encode().data(), tx.encode().size()) == i2c::ERROR_OK) {
38 return nfc::STATUS_OK;
39 }
40 return nfc::STATUS_FAILED;
41}
42
44 PN7150::dump_config();
45 LOG_I2C_DEVICE(this);
46}
47
48} // namespace pn7150_i2c
49} // namespace esphome
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
Definition i2c.h:190
optional< std::array< uint8_t, N > > read_bytes_raw()
Definition i2c.h:229
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 pn7150.cpp:1130
uint8_t read_nfcc(nfc::NciMessage &rx, uint16_t timeout) override
uint8_t write_nfcc(nfc::NciMessage &tx) override
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:13
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t length
Definition tt21100.cpp:0