Add non-blocking DMA option in writePixels()

This commit is contained in:
Phillip Burgess 2019-03-17 18:15:27 -07:00
parent b8fd9b4366
commit 1bd0463d15
2 changed files with 43 additions and 9 deletions

View File

@ -865,8 +865,16 @@ void Adafruit_SPITFT::writePixel(int16_t x, int16_t y, uint16_t color) {
@param colors Pointer to array of 16-bit pixel values in '565' RGB
format.
@param len Number of elements in 'colors' array.
@param block If true (default case if unspecified), function blocks
until DMA transfer is complete. This is simply IGNORED
if DMA is not enabled. If false, the function returns
immediately after the last DMA transfer is started,
and one should use the dmaWait() function before
doing ANY other display-related activities (or even any
SPI-related activities, if using an SPI display that
shares the bus with other devices).
*/
void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block) {
if(!len) return; // Avoid 0-byte transfers
@ -917,6 +925,7 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
}
lastFillColor = 0x0000; // pixelBuf has been sullied
lastFillLen = 0;
if(block) {
while(dma_busy); // Wait for last line to complete
#if defined(__SAMD51__)
if(connection == TFT_HARD_SPI) {
@ -926,6 +935,7 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
pinPeripheral(tft8._wr, PIO_OUTPUT); // Switch WR back to GPIO
}
#endif // end __SAMD51__
}
return;
}
#endif // end USE_SPI_DMA
@ -937,6 +947,26 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len) {
}
}
/*!
@brief Wait for the last DMA transfer in a prior non-blocking
writePixels() call to complete. This does nothing if DMA
is not enabled, and is not needed if blocking writePixels()
was used (as is the default case).
*/
void Adafruit_SPITFT::dmaWait(void) {
#if defined(USE_SPI_DMA)
while(dma_busy);
#if defined(__SAMD51__)
if(connection == TFT_HARD_SPI) {
// See SAMD51 note in writeColor()
hwspi._spi->setDataMode(SPI_MODE0);
} else {
pinPeripheral(tft8._wr, PIO_OUTPUT); // Switch WR back to GPIO
}
#endif // end __SAMD51__
#endif
}
/*!
@brief Issue a series of pixels, all the same color. Not self-
contained; should follow startWrite() and setAddrWindow() calls.

View File

@ -191,7 +191,7 @@ class Adafruit_SPITFT : public Adafruit_GFX {
// before ending the transaction. It's more efficient than starting a
// transaction every time.
void writePixel(int16_t x, int16_t y, uint16_t color);
void writePixels(uint16_t *colors, uint32_t len);
void writePixels(uint16_t *colors, uint32_t len, bool block=true);
void writeColor(uint16_t color, uint32_t len);
void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color);
@ -206,6 +206,10 @@ class Adafruit_SPITFT : public Adafruit_GFX {
// CALLING THIS WITH UNCLIPPED OR NEGATIVE VALUES COULD BE DISASTROUS.
inline void writeFillRectPreclipped(int16_t x, int16_t y,
int16_t w, int16_t h, uint16_t color);
// Another new function, companion to the new non-blocking
// writePixels() variant.
void dmaWait(void);
// These functions are similar to the 'write' functions above, but with
// a chip-select and/or SPI transaction built-in. They're typically used