From 8c858c090a2069303338ef33d12738db8e53d638 Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Wed, 20 Jul 2022 17:15:40 -0700 Subject: [PATCH] Enable DMA by default on all SAMD boards --- library.properties | 2 +- src/Adafruit_SPITFT.cpp | 22 ++++++++++------------ src/Adafruit_SPITFT.h | 26 +++++++------------------- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/library.properties b/library.properties index 355e170..5ed8427 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit GFX Library -version=1.11.3 +version=1.12.0 author=Adafruit maintainer=Adafruit sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from. diff --git a/src/Adafruit_SPITFT.cpp b/src/Adafruit_SPITFT.cpp index 2c8ef01..ced9573 100644 --- a/src/Adafruit_SPITFT.cpp +++ b/src/Adafruit_SPITFT.cpp @@ -51,8 +51,7 @@ #define digitalPinToPort(P) (&(PORT_IOBUS->Group[g_APinDescription[P].ulPort])) #endif // end PORT_IOBUS -#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) -// #pragma message ("GFX DMA IS ENABLED. HIGHLY EXPERIMENTAL.") +#if defined(USE_SAMD_DMA) #include "wiring_private.h" // pinPeripheral() function #include #include // memalign() function @@ -89,7 +88,7 @@ static const struct { #define NUM_TIMERS (sizeof tcList / sizeof tcList[0]) ///< # timer/counters #endif // end __SAMD51__ -#endif // end USE_SPI_DMA +#endif // end USE_SAMD_DMA // Possible values for Adafruit_SPITFT.connection: #define TFT_HARD_SPI 0 ///< Display interface = hardware SPI @@ -649,7 +648,7 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { delay(200); } -#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) +#if defined(USE_SAMD_DMA) if (((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) && (dma.allocate() == DMA_STATUS_OK)) { // Allocate channel // The DMA library needs to alloc at least one valid descriptor, @@ -887,7 +886,7 @@ void Adafruit_SPITFT::initSPI(uint32_t freq, uint8_t spiMode) { } // end addDescriptor() dma.free(); // Deallocate DMA channel } -#endif // end USE_SPI_DMA +#endif // end USE_SAMD_DMA } /*! @@ -1037,8 +1036,7 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block, spi_write_blocking(pi_spi, (uint8_t *)colors, len * 2); } return; -#elif defined(USE_SPI_DMA) && \ - (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) +#elif defined(USE_SAMD_DMA) if ((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) { int maxSpan = maxFillLen / 2; // One scanline max uint8_t pixelBufIdx = 0; // Active pixel buffer number @@ -1127,7 +1125,7 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block, } return; } -#endif // end USE_SPI_DMA +#endif // end USE_SAMD_DMA // All other cases (bitbang SPI or non-DMA hard SPI or parallel), // use a loop with the normal 16-bit data write function: @@ -1157,7 +1155,7 @@ void Adafruit_SPITFT::writePixels(uint16_t *colors, uint32_t len, bool block, was used (as is the default case). */ void Adafruit_SPITFT::dmaWait(void) { -#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) +#if defined(USE_SAMD_DMA) while (dma_busy) ; #if defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO) @@ -1177,7 +1175,7 @@ void Adafruit_SPITFT::dmaWait(void) { @return true if DMA is enabled and transmitting data, false otherwise. */ bool Adafruit_SPITFT::dmaBusy(void) const { -#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) +#if defined(USE_SAMD_DMA) return dma_busy; #else return false; @@ -1245,7 +1243,7 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) { return; } #else // !ESP32 -#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) +#if defined(USE_SAMD_DMA) if (((connection == TFT_HARD_SPI) || (connection == TFT_PARALLEL)) && (len >= 16)) { // Don't bother with DMA on short pixel runs int i, d, numDescriptors; @@ -1336,7 +1334,7 @@ void Adafruit_SPITFT::writeColor(uint16_t color, uint32_t len) { #endif // end __SAMD51__ return; } -#endif // end USE_SPI_DMA +#endif // end USE_SAMD_DMA #endif // end !ESP32 // All other cases (non-DMA hard SPI, bitbang SPI, parallel)... diff --git a/src/Adafruit_SPITFT.h b/src/Adafruit_SPITFT.h index 3746d82..54e1be0 100644 --- a/src/Adafruit_SPITFT.h +++ b/src/Adafruit_SPITFT.h @@ -30,8 +30,8 @@ typedef uint8_t ADAGFX_PORT_t; ///< PORT values are 8-bit #define USE_FAST_PINIO ///< Use direct PORT register access #elif defined(ARDUINO_STM32_FEATHER) // WICED -typedef class HardwareSPI SPIClass; ///< SPI is a bit odd on WICED -typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit +typedef class HardwareSPI SPIClass; ///< SPI is a bit odd on WICED +typedef uint32_t ADAGFX_PORT_t; ///< PORT values are 32-bit #elif defined(__arm__) #if defined(ARDUINO_ARCH_SAMD) // Adafruit M0, M4 @@ -70,26 +70,16 @@ typedef volatile ADAGFX_PORT_t *PORTreg_t; ///< PORT register type #define DEFAULT_SPI_FREQ 16000000L ///< Hardware SPI default speed #endif -#if defined(ADAFRUIT_PYPORTAL) || defined(ADAFRUIT_PYPORTAL_M4_TITANO) || \ - defined(ADAFRUIT_PYBADGE_M4_EXPRESS) || \ - defined(ADAFRUIT_PYGAMER_M4_EXPRESS) || \ - defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) || defined(NRF52_SERIES) || \ - defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) -#define USE_SPI_DMA ///< Auto DMA -#else - //#define USE_SPI_DMA ///< If set, - // use DMA if available +#if defined(__SAMD51__) || defined(SAM_D5X_E5X) || defined(_SAMD21_) || \ + defined(SAMD21) || defined(ARDUINO_SAMD_ZERO) +#define USE_SAMD_DMA ///< Enable DMA on ALL SAMD boards now, not a list +#include #endif -// Another "oops" name -- this now also handles parallel DMA. // If DMA is enabled, Arduino sketch MUST #include // Estimated RAM usage: // 4 bytes/pixel on display major axis + 8 bytes/pixel on minor axis, // e.g. 320x240 pixels = 320 * 4 + 240 * 8 = 3,200 bytes. -#if defined(USE_SPI_DMA) && (defined(__SAMD51__) || defined(ARDUINO_SAMD_ZERO)) -#include -#endif - // This is kind of a kludge. Needed a way to disambiguate the software SPI // and parallel constructors via their argument lists. Originally tried a // bool as the first argument to the parallel constructor (specifying 8-bit @@ -487,9 +477,7 @@ protected: #if defined(__cplusplus) && (__cplusplus >= 201100) }; ///< Only one interface is active #endif -#if defined(USE_SPI_DMA) && \ - (defined(__SAMD51__) || \ - defined(ARDUINO_SAMD_ZERO)) // Used by hardware SPI and tft8 +#if defined(USE_SAMD_DMA) // Used by hardware SPI and tft8 Adafruit_ZeroDMA dma; ///< DMA instance DmacDescriptor *dptr = NULL; ///< 1st descriptor DmacDescriptor *descriptor = NULL; ///< Allocated descriptor list