Skip to content

Use SPI.transfer for spiRec where applicable #24

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

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
18 changes: 14 additions & 4 deletions src/utility/Sd2Card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ void spiSend(uint8_t data) {
sei();
}
#endif // SOFTWARE_SPI

void spiRec(uint8_t* data, int size) {
#ifdef USE_SPI_LIB
SDCARD_SPI.transfer(data, size);
#else
while (size) {
*data++ = spiRec();
size--;
}
#endif
}

//------------------------------------------------------------------------------
// send command and return error code. Return zero for OK
uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
Expand Down Expand Up @@ -430,9 +442,7 @@ uint8_t Sd2Card::readData(uint32_t block,
spiRec();
}
// transfer data
for (uint16_t i = 0; i < count; i++) {
dst[i] = spiRec();
}
spiRec(dst, count);
#endif // OPTIMIZE_HARDWARE_SPI

offset_ += count;
Expand Down Expand Up @@ -479,7 +489,7 @@ uint8_t Sd2Card::readRegister(uint8_t cmd, void* buf) {
}
if (!waitStartBlock()) goto fail;
// transfer data
for (uint16_t i = 0; i < 16; i++) dst[i] = spiRec();
spiRec(dst, 16);
spiRec(); // get first crc byte
spiRec(); // get second crc byte
chipSelectHigh();
Expand Down