Skip to content

Commit 512fde0

Browse files
authored
Merge pull request #77 from monroewilliams/master
Faster hardware SPI writes on SAMD
2 parents 92b460c + 5efa09d commit 512fde0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Adafruit_SPIDevice.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,22 @@ bool Adafruit_SPIDevice::write(uint8_t *buffer, size_t len,
312312
_spi->transferBytes(buffer, nullptr, len);
313313
}
314314
} else
315+
#elif defined(ARDUINO_ARCH_SAMD) && defined(_ADAFRUIT_ZERODMA_H_)
316+
// The variant of transfer() used below currently only exists in the Adafruit
317+
// core. It causes a build failure when building against the main Arduino SAMD
318+
// core. Unfortunately there doesn't seem to be a supported #define that this
319+
// code can use to tell which core it's building against. This hack (checking
320+
// for the include guard that gets defined when the Adafruit core's SPI.h
321+
// includes Adafruit_ZeroDMA.h) works for now, but it should be improved when
322+
// possible.
323+
if (_spi) {
324+
if (prefix_len > 0) {
325+
_spi->transfer(prefix_buffer, nullptr, prefix_len);
326+
}
327+
if (len > 0) {
328+
_spi->transfer(buffer, nullptr, len);
329+
}
330+
} else
315331
#endif
316332
{
317333
for (size_t i = 0; i < prefix_len; i++) {
@@ -417,6 +433,19 @@ bool Adafruit_SPIDevice::write_then_read(uint8_t *write_buffer,
417433
_spi->transferBytes(write_buffer, nullptr, write_len);
418434
}
419435
} else
436+
#elif defined(ARDUINO_ARCH_SAMD) && defined(_ADAFRUIT_ZERODMA_H_)
437+
// The variant of transfer() used below currently only exists in the Adafruit
438+
// core. It causes a build failure when building against the main Arduino SAMD
439+
// core. Unfortunately there doesn't seem to be a supported #define that this
440+
// code can use to tell which core it's building against. This hack (checking
441+
// for the include guard that gets defined when the Adafruit core's SPI.h
442+
// includes Adafruit_ZeroDMA.h) works for now, but it should be improved when
443+
// possible.
444+
if (_spi) {
445+
if (write_len > 0) {
446+
_spi->transfer(write_buffer, nullptr, write_len);
447+
}
448+
} else
420449
#endif
421450
{
422451
for (size_t i = 0; i < write_len; i++) {

0 commit comments

Comments
 (0)