Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 47e6ea1

Browse files
authored
v1.7.0 to use Ethernet_Generic library
### Releases v1.7.0 1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00. 2. Add support to `RP2040` using [`Earle Philhower's arduino-pico` core](https://github.com/earlephilhower/arduino-pico) with either `SPI0` or `SPI1` 3. Add support to WIZNet W5100S, such as [**WIZnet Ethernet HAT**](https://docs.wiznet.io/Product/Open-Source-Hardware/wiznet_ethernet_hat) and [**W5100S-EVB-Pico**](https://docs.wiznet.io/Product/iEthernet/W5100S/w5100s-evb-pico)
1 parent 07f3b6c commit 47e6ea1

File tree

46 files changed

+2518
-1279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2518
-1279
lines changed

examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/AVR_Ethernet_DuckDNS_Client.ino

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP)
3030
Serial.println(newIP);
3131
}
3232

33-
void setup()
33+
void initEthernet()
3434
{
35-
Serial.begin(115200);
36-
while (!Serial);
37-
38-
Serial.print("\nStart AVR_Ethernet_DuckDNS_Client on " + String(BOARD_NAME));
39-
Serial.println(" with " + String(SHIELD_TYPE));
40-
Serial.println(DDNS_GENERIC_VERSION);
41-
42-
// For other boards, to change if necessary
43-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
44-
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
45-
46-
Ethernet.init (USE_THIS_SS_PIN);
47-
48-
#elif USE_ETHERNET3
49-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
50-
#ifndef ETHERNET3_MAX_SOCK_NUM
51-
#define ETHERNET3_MAX_SOCK_NUM 4
52-
#endif
35+
#if USE_ETHERNET_GENERIC
36+
ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
37+
#elif USE_ETHERNET_ENC
38+
ET_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
39+
#elif USE_UIP_ETHERNET
40+
ET_LOGWARN(F("=========== USE_UIP_ETHERNET ==========="));
41+
#else
42+
ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ==========="));
43+
#endif
5344

54-
Ethernet.setCsPin (USE_THIS_SS_PIN);
55-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
45+
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
5646

57-
#endif //#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
47+
ET_LOGWARN(F("Default SPI pinout:"));
48+
ET_LOGWARN1(F("MOSI:"), MOSI);
49+
ET_LOGWARN1(F("MISO:"), MISO);
50+
ET_LOGWARN1(F("SCK:"), SCK);
51+
ET_LOGWARN1(F("SS:"), SS);
52+
ET_LOGWARN(F("========================="));
5853

54+
// For other boards, to change if necessary
55+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
56+
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
57+
Ethernet.init (USE_THIS_SS_PIN);
58+
59+
#elif USE_CUSTOM_ETHERNET
60+
// You have to add initialization for your Custom Ethernet here
61+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
62+
//Ethernet.init(USE_THIS_SS_PIN);
63+
64+
#endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
65+
5966
// start the ethernet connection and the server:
6067
// Use DHCP dynamic IP and random mac
6168
uint16_t index = millis() % NUMBER_OF_MAC;
6269
// Use Static IP
6370
//Ethernet.begin(mac[index], ip);
6471
Ethernet.begin(mac[index]);
72+
}
73+
74+
void setup()
75+
{
76+
Serial.begin(115200);
77+
while (!Serial && millis() < 5000);
78+
79+
Serial.print("\nStart AVR_Ethernet_DuckDNS_Client on " + String(BOARD_NAME));
80+
Serial.println(" with " + String(SHIELD_TYPE));
81+
Serial.println(DDNS_GENERIC_VERSION);
82+
83+
initEthernet();
6584

6685
Serial.print(F("\nHTTP WebServer is @ IP : "));
6786
Serial.println(Ethernet.localIP());

examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/defines.h

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -64,66 +64,73 @@
6464
// Select Ethernet Library for the Shield
6565
///////////////////////////////////////////
6666

67-
#define USE_UIP_ETHERNET false
68-
#define USE_CUSTOM_ETHERNET false
67+
#include <SPI.h>
68+
69+
// To override the default CS/SS pin. Don't use unless you know exactly which pin to use
70+
// You can define here or customize for each board at same place with BOARD_TYPE
71+
// Check @ defined(SEEED_XIAO_M0)
72+
//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15
6973

7074
// Only one if the following to be true
71-
#define USE_ETHERNET false
72-
#define USE_ETHERNET2 false //true
73-
#define USE_ETHERNET3 false //true
74-
#define USE_ETHERNET_LARGE true
75-
#define USE_ETHERNET_ESP8266 false //true
76-
#define USE_ETHERNET_ENC false
77-
78-
#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC )
75+
#define USE_ETHERNET_GENERIC true
76+
#define USE_ETHERNET_ESP8266 false
77+
#define USE_ETHERNET_ENC false
78+
#define USE_UIP_ETHERNET false
79+
#define USE_CUSTOM_ETHERNET false
80+
81+
////////////////////////////
82+
83+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET )
7984
#ifdef USE_CUSTOM_ETHERNET
8085
#undef USE_CUSTOM_ETHERNET
81-
#define USE_CUSTOM_ETHERNET false
8286
#endif
87+
#define USE_CUSTOM_ETHERNET false
8388
#endif
8489

