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

Commit

Permalink
v1.7.0 to use Ethernet_Generic library
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
khoih-prog authored Apr 25, 2022
1 parent 07f3b6c commit 47e6ea1
Show file tree
Hide file tree
Showing 46 changed files with 2,518 additions and 1,279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
109 changes: 58 additions & 51 deletions examples/Ethernet/AVR/AVR_Ethernet_DuckDNS_Client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,66 +64,73 @@
// Select Ethernet Library for the Shield
///////////////////////////////////////////

#define USE_UIP_ETHERNET false
#define USE_CUSTOM_ETHERNET false
#include <SPI.h>

// 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

/////////////////////////////////

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 47e6ea1

Please sign in to comment.