@@ -119,7 +119,7 @@ void ETHClass::_onEthEvent(int32_t event_id, void *event_data) {
119
119
}
120
120
121
121
ETHClass::ETHClass (uint8_t eth_index)
122
- : _eth_handle(NULL ), _eth_index(eth_index), _phy_type(ETH_PHY_MAX), _glue_handle(NULL )
122
+ : _eth_handle(NULL ), _eth_index(eth_index), _phy_type(ETH_PHY_MAX), _glue_handle(NULL ), _mac( NULL ), _phy( NULL )
123
123
#if ETH_SPI_SUPPORTS_CUSTOM
124
124
,
125
125
_spi (NULL )
@@ -587,8 +587,6 @@ bool ETHClass::beginSPI(
587
587
spi_devcfg.spics_io_num = _pin_cs;
588
588
spi_devcfg.queue_size = 20 ;
589
589
590
- esp_eth_mac_t *mac = NULL ;
591
- esp_eth_phy_t *phy = NULL ;
592
590
#if CONFIG_ETH_SPI_ETHERNET_W5500
593
591
if (type == ETH_PHY_W5500) {
594
592
eth_w5500_config_t mac_config = ETH_W5500_DEFAULT_CONFIG (spi_host, &spi_devcfg);
@@ -607,8 +605,8 @@ bool ETHClass::beginSPI(
607
605
mac_config.custom_spi_driver .write = _eth_spi_write;
608
606
}
609
607
#endif
610
- mac = esp_eth_mac_new_w5500 (&mac_config, ð_mac_config);
611
- phy = esp_eth_phy_new_w5500 (&phy_config);
608
+ _mac = esp_eth_mac_new_w5500 (&mac_config, ð_mac_config);
609
+ _phy = esp_eth_phy_new_w5500 (&phy_config);
612
610
} else
613
611
#endif
614
612
#if CONFIG_ETH_SPI_ETHERNET_DM9051
@@ -624,8 +622,8 @@ bool ETHClass::beginSPI(
624
622
mac_config.custom_spi_driver .write = _eth_spi_write;
625
623
}
626
624
#endif
627
- mac = esp_eth_mac_new_dm9051 (&mac_config, ð_mac_config);
628
- phy = esp_eth_phy_new_dm9051 (&phy_config);
625
+ _mac = esp_eth_mac_new_dm9051 (&mac_config, ð_mac_config);
626
+ _phy = esp_eth_phy_new_dm9051 (&phy_config);
629
627
} else
630
628
#endif
631
629
#if CONFIG_ETH_SPI_ETHERNET_KSZ8851SNL
@@ -641,8 +639,8 @@ bool ETHClass::beginSPI(
641
639
mac_config.custom_spi_driver .write = _eth_spi_write;
642
640
}
643
641
#endif
644
- mac = esp_eth_mac_new_ksz8851snl (&mac_config, ð_mac_config);
645
- phy = esp_eth_phy_new_ksz8851snl (&phy_config);
642
+ _mac = esp_eth_mac_new_ksz8851snl (&mac_config, ð_mac_config);
643
+ _phy = esp_eth_phy_new_ksz8851snl (&phy_config);
646
644
} else
647
645
#endif
648
646
{
@@ -651,7 +649,7 @@ bool ETHClass::beginSPI(
651
649
}
652
650
653
651
// Init Ethernet driver to default and install it
654
- esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG (mac, phy );
652
+ esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG (_mac, _phy );
655
653
ret = esp_eth_driver_install (ð_config, &_eth_handle);
656
654
if (ret != ESP_OK) {
657
655
log_e (" SPI Ethernet driver install failed: %d" , ret);
@@ -841,6 +839,16 @@ void ETHClass::end(void) {
841
839
return ;
842
840
}
843
841
_eth_handle = NULL ;
842
+ // delete mac
843
+ if (_mac != NULL ) {
844
+ _mac->del (_mac);
845
+ _mac = NULL ;
846
+ }
847
+ // delete phy
848
+ if (_phy != NULL ) {
849
+ _phy->del (_phy);
850
+ _phy = NULL ;
851
+ }
844
852
}
845
853
846
854
if (_eth_ev_instance != NULL ) {
0 commit comments