@@ -238,32 +238,10 @@ void printDateTime(time_t t, const char *tz)
238238
239239// ////////////////////////////////////////
240240
241- void setup ()
241+ void initEthernet ()
242242{
243- Serial.begin (115200 );
244- while (!Serial);
245-
246- delay (200 );
247-
248- Serial.print (F (" \n Start RP2040_RTC_Alarm_Ethernet on " )); Serial.print (BOARD_NAME);
249- Serial.print (F (" with " )); Serial.println (SHIELD_TYPE);
250- Serial.println (RP2040_RTC_VERSION);
251- Serial.println (TIMEZONE_GENERIC_VERSION);
252-
253- #if USE_ETHERNET_WRAPPER
254-
255- EthernetInit ();
256-
257- #else
258-
259- #if USE_ETHERNET
260- ET_LOGWARN (F (" =========== USE_ETHERNET ===========" ));
261- #elif USE_ETHERNET2
262- ET_LOGWARN (F (" =========== USE_ETHERNET2 ===========" ));
263- #elif USE_ETHERNET3
264- ET_LOGWARN (F (" =========== USE_ETHERNET3 ===========" ));
265- #elif USE_ETHERNET_LARGE
266- ET_LOGWARN (F (" =========== USE_ETHERNET_LARGE ===========" ));
243+ #if USE_ETHERNET_GENERIC
244+ ET_LOGWARN (F (" =========== USE_ETHERNET_GENERIC ===========" ));
267245#elif USE_ETHERNET_ESP8266
268246 ET_LOGWARN (F (" =========== USE_ETHERNET_ESP8266 ===========" ));
269247#else
@@ -277,122 +255,37 @@ void setup()
277255 ET_LOGWARN1 (F (" SS:" ), SS);
278256 ET_LOGWARN (F (" =========================" ));
279257
280- #if defined(ESP8266)
281- // For ESP8266, change for other boards if necessary
282- #ifndef USE_THIS_SS_PIN
283- #define USE_THIS_SS_PIN D2 // For ESP8266
284- #endif
285-
286- ET_LOGWARN1 (F (" ESP8266 setCsPin:" ), USE_THIS_SS_PIN);
287-
288- #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
289- // For ESP8266
290- // Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8
291- // Ethernet 0 X X X X 0
292- // Ethernet2 X X X X X 0
293- // Ethernet3 X X X X X 0
294- // EthernetLarge X X X X X 0
295- // Ethernet_ESP8266 0 0 0 0 0 0
296- // D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs
297- // Must use library patch for Ethernet, EthernetLarge libraries
298- Ethernet.init (USE_THIS_SS_PIN);
299-
300- #elif USE_ETHERNET3
301- // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
302- #ifndef ETHERNET3_MAX_SOCK_NUM
303- #define ETHERNET3_MAX_SOCK_NUM 4
304- #endif
305-
306- Ethernet.setCsPin (USE_THIS_SS_PIN);
307- Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
308-
309- #elif USE_CUSTOM_ETHERNET
310-
311- // You have to add initialization for your Custom Ethernet here
312- // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
313- Ethernet.init (USE_THIS_SS_PIN);
314-
315- #endif // ( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
316-
317- #elif defined(ESP32)
318-
319- // You can use Ethernet.init(pin) to configure the CS pin
320- // Ethernet.init(10); // Most Arduino shields
321- // Ethernet.init(5); // MKR ETH shield
322- // Ethernet.init(0); // Teensy 2.0
323- // Ethernet.init(20); // Teensy++ 2.0
324- // Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet
325- // Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet
326-
327- #ifndef USE_THIS_SS_PIN
328- #define USE_THIS_SS_PIN 22 // For ESP32
329- #endif
330-
331- ET_LOGWARN1 (F (" ESP32 setCsPin:" ), USE_THIS_SS_PIN);
332-
333- // For other boards, to change if necessary
334- #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
335- // Must use library patch for Ethernet, EthernetLarge libraries
336- // ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge
337- // ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3
338-
339- // Ethernet.setCsPin (USE_THIS_SS_PIN);
340- Ethernet.init (USE_THIS_SS_PIN);
341-
342- #elif USE_ETHERNET3
343- // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
344- #ifndef ETHERNET3_MAX_SOCK_NUM
345- #define ETHERNET3_MAX_SOCK_NUM 4
346- #endif
347-
348- Ethernet.setCsPin (USE_THIS_SS_PIN);
349- Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
258+ #if ETHERNET_USE_RPIPICO
350259
351- #elif USE_CUSTOM_ETHERNET
352-
353- // You have to add initialization for your Custom Ethernet here
354- // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
355- Ethernet.init (USE_THIS_SS_PIN);
356-
357- #endif // ( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
358-
359- #else // defined(ESP8266)
360- // unknown board, do nothing, use default SS = 10
361- #ifndef USE_THIS_SS_PIN
362- #define USE_THIS_SS_PIN 10 // For other boards
363- #endif
260+ pinMode (USE_THIS_SS_PIN, OUTPUT);
261+ digitalWrite (USE_THIS_SS_PIN, HIGH);
262+
263+ // ETHERNET_USE_RPIPICO, use default SS = 5 or 17
264+ #ifndef USE_THIS_SS_PIN
265+ #if defined(ARDUINO_ARCH_MBED)
266+ #define USE_THIS_SS_PIN 5 // For Arduino Mbed core
267+ #else
268+ #define USE_THIS_SS_PIN 17 // For E.Philhower core
269+ #endif
270+ #endif
364271
365- ET_LOGWARN3 (F (" Board : " ), BOARD_NAME, F ( " , setCsPin:" ), USE_THIS_SS_PIN);
272+ ET_LOGWARN1 (F (" RPIPICO setCsPin:" ), USE_THIS_SS_PIN);
366273
367274 // For other boards, to change if necessary
368- #if ( USE_ETHERNET || USE_ETHERNET_LARGE || USE_ETHERNET2 || USE_ETHERNET_ENC )
369- // Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
370-
371- Ethernet.init (USE_THIS_SS_PIN);
275+ #if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
276+ // Must use library patch for Ethernet, EthernetLarge libraries
277+ // For RPI Pico using Arduino Mbed RP2040 core
278+ // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
279+ // For RPI Pico using E. Philhower RP2040 core
280+ // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
281+ // Default pin 5/17 to SS/CS
282+
283+ // Ethernet.setCsPin (USE_THIS_SS_PIN);
284+ Ethernet.init (USE_THIS_SS_PIN);
285+ #endif // ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
372286
373- #elif USE_ETHERNET3
374- // Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer
375- #ifndef ETHERNET3_MAX_SOCK_NUM
376- #define ETHERNET3_MAX_SOCK_NUM 4
377287#endif
378288
379- Ethernet.setCsPin (USE_THIS_SS_PIN);
380- Ethernet.init (ETHERNET3_MAX_SOCK_NUM);
381-
382- #elif USE_CUSTOM_ETHERNET
383-
384- // You have to add initialization for your Custom Ethernet here
385- // This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
386- Ethernet.init (USE_THIS_SS_PIN);
387-
388- #endif // ( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )
389-
390- #endif // defined(ESP8266)
391-
392-
393- #endif // USE_ETHERNET_WRAPPER
394-
395-
396289 // start the ethernet connection and the server:
397290 // Use DHCP dynamic IP and random mac
398291 uint16_t index = millis () % NUMBER_OF_MAC;
@@ -407,16 +300,29 @@ void setup()
407300 Serial.print (F (" MISO:" )); Serial.println (MISO);
408301 Serial.print (F (" SCK:" )); Serial.println (SCK);
409302 Serial.print (F (" SS:" )); Serial.println (SS);
410- #if USE_ETHERNET3
411- Serial.print (F (" SPI_CS:" )); Serial.println (SPI_CS);
412- #endif
413303 Serial.println (F (" =========================" ));
414304
415- Serial.print (F (" Using mac index = " )); Serial.println (index);
305+ Serial.print (F (" Using mac index = " ));
306+ Serial.println (index);
416307
417308 // you're connected now, so print out the data
418309 Serial.print (F (" You're connected to the network, IP = " ));
419310 Serial.println (Ethernet.localIP ());
311+ }
312+
313+ void setup ()
314+ {
315+ Serial.begin (115200 );
316+ while (!Serial && millis () < 5000 );
317+
318+ delay (200 );
319+
320+ Serial.print (F (" \n Start RP2040_RTC_Alarm_Ethernet on " )); Serial.print (BOARD_NAME);
321+ Serial.print (F (" with " )); Serial.println (SHIELD_TYPE);
322+ Serial.println (RP2040_RTC_VERSION);
323+ Serial.println (TIMEZONE_GENERIC_VERSION);
324+
325+ initEthernet ();
420326
421327 myTZ = new Timezone (myDST, mySTD);
422328
0 commit comments