Skip to content

Commit 8f123f3

Browse files
SPI DMA WIP and still not working :/
1 parent 99b90ff commit 8f123f3

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

libraries/SPI/SPI.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void SPIClass::transfer(void *buf, size_t count)
236236
}
237237

238238
// Pointer to SPIClass object, one per DMA channel.
239-
static SPIClass *spiPtr[DMAC_CH_NUM] = { 0 }; // Inits list to NULL
239+
static SPIClass *spiPtr[DMAC_CH_NUM] = { 0 }; // Legit inits list to NULL
240240

241241
void SPIClass::dmaCallback(Adafruit_ZeroDMA *dma) {
242242
// dmaCallback() receives an Adafruit_ZeroDMA object. From this we can get
@@ -247,7 +247,7 @@ void SPIClass::dmaCallback(Adafruit_ZeroDMA *dma) {
247247
}
248248

249249
void SPIClass::transfer(const void* txbuf, void* rxbuf, size_t count,
250-
bool background) {
250+
bool block) {
251251

252252
// If receiving data and the RX DMA channel is not yet allocated...
253253
if(rxbuf && (readChannel.getChannel() >= DMAC_CH_NUM)) {
@@ -312,20 +312,20 @@ void SPIClass::transfer(const void* txbuf, void* rxbuf, size_t count,
312312
// We could set up a descriptor chain, but that gets more
313313
// complex. For now, instead, break up long transfers into
314314
// chunks of 65,535 bytes max...these transfers are all
315-
// blocking, regardless of the "background" argument, except
315+
// blocking, regardless of the "block" argument, except
316316
// for the last one which will observe the background request.
317317
// The fractional part is done first, so for any "partially
318-
// backgrounded" transfers like these at least it's the
319-
// largest single-descriptor transfer possible that occurs
320-
// in the background, rather than the tail end.
318+
// blocking" transfers like these at least it's the largest
319+
// single-descriptor transfer possible that occurs in the
320+
// background, rather than the tail end.
321321
int bytesThisPass;
322-
bool block;
322+
bool blockThisPass;
323323
if(count > 65535) { // Too big for 1 descriptor
324-
block = true;
324+
blockThisPass = true;
325325
bytesThisPass = count % 65535; // Fractional part
326326
if(!bytesThisPass) bytesThisPass = 65535;
327327
} else {
328-
block = !background;
328+
blockThisPass = block;
329329
bytesThisPass = count;
330330
}
331331

@@ -353,7 +353,7 @@ void SPIClass::transfer(const void* txbuf, void* rxbuf, size_t count,
353353
dma_busy = true;
354354
writeChannel.startJob();
355355
count -= bytesThisPass;
356-
if(block) {
356+
if(blockThisPass) {
357357
while(dma_busy);
358358
}
359359
}

libraries/SPI/SPI.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class SPIClass {
116116
uint16_t transfer16(uint16_t data);
117117
void transfer(void *buf, size_t count);
118118
void transfer(const void* txbuf, void* rxbuf, size_t count,
119-
bool background = false);
119+
bool block = true);
120120
void waitForTransfer(void);
121121

122122
// Transaction Functions
@@ -167,9 +167,9 @@ class SPIClass {
167167
char interruptSave;
168168
uint32_t interruptMask;
169169

170-
// transfer(txbuf, rxbuf, count, background) uses DMA if possible
171-
Adafruit_ZeroDMA writeChannel,
172-
readChannel;
170+
// transfer(txbuf, rxbuf, count, block) uses DMA if possible
171+
Adafruit_ZeroDMA readChannel,
172+
writeChannel;
173173
DmacDescriptor *readDescriptor = NULL,
174174
*writeDescriptor = NULL;
175175
volatile bool dma_busy = false;

0 commit comments

Comments
 (0)