Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SdSpiTeensy3.cpp - Use transfer(tx, rx, size) - avoid 512 bytes on stack #14

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/SpiDriver/SdSpiTeensy3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
#include "SdSpiDriver.h"
#if defined(SD_USE_CUSTOM_SPI) && defined(__arm__) && defined(CORE_TEENSY)
#define USE_BLOCK_TRANSFER 1
#define USE_TRANSFER_TX_RX 1
//------------------------------------------------------------------------------
void SdSpiArduinoDriver::activate() {
m_spi->beginTransaction(m_spiSettings);
Expand Down Expand Up @@ -59,14 +59,13 @@ uint8_t SdSpiArduinoDriver::receive() {
}
//------------------------------------------------------------------------------
uint8_t SdSpiArduinoDriver::receive(uint8_t* buf, size_t count) {
#if USE_BLOCK_TRANSFER
#ifdef USE_TRANSFER_TX_RX
m_spi->setTransferWriteFill(0xff);
m_spi->transfer(nullptr, buf, count);
#else
memset(buf, 0XFF, count);
m_spi->transfer(buf, count);
#else // USE_BLOCK_TRANSFER
for (size_t i = 0; i < count; i++) {
buf[i] = m_spi->transfer(0XFF);
}
#endif // USE_BLOCK_TRANSFER
#endif
return 0;
}
//------------------------------------------------------------------------------
Expand All @@ -75,16 +74,16 @@ void SdSpiArduinoDriver::send(uint8_t data) {
}
//------------------------------------------------------------------------------
void SdSpiArduinoDriver::send(const uint8_t* buf , size_t count) {
#if USE_BLOCK_TRANSFER
#ifdef USE_TRANSFER_TX_RX
m_spi->transfer(buf, nullptr, count);
#else
uint32_t tmp[128];
if (0 < count && count <= 512) {
memcpy(tmp, buf, count);
m_spi->transfer(tmp, count);
return;
}
#endif // USE_BLOCK_TRANSFER
for (size_t i = 0; i < count; i++) {
m_spi->transfer(buf[i]);
}

#endif
}
#endif // defined(SD_USE_CUSTOM_SPI) && defined(__arm__) &&defined(CORE_TEENSY)