From 47e6ea1036bf88fdc3f5b55c5e112b1b729545d0 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Mon, 25 Apr 2022 03:29:00 -0400 Subject: [PATCH] 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) --- .../AVR_Ethernet_DuckDNS_Client.ino | 63 +- .../AVR/AVR_Ethernet_DuckDNS_Client/defines.h | 109 +-- .../RP2040_Ethernet_DuckDNS_Client.ino | 63 +- .../RP2040_Ethernet_DuckDNS_Client/defines.h | 187 +++-- .../SAM-DUE_Ethernet_DuckDNS_Client.ino | 63 +- .../SAM-DUE_Ethernet_DuckDNS_Client/defines.h | 109 +-- .../SAMD_Ethernet_DuckDNS_Client.ino | 63 +- .../SAMD_Ethernet_DuckDNS_Client/defines.h | 110 +-- .../STM32_Ethernet_DuckDNS_Client.ino | 63 +- .../STM32_Ethernet_DuckDNS_Client/defines.h | 41 +- .../Teensy_Ethernet_DuckDNS_Client.ino | 63 +- .../Teensy_Ethernet_DuckDNS_Client/defines.h | 111 +-- .../WT32_ETH01_DuckDNS_Client.ino | 2 +- .../megaAVR_Ethernet_DuckDNS_Client/defines.h | 109 +-- .../megaAVR_Ethernet_DuckDNS_Client.ino | 63 +- examples/Ethernet/multiFileProject/defines.h | 759 ++++++++++++++++++ .../multiFileProject/multiFileProject.cpp | 18 + .../multiFileProject/multiFileProject.h | 21 + .../multiFileProject/multiFileProject.ino | 36 + .../multiFileProject/wifi_credentials.h | 2 + .../nRF52_Ethernet_DuckDNS_Client/defines.h | 109 +-- .../nRF52_Ethernet_DuckDNS_Client.ino | 63 +- .../Generic/DuckDNS_Client/DuckDNS_Client.ino | 50 +- examples/Generic/DuckDNS_Client/defines.h | 80 +- .../Generic/DynDNS_Client/DynDNS_Client.ino | 52 +- examples/Generic/DynDNS_Client/defines.h | 80 +- examples/Generic/Dynu_Client/Dynu_Client.ino | 51 +- examples/Generic/Dynu_Client/defines.h | 80 +- .../Generic/No-ip_Client/No-ip_Client.ino | 51 +- examples/Generic/No-ip_Client/defines.h | 80 +- examples/Generic/OVH_Client/OVH_Client.ino | 51 +- examples/Generic/OVH_Client/defines.h | 80 +- .../afraid-org_Client/afraid-org_Client.ino | 50 +- examples/Generic/afraid-org_Client/defines.h | 80 +- .../all-inkl_Client/all-inkl_Client.ino | 50 +- examples/Generic/all-inkl_Client/defines.h | 80 +- examples/Generic/dyndns-it_Client/defines.h | 80 +- .../dyndns-it_Client/dyndns-it_Client.ino | 51 +- examples/Generic/enom_Client/defines.h | 80 +- examples/Generic/enom_Client/enom_Client.ino | 51 +- examples/Generic/freemyip_Client/defines.h | 80 +- .../freemyip_Client/freemyip_Client.ino | 50 +- examples/Generic/selfhost-de_Client/defines.h | 80 +- .../selfhost-de_Client/selfhost-de_Client.ino | 51 +- examples/Generic/strato_Client/defines.h | 80 +- .../Generic/strato_Client/strato_Client.ino | 52 +- 46 files changed, 2518 insertions(+), 1279 deletions(-) create mode 100644 examples/Ethernet/multiFileProject/defines.h create mode 100644 examples/Ethernet/multiFileProject/multiFileProject.cpp create mode 100644 examples/Ethernet/multiFileProject/multiFileProject.h create mode 100644 examples/Ethernet/multiFileProject/multiFileProject.ino create mode 100644 examples/Ethernet/multiFileProject/wifi_credentials.h diff --git a/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/AVR_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/AVR_Ethernet_DuckDNS_Client.ino index 12f1332..3c79f94 100644 --- a/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/AVR_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/AVR_Ethernet_DuckDNS_Client.ino @@ -30,38 +30,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart AVR_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + #if USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); -#endif //#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + //Ethernet.init(USE_THIS_SS_PIN); + + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // start the ethernet connection and the server: // Use DHCP dynamic IP and random mac uint16_t index = millis() % NUMBER_OF_MAC; // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print("\nStart AVR_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + + initEthernet(); Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/defines.h index 9074f78..00547f8 100644 --- a/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/defines.h @@ -64,66 +64,73 @@ // Select Ethernet Library for the Shield /////////////////////////////////////////// -#define USE_UIP_ETHERNET false -#define USE_CUSTOM_ETHERNET false +#include + +// To override the default CS/SS pin. Don't use unless you know exactly which pin to use +// You can define here or customize for each board at same place with BOARD_TYPE +// Check @ defined(SEEED_XIAO_M0) +//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15 // Only one if the following to be true -#define USE_ETHERNET false -#define USE_ETHERNET2 false //true -#define USE_ETHERNET3 false //true -#define USE_ETHERNET_LARGE true -#define USE_ETHERNET_ESP8266 false //true -#define USE_ETHERNET_ENC false - -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) +#define USE_ETHERNET_GENERIC true +#define USE_ETHERNET_ESP8266 false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + + //////////////////////////// + +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET - #define USE_CUSTOM_ETHERNET false #endif + #define USE_CUSTOM_ETHERNET false #endif -// Currently, only Ethernet lib available for STM32 using W5x00 -#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) - #if USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" - #elif USE_ETHERNET_ESP8266 - #include "Ethernet_ESP8266.h" - #warning Use Ethernet_ESP8266 lib - #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" - #elif USE_ETHERNET_ENC - #include "EthernetENC.h" - #warning Use EthernetENC lib - #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" - #elif USE_CUSTOM_ETHERNET - #include "Ethernet_XYZ.h" - #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. - #define SHIELD_TYPE "using Custom Ethernet Library" - #elif USE_UIP_ETHERNET +#if USE_ETHERNET_GENERIC + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI" + + #define ETHERNET_LARGE_BUFFERS + + #define _ETG_LOGLEVEL_ 1 + + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + +#elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Using EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + +#elif USE_CUSTOM_ETHERNET + //#include "Ethernet_XYZ.h" + #include "Ethernet.h" + #warning Using Custom Ethernet library. You must include a library and initialize. + #define SHIELD_TYPE "Custom Ethernet using Ethernet Library" + +#elif USE_UIP_ETHERNET #include "UIPEthernet.h" - #warning Use UIPEthernet library - #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" - #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" - #endif -#endif + #warning Using UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + +#else + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" -///////////////////////////////// +// Ethernet_Shield_W5200, EtherCard, EtherSia not supported +// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET +// Otherwise, standard Ethernet library will be used for W5x00 + + //////////////////////////// + +#endif // #if USE_ETHERNET_GENERIC ///////////////////////////////// diff --git a/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/RP2040_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/RP2040_Ethernet_DuckDNS_Client.ino index 470f0e8..9849b57 100644 --- a/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/RP2040_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/RP2040_Ethernet_DuckDNS_Client.ino @@ -28,38 +28,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart RP2040_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + #if USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); -#endif //( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + //Ethernet.init(USE_THIS_SS_PIN); + + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // start the ethernet connection and the server: // Use DHCP dynamic IP and random mac uint16_t index = millis() % NUMBER_OF_MAC; // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print("\nStart RP2040_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + + initEthernet(); Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/defines.h index c72d0d0..beb7ab7 100644 --- a/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/RP2040/RP2040_Ethernet_DuckDNS_Client/defines.h @@ -28,10 +28,11 @@ ///////////////////////////////// -#if !( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) +#if !( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || \ + defined(ARDUINO_GENERIC_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) ) #error This code is intended to run only on the RP2040-based boards ! Please check your Tools->Board setting. -#elif !defined(ARDUINO_ARCH_MBED) - #error Only ARDUINO_ARCH_MBED supported on the RP2040-based boards ! Please check your Tools->Board setting. +//#elif !defined(ARDUINO_ARCH_MBED) +// #error Only ARDUINO_ARCH_MBED supported on the RP2040-based boards ! Please check your Tools->Board setting. #endif ///////////////////////////////// @@ -40,94 +41,137 @@ #undef ETHERNET_USE_RP2040 #endif -#define ETHERNET_USE_RP2040 true -#warning Use RP2040 architecture with Ethernet +#define ETHERNET_USE_RP2040 true -// Default pin 5 to SS/CS -#define USE_THIS_SS_PIN 5 +#if defined(ETHERNET_USE_RPIPICO) + #undef ETHERNET_USE_RPIPICO +#endif +#define ETHERNET_USE_RPIPICO true + +#warning Use RP2040 architecture with Ethernet ///////////////////////////////// + +#if ETHERNET_USE_RPIPICO -#if defined(ARDUINO_ARCH_MBED) - #if defined(BOARD_NAME) - #undef BOARD_NAME - #endif - - #if defined(ARDUINO_RASPBERRY_PI_PICO) - #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" - #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) - #define BOARD_TYPE "MBED DAFRUIT_FEATHER_RP2040" - #elif defined(ARDUINO_GENERIC_RP2040) - #define BOARD_TYPE "MBED GENERIC_RP2040" + // Default pin 5 (in Mbed) or 17 to SS/CS + #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + + #if defined(BOARD_NAME) + #undef BOARD_NAME + #endif + + #if defined(ARDUINO_RASPBERRY_PI_PICO) + #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" + #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) + #define BOARD_TYPE "MBED DAFRUIT_FEATHER_RP2040" + #elif defined(ARDUINO_GENERIC_RP2040) + #define BOARD_TYPE "MBED GENERIC_RP2040" + #else + #define BOARD_TYPE "MBED Unknown RP2040" + #endif + #else - #define BOARD_TYPE "MBED Unknown RP2040" + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + #endif -#endif //ARDUINO_ARCH_RP2040 + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture + +#endif + +#ifndef BOARD_NAME + #define BOARD_NAME BOARD_TYPE +#endif /////////////////////////////////////////// // Select Ethernet Library for the Shield /////////////////////////////////////////// -#define USE_UIP_ETHERNET false -#define USE_CUSTOM_ETHERNET false +#include + +// To override the default CS/SS pin. Don't use unless you know exactly which pin to use +// You can define here or customize for each board at same place with BOARD_TYPE +// Check @ defined(SEEED_XIAO_M0) +//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15 // Only one if the following to be true -#define USE_ETHERNET false -#define USE_ETHERNET2 false //true -#define USE_ETHERNET3 false //true -#define USE_ETHERNET_LARGE true -#define USE_ETHERNET_ESP8266 false //true -#define USE_ETHERNET_ENC false - -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) +#define USE_ETHERNET_GENERIC true +#define USE_ETHERNET_ESP8266 false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + + //////////////////////////// + +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET - #define USE_CUSTOM_ETHERNET false #endif + #define USE_CUSTOM_ETHERNET false #endif -// Currently, only Ethernet lib available for STM32 using W5x00 -#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) - #if USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" - #elif USE_ETHERNET_ESP8266 - #include "Ethernet_ESP8266.h" - #warning Use Ethernet_ESP8266 lib - #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" - #elif USE_ETHERNET_ENC - #include "EthernetENC.h" - #warning Use EthernetENC lib - #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" - #elif USE_CUSTOM_ETHERNET - #include "Ethernet_XYZ.h" - #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. - #define SHIELD_TYPE "using Custom Ethernet Library" - #elif USE_UIP_ETHERNET +#if USE_ETHERNET_GENERIC + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI" + + #define ETHERNET_LARGE_BUFFERS + + #define _ETG_LOGLEVEL_ 1 + + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + +#elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Using EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + +#elif USE_CUSTOM_ETHERNET + //#include "Ethernet_XYZ.h" + #include "Ethernet.h" + #warning Using Custom Ethernet library. You must include a library and initialize. + #define SHIELD_TYPE "Custom Ethernet using Ethernet Library" + +#elif USE_UIP_ETHERNET #include "UIPEthernet.h" - #warning Use UIPEthernet library - #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" - #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" - #endif -#endif + #warning Using UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + +#else + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" -///////////////////////////////// +// Ethernet_Shield_W5200, EtherCard, EtherSia not supported +// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET +// Otherwise, standard Ethernet library will be used for W5x00 + + //////////////////////////// + +#endif // #if USE_ETHERNET_GENERIC ///////////////////////////////// @@ -144,7 +188,6 @@ #endif ///////////////////////////////// - #include #include diff --git a/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/SAM-DUE_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/SAM-DUE_Ethernet_DuckDNS_Client.ino index 41564d7..7f7f935 100644 --- a/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/SAM-DUE_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/SAM-DUE_Ethernet_DuckDNS_Client.ino @@ -28,38 +28,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart SAM-DUE_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + #if USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); -#endif //#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + //Ethernet.init(USE_THIS_SS_PIN); + + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // start the ethernet connection and the server: // Use DHCP dynamic IP and random mac uint16_t index = millis() % NUMBER_OF_MAC; // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print("\nStart SAM-DUE_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + + initEthernet(); Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/defines.h index bd73923..2161c47 100644 --- a/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/SAM-DUE/SAM-DUE_Ethernet_DuckDNS_Client/defines.h @@ -57,66 +57,73 @@ // Select Ethernet Library for the Shield /////////////////////////////////////////// -#define USE_UIP_ETHERNET false -#define USE_CUSTOM_ETHERNET false +#include + +// To override the default CS/SS pin. Don't use unless you know exactly which pin to use +// You can define here or customize for each board at same place with BOARD_TYPE +// Check @ defined(SEEED_XIAO_M0) +//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15 // Only one if the following to be true -#define USE_ETHERNET false -#define USE_ETHERNET2 false //true -#define USE_ETHERNET3 false //true -#define USE_ETHERNET_LARGE true -#define USE_ETHERNET_ESP8266 false //true -#define USE_ETHERNET_ENC false - -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) +#define USE_ETHERNET_GENERIC true +#define USE_ETHERNET_ESP8266 false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + + //////////////////////////// + +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET - #define USE_CUSTOM_ETHERNET false #endif + #define USE_CUSTOM_ETHERNET false #endif -// Currently, only Ethernet lib available for STM32 using W5x00 -#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) - #if USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" - #elif USE_ETHERNET_ESP8266 - #include "Ethernet_ESP8266.h" - #warning Use Ethernet_ESP8266 lib - #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" - #elif USE_ETHERNET_ENC - #include "EthernetENC.h" - #warning Use EthernetENC lib - #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" - #elif USE_CUSTOM_ETHERNET - #include "Ethernet_XYZ.h" - #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. - #define SHIELD_TYPE "using Custom Ethernet Library" - #elif USE_UIP_ETHERNET +#if USE_ETHERNET_GENERIC + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI" + + #define ETHERNET_LARGE_BUFFERS + + #define _ETG_LOGLEVEL_ 1 + + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + +#elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Using EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + +#elif USE_CUSTOM_ETHERNET + //#include "Ethernet_XYZ.h" + #include "Ethernet.h" + #warning Using Custom Ethernet library. You must include a library and initialize. + #define SHIELD_TYPE "Custom Ethernet using Ethernet Library" + +#elif USE_UIP_ETHERNET #include "UIPEthernet.h" - #warning Use UIPEthernet library - #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" - #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" - #endif -#endif + #warning Using UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + +#else + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" -///////////////////////////////// +// Ethernet_Shield_W5200, EtherCard, EtherSia not supported +// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET +// Otherwise, standard Ethernet library will be used for W5x00 + + //////////////////////////// + +#endif // #if USE_ETHERNET_GENERIC ///////////////////////////////// diff --git a/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/SAMD_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/SAMD_Ethernet_DuckDNS_Client.ino index ae3d395..e134c70 100644 --- a/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/SAMD_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/SAMD_Ethernet_DuckDNS_Client.ino @@ -28,38 +28,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart SAMD_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + #if USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); -#endif //#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + //Ethernet.init(USE_THIS_SS_PIN); + + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // start the ethernet connection and the server: // Use DHCP dynamic IP and random mac uint16_t index = millis() % NUMBER_OF_MAC; // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print("\nStart SAMD_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + + initEthernet(); Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/defines.h index 13ca0b0..9b9daa2 100644 --- a/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/SAMD/SAMD_Ethernet_DuckDNS_Client/defines.h @@ -161,65 +161,73 @@ // Select Ethernet Library for the Shield /////////////////////////////////////////// -#define USE_UIP_ETHERNET false -#define USE_CUSTOM_ETHERNET false +#include + +// To override the default CS/SS pin. Don't use unless you know exactly which pin to use +// You can define here or customize for each board at same place with BOARD_TYPE +// Check @ defined(SEEED_XIAO_M0) +//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15 // Only one if the following to be true -#define USE_ETHERNET false -#define USE_ETHERNET2 false //true -#define USE_ETHERNET3 false //true -#define USE_ETHERNET_LARGE true -#define USE_ETHERNET_ESP8266 false //true -#define USE_ETHERNET_ENC false - -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) +#define USE_ETHERNET_GENERIC true +#define USE_ETHERNET_ESP8266 false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + + //////////////////////////// + +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET - #define USE_CUSTOM_ETHERNET false #endif + #define USE_CUSTOM_ETHERNET false #endif -// Currently, only Ethernet lib available for STM32 using W5x00 -#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) - #if USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" - #elif USE_ETHERNET_ESP8266 - #include "Ethernet_ESP8266.h" - #warning Use Ethernet_ESP8266 lib - #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" - #elif USE_ETHERNET_ENC - #include "EthernetENC.h" - #warning Use EthernetENC lib - #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" - #elif USE_CUSTOM_ETHERNET - #include "Ethernet_XYZ.h" - #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. - #define SHIELD_TYPE "using Custom Ethernet Library" - #elif USE_UIP_ETHERNET +#if USE_ETHERNET_GENERIC + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI" + + #define ETHERNET_LARGE_BUFFERS + + #define _ETG_LOGLEVEL_ 1 + + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + +#elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Using EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + +#elif USE_CUSTOM_ETHERNET + //#include "Ethernet_XYZ.h" + #include "Ethernet.h" + #warning Using Custom Ethernet library. You must include a library and initialize. + #define SHIELD_TYPE "Custom Ethernet using Ethernet Library" + +#elif USE_UIP_ETHERNET #include "UIPEthernet.h" - #warning Use UIPEthernet library - #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" - #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" - #endif -#endif -///////////////////////////////// + #warning Using UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + +#else + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" + +// Ethernet_Shield_W5200, EtherCard, EtherSia not supported +// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET +// Otherwise, standard Ethernet library will be used for W5x00 + + //////////////////////////// + +#endif // #if USE_ETHERNET_GENERIC ///////////////////////////////// diff --git a/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/STM32_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/STM32_Ethernet_DuckDNS_Client.ino index fc30857..55acade 100644 --- a/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/STM32_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/STM32_Ethernet_DuckDNS_Client.ino @@ -24,45 +24,42 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart STM32_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); +#if USE_BUILTIN_ETHERNET + ET_LOGWARN(F("=========== USE_BUILTIN_ETHERNET ===========")); +#elif USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); + #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) - ET_LOGWARN(F("Default SPI pinout:")); - ET_LOGWARN1(F("MOSI:"), MOSI); - ET_LOGWARN1(F("MISO:"), MISO); - ET_LOGWARN1(F("SCK:"), SCK); - ET_LOGWARN1(F("SS:"), SS); - ET_LOGWARN(F("=========================")); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); - #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary - #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries Ethernet.init (USE_THIS_SS_PIN); - - #elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - + #elif USE_CUSTOM_ETHERNET // You have to add initialization for your Custom Ethernet here // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough //Ethernet.init(USE_THIS_SS_PIN); - #endif //( ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) #endif // start the ethernet connection and the server: @@ -71,6 +68,18 @@ void setup() // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial); + + Serial.print("\nStart STM32_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/defines.h index 81cf74b..1618e67 100644 --- a/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/STM32/STM32_Ethernet_DuckDNS_Client/defines.h @@ -56,16 +56,14 @@ #if !(USE_BUILTIN_ETHERNET || USE_UIP_ETHERNET) // Only one if the following to be true - #define USE_ETHERNET false //true - #define USE_ETHERNET2 true //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE false - #define USE_ETHERNET_ESP8266 false //true + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false #define USE_CUSTOM_ETHERNET false #endif -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #endif @@ -78,18 +76,13 @@ #elif (USE_UIP_ETHERNET) #warning Using ENC28J60 & UIPEthernet lib #define SHIELD_TYPE "ENC28J60 & UIPEthernet Library" -#elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Using W5x00 & Ethernet3 lib - #define SHIELD_TYPE "W5x00 & Ethernet3 Library" -#elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Using W5x00 & Ethernet2 lib - #define SHIELD_TYPE "W5x00 & Ethernet2 Library" -#elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Using W5x00 & EthernetLarge lib - #define SHIELD_TYPE "W5x00 & EthernetLarge Library" +#elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using W5x00 & Ethernet_Generic lib + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Using W5x00 & Ethernet_ESP8266 lib @@ -104,10 +97,14 @@ #warning Using Custom Ethernet library. You must include a library and initialize. #define SHIELD_TYPE "Custom Ethernet & Ethernet_XYZ Library" #else - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Using Ethernet lib - #define SHIELD_TYPE "W5x00 & Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #if defined(STM32F0) diff --git a/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/Teensy_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/Teensy_Ethernet_DuckDNS_Client.ino index 3be59ba..55a556c 100644 --- a/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/Teensy_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/Teensy_Ethernet_DuckDNS_Client.ino @@ -30,39 +30,58 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart Teensy_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + #if USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); -#endif //#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + //Ethernet.init(USE_THIS_SS_PIN); + + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // start the ethernet connection and the server: // Use DHCP dynamic IP and random mac uint16_t index = millis() % NUMBER_OF_MAC; // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print("\nStart Teensy_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + initEthernet(); + Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/defines.h index 2a9f95a..1310acd 100644 --- a/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/Teensy/Teensy_Ethernet_DuckDNS_Client/defines.h @@ -89,70 +89,73 @@ // Select Ethernet Library for the Shield /////////////////////////////////////////// -#define USE_UIP_ETHERNET false -#define USE_CUSTOM_ETHERNET false +#include + +// To override the default CS/SS pin. Don't use unless you know exactly which pin to use +// You can define here or customize for each board at same place with BOARD_TYPE +// Check @ defined(SEEED_XIAO_M0) +//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15 // Only one if the following to be true -#define USE_ETHERNET false -#define USE_ETHERNET2 false //true -#define USE_ETHERNET3 false //true -#define USE_ETHERNET_LARGE true -#define USE_ETHERNET_ESP8266 false //true -#define USE_ETHERNET_ENC false - -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) +#define USE_ETHERNET_GENERIC true +#define USE_ETHERNET_ESP8266 false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + + //////////////////////////// + +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #endif #define USE_CUSTOM_ETHERNET false #endif -// Currently, only Ethernet lib available for STM32 using W5x00 -#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) - #if USE_NATIVE_ETHERNET - #include "NativeEthernet.h" - #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error - #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" - #elif USE_ETHERNET_ESP8266 - #include "Ethernet_ESP8266.h" - #warning Use Ethernet_ESP8266 lib - #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" - #elif USE_ETHERNET_ENC - #include "EthernetENC.h" - #warning Use EthernetENC lib - #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" - #elif USE_CUSTOM_ETHERNET - #include "Ethernet_XYZ.h" - #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. - #define SHIELD_TYPE "using Custom Ethernet Library" - #elif USE_UIP_ETHERNET +#if USE_ETHERNET_GENERIC + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI" + + #define ETHERNET_LARGE_BUFFERS + + #define _ETG_LOGLEVEL_ 1 + + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + +#elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Using EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + +#elif USE_CUSTOM_ETHERNET + //#include "Ethernet_XYZ.h" + #include "Ethernet.h" + #warning Using Custom Ethernet library. You must include a library and initialize. + #define SHIELD_TYPE "Custom Ethernet using Ethernet Library" + +#elif USE_UIP_ETHERNET #include "UIPEthernet.h" - #warning Use UIPEthernet library - #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" - #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" - #endif -#endif + #warning Using UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + +#else + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" -///////////////////////////////// +// Ethernet_Shield_W5200, EtherCard, EtherSia not supported +// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET +// Otherwise, standard Ethernet library will be used for W5x00 + + //////////////////////////// + +#endif // #if USE_ETHERNET_GENERIC ///////////////////////////////// diff --git a/examples/Ethernet/WT32_ETH01/WT32_ETH01_DuckDNS_Client/WT32_ETH01_DuckDNS_Client.ino b/examples/Ethernet/WT32_ETH01/WT32_ETH01_DuckDNS_Client/WT32_ETH01_DuckDNS_Client.ino index 68b5245..d501196 100644 --- a/examples/Ethernet/WT32_ETH01/WT32_ETH01_DuckDNS_Client/WT32_ETH01_DuckDNS_Client.ino +++ b/examples/Ethernet/WT32_ETH01/WT32_ETH01_DuckDNS_Client/WT32_ETH01_DuckDNS_Client.ino @@ -31,7 +31,7 @@ void onUpdateCallback(const char* oldIP, const char* newIP) void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000); Serial.print(F("\nStart WT32_ETH01_DuckDNS_Client on ")); Serial.print(BOARD_NAME); Serial.print(F(" with ")); Serial.println(SHIELD_TYPE); diff --git a/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/defines.h index aa1a11b..a259586 100644 --- a/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/defines.h @@ -64,66 +64,73 @@ // Select Ethernet Library for the Shield /////////////////////////////////////////// -#define USE_UIP_ETHERNET false -#define USE_CUSTOM_ETHERNET false +#include + +// To override the default CS/SS pin. Don't use unless you know exactly which pin to use +// You can define here or customize for each board at same place with BOARD_TYPE +// Check @ defined(SEEED_XIAO_M0) +//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15 // Only one if the following to be true -#define USE_ETHERNET false -#define USE_ETHERNET2 false //true -#define USE_ETHERNET3 false //true -#define USE_ETHERNET_LARGE true -#define USE_ETHERNET_ESP8266 false //true -#define USE_ETHERNET_ENC false - -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) +#define USE_ETHERNET_GENERIC true +#define USE_ETHERNET_ESP8266 false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + + //////////////////////////// + +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET - #define USE_CUSTOM_ETHERNET false #endif + #define USE_CUSTOM_ETHERNET false #endif -// Currently, only Ethernet lib available for STM32 using W5x00 -#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) - #if USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" - #elif USE_ETHERNET_ESP8266 - #include "Ethernet_ESP8266.h" - #warning Use Ethernet_ESP8266 lib - #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" - #elif USE_ETHERNET_ENC - #include "EthernetENC.h" - #warning Use EthernetENC lib - #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" - #elif USE_CUSTOM_ETHERNET - #include "Ethernet_XYZ.h" - #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. - #define SHIELD_TYPE "using Custom Ethernet Library" - #elif USE_UIP_ETHERNET +#if USE_ETHERNET_GENERIC + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI" + + #define ETHERNET_LARGE_BUFFERS + + #define _ETG_LOGLEVEL_ 1 + + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + +#elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Using EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + +#elif USE_CUSTOM_ETHERNET + //#include "Ethernet_XYZ.h" + #include "Ethernet.h" + #warning Using Custom Ethernet library. You must include a library and initialize. + #define SHIELD_TYPE "Custom Ethernet using Ethernet Library" + +#elif USE_UIP_ETHERNET #include "UIPEthernet.h" - #warning Use UIPEthernet library - #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" - #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" - #endif -#endif + #warning Using UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + +#else + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" -///////////////////////////////// +// Ethernet_Shield_W5200, EtherCard, EtherSia not supported +// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET +// Otherwise, standard Ethernet library will be used for W5x00 + + //////////////////////////// + +#endif // #if USE_ETHERNET_GENERIC ///////////////////////////////// diff --git a/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/megaAVR_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/megaAVR_Ethernet_DuckDNS_Client.ino index b71aa5f..d2fed06 100644 --- a/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/megaAVR_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/megaAVR/megaAVR_Ethernet_DuckDNS_Client/megaAVR_Ethernet_DuckDNS_Client.ino @@ -28,38 +28,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart megaAVR_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + #if USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); -#endif //#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + //Ethernet.init(USE_THIS_SS_PIN); + + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // start the ethernet connection and the server: // Use DHCP dynamic IP and random mac uint16_t index = millis() % NUMBER_OF_MAC; // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print("\nStart megaAVR_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + + initEthernet(); Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Ethernet/multiFileProject/defines.h b/examples/Ethernet/multiFileProject/defines.h new file mode 100644 index 0000000..f25bc40 --- /dev/null +++ b/examples/Ethernet/multiFileProject/defines.h @@ -0,0 +1,759 @@ +/**************************************************************************************************************************** + defines.h + + For all Generic boards such as ESP8266, ESP32, SAM DUE, SAMD21/SAMD51, nRF52, STM32F/L/H/G/WB/MP1, AVR, megaAVR, Teensy + with WiFiNINA, ESP8266/ESP32 WiFi, ESP8266-AT, W5x00, ENC28J60, built-in Ethernet LAN8742A, WT32_ETH01 + + DDNS_Generic is a library to update DDNS IP address for DDNS services such as + duckdns, noip, dyndns, dynu, enom, all-inkl, selfhost.de, dyndns.it, strato, freemyip, afraid.org, ovh.com + + Based on and modified from + 1) EasyDDNS (/~https://github.com/ayushsharma82/EasyDDNS) + 2) ArduinoHttpClient (/~https://github.com/arduino-libraries/ArduinoHttpClient) + + Built by Khoi Hoang /~https://github.com/khoih-prog/DDNS_Generic + + Licensed under MIT license + *****************************************************************************************************************************/ + +#ifndef defines_h +#define defines_h + +#define DEBUG_WIFI_WEBSERVER_PORT Serial + +// Debug Level from 0 to 4 +#define _WIFI_LOGLEVEL_ 4 +#define _WIFININA_LOGLEVEL_ 4 +#define _DDNS_GENERIC_LOGLEVEL_ 2 + +// Select DDNS_USING_WIFI for boards using built-in WiFi, such as Nano-33-IoT +#define DDNS_USING_WIFI false +#define DDNS_USING_ETHERNET true + +///////////////////////////////// + +#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \ + defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \ + defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) + + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_NRF528XX) + #undef WIFI_USE_NRF528XX + #endif + #define WIFI_USE_NRF528XX true + #warning Use NRF52 architecture with WiFi + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_NRF528XX) + #undef ETHERNET_USE_NRF528XX + #endif + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define ETHERNET_USE_NRF528XX true + #warning Use NRF52 architecture with Ethernet + #endif + +#endif + +///////////////////////////////// + +#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) + + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_RP2040) + #undef WIFI_USE_RP2040 + #endif + #define WIFI_USE_RP2040 true + + #if !defined(ARDUINO_ARCH_MBED) + #warning Use RP2040 architecture with WiFi + #else + #error ARDUINO_ARCH_MBED WiFi not supported yet on the RP2040-based boards ! Please check your Tools->Board setting. + #endif + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_RP2040) + #undef ETHERNET_USE_RP2040 + #endif + // Default pin 5 to SS/CS + #define USE_THIS_SS_PIN 5 + #define ETHERNET_USE_RP2040 true + + #if defined(ARDUINO_ARCH_MBED) + #warning Use MBED RP2040 architecture with Ethernet + #else + #warning Use RP2040 architecture with Ethernet + //#error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. + #endif + #endif + +#endif + +///////////////////////////////// + +#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \ + || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \ + || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \ + || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD21E18A__) || defined(__SAMD51__) || defined(__SAMD51J20A__) || defined(__SAMD51J19A__) \ + || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) || defined(__SAMD21G18A__) ) + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_SAMD) + #undef WIFI_USE_SAMD + #endif + #define WIFI_USE_SAMD true + #warning Use SAMD architecture with WiFi + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_SAMD) + #undef ETHERNET_USE_SAMD + #endif + // For SAMD + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define ETHERNET_USE_SAMD true + #warning Use SAMD architecture with Ethernet + #endif + +#endif + +///////////////////////////////// + +#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_SAM_DUE) + #undef WIFI_USE_SAM_DUE + #endif + #define WIFI_USE_SAM_DUE true + #warning Use SAM_DUE architecture with WiFi + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_SAM_DUE) + #undef ETHERNET_USE_SAM_DUE + #endif + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define ETHERNET_USE_SAM_DUE true + #warning Use SAM_DUE architecture with Ethernet + #endif +#endif + +///////////////////////////////// + +#if ( defined(__AVR_ATmega2560__) ) + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_AVR) + #undef WIFI_USE_AVR + #endif + #define WIFI_USE_AVR true + #warning Use AVR architecture with WiFi + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_AVR) + #undef ETHERNET_USE_AVR + #endif + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define ETHERNET_USE_AVR true + #warning Use AVR architecture with Ethernet + #endif +#endif + +#if ( defined(CORE_TEENSY) ) + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_TEENSY) + #undef WIFI_USE_TEENSY + #endif + #define WIFI_USE_TEENSY true + #warning Use Teensy architecture with WiFi + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_TEENSY) + #undef ETHERNET_USE_TEENSY + #endif + #define ETHERNET_USE_TEENSY true + #warning Use Teensy architecture with Ethernet + #endif +#endif + +///////////////////////////////// + +#if ( defined(__AVR_ATmega4809__) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) ) + + // Default WiFiNINA for UNO WiFi Rev2 + #if defined(ARDUINO_AVR_UNO_WIFI_REV2) + #if !(DDNS_USING_WIFI) + #undef DDNS_USING_WIFI + #define DDNS_USING_WIFI true + #endif + #if (DDNS_USING_ETHERNET) + #undef DDNS_USING_ETHERNET + #define DDNS_USING_ETHERNET false + #endif + #endif + + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_MEGA_AVR) + #undef WIFI_USE_MEGA_AVR + #endif + #define WIFI_USE_MEGA_AVR true + #warning Use megaAVR architecture with WiFi + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_MEGA_AVR) + #undef ETHERNET_USE_MEGA_AVR + #endif + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define ETHERNET_USE_MEGA_AVR true + #warning Use megaAVR architecture with Ethernet + #endif +#endif + +///////////////////////////////// + +#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \ + defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \ + defined(STM32WB) || defined(STM32MP1) ) + + #if (DDNS_USING_WIFI) + #if defined(WIFI_USE_STM32) + #undef WIFI_USE_STM32 + #endif + #define WIFI_USE_STM32 true + #warning Use STM32 architecture with WiFi + #elif DDNS_USING_ETHERNET + #if defined(ETHERNET_USE_STM32) + #undef ETHERNET_USE_STM32 + #endif + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define ETHERNET_USE_STM32 true + #warning Use STM32 architecture with Ethernet + #endif + +#endif + +///////////////////////////////// + +#ifdef CORE_TEENSY + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define EspSerial Serial2 //Serial2, Pin RX2 : 7, TX2 : 8 + + #if defined(__IMXRT1062__) + // For Teensy 4.1/4.0 + #if defined(ARDUINO_TEENSY41) + #define BOARD_TYPE "TEENSY 4.1" + // Use true for NativeEthernet Library, false if using other Ethernet libraries + #define USE_NATIVE_ETHERNET true + #elif defined(ARDUINO_TEENSY40) + #define BOARD_TYPE "TEENSY 4.0" + #else + #define BOARD_TYPE "TEENSY 4.x" + #endif + #elif defined(__MK66FX1M0__) + #define BOARD_TYPE "Teensy 3.6" + #elif defined(__MK64FX512__) + #define BOARD_TYPE "Teensy 3.5" + #elif defined(__MKL26Z64__) + #define BOARD_TYPE "Teensy LC" + #elif defined(__MK20DX256__) + #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete) + #elif defined(__MK20DX128__) + #define BOARD_TYPE "Teensy 3.0" + #elif defined(__AVR_AT90USB1286__) + #error Teensy 2.0++ not supported yet + #elif defined(__AVR_ATmega32U4__) + #error Teensy 2.0 not supported yet + #else + // For Other Boards + #define BOARD_TYPE "Unknown Teensy Board" + #endif + +#elif defined(WIFI_USE_NRF528XX) || defined(ETHERNET_USE_NRF528XX) + // For nRF52 + #define EspSerial Serial1 + + #if defined(NRF52840_FEATHER) + #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" + #elif defined(NRF52832_FEATHER) + #define BOARD_TYPE "NRF52832_FEATHER" + #elif defined(NRF52840_FEATHER_SENSE) + #define BOARD_TYPE "NRF52840_FEATHER_SENSE" + #elif defined(NRF52840_ITSYBITSY) + #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" + #elif defined(NRF52840_CIRCUITPLAY) + #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" + #elif defined(NRF52840_CLUE) + #define BOARD_TYPE "NRF52840_CLUE" + #elif defined(NRF52840_METRO) + #define BOARD_TYPE "NRF52840_METRO_EXPRESS" + #elif defined(NRF52840_PCA10056) + #define BOARD_TYPE "NORDIC_NRF52840DK" + #elif defined(NINA_B302_ublox) + #define BOARD_TYPE "NINA_B302_ublox" + #elif defined(NINA_B112_ublox) + #define BOARD_TYPE "NINA_B112_ublox" + #elif defined(PARTICLE_XENON) + #define BOARD_TYPE "PARTICLE_XENON" + #elif defined(MDBT50Q_RX) + #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" + #elif defined(ARDUINO_NRF52_ADAFRUIT) + #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" + #else + #define BOARD_TYPE "nRF52 Unknown" + #endif + +#elif defined(WIFI_USE_RP2040) || defined(ETHERNET_USE_RP2040) + // For RP2040 + #define EspSerial Serial1 + + #if defined(ARDUINO_ARCH_MBED) + #if defined(BOARD_NAME) + #undef BOARD_NAME + #endif + + #if defined(ARDUINO_RASPBERRY_PI_PICO) + #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" + #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) + #define BOARD_TYPE "MBED DAFRUIT_FEATHER_RP2040" + #elif defined(ARDUINO_GENERIC_RP2040) + #define BOARD_TYPE "MBED GENERIC_RP2040" + #else + #define BOARD_TYPE "MBED Unknown RP2040" + #endif + #endif //ARDUINO_ARCH_MBED + +#elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) + // For SAMD + #define EspSerial Serial1 + + #if ( defined(ARDUINO_SAMD_ZERO) && !defined(SEEED_XIAO_M0) ) + #define BOARD_TYPE "SAMD Zero" + #elif defined(ARDUINO_SAMD_MKR1000) + #define BOARD_TYPE "SAMD MKR1000" + #elif defined(ARDUINO_SAMD_MKRWIFI1010) + #define BOARD_TYPE "SAMD MKRWIFI1010" + #elif defined(ARDUINO_SAMD_NANO_33_IOT) + #define BOARD_TYPE "SAMD NANO_33_IOT" + #elif defined(ARDUINO_SAMD_MKRFox1200) + #define BOARD_TYPE "SAMD MKRFox1200" + #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) + #define BOARD_TYPE "SAMD MKRWAN13X0" + #elif defined(ARDUINO_SAMD_MKRGSM1400) + #define BOARD_TYPE "SAMD MKRGSM1400" + #elif defined(ARDUINO_SAMD_MKRNB1500) + #define BOARD_TYPE "SAMD MKRNB1500" + #elif defined(ARDUINO_SAMD_MKRVIDOR4000) + #define BOARD_TYPE "SAMD MKRVIDOR4000" + #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) + #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" + #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS" + #elif defined(ADAFRUIT_METRO_M0_EXPRESS) + #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" + #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" + #elif defined(ADAFRUIT_GEMMA_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" + #elif defined(ADAFRUIT_TRINKET_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" + #elif defined(ADAFRUIT_ITSYBITSY_M0) + #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" + #elif defined(ARDUINO_SAMD_HALLOWING_M0) + #define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0" + #elif defined(ADAFRUIT_METRO_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" + #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" + #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" + #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" + #elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" + #elif defined(ADAFRUIT_PYPORTAL) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" + #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO" + #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" + #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) + #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" + #elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" + #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" + #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) + #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" + #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" + #elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS) + #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" + #elif defined(SEEED_WIO_TERMINAL) + #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" + #elif defined(SEEED_FEMTO_M0) + #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" + #elif defined(SEEED_XIAO_M0) + #define BOARD_TYPE "SAMD SEEED_XIAO_M0" + #ifdef USE_THIS_SS_PIN + #undef USE_THIS_SS_PIN + #endif + #define USE_THIS_SS_PIN A1 + #warning define SEEED_XIAO_M0 USE_THIS_SS_PIN == A1 + #elif defined(Wio_Lite_MG126) + #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" + #elif defined(WIO_GPS_BOARD) + #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" + #elif defined(SEEEDUINO_ZERO) + #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" + #elif defined(SEEEDUINO_LORAWAN) + #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" + #elif defined(SEEED_GROVE_UI_WIRELESS) + #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" + #elif defined(__SAMD21E18A__) + #define BOARD_TYPE "SAMD21E18A" + #elif defined(__SAMD21G18A__) + #define BOARD_TYPE "SAMD21G18A" + #elif defined(__SAMD51G19A__) + #define BOARD_TYPE "SAMD51G19A" + #elif defined(__SAMD51J19A__) + #define BOARD_TYPE "SAMD51J19A" + #elif defined(__SAMD51P19A__) + #define BOARD_TYPE "__SAMD51P19A__" + #elif defined(__SAMD51J20A__) + #define BOARD_TYPE "SAMD51J20A" + #elif defined(__SAM3X8E__) + #define BOARD_TYPE "SAM3X8E" + #elif defined(__CPU_ARC__) + #define BOARD_TYPE "CPU_ARC" + #elif defined(__SAMD51__) + #define BOARD_TYPE "SAMD51" + #else + #define BOARD_TYPE "SAMD Unknown" + #endif + +#elif defined(WIFI_USE_STM32) || defined(ETHERNET_USE_STM32) + // For STM32 + #warning EspSerial using SERIAL_PORT_HARDWARE, can be Serial or Serial1. See your board variant.h + #define EspSerial SERIAL_PORT_HARDWARE //Serial1 + + #if defined(STM32F0) + #warning STM32F0 board selected + #define BOARD_TYPE "STM32F0" + #elif defined(STM32F1) + #warning STM32F1 board selected + #define BOARD_TYPE "STM32F1" + #elif defined(STM32F2) + #warning STM32F2 board selected + #define BOARD_TYPE "STM32F2" + #elif defined(STM32F3) + #warning STM32F3 board selected + #define BOARD_TYPE "STM32F3" + #elif defined(STM32F4) + #warning STM32F4 board selected + #define BOARD_TYPE "STM32F4" + #elif defined(STM32F7) + #warning STM32F7 board selected + #define BOARD_TYPE "STM32F7" + #elif defined(STM32L0) + #warning STM32L0 board selected + #define BOARD_TYPE "STM32L0" + #elif defined(STM32L1) + #warning STM32L1 board selected + #define BOARD_TYPE "STM32L1" + #elif defined(STM32L4) + #warning STM32L4 board selected + #define BOARD_TYPE "STM32L4" + #elif defined(STM32H7) + #warning STM32H7 board selected + #define BOARD_TYPE "STM32H7" + #elif defined(STM32G0) + #warning STM32G0 board selected + #define BOARD_TYPE "STM32G0" + #elif defined(STM32G4) + #warning STM32G4 board selected + #define BOARD_TYPE "STM32G4" + #elif defined(STM32WB) + #warning STM32WB board selected + #define BOARD_TYPE "STM32WB" + #elif defined(STM32MP1) + #warning STM32MP1 board selected + #define BOARD_TYPE "STM32MP1" + #else + #warning STM32 unknown board selected + #define BOARD_TYPE "STM32 Unknown" + #endif + +#elif ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) + // For SAM DUE + #define EspSerial Serial1 + + #warning SAM DUE board selected + #define BOARD_TYPE "SAM DUE" + +#elif (ESP8266) + #warning ESP8266 board selected + +#elif (ESP32) + #warning ESP32 board selected + +#elif defined(WIFI_USE_MEGA_AVR) || defined(ETHERNET_USE_MEGA_AVR) + // For megaAVR such as UNO WiFi Rev2 + #define EspSerial Serial1 + + #if defined(ARDUINO_AVR_UNO_WIFI_REV2) + #define BOARD_TYPE "ARDUINO_AVR_UNO_WIFI_REV2" + #elif defined(ARDUINO_AVR_NANO_EVERY) + #define BOARD_TYPE "ARDUINO_AVR_NANO_EVERY" + #else + #define BOARD_TYPE "Unknown MegaAVR ATmega4809" + #endif + + #warning megaAVR ATmega4809 board selected + + #ifndef BOARD_TYPE + #define BOARD_TYPE "MegaAVR ATmega4809" + #endif + +#elif defined(WIFI_USE_AVR) || defined(ETHERNET_USE_AVR) + // For Mega + #define EspSerial Serial3 + + #if defined(ARDUINO_AVR_MEGA2560) + #define BOARD_TYPE "AVR_MEGA2560" + #elif defined(ARDUINO_AVR_MEGA) + #define BOARD_TYPE "ARDUINO_AVR_MEGA" + #elif defined(ARDUINO_AVR_ADK) + #define BOARD_TYPE "ARDUINO_AVR_ADK" + #endif + + #warning AVR Mega board selected + + #ifndef BOARD_TYPE + #define BOARD_TYPE "AVR Mega" + #endif + +#else + // For UNO, Nano + #error UNO, Nano, etc. not supported. Not enough memory + // Default pin 10 to SS/CS + #define USE_THIS_SS_PIN 10 + #define BOARD_TYPE "Unsupported AVR" +#endif // #ifdef CORE_TEENSY + +///////////////////////////////// + +#if (ESP8266 || ESP32) + + #ifdef DDNS_USING_WIFI + #undef DDNS_USING_WIFI + #endif + + #ifdef DDNS_USING_ETHERNET + #undef DDNS_USING_ETHERNET + #endif + + #warning Using Built-in ESP WiFi for ESP8266/ESP32 + + #define SHIELD_TYPE "Built-in ESP WiFi" + + #define DDNS_USING_WIFI true + #define DDNS_USING_ETHERNET false + +#elif ( (DDNS_USING_WIFI) && !(ESP8266 || ESP32) ) + + // Select one to be true: USE_WIFI_NINA, DDNS_USING_WIFI_AT or USE_WIFI_CUSTOM + #define USE_WIFI_NINA true + //#define USE_WIFI_NINA false + + //#define DDNS_USING_WIFI_AT true + #define DDNS_USING_WIFI_AT false + + // If not USE_WIFI_NINA, you can USE_WIFI_CUSTOM, then include the custom WiFi library here + //#define USE_WIFI_CUSTOM true + #define USE_WIFI_CUSTOM false + + #if !(USE_WIFI_NINA || DDNS_USING_WIFI_AT || USE_WIFI_CUSTOM) + #error Select either USE_WIFI_NINA || DDNS_USING_WIFI_AT || USE_WIFI_CUSTOM to be true + #endif + + #if defined(ARDUINO_SAMD_MKR1000) + #if defined(USE_WIFI_NINA) + #undef USE_WIFI_NINA + #endif + #define USE_WIFI_NINA false + #define USE_WIFI101 true + #define SHIELD_TYPE "WiFi101" + #endif + + #if (!USE_WIFI101) + #if USE_WIFI_NINA + #warning Using WiFiNINA and WiFiNINA_Generic Library + #define SHIELD_TYPE "WiFiNINA using WiFiNINA_Generic Library" + #elif DDNS_USING_WIFI_AT + #warning Using ESP8266-AT/ESP32-AT and ESP8266_AT_WebServer Library + #define SHIELD_TYPE "ESP8266-AT/ESP32-AT using ESP8266_AT_WebServer Library" + #elif USE_WIFI_CUSTOM + #warning Using Custom WiFi + #define SHIELD_TYPE "Custom WiFi" + //#include "WiFi_XYZ.h" + #include "WiFiEspAT.h" + #endif + #endif + +#elif DDNS_USING_ETHERNET + + // This must be true if using LAN8742A for STM32F, such as Nucleo-144 F767ZI + #define USE_BUILTIN_ETHERNET false + ////////// + + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + // Only one if the following to be true + #define USE_ETHERNET false + #define USE_ETHERNET2 false //true + #define USE_ETHERNET3 false //true + #define USE_ETHERNET_LARGE true + #define USE_ETHERNET_ESP8266 false //true + #define USE_ETHERNET_ENC false + + #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #ifdef USE_CUSTOM_ETHERNET + #undef USE_CUSTOM_ETHERNET + #define USE_CUSTOM_ETHERNET false + #endif + #endif + + // Currently, only Ethernet lib available for STM32 using W5x00 + #if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) + #if USE_NATIVE_ETHERNET + #include "NativeEthernet.h" + #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error + #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" + #elif USE_ETHERNET3 + #include "Ethernet3.h" + #warning Use Ethernet3 lib + #define SHIELD_TYPE "W5x00 using Ethernet3 Library" + #elif USE_ETHERNET2 + #include "Ethernet2.h" + #warning Use Ethernet2 lib + #define SHIELD_TYPE "W5x00 using Ethernet2 Library" + #elif USE_ETHERNET_LARGE + #include "EthernetLarge.h" + #warning Use EthernetLarge lib + #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_ESP8266 + #include "Ethernet_ESP8266.h" + #warning Use Ethernet_ESP8266 lib + #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" + #elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Use EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + #elif USE_CUSTOM_ETHERNET + #include "Ethernet_XYZ.h" + #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. + #define SHIELD_TYPE "using Custom Ethernet Library" + #elif USE_UIP_ETHERNET + #include "UIPEthernet.h" + #warning Use UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + #else + #ifdef USE_ETHERNET + #undef USE_ETHERNET + #endif + #define USE_ETHERNET true + #include "Ethernet.h" + #warning Use Ethernet lib + #define SHIELD_TYPE "W5x00 using Ethernet Library" + #endif + #elif USE_BUILTIN_ETHERNET + #warning Use built-in LAN8742A Library + #define SHIELD_TYPE "LAN8742A using STM32Ethernet Library" + #endif + +#endif // (ESP6288 || ESP32) + +///////////////////////////////// + +#if ( (DDNS_USING_WIFI) && !(ESP8266 || ESP32) ) + + #if DDNS_USING_WIFI_AT + #include + #else + #include + #endif + +#elif DDNS_USING_ETHERNET + + #if (ETHERNET_USE_STM32) + #include + #else + #include + #endif +#endif + +///////////////////////////////// + +#ifndef BOARD_NAME + #ifdef ARDUINO_BOARD + #define BOARD_NAME ARDUINO_BOARD + #else + #define BOARD_NAME BOARD_TYPE + #endif +#endif + +#ifndef SHIELD_TYPE + #define SHIELD_TYPE "Unknown shield" +#endif + +///////////////////////////////// + +#include + +#if (DDNS_USING_WIFI) + + #if DDNS_USING_WIFI_AT + ESP8266_AT_WebServer server(80); + #else + WiFiServer server(80); + #endif + + #include "wifi_credentials.h" + + const char* ssid = SECRET_SSID; + const char* password = SECRET_PASS; + +#elif (DDNS_USING_ETHERNET) + + EthernetServer server(80); + + // Enter a MAC address and IP address for your controller below. + #define NUMBER_OF_MAC 20 + + byte mac[][NUMBER_OF_MAC] = + { + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, + { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, + }; + + // Select the IP address according to your local network + IPAddress ip(192, 168, 2, 222); +#endif + +///////////////////////////////// + +#endif //defines_h diff --git a/examples/Ethernet/multiFileProject/multiFileProject.cpp b/examples/Ethernet/multiFileProject/multiFileProject.cpp new file mode 100644 index 0000000..6f29f48 --- /dev/null +++ b/examples/Ethernet/multiFileProject/multiFileProject.cpp @@ -0,0 +1,18 @@ +/**************************************************************************************************************************** + multiFileProject.cpp + + DDNS_Generic is a library to update DDNS IP address for DDNS services such as + duckdns, noip, dyndns, dynu, enom, all-inkl, selfhost.de, dyndns.it, strato, freemyip, afraid.org, ovh.com + + Based on and modified from + 1) EasyDDNS (/~https://github.com/ayushsharma82/EasyDDNS) + 2) ArduinoHttpClient (/~https://github.com/arduino-libraries/ArduinoHttpClient) + + Built by Khoi Hoang /~https://github.com/khoih-prog/DDNS_Generic + + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#include "multiFileProject.h" diff --git a/examples/Ethernet/multiFileProject/multiFileProject.h b/examples/Ethernet/multiFileProject/multiFileProject.h new file mode 100644 index 0000000..ae304ec --- /dev/null +++ b/examples/Ethernet/multiFileProject/multiFileProject.h @@ -0,0 +1,21 @@ +/**************************************************************************************************************************** + multiFileProject.h + + DDNS_Generic is a library to update DDNS IP address for DDNS services such as + duckdns, noip, dyndns, dynu, enom, all-inkl, selfhost.de, dyndns.it, strato, freemyip, afraid.org, ovh.com + + Based on and modified from + 1) EasyDDNS (/~https://github.com/ayushsharma82/EasyDDNS) + 2) ArduinoHttpClient (/~https://github.com/arduino-libraries/ArduinoHttpClient) + + Built by Khoi Hoang /~https://github.com/khoih-prog/DDNS_Generic + + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +#pragma once + +// Can be included as many times as necessary, without `Multiple Definitions` Linker Error +#include "DDNS_Generic.hpp" diff --git a/examples/Ethernet/multiFileProject/multiFileProject.ino b/examples/Ethernet/multiFileProject/multiFileProject.ino new file mode 100644 index 0000000..b89fcd2 --- /dev/null +++ b/examples/Ethernet/multiFileProject/multiFileProject.ino @@ -0,0 +1,36 @@ +/**************************************************************************************************************************** + multiFileProject.ino + + DDNS_Generic is a library to update DDNS IP address for DDNS services such as + duckdns, noip, dyndns, dynu, enom, all-inkl, selfhost.de, dyndns.it, strato, freemyip, afraid.org, ovh.com + + Based on and modified from + 1) EasyDDNS (/~https://github.com/ayushsharma82/EasyDDNS) + 2) ArduinoHttpClient (/~https://github.com/arduino-libraries/ArduinoHttpClient) + + Built by Khoi Hoang /~https://github.com/khoih-prog/DDNS_Generic + + Licensed under MIT license +*****************************************************************************************************************************/ + +// To demo how to include files in multi-file Projects + +// The .hpp contains only definitions, and can be included as many times as necessary, without `Multiple Definitions` Linker Error +// The .h contains implementations, and can be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error + +#include "defines.h" + +// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error +#include "DDNS_Generic.h" + +#include "multiFileProject.h" + +void setup() +{ + +} + +void loop() +{ + // put your main code here, to run repeatedly: +} diff --git a/examples/Ethernet/multiFileProject/wifi_credentials.h b/examples/Ethernet/multiFileProject/wifi_credentials.h new file mode 100644 index 0000000..6c94b3a --- /dev/null +++ b/examples/Ethernet/multiFileProject/wifi_credentials.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "your_ssid" +#define SECRET_PASS "your_pass" diff --git a/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/defines.h b/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/defines.h index 2e43f70..bc948d4 100644 --- a/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/defines.h +++ b/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/defines.h @@ -84,66 +84,73 @@ // Select Ethernet Library for the Shield /////////////////////////////////////////// -#define USE_UIP_ETHERNET false -#define USE_CUSTOM_ETHERNET false +#include + +// To override the default CS/SS pin. Don't use unless you know exactly which pin to use +// You can define here or customize for each board at same place with BOARD_TYPE +// Check @ defined(SEEED_XIAO_M0) +//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15 // Only one if the following to be true -#define USE_ETHERNET false -#define USE_ETHERNET2 false //true -#define USE_ETHERNET3 false //true -#define USE_ETHERNET_LARGE true -#define USE_ETHERNET_ESP8266 false //true -#define USE_ETHERNET_ENC false - -#if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC ) +#define USE_ETHERNET_GENERIC true +#define USE_ETHERNET_ESP8266 false +#define USE_ETHERNET_ENC false +#define USE_UIP_ETHERNET false +#define USE_CUSTOM_ETHERNET false + + //////////////////////////// + +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_UIP_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET - #define USE_CUSTOM_ETHERNET false #endif + #define USE_CUSTOM_ETHERNET false #endif -// Currently, only Ethernet lib available for STM32 using W5x00 -#if !(USE_BUILTIN_ETHERNET || ETHERNET_USE_STM32) - #if USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" - #elif USE_ETHERNET_ESP8266 - #include "Ethernet_ESP8266.h" - #warning Use Ethernet_ESP8266 lib - #define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library" - #elif USE_ETHERNET_ENC - #include "EthernetENC.h" - #warning Use EthernetENC lib - #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" - #elif USE_CUSTOM_ETHERNET - #include "Ethernet_XYZ.h" - #warning Use Custom Ethernet library from EthernetWrapper. You must include a library here or error. - #define SHIELD_TYPE "using Custom Ethernet Library" - #elif USE_UIP_ETHERNET +#if USE_ETHERNET_GENERIC + + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI" + + #define ETHERNET_LARGE_BUFFERS + + #define _ETG_LOGLEVEL_ 1 + + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + +#elif USE_ETHERNET_ENC + #include "EthernetENC.h" + #warning Using EthernetENC lib + #define SHIELD_TYPE "ENC28J60 using EthernetENC Library" + +#elif USE_CUSTOM_ETHERNET + //#include "Ethernet_XYZ.h" + #include "Ethernet.h" + #warning Using Custom Ethernet library. You must include a library and initialize. + #define SHIELD_TYPE "Custom Ethernet using Ethernet Library" + +#elif USE_UIP_ETHERNET #include "UIPEthernet.h" - #warning Use UIPEthernet library - #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" - #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" - #endif -#endif + #warning Using UIPEthernet library + #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" + +#else + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" -///////////////////////////////// +// Ethernet_Shield_W5200, EtherCard, EtherSia not supported +// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET +// Otherwise, standard Ethernet library will be used for W5x00 + + //////////////////////////// + +#endif // #if USE_ETHERNET_GENERIC ///////////////////////////////// diff --git a/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/nRF52_Ethernet_DuckDNS_Client.ino b/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/nRF52_Ethernet_DuckDNS_Client.ino index 7304a30..c1331b5 100644 --- a/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/nRF52_Ethernet_DuckDNS_Client.ino +++ b/examples/Ethernet/nRF52/nRF52_Ethernet_DuckDNS_Client/nRF52_Ethernet_DuckDNS_Client.ino @@ -28,38 +28,57 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } -void setup() +void initEthernet() { - Serial.begin(115200); - while (!Serial); - - Serial.print("\nStart nRF52_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); - Serial.println(" with " + String(SHIELD_TYPE)); - Serial.println(DDNS_GENERIC_VERSION); - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif + #if USE_ETHERNET_GENERIC + ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ===========")); +#elif USE_ETHERNET_ENC + ET_LOGWARN(F("=========== USE_ETHERNET_ENC ===========")); +#elif USE_UIP_ETHERNET + ET_LOGWARN(F("=========== USE_UIP_ETHERNET ===========")); +#else + ET_LOGWARN(F("=========== USE_CUSTOM_ETHERNET ===========")); +#endif - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); + ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN); -#endif //( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) + ET_LOGWARN(F("Default SPI pinout:")); + ET_LOGWARN1(F("MOSI:"), MOSI); + ET_LOGWARN1(F("MISO:"), MISO); + ET_LOGWARN1(F("SCK:"), SCK); + ET_LOGWARN1(F("SS:"), SS); + ET_LOGWARN(F("=========================")); + // For other boards, to change if necessary + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + Ethernet.init (USE_THIS_SS_PIN); + + #elif USE_CUSTOM_ETHERNET + // You have to add initialization for your Custom Ethernet here + // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough + //Ethernet.init(USE_THIS_SS_PIN); + + #endif //( ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // start the ethernet connection and the server: // Use DHCP dynamic IP and random mac uint16_t index = millis() % NUMBER_OF_MAC; // Use Static IP //Ethernet.begin(mac[index], ip); Ethernet.begin(mac[index]); +} + +void setup() +{ + Serial.begin(115200); + while (!Serial && millis() < 5000); + + Serial.print("\nStart nRF52_Ethernet_DuckDNS_Client on " + String(BOARD_NAME)); + Serial.println(" with " + String(SHIELD_TYPE)); + Serial.println(DDNS_GENERIC_VERSION); + + initEthernet(); Serial.print(F("\nHTTP WebServer is @ IP : ")); Serial.println(Ethernet.localIP()); diff --git a/examples/Generic/DuckDNS_Client/DuckDNS_Client.ino b/examples/Generic/DuckDNS_Client/DuckDNS_Client.ino index 08856fa..dec5a69 100644 --- a/examples/Generic/DuckDNS_Client/DuckDNS_Client.ino +++ b/examples/Generic/DuckDNS_Client/DuckDNS_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart DuckDNS_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,32 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/DuckDNS_Client/defines.h b/examples/Generic/DuckDNS_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/DuckDNS_Client/defines.h +++ b/examples/Generic/DuckDNS_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/DynDNS_Client/DynDNS_Client.ino b/examples/Generic/DynDNS_Client/DynDNS_Client.ino index 7bfa5f8..7fd1314 100644 --- a/examples/Generic/DynDNS_Client/DynDNS_Client.ino +++ b/examples/Generic/DynDNS_Client/DynDNS_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart DynDNS_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,34 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/DynDNS_Client/defines.h b/examples/Generic/DynDNS_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/DynDNS_Client/defines.h +++ b/examples/Generic/DynDNS_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/Dynu_Client/Dynu_Client.ino b/examples/Generic/Dynu_Client/Dynu_Client.ino index 39fa202..d4d2ff0 100644 --- a/examples/Generic/Dynu_Client/Dynu_Client.ino +++ b/examples/Generic/Dynu_Client/Dynu_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart Dynu_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,33 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/Dynu_Client/defines.h b/examples/Generic/Dynu_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/Dynu_Client/defines.h +++ b/examples/Generic/Dynu_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/No-ip_Client/No-ip_Client.ino b/examples/Generic/No-ip_Client/No-ip_Client.ino index 77853d2..b3228ca 100644 --- a/examples/Generic/No-ip_Client/No-ip_Client.ino +++ b/examples/Generic/No-ip_Client/No-ip_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart No-ip_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,33 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/No-ip_Client/defines.h b/examples/Generic/No-ip_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/No-ip_Client/defines.h +++ b/examples/Generic/No-ip_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/OVH_Client/OVH_Client.ino b/examples/Generic/OVH_Client/OVH_Client.ino index cf546b1..9b6fe5f 100644 --- a/examples/Generic/OVH_Client/OVH_Client.ino +++ b/examples/Generic/OVH_Client/OVH_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart OVH_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,33 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/OVH_Client/defines.h b/examples/Generic/OVH_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/OVH_Client/defines.h +++ b/examples/Generic/OVH_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/afraid-org_Client/afraid-org_Client.ino b/examples/Generic/afraid-org_Client/afraid-org_Client.ino index 9d90f92..f940f28 100644 --- a/examples/Generic/afraid-org_Client/afraid-org_Client.ino +++ b/examples/Generic/afraid-org_Client/afraid-org_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart afraid-org_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,32 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif //#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/afraid-org_Client/defines.h b/examples/Generic/afraid-org_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/afraid-org_Client/defines.h +++ b/examples/Generic/afraid-org_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/all-inkl_Client/all-inkl_Client.ino b/examples/Generic/all-inkl_Client/all-inkl_Client.ino index d5546d3..3141594 100644 --- a/examples/Generic/all-inkl_Client/all-inkl_Client.ino +++ b/examples/Generic/all-inkl_Client/all-inkl_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart all-inkl_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,32 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/all-inkl_Client/defines.h b/examples/Generic/all-inkl_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/all-inkl_Client/defines.h +++ b/examples/Generic/all-inkl_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/dyndns-it_Client/defines.h b/examples/Generic/dyndns-it_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/dyndns-it_Client/defines.h +++ b/examples/Generic/dyndns-it_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/dyndns-it_Client/dyndns-it_Client.ino b/examples/Generic/dyndns-it_Client/dyndns-it_Client.ino index 6148773..8bf9b29 100644 --- a/examples/Generic/dyndns-it_Client/dyndns-it_Client.ino +++ b/examples/Generic/dyndns-it_Client/dyndns-it_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart dyndns-it_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,33 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/enom_Client/defines.h b/examples/Generic/enom_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/enom_Client/defines.h +++ b/examples/Generic/enom_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/enom_Client/enom_Client.ino b/examples/Generic/enom_Client/enom_Client.ino index b678a40..c46612a 100644 --- a/examples/Generic/enom_Client/enom_Client.ino +++ b/examples/Generic/enom_Client/enom_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart enom_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,33 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/freemyip_Client/defines.h b/examples/Generic/freemyip_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/freemyip_Client/defines.h +++ b/examples/Generic/freemyip_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/freemyip_Client/freemyip_Client.ino b/examples/Generic/freemyip_Client/freemyip_Client.ino index b24c556..eb407bc 100644 --- a/examples/Generic/freemyip_Client/freemyip_Client.ino +++ b/examples/Generic/freemyip_Client/freemyip_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart freemyip_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,32 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/selfhost-de_Client/defines.h b/examples/Generic/selfhost-de_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/selfhost-de_Client/defines.h +++ b/examples/Generic/selfhost-de_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/selfhost-de_Client/selfhost-de_Client.ino b/examples/Generic/selfhost-de_Client/selfhost-de_Client.ino index a09166d..788c3ae 100644 --- a/examples/Generic/selfhost-de_Client/selfhost-de_Client.ino +++ b/examples/Generic/selfhost-de_Client/selfhost-de_Client.ino @@ -28,10 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); + while (!Serial && millis() < 5000) Serial.print("\nStart selfhost-de_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); @@ -93,33 +114,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif diff --git a/examples/Generic/strato_Client/defines.h b/examples/Generic/strato_Client/defines.h index 93c21c6..e230ca8 100644 --- a/examples/Generic/strato_Client/defines.h +++ b/examples/Generic/strato_Client/defines.h @@ -79,8 +79,6 @@ #if defined(ARDUINO_ARCH_MBED) #warning Use RP2040 architecture with Ethernet - #else - #error Only ARDUINO_ARCH_MBED supported Ethernet on the RP2040-based boards ! Please check your Tools->Board setting. #endif #endif @@ -300,11 +298,17 @@ // For RP2040 #define EspSerial Serial1 + // Default pin 5 (in Mbed) or 17 to SS/CS #if defined(ARDUINO_ARCH_MBED) + // For RPI Pico using Arduino Mbed RP2040 core + // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 + + #define USE_THIS_SS_PIN 17 + #if defined(BOARD_NAME) #undef BOARD_NAME #endif - + #if defined(ARDUINO_RASPBERRY_PI_PICO) #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) @@ -314,7 +318,26 @@ #else #define BOARD_TYPE "MBED Unknown RP2040" #endif - #endif //ARDUINO_ARCH_MBED + + #else + + //#define USING_SPI2 true + + // For RPI Pico using E. Philhower RP2040 core + #if (USING_SPI2) + // SCK: GPIO14, MOSI: GPIO15, MISO: GPIO12, SS/CS: GPIO13 for SPI1 + #define USE_THIS_SS_PIN 13 + #else + // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 for SPI0 + #define USE_THIS_SS_PIN 17 + #endif + + #endif + + #define SS_PIN_DEFAULT USE_THIS_SS_PIN + + // For RPI Pico + #warning Use RPI-Pico RP2040 architecture #elif defined(WIFI_USE_SAMD) || defined(ETHERNET_USE_SAMD) // For SAMD @@ -604,14 +627,15 @@ #define USE_CUSTOM_ETHERNET false // Only one if the following to be true - #define USE_ETHERNET false - #define USE_ETHERNET2 false //true - #define USE_ETHERNET3 false //true - #define USE_ETHERNET_LARGE true - #define USE_ETHERNET_ESP8266 false //true - #define USE_ETHERNET_ENC false + #define USE_ETHERNET_GENERIC true + #define USE_ETHERNET_ESP8266 false + #define USE_ETHERNET_ENC false + #define USE_UIP_ETHERNET false + #define USE_CUSTOM_ETHERNET false + + //////////////////////////// - #if ( USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) + #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET ) #ifdef USE_CUSTOM_ETHERNET #undef USE_CUSTOM_ETHERNET #define USE_CUSTOM_ETHERNET false @@ -624,18 +648,13 @@ #include "NativeEthernet.h" #warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error #define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library" - #elif USE_ETHERNET3 - #include "Ethernet3.h" - #warning Use Ethernet3 lib - #define SHIELD_TYPE "W5x00 using Ethernet3 Library" - #elif USE_ETHERNET2 - #include "Ethernet2.h" - #warning Use Ethernet2 lib - #define SHIELD_TYPE "W5x00 using Ethernet2 Library" - #elif USE_ETHERNET_LARGE - #include "EthernetLarge.h" - #warning Use EthernetLarge lib - #define SHIELD_TYPE "W5x00 using EthernetLarge Library" + #elif USE_ETHERNET_GENERIC + #include "Ethernet_Generic.h" + #warning Using Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using Ethernet_Generic Library" + + #define ETHERNET_LARGE_BUFFERS + #elif USE_ETHERNET_ESP8266 #include "Ethernet_ESP8266.h" #warning Use Ethernet_ESP8266 lib @@ -653,13 +672,14 @@ #warning Use UIPEthernet library #define SHIELD_TYPE "ENC28J60 using UIPEthernet Library" #else - #ifdef USE_ETHERNET - #undef USE_ETHERNET - #endif - #define USE_ETHERNET true - #include "Ethernet.h" - #warning Use Ethernet lib - #define SHIELD_TYPE "W5x00 using Ethernet Library" + #ifdef USE_ETHERNET_GENERIC + #undef USE_ETHERNET_GENERIC + #endif + #define USE_ETHERNET_GENERIC true + + #include "Ethernet_Generic.h" + #warning Using default Ethernet_Generic lib + #define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library" #endif #elif USE_BUILTIN_ETHERNET #warning Use built-in LAN8742A Library diff --git a/examples/Generic/strato_Client/strato_Client.ino b/examples/Generic/strato_Client/strato_Client.ino index 1334f70..71b8aca 100644 --- a/examples/Generic/strato_Client/strato_Client.ino +++ b/examples/Generic/strato_Client/strato_Client.ino @@ -28,11 +28,31 @@ void onUpdateCallback(const char* oldIP, const char* newIP) Serial.println(newIP); } +void initEthernet() +{ + // For other boards, to change if necessary +#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries + + Ethernet.init (USE_THIS_SS_PIN); + +#endif // #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC ) + + // start the ethernet connection and the server: + // Use DHCP dynamic IP and random mac + uint16_t index = millis() % NUMBER_OF_MAC; + // Use Static IP + //Ethernet.begin(mac[index], ip); + Ethernet.begin(mac[index]); + + Serial.print(F("\nHTTP WebServer is @ IP : ")); + Serial.println(Ethernet.localIP()); +} + void setup() { Serial.begin(115200); - while (!Serial); - + while (!Serial && millis() < 5000) Serial.print("\nStart strato_Client on " + String(BOARD_NAME)); Serial.println(" with " + String(SHIELD_TYPE)); Serial.println(DDNS_GENERIC_VERSION); @@ -93,33 +113,7 @@ void setup() #elif (DDNS_USING_ETHERNET) - // For other boards, to change if necessary -#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries - - Ethernet.init (USE_THIS_SS_PIN); - -#elif USE_ETHERNET3 - // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer - #ifndef ETHERNET3_MAX_SOCK_NUM - #define ETHERNET3_MAX_SOCK_NUM 4 - #endif - - Ethernet.setCsPin (USE_THIS_SS_PIN); - Ethernet.init (ETHERNET3_MAX_SOCK_NUM); - -#endif // #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC ) - - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - // Use Static IP - //Ethernet.begin(mac[index], ip); - Ethernet.begin(mac[index]); - - Serial.print(F("\nHTTP WebServer is @ IP : ")); - Serial.println(Ethernet.localIP()); + initEthernet(); #endif