Skip to content

Commit f2daaae

Browse files
committed
Allow redefining ETHERNET_MAX_SOCK_NUM, ETHERNET_SPI_SPEED
1 parent 9e8a98c commit f2daaae

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

src/Ethernet.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
// up to 4 sockets. W5200 & W5500 can have up to 8 sockets. Several bytes
3434
// of RAM are used for each socket. Reducing the maximum can save RAM, but
3535
// you are limited to fewer simultaneous connections.
36-
#if defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048)
36+
#if defined(ETHERNET_MAX_SOCK_NUM)
37+
#define MAX_SOCK_NUM ETHERNET_MAX_SOCK_NUM
38+
#elif defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048)
3739
#define MAX_SOCK_NUM 4
3840
#else
3941
#define MAX_SOCK_NUM 8

src/utility/w5100.h

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,28 @@
1717
#include <Arduino.h>
1818
#include <SPI.h>
1919

20-
// Safe for all chips
21-
#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)
22-
23-
// Safe for W5200 and W5500, but too fast for W5100
24-
// Uncomment this if you know you'll never need W5100 support.
25-
// Higher SPI clock only results in faster transfer to hosts on a LAN
26-
// or with very low packet latency. With ordinary internet latency,
27-
// the TCP window size & packet loss determine your overall speed.
28-
//#define SPI_ETHERNET_SETTINGS SPISettings(30000000, MSBFIRST, SPI_MODE0)
20+
#if defined(ETHERNET_SPI_SPEED)
21+
// Good! Using the configured value.
22+
#elif defined(ARDUINO_ARCH_ARC32)
23+
// Arduino 101's SPI can not run faster than 8 MHz.
24+
#define ETHERNET_SPI_SPEED 8000000
25+
#elif defined(__SAMD21G18A__)
26+
// Arduino Zero can't use W5100-based shields faster than 8 MHz
27+
// https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848
28+
// W5500 does seem to work at 12 MHz. Delete this if only using W5500
29+
#define ETHERNET_SPI_SPEED 8000000
30+
#else
31+
// Default. Safe for all chips.
32+
#define ETHERNET_SPI_SPEED 14000000
33+
#endif
2934

35+
#define SPI_ETHERNET_SETTINGS SPISettings(ETHERNET_SPI_SPEED, MSBFIRST, SPI_MODE0)
3036

3137
// Require Ethernet.h, because we need MAX_SOCK_NUM
3238
#ifndef ethernet_h_
3339
#error "Ethernet.h must be included before w5100.h"
3440
#endif
3541

36-
37-
// Arduino 101's SPI can not run faster than 8 MHz.
38-
#if defined(ARDUINO_ARCH_ARC32)
39-
#undef SPI_ETHERNET_SETTINGS
40-
#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0)
41-
#endif
42-
43-
// Arduino Zero can't use W5100-based shields faster than 8 MHz
44-
// https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848
45-
// W5500 does seem to work at 12 MHz. Delete this if only using W5500
46-
#if defined(__SAMD21G18A__)
47-
#undef SPI_ETHERNET_SETTINGS
48-
#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0)
49-
#endif
50-
51-
5242
typedef uint8_t SOCKET;
5343

5444
class SnMR {

0 commit comments

Comments
 (0)