Skip to content

Commit ed9ca41

Browse files
committed
Add support for Teensy 4.1 and the QNEthernet library
1 parent b54a53b commit ed9ca41

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/ConnectionHandlerDefinitions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
#define NETWORK_CONNECTED WL_CONNECTED
145145
#endif
146146

147+
#if defined(ARDUINO_TEENSY41)
148+
#define BOARD_HAS_ETHERNET
149+
#endif
150+
147151
#endif // BOARD_HAS_NOTECARD
148152

149153
/******************************************************************************

src/EthernetConnectionHandler.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,19 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit()
7474

7575
// An ip address is provided -> static ip configuration
7676
if (ip != INADDR_NONE) {
77+
#if defined(ARDUINO_TEENSY41)
78+
if (Ethernet.begin(nullptr, ip,
79+
IPAddress(_settings.eth.dns.type, _settings.eth.dns.bytes),
80+
IPAddress(_settings.eth.gateway.type, _settings.eth.gateway.bytes),
81+
IPAddress(_settings.eth.netmask.type, _settings.eth.netmask.bytes)) == 0) {
82+
#else
7783
if (Ethernet.begin(nullptr, ip,
7884
IPAddress(_settings.eth.dns.type, _settings.eth.dns.bytes),
7985
IPAddress(_settings.eth.gateway.type, _settings.eth.gateway.bytes),
8086
IPAddress(_settings.eth.netmask.type, _settings.eth.netmask.bytes),
8187
_settings.eth.timeout,
8288
_settings.eth.response_timeout) == 0) {
89+
#endif // ARDUINO_TEENSY41
8390

8491
DEBUG_ERROR(F("Failed to configure Ethernet, check cable connection"));
8592
DEBUG_VERBOSE("timeout: %d, response timeout: %d",
@@ -88,7 +95,11 @@ NetworkConnectionState EthernetConnectionHandler::update_handleInit()
8895
}
8996
// An ip address is not provided -> dhcp configuration
9097
} else {
98+
#if defined(ARDUINO_TEENSY41)
99+
if (Ethernet.begin(nullptr, _settings.eth.timeout) == 0) {
100+
#else
91101
if (Ethernet.begin(nullptr, _settings.eth.timeout, _settings.eth.response_timeout) == 0) {
102+
#endif // ARDUINO_TEENSY41
92103
DEBUG_ERROR(F("Waiting Ethernet configuration from DHCP server, check cable connection"));
93104
DEBUG_VERBOSE("timeout: %d, response timeout: %d",
94105
_settings.eth.timeout, _settings.eth.response_timeout);
@@ -110,6 +121,10 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
110121
return NetworkConnectionState::CONNECTED;
111122
}
112123

124+
#if defined(ARDUINO_TEENSY41)
125+
DEBUG_INFO(F("Connected to network"));
126+
return NetworkConnectionState::CONNECTED;
127+
#else
113128
int ping_result = Ethernet.ping("time.arduino.cc");
114129
DEBUG_INFO(F("Ethernet.ping(): %d"), ping_result);
115130
if (ping_result < 0)
@@ -123,6 +138,7 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnecting()
123138
DEBUG_INFO(F("Connected to Internet"));
124139
return NetworkConnectionState::CONNECTED;
125140
}
141+
#endif // ARDUINO_TEENSY41
126142

127143
}
128144

@@ -141,7 +157,11 @@ NetworkConnectionState EthernetConnectionHandler::update_handleConnected()
141157

142158
NetworkConnectionState EthernetConnectionHandler::update_handleDisconnecting()
143159
{
160+
#if defined(ARDUINO_TEENSY41)
161+
Ethernet.end();
162+
#else
144163
Ethernet.disconnect();
164+
#endif
145165
return NetworkConnectionState::DISCONNECTED;
146166
}
147167

src/EthernetConnectionHandler.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#elif defined(ARDUINO_OPTA)
2727
#include <Ethernet.h>
2828
#include <PortentaEthernet.h>
29+
#elif defined(ARDUINO_TEENSY41)
30+
#include <QNEthernet.h>
31+
32+
using namespace qindesign::network;
2933
#endif
3034

3135
#ifndef BOARD_HAS_ETHERNET

0 commit comments

Comments
 (0)