diff --git a/src/Ethernet.h b/src/Ethernet.h index 0045de88..4a883af7 100644 --- a/src/Ethernet.h +++ b/src/Ethernet.h @@ -33,7 +33,9 @@ // up to 4 sockets. W5200 & W5500 can have up to 8 sockets. Several bytes // of RAM are used for each socket. Reducing the maximum can save RAM, but // you are limited to fewer simultaneous connections. -#if defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048) +#if defined(ETHERNET_MAX_SOCK_NUM) +#define MAX_SOCK_NUM ETHERNET_MAX_SOCK_NUM +#elif defined(RAMEND) && defined(RAMSTART) && ((RAMEND - RAMSTART) <= 2048) #define MAX_SOCK_NUM 4 #else #define MAX_SOCK_NUM 8 diff --git a/src/utility/w5100.h b/src/utility/w5100.h index b2e8ec83..a3495e80 100644 --- a/src/utility/w5100.h +++ b/src/utility/w5100.h @@ -17,38 +17,28 @@ #include #include -// Safe for all chips -#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0) - -// Safe for W5200 and W5500, but too fast for W5100 -// Uncomment this if you know you'll never need W5100 support. -// Higher SPI clock only results in faster transfer to hosts on a LAN -// or with very low packet latency. With ordinary internet latency, -// the TCP window size & packet loss determine your overall speed. -//#define SPI_ETHERNET_SETTINGS SPISettings(30000000, MSBFIRST, SPI_MODE0) +#if defined(ETHERNET_SPI_SPEED) + // Good! Using the configured value. +#elif defined(ARDUINO_ARCH_ARC32) + // Arduino 101's SPI can not run faster than 8 MHz. + #define ETHERNET_SPI_SPEED 8000000 +#elif defined(__SAMD21G18A__) + // Arduino Zero can't use W5100-based shields faster than 8 MHz + // https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848 + // W5500 does seem to work at 12 MHz. Delete this if only using W5500 + #define ETHERNET_SPI_SPEED 8000000 +#else + // Default. Safe for all chips. + #define ETHERNET_SPI_SPEED 14000000 +#endif +#define SPI_ETHERNET_SETTINGS SPISettings(ETHERNET_SPI_SPEED, MSBFIRST, SPI_MODE0) // Require Ethernet.h, because we need MAX_SOCK_NUM #ifndef ethernet_h_ #error "Ethernet.h must be included before w5100.h" #endif - -// Arduino 101's SPI can not run faster than 8 MHz. -#if defined(ARDUINO_ARCH_ARC32) -#undef SPI_ETHERNET_SETTINGS -#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0) -#endif - -// Arduino Zero can't use W5100-based shields faster than 8 MHz -// https://github.com/arduino-libraries/Ethernet/issues/37#issuecomment-408036848 -// W5500 does seem to work at 12 MHz. Delete this if only using W5500 -#if defined(__SAMD21G18A__) -#undef SPI_ETHERNET_SETTINGS -#define SPI_ETHERNET_SETTINGS SPISettings(8000000, MSBFIRST, SPI_MODE0) -#endif - - typedef uint8_t SOCKET; class SnMR {