Skip to content

Commit 3dee632

Browse files
committed
w5100: use SPI transfer buf
Performance increase as suggested by @jayzakk here: arduino-libraries#145
1 parent 1b6f90c commit 3dee632

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/utility/w5100.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,14 @@ uint16_t W5100Class::read(uint16_t addr, uint8_t *buf, uint16_t len)
412412
cmd[1] = addr & 0xFF;
413413
cmd[2] = (len >> 8) & 0x7F;
414414
cmd[3] = len & 0xFF;
415+
#ifdef SPI_HAS_TRANSFER_BUF
416+
_spibus.transfer(cmd, nullptr, 4);
417+
_spibus.transfer(nullptr, buf, len);
418+
#else
415419
_spibus.transfer(cmd, 4);
416420
memset(buf, 0, len);
417421
_spibus.transfer(buf, len);
422+
#endif
418423
resetSS();
419424
} else { // chip == 55
420425
setSS();
@@ -456,9 +461,14 @@ uint16_t W5100Class::read(uint16_t addr, uint8_t *buf, uint16_t len)
456461
cmd[2] = ((addr >> 6) & 0xE0) | 0x18; // 2K buffers
457462
#endif
458463
}
464+
#ifdef SPI_HAS_TRANSFER_BUF
465+
_spibus.transfer(cmd, nullptr, 3);
466+
_spibus.transfer(nullptr, buf, len);
467+
#else
459468
_spibus.transfer(cmd, 3);
460469
memset(buf, 0, len);
461470
_spibus.transfer(buf, len);
471+
#endif
462472
resetSS();
463473
}
464474
return len;

src/utility/w5100.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
#include <SPI.h>
1919

2020
// Safe for all chips
21-
#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)
21+
//#define SPI_ETHERNET_SETTINGS SPISettings(14000000, MSBFIRST, SPI_MODE0)
2222

2323
// Safe for W5200 and W5500, but too fast for W5100
2424
// Uncomment this if you know you'll never need W5100 support.
2525
// Higher SPI clock only results in faster transfer to hosts on a LAN
2626
// or with very low packet latency. With ordinary internet latency,
2727
// the TCP window size & packet loss determine your overall speed.
28-
//#define SPI_ETHERNET_SETTINGS SPISettings(30000000, MSBFIRST, SPI_MODE0)
28+
#define SPI_ETHERNET_SETTINGS SPISettings(30000000, MSBFIRST, SPI_MODE0)
2929

3030

3131
// Require Ethernet.h, because we need MAX_SOCK_NUM

0 commit comments

Comments
 (0)