Skip to content

Commit 90036a2

Browse files
authored
fix(eth): Eth pins check in examples to avoid redefinition (#9242)
1 parent 0a2a487 commit 90036a2

File tree

4 files changed

+49
-37
lines changed

4 files changed

+49
-37
lines changed

Diff for: libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino

+2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
// Important to be defined BEFORE including ETH.h for ETH.begin() to work.
77
// Example RMII LAN8720 (Olimex, etc.)
8+
#ifndef ETH_PHY_TYPE
89
#define ETH_PHY_TYPE ETH_PHY_LAN8720
910
#define ETH_PHY_ADDR 0
1011
#define ETH_PHY_MDC 23
1112
#define ETH_PHY_MDIO 18
1213
#define ETH_PHY_POWER -1
1314
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
15+
#endif
1416

1517
#include <ETH.h>
1618

Diff for: libraries/Ethernet/examples/ETH_TLK110/ETH_TLK110.ino

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
#include <ETH.h>
77

8-
#define ETH_TYPE ETH_PHY_TLK110
9-
#define ETH_ADDR 31
10-
#define ETH_MDC_PIN 23
11-
#define ETH_MDIO_PIN 18
12-
#define ETH_POWER_PIN 17
8+
#ifndef ETH_PHY_TYPE
9+
#define ETH_PHY_TYPE ETH_PHY_TLK110
10+
#define ETH_PHY_ADDR 31
11+
#define ETH_PHY_MDC 23
12+
#define ETH_PHY_MDIO 18
13+
#define ETH_PHY_POWER 17
1314
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
15+
#endif
1416

1517
static bool eth_connected = false;
1618

@@ -73,7 +75,7 @@ void setup()
7375
{
7476
Serial.begin(115200);
7577
WiFi.onEvent(WiFiEvent); // Will call WiFiEvent() from another thread.
76-
ETH.begin(ETH_TYPE, ETH_ADDR, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_POWER_PIN, ETH_CLK_MODE);
78+
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_POWER, ETH_CLK_MODE);
7779
}
7880

7981

Diff for: libraries/Ethernet/examples/ETH_W5500_Arduino_SPI/ETH_W5500_Arduino_SPI.ino

+19-15
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,28 @@
99
// Set this to 1 to enable dual Ethernet support
1010
#define USE_TWO_ETH_PORTS 0
1111

12-
#define ETH_TYPE ETH_PHY_W5500
13-
#define ETH_ADDR 1
14-
#define ETH_CS 15
15-
#define ETH_IRQ 4
16-
#define ETH_RST 5
12+
#ifndef ETH_PHY_TYPE
13+
#define ETH_PHY_TYPE ETH_PHY_W5500
14+
#define ETH_PHY_ADDR 1
15+
#define ETH_PHY_CS 15
16+
#define ETH_PHY_IRQ 4
17+
#define ETH_PHY_RST 5
18+
#endif
1719

1820
// SPI pins
19-
#define ETH_SPI_SCK 14
20-
#define ETH_SPI_MISO 12
21-
#define ETH_SPI_MOSI 13
21+
#define ETH_SPI_SCK 14
22+
#define ETH_SPI_MISO 12
23+
#define ETH_SPI_MOSI 13
2224

2325
#if USE_TWO_ETH_PORTS
2426
// Second port on shared SPI bus
25-
#define ETH1_TYPE ETH_PHY_W5500
26-
#define ETH1_ADDR 1
27-
#define ETH1_CS 32
28-
#define ETH1_IRQ 33
29-
#define ETH1_RST 18
27+
#ifndef ETH1_PHY_TYPE
28+
#define ETH1_PHY_TYPE ETH_PHY_W5500
29+
#define ETH1_PHY_ADDR 1
30+
#define ETH1_PHY_CS 32
31+
#define ETH1_PHY_IRQ 33
32+
#define ETH1_PHY_RST 18
33+
#endif
3034
ETHClass ETH1(1);
3135
#endif
3236

@@ -94,9 +98,9 @@ void setup()
9498
WiFi.onEvent(onEvent);
9599

96100
SPI.begin(ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
97-
ETH.begin(ETH_TYPE, ETH_ADDR, ETH_CS, ETH_IRQ, ETH_RST, SPI);
101+
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, SPI);
98102
#if USE_TWO_ETH_PORTS
99-
ETH1.begin(ETH1_TYPE, ETH1_ADDR, ETH1_CS, ETH1_IRQ, ETH1_RST, SPI);
103+
ETH1.begin(ETH1_PHY_TYPE, ETH1_PHY_ADDR, ETH1_PHY_CS, ETH1_PHY_IRQ, ETH1_PHY_RST, SPI);
100104
#endif
101105
}
102106

Diff for: libraries/Ethernet/examples/ETH_W5500_IDF_SPI/ETH_W5500_IDF_SPI.ino

+20-16
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88
// Set this to 1 to enable dual Ethernet support
99
#define USE_TWO_ETH_PORTS 0
1010

11-
#define ETH_TYPE ETH_PHY_W5500
12-
#define ETH_ADDR 1
13-
#define ETH_CS 15
14-
#define ETH_IRQ 4
15-
#define ETH_RST 5
16-
#define ETH_SPI_HOST SPI2_HOST
17-
#define ETH_SPI_SCK 14
18-
#define ETH_SPI_MISO 12
19-
#define ETH_SPI_MOSI 13
11+
#ifndef ETH_PHY_TYPE
12+
#define ETH_PHY_TYPE ETH_PHY_W5500
13+
#define ETH_PHY_ADDR 1
14+
#define ETH_PHY_CS 15
15+
#define ETH_PHY_IRQ 4
16+
#define ETH_PHY_RST 5
17+
#define ETH_PHY_SPI_HOST SPI2_HOST
18+
#define ETH_PHY_SPI_SCK 14
19+
#define ETH_PHY_SPI_MISO 12
20+
#define ETH_PHY_SPI_MOSI 13
21+
#endif
2022

2123
#if USE_TWO_ETH_PORTS
2224
// Second port on shared SPI bus
23-
#define ETH1_TYPE ETH_PHY_W5500
24-
#define ETH1_ADDR 1
25-
#define ETH1_CS 32
26-
#define ETH1_IRQ 33
27-
#define ETH1_RST 18
25+
#ifndef ETH1_PHY_TYPE
26+
#define ETH1_PHY_TYPE ETH_PHY_W5500
27+
#define ETH1_PHY_ADDR 1
28+
#define ETH1_PHY_CS 32
29+
#define ETH1_PHY_IRQ 33
30+
#define ETH1_PHY_RST 18
31+
#endif
2832
ETHClass ETH1(1);
2933
#endif
3034

@@ -90,10 +94,10 @@ void setup()
9094
{
9195
Serial.begin(115200);
9296
WiFi.onEvent(onEvent);
93-
ETH.begin(ETH_TYPE, ETH_ADDR, ETH_CS, ETH_IRQ, ETH_RST, ETH_SPI_HOST, ETH_SPI_SCK, ETH_SPI_MISO, ETH_SPI_MOSI);
97+
ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_CS, ETH_PHY_IRQ, ETH_PHY_RST, ETH_PHY_SPI_HOST, ETH_PHY_SPI_SCK, ETH_PHY_SPI_MISO, ETH_PHY_SPI_MOSI);
9498
#if USE_TWO_ETH_PORTS
9599
// Since SPI bus is shared, we should skip the SPI pins when calling ETH1.begin()
96-
ETH1.begin(ETH1_TYPE, ETH1_ADDR, ETH1_CS, ETH1_IRQ, ETH1_RST, ETH_SPI_HOST);
100+
ETH1.begin(ETH1_PHY_TYPE, ETH1_PHY_ADDR, ETH1_PHY_CS, ETH1_PHY_IRQ, ETH1_PHY_RST, ETH_PHY_SPI_HOST);
97101
#endif
98102
}
99103

0 commit comments

Comments
 (0)