Skip to content

Commit 2274922

Browse files
committed
Ethernet library now use SPI_HAS_EXTENDED_CS_PIN_HANDLING to detect when Extended SPI API is available
1 parent 419597f commit 2274922

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

libraries/Ethernet/src/utility/w5100.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void W5100Class::init(void)
2626
{
2727
delay(300);
2828

29-
#if defined(ARDUINO_ARCH_AVR)
29+
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
3030
SPI.begin();
3131
initSS();
3232
#else
@@ -136,7 +136,7 @@ void W5100Class::read_data(SOCKET s, volatile uint16_t src, volatile uint8_t *ds
136136

137137
uint8_t W5100Class::write(uint16_t _addr, uint8_t _data)
138138
{
139-
#if defined(ARDUINO_ARCH_AVR)
139+
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
140140
setSS();
141141
SPI.transfer(0xF0);
142142
SPI.transfer(_addr >> 8);
@@ -156,7 +156,7 @@ uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
156156
{
157157
for (uint16_t i=0; i<_len; i++)
158158
{
159-
#if defined(ARDUINO_ARCH_AVR)
159+
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
160160
setSS();
161161
SPI.transfer(0xF0);
162162
SPI.transfer(_addr >> 8);
@@ -177,7 +177,7 @@ uint16_t W5100Class::write(uint16_t _addr, const uint8_t *_buf, uint16_t _len)
177177

178178
uint8_t W5100Class::read(uint16_t _addr)
179179
{
180-
#if defined(ARDUINO_ARCH_AVR)
180+
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
181181
setSS();
182182
SPI.transfer(0x0F);
183183
SPI.transfer(_addr >> 8);
@@ -197,7 +197,7 @@ uint16_t W5100Class::read(uint16_t _addr, uint8_t *_buf, uint16_t _len)
197197
{
198198
for (uint16_t i=0; i<_len; i++)
199199
{
200-
#if defined(ARDUINO_ARCH_AVR)
200+
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
201201
setSS();
202202
SPI.transfer(0x0F);
203203
SPI.transfer(_addr >> 8);

libraries/Ethernet/src/utility/w5100.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#define SPI_CS 10
1616

17-
#if defined(ARDUINO_ARCH_AVR)
17+
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
1818
#define SPI_ETHERNET_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0)
1919
#else
2020
#define SPI_ETHERNET_SETTINGS SPI_CS,SPISettings(4000000, MSBFIRST, SPI_MODE0)
@@ -330,25 +330,25 @@ class W5100Class {
330330
uint16_t RBASE[SOCKETS]; // Rx buffer base address
331331

332332
private:
333-
#if defined(ARDUINO_ARCH_AVR)
334-
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
335-
inline static void initSS() { DDRB |= _BV(4); };
336-
inline static void setSS() { PORTB &= ~_BV(4); };
337-
inline static void resetSS() { PORTB |= _BV(4); };
338-
#elif defined(__AVR_ATmega32U4__)
339-
inline static void initSS() { DDRB |= _BV(6); };
340-
inline static void setSS() { PORTB &= ~_BV(6); };
341-
inline static void resetSS() { PORTB |= _BV(6); };
342-
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
343-
inline static void initSS() { DDRB |= _BV(0); };
344-
inline static void setSS() { PORTB &= ~_BV(0); };
345-
inline static void resetSS() { PORTB |= _BV(0); };
346-
#else
347-
inline static void initSS() { DDRB |= _BV(2); };
348-
inline static void setSS() { PORTB &= ~_BV(2); };
349-
inline static void resetSS() { PORTB |= _BV(2); };
350-
#endif
351-
#endif // ARDUINO_ARCH_AVR
333+
#if !defined(SPI_HAS_EXTENDED_CS_PIN_HANDLING)
334+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
335+
inline static void initSS() { DDRB |= _BV(4); };
336+
inline static void setSS() { PORTB &= ~_BV(4); };
337+
inline static void resetSS() { PORTB |= _BV(4); };
338+
#elif defined(__AVR_ATmega32U4__)
339+
inline static void initSS() { DDRB |= _BV(6); };
340+
inline static void setSS() { PORTB &= ~_BV(6); };
341+
inline static void resetSS() { PORTB |= _BV(6); };
342+
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
343+
inline static void initSS() { DDRB |= _BV(0); };
344+
inline static void setSS() { PORTB &= ~_BV(0); };
345+
inline static void resetSS() { PORTB |= _BV(0); };
346+
#else
347+
inline static void initSS() { DDRB |= _BV(2); };
348+
inline static void setSS() { PORTB &= ~_BV(2); };
349+
inline static void resetSS() { PORTB |= _BV(2); };
350+
#endif
351+
#endif // !SPI_HAS_EXTENDED_CS_PIN_HANDLING
352352
};
353353

354354
extern W5100Class W5100;

0 commit comments

Comments
 (0)