@@ -271,8 +271,8 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
271
271
eth_mac_config.sw_reset_timeout_ms = 1000 ;
272
272
eth_mac_config.rx_task_stack_size = _task_stack_size;
273
273
274
- esp_eth_mac_t *mac = esp_eth_mac_new_esp32 (&mac_config, ð_mac_config);
275
- if (mac == NULL ) {
274
+ _mac = esp_eth_mac_new_esp32 (&mac_config, ð_mac_config);
275
+ if (_mac == NULL ) {
276
276
log_e (" esp_eth_mac_new_esp32 failed" );
277
277
return false ;
278
278
}
@@ -281,26 +281,25 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
281
281
phy_config.phy_addr = phy_addr;
282
282
phy_config.reset_gpio_num = _pin_power;
283
283
284
- esp_eth_phy_t *phy = NULL ;
285
284
switch (type) {
286
285
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
287
- case ETH_PHY_GENERIC: phy = esp_eth_phy_new_generic (&phy_config); break ;
286
+ case ETH_PHY_GENERIC: _phy = esp_eth_phy_new_generic (&phy_config); break ;
288
287
#endif
289
- case ETH_PHY_LAN8720: phy = esp_eth_phy_new_lan87xx (&phy_config); break ;
290
- case ETH_PHY_TLK110: phy = esp_eth_phy_new_ip101 (&phy_config); break ;
291
- case ETH_PHY_RTL8201: phy = esp_eth_phy_new_rtl8201 (&phy_config); break ;
292
- case ETH_PHY_DP83848: phy = esp_eth_phy_new_dp83848 (&phy_config); break ;
293
- case ETH_PHY_KSZ8041: phy = esp_eth_phy_new_ksz80xx (&phy_config); break ;
294
- case ETH_PHY_KSZ8081: phy = esp_eth_phy_new_ksz80xx (&phy_config); break ;
288
+ case ETH_PHY_LAN8720: _phy = esp_eth_phy_new_lan87xx (&phy_config); break ;
289
+ case ETH_PHY_TLK110: _phy = esp_eth_phy_new_ip101 (&phy_config); break ;
290
+ case ETH_PHY_RTL8201: _phy = esp_eth_phy_new_rtl8201 (&phy_config); break ;
291
+ case ETH_PHY_DP83848: _phy = esp_eth_phy_new_dp83848 (&phy_config); break ;
292
+ case ETH_PHY_KSZ8041: _phy = esp_eth_phy_new_ksz80xx (&phy_config); break ;
293
+ case ETH_PHY_KSZ8081: _phy = esp_eth_phy_new_ksz80xx (&phy_config); break ;
295
294
default : log_e (" Unsupported PHY %d" , type); break ;
296
295
}
297
- if (phy == NULL ) {
296
+ if (_phy == NULL ) {
298
297
log_e (" esp_eth_phy_new failed" );
299
298
return false ;
300
299
}
301
300
302
301
_eth_handle = NULL ;
303
- esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG (mac, phy );
302
+ esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG (_mac, _phy );
304
303
ret = esp_eth_driver_install (ð_config, &_eth_handle);
305
304
if (ret != ESP_OK) {
306
305
log_e (" Ethernet driver install failed: %d" , ret);
@@ -1010,6 +1009,18 @@ bool ETHClass::fullDuplex() const {
1010
1009
return (link_duplex == ETH_DUPLEX_FULL);
1011
1010
}
1012
1011
1012
+ bool ETHClass::setFullDuplex (bool on) {
1013
+ if (_eth_handle == NULL ) {
1014
+ return false ;
1015
+ }
1016
+ eth_duplex_t link_duplex = on ? ETH_DUPLEX_FULL : ETH_DUPLEX_HALF;
1017
+ esp_err_t err = esp_eth_ioctl (_eth_handle, ETH_CMD_S_DUPLEX_MODE, &link_duplex);
1018
+ if (err != ESP_OK) {
1019
+ log_e (" Failed to set duplex mode: 0x%x: %s" , err, esp_err_to_name (err));
1020
+ }
1021
+ return err == ESP_OK;
1022
+ }
1023
+
1013
1024
bool ETHClass::autoNegotiation () const {
1014
1025
if (_eth_handle == NULL ) {
1015
1026
return false ;
@@ -1019,6 +1030,17 @@ bool ETHClass::autoNegotiation() const {
1019
1030
return auto_nego;
1020
1031
}
1021
1032
1033
+ bool ETHClass::setAutoNegotiation (bool on) {
1034
+ if (_eth_handle == NULL ) {
1035
+ return false ;
1036
+ }
1037
+ esp_err_t err = esp_eth_ioctl (_eth_handle, ETH_CMD_S_AUTONEGO, &on);
1038
+ if (err != ESP_OK) {
1039
+ log_e (" Failed to set auto negotiation: 0x%x: %s" , err, esp_err_to_name (err));
1040
+ }
1041
+ return err == ESP_OK;
1042
+ }
1043
+
1022
1044
uint32_t ETHClass::phyAddr () const {
1023
1045
if (_eth_handle == NULL ) {
1024
1046
return 0 ;
@@ -1028,7 +1050,7 @@ uint32_t ETHClass::phyAddr() const {
1028
1050
return phy_addr;
1029
1051
}
1030
1052
1031
- uint8_t ETHClass::linkSpeed () const {
1053
+ uint16_t ETHClass::linkSpeed () const {
1032
1054
if (_eth_handle == NULL ) {
1033
1055
return 0 ;
1034
1056
}
@@ -1037,6 +1059,18 @@ uint8_t ETHClass::linkSpeed() const {
1037
1059
return (link_speed == ETH_SPEED_10M) ? 10 : 100 ;
1038
1060
}
1039
1061
1062
+ bool ETHClass::setLinkSpeed (uint16_t speed) {
1063
+ if (_eth_handle == NULL ) {
1064
+ return false ;
1065
+ }
1066
+ eth_speed_t link_speed = (speed == 10 ) ? ETH_SPEED_10M : ETH_SPEED_100M;
1067
+ esp_err_t err = esp_eth_ioctl (_eth_handle, ETH_CMD_S_SPEED, &link_speed);
1068
+ if (err != ESP_OK) {
1069
+ log_e (" Failed to set link speed: 0x%x: %s" , err, esp_err_to_name (err));
1070
+ }
1071
+ return err == ESP_OK;
1072
+ }
1073
+
1040
1074
// void ETHClass::getMac(uint8_t* mac)
1041
1075
// {
1042
1076
// if(_eth_handle != NULL && mac != NULL){
0 commit comments