Skip to content

Commit 6dda96a

Browse files
committed
feat(eth): Add setters for negotiation, speed and duplex modes
1 parent 9e2f755 commit 6dda96a

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

Diff for: libraries/Ethernet/src/ETH.cpp

+36-1
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,18 @@ bool ETHClass::fullDuplex() const {
10101010
return (link_duplex == ETH_DUPLEX_FULL);
10111011
}
10121012

1013+
bool ETHClass::setFullDuplex(bool on) {
1014+
if (_eth_handle == NULL) {
1015+
return false;
1016+
}
1017+
eth_duplex_t link_duplex = on?ETH_DUPLEX_FULL:ETH_DUPLEX_HALF;
1018+
esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_DUPLEX_MODE, &link_duplex);
1019+
if (err != ESP_OK) {
1020+
log_e("Failed to set duplex mode: 0x%x: %s", err, esp_err_to_name(err));
1021+
}
1022+
return err == ESP_OK;
1023+
}
1024+
10131025
bool ETHClass::autoNegotiation() const {
10141026
if (_eth_handle == NULL) {
10151027
return false;
@@ -1019,6 +1031,17 @@ bool ETHClass::autoNegotiation() const {
10191031
return auto_nego;
10201032
}
10211033

1034+
bool ETHClass::setAutoNegotiation(bool on) {
1035+
if (_eth_handle == NULL) {
1036+
return false;
1037+
}
1038+
esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_AUTONEGO, &on);
1039+
if (err != ESP_OK) {
1040+
log_e("Failed to set auto negotiation: 0x%x: %s", err, esp_err_to_name(err));
1041+
}
1042+
return err == ESP_OK;
1043+
}
1044+
10221045
uint32_t ETHClass::phyAddr() const {
10231046
if (_eth_handle == NULL) {
10241047
return 0;
@@ -1028,7 +1051,7 @@ uint32_t ETHClass::phyAddr() const {
10281051
return phy_addr;
10291052
}
10301053

1031-
uint8_t ETHClass::linkSpeed() const {
1054+
uint16_t ETHClass::linkSpeed() const {
10321055
if (_eth_handle == NULL) {
10331056
return 0;
10341057
}
@@ -1037,6 +1060,18 @@ uint8_t ETHClass::linkSpeed() const {
10371060
return (link_speed == ETH_SPEED_10M) ? 10 : 100;
10381061
}
10391062

1063+
bool ETHClass::setLinkSpeed(uint16_t speed) {
1064+
if (_eth_handle == NULL) {
1065+
return false;
1066+
}
1067+
eth_speed_t link_speed = (speed == 10)?ETH_SPEED_10M:ETH_SPEED_100M;
1068+
esp_err_t err = esp_eth_ioctl(_eth_handle, ETH_CMD_S_SPEED, &link_speed);
1069+
if (err != ESP_OK) {
1070+
log_e("Failed to set link speed: 0x%x: %s", err, esp_err_to_name(err));
1071+
}
1072+
return err == ESP_OK;
1073+
}
1074+
10401075
// void ETHClass::getMac(uint8_t* mac)
10411076
// {
10421077
// if(_eth_handle != NULL && mac != NULL){

Diff for: libraries/Ethernet/src/ETH.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,14 @@ class ETHClass : public NetworkInterface {
192192

193193
// ETH Handle APIs
194194
bool fullDuplex() const;
195-
uint8_t linkSpeed() const;
195+
bool setFullDuplex(bool on);
196+
197+
uint16_t linkSpeed() const;
198+
bool setLinkSpeed(uint16_t speed);//10 or 100
199+
196200
bool autoNegotiation() const;
201+
bool setAutoNegotiation(bool on);
202+
197203
uint32_t phyAddr() const;
198204

199205
esp_eth_handle_t handle() const;

0 commit comments

Comments
 (0)