23
23
#include " utility/w5100.h"
24
24
#include " Dhcp.h"
25
25
26
+ #ifdef CONFIG_IDF_TARGET_ESP32
27
+ #ifdef ETH_USE_HSPI
28
+ SPIClass spiETH = SPIClass(HSPI);
29
+ #elif defined(ETH_USE_FSPI)
30
+ SPIClass spiETH = SPIClass(FSPI);
31
+ #else // use default VSPI port
32
+ SPIClass spiETH = SPIClass(VSPI);
33
+ #endif
34
+ #else
35
+ #ifdef ETH_USE_HSPI
36
+ SPIClass spiETH = SPIClass(HSPI);
37
+ #elif defined(ETH_USE_FSPI)
38
+ SPIClass spiETH = SPIClass(FSPI);
39
+ #else // use FSPI port
40
+ #ifdef ARDUINO_ARCH_SAMD
41
+ SPIClassSAMD spiETH = SPI;
42
+ #else
43
+ SPIClass spiETH = SPI;
44
+ #endif
45
+ #endif
46
+ #endif
47
+
26
48
IPAddress EthernetClass::_dnsServerAddress;
27
49
DhcpClass* EthernetClass::_dhcp = NULL ;
28
50
51
+ /* **************************************************************************************
52
+ ** Function name: getSPIinstance
53
+ ** Description: Get the instance of the SPI class
54
+ ***************************************************************************************/
55
+ #ifdef ARDUINO_ARCH_SAMD
56
+ SPIClassSAMD& EthernetClass::getSPIinstance (void )
57
+ {
58
+ return spiETH;
59
+ }
60
+ #else
61
+ SPIClass& EthernetClass::getSPIinstance (void )
62
+ {
63
+ return spiETH;
64
+ }
65
+ #endif
66
+
29
67
int EthernetClass::begin (uint8_t *mac, unsigned long timeout, unsigned long responseTimeout)
30
68
{
31
69
static DhcpClass s_dhcp;
32
70
_dhcp = &s_dhcp;
33
71
34
72
// Initialise the basic info
35
73
if (W5100.init () == 0 ) return 0 ;
36
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
74
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
37
75
W5100.setMACAddress (mac);
38
76
W5100.setIPAddress (IPAddress (0 ,0 ,0 ,0 ).raw_address ());
39
- SPI .endTransaction ();
77
+ spiETH .endTransaction ();
40
78
41
79
// Now try to get our config info from a DHCP server
42
80
int ret = _dhcp->beginWithDHCP (mac, timeout, responseTimeout);
43
81
if (ret == 1 ) {
44
82
// We've successfully found a DHCP server and got our configuration
45
83
// info, so set things accordingly
46
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
84
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
47
85
W5100.setIPAddress (_dhcp->getLocalIp ().raw_address ());
48
86
W5100.setGatewayIp (_dhcp->getGatewayIp ().raw_address ());
49
87
W5100.setSubnetMask (_dhcp->getSubnetMask ().raw_address ());
50
- SPI .endTransaction ();
88
+ spiETH .endTransaction ();
51
89
_dnsServerAddress = _dhcp->getDnsServerIp ();
52
90
socketPortRand (micros ());
53
91
}
@@ -81,7 +119,7 @@ void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress g
81
119
void EthernetClass::begin (uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet)
82
120
{
83
121
if (W5100.init () == 0 ) return ;
84
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
122
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
85
123
W5100.setMACAddress (mac);
86
124
#ifdef ESP8266
87
125
W5100.setIPAddress (&ip[0 ]);
@@ -96,7 +134,7 @@ void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress g
96
134
W5100.setGatewayIp (gateway._address );
97
135
W5100.setSubnetMask (subnet._address );
98
136
#endif
99
- SPI .endTransaction ();
137
+ spiETH .endTransaction ();
100
138
_dnsServerAddress = dns;
101
139
}
102
140
@@ -138,11 +176,11 @@ int EthernetClass::maintain()
138
176
case DHCP_CHECK_RENEW_OK:
139
177
case DHCP_CHECK_REBIND_OK:
140
178
// we might have got a new IP.
141
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
179
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
142
180
W5100.setIPAddress (_dhcp->getLocalIp ().raw_address ());
143
181
W5100.setGatewayIp (_dhcp->getGatewayIp ().raw_address ());
144
182
W5100.setSubnetMask (_dhcp->getSubnetMask ().raw_address ());
145
- SPI .endTransaction ();
183
+ spiETH .endTransaction ();
146
184
_dnsServerAddress = _dhcp->getDnsServerIp ();
147
185
break ;
148
186
default :
@@ -156,82 +194,82 @@ int EthernetClass::maintain()
156
194
157
195
void EthernetClass::MACAddress (uint8_t *mac_address)
158
196
{
159
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
197
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
160
198
W5100.getMACAddress (mac_address);
161
- SPI .endTransaction ();
199
+ spiETH .endTransaction ();
162
200
}
163
201
164
202
IPAddress EthernetClass::localIP ()
165
203
{
166
204
IPAddress ret;
167
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
205
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
168
206
W5100.getIPAddress (ret.raw_address ());
169
- SPI .endTransaction ();
207
+ spiETH .endTransaction ();
170
208
return ret;
171
209
}
172
210
173
211
IPAddress EthernetClass::subnetMask ()
174
212
{
175
213
IPAddress ret;
176
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
214
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
177
215
W5100.getSubnetMask (ret.raw_address ());
178
- SPI .endTransaction ();
216
+ spiETH .endTransaction ();
179
217
return ret;
180
218
}
181
219
182
220
IPAddress EthernetClass::gatewayIP ()
183
221
{
184
222
IPAddress ret;
185
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
223
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
186
224
W5100.getGatewayIp (ret.raw_address ());
187
- SPI .endTransaction ();
225
+ spiETH .endTransaction ();
188
226
return ret;
189
227
}
190
228
191
229
void EthernetClass::setMACAddress (const uint8_t *mac_address)
192
230
{
193
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
231
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
194
232
W5100.setMACAddress (mac_address);
195
- SPI .endTransaction ();
233
+ spiETH .endTransaction ();
196
234
}
197
235
198
236
void EthernetClass::setLocalIP (const IPAddress local_ip)
199
237
{
200
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
238
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
201
239
IPAddress ip = local_ip;
202
240
W5100.setIPAddress (ip.raw_address ());
203
- SPI .endTransaction ();
241
+ spiETH .endTransaction ();
204
242
}
205
243
206
244
void EthernetClass::setSubnetMask (const IPAddress subnet)
207
245
{
208
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
246
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
209
247
IPAddress ip = subnet;
210
248
W5100.setSubnetMask (ip.raw_address ());
211
- SPI .endTransaction ();
249
+ spiETH .endTransaction ();
212
250
}
213
251
214
252
void EthernetClass::setGatewayIP (const IPAddress gateway)
215
253
{
216
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
254
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
217
255
IPAddress ip = gateway;
218
256
W5100.setGatewayIp (ip.raw_address ());
219
- SPI .endTransaction ();
257
+ spiETH .endTransaction ();
220
258
}
221
259
222
260
void EthernetClass::setRetransmissionTimeout (uint16_t milliseconds)
223
261
{
224
262
if (milliseconds > 6553 ) milliseconds = 6553 ;
225
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
263
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
226
264
W5100.setRetransmissionTime (milliseconds * 10 );
227
- SPI .endTransaction ();
265
+ spiETH .endTransaction ();
228
266
}
229
267
230
268
void EthernetClass::setRetransmissionCount (uint8_t num)
231
269
{
232
- SPI .beginTransaction (SPI_ETHERNET_SETTINGS);
270
+ spiETH .beginTransaction (SPI_ETHERNET_SETTINGS);
233
271
W5100.setRetransmissionCount (num);
234
- SPI .endTransaction ();
272
+ spiETH .endTransaction ();
235
273
}
236
274
237
275
0 commit comments