From 1b54ce87e90865c1f20d8f1aa82108bc64168743 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Fri, 11 Dec 2020 21:10:12 +0000 Subject: [PATCH] Optional ESP32 DMA engine control of TFT_CS This change has no impact on examples See also #850 --- Processors/TFT_eSPI_ESP32.c | 8 ++++++-- Processors/TFT_eSPI_STM32.c | 4 +++- TFT_eSPI.h | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Processors/TFT_eSPI_ESP32.c b/Processors/TFT_eSPI_ESP32.c index 3df895c..0205dc1 100644 --- a/Processors/TFT_eSPI_ESP32.c +++ b/Processors/TFT_eSPI_ESP32.c @@ -665,7 +665,7 @@ void IRAM_ATTR dc_callback(spi_transaction_t *spi_tx) ** Function name: initDMA ** Description: Initialise the DMA engine - returns true if init OK ***************************************************************************************/ -bool TFT_eSPI::initDMA(void) +bool TFT_eSPI::initDMA(bool ctrl_cs) { if (DMA_Enabled) return false; @@ -680,6 +680,10 @@ bool TFT_eSPI::initDMA(void) .flags = 0, .intr_flags = 0 }; + + int8_t pin = -1; + if (ctrl_cs) pin = TFT_CS; + spi_device_interface_config_t devcfg = { .command_bits = 0, .address_bits = 0, @@ -690,7 +694,7 @@ bool TFT_eSPI::initDMA(void) .cs_ena_posttrans = 0, .clock_speed_hz = SPI_FREQUENCY, .input_delay_ns = 0, - .spics_io_num = TFT_CS, + .spics_io_num = pin, .flags = SPI_DEVICE_NO_DUMMY, //0, .queue_size = 1, .pre_cb = 0, //dc_callback, //Callback to handle D/C line diff --git a/Processors/TFT_eSPI_STM32.c b/Processors/TFT_eSPI_STM32.c index 6c95d2f..a9951dd 100644 --- a/Processors/TFT_eSPI_STM32.c +++ b/Processors/TFT_eSPI_STM32.c @@ -538,8 +538,10 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t // This initialisation is for STM32F2xx/4xx/7xx processors and may not work on others // Dual core H7xx series not supported yet, they are different and have a DMA MUX: // https://electronics.stackexchange.com/questions/379813/configuring-the-dma-request-multiplexer-on-a-stm32h7-mcu -bool TFT_eSPI::initDMA(void) +bool TFT_eSPI::initDMA(bool ctrl_cs) { + ctrl_cs = ctrl_cs; // Not used for STM32, so stop compiler warning + #if (TFT_SPI_PORT == 1) __HAL_RCC_DMA2_CLK_ENABLE(); // Enable DMA2 clock dmaHal.Init.Channel = DMA_CHANNEL_3; // DMA channel 3 is for SPI1 TX diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 4234199..75dce54 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -16,7 +16,7 @@ #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "2.3.52" +#define TFT_ESPI_VERSION "2.3.53" // Bit level feature flags // Bit 0 set: viewport capability @@ -618,7 +618,9 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac // function will wait for the DMA to complete, so this may defeat any DMA performance benefit. // - bool initDMA(void); // Initialise the DMA engine and attach to SPI bus - typically used in setup() + bool initDMA(bool ctrl_cs = false); // Initialise the DMA engine and attach to SPI bus - typically used in setup() + // Parameter "true" enables DMA engine control of TFT chip select (ESP32 only) + // For ESP32 only, TFT reads will not work if parameter is true void deInitDMA(void); // De-initialise the DMA engine and detach from SPI bus - typically not used // Push an image to the TFT using DMA, buffer is optional and grabs (double buffers) a copy of the image