Skip to content

Commit 8b88806

Browse files
SPI DMA still WIP still not working
1 parent 8f123f3 commit 8b88806

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

libraries/Adafruit_ZeroDMA/Adafruit_ZeroDMA.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ ZeroDMAstatus Adafruit_ZeroDMA::allocate(void) {
250250
return DMA_STATUS_OK;
251251
}
252252

253-
void Adafruit_ZeroDMA::setPriority(dma_priority pri) {
253+
void Adafruit_ZeroDMA::setPriority(dma_priority pri) const {
254254
#ifdef __SAMD51__
255255
DMAC->Channel[channel].CHPRILVL.bit.PRILVL = pri;
256256
#else
@@ -341,7 +341,7 @@ void Adafruit_ZeroDMA::setCallback(
341341
}
342342

343343
// Suspend/resume don't quite do what I thought -- avoid using for now.
344-
void Adafruit_ZeroDMA::suspend(void) {
344+
void Adafruit_ZeroDMA::suspend(void) const {
345345
cpu_irq_enter_critical();
346346
#ifdef __SAMD51__
347347
DMAC->Channel[channel].CHCTRLB.reg |= DMAC_CHCTRLB_CMD_SUSPEND;
@@ -428,12 +428,17 @@ void Adafruit_ZeroDMA::setAction(dma_transfer_trigger_action action) {
428428
}
429429

430430
// Issue software trigger. Channel must be allocated & descriptors added!
431-
void Adafruit_ZeroDMA::trigger(void) {
431+
void Adafruit_ZeroDMA::trigger(void) const {
432432
if((channel <= DMAC_CH_NUM) & hasDescriptors) {
433433
DMAC->SWTRIGCTRL.reg |= (1 << channel);
434434
}
435435
}
436436

437+
// Returns true if DMA transfer in progress.
438+
bool Adafruit_ZeroDMA::isActive(void) const {
439+
return _writeback[channel].BTCTRL.bit.VALID;
440+
}
441+
437442
// DMA DESCRIPTOR FUNCTIONS ------------------------------------------------
438443

439444
// Allocates a new DMA descriptor (if needed) and appends it to the
@@ -610,7 +615,7 @@ void Adafruit_ZeroDMA::loop(boolean flag) {
610615

611616
// MISCELLANY --------------------------------------------------------------
612617

613-
void Adafruit_ZeroDMA::printStatus(ZeroDMAstatus s) {
618+
void Adafruit_ZeroDMA::printStatus(ZeroDMAstatus s) const {
614619
if(s == DMA_STATUS_JOBSTATUS) s = jobStatus;
615620
Serial.print("Status: ");
616621
switch(s) {

libraries/Adafruit_ZeroDMA/Adafruit_ZeroDMA.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ class Adafruit_ZeroDMA {
4848
bool stepSel = DMA_STEPSEL_DST);
4949
void changeDescriptor(DmacDescriptor *d, void *src = NULL,
5050
void *dst = NULL, uint32_t count = 0);
51+
bool isActive(void) const;
5152

5253
void _IRQhandler(uint8_t flags); // DO NOT TOUCH
5354

54-
bool isActive(void) const {
55-
return _writeback[channel].BTCTRL.bit.VALID;
56-
}
5755

5856
protected:
5957
uint8_t channel;

libraries/SPI/SPI.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void SPIClass::transfer(const void* txbuf, void* rxbuf, size_t count,
277277
if(writeChannel.allocate() == DMA_STATUS_OK) {
278278
writeDescriptor =
279279
writeChannel.addDescriptor(
280-
(void *)NULL, // Source address (set later)
280+
NULL, // Source address (set later)
281281
(void *)getDataRegister(), // Dest (SPI data register)
282282
0, // Count (set later)
283283
DMA_BEAT_SIZE_BYTE, // Bytes/hwords/words
@@ -290,11 +290,11 @@ void SPIClass::transfer(const void* txbuf, void* rxbuf, size_t count,
290290
}
291291
}
292292

293-
if(writeDescriptor) { // If this allocated, then use DMA
294-
static uint8_t dum = 0xFF; // Dummy byte for read-only transfers
293+
if(writeDescriptor && (readDescriptor || !rxbuf)) {
294+
static const uint8_t dum = 0xFF; // Dummy byte for read-only xfers
295295

296-
// Initialize read descriptor dest address to rxbuf (even if unused)
297-
readDescriptor->DSTADDR.reg = (uint32_t)rxbuf;
296+
// Initialize read descriptor dest address to rxbuf (even if NULL)
297+
if(readDescriptor) readDescriptor->DSTADDR.reg = (uint32_t)rxbuf;
298298

299299
// If reading only, set up writeDescriptor to issue dummy bytes
300300
// (set SRCADDR to &dum and SRCINC to 0). Otherwise, set SRCADDR

0 commit comments

Comments
 (0)