From 80ab5c3060c3a067df06a84665b82f92431feb51 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 17 Apr 2022 22:47:26 +0200 Subject: [PATCH] LVGL fix conflict between SPI DMA and SD card --- .../Display_Renderer-gemu-1.0/src/renderer.h | 2 +- lib/lib_display/UDisplay/uDisplay.cpp | 30 +++++++------------ lib/lib_display/UDisplay/uDisplay.h | 2 +- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/lib_display/Display_Renderer-gemu-1.0/src/renderer.h b/lib/lib_display/Display_Renderer-gemu-1.0/src/renderer.h index 925b0ad7d..74d812529 100644 --- a/lib/lib_display/Display_Renderer-gemu-1.0/src/renderer.h +++ b/lib/lib_display/Display_Renderer-gemu-1.0/src/renderer.h @@ -34,7 +34,7 @@ typedef struct LVGL_PARAMS { struct { uint8_t use_dma : 1; uint8_t swap_color : 1; - uint8_t resvd_0 : 1; + uint8_t async_dma : 1; // force DMA completion before returning, avoid conflict with other devices on same bus. If set you should make sure the display is the only device on the bus uint8_t resvd_1 : 1; uint8_t resvd_2 : 1; uint8_t resvd_3 : 1; diff --git a/lib/lib_display/UDisplay/uDisplay.cpp b/lib/lib_display/UDisplay/uDisplay.cpp index a6b8d1e6f..71025069b 100755 --- a/lib/lib_display/UDisplay/uDisplay.cpp +++ b/lib/lib_display/UDisplay/uDisplay.cpp @@ -465,7 +465,7 @@ Renderer *uDisplay::Init(void) { uspi->begin(spi_clk, spi_miso, spi_mosi, -1); if (lvgl_param.use_dma) { spi_host = VSPI_HOST; - initDMA(spi_cs); + initDMA(lvgl_param.async_dma ? spi_cs : -1); // disable DMA CS if sync, we control it directly } } else if (spi_nr == 2) { @@ -473,7 +473,7 @@ Renderer *uDisplay::Init(void) { uspi->begin(spi_clk, spi_miso, spi_mosi, -1); if (lvgl_param.use_dma) { spi_host = HSPI_HOST; - initDMA(spi_cs); + initDMA(lvgl_param.async_dma ? spi_cs : -1); // disable DMA CS if sync, we control it directly } } else { pinMode(spi_clk, OUTPUT); @@ -1974,24 +1974,13 @@ void uDisplay::beginTransaction(SPISettings s) { #ifdef ESP32 if (lvgl_param.use_dma) { dmaWait(); - } else { - uspi->beginTransaction(s); } -#else - uspi->beginTransaction(s); #endif + uspi->beginTransaction(s); } void uDisplay::endTransaction(void) { -#ifdef ESP32 - if (lvgl_param.use_dma) { - dmaBusy(); - } else { - uspi->endTransaction(); - } -#else uspi->endTransaction(); -#endif } @@ -2002,7 +1991,7 @@ void uDisplay::endTransaction(void) { ** Function name: initDMA ** Description: Initialise the DMA engine - returns true if init OK ***************************************************************************************/ -bool uDisplay::initDMA(bool ctrl_cs) +bool uDisplay::initDMA(int32_t ctrl_cs) { if (DMA_Enabled) return false; @@ -2018,9 +2007,6 @@ bool uDisplay::initDMA(bool ctrl_cs) .intr_flags = 0 }; - int8_t pin = -1; - if (ctrl_cs) pin = spi_cs; - spi_device_interface_config_t devcfg = { .command_bits = 0, .address_bits = 0, @@ -2031,7 +2017,7 @@ bool uDisplay::initDMA(bool ctrl_cs) .cs_ena_posttrans = 0, .clock_speed_hz = spi_speed*1000000, .input_delay_ns = 0, - .spics_io_num = pin, + .spics_io_num = ctrl_cs, .flags = SPI_DEVICE_NO_DUMMY, //0, .queue_size = 1, .pre_cb = 0, //dc_callback, //Callback to handle D/C line @@ -2119,6 +2105,9 @@ void uDisplay::pushPixelsDMA(uint16_t* image, uint32_t len) { assert(ret == ESP_OK); spiBusyCheck++; + if (!lvgl_param.async_dma) { + dmaWait(); + } } /*************************************************************************************** @@ -2145,6 +2134,9 @@ void uDisplay::pushPixels3DMA(uint8_t* image, uint32_t len) { assert(ret == ESP_OK); spiBusyCheck++; + if (!lvgl_param.async_dma) { + dmaWait(); + } } diff --git a/lib/lib_display/UDisplay/uDisplay.h b/lib/lib_display/UDisplay/uDisplay.h index b5eae65c5..9a233fcff 100755 --- a/lib/lib_display/UDisplay/uDisplay.h +++ b/lib/lib_display/UDisplay/uDisplay.h @@ -233,7 +233,7 @@ class uDisplay : public Renderer { spi_device_handle_t dmaHAL; spi_host_device_t spi_host = VSPI_HOST; // spi_host_device_t spi_host = VSPI_HOST; - bool initDMA(bool ctrl_cs); + bool initDMA(int32_t ctrl_cs); void deInitDMA(void); bool dmaBusy(void); void dmaWait(void);