ESPHome 2026.7.0
Loading...
Searching...
No Matches
ethernet_component_esp32.cpp
Go to the documentation of this file.
2
3#if defined(USE_ETHERNET) && defined(USE_ESP32)
4
7#include "esphome/core/log.h"
8#include "w5500_custom_spi.h"
9
10#include <lwip/dns.h>
11#include <cinttypes>
12#include "esp_event.h"
13
14// IDF 6.0 moved per-chip PHY/MAC drivers to the Espressif Component Registry;
15// they are no longer included via esp_eth.h and need explicit includes.
16// On IDF 5.x these headers don't exist as standalone files.
17#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
18#ifdef USE_ETHERNET_LAN8720
19#include "esp_eth_phy_lan87xx.h"
20#endif
21#ifdef USE_ETHERNET_RTL8201
22#include "esp_eth_phy_rtl8201.h"
23#endif
24#ifdef USE_ETHERNET_DP83848
25#include "esp_eth_phy_dp83848.h"
26#endif
27#ifdef USE_ETHERNET_IP101
28#include "esp_eth_phy_ip101.h"
29#endif
30#ifdef USE_ETHERNET_KSZ8081
31#include "esp_eth_phy_ksz80xx.h"
32#endif
33#ifdef USE_ETHERNET_W5500
34#include "esp_eth_mac_w5500.h"
35#include "esp_eth_phy_w5500.h"
36#endif
37#ifdef USE_ETHERNET_DM9051
38#include "esp_eth_mac_dm9051.h"
39#include "esp_eth_phy_dm9051.h"
40#endif
41#endif // ESP_IDF_VERSION >= 6.0.0
42
43// LAN867x header exists on all IDF versions (external component since IDF 5.3)
44#ifdef USE_ETHERNET_LAN8670
45#include "esp_eth_phy_lan867x.h"
46#endif
47
48// ENC28J60 header exists on all IDF versions (always an external component)
49#ifdef USE_ETHERNET_ENC28J60
50#include "esp_eth_enc28j60.h"
51#endif
52
53#ifdef USE_ETHERNET_SPI
54#include <driver/gpio.h>
55#include <driver/spi_master.h>
56#endif
57
58namespace esphome::ethernet {
59
60static const char *const TAG = "ethernet";
61
62// PHY register size for hex logging
63static constexpr size_t PHY_REG_SIZE = 2;
64
66 ESP_LOGE(TAG, "%s: (%d) %s", message, err, esp_err_to_name(err));
67 this->mark_failed();
68}
69
70#define ESPHL_ERROR_CHECK(err, message) \
71 if ((err) != ESP_OK) { \
72 this->log_error_and_mark_failed_(err, message); \
73 return; \
74 }
75
76#define ESPHL_ERROR_CHECK_RET(err, message, ret) \
77 if ((err) != ESP_OK) { \
78 this->log_error_and_mark_failed_(err, message); \
79 return ret; \
80 }
81
84
85 switch (this->state_) {
87 if (this->started_) {
88 ESP_LOGI(TAG, "Starting connection");
90 this->start_connect_();
91 }
92 break;
94 if (!this->started_) {
95 ESP_LOGI(TAG, "Stopped connection");
97 } else if (this->connected_) {
98 // connection established
99 ESP_LOGI(TAG, "Connected");
101
102 this->dump_connect_params_();
103 this->status_clear_warning();
104#ifdef USE_ETHERNET_CONNECT_TRIGGER
106#endif
107 } else if (now - this->connect_begin_ > 15000) {
108 ESP_LOGW(TAG, "Connecting failed; reconnecting");
109 this->start_connect_();
110 }
111 break;
113 if (!this->started_) {
114 ESP_LOGI(TAG, "Stopped connection");
116#ifdef USE_ETHERNET_DISCONNECT_TRIGGER
118#endif
119 } else if (!this->connected_) {
120 ESP_LOGW(TAG, "Connection lost; reconnecting");
122 this->start_connect_();
123#ifdef USE_ETHERNET_DISCONNECT_TRIGGER
125#endif
126 } else {
127 this->finish_connect_();
128 // When connected and stable, disable the loop to save CPU cycles
129 this->disable_loop();
130 }
131 break;
132 }
133}
134
136 if (esp_reset_reason() != ESP_RST_DEEPSLEEP) {
137 // Delay here to allow power to stabilise before Ethernet is initialized.
138 delay(300); // NOLINT
139 }
140
141 if (this->enable_on_boot_) {
142 this->ethernet_lazy_init_();
143 if (!this->ethernet_initialized_) {
144 // lazy_init bailed early via ESPHL_ERROR_CHECK or mark_failed; nothing more to do.
145 return;
146 }
147 esp_err_t err = esp_eth_start(this->eth_handle_);
148 ESPHL_ERROR_CHECK(err, "ETH start error");
149 } else {
150 ESP_LOGCONFIG(TAG, "Skipping init (enable_on_boot: false)");
151 this->disabled_ = true;
152 }
153}
154
156 if (this->ethernet_initialized_)
157 return;
158
159 esp_err_t err;
160
161#ifdef USE_ETHERNET_SPI
162 // Install GPIO ISR handler to be able to service SPI Eth modules interrupts
163 gpio_install_isr_service(0);
164
165 spi_bus_config_t buscfg = {
166 .mosi_io_num = this->mosi_pin_,
167 .miso_io_num = this->miso_pin_,
168 .sclk_io_num = this->clk_pin_,
169 .quadwp_io_num = -1,
170 .quadhd_io_num = -1,
171 .data4_io_num = -1,
172 .data5_io_num = -1,
173 .data6_io_num = -1,
174 .data7_io_num = -1,
175 .max_transfer_sz = 0,
176 .flags = 0,
177 .intr_flags = 0,
178 };
179
180 auto host = this->interface_;
181
182 err = spi_bus_initialize(host, &buscfg, SPI_DMA_CH_AUTO);
183 ESPHL_ERROR_CHECK(err, "SPI bus initialize error");
184#endif
185 // Network interface setup handled by network component
186
187 esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
188 this->eth_netif_ = esp_netif_new(&cfg);
189
190 // Init MAC and PHY configs to default
191 eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
192 eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
193
194#ifdef USE_ETHERNET_SPI // Configure SPI interface and Ethernet driver for specific SPI module
195 spi_device_interface_config_t devcfg = {
196 .command_bits = 0,
197 .address_bits = 0,
198 .dummy_bits = 0,
199 .mode = 0,
200 .duty_cycle_pos = 0,
201 .cs_ena_pretrans = 0,
202 .cs_ena_posttrans = 0,
203 .clock_speed_hz = this->clock_speed_,
204 .input_delay_ns = 0,
205 .spics_io_num = this->cs_pin_,
206 .flags = 0,
207 .queue_size = 20,
208 .pre_cb = nullptr,
209 .post_cb = nullptr,
210 };
211
212#if defined(USE_ETHERNET_W5500)
213 eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG(host, &devcfg);
214#elif defined(USE_ETHERNET_DM9051)
215 eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(host, &devcfg);
216#elif defined(USE_ETHERNET_ENC28J60)
217 eth_enc28j60_config_t enc28j60_config = ETH_ENC28J60_DEFAULT_CONFIG(host, &devcfg);
218#endif
219
220#if defined(USE_ETHERNET_W5500)
221 w5500_config.int_gpio_num = this->interrupt_pin_;
222#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
223 w5500_config.poll_period_ms = this->polling_interval_;
224#endif
225 // Install the custom SPI driver that offloads the bulk RX/TX frame transfers off the busy-wait
226 // path. w5500_config (and the devcfg it references) outlives esp_eth_mac_new_w5500() below, which
227 // runs the driver's init().
228 install_w5500_async_spi(w5500_config);
229#elif defined(USE_ETHERNET_DM9051)
230 dm9051_config.int_gpio_num = this->interrupt_pin_;
231#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
232 dm9051_config.poll_period_ms = this->polling_interval_;
233#endif
234#elif defined(USE_ETHERNET_ENC28J60)
235 enc28j60_config.int_gpio_num = this->interrupt_pin_;
236 // ENC28J60 does not support poll_period_ms
237#endif
238
239 phy_config.phy_addr = this->phy_addr_spi_;
240 phy_config.reset_gpio_num = this->reset_pin_;
241
242 esp_eth_mac_t *mac = nullptr;
243#elif defined(USE_ETHERNET_OPENETH)
244 esp_eth_mac_t *mac = esp_eth_mac_new_openeth(&mac_config);
245#else
246 phy_config.phy_addr = this->phy_addr_;
247 phy_config.reset_gpio_num = this->power_pin_;
248
249 eth_esp32_emac_config_t esp32_emac_config = eth_esp32_emac_default_config();
250#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
251 esp32_emac_config.smi_gpio.mdc_num = this->mdc_pin_;
252 esp32_emac_config.smi_gpio.mdio_num = this->mdio_pin_;
253#else
254 esp32_emac_config.smi_mdc_gpio_num = this->mdc_pin_;
255 esp32_emac_config.smi_mdio_gpio_num = this->mdio_pin_;
256#endif
257 // The RGMII types (GENERIC, YT8531) use the RGMII interface and default GPIO map from
258 // eth_esp32_emac_default_config(); writing the RMII clock config would clobber that
259 // union, so skip the RMII clock override for them.
260 if (this->type_ != ETHERNET_TYPE_GENERIC && this->type_ != ETHERNET_TYPE_YT8531) {
261 esp32_emac_config.clock_config.rmii.clock_mode = this->clk_mode_;
262 esp32_emac_config.clock_config.rmii.clock_gpio =
263 static_cast<decltype(esp32_emac_config.clock_config.rmii.clock_gpio)>(this->clk_pin_);
264 }
265
266 esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config);
267#endif
268
269 switch (this->type_) {
270#ifdef USE_ETHERNET_OPENETH
272 phy_config.autonego_timeout_ms = 1000;
273#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
274 this->phy_ = esp_eth_phy_new_generic(&phy_config);
275#else
276 this->phy_ = esp_eth_phy_new_dp83848(&phy_config);
277#endif
278 break;
279 }
280#endif
281#if CONFIG_ETH_USE_ESP32_EMAC
282#ifdef USE_ETHERNET_LAN8720
284 this->phy_ = esp_eth_phy_new_lan87xx(&phy_config);
285 break;
286 }
287#endif
288#ifdef USE_ETHERNET_RTL8201
290 this->phy_ = esp_eth_phy_new_rtl8201(&phy_config);
291 break;
292 }
293#endif
294#ifdef USE_ETHERNET_DP83848
296 this->phy_ = esp_eth_phy_new_dp83848(&phy_config);
297 break;
298 }
299#endif
300#ifdef USE_ETHERNET_IP101
301 case ETHERNET_TYPE_IP101: {
302 this->phy_ = esp_eth_phy_new_ip101(&phy_config);
303 break;
304 }
305#endif
306#ifdef USE_ETHERNET_JL1101
308 // PlatformIO (pioarduino): builtin esp_eth_phy_new_jl1101() on all IDF versions
309 // Non-PlatformIO: custom ESPHome driver (esp_eth_phy_jl1101.c)
310 this->phy_ = esp_eth_phy_new_jl1101(&phy_config);
311 break;
312 }
313#endif
314#ifdef USE_ETHERNET_KSZ8081
317 this->phy_ = esp_eth_phy_new_ksz80xx(&phy_config);
318 break;
319 }
320#endif
321#ifdef USE_ETHERNET_LAN8670
323 this->phy_ = esp_eth_phy_new_lan867x(&phy_config);
324 break;
325 }
326#endif
327#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
328 // GENERIC and YT8531 both use the built-in generic 802.3 PHY driver; YT8531 gets
329 // extra chip-specific tuning applied later in ethernet_lazy_init_().
330#ifdef USE_ETHERNET_GENERIC
332#endif
333#ifdef USE_ETHERNET_YT8531
335#endif
336#if defined(USE_ETHERNET_GENERIC) || defined(USE_ETHERNET_YT8531)
337 this->phy_ = esp_eth_phy_new_generic(&phy_config);
338 break;
339#endif
340#endif
341#endif
342#ifdef USE_ETHERNET_SPI
343#if defined(USE_ETHERNET_W5500)
344 case ETHERNET_TYPE_W5500: {
345 mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
346 this->phy_ = esp_eth_phy_new_w5500(&phy_config);
347 break;
348 }
349#elif defined(USE_ETHERNET_DM9051)
351 mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
352 this->phy_ = esp_eth_phy_new_dm9051(&phy_config);
353 break;
354 }
355#elif defined(USE_ETHERNET_ENC28J60)
357 mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config);
358 this->phy_ = esp_eth_phy_new_enc28j60(&phy_config);
359 break;
360 }
361#endif
362#endif
363 default: {
364 this->mark_failed();
365 return;
366 }
367 }
368
369 esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, this->phy_);
370 this->eth_handle_ = nullptr;
371 err = esp_eth_driver_install(&eth_config, &this->eth_handle_);
372 ESPHL_ERROR_CHECK(err, "ETH driver install error");
373
374#ifndef USE_ETHERNET_SPI
375#ifdef USE_ETHERNET_KSZ8081
376 if (this->type_ == ETHERNET_TYPE_KSZ8081RNA && this->clk_mode_ == EMAC_CLK_OUT) {
377 // KSZ8081RNA default is incorrect. It expects a 25MHz clock instead of the 50MHz we provide.
379 }
380#endif // USE_ETHERNET_KSZ8081
381
382 for (const auto &phy_register : this->phy_registers_) {
383 this->write_phy_register_(mac, phy_register);
384 }
385
386#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
387#ifdef USE_ETHERNET_GENERIC
388 // The generic 802.3 PHY driver only resets the PHY in its init; it never enables
389 // auto-negotiation. A PHY that resets into a forced-speed mode (BMCR auto-nego bit
390 // clear) therefore stays there, and esp_eth_start() skips negotiation because the
391 // driver cached auto_nego_en=false at install time. Force auto-negotiation on here
392 // (which also updates that cached state) so esp_eth_start() restarts a proper
393 // negotiation. (YT8531 does this as part of its own chip-specific init below.)
394 if (this->type_ == ETHERNET_TYPE_GENERIC) {
395 bool autoneg_enable = true;
396 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_AUTONEGO, &autoneg_enable);
397 ESPHL_ERROR_CHECK(err, "Enable auto-negotiation failed");
398 }
399#endif
400#ifdef USE_ETHERNET_YT8531
401 if (this->type_ == ETHERNET_TYPE_YT8531) {
402 this->yt8531_phy_init_();
403 if (this->is_failed())
404 return;
405 }
406#endif
407#endif // ESP_IDF_VERSION >= 6.0.0
408#endif // !USE_ETHERNET_SPI
409
410 // use ESP internal eth mac
411 uint8_t mac_addr[6];
412 if (this->fixed_mac_.has_value()) {
413 memcpy(mac_addr, this->fixed_mac_->data(), 6);
414 } else {
415 esp_read_mac(mac_addr, ESP_MAC_ETH);
416 }
417 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_MAC_ADDR, mac_addr);
418 ESPHL_ERROR_CHECK(err, "set mac address error");
419
420 /* attach Ethernet driver to TCP/IP stack */
421 err = esp_netif_attach(this->eth_netif_, esp_eth_new_netif_glue(this->eth_handle_));
422 ESPHL_ERROR_CHECK(err, "ETH netif attach error");
423
424 // Register user defined event handers
425 err = esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &EthernetComponent::eth_event_handler, nullptr);
426 ESPHL_ERROR_CHECK(err, "ETH event handler register error");
427 err = esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &EthernetComponent::got_ip_event_handler, nullptr);
428 ESPHL_ERROR_CHECK(err, "GOT IP event handler register error");
429#if USE_NETWORK_IPV6
430 err = esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &EthernetComponent::got_ip6_event_handler, nullptr);
431 ESPHL_ERROR_CHECK(err, "GOT IPv6 event handler register error");
432#endif /* USE_NETWORK_IPV6 */
433
434 this->ethernet_initialized_ = true;
435}
436
438 if (!this->disabled_)
439 return;
440
441 ESP_LOGD(TAG, "Enabling");
442 this->ethernet_lazy_init_();
443 if (!this->ethernet_initialized_) {
444 ESP_LOGE(TAG, "Cannot enable - init failed");
445 return;
446 }
447 esp_err_t err = esp_eth_start(this->eth_handle_);
448 if (err != ESP_OK) {
449 ESP_LOGE(TAG, "esp_eth_start failed: %s", esp_err_to_name(err));
450 return;
451 }
452 this->disabled_ = false;
453 // The ETH_EVENT_START handler will set started_=true; the loop state machine
454 // will then drive the STOPPED -> CONNECTING -> CONNECTED transitions.
455 this->enable_loop();
456}
457
459 if (this->disabled_)
460 return;
461
462 ESP_LOGD(TAG, "Disabling");
463 esp_err_t err = esp_eth_stop(this->eth_handle_);
464 if (err != ESP_OK) {
465 ESP_LOGW(TAG, "esp_eth_stop failed: %s — disabling anyway", esp_err_to_name(err));
466 }
467 this->disabled_ = true;
468 // ETH_EVENT_STOP will clear started_; loop() will transition to STOPPED.
469}
470
472 const char *eth_type;
473 switch (this->type_) {
474#ifdef USE_ETHERNET_LAN8720
476 eth_type = "LAN8720";
477 break;
478#endif
479#ifdef USE_ETHERNET_RTL8201
481 eth_type = "RTL8201";
482 break;
483#endif
484#ifdef USE_ETHERNET_DP83848
486 eth_type = "DP83848";
487 break;
488#endif
489#ifdef USE_ETHERNET_IP101
491 eth_type = "IP101";
492 break;
493#endif
494#ifdef USE_ETHERNET_JL1101
496 eth_type = "JL1101";
497 break;
498#endif
499#ifdef USE_ETHERNET_KSZ8081
501 eth_type = "KSZ8081";
502 break;
503
505 eth_type = "KSZ8081RNA";
506 break;
507#endif
508#if defined(USE_ETHERNET_W5500)
510 eth_type = "W5500";
511 break;
512#elif defined(USE_ETHERNET_DM9051)
514 eth_type = "DM9051";
515 break;
516#elif defined(USE_ETHERNET_ENC28J60)
518 eth_type = "ENC28J60";
519 break;
520#endif
521#ifdef USE_ETHERNET_OPENETH
523 eth_type = "OPENETH";
524 break;
525#endif
526#ifdef USE_ETHERNET_LAN8670
528 eth_type = "LAN8670";
529 break;
530#endif
531#ifdef USE_ETHERNET_GENERIC
533 eth_type = "Generic (RGMII)";
534 break;
535#endif
536#ifdef USE_ETHERNET_YT8531
538 eth_type = "YT8531 (RGMII)";
539 break;
540#endif
541
542 default:
543 eth_type = "Unknown";
544 break;
545 }
546
547 ESP_LOGCONFIG(TAG,
548 "Ethernet:\n"
549 " Connected: %s",
550 YESNO(this->is_connected()));
551 this->dump_connect_params_();
552#ifdef USE_ETHERNET_SPI
553 ESP_LOGCONFIG(TAG,
554 " CLK Pin: %u\n"
555 " MISO Pin: %u\n"
556 " MOSI Pin: %u\n"
557 " CS Pin: %u",
558 this->clk_pin_, this->miso_pin_, this->mosi_pin_, this->cs_pin_);
559 const char *spi_interface = "spi3";
560 if (this->interface_ == SPI2_HOST) {
561 spi_interface = "spi2";
562 }
563 ESP_LOGCONFIG(TAG, " Interface: %s", spi_interface);
564#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
565 if (this->polling_interval_ != 0) {
566 ESP_LOGCONFIG(TAG, " Polling Interval: %" PRIu32 " ms", this->polling_interval_);
567 } else
568#endif
569 {
570 ESP_LOGCONFIG(TAG, " IRQ Pin: %d", this->interrupt_pin_);
571 }
572 ESP_LOGCONFIG(TAG,
573 " Reset Pin: %d\n"
574 " Clock Speed: %d MHz",
575 this->reset_pin_, this->clock_speed_ / 1000000);
576#else
577 if (this->power_pin_ != -1) {
578 ESP_LOGCONFIG(TAG, " Power Pin: %u", this->power_pin_);
579 }
580 ESP_LOGCONFIG(TAG,
581 " CLK Pin: %u\n"
582 " MDC Pin: %u\n"
583 " MDIO Pin: %u\n"
584 " PHY addr: %u",
585 this->clk_pin_, this->mdc_pin_, this->mdio_pin_, this->phy_addr_);
586#endif
587 ESP_LOGCONFIG(TAG, " Type: %s", eth_type);
588}
589
591 network::IPAddresses addresses;
592 if (!this->ethernet_initialized_)
593 return addresses; // all-zero IPs
594 esp_netif_ip_info_t ip;
595 esp_err_t err = esp_netif_get_ip_info(this->eth_netif_, &ip);
596 if (err != ESP_OK) {
597 ESP_LOGV(TAG, "esp_netif_get_ip_info failed: %s", esp_err_to_name(err));
598 // TODO: do something smarter
599 // return false;
600 } else {
601 addresses[0] = network::IPAddress(&ip.ip);
602 }
603#if USE_NETWORK_IPV6
604 struct esp_ip6_addr if_ip6s[CONFIG_LWIP_IPV6_NUM_ADDRESSES];
605 uint8_t count = 0;
606 count = esp_netif_get_all_ip6(this->eth_netif_, if_ip6s);
607 assert(count <= CONFIG_LWIP_IPV6_NUM_ADDRESSES);
608 assert(count < addresses.size());
609 for (int i = 0; i < count; i++) {
610 addresses[i + 1] = network::IPAddress(&if_ip6s[i]);
611 }
612#endif /* USE_NETWORK_IPV6 */
613
614 return addresses;
615}
616
619 const ip_addr_t *dns_ip = dns_getserver(num);
620 return dns_ip;
621}
622
623void EthernetComponent::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event, void *event_data) {
624 const char *event_name;
625
626 switch (event) {
627 case ETHERNET_EVENT_START:
628 event_name = "ETH started";
631 break;
632 case ETHERNET_EVENT_STOP:
633 event_name = "ETH stopped";
636 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
637 break;
638 case ETHERNET_EVENT_CONNECTED:
639 event_name = "ETH connected";
640 // For static IP configurations, GOT_IP event may not fire, so notify IP listeners here
641#if defined(USE_ETHERNET_IP_STATE_LISTENERS) && defined(USE_ETHERNET_MANUAL_IP)
642 if (global_eth_component->manual_ip_.has_value()) {
644 }
645#endif
646 break;
647 case ETHERNET_EVENT_DISCONNECTED:
648 event_name = "ETH disconnected";
650 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
651 break;
652 default:
653 return;
654 }
655
656 ESP_LOGV(TAG, "[Ethernet event] %s (num=%" PRId32 ")", event_name, event);
657}
658
659void EthernetComponent::got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
660 void *event_data) {
661 ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
662 const esp_netif_ip_info_t *ip_info = &event->ip_info;
663 ESP_LOGV(TAG, "[Ethernet event] ETH Got IP " IPSTR, IP2STR(&ip_info->ip));
665#if USE_NETWORK_IPV6 && (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
666 global_eth_component->connected_ = global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT;
667 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
668#else
670 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
671#endif /* USE_NETWORK_IPV6 */
672#ifdef USE_ETHERNET_IP_STATE_LISTENERS
674#endif
675}
676
677#if USE_NETWORK_IPV6
678void EthernetComponent::got_ip6_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
679 void *event_data) {
680 ip_event_got_ip6_t *event = (ip_event_got_ip6_t *) event_data;
681 ESP_LOGV(TAG, "[Ethernet event] ETH Got IPv6: " IPV6STR, IPV62STR(event->ip6_info.ip));
683#if (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
685 global_eth_component->got_ipv4_address_ && (global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT);
686 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
687#else
689 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
690#endif
691#ifdef USE_ETHERNET_IP_STATE_LISTENERS
693#endif
694}
695#endif /* USE_NETWORK_IPV6 */
696
698#if USE_NETWORK_IPV6
699 // Retry IPv6 link-local setup if it failed during initial connect
700 // This handles the case where min_ipv6_addr_count is NOT set (or is 0),
701 // allowing us to reach CONNECTED state with just IPv4.
702 // If IPv6 setup failed in start_connect_() because the interface wasn't ready:
703 // - Bootup timing issues (#10281)
704 // - Cable unplugged/network interruption (#10705)
705 // We can now retry since we're in CONNECTED state and the interface is definitely up.
706 if (!this->ipv6_setup_done_) {
707 esp_err_t err = esp_netif_create_ip6_linklocal(this->eth_netif_);
708 if (err == ESP_OK) {
709 ESP_LOGD(TAG, "IPv6 link-local address created (retry succeeded)");
710 }
711 // Always set the flag to prevent continuous retries
712 // If IPv6 setup fails here with the interface up and stable, it's
713 // likely a persistent issue (IPv6 disabled at router, hardware
714 // limitation, etc.) that won't be resolved by further retries.
715 // The device continues to work with IPv4.
716 this->ipv6_setup_done_ = true;
717 }
718#endif /* USE_NETWORK_IPV6 */
719}
720
723#if USE_NETWORK_IPV6
725 this->ipv6_setup_done_ = false;
726#endif /* USE_NETWORK_IPV6 */
727 this->connect_begin_ = millis();
728 this->status_set_warning(LOG_STR("waiting for IP configuration"));
729
730 esp_err_t err;
731 err = esp_netif_set_hostname(this->eth_netif_, App.get_name().c_str());
732 if (err != ERR_OK) {
733 ESP_LOGW(TAG, "esp_netif_set_hostname failed: %s", esp_err_to_name(err));
734 }
735
736 esp_netif_ip_info_t info;
737#ifdef USE_ETHERNET_MANUAL_IP
738 if (this->manual_ip_.has_value()) {
739 info.ip = this->manual_ip_->static_ip;
740 info.gw = this->manual_ip_->gateway;
741 info.netmask = this->manual_ip_->subnet;
742 } else
743#endif
744 {
745 info.ip.addr = 0;
746 info.gw.addr = 0;
747 info.netmask.addr = 0;
748 }
749
750 esp_netif_dhcp_status_t status = ESP_NETIF_DHCP_INIT;
751
752 err = esp_netif_dhcpc_get_status(this->eth_netif_, &status);
753 ESPHL_ERROR_CHECK(err, "DHCPC Get Status Failed!");
754
755 ESP_LOGV(TAG, "DHCP Client Status: %d", status);
756
757 err = esp_netif_dhcpc_stop(this->eth_netif_);
758 if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) {
759 ESPHL_ERROR_CHECK(err, "DHCPC stop error");
760 }
761
762 err = esp_netif_set_ip_info(this->eth_netif_, &info);
763 ESPHL_ERROR_CHECK(err, "DHCPC set IP info error");
764
765#ifdef USE_ETHERNET_MANUAL_IP
766 if (this->manual_ip_.has_value()) {
768 if (this->manual_ip_->dns1.is_set()) {
769 ip_addr_t d;
770 d = this->manual_ip_->dns1;
771 dns_setserver(0, &d);
772 }
773 if (this->manual_ip_->dns2.is_set()) {
774 ip_addr_t d;
775 d = this->manual_ip_->dns2;
776 dns_setserver(1, &d);
777 }
778 } else
779#endif
780 {
781 err = esp_netif_dhcpc_start(this->eth_netif_);
782 if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
783 ESPHL_ERROR_CHECK(err, "DHCPC start error");
784 }
785 }
786#if USE_NETWORK_IPV6
787 // Attempt to create IPv6 link-local address
788 // We MUST attempt this here, not just in finish_connect_(), because with
789 // min_ipv6_addr_count set, the component won't reach CONNECTED state without IPv6.
790 // However, this may fail with ESP_FAIL if the interface is not up yet:
791 // - At bootup when link isn't ready (#10281)
792 // - After disconnection/cable unplugged (#10705)
793 // We'll retry in finish_connect_() if it fails here.
794 err = esp_netif_create_ip6_linklocal(this->eth_netif_);
795 if (err != ESP_OK) {
796 if (err == ESP_ERR_ESP_NETIF_INVALID_PARAMS) {
797 // This is a programming error, not a transient failure
798 ESPHL_ERROR_CHECK(err, "esp_netif_create_ip6_linklocal invalid parameters");
799 } else {
800 // ESP_FAIL means the interface isn't up yet
801 // This is expected and non-fatal, happens in multiple scenarios:
802 // - During reconnection after network interruptions (#10705)
803 // - At bootup when the link isn't ready yet (#10281)
804 // We'll retry once we reach CONNECTED state and the interface is up
805 ESP_LOGW(TAG, "esp_netif_create_ip6_linklocal failed: %s", esp_err_to_name(err));
806 // Don't mark component as failed - this is a transient error
807 }
808 }
809#endif /* USE_NETWORK_IPV6 */
810
811 this->connect_begin_ = millis();
812 this->status_set_warning();
813}
814
816 if (!this->ethernet_initialized_) {
817 ESP_LOGCONFIG(TAG, " uninitialized/disabled");
818 return;
819 }
820 esp_netif_ip_info_t ip;
821 esp_netif_get_ip_info(this->eth_netif_, &ip);
822 const ip_addr_t *dns_ip1;
823 const ip_addr_t *dns_ip2;
824 {
826 dns_ip1 = dns_getserver(0);
827 dns_ip2 = dns_getserver(1);
828 }
829
830 // Use stack buffers for IP address formatting to avoid heap allocations
831 char ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
832 char subnet_buf[network::IP_ADDRESS_BUFFER_SIZE];
833 char gateway_buf[network::IP_ADDRESS_BUFFER_SIZE];
834 char dns1_buf[network::IP_ADDRESS_BUFFER_SIZE];
835 char dns2_buf[network::IP_ADDRESS_BUFFER_SIZE];
836 char mac_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
837 uint16_t link_speed = 10;
838 switch (this->get_link_speed()) {
839 case ETH_SPEED_100M:
840 link_speed = 100;
841 break;
842#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 1, 0)
843 case ETH_SPEED_1000M:
844 link_speed = 1000;
845 break;
846#endif
847 default:
848 break;
849 }
850 ESP_LOGCONFIG(TAG,
851 " IP Address: %s\n"
852 " Hostname: '%s'\n"
853 " Subnet: %s\n"
854 " Gateway: %s\n"
855 " DNS1: %s\n"
856 " DNS2: %s\n"
857 " MAC Address: %s\n"
858 " Is Full Duplex: %s\n"
859 " Link Speed: %u",
860 network::IPAddress(&ip.ip).str_to(ip_buf), App.get_name().c_str(),
861 network::IPAddress(&ip.netmask).str_to(subnet_buf), network::IPAddress(&ip.gw).str_to(gateway_buf),
862 network::IPAddress(dns_ip1).str_to(dns1_buf), network::IPAddress(dns_ip2).str_to(dns2_buf),
863 this->get_eth_mac_address_pretty_into_buffer(mac_buf),
864 YESNO(this->get_duplex_mode() == ETH_DUPLEX_FULL), link_speed);
865
866#if USE_NETWORK_IPV6
867 struct esp_ip6_addr if_ip6s[CONFIG_LWIP_IPV6_NUM_ADDRESSES];
868 uint8_t count = 0;
869 count = esp_netif_get_all_ip6(this->eth_netif_, if_ip6s);
870 assert(count <= CONFIG_LWIP_IPV6_NUM_ADDRESSES);
871 for (int i = 0; i < count; i++) {
872 ESP_LOGCONFIG(TAG, " IPv6: " IPV6STR, IPV62STR(if_ip6s[i]));
873 }
874#endif /* USE_NETWORK_IPV6 */
875}
876
877#ifdef USE_ETHERNET_SPI
878void EthernetComponent::set_clk_pin(uint8_t clk_pin) { this->clk_pin_ = clk_pin; }
879void EthernetComponent::set_miso_pin(uint8_t miso_pin) { this->miso_pin_ = miso_pin; }
880void EthernetComponent::set_mosi_pin(uint8_t mosi_pin) { this->mosi_pin_ = mosi_pin; }
881void EthernetComponent::set_cs_pin(uint8_t cs_pin) { this->cs_pin_ = cs_pin; }
882void EthernetComponent::set_interrupt_pin(uint8_t interrupt_pin) { this->interrupt_pin_ = interrupt_pin; }
883void EthernetComponent::set_reset_pin(uint8_t reset_pin) { this->reset_pin_ = reset_pin; }
884void EthernetComponent::set_clock_speed(int clock_speed) { this->clock_speed_ = clock_speed; }
885void EthernetComponent::set_interface(spi_host_device_t interface) { this->interface_ = interface; }
886#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
887void EthernetComponent::set_polling_interval(uint32_t polling_interval) { this->polling_interval_ = polling_interval; }
888#endif
889#else
890void EthernetComponent::set_phy_addr(uint8_t phy_addr) { this->phy_addr_ = phy_addr; }
891void EthernetComponent::set_power_pin(int power_pin) { this->power_pin_ = power_pin; }
892void EthernetComponent::set_mdc_pin(uint8_t mdc_pin) { this->mdc_pin_ = mdc_pin; }
893void EthernetComponent::set_mdio_pin(uint8_t mdio_pin) { this->mdio_pin_ = mdio_pin; }
894void EthernetComponent::set_clk_pin(uint8_t clk_pin) { this->clk_pin_ = clk_pin; }
895void EthernetComponent::set_clk_mode(emac_rmii_clock_mode_t clk_mode) { this->clk_mode_ = clk_mode; }
896void EthernetComponent::add_phy_register(PHYRegister register_value) { this->phy_registers_.push_back(register_value); }
897#endif
898
900 if (!this->ethernet_initialized_) {
901 // External callers (mdns, ethernet_info, etc.) may ask for the MAC before/regardless
902 // of whether ethernet is enabled. Use the configured MAC if set, else the system ETH MAC.
903 if (this->fixed_mac_.has_value()) {
904 memcpy(mac, this->fixed_mac_->data(), 6);
905 } else {
906 esp_read_mac(mac, ESP_MAC_ETH);
907 }
908 return;
909 }
910 esp_err_t err;
911 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_MAC_ADDR, mac);
912 ESPHL_ERROR_CHECK(err, "ETH_CMD_G_MAC error");
913}
914
915std::string EthernetComponent::get_eth_mac_address_pretty() {
916 char buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
917 return std::string(this->get_eth_mac_address_pretty_into_buffer(buf));
918}
919
921 std::span<char, MAC_ADDRESS_PRETTY_BUFFER_SIZE> buf) {
922 uint8_t mac[6];
924 format_mac_addr_upper(mac, buf.data());
925 return buf.data();
926}
927
929 if (!this->ethernet_initialized_)
930 return ETH_DUPLEX_HALF;
931 esp_err_t err;
932 eth_duplex_t duplex_mode;
933 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_DUPLEX_MODE, &duplex_mode);
934 ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_DUPLEX_MODE error", ETH_DUPLEX_HALF);
935 return duplex_mode;
936}
937
939 if (!this->ethernet_initialized_)
940 return ETH_SPEED_10M;
941 esp_err_t err;
943 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_SPEED, &speed);
944 ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_SPEED error", ETH_SPEED_10M);
945 return speed;
946}
947
949 ESP_LOGI(TAG, "Powering down ethernet PHY");
950 if (this->phy_ == nullptr) {
951 ESP_LOGE(TAG, "Ethernet PHY not assigned");
952 return false;
953 }
954 this->connected_ = false;
955 this->started_ = false;
956 // No need to enable_loop() here as this is only called during shutdown/reboot
957 if (this->phy_->pwrctl(this->phy_, false) != ESP_OK) {
958 ESP_LOGE(TAG, "Error powering down ethernet PHY");
959 return false;
960 }
961 return true;
962}
963
964#ifndef USE_ETHERNET_SPI
965
966#ifdef USE_ETHERNET_KSZ8081
967constexpr uint8_t KSZ80XX_PC2R_REG_ADDR = 0x1F;
968
970 esp_err_t err;
971
972 uint32_t phy_control_2;
973 err = mac->read_phy_reg(mac, this->phy_addr_, KSZ80XX_PC2R_REG_ADDR, &(phy_control_2));
974 ESPHL_ERROR_CHECK(err, "Read PHY Control 2 failed");
975#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
976 char hex_buf[format_hex_pretty_size(PHY_REG_SIZE)];
977#endif
978 ESP_LOGVV(TAG, "KSZ8081 PHY Control 2: %s", format_hex_pretty_to(hex_buf, (uint8_t *) &phy_control_2, PHY_REG_SIZE));
979
980 /*
981 * Bit 7 is `RMII Reference Clock Select`. Default is `0`.
982 * KSZ8081RNA:
983 * 0 - clock input to XI (Pin 8) is 25 MHz for RMII - 25 MHz clock mode.
984 * 1 - clock input to XI (Pin 8) is 50 MHz for RMII - 50 MHz clock mode.
985 * KSZ8081RND:
986 * 0 - clock input to XI (Pin 8) is 50 MHz for RMII - 50 MHz clock mode.
987 * 1 - clock input to XI (Pin 8) is 25 MHz (driven clock only, not a crystal) for RMII - 25 MHz clock mode.
988 */
989 if ((phy_control_2 & (1 << 7)) != (1 << 7)) {
990 phy_control_2 |= 1 << 7;
991 err = mac->write_phy_reg(mac, this->phy_addr_, KSZ80XX_PC2R_REG_ADDR, phy_control_2);
992 ESPHL_ERROR_CHECK(err, "Write PHY Control 2 failed");
993 err = mac->read_phy_reg(mac, this->phy_addr_, KSZ80XX_PC2R_REG_ADDR, &(phy_control_2));
994 ESPHL_ERROR_CHECK(err, "Read PHY Control 2 failed");
995 ESP_LOGVV(TAG, "KSZ8081 PHY Control 2: %s",
996 format_hex_pretty_to(hex_buf, (uint8_t *) &phy_control_2, PHY_REG_SIZE));
997 }
998}
999#endif // USE_ETHERNET_KSZ8081
1000
1001void EthernetComponent::write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data) {
1002 esp_err_t err;
1003
1004#ifdef USE_ETHERNET_RTL8201
1005 constexpr uint8_t eth_phy_psr_reg_addr = 0x1F;
1006 if (this->type_ == ETHERNET_TYPE_RTL8201 && register_data.page) {
1007 ESP_LOGD(TAG, "Select PHY Register Page: 0x%02" PRIX32, register_data.page);
1008 err = mac->write_phy_reg(mac, this->phy_addr_, eth_phy_psr_reg_addr, register_data.page);
1009 ESPHL_ERROR_CHECK(err, "Select PHY Register page failed");
1010 }
1011#endif
1012
1013 ESP_LOGD(TAG, "Writing PHY reg 0x%02" PRIX32 " = 0x%04" PRIX32, register_data.address, register_data.value);
1014 err = mac->write_phy_reg(mac, this->phy_addr_, register_data.address, register_data.value);
1015 ESPHL_ERROR_CHECK(err, "Writing PHY Register failed");
1016
1017#ifdef USE_ETHERNET_RTL8201
1018 if (this->type_ == ETHERNET_TYPE_RTL8201 && register_data.page) {
1019 ESP_LOGD(TAG, "Select PHY Register Page 0x00");
1020 err = mac->write_phy_reg(mac, this->phy_addr_, eth_phy_psr_reg_addr, 0x0);
1021 ESPHL_ERROR_CHECK(err, "Select PHY Register Page 0 failed");
1022 }
1023#endif
1024}
1025
1026#ifdef USE_ETHERNET_YT8531
1028 esp_err_t err;
1029
1030 // The YT8531 disables auto-negotiation on hardware reset (undocumented behavior), and the
1031 // generic 802.3 driver only resets the PHY, so re-enable it (this also updates the driver's
1032 // cached auto-nego state used by esp_eth_start()).
1033 bool autoneg_enable = true;
1034 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_AUTONEGO, &autoneg_enable);
1035 ESPHL_ERROR_CHECK(err, "YT8531 enable auto-negotiation failed");
1036
1037 // RGMII needs ~2 ns Tx and Rx clock delays for reliable data sampling. These are set through
1038 // the YT8531 extended-register interface: write the ext-register address to 0x1E, then
1039 // read/modify/write its value via 0x1F.
1040 esp_eth_phy_reg_rw_data_t phy_reg;
1041 uint32_t reg_val;
1042 phy_reg.reg_value_p = &reg_val;
1043
1044 // RX ~2 ns coarse delay: EXT_CHIP_CONFIG (0xA001), set rxc_dly_en (bit 8).
1045 reg_val = 0xA001;
1046 phy_reg.reg_addr = 0x1E;
1047 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1048 ESPHL_ERROR_CHECK(err, "YT8531 select Chip_Config failed");
1049 phy_reg.reg_addr = 0x1F;
1050 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_READ_PHY_REG, &phy_reg);
1051 ESPHL_ERROR_CHECK(err, "YT8531 read Chip_Config failed");
1052 reg_val |= (1U << 8);
1053 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1054 ESPHL_ERROR_CHECK(err, "YT8531 write Chip_Config failed");
1055
1056 // TX ~2 ns delay: EXT_RGMII_CONFIG1 (0xA003), tx_delay_sel[3:0] and tx_delay_sel_fe[7:4] = 13.
1057 reg_val = 0xA003;
1058 phy_reg.reg_addr = 0x1E;
1059 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1060 ESPHL_ERROR_CHECK(err, "YT8531 select RGMII_Config1 failed");
1061 phy_reg.reg_addr = 0x1F;
1062 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_READ_PHY_REG, &phy_reg);
1063 ESPHL_ERROR_CHECK(err, "YT8531 read RGMII_Config1 failed");
1064 reg_val = (reg_val & ~0x00FFU) | (13U << 4) | (13U << 0);
1065 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1066 ESPHL_ERROR_CHECK(err, "YT8531 write RGMII_Config1 failed");
1067}
1068#endif
1069
1070#endif
1071
1072} // namespace esphome::ethernet
1073
1074#endif // USE_ETHERNET && USE_ESP32
uint8_t status
Definition bl0942.h:8
const StringRef & get_name() const
Get the name of this Application set by pre_setup().
uint32_t IRAM_ATTR HOT get_loop_component_start_time() const
Get the cached time in milliseconds from when the current component started its loop execution.
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:274
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
void enable_loop()
Enable this component's loop.
Definition component.h:248
void disable_loop()
Disable this component's loop.
void status_clear_warning()
Definition component.h:291
Helper class to lock the lwIP TCPIP core when making lwIP API calls from non-TCPIP threads.
Definition helpers.h:1985
constexpr const char * c_str() const
Definition string_ref.h:73
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
Definition automation.h:461
void set_interface(spi_host_device_t interface)
std::vector< PHYRegister > phy_registers_
static void got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
void set_polling_interval(uint32_t polling_interval)
void yt8531_phy_init_()
Apply YT8531-specific config: re-enable auto-negotiation (disabled on reset) and set the RGMII Tx/Rx ...
void write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data)
Set arbitratry PHY registers from config.
static void got_ip6_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
void log_error_and_mark_failed_(esp_err_t err, const char *message)
network::IPAddress get_dns_address(uint8_t num)
void add_phy_register(PHYRegister register_value)
void ksz8081_set_clock_reference_(esp_eth_mac_t *mac)
Set RMII Reference Clock Select bit for KSZ8081.
static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
optional< std::array< uint8_t, 6 > > fixed_mac_
void set_clk_mode(emac_rmii_clock_mode_t clk_mode)
ESPDEPRECATED("Use get_eth_mac_address_pretty_into_buffer() instead. Removed in 2026.9.0", "2026.3.0") std const char * get_eth_mac_address_pretty_into_buffer(std::span< char, MAC_ADDRESS_PRETTY_BUFFER_SIZE > buf)
const LogString * message
Definition component.cpp:35
eth_esp32_emac_config_t eth_esp32_emac_default_config(void)
int speed
Definition fan.h:3
in_addr ip_addr_t
Definition ip_address.h:22
constexpr uint8_t KSZ80XX_PC2R_REG_ADDR
void install_w5500_async_spi(eth_w5500_config_t &config)
esp_eth_phy_t * esp_eth_phy_new_jl1101(const eth_phy_config_t *config)
EthernetComponent * global_eth_component
std::array< IPAddress, 5 > IPAddresses
Definition ip_address.h:223
char * format_hex_pretty_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length, char separator)
Format byte array as uppercase hex to buffer (base implementation).
Definition helpers.cpp:340
constexpr size_t format_hex_pretty_size(size_t byte_count)
Calculate buffer size needed for format_hex_pretty_to with separator: "XX:XX:...:XX\0".
Definition helpers.h:1400
void HOT delay(uint32_t ms)
Definition hal.cpp:85
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:28
Application App
Global storage of Application pointer - only one Application can exist.
char * format_mac_addr_upper(const uint8_t *mac, char *output)
Format MAC address as XX:XX:XX:XX:XX:XX (uppercase, colon separators)
Definition helpers.h:1467
static void uint32_t
uint8_t event_id
Definition tt21100.cpp:3
SemaphoreHandle_t lock