Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf5265c

Browse filesBrowse files
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>
1 parent eeb6a26 commit bf5265c
Copy full SHA for bf5265c

File tree

Expand file treeCollapse file tree

2 files changed

+43
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+43
-2
lines changed

‎libraries/Ethernet/src/ETH.cpp

Copy file name to clipboardExpand all lines: libraries/Ethernet/src/ETH.cpp
+36-1Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,18 @@ bool ETHClass::fullDuplex() const {
10091009
return (link_duplex == ETH_DUPLEX_FULL);
10101010
}
10111011

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+
10121024
bool ETHClass::autoNegotiation() const {
10131025
if (_eth_handle == NULL) {
10141026
return false;
@@ -1018,6 +1030,17 @@ bool ETHClass::autoNegotiation() const {
10181030
return auto_nego;
10191031
}
10201032

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+
10211044
uint32_t ETHClass::phyAddr() const {
10221045
if (_eth_handle == NULL) {
10231046
return 0;
@@ -1027,7 +1050,7 @@ uint32_t ETHClass::phyAddr() const {
10271050
return phy_addr;
10281051
}
10291052

1030-
uint8_t ETHClass::linkSpeed() const {
1053+
uint16_t ETHClass::linkSpeed() const {
10311054
if (_eth_handle == NULL) {
10321055
return 0;
10331056
}
@@ -1036,6 +1059,18 @@ uint8_t ETHClass::linkSpeed() const {
10361059
return (link_speed == ETH_SPEED_10M) ? 10 : 100;
10371060
}
10381061

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+
10391074
// void ETHClass::getMac(uint8_t* mac)
10401075
// {
10411076
// if(_eth_handle != NULL && mac != NULL){

‎libraries/Ethernet/src/ETH.h

Copy file name to clipboardExpand all lines: libraries/Ethernet/src/ETH.h
+7-1Lines changed: 7 additions & 1 deletion
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.