Skip to content

Commit 4d2f64a

Browse files
Add bidirectional bulk SPI transfer, update SdFAT (earlephilhower#819)
Should speed up SD transfers significantly (2.5x+). See earlephilhower#801
1 parent 9997461 commit 4d2f64a

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

cores/rp2040/api/HardwareSPI.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ class HardwareSPI
110110
virtual uint16_t transfer16(uint16_t data) = 0;
111111
virtual void transfer(void *buf, size_t count) = 0;
112112

113+
// New transfer API. If either send or recv == nullptr then ignore it
114+
virtual void transfer(const void *send, void *recv, size_t count) {
115+
const uint8_t *out = (const uint8_t *)send;
116+
uint8_t *in = (uint8_t *)recv;
117+
for (size_t i = 0; i < count; i++) {
118+
uint8_t t = out ? *(out++) : 0xff;
119+
t = transfer(t);
120+
if (in) {
121+
*(in++) = t;
122+
}
123+
}
124+
}
125+
113126
// Transaction Functions
114127
virtual void usingInterrupt(int interruptNumber) = 0;
115128
virtual void notUsingInterrupt(int interruptNumber) = 0;

libraries/SPI/src/SPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ void SPIClassRP2040::transfer(void *buf, size_t count) {
141141
DEBUGSPI("SPI::transfer completed\n");
142142
}
143143

144-
void SPIClassRP2040::transfer(void *txbuf, void *rxbuf, size_t count) {
144+
void SPIClassRP2040::transfer(const void *txbuf, void *rxbuf, size_t count) {
145145
if (!_initted) {
146146
return;
147147
}
148148

149149
DEBUGSPI("SPI::transfer(%p, %p, %d)\n", txbuf, rxbuf, count);
150-
uint8_t *txbuff = reinterpret_cast<uint8_t *>(txbuf);
150+
const uint8_t *txbuff = reinterpret_cast<const uint8_t *>(txbuf);
151151
uint8_t *rxbuff = reinterpret_cast<uint8_t *>(rxbuf);
152152

153153
// MSB version is easy!

libraries/SPI/src/SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class SPIClassRP2040 : public arduino::HardwareSPI {
3636
void transfer(void *buf, size_t count) override;
3737

3838
// Sends one buffer and receives into another, much faster! can set rx or txbuf to NULL
39-
void transfer(void *txbuf, void *rxbuf, size_t count);
39+
void transfer(const void *txbuf, void *rxbuf, size_t count) override;
4040

4141
// Call before/after every complete transaction
4242
void beginTransaction(SPISettings settings) override;

0 commit comments

Comments
 (0)