Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eth): Add setters for negotiation, speed and duplex modes #11053

Merged
merged 2 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion libraries/Ethernet/src/ETH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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){
Expand Down
8 changes: 7 additions & 1 deletion libraries/Ethernet/src/ETH.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading