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

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

* ci(pre-commit): Apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
Me No Dev 2025-03-10 21:20:07 +02:00 committed by GitHub
parent eeb6a26ed1
commit bf5265c7d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 2 deletions

View file

@ -1009,6 +1009,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;
@ -1018,6 +1030,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;
@ -1027,7 +1050,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;
}
@ -1036,6 +1059,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){

View file

@ -192,8 +192,14 @@ public:
// 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;