85-
// Currently, only Ethernet lib available for STM32 using W5x00
86-
#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32)
87-
#if USE_ETHERNET3
88-
#include "Ethernet3.h"
89-
#warning Use Ethernet3 lib
90-
#define SHIELD_TYPE "W5x00 using Ethernet3 Library"
91-
#elif USE_ETHERNET2
92-
#include "Ethernet2.h"
93-
#warning Use Ethernet2 lib
94-
#define SHIELD_TYPE "W5x00 using Ethernet2 Library"
95-
#elif USE_ETHERNET_LARGE
96-
#include "EthernetLarge.h"
97-
#warning Use EthernetLarge lib
98-
#define SHIELD_TYPE "W5x00 using EthernetLarge Library"
99-
#elif USE_ETHERNET_ESP8266
100-
#include "Ethernet_ESP8266.h"
101-
#warning Use Ethernet_ESP8266 lib
102-
#define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library"
103-
#elif USE_ETHERNET_ENC
104-
#include "EthernetENC.h"
105-
#warning Use EthernetENC lib
106-
#define SHIELD_TYPE "ENC28J60 using EthernetENC Library"
107-
#elif USE_CUSTOM_ETHERNET
108-
#include "Ethernet_XYZ.h"
109-
#warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error.
110-
#define SHIELD_TYPE "using Custom Ethernet Library"
111-
#elif USE_UIP_ETHERNET
90+
#if USE_ETHERNET_GENERIC
91+
92+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI"
93+
94+
#define ETHERNET_LARGE_BUFFERS
95+
96+
#define _ETG_LOGLEVEL_ 1
97+
98+
#include "Ethernet_Generic.h"
99+
#warning Using Ethernet_Generic lib
100+
101+
#elif USE_ETHERNET_ENC
102+
#include "EthernetENC.h"
103+
#warning Using EthernetENC lib
104+
#define SHIELD_TYPE "ENC28J60 using EthernetENC Library"
105+
106+
#elif USE_CUSTOM_ETHERNET
107+
//#include "Ethernet_XYZ.h"
108+
#include "Ethernet.h"
109+
#warning Using Custom Ethernet library. You must include a library and initialize.
110+
#define SHIELD_TYPE "Custom Ethernet using Ethernet Library"
111+
112+
#elif USE_UIP_ETHERNET
112113
#include "UIPEthernet.h"
113-
#warning Use UIPEthernet library
114-
#define SHIELD_TYPE "ENC28J60 using UIPEthernet Library"
115-
#else
116-
#ifdef USE_ETHERNET
117-
#undef USE_ETHERNET
118-
#endif
119-
#define USE_ETHERNET true
120-
#include "Ethernet.h"
121-
#warning Use Ethernet lib
122-
#define SHIELD_TYPE "W5x00 using Ethernet Library"
123-
#endif
124-
#endif
114+
#warning Using UIPEthernet library
115+
#define SHIELD_TYPE "ENC28J60 using UIPEthernet Library"
116+
117+
#else
118+
#ifdef USE_ETHERNET_GENERIC
119+
#undef USE_ETHERNET_GENERIC
120+
#endif
121+
#define USE_ETHERNET_GENERIC true
122+
123+
#include "Ethernet_Generic.h"
124+
#warning Using default Ethernet_Generic lib
125+
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
125126

126-
/////////////////////////////////
127+
// Ethernet_Shield_W5200, EtherCard, EtherSia not supported
128+
// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET
129+
// Otherwise, standard Ethernet library will be used for W5x00
130+
131+
////////////////////////////
132+
133+
#endif // #if USE_ETHERNET_GENERIC
127134

128135
/////////////////////////////////
129136

examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/RP2040_Ethernet_DuckDNS_Client.ino

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP)
2828
Serial.println(newIP);
2929
}
3030

31-
void setup()
31+
void initEthernet()
3232
{
33-
Serial.begin(115200);
34-
while (!Serial);
35-
36-
Serial.print("\nStart RP2040_Ethernet_DuckDNS_Client on " + String(BOARD_NAME));
37-
Serial.println(" with " + String(SHIELD_TYPE));
38-
Serial.println(DDNS_GENERIC_VERSION);
39-
40-
// For other boards, to change if necessary
41-
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
42-
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
43-
44-
Ethernet.init (USE_THIS_SS_PIN);
45-
46-
#elif USE_ETHERNET3
47-
// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
48-
#ifndef ETHERNET3_MAX_SOCK_NUM
49-
#define ETHERNET3_MAX_SOCK_NUM 4
50-
#endif
33+
#if USE_ETHERNET_GENERIC
34+
ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
35+
#elif USE_ETHERNET_ENC
36+
ET_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
37+
#elif USE_UIP_ETHERNET
38+
ET_LOGWARN(F("=========== USE_UIP_ETHERNET ==========="));
39+
#else
40+
ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ==========="));
41+
#endif
5142

52-
Ethernet.setCsPin (USE_THIS_SS_PIN);
53-
Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
43+
ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
5444

55-
#endif //( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
45+
ET_LOGWARN(F("Default SPI pinout:"));
46+
ET_LOGWARN1(F("MOSI:"), MOSI);
47+
ET_LOGWARN1(F("MISO:"), MISO);
48+
ET_LOGWARN1(F("SCK:"), SCK);
49+
ET_LOGWARN1(F("SS:"), SS);
50+
ET_LOGWARN(F("========================="));
5651

52+
// For other boards, to change if necessary
53+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
54+
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
55+
Ethernet.init (USE_THIS_SS_PIN);
56+
57+
#elif USE_CUSTOM_ETHERNET
58+
// You have to add initialization for your Custom Ethernet here
59+
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
60+
//Ethernet.init(USE_THIS_SS_PIN);
61+
62+
#endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
63+
5764
// start the ethernet connection and the server:
5865
// Use DHCP dynamic IP and random mac
5966
uint16_t index = millis() % NUMBER_OF_MAC;
6067
// Use Static IP
6168
//Ethernet.begin(mac[index], ip);
6269
Ethernet.begin(mac[index]);
70+
}
71+
72+
void setup()
73+
{
74+
Serial.begin(115200);
75+
while (!Serial && millis() < 5000);
76+
77+
Serial.print("\nStart RP2040_Ethernet_DuckDNS_Client on " + String(BOARD_NAME));
78+
Serial.println(" with " + String(SHIELD_TYPE));
79+
Serial.println(DDNS_GENERIC_VERSION);
80+
81+
initEthernet();
6382

6483
Serial.print(F("\nHTTP WebServer is @ IP : "));
6584
Serial.println(Ethernet.localIP());

0 commit comments

Comments
 (0)