ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
pn7150.cpp
Go to the documentation of this file.
1#include "pn7150.h"
2
3#include "esphome/core/log.h"
4
5namespace esphome::pn7150 {
6
7ESPHOME_LOG_TAG(TAG, "pn7150");
8
10 ESP_LOGCONFIG(TAG, "PN7150:");
11 PN71xx::dump_config();
12}
13
14uint8_t PN7150::verify_reset(nfc::NciMessage &rx, const bool reset_config) {
15 // CORE_RESET_RSP payload: status, NCI version (reported as 1.1, see UM10936 4.1), configuration status
16 if ((!rx.message_type_is(nfc::NCI_PKT_MT_CTRL_RESPONSE)) || (!rx.message_length_is(3)) ||
17 (rx.get_message()[nfc::NCI_PKT_PAYLOAD_OFFSET + 1] != 0x11) ||
18 (rx.get_message()[nfc::NCI_PKT_PAYLOAD_OFFSET + 2] != (uint8_t) reset_config)) {
19 char buf[nfc::FORMAT_BYTES_BUFFER_SIZE];
20 ESP_LOGE(TAG, "Reset response was malformed: %s", nfc::format_bytes_to(buf, rx.get_message()));
21 return nfc::STATUS_FAILED;
22 }
23
24 ESP_LOGD(TAG, "Configuration %s, NCI version: 0x%02X",
25 rx.get_message()[nfc::NCI_PKT_PAYLOAD_OFFSET + 2] ? LOG_STR_LITERAL("reset") : LOG_STR_LITERAL("retained"),
26 rx.get_message()[nfc::NCI_PKT_PAYLOAD_OFFSET + 1]);
27
28 return nfc::STATUS_OK;
29}
30
32 // NCI 1.0 CORE_INIT_RSP: the manufacturer ID and 4 bytes of manufacturer specific information follow the list of
33 // supported RF interfaces, whose length is at offset 8 (UM10936, 5.2)
34 const auto &msg = rx.get_message();
35 if (msg.size() < 9u || msg.size() < 20u + msg[8]) {
36 char buf[nfc::FORMAT_BYTES_BUFFER_SIZE];
37 ESP_LOGE(TAG, "Initialise response too short: %s", nfc::format_bytes_to(buf, msg));
38 return nfc::STATUS_FAILED;
39 }
40 const uint8_t n = msg[8];
41
42 ESP_LOGD(TAG,
43 "PN7150 chip info:\n"
44 " Manufacturer ID: 0x%02X\n"
45 " Hardware version: 0x%02X\n"
46 " ROM code version: 0x%02X\n"
47 " FLASH major version: 0x%02X\n"
48 " FLASH minor version: 0x%02X",
49 msg[15 + n], msg[16 + n], msg[17 + n], msg[18 + n], msg[19 + n]);
50
52}
53
54} // namespace esphome::pn7150
One NCI packet, held in a fixed buffer so building and reading messages never allocates.
Definition nci_message.h:16
bool message_type_is(uint8_t message_type) const
bool message_length_is(uint8_t message_length, bool recompute=false)
uint8_t get_simple_status_response() const
uint8_t process_init_response(nfc::NciMessage &rx) override
Definition pn7150.cpp:31
uint8_t verify_reset(nfc::NciMessage &rx, bool reset_config) override
Definition pn7150.cpp:14
void dump_config() override
Definition pn7150.cpp:9
char * format_bytes_to(char *buffer, std::span< const uint8_t > bytes)
Format bytes to buffer with ' ' separator (e.g., "04 11 22 33"). Returns buffer for inline use.
Definition nfc.cpp:14
ESPHOME_LOG_TAG(TAG, "pn7150")