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

Commit

Permalink
v1.1.0 to use Ethernet_Generic library
Browse files Browse the repository at this point in the history
### Releases v1.1.0

1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00.
2. Add support to `SPI1` for `RP2040` using [`Earle Philhower's arduino-pico` core](https://github.com/earlephilhower/arduino-pico)
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 715df9e commit aa5b97c
Show file tree
Hide file tree
Showing 14 changed files with 339 additions and 509 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p

Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.16) or Platform.io version
* `RP2040` Core Version (e.g. Arduino-mbed RP2040 v2.5.2 or arduino-pico core v1.9.5)
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* `RP2040` Core Version (e.g. Arduino-mbed RP2040 v3.0.1 or arduino-pico core v1.13.3)
* `RP2040` Board type (e.g. NANO_RP2040_CONNECT, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
Expand All @@ -27,11 +27,11 @@ Please ensure to specify the following:
### Example

```
Arduino IDE version: 1.8.16
Arduino-mbed RP2040 v2.5.2
Arduino IDE version: 1.8.19
Arduino-mbed RP2040 v3.0.1
NANO_RP2040_CONNECT Module
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-96-generic #109-Ubuntu SMP Wed Jan 12 16:49:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.13.0-40-generic #45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while using TimerInterrupt.
Expand Down
312 changes: 151 additions & 161 deletions README.md

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.1.0](#releases-v110)
* [Releases v1.0.8](#releases-v108)
* [Releases v1.0.7](#releases-v107)
* [Releases v1.0.6](#releases-v106)
Expand All @@ -27,6 +28,12 @@

## Changelog

### Releases v1.1.0

1. Use new [Ethernet_Generic library](https://github.com/khoih-prog/Ethernet_Generic) as default for W5x00.
2. Add support to `SPI1` for `RP2040` using [`Earle Philhower's arduino-pico` core](https://github.com/earlephilhower/arduino-pico)
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)

### Releases v1.0.8

1. Update dependency on [Timezone_Generic Library](https://github.com/khoih-prog/Timezone_Generic)
Expand Down
2 changes: 1 addition & 1 deletion examples/Alarm/RP2040_RTC_Alarm/RP2040_RTC_Alarm.ino
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void printDateTime(time_t t, const char *tz)
void setup()
{
Serial.begin(115200);
while (!Serial);
while (!Serial && millis() < 5000);

delay(200);

Expand Down
182 changes: 44 additions & 138 deletions examples/Alarm/RP2040_RTC_Alarm_Ethernet/RP2040_RTC_Alarm_Ethernet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -238,32 +238,10 @@ void printDateTime(time_t t, const char *tz)

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

void setup()
void initEthernet()
{
Serial.begin(115200);
while (!Serial);

delay(200);

Serial.print(F("\nStart RP2040_RTC_Alarm_Ethernet on ")); Serial.print(BOARD_NAME);
Serial.print(F(" with ")); Serial.println(SHIELD_TYPE);
Serial.println(RP2040_RTC_VERSION);
Serial.println(TIMEZONE_GENERIC_VERSION);

#if USE_ETHERNET_WRAPPER

EthernetInit();

#else

#if USE_ETHERNET
ET_LOGWARN(F("=========== USE_ETHERNET ==========="));
#elif USE_ETHERNET2
ET_LOGWARN(F("=========== USE_ETHERNET2 ==========="));
#elif USE_ETHERNET3
ET_LOGWARN(F("=========== USE_ETHERNET3 ==========="));
#elif USE_ETHERNET_LARGE
ET_LOGWARN(F("=========== USE_ETHERNET_LARGE ==========="));
#if USE_ETHERNET_GENERIC
ET_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
#elif USE_ETHERNET_ESP8266
ET_LOGWARN(F("=========== USE_ETHERNET_ESP8266 ==========="));
#else
Expand All @@ -277,122 +255,37 @@ void setup()
ET_LOGWARN1(F("SS:"), SS);
ET_LOGWARN(F("========================="));

#if defined(ESP8266)
// For ESP8266, change for other boards if necessary
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN D2 // For ESP8266
#endif

ET_LOGWARN1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);

#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
// For ESP8266
// Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8
// Ethernet 0 X X X X 0
// Ethernet2 X X X X X 0
// Ethernet3 X X X X X 0
// EthernetLarge X X X X X 0
// Ethernet_ESP8266 0 0 0 0 0 0
// D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs
// Must use library patch for Ethernet, 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_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )

#elif defined(ESP32)

// You can use Ethernet.init(pin) to configure the CS pin
//Ethernet.init(10); // Most Arduino shields
//Ethernet.init(5); // MKR ETH shield
//Ethernet.init(0); // Teensy 2.0
//Ethernet.init(20); // Teensy++ 2.0
//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet

#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 22 // For ESP32
#endif

ET_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);

// For other boards, to change if necessary
#if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, EthernetLarge libraries
// ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
// ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3

//Ethernet.setCsPin (USE_THIS_SS_PIN);
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);
#if ETHERNET_USE_RPIPICO

#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_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )

#else //defined(ESP8266)
// unknown board, do nothing, use default SS = 10
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 10 // For other boards
#endif
pinMode(USE_THIS_SS_PIN, OUTPUT);
digitalWrite(USE_THIS_SS_PIN, HIGH);

// ETHERNET_USE_RPIPICO, use default SS = 5 or 17
#ifndef USE_THIS_SS_PIN
#if defined(ARDUINO_ARCH_MBED)
#define USE_THIS_SS_PIN 5 // For Arduino Mbed core
#else
#define USE_THIS_SS_PIN 17 // For E.Philhower core
#endif
#endif

ET_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
ET_LOGWARN1(F("RPIPICO setCsPin:"), USE_THIS_SS_PIN);

// 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);
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, EthernetLarge libraries
// For RPI Pico using Arduino Mbed RP2040 core
// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
// For RPI Pico using E. Philhower RP2040 core
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
// Default pin 5/17 to SS/CS

//Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (USE_THIS_SS_PIN);
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

#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_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )

#endif //defined(ESP8266)


#endif //USE_ETHERNET_WRAPPER


// start the ethernet connection and the server:
// Use DHCP dynamic IP and random mac
uint16_t index = millis() % NUMBER_OF_MAC;
Expand All @@ -407,16 +300,29 @@ void setup()
Serial.print(F("MISO:")); Serial.println(MISO);
Serial.print(F("SCK:")); Serial.println(SCK);
Serial.print(F("SS:")); Serial.println(SS);
#if USE_ETHERNET3
Serial.print(F("SPI_CS:")); Serial.println(SPI_CS);
#endif
Serial.println(F("========================="));

Serial.print(F("Using mac index = ")); Serial.println(index);
Serial.print(F("Using mac index = "));
Serial.println(index);

// you're connected now, so print out the data
Serial.print(F("You're connected to the network, IP = "));
Serial.println(Ethernet.localIP());
}

void setup()
{
Serial.begin(115200);
while (!Serial && millis() < 5000);

delay(200);

Serial.print(F("\nStart RP2040_RTC_Alarm_Ethernet on ")); Serial.print(BOARD_NAME);
Serial.print(F(" with ")); Serial.println(SHIELD_TYPE);
Serial.println(RP2040_RTC_VERSION);
Serial.println(TIMEZONE_GENERIC_VERSION);

initEthernet();

myTZ = new Timezone(myDST, mySTD);

Expand Down
55 changes: 24 additions & 31 deletions examples/Alarm/RP2040_RTC_Alarm_Ethernet/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@
#undef ETHERNET_USE_RP2040
#endif
#define ETHERNET_USE_RP2040 true
#define ETHERNET_USE_RPIPICO true
#endif

#if ETHERNET_USE_RP2040
#if ETHERNET_USE_RP2040 || ETHERNET_USE_RPIPICO

// 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
// SDA: 6, SCL: 7
// For Nano_RP2040_Connect using Arduino Mbed RP2040 core
// SDA: 14 = A4, SCL: 19 = A5

#define USE_THIS_SS_PIN 5
#define USE_THIS_SS_PIN 17 //5

#if defined(BOARD_NAME)
#undef BOARD_NAME
Expand All @@ -51,8 +49,7 @@

#else
// For RPI Pico using E. Philhower RP2040 core
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
// SDA: 4, SCL: 5
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
#define USE_THIS_SS_PIN 17

#endif
Expand Down Expand Up @@ -91,35 +88,28 @@
// Check @ defined(SEEED_XIAO_M0)
//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15

// Only one of the following to be true
#define USE_ETHERNET false
#define USE_ETHERNET2 false
#define USE_ETHERNET3 false
#define USE_ETHERNET_LARGE true
#define USE_ETHERNET_ESP8266 false
// Only one if the following to be true
#define USE_ETHERNET_GENERIC true
#define USE_ETHERNET_ESP8266 false
#define USE_ETHERNET_ENC false
#define USE_CUSTOM_ETHERNET false


#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
#define USE_CUSTOM_ETHERNET false //true
#endif

#if USE_ETHERNET3
#include "Ethernet3.h"
#warning Using Ethernet3 lib
#define SHIELD_TYPE "W5x00 using Ethernet3 Library"
#elif USE_ETHERNET2
#include "Ethernet2.h"
#warning Using Ethernet2 lib
#define SHIELD_TYPE "W5x00 using Ethernet2 Library"
#elif USE_ETHERNET_LARGE
#include "EthernetLarge.h"
#warning Using EthernetLarge lib
#define SHIELD_TYPE "W5x00 using EthernetLarge Library"
#if USE_ETHERNET_GENERIC
#define ETHERNET_LARGE_BUFFERS

#define _ETG_LOGLEVEL_ 1

#include "Ethernet_Generic.h"

#warning Using Ethernet_Generic lib
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
#elif USE_ETHERNET_ESP8266
#include "Ethernet_ESP8266.h"
#warning Using Ethernet_ESP8266 lib
Expand All @@ -134,10 +124,13 @@
#warning Using Custom Ethernet library. You must include a library and initialize.
#define SHIELD_TYPE "Custom Ethernet using Ethernet_XYZ Library"
#else
#define USE_ETHERNET true
#include "Ethernet.h"
#warning Using 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

// Ethernet_Shield_W5200, EtherCard, EtherSia not supported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void printDateTime(time_t t, const char *tz)
void setup()
{
Serial.begin(115200);
while (!Serial);
while (!Serial && millis() < 5000);

delay(200);

Expand Down
2 changes: 1 addition & 1 deletion examples/Time/RP2040_RTC_Time/RP2040_RTC_Time.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void printDateTime(time_t t, const char *tz)
void setup()
{
Serial.begin(115200);
while (!Serial);
while (!Serial && millis() < 5000);

delay(200);

Expand Down
Loading

0 comments on commit aa5b97c

Please sign in to comment.