From 6dda96a6b52399f7da94b9778b693eae06f91546 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Fri, 7 Mar 2025 16:51:36 +0200 Subject: [PATCH 1/2] feat(eth): Add setters for negotiation, speed and duplex modes --- libraries/Ethernet/src/ETH.cpp | 37 +++++++++++++++++++++++++++++++++- libraries/Ethernet/src/ETH.h | 8 +++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index bf63de8724d..f08dbe6820a 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -1010,6 +1010,18 @@ bool ETHClass::fullDuplex() const { return (link_duplex == ETH_DUPLEX_FULL); } +bool ETHClass::setFullDuplex(bool on) { + if (_eth_handle == NULL) { + return false; + } + eth_duplex_t link_duplex = on?ETH_DUPLEX_FULL:ETH_DUPLEX_HALF; + esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_DUPLEX_MODE, &link_duplex); + if (err != ESP_OK) { + log_e("Failed to set duplex mode: 0x%x: %s", err, esp_err_to_name(err)); + } + return err == ESP_OK; +} + bool ETHClass::autoNegotiation() const { if (_eth_handle == NULL) { return false; @@ -1019,6 +1031,17 @@ bool ETHClass::autoNegotiation() const { return auto_nego; } +bool ETHClass::setAutoNegotiation(bool on) { + if (_eth_handle == NULL) { + return false; + } + esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_AUTONEGO, &on); + if (err != ESP_OK) { + log_e("Failed to set auto negotiation: 0x%x: %s", err, esp_err_to_name(err)); + } + return err == ESP_OK; +} + uint32_t ETHClass::phyAddr() const { if (_eth_handle == NULL) { return 0; @@ -1028,7 +1051,7 @@ uint32_t ETHClass::phyAddr() const { return phy_addr; } -uint8_t ETHClass::linkSpeed() const { +uint16_t ETHClass::linkSpeed() const { if (_eth_handle == NULL) { return 0; } @@ -1037,6 +1060,18 @@ uint8_t ETHClass::linkSpeed() const { return (link_speed == ETH_SPEED_10M) ? 10 : 100; } +bool ETHClass::setLinkSpeed(uint16_t speed) { + if (_eth_handle == NULL) { + return false; + } + eth_speed_t link_speed = (speed == 10)?ETH_SPEED_10M:ETH_SPEED_100M; + esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_SPEED, &link_speed); + if (err != ESP_OK) { + log_e("Failed to set link speed: 0x%x: %s", err, esp_err_to_name(err)); + } + return err == ESP_OK; +} + // void ETHClass::getMac(uint8_t* mac) // { // if(_eth_handle != NULL && mac != NULL){ diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index cbddac065b9..972992589cb 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -192,8 +192,14 @@ class ETHClass : public NetworkInterface { // ETH Handle APIs bool fullDuplex() const; - uint8_t linkSpeed() const; + bool setFullDuplex(bool on); + + uint16_t linkSpeed() const; + bool setLinkSpeed(uint16_t speed);//10 or 100 + bool autoNegotiation() const; + bool setAutoNegotiation(bool on); + uint32_t phyAddr() const; esp_eth_handle_t handle() const; From 922ef56da5ef1884b3addff3c85cc8ec36257a7a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 17:10:53 +0000 Subject: [PATCH 2/2] ci(pre-commit): Apply automatic fixes --- libraries/Ethernet/src/ETH.cpp | 4 ++-- libraries/Ethernet/src/ETH.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/Ethernet/src/ETH.cpp b/libraries/Ethernet/src/ETH.cpp index f08dbe6820a..ef520273020 100644 --- a/libraries/Ethernet/src/ETH.cpp +++ b/libraries/Ethernet/src/ETH.cpp @@ -1014,7 +1014,7 @@ bool ETHClass::setFullDuplex(bool on) { if (_eth_handle == NULL) { return false; } - eth_duplex_t link_duplex = on?ETH_DUPLEX_FULL:ETH_DUPLEX_HALF; + eth_duplex_t link_duplex = on ? ETH_DUPLEX_FULL : ETH_DUPLEX_HALF; esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_DUPLEX_MODE, &link_duplex); if (err != ESP_OK) { log_e("Failed to set duplex mode: 0x%x: %s", err, esp_err_to_name(err)); @@ -1064,7 +1064,7 @@ bool ETHClass::setLinkSpeed(uint16_t speed) { if (_eth_handle == NULL) { return false; } - eth_speed_t link_speed = (speed == 10)?ETH_SPEED_10M:ETH_SPEED_100M; + eth_speed_t link_speed = (speed == 10) ? ETH_SPEED_10M : ETH_SPEED_100M; esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_SPEED, &link_speed); if (err != ESP_OK) { log_e("Failed to set link speed: 0x%x: %s", err, esp_err_to_name(err)); diff --git a/libraries/Ethernet/src/ETH.h b/libraries/Ethernet/src/ETH.h index 972992589cb..891863e34bf 100644 --- a/libraries/Ethernet/src/ETH.h +++ b/libraries/Ethernet/src/ETH.h @@ -193,9 +193,9 @@ class ETHClass : public NetworkInterface { // ETH Handle APIs bool fullDuplex() const; bool setFullDuplex(bool on); - + uint16_t linkSpeed() const; - bool setLinkSpeed(uint16_t speed);//10 or 100 + bool setLinkSpeed(uint16_t speed); //10 or 100 bool autoNegotiation() const; bool setAutoNegotiation(bool on);