Skip to content

Commit 833a9ba

Browse files
BriscoeTechBriscoeTech
BriscoeTech
authored and
BriscoeTech
committed
* commented out non dma function for now. Its function signature conflicts with dma transfer with optional boolean for blocking. I dont know of a instance where the non dma is a requirement or better, so it is commented out for now.
* initialized variables so to avoid constructor error message in sloeber * changed void pointer math to have a explicit type cast to uint8_t, void pointer math was generating compiler error and we know we are doing byte math. * added explicit typecast of null function pointer, this prevents ambiguity on what function signature we are calling and prevents compiler warnings in sloeber
1 parent 858e01d commit 833a9ba

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

libraries/SPI/SPI.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ void SPIClass::transfer(void *buf, size_t count)
235235
}
236236
}
237237

238+
/*
238239
// Non-DMA transfer function.
239240
// this was removed from the dma function and made its own
240241
void SPIClass::transfer(void* txbuf, void* rxbuf, size_t count)
@@ -260,6 +261,7 @@ void SPIClass::transfer(void* txbuf, void* rxbuf, size_t count)
260261
}
261262
}
262263
}
264+
*/
263265

264266
// Pointer to SPIClass object, one per DMA channel.
265267
static SPIClass *spiPtr[DMAC_CH_NUM] = { 0 }; // Legit inits list to NULL
@@ -309,8 +311,9 @@ void SPIClass::checkDmaComplete(uint8_t channel)
309311
// initiate another transfer for the next section of bytes
310312
// update buffer pointers offsets
311313
// use the same user callback as last time if any
312-
void* txbuf = spiPtr[channel]->txbuf_last + DMA_MAX_TRANSFER_SIZE;
313-
void* rxbuf = spiPtr[channel]->rxbuf_last + DMA_MAX_TRANSFER_SIZE;
314+
// (uint8_t*) typecast needed as c does not like pointer math of void*, but we know we are doing byte math
315+
void* txbuf = (uint8_t*)spiPtr[channel]->txbuf_last + DMA_MAX_TRANSFER_SIZE;
316+
void* rxbuf = (uint8_t*)spiPtr[channel]->rxbuf_last + DMA_MAX_TRANSFER_SIZE;
314317
spiPtr[channel]->transfer(txbuf, rxbuf, spiPtr[channel]->dma_bytes_remaining, spiPtr[channel]->userDmaCallback );
315318
}
316319
// the transfer is completed, no bytes remaining
@@ -331,10 +334,10 @@ void SPIClass::checkDmaComplete(uint8_t channel)
331334
}
332335

333336
// dma transfer function for spi with poll for completion
334-
void SPIClass::transfer(const void* txbuf, void* rxbuf, uint32_t count, bool block)
337+
void SPIClass::transfer(void* txbuf, void* rxbuf, uint32_t count, bool block)
335338
{
336339
// start the dma transfer, but do not specify a user callback function, will poll for completion instead
337-
transfer(txbuf, rxbuf, count, NULL);
340+
transfer(txbuf, rxbuf, count, (void (*)(void))NULL );
338341

339342
// if this function should automatically wait for completion, otherwise user must do manually
340343
if(block)

libraries/SPI/SPI.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class SPIClass {
117117
byte transfer(uint8_t data);
118118
uint16_t transfer16(uint16_t data);
119119
void transfer(void *buf, size_t count);
120-
void transfer(void* txbuf, void* rxbuf, size_t count); //non dma
121-
void transfer(const void* txbuf, void* rxbuf, uint32_t count, bool block = true); //dma poll for completion
120+
//void transfer(void* txbuf, void* rxbuf, size_t count); //non dma
121+
void transfer(void* txbuf, void* rxbuf, uint32_t count, bool block); //dma poll for completion
122122
void waitForTransfer(void); //dma poll for completion
123123
void transfer(void* txbuf, void* rxbuf, uint32_t count, void (*functionToCallWhenComplete)(void) ); //dma asynchronous
124124

@@ -180,12 +180,12 @@ class SPIClass {
180180
DmacDescriptor *readDescriptor = NULL;
181181
DmacDescriptor *writeDescriptor = NULL;
182182

183-
volatile bool dma_write_done = false; // true when read dma callback completes
184-
volatile bool dma_read_done = false; // true when write dma callback completes
185-
uint32_t dma_bytes_remaining; // number of bytes remaining for future dma transactions
186-
volatile bool dma_complete = false; // all transactions completed and no bytes remaining
187-
void* txbuf_last; // pointer to buffer last used
188-
void* rxbuf_last; // pointer to buffer last used
183+
volatile bool dma_write_done = false; // true when read dma callback completes
184+
volatile bool dma_read_done = false; // true when write dma callback completes
185+
uint32_t dma_bytes_remaining = 0; // number of bytes remaining for future dma transactions
186+
volatile bool dma_complete = false; // all transactions completed and no bytes remaining
187+
void* txbuf_last = NULL; // pointer to buffer last used
188+
void* rxbuf_last = NULL; // pointer to buffer last used
189189

190190
static void dmaCallback_read(Adafruit_ZeroDMA *dma);
191191
static void dmaCallback_write(Adafruit_ZeroDMA *dma);

libraries/SPI/examples/zerodma_spi1/zerodma_spi1.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ void loop()
104104
// send the command byte
105105
//SPI.transfer(255);
106106

107-
#define DMA_TEST 3 //select the type of dma to test
107+
#define DMA_TEST 1 //select the type of dma to test
108108
#if(DMA_TEST == 1)
109109
// asyncronous dma transfer
110110
// reset the transaction flag
111111
dmaDone = false;
112112

113113
// calls the dma transfer, this call does not block
114-
// will call the callback frunction when the dma is completed
114+
// will call the callback function when the dma is completed
115115
SPI.transfer(send_memory, receive_memory, DATA_LENGTH, callback_dmaDone); //dma
116116

117117
// can do other things here...

0 commit comments

Comments
 (0)