ESPHome 2026.7.4
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 does not support poll_period_ms. CS must stay asserted for the chip's CS hold
236 // time (t10, 210 ns) after the last clock or MAC/MII register reads fail ("wrong chip ID")
237 enc28j60_config.spi_devcfg->cs_ena_posttrans = enc28j60_cal_spi_cs_hold_time((this->clock_speed_ + 999999) / 1000000);
238 enc28j60_config.int_gpio_num = this->interrupt_pin_;
239#endif
240
241 phy_config.phy_addr = this->phy_addr_spi_;
242 phy_config.reset_gpio_num = this->reset_pin_;
243
244 esp_eth_mac_t *mac = nullptr;
245#elif defined(USE_ETHERNET_OPENETH)
246 esp_eth_mac_t *mac = esp_eth_mac_new_openeth(&mac_config);
247#else
248 phy_config.phy_addr = this->phy_addr_;
249 phy_config.reset_gpio_num = this->power_pin_;
250
251 eth_esp32_emac_config_t esp32_emac_config = eth_esp32_emac_default_config();
252#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0)
253 esp32_emac_config.smi_gpio.mdc_num = this->mdc_pin_;
254 esp32_emac_config.smi_gpio.mdio_num = this->mdio_pin_;
255#else
256 esp32_emac_config.smi_mdc_gpio_num = this->mdc_pin_;
257 esp32_emac_config.smi_mdio_gpio_num = this->mdio_pin_;
258#endif
259 // The RGMII types (GENERIC, YT8531) use the RGMII interface and default GPIO map from
260 // eth_esp32_emac_default_config(); writing the RMII clock config would clobber that
261 // union, so skip the RMII clock override for them.
262 if (this->type_ != ETHERNET_TYPE_GENERIC && this->type_ != ETHERNET_TYPE_YT8531) {
263 esp32_emac_config.clock_config.rmii.clock_mode = this->clk_mode_;
264 esp32_emac_config.clock_config.rmii.clock_gpio =
265 static_cast<decltype(esp32_emac_config.clock_config.rmii.clock_gpio)>(this->clk_pin_);
266 }
267
268 esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config);
269#endif
270
271 switch (this->type_) {
272#ifdef USE_ETHERNET_OPENETH
274 phy_config.autonego_timeout_ms = 1000;
275#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
276 this->phy_ = esp_eth_phy_new_generic(&phy_config);
277#else
278 this->phy_ = esp_eth_phy_new_dp83848(&phy_config);
279#endif
280 break;
281 }
282#endif
283#if CONFIG_ETH_USE_ESP32_EMAC
284#ifdef USE_ETHERNET_LAN8720
286 this->phy_ = esp_eth_phy_new_lan87xx(&phy_config);
287 break;
288 }
289#endif
290#ifdef USE_ETHERNET_RTL8201
292 this->phy_ = esp_eth_phy_new_rtl8201(&phy_config);
293 break;
294 }
295#endif
296#ifdef USE_ETHERNET_DP83848
298 this->phy_ = esp_eth_phy_new_dp83848(&phy_config);
299 break;
300 }
301#endif
302#ifdef USE_ETHERNET_IP101
303 case ETHERNET_TYPE_IP101: {
304 this->phy_ = esp_eth_phy_new_ip101(&phy_config);
305 break;
306 }
307#endif
308#ifdef USE_ETHERNET_JL1101
310 // PlatformIO (pioarduino): builtin esp_eth_phy_new_jl1101() on all IDF versions
311 // Non-PlatformIO: custom ESPHome driver (esp_eth_phy_jl1101.c)
312 this->phy_ = esp_eth_phy_new_jl1101(&phy_config);
313 break;
314 }
315#endif
316#ifdef USE_ETHERNET_KSZ8081
319 this->phy_ = esp_eth_phy_new_ksz80xx(&phy_config);
320 break;
321 }
322#endif
323#ifdef USE_ETHERNET_LAN8670
325 this->phy_ = esp_eth_phy_new_lan867x(&phy_config);
326 break;
327 }
328#endif
329#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
330 // GENERIC and YT8531 both use the built-in generic 802.3 PHY driver; YT8531 gets
331 // extra chip-specific tuning applied later in ethernet_lazy_init_().
332#ifdef USE_ETHERNET_GENERIC
334#endif
335#ifdef USE_ETHERNET_YT8531
337#endif
338#if defined(USE_ETHERNET_GENERIC) || defined(USE_ETHERNET_YT8531)
339 this->phy_ = esp_eth_phy_new_generic(&phy_config);
340 break;
341#endif
342#endif
343#endif
344#ifdef USE_ETHERNET_SPI
345#if defined(USE_ETHERNET_W5500)
346 case ETHERNET_TYPE_W5500: {
347 mac = esp_eth_mac_new_w5500(&w5500_config, &mac_config);
348 this->phy_ = esp_eth_phy_new_w5500(&phy_config);
349 break;
350 }
351#elif defined(USE_ETHERNET_DM9051)
353 mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config);
354 this->phy_ = esp_eth_phy_new_dm9051(&phy_config);
355 break;
356 }
357#elif defined(USE_ETHERNET_ENC28J60)
359 mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config);
360 this->phy_ = esp_eth_phy_new_enc28j60(&phy_config);
361 break;
362 }
363#endif
364#endif
365 default: {
366 this->mark_failed();
367 return;
368 }
369 }
370
371 esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, this->phy_);
372 this->eth_handle_ = nullptr;
373 err = esp_eth_driver_install(&eth_config, &this->eth_handle_);
374 ESPHL_ERROR_CHECK(err, "ETH driver install error");
375
376#ifndef USE_ETHERNET_SPI
377#ifdef USE_ETHERNET_KSZ8081
378 if (this->type_ == ETHERNET_TYPE_KSZ8081RNA && this->clk_mode_ == EMAC_CLK_OUT) {
379 // KSZ8081RNA default is incorrect. It expects a 25MHz clock instead of the 50MHz we provide.
381 }
382#endif // USE_ETHERNET_KSZ8081
383
384 for (const auto &phy_register : this->phy_registers_) {
385 this->write_phy_register_(mac, phy_register);
386 }
387
388#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0)
389#ifdef USE_ETHERNET_GENERIC
390 // The generic 802.3 PHY driver only resets the PHY in its init; it never enables
391 // auto-negotiation. A PHY that resets into a forced-speed mode (BMCR auto-nego bit
392 // clear) therefore stays there, and esp_eth_start() skips negotiation because the
393 // driver cached auto_nego_en=false at install time. Force auto-negotiation on here
394 // (which also updates that cached state) so esp_eth_start() restarts a proper
395 // negotiation. (YT8531 does this as part of its own chip-specific init below.)
396 if (this->type_ == ETHERNET_TYPE_GENERIC) {
397 bool autoneg_enable = true;
398 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_AUTONEGO, &autoneg_enable);
399 ESPHL_ERROR_CHECK(err, "Enable auto-negotiation failed");
400 }
401#endif
402#ifdef USE_ETHERNET_YT8531
403 if (this->type_ == ETHERNET_TYPE_YT8531) {
404 this->yt8531_phy_init_();
405 if (this->is_failed())
406 return;
407 }
408#endif
409#endif // ESP_IDF_VERSION >= 6.0.0
410#endif // !USE_ETHERNET_SPI
411
412 // use ESP internal eth mac
413 uint8_t mac_addr[6];
414 if (this->fixed_mac_.has_value()) {
415 memcpy(mac_addr, this->fixed_mac_->data(), 6);
416 } else {
417 esp_read_mac(mac_addr, ESP_MAC_ETH);
418 }
419 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_MAC_ADDR, mac_addr);
420 ESPHL_ERROR_CHECK(err, "set mac address error");
421
422 /* attach Ethernet driver to TCP/IP stack */
423 err = esp_netif_attach(this->eth_netif_, esp_eth_new_netif_glue(this->eth_handle_));
424 ESPHL_ERROR_CHECK(err, "ETH netif attach error");
425
426 // Register user defined event handers
427 err = esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &EthernetComponent::eth_event_handler, nullptr);
428 ESPHL_ERROR_CHECK(err, "ETH event handler register error");
429 err = esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &EthernetComponent::got_ip_event_handler, nullptr);
430 ESPHL_ERROR_CHECK(err, "GOT IP event handler register error");
431#if USE_NETWORK_IPV6
432 err = esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &EthernetComponent::got_ip6_event_handler, nullptr);
433 ESPHL_ERROR_CHECK(err, "GOT IPv6 event handler register error");
434#endif /* USE_NETWORK_IPV6 */
435
436 this->ethernet_initialized_ = true;
437}
438
440 if (!this->disabled_)
441 return;
442
443 ESP_LOGD(TAG, "Enabling");
444 this->ethernet_lazy_init_();
445 if (!this->ethernet_initialized_) {
446 ESP_LOGE(TAG, "Cannot enable - init failed");
447 return;
448 }
449 esp_err_t err = esp_eth_start(this->eth_handle_);
450 if (err != ESP_OK) {
451 ESP_LOGE(TAG, "esp_eth_start failed: %s", esp_err_to_name(err));
452 return;
453 }
454 this->disabled_ = false;
455 // The ETH_EVENT_START handler will set started_=true; the loop state machine
456 // will then drive the STOPPED -> CONNECTING -> CONNECTED transitions.
457 this->enable_loop();
458}
459
461 if (this->disabled_)
462 return;
463
464 ESP_LOGD(TAG, "Disabling");
465 esp_err_t err = esp_eth_stop(this->eth_handle_);
466 if (err != ESP_OK) {
467 ESP_LOGW(TAG, "esp_eth_stop failed: %s — disabling anyway", esp_err_to_name(err));
468 }
469 this->disabled_ = true;
470 // ETH_EVENT_STOP will clear started_; loop() will transition to STOPPED.
471}
472
474 const char *eth_type;
475 switch (this->type_) {
476#ifdef USE_ETHERNET_LAN8720
478 eth_type = "LAN8720";
479 break;
480#endif
481#ifdef USE_ETHERNET_RTL8201
483 eth_type = "RTL8201";
484 break;
485#endif
486#ifdef USE_ETHERNET_DP83848
488 eth_type = "DP83848";
489 break;
490#endif
491#ifdef USE_ETHERNET_IP101
493 eth_type = "IP101";
494 break;
495#endif
496#ifdef USE_ETHERNET_JL1101
498 eth_type = "JL1101";
499 break;
500#endif
501#ifdef USE_ETHERNET_KSZ8081
503 eth_type = "KSZ8081";
504 break;
505
507 eth_type = "KSZ8081RNA";
508 break;
509#endif
510#if defined(USE_ETHERNET_W5500)
512 eth_type = "W5500";
513 break;
514#elif defined(USE_ETHERNET_DM9051)
516 eth_type = "DM9051";
517 break;
518#elif defined(USE_ETHERNET_ENC28J60)
520 eth_type = "ENC28J60";
521 break;
522#endif
523#ifdef USE_ETHERNET_OPENETH
525 eth_type = "OPENETH";
526 break;
527#endif
528#ifdef USE_ETHERNET_LAN8670
530 eth_type = "LAN8670";
531 break;
532#endif
533#ifdef USE_ETHERNET_GENERIC
535 eth_type = "Generic (RGMII)";
536 break;
537#endif
538#ifdef USE_ETHERNET_YT8531
540 eth_type = "YT8531 (RGMII)";
541 break;
542#endif
543
544 default:
545 eth_type = "Unknown";
546 break;
547 }
548
549 ESP_LOGCONFIG(TAG,
550 "Ethernet:\n"
551 " Connected: %s",
552 YESNO(this->is_connected()));
553 this->dump_connect_params_();
554#ifdef USE_ETHERNET_SPI
555 ESP_LOGCONFIG(TAG,
556 " CLK Pin: %u\n"
557 " MISO Pin: %u\n"
558 " MOSI Pin: %u\n"
559 " CS Pin: %u",
560 this->clk_pin_, this->miso_pin_, this->mosi_pin_, this->cs_pin_);
561 const char *spi_interface = "spi3";
562 if (this->interface_ == SPI2_HOST) {
563 spi_interface = "spi2";
564 }
565 ESP_LOGCONFIG(TAG, " Interface: %s", spi_interface);
566#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
567 if (this->polling_interval_ != 0) {
568 ESP_LOGCONFIG(TAG, " Polling Interval: %" PRIu32 " ms", this->polling_interval_);
569 } else
570#endif
571 {
572 ESP_LOGCONFIG(TAG, " IRQ Pin: %d", this->interrupt_pin_);
573 }
574 ESP_LOGCONFIG(TAG,
575 " Reset Pin: %d\n"
576 " Clock Speed: %d MHz",
577 this->reset_pin_, this->clock_speed_ / 1000000);
578#else
579 if (this->power_pin_ != -1) {
580 ESP_LOGCONFIG(TAG, " Power Pin: %u", this->power_pin_);
581 }
582 ESP_LOGCONFIG(TAG,
583 " CLK Pin: %u\n"
584 " MDC Pin: %u\n"
585 " MDIO Pin: %u\n"
586 " PHY addr: %u",
587 this->clk_pin_, this->mdc_pin_, this->mdio_pin_, this->phy_addr_);
588#endif
589 ESP_LOGCONFIG(TAG, " Type: %s", eth_type);
590}
591
593 network::IPAddresses addresses;
594 if (!this->ethernet_initialized_)
595 return addresses; // all-zero IPs
596 esp_netif_ip_info_t ip;
597 esp_err_t err = esp_netif_get_ip_info(this->eth_netif_, &ip);
598 if (err != ESP_OK) {
599 ESP_LOGV(TAG, "esp_netif_get_ip_info failed: %s", esp_err_to_name(err));
600 // TODO: do something smarter
601 // return false;
602 } else {
603 addresses[0] = network::IPAddress(&ip.ip);
604 }
605#if USE_NETWORK_IPV6
606 struct esp_ip6_addr if_ip6s[CONFIG_LWIP_IPV6_NUM_ADDRESSES];
607 uint8_t count = 0;
608 count = esp_netif_get_all_ip6(this->eth_netif_, if_ip6s);
609 assert(count <= CONFIG_LWIP_IPV6_NUM_ADDRESSES);
610 assert(count < addresses.size());
611 for (int i = 0; i < count; i++) {
612 addresses[i + 1] = network::IPAddress(&if_ip6s[i]);
613 }
614#endif /* USE_NETWORK_IPV6 */
615
616 return addresses;
617}
618
621 const ip_addr_t *dns_ip = dns_getserver(num);
622 return dns_ip;
623}
624
625void EthernetComponent::eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event, void *event_data) {
626 const char *event_name;
627
628 switch (event) {
629 case ETHERNET_EVENT_START:
630 event_name = "ETH started";
633 break;
634 case ETHERNET_EVENT_STOP:
635 event_name = "ETH stopped";
638 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
639 break;
640 case ETHERNET_EVENT_CONNECTED:
641 event_name = "ETH connected";
642 // For static IP configurations, GOT_IP event may not fire, so notify IP listeners here
643#if defined(USE_ETHERNET_IP_STATE_LISTENERS) && defined(USE_ETHERNET_MANUAL_IP)
644 if (global_eth_component->manual_ip_.has_value()) {
646 }
647#endif
648 break;
649 case ETHERNET_EVENT_DISCONNECTED:
650 event_name = "ETH disconnected";
652 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
653 break;
654 default:
655 return;
656 }
657
658 ESP_LOGV(TAG, "[Ethernet event] %s (num=%" PRId32 ")", event_name, event);
659}
660
661void EthernetComponent::got_ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
662 void *event_data) {
663 ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
664 const esp_netif_ip_info_t *ip_info = &event->ip_info;
665 ESP_LOGV(TAG, "[Ethernet event] ETH Got IP " IPSTR, IP2STR(&ip_info->ip));
667#if USE_NETWORK_IPV6 && (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
668 global_eth_component->connected_ = global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT;
669 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
670#else
672 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
673#endif /* USE_NETWORK_IPV6 */
674#ifdef USE_ETHERNET_IP_STATE_LISTENERS
676#endif
677}
678
679#if USE_NETWORK_IPV6
680void EthernetComponent::got_ip6_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id,
681 void *event_data) {
682 ip_event_got_ip6_t *event = (ip_event_got_ip6_t *) event_data;
683 ESP_LOGV(TAG, "[Ethernet event] ETH Got IPv6: " IPV6STR, IPV62STR(event->ip6_info.ip));
685#if (USE_NETWORK_MIN_IPV6_ADDR_COUNT > 0)
687 global_eth_component->got_ipv4_address_ && (global_eth_component->ipv6_count_ >= USE_NETWORK_MIN_IPV6_ADDR_COUNT);
688 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
689#else
691 global_eth_component->enable_loop_soon_any_context(); // Enable loop when connection state changes
692#endif
693#ifdef USE_ETHERNET_IP_STATE_LISTENERS
695#endif
696}
697#endif /* USE_NETWORK_IPV6 */
698
700#if USE_NETWORK_IPV6
701 // Retry IPv6 link-local setup if it failed during initial connect
702 // This handles the case where min_ipv6_addr_count is NOT set (or is 0),
703 // allowing us to reach CONNECTED state with just IPv4.
704 // If IPv6 setup failed in start_connect_() because the interface wasn't ready:
705 // - Bootup timing issues (#10281)
706 // - Cable unplugged/network interruption (#10705)
707 // We can now retry since we're in CONNECTED state and the interface is definitely up.
708 if (!this->ipv6_setup_done_) {
709 esp_err_t err = esp_netif_create_ip6_linklocal(this->eth_netif_);
710 if (err == ESP_OK) {
711 ESP_LOGD(TAG, "IPv6 link-local address created (retry succeeded)");
712 }
713 // Always set the flag to prevent continuous retries
714 // If IPv6 setup fails here with the interface up and stable, it's
715 // likely a persistent issue (IPv6 disabled at router, hardware
716 // limitation, etc.) that won't be resolved by further retries.
717 // The device continues to work with IPv4.
718 this->ipv6_setup_done_ = true;
719 }
720#endif /* USE_NETWORK_IPV6 */
721}
722
725#if USE_NETWORK_IPV6
727 this->ipv6_setup_done_ = false;
728#endif /* USE_NETWORK_IPV6 */
729 this->connect_begin_ = millis();
730 this->status_set_warning(LOG_STR("waiting for IP configuration"));
731
732 esp_err_t err;
733 err = esp_netif_set_hostname(this->eth_netif_, App.get_name().c_str());
734 if (err != ERR_OK) {
735 ESP_LOGW(TAG, "esp_netif_set_hostname failed: %s", esp_err_to_name(err));
736 }
737
738 esp_netif_ip_info_t info;
739#ifdef USE_ETHERNET_MANUAL_IP
740 if (this->manual_ip_.has_value()) {
741 info.ip = this->manual_ip_->static_ip;
742 info.gw = this->manual_ip_->gateway;
743 info.netmask = this->manual_ip_->subnet;
744 } else
745#endif
746 {
747 info.ip.addr = 0;
748 info.gw.addr = 0;
749 info.netmask.addr = 0;
750 }
751
752 esp_netif_dhcp_status_t status = ESP_NETIF_DHCP_INIT;
753
754 err = esp_netif_dhcpc_get_status(this->eth_netif_, &status);
755 ESPHL_ERROR_CHECK(err, "DHCPC Get Status Failed!");
756
757 ESP_LOGV(TAG, "DHCP Client Status: %d", status);
758
759 err = esp_netif_dhcpc_stop(this->eth_netif_);
760 if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) {
761 ESPHL_ERROR_CHECK(err, "DHCPC stop error");
762 }
763
764 err = esp_netif_set_ip_info(this->eth_netif_, &info);
765 ESPHL_ERROR_CHECK(err, "DHCPC set IP info error");
766
767#ifdef USE_ETHERNET_MANUAL_IP
768 if (this->manual_ip_.has_value()) {
770 if (this->manual_ip_->dns1.is_set()) {
771 ip_addr_t d;
772 d = this->manual_ip_->dns1;
773 dns_setserver(0, &d);
774 }
775 if (this->manual_ip_->dns2.is_set()) {
776 ip_addr_t d;
777 d = this->manual_ip_->dns2;
778 dns_setserver(1, &d);
779 }
780 } else
781#endif
782 {
783 err = esp_netif_dhcpc_start(this->eth_netif_);
784 if (err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
785 ESPHL_ERROR_CHECK(err, "DHCPC start error");
786 }
787 }
788#if USE_NETWORK_IPV6
789 // Attempt to create IPv6 link-local address
790 // We MUST attempt this here, not just in finish_connect_(), because with
791 // min_ipv6_addr_count set, the component won't reach CONNECTED state without IPv6.
792 // However, this may fail with ESP_FAIL if the interface is not up yet:
793 // - At bootup when link isn't ready (#10281)
794 // - After disconnection/cable unplugged (#10705)
795 // We'll retry in finish_connect_() if it fails here.
796 err = esp_netif_create_ip6_linklocal(this->eth_netif_);
797 if (err != ESP_OK) {
798 if (err == ESP_ERR_ESP_NETIF_INVALID_PARAMS) {
799 // This is a programming error, not a transient failure
800 ESPHL_ERROR_CHECK(err, "esp_netif_create_ip6_linklocal invalid parameters");
801 } else {
802 // ESP_FAIL means the interface isn't up yet
803 // This is expected and non-fatal, happens in multiple scenarios:
804 // - During reconnection after network interruptions (#10705)
805 // - At bootup when the link isn't ready yet (#10281)
806 // We'll retry once we reach CONNECTED state and the interface is up
807 ESP_LOGW(TAG, "esp_netif_create_ip6_linklocal failed: %s", esp_err_to_name(err));
808 // Don't mark component as failed - this is a transient error
809 }
810 }
811#endif /* USE_NETWORK_IPV6 */
812
813 this->connect_begin_ = millis();
814 this->status_set_warning();
815}
816
818 if (!this->ethernet_initialized_) {
819 ESP_LOGCONFIG(TAG, " uninitialized/disabled");
820 return;
821 }
822 esp_netif_ip_info_t ip;
823 esp_netif_get_ip_info(this->eth_netif_, &ip);
824 const ip_addr_t *dns_ip1;
825 const ip_addr_t *dns_ip2;
826 {
828 dns_ip1 = dns_getserver(0);
829 dns_ip2 = dns_getserver(1);
830 }
831
832 // Use stack buffers for IP address formatting to avoid heap allocations
833 char ip_buf[network::IP_ADDRESS_BUFFER_SIZE];
834 char subnet_buf[network::IP_ADDRESS_BUFFER_SIZE];
835 char gateway_buf[network::IP_ADDRESS_BUFFER_SIZE];
836 char dns1_buf[network::IP_ADDRESS_BUFFER_SIZE];
837 char dns2_buf[network::IP_ADDRESS_BUFFER_SIZE];
838 char mac_buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
839 uint16_t link_speed = 10;
840 switch (this->get_link_speed()) {
841 case ETH_SPEED_100M:
842 link_speed = 100;
843 break;
844#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 1, 0)
845 case ETH_SPEED_1000M:
846 link_speed = 1000;
847 break;
848#endif
849 default:
850 break;
851 }
852 ESP_LOGCONFIG(TAG,
853 " IP Address: %s\n"
854 " Hostname: '%s'\n"
855 " Subnet: %s\n"
856 " Gateway: %s\n"
857 " DNS1: %s\n"
858 " DNS2: %s\n"
859 " MAC Address: %s\n"
860 " Is Full Duplex: %s\n"
861 " Link Speed: %u",
862 network::IPAddress(&ip.ip).str_to(ip_buf), App.get_name().c_str(),
863 network::IPAddress(&ip.netmask).str_to(subnet_buf), network::IPAddress(&ip.gw).str_to(gateway_buf),
864 network::IPAddress(dns_ip1).str_to(dns1_buf), network::IPAddress(dns_ip2).str_to(dns2_buf),
865 this->get_eth_mac_address_pretty_into_buffer(mac_buf),
866 YESNO(this->get_duplex_mode() == ETH_DUPLEX_FULL), link_speed);
867
868#if USE_NETWORK_IPV6
869 struct esp_ip6_addr if_ip6s[CONFIG_LWIP_IPV6_NUM_ADDRESSES];
870 uint8_t count = 0;
871 count = esp_netif_get_all_ip6(this->eth_netif_, if_ip6s);
872 assert(count <= CONFIG_LWIP_IPV6_NUM_ADDRESSES);
873 for (int i = 0; i < count; i++) {
874 ESP_LOGCONFIG(TAG, " IPv6: " IPV6STR, IPV62STR(if_ip6s[i]));
875 }
876#endif /* USE_NETWORK_IPV6 */
877}
878
879#ifdef USE_ETHERNET_SPI
880void EthernetComponent::set_clk_pin(uint8_t clk_pin) { this->clk_pin_ = clk_pin; }
881void EthernetComponent::set_miso_pin(uint8_t miso_pin) { this->miso_pin_ = miso_pin; }
882void EthernetComponent::set_mosi_pin(uint8_t mosi_pin) { this->mosi_pin_ = mosi_pin; }
883void EthernetComponent::set_cs_pin(uint8_t cs_pin) { this->cs_pin_ = cs_pin; }
884void EthernetComponent::set_interrupt_pin(uint8_t interrupt_pin) { this->interrupt_pin_ = interrupt_pin; }
885void EthernetComponent::set_reset_pin(uint8_t reset_pin) { this->reset_pin_ = reset_pin; }
886void EthernetComponent::set_clock_speed(int clock_speed) { this->clock_speed_ = clock_speed; }
887void EthernetComponent::set_interface(spi_host_device_t interface) { this->interface_ = interface; }
888#ifdef USE_ETHERNET_SPI_POLLING_SUPPORT
889void EthernetComponent::set_polling_interval(uint32_t polling_interval) { this->polling_interval_ = polling_interval; }
890#endif
891#else
892void EthernetComponent::set_phy_addr(uint8_t phy_addr) { this->phy_addr_ = phy_addr; }
893void EthernetComponent::set_power_pin(int power_pin) { this->power_pin_ = power_pin; }
894void EthernetComponent::set_mdc_pin(uint8_t mdc_pin) { this->mdc_pin_ = mdc_pin; }
895void EthernetComponent::set_mdio_pin(uint8_t mdio_pin) { this->mdio_pin_ = mdio_pin; }
896void EthernetComponent::set_clk_pin(uint8_t clk_pin) { this->clk_pin_ = clk_pin; }
897void EthernetComponent::set_clk_mode(emac_rmii_clock_mode_t clk_mode) { this->clk_mode_ = clk_mode; }
898void EthernetComponent::add_phy_register(PHYRegister register_value) { this->phy_registers_.push_back(register_value); }
899#endif
900
902 if (!this->ethernet_initialized_) {
903 // External callers (mdns, ethernet_info, etc.) may ask for the MAC before/regardless
904 // of whether ethernet is enabled. Use the configured MAC if set, else the system ETH MAC.
905 if (this->fixed_mac_.has_value()) {
906 memcpy(mac, this->fixed_mac_->data(), 6);
907 } else {
908 esp_read_mac(mac, ESP_MAC_ETH);
909 }
910 return;
911 }
912 esp_err_t err;
913 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_MAC_ADDR, mac);
914 ESPHL_ERROR_CHECK(err, "ETH_CMD_G_MAC error");
915}
916
917std::string EthernetComponent::get_eth_mac_address_pretty() {
918 char buf[MAC_ADDRESS_PRETTY_BUFFER_SIZE];
919 return std::string(this->get_eth_mac_address_pretty_into_buffer(buf));
920}
921
923 std::span<char, MAC_ADDRESS_PRETTY_BUFFER_SIZE> buf) {
924 uint8_t mac[6];
926 format_mac_addr_upper(mac, buf.data());
927 return buf.data();
928}
929
931 if (!this->ethernet_initialized_)
932 return ETH_DUPLEX_HALF;
933 esp_err_t err;
934 eth_duplex_t duplex_mode;
935 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_DUPLEX_MODE, &duplex_mode);
936 ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_DUPLEX_MODE error", ETH_DUPLEX_HALF);
937 return duplex_mode;
938}
939
941 if (!this->ethernet_initialized_)
942 return ETH_SPEED_10M;
943 esp_err_t err;
945 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_G_SPEED, &speed);
946 ESPHL_ERROR_CHECK_RET(err, "ETH_CMD_G_SPEED error", ETH_SPEED_10M);
947 return speed;
948}
949
951 ESP_LOGI(TAG, "Powering down ethernet PHY");
952 if (this->phy_ == nullptr) {
953 ESP_LOGE(TAG, "Ethernet PHY not assigned");
954 return false;
955 }
956 this->connected_ = false;
957 this->started_ = false;
958 // No need to enable_loop() here as this is only called during shutdown/reboot
959 if (this->phy_->pwrctl(this->phy_, false) != ESP_OK) {
960 ESP_LOGE(TAG, "Error powering down ethernet PHY");
961 return false;
962 }
963 return true;
964}
965
966#ifndef USE_ETHERNET_SPI
967
968#ifdef USE_ETHERNET_KSZ8081
969constexpr uint8_t KSZ80XX_PC2R_REG_ADDR = 0x1F;
970
972 esp_err_t err;
973
974 uint32_t phy_control_2;
975 err = mac->read_phy_reg(mac, this->phy_addr_, KSZ80XX_PC2R_REG_ADDR, &(phy_control_2));
976 ESPHL_ERROR_CHECK(err, "Read PHY Control 2 failed");
977#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
978 char hex_buf[format_hex_pretty_size(PHY_REG_SIZE)];
979#endif
980 ESP_LOGVV(TAG, "KSZ8081 PHY Control 2: %s", format_hex_pretty_to(hex_buf, (uint8_t *) &phy_control_2, PHY_REG_SIZE));
981
982 /*
983 * Bit 7 is `RMII Reference Clock Select`. Default is `0`.
984 * KSZ8081RNA:
985 * 0 - clock input to XI (Pin 8) is 25 MHz for RMII - 25 MHz clock mode.
986 * 1 - clock input to XI (Pin 8) is 50 MHz for RMII - 50 MHz clock mode.
987 * KSZ8081RND:
988 * 0 - clock input to XI (Pin 8) is 50 MHz for RMII - 50 MHz clock mode.
989 * 1 - clock input to XI (Pin 8) is 25 MHz (driven clock only, not a crystal) for RMII - 25 MHz clock mode.
990 */
991 if ((phy_control_2 & (1 << 7)) != (1 << 7)) {
992 phy_control_2 |= 1 << 7;
993 err = mac->write_phy_reg(mac, this->phy_addr_, KSZ80XX_PC2R_REG_ADDR, phy_control_2);
994 ESPHL_ERROR_CHECK(err, "Write PHY Control 2 failed");
995 err = mac->read_phy_reg(mac, this->phy_addr_, KSZ80XX_PC2R_REG_ADDR, &(phy_control_2));
996 ESPHL_ERROR_CHECK(err, "Read PHY Control 2 failed");
997 ESP_LOGVV(TAG, "KSZ8081 PHY Control 2: %s",
998 format_hex_pretty_to(hex_buf, (uint8_t *) &phy_control_2, PHY_REG_SIZE));
999 }
1000}
1001#endif // USE_ETHERNET_KSZ8081
1002
1003void EthernetComponent::write_phy_register_(esp_eth_mac_t *mac, PHYRegister register_data) {
1004 esp_err_t err;
1005
1006#ifdef USE_ETHERNET_RTL8201
1007 constexpr uint8_t eth_phy_psr_reg_addr = 0x1F;
1008 if (this->type_ == ETHERNET_TYPE_RTL8201 && register_data.page) {
1009 ESP_LOGD(TAG, "Select PHY Register Page: 0x%02" PRIX32, register_data.page);
1010 err = mac->write_phy_reg(mac, this->phy_addr_, eth_phy_psr_reg_addr, register_data.page);
1011 ESPHL_ERROR_CHECK(err, "Select PHY Register page failed");
1012 }
1013#endif
1014
1015 ESP_LOGD(TAG, "Writing PHY reg 0x%02" PRIX32 " = 0x%04" PRIX32, register_data.address, register_data.value);
1016 err = mac->write_phy_reg(mac, this->phy_addr_, register_data.address, register_data.value);
1017 ESPHL_ERROR_CHECK(err, "Writing PHY Register failed");
1018
1019#ifdef USE_ETHERNET_RTL8201
1020 if (this->type_ == ETHERNET_TYPE_RTL8201 && register_data.page) {
1021 ESP_LOGD(TAG, "Select PHY Register Page 0x00");
1022 err = mac->write_phy_reg(mac, this->phy_addr_, eth_phy_psr_reg_addr, 0x0);
1023 ESPHL_ERROR_CHECK(err, "Select PHY Register Page 0 failed");
1024 }
1025#endif
1026}
1027
1028#ifdef USE_ETHERNET_YT8531
1030 esp_err_t err;
1031
1032 // The YT8531 disables auto-negotiation on hardware reset (undocumented behavior), and the
1033 // generic 802.3 driver only resets the PHY, so re-enable it (this also updates the driver's
1034 // cached auto-nego state used by esp_eth_start()).
1035 bool autoneg_enable = true;
1036 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_S_AUTONEGO, &autoneg_enable);
1037 ESPHL_ERROR_CHECK(err, "YT8531 enable auto-negotiation failed");
1038
1039 // RGMII needs ~2 ns Tx and Rx clock delays for reliable data sampling. These are set through
1040 // the YT8531 extended-register interface: write the ext-register address to 0x1E, then
1041 // read/modify/write its value via 0x1F.
1042 esp_eth_phy_reg_rw_data_t phy_reg;
1043 uint32_t reg_val;
1044 phy_reg.reg_value_p = &reg_val;
1045
1046 // RX ~2 ns coarse delay: EXT_CHIP_CONFIG (0xA001), set rxc_dly_en (bit 8).
1047 reg_val = 0xA001;
1048 phy_reg.reg_addr = 0x1E;
1049 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1050 ESPHL_ERROR_CHECK(err, "YT8531 select Chip_Config failed");
1051 phy_reg.reg_addr = 0x1F;
1052 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_READ_PHY_REG, &phy_reg);
1053 ESPHL_ERROR_CHECK(err, "YT8531 read Chip_Config failed");
1054 reg_val |= (1U << 8);
1055 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1056 ESPHL_ERROR_CHECK(err, "YT8531 write Chip_Config failed");
1057
1058 // TX ~2 ns delay: EXT_RGMII_CONFIG1 (0xA003), tx_delay_sel[3:0] and tx_delay_sel_fe[7:4] = 13.
1059 reg_val = 0xA003;
1060 phy_reg.reg_addr = 0x1E;
1061 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1062 ESPHL_ERROR_CHECK(err, "YT8531 select RGMII_Config1 failed");
1063 phy_reg.reg_addr = 0x1F;
1064 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_READ_PHY_REG, &phy_reg);
1065 ESPHL_ERROR_CHECK(err, "YT8531 read RGMII_Config1 failed");
1066 reg_val = (reg_val & ~0x00FFU) | (13U << 4) | (13U << 0);
1067 err = esp_eth_ioctl(this->eth_handle_, ETH_CMD_WRITE_PHY_REG, &phy_reg);
1068 ESPHL_ERROR_CHECK(err, "YT8531 write RGMII_Config1 failed");
1069}
1070#endif
1071
1072#endif
1073
1074} // namespace esphome::ethernet
1075
1076#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