From 30f0014b0cee9c16c88a2beda31e7d636f90b4b8 Mon Sep 17 00:00:00 2001 From: mrfaptastic <12006953+mrfaptastic@users.noreply.github.com> Date: Fri, 30 Sep 2022 11:31:53 +0100 Subject: [PATCH] Enable double buffering Doesn't work though with new refactored code on S3 device - do not use... --- src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp | 3 + .../esp32/esp32_i2s_parallel_dma.cpp | 3 + src/platforms/esp32s3/gdma_lcd_parallel16.cpp | 59 ++++++++++++++++++- src/platforms/esp32s3/gdma_lcd_parallel16.hpp | 12 ++-- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp index 6d8e521..740071c 100644 --- a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp +++ b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp @@ -98,6 +98,9 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory() // malloc the DMA linked list descriptors that i2s_parallel will need desccount = numDMAdescriptorsPerRow * ROWS_PER_FRAME; + if (m_cfg.double_buff) + dma_bus.enable_double_dma_desc(); + dma_bus.allocate_dma_desc_memory(desccount); /* diff --git a/src/platforms/esp32/esp32_i2s_parallel_dma.cpp b/src/platforms/esp32/esp32_i2s_parallel_dma.cpp index 94f0d50..fb0905d 100644 --- a/src/platforms/esp32/esp32_i2s_parallel_dma.cpp +++ b/src/platforms/esp32/esp32_i2s_parallel_dma.cpp @@ -564,6 +564,9 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default) _dmadesc_a[_dmadesc_count-1].qe.stqe_next = &_dmadesc_a[0]; _dmadesc_b[_dmadesc_count-1].qe.stqe_next = &_dmadesc_a[0]; } + + _dmadesc_a_active ^= _dmadesc_a_active; + } // end flip diff --git a/src/platforms/esp32s3/gdma_lcd_parallel16.cpp b/src/platforms/esp32s3/gdma_lcd_parallel16.cpp index 785e489..0b25c77 100644 --- a/src/platforms/esp32s3/gdma_lcd_parallel16.cpp +++ b/src/platforms/esp32s3/gdma_lcd_parallel16.cpp @@ -269,7 +269,7 @@ void Bus_Parallel16::enable_double_dma_desc(void) { - //_double_dma_buffer = true; + _double_dma_buffer = true; } // Need this to work for double buffers etc. @@ -288,8 +288,20 @@ return false; } + if (_double_dma_buffer) + { + _dmadesc_b= (HUB75_DMA_DESCRIPTOR_T*)heap_caps_malloc(sizeof(HUB75_DMA_DESCRIPTOR_T) * len, MALLOC_CAP_DMA); + + if (_dmadesc_b == nullptr) + { + ESP_LOGE(TAG, "ERROR: Couldn't malloc _dmadesc_b. Not enough memory."); + _double_dma_buffer = false; + } + } + + _dmadesc_a_idx = 0; - // _dmadesc_b_idx = 0; + _dmadesc_b_idx = 0; return true; @@ -311,6 +323,29 @@ return; } + if (_double_dma_buffer == true && dmadesc_b == true) + { + + _dmadesc_b[_dmadesc_b_idx].dw0.owner = DMA_DESCRIPTOR_BUFFER_OWNER_DMA; + _dmadesc_b[_dmadesc_b_idx].dw0.suc_eof = 0; + _dmadesc_b[_dmadesc_b_idx].dw0.size = _dmadesc_b[_dmadesc_b_idx].dw0.length = size; //sizeof(data); + _dmadesc_b[_dmadesc_b_idx].buffer = data; //data; + + if (_dmadesc_b_idx == _dmadesc_count-1) { + _dmadesc_b[_dmadesc_b_idx].next = (dma_descriptor_t *) &_dmadesc_b[0]; + } + else { + _dmadesc_b[_dmadesc_b_idx].next = (dma_descriptor_t *) &_dmadesc_b[_dmadesc_b_idx+1]; + } + + _dmadesc_b_idx++; + + + + } + else + { + _dmadesc_a[_dmadesc_a_idx].dw0.owner = DMA_DESCRIPTOR_BUFFER_OWNER_DMA; _dmadesc_a[_dmadesc_a_idx].dw0.suc_eof = 0; _dmadesc_a[_dmadesc_a_idx].dw0.size = _dmadesc_a[_dmadesc_a_idx].dw0.length = size; //sizeof(data); @@ -326,6 +361,8 @@ _dmadesc_a_idx++; + } + } // end create_dma_desc_link void Bus_Parallel16::dma_transfer_start() @@ -349,7 +386,23 @@ void Bus_Parallel16::flip_dma_output_buffer() { - + + if ( _double_dma_buffer == false) return; + + if ( _dmadesc_a_active == true) // change across to everything 'b'' + { + _dmadesc_a[_dmadesc_count-1].next = (dma_descriptor_t *) &_dmadesc_b[0]; + _dmadesc_b[_dmadesc_count-1].next = (dma_descriptor_t *) &_dmadesc_b[0]; + } + else + { + _dmadesc_a[_dmadesc_count-1].next = (dma_descriptor_t *) &_dmadesc_a[0]; + _dmadesc_b[_dmadesc_count-1].next = (dma_descriptor_t *) &_dmadesc_a[0]; + } + + _dmadesc_a_active ^= _dmadesc_a_active; + + } // end flip diff --git a/src/platforms/esp32s3/gdma_lcd_parallel16.hpp b/src/platforms/esp32s3/gdma_lcd_parallel16.hpp index 810eacb..2417626 100644 --- a/src/platforms/esp32s3/gdma_lcd_parallel16.hpp +++ b/src/platforms/esp32s3/gdma_lcd_parallel16.hpp @@ -157,15 +157,11 @@ HUB75_DMA_DESCRIPTOR_T* _dmadesc_a = nullptr; - // uint32_t _clock_reg_value; - // uint32_t _fast_wait = 0; - - //bool _double_dma_buffer = false; - //bool _dmadesc_a_active = true; - - //uint32_t _dmadesc_b_idx = 0; + bool _double_dma_buffer = false; + bool _dmadesc_a_active = true; + uint32_t _dmadesc_b_idx = 0; - //HUB75_DMA_DESCRIPTOR_T* _dmadesc_b = nullptr; + HUB75_DMA_DESCRIPTOR_T* _dmadesc_b = nullptr; esp_lcd_i80_bus_handle_t _i80_bus;