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

Commit 0e5f1fa

Browse files
authored
v1.3.1 to add support to Teensy 4.1
### Releases v1.3.1 1. Add QNEthernet and NativeEthernet
1 parent 83edb3d commit 0e5f1fa

File tree

10 files changed

+312
-203
lines changed

10 files changed

+312
-203
lines changed

changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.3.1](#releases-v131)
1516
* [Releases v1.3.0](#releases-v130)
1617
* [Releases v1.2.3](#releases-v123)
1718
* [Releases v1.2.2](#releases-v122)
@@ -25,6 +26,10 @@
2526

2627
## Changelog
2728

29+
### Releases v1.3.1
30+
31+
1. Add support to Teensy 4.1 QNEthernet and NativeEthernet
32+
2833
### Releases v1.3.0
2934

3035
1. Add support to `Portenta_H7 Ethernet and WiFi`

examples/Alarm/Ethernet/Alarm_Ethernet/Alarm_Ethernet.ino

+61-16
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ void getNTPTime(void)
7878
if (!gotCurrentTime)
7979
{
8080
sendNTPpacket(timeServer); // send an NTP packet to a time server
81-
// wait to see if a reply is available
82-
delay(1000);
81+
82+
// wait for a reply for UDP_TIMEOUT miliseconds
83+
static unsigned long startMs = millis();
84+
85+
while (!Udp.available() && (millis() - startMs) < UDP_TIMEOUT) {}
8386

8487
if (Udp.parsePacket())
8588
{
@@ -248,7 +251,7 @@ void setup()
248251
Serial.println(DS323X_GENERIC_VERSION);
249252

250253
#if defined(PIN_WIRE_SDA)
251-
// Arduino core, ESP8266, Adafruit
254+
// Arduino core, ESP8266, Adafruit, Teensy
252255
TZ_LOGWARN(F("Default DS323X pinout:"));
253256
TZ_LOGWARN1(F("SDA:"), PIN_WIRE_SDA);
254257
TZ_LOGWARN1(F("SCL:"), PIN_WIRE_SCL);
@@ -270,6 +273,8 @@ void setup()
270273
TZ_LOGWARN(F("======== USE_PORTENTA_H7_ETHERNET ========"));
271274
#elif USE_NATIVE_ETHERNET
272275
TZ_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));
276+
#elif USE_QN_ETHERNET
277+
TZ_LOGWARN(F("======== USE_QN_ETHERNET ========"));
273278
#elif USE_ETHERNET_GENERIC
274279
TZ_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
275280
#elif USE_ETHERNET_ESP8266
@@ -280,7 +285,7 @@ void setup()
280285
TZ_LOGWARN(F("========================="));
281286
#endif
282287

283-
#if !(USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7)
288+
#if !(USE_NATIVE_ETHERNET || USE_QN_ETHERNET || USE_ETHERNET_PORTENTA_H7)
284289
TZ_LOGWARN(F("Default SPI pinout:"));
285290
TZ_LOGWARN1(F("MOSI:"), MOSI);
286291
TZ_LOGWARN1(F("MISO:"), MISO);
@@ -389,7 +394,7 @@ void setup()
389394
#endif
390395

391396
// For other boards, to change if necessary
392-
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )
397+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
393398
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
394399

395400
Ethernet.init (USE_THIS_SS_PIN);
@@ -404,16 +409,9 @@ void setup()
404409

405410
#endif // defined(ESP8266)
406411

407-
#endif // #if !(USE_NATIVE_ETHERNET)
408-
409-
410-
// start the ethernet connection and the server:
411-
// Use DHCP dynamic IP and random mac
412-
uint16_t index = millis() % NUMBER_OF_MAC;
413-
// Use Static IP
414-
//Ethernet.begin(mac[index], ip);
415-
Ethernet.begin(mac[index]);
412+
#endif // #if !(USE_NATIVE_ETHERNET || USE_QN_ETHERNET || USE_ETHERNET_PORTENTA_H7)
416413

414+
#if !(USE_NATIVE_ETHERNET || USE_QN_ETHERNET || USE_ETHERNET_PORTENTA_H7)
417415
// Just info to know how to connect correctly
418416
Serial.println(F("========================="));
419417
Serial.println(F("Currently Used SPI pinout:"));
@@ -426,9 +424,56 @@ void setup()
426424
Serial.print(F("SS:"));
427425
Serial.println(SS);
428426
Serial.println(F("========================="));
427+
#endif
428+
429+
#if (USE_QN_ETHERNET)
430+
#define USING_DHCP true
431+
432+
#if USING_DHCP
433+
// Start the Ethernet connection, using DHCP
434+
Serial.print("Initialize QNEthernet using DHCP => ");
435+
Ethernet.begin();
436+
#else
437+
// Start the Ethernet connection, using static IP
438+
Serial.print("Initialize QNEthernet using static IP => ");
439+
Ethernet.begin(myIP, myNetmask, myGW);
440+
Ethernet.setDNSServerIP(mydnsServer);
441+
#endif
442+
443+
if (!Ethernet.waitForLocalIP(5000))
444+
{
445+
Serial.println(F("Failed to configure Ethernet"));
446+
447+
if (!Ethernet.linkStatus())
448+
{
449+
Serial.println(F("Ethernet cable is not connected."));
450+
}
451+
452+
// Stay here forever
453+
while (true)
454+
{
455+
delay(1);
456+
}
457+
}
458+
459+
if (!Ethernet.waitForLink(5000))
460+
{
461+
Serial.println(F("Failed to wait for Link"));
462+
}
463+
464+
#else
465+
466+
// start the ethernet connection and the server:
467+
// Use DHCP dynamic IP and random mac
468+
uint16_t index = millis() % NUMBER_OF_MAC;
469+
// Use Static IP
470+
//Ethernet.begin(mac[index], myIP);
471+
Ethernet.begin(mac[index]);
429472

430473
Serial.print(F("Using mac index = "));
431474
Serial.println(index);
475+
476+
#endif
432477

433478
// you're connected now, so print out the data
434479
Serial.print(F("You're connected to the network, IP = "));
@@ -453,7 +498,7 @@ void setAlarm(void)
453498
// Valid when RTC is already correct
454499
DateTime currentTime = rtc.now();
455500

456-
time_t utc = currentTime.get_time_t();
501+
time_t utc = currentTime.get_time_t();
457502

458503
// Alarm 1 time is 30s from now
459504
DateTime alarm1 = DateTime(utc + 30);
@@ -470,7 +515,7 @@ void setAlarm(void)
470515
void loop()
471516
{
472517
// Get time from NTP once, then update RTC
473-
// You certainly can make NTP check every hour/day to update RTC ti have better accuracy
518+
// You certainly can make NTP check every hour/day to update RTC to have better accuracy
474519
getNTPTime();
475520

476521
if (!setAlarmDone && gotCurrentTime)

examples/Alarm/Ethernet/Alarm_Ethernet/defines.h

+83-81
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// Debug Level from 0 to 4
1616
#define _ETHERNET_WEBSERVER_LOGLEVEL_ 3
17-
#define _TZ_LOGLEVEL_ 1
17+
#define _TZ_LOGLEVEL_ 2
1818

1919
#if ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) )
2020

@@ -227,7 +227,8 @@
227227
#if defined(ARDUINO_TEENSY41)
228228
#define BOARD_TYPE "TEENSY 4.1"
229229
// Use true for NativeEthernet Library, false if using other Ethernet libraries
230-
#define USE_NATIVE_ETHERNET true
230+
#define USE_QN_ETHERNET true
231+
#define USE_NATIVE_ETHERNET false
231232
#elif defined(ARDUINO_TEENSY40)
232233
#define BOARD_TYPE "TEENSY 4.0"
233234
#else
@@ -319,9 +320,6 @@
319320

320321
#include <SPI.h>
321322

322-
//#define USE_ETHERNET_WRAPPER true
323-
#define USE_ETHERNET_WRAPPER false
324-
325323
// Use true for ENC28J60 and UIPEthernet library (https://github.com/UIPEthernet/UIPEthernet)
326324
// Use false for W5x00 and Ethernetx library (https://www.arduino.cc/en/Reference/Ethernet)
327325

@@ -342,91 +340,93 @@
342340
#define USE_ETHERNET_ESP8266 false
343341
#define USE_ETHERNET_ENC false
344342
#define USE_CUSTOM_ETHERNET false
345-
346-
#if !USE_ETHERNET_WRAPPER
347-
348-
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || \
349-
USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7 )
350-
#ifdef USE_CUSTOM_ETHERNET
351-
#undef USE_CUSTOM_ETHERNET
352-
#endif
353-
#define USE_CUSTOM_ETHERNET false
343+
344+
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ESP8266 || USE_ETHERNET_ENC || \
345+
USE_NATIVE_ETHERNET || USE_QN_ETHERNET || USE_ETHERNET_PORTENTA_H7 )
346+
#ifdef USE_CUSTOM_ETHERNET
347+
#undef USE_CUSTOM_ETHERNET
354348
#endif
349+
#define USE_CUSTOM_ETHERNET false
350+
#endif
355351

356-
#if USE_ETHERNET_PORTENTA_H7
357-
#include <Portenta_Ethernet.h>
358-
#include <Ethernet.h>
359-
#warning Using Portenta_Ethernet lib for Portenta_H7.
360-
#define SHIELD_TYPE "Ethernet using Portenta_Ethernet Library"
361-
#elif USE_NATIVE_ETHERNET
362-
#include "NativeEthernet.h"
363-
#warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
364-
#define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library"
365-
#elif USE_ETHERNET_GENERIC
366-
#if (ESP32)
367-
#include <soc/spi_pins.h>
368-
369-
// Optional SPI2
370-
#define USING_SPI2 true
371-
372-
#if USING_SPI2
373-
#define PIN_MISO HSPI_IOMUX_PIN_NUM_MISO
374-
#define PIN_MOSI HSPI_IOMUX_PIN_NUM_MOSI
375-
#define PIN_SCK HSPI_IOMUX_PIN_NUM_CLK
376-
#define PIN_SS HSPI_IOMUX_PIN_NUM_CS
352+
#if USE_ETHERNET_PORTENTA_H7
353+
#include <Portenta_Ethernet.h>
354+
#include <Ethernet.h>
355+
#warning Using Portenta_Ethernet lib for Portenta_H7.
356+
#define SHIELD_TYPE "Ethernet using Portenta_Ethernet Library"
357+
#elif USE_QN_ETHERNET
358+
#include "QNEthernet.h" // https://github.com/ssilverman/QNEthernet
359+
using namespace qindesign::network;
360+
#warning Using QNEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
361+
#define SHIELD_TYPE "QNEthernet"
362+
#elif USE_NATIVE_ETHERNET
363+
#include "NativeEthernet.h"
364+
#warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error
365+
#define SHIELD_TYPE "NativeEthernet"
366+
#elif USE_ETHERNET_GENERIC
367+
#if (ESP32)
368+
#include <soc/spi_pins.h>
377369

378-
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI2"
379-
380-
#else
381-
382-
#define PIN_MISO MISO
383-
#define PIN_MOSI MOSI
384-
#define PIN_SCK SCK
385-
#define PIN_SS SS
370+
// Optional SPI2
371+
#define USING_SPI2 true
372+
373+
#if USING_SPI2
374+
#define PIN_MISO HSPI_IOMUX_PIN_NUM_MISO
375+
#define PIN_MOSI HSPI_IOMUX_PIN_NUM_MOSI
376+
#define PIN_SCK HSPI_IOMUX_PIN_NUM_CLK
377+
#define PIN_SS HSPI_IOMUX_PIN_NUM_CS
378+
379+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI2"
386380

387-
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI"
388-
389-
#endif
390-
391381
#else
392-
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
382+
383+
#define PIN_MISO MISO
384+
#define PIN_MOSI MOSI
385+
#define PIN_SCK SCK
386+
#define PIN_SS SS
387+
388+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI"
389+
393390
#endif
394391

395-
#define ETHERNET_LARGE_BUFFERS
396-
397-
#define _ETG_LOGLEVEL_ 1
398-
399-
#include "Ethernet_Generic.h"
400-
#warning Using Ethernet_Generic lib
401-
402-
#elif USE_ETHERNET_ESP8266
403-
#include "Ethernet_ESP8266.h"
404-
#warning Using Ethernet_ESP8266 lib
405-
#define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library"
406-
#elif USE_ETHERNET_ENC
407-
#include "EthernetENC.h"
408-
#warning Using EthernetENC lib
409-
#define SHIELD_TYPE "ENC28J60 using EthernetENC Library"
410-
#elif USE_CUSTOM_ETHERNET
411-
//#include "Ethernet_XYZ.h"
412-
#include "EthernetENC.h"
413-
#warning Using Custom Ethernet library. You must include a library and initialize.
414-
#define SHIELD_TYPE "Custom Ethernet using Ethernet_XYZ Library"
415392
#else
416-
#ifdef USE_ETHERNET_GENERIC
417-
#undef USE_ETHERNET_GENERIC
418-
#endif
419-
#define USE_ETHERNET_GENERIC true
420-
#include "Ethernet_Generic.h"
421-
#warning Using default Ethernet_Generic lib
422-
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
393+
#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library"
423394
#endif
395+
396+
#define ETHERNET_LARGE_BUFFERS
397+
398+
#define _ETG_LOGLEVEL_ 1
424399

425-
// Ethernet_Shield_W5200, EtherCard, EtherSia not supported
426-
// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET
427-
// Otherwise, standard Ethernet library will be used for W5x00
400+
#include "Ethernet_Generic.h"
401+
#warning Using Ethernet_Generic lib
402+
403+
#elif USE_ETHERNET_ESP8266
404+
#include "Ethernet_ESP8266.h"
405+
#warning Using Ethernet_ESP8266 lib
406+
#define SHIELD_TYPE "W5x00 using Ethernet_ESP8266 Library"
407+
#elif USE_ETHERNET_ENC
408+
#include "EthernetENC.h"
409+
#warning Using EthernetENC lib
410+
#define SHIELD_TYPE "ENC28J60 using EthernetENC Library"
411+
#elif USE_CUSTOM_ETHERNET
412+
//#include "Ethernet_XYZ.h"
413+
#include "EthernetENC.h"
414+
#warning Using Custom Ethernet library. You must include a library and initialize.
415+
#define SHIELD_TYPE "Custom Ethernet using Ethernet_XYZ Library"
416+
#else
417+
#ifdef USE_ETHERNET_GENERIC
418+
#undef USE_ETHERNET_GENERIC
419+
#endif
420+
#define USE_ETHERNET_GENERIC true
421+
#include "Ethernet_Generic.h"
422+
#warning Using default Ethernet_Generic lib
423+
#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"
424+
#endif
425+
426+
// Ethernet_Shield_W5200, EtherCard, EtherSia not supported
427+
// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET
428+
// Otherwise, standard Ethernet library will be used for W5x00
428429

429-
#endif // USE_ETHERNET_WRAPPER
430430
#elif USE_UIP_ETHERNET
431431
#include "UIPEthernet.h"
432432
#warning Using UIPEthernet library
@@ -467,9 +467,11 @@ byte mac[][NUMBER_OF_MAC] =
467467
};
468468

469469
// Select the IP address according to your local network
470-
IPAddress ip(192, 168, 2, 222);
470+
IPAddress myIP(192, 168, 2, 222);
471+
IPAddress myNetmask(255, 255, 255, 0);
472+
IPAddress myGW(192, 168, 2, 1);
471473

472474
// Google DNS Server IP
473-
IPAddress myDns(8, 8, 8, 8);
475+
IPAddress mydnsServer(8, 8, 8, 8);
474476

475477
#endif //defines_h

0 commit comments

Comments
 (0)