Fix to compile issues for PlatformIO

This commit is contained in:
mrfaptastic 2023-01-01 16:22:28 +00:00
parent ce2b6264dd
commit f9ff4b4078
3 changed files with 40 additions and 63 deletions

View file

@ -6,12 +6,6 @@
#include "rom/cache.h"
#endif
extern Bus_Parallel16 dma_bus;
#if CORE_DEBUG_LEVEL > 0
static const char* TAG = "MatrixPanel";
#endif
/* This replicates same function in rowBitStruct, but due to induced inlining it might be MUCH faster
* when used in tight loops while method from struct could be flushed out of instruction cache between
* loop cycles do NOT forget about buff_id param if using this.
@ -59,8 +53,8 @@ extern Bus_Parallel16 dma_bus;
bool MatrixPanel_I2S_DMA::allocateDMAmemory()
{
ESP_LOGI(TAG, "Free heap: %d", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
ESP_LOGI(TAG, "Free SPIRAM: %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
ESP_LOGI("I2S-DMA", "Free heap: %d", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
ESP_LOGI("I2S-DMA", "Free SPIRAM: %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
// Alright, theoretically we should be OK, so let us do this, so
@ -75,8 +69,8 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory()
if (ptr->data == nullptr)
{
ESP_LOGE(TAG, "CRITICAL ERROR: Not enough memory for requested colour depth! Please reduce PIXEL_COLOUR_DEPTH_BITS value.\r\n");
ESP_LOGE(TAG, "Could not allocate rowBitStruct %d!.\r\n", malloc_num);
ESP_LOGE("I2S-DMA", "CRITICAL ERROR: Not enough memory for requested colour depth! Please reduce PIXEL_COLOUR_DEPTH_BITS value.\r\n");
ESP_LOGE("I2S-DMA", "Could not allocate rowBitStruct %d!.\r\n", malloc_num);
return false;
// TODO: should we release all previous rowBitStructs here???
@ -86,7 +80,7 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory()
dma_buff.rowBits.emplace_back(ptr); // save new rowBitStruct into rows vector
++dma_buff.rows;
}
ESP_LOGI(TAG, "Allocating %d bytes memory for DMA BCM framebuffer(s).", allocated_fb_memory);
ESP_LOGI("I2S-DMA", "Allocating %d bytes memory for DMA BCM framebuffer(s).", allocated_fb_memory);
// calculate the lowest LSBMSB_TRANSITION_BIT value that will fit in memory that will meet or exceed the configured refresh rate
#if !defined(FORCE_COLOUR_DEPTH)
@ -106,7 +100,7 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory()
int actualRefreshRate = 1000000000UL/(nsPerFrame);
calculated_refresh_rate = actualRefreshRate;
ESP_LOGW(TAG, "lsbMsbTransitionBit of %d gives %d Hz refresh rate.", lsbMsbTransitionBit, actualRefreshRate);
ESP_LOGW("I2S-DMA", "lsbMsbTransitionBit of %d gives %d Hz refresh rate.", lsbMsbTransitionBit, actualRefreshRate);
if (actualRefreshRate > m_cfg.min_refresh_rate)
break;
@ -128,14 +122,14 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory()
numDMAdescriptorsPerRow += (1<<(i - lsbMsbTransitionBit - 1));
}
ESP_LOGI(TAG, "Recalculated number of DMA descriptors per row: %d", numDMAdescriptorsPerRow);
ESP_LOGI("I2S-DMA", "Recalculated number of DMA descriptors per row: %d", numDMAdescriptorsPerRow);
// Refer to 'DMA_LL_PAYLOAD_SPLIT' code in configureDMA() below to understand why this exists.
// numDMAdescriptorsPerRow is also used to calculate descount which is super important in i2s_parallel_config_t SoC DMA setup.
if ( dma_buff.rowBits[0]->size() > DMA_MAX )
{
ESP_LOGW(TAG, "rowColorDepthStruct struct is too large, split DMA payload required. Adding %d DMA descriptors\n", PIXEL_COLOUR_DEPTH_BITS-1);
ESP_LOGW("I2S-DMA", "rowColorDepthStruct struct is too large, split DMA payload required. Adding %d DMA descriptors\n", PIXEL_COLOUR_DEPTH_BITS-1);
numDMAdescriptorsPerRow += PIXEL_COLOUR_DEPTH_BITS-1;
// Note: If numDMAdescriptorsPerRow is even just one descriptor too large, DMA linked list will not correctly loop.
@ -232,7 +226,7 @@ void MatrixPanel_I2S_DMA::configureDMA(const HUB75_I2S_CFG& _cfg)
} // end frame rows
ESP_LOGI(TAG, "%d DMA descriptors linked to buffer data.", current_dmadescriptor_offset);
ESP_LOGI("I2S-DMA", "%d DMA descriptors linked to buffer data.", current_dmadescriptor_offset);
//
// Setup DMA and Output to GPIO
@ -272,7 +266,7 @@ void MatrixPanel_I2S_DMA::configureDMA(const HUB75_I2S_CFG& _cfg)
flipDMABuffer(); // display back buffer 0, draw to 1, ignored if double buffering isn't enabled.
//i2s_parallel_send_dma(ESP32_I2S_DEVICE, &dmadesc_a[0]);
ESP_LOGI(TAG, "DMA setup completed");
ESP_LOGI("I2S-DMA", "DMA setup completed");
} // end initMatrixDMABuff
@ -491,7 +485,7 @@ void MatrixPanel_I2S_DMA::clearFrameBuffer(bool _buff_id){
} else {
row[ESP32_TX_FIFO_POSITION_ADJUST(x_pixel)] = abcde;
}
// ESP_LOGI(TAG, "x pixel 1: %d", x_pixel);
// ESP_LOGI("", "x pixel 1: %d", x_pixel);
} while(x_pixel!=dma_buff.rowBits[row_idx]->width && x_pixel);
// colour_index[0] (LSB) x_pixels must be "marked" with a previous's row address, 'cause it is used to display
@ -508,7 +502,7 @@ void MatrixPanel_I2S_DMA::clearFrameBuffer(bool _buff_id){
row[ESP32_TX_FIFO_POSITION_ADJUST(x_pixel)] = abcde;
}
//row[x_pixel] = abcde;
// ESP_LOGI(TAG, "x pixel 2: %d", x_pixel);
// ESP_LOGI("", "x pixel 2: %d", x_pixel);
} while(x_pixel);

View file

@ -22,10 +22,6 @@ Modified heavily for the ESP32 HUB75 DMA library by:
#include <sdkconfig.h>
#if defined (CONFIG_IDF_TARGET_ESP32) || defined (CONFIG_IDF_TARGET_ESP32S2)
#if CORE_DEBUG_LEVEL > 0
static const char* TAG = "esp32_i2s_parallel_dma";
#endif
#include "esp32_i2s_parallel_dma.hpp"
#include <driver/gpio.h>
@ -103,14 +99,14 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
void Bus_Parallel16::config(const config_t& cfg)
{
ESP_LOGI(TAG, "Performing config for ESP32 or ESP32-S2");
ESP_LOGI("ESP32/S2", "Performing config for ESP32 or ESP32-S2");
_cfg = cfg;
_dev = getDev();
}
bool Bus_Parallel16::init(void) // The big one that gets everything setup.
{
ESP_LOGI(TAG, "Performing DMA bus init() for ESP32 or ESP32-S2");
ESP_LOGI("ESP32/S2", "Performing DMA bus init() for ESP32 or ESP32-S2");
if(_cfg.parallel_width < 8 || _cfg.parallel_width >= 24) {
return false;
@ -234,7 +230,7 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
return false;
}
ESP_LOGI(TAG, "i2s pll clk_div_main is: %d", _div_num);
ESP_LOGI("ESP32/S2", "i2s pll clk_div_main is: %d", _div_num);
dev->clkm_conf.clkm_div_b = 0; // Clock numerator
@ -389,7 +385,7 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
irq_hndlr, NULL, NULL);
if(err) {
ESP_LOGE(TAG, "init() Failed to setup interrupt request handeler.");
ESP_LOGE("ESP32/S2", "init() Failed to setup interrupt request handeler.");
return false;
}
@ -399,9 +395,9 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
#if defined (CONFIG_IDF_TARGET_ESP32S2)
ESP_LOGD(TAG, "init() GPIO and clock configuration set for ESP32-S2");
ESP_LOGD("ESP32-S2", "init() GPIO and clock configuration set for ESP32-S2");
#else
ESP_LOGD(TAG, "init() GPIO and clock configuration set for ESP32");
ESP_LOGD("ESP32-ORIG", "init() GPIO and clock configuration set for ESP32");
#endif
@ -439,13 +435,13 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
_dmadesc_count = len;
_dmadesc_last = len-1;
ESP_LOGI(TAG, "Allocating memory for %d DMA descriptors.", len);
ESP_LOGI("ESP32/S2", "Allocating memory for %d DMA descriptors.", len);
_dmadesc_a= (HUB75_DMA_DESCRIPTOR_T*)heap_caps_malloc(sizeof(HUB75_DMA_DESCRIPTOR_T) * len, MALLOC_CAP_DMA);
if (_dmadesc_a == nullptr)
{
ESP_LOGE(TAG, "ERROR: Couldn't malloc _dmadesc_a. Not enough memory.");
ESP_LOGE("ESP32/S2", "ERROR: Couldn't malloc _dmadesc_a. Not enough memory.");
return false;
}
@ -454,13 +450,13 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
{
if (_dmadesc_b) heap_caps_free(_dmadesc_b); // free all dma descrptios previously
ESP_LOGD(TAG, "Allocating the second buffer (double buffer enabled).");
ESP_LOGD("ESP32/S2", "Allocating the second buffer (double buffer enabled).");
_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.");
ESP_LOGE("ESP32/S2", "ERROR: Couldn't malloc _dmadesc_b. Not enough memory.");
_double_dma_buffer = false;
return false;
}
@ -469,7 +465,7 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
_dmadesc_a_idx = 0;
_dmadesc_b_idx = 0;
ESP_LOGD(TAG, "Allocating %d bytes of memory for DMA descriptors.", sizeof(HUB75_DMA_DESCRIPTOR_T) * len);
ESP_LOGD("ESP32/S2", "Allocating %d bytes of memory for DMA descriptors.", sizeof(HUB75_DMA_DESCRIPTOR_T) * len);
// New - Temporary blank descriptor for transitions between DMA buffer
_dmadesc_blank = (HUB75_DMA_DESCRIPTOR_T*)heap_caps_malloc(sizeof(HUB75_DMA_DESCRIPTOR_T) * 1, MALLOC_CAP_DMA);
@ -489,20 +485,17 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
void Bus_Parallel16::create_dma_desc_link(void *data, size_t size, bool dmadesc_b)
{
static constexpr size_t MAX_DMA_LEN = (4096-4);
/*
if (dmadesc_b)
ESP_LOGI(TAG, " * Double buffer descriptor.");
*/
if (size > MAX_DMA_LEN)
{
size = MAX_DMA_LEN;
ESP_LOGW(TAG, "Creating DMA descriptor which links to payload with size greater than MAX_DMA_LEN!");
ESP_LOGW("ESP32/S2", "Creating DMA descriptor which links to payload with size greater than MAX_DMA_LEN!");
}
if ( !dmadesc_b )
{
if ( (_dmadesc_a_idx+1) > _dmadesc_count) {
ESP_LOGE(TAG, "Attempted to create more DMA descriptors than allocated memory for. Expecting a maximum of %d DMA descriptors", _dmadesc_count);
ESP_LOGE("ESP32/S2", "Attempted to create more DMA descriptors than allocated memory for. Expecting a maximum of %d DMA descriptors", _dmadesc_count);
return;
}
}
@ -510,14 +503,7 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
volatile lldesc_t *dmadesc;
volatile lldesc_t *next;
bool eof = false;
/*
dmadesc_a[desccount-1].eof = 1;
dmadesc_a[desccount-1].qe.stqe_next=(lldesc_t*)&dmadesc_a[0];
*/
// ESP_LOGI(TAG, "Creating descriptor %d\n", _dmadesc_a_idx);
if ( (dmadesc_b == true) ) // for primary buffer
{
dmadesc = &_dmadesc_b[_dmadesc_b_idx];
@ -535,7 +521,7 @@ static void IRAM_ATTR irq_hndlr(void* arg) { // if we use I2S1 (default)
}
if ( _dmadesc_a_idx == (_dmadesc_last) ) {
ESP_LOGW(TAG, "Creating final DMA descriptor and linking back to 0.");
ESP_LOGW("ESP32/S2", "Creating final DMA descriptor and linking back to 0.");
}
dmadesc->size = size;

View file

@ -26,9 +26,9 @@
#include "gdma_lcd_parallel16.hpp"
#include "esp_attr.h"
#if CORE_DEBUG_LEVEL > 0
static const char* TAG = "gdma_lcd_parallel16";
#endif
//#if (CORE_DEBUG_LEVEL > ARDUHAL_LOG_LEVEL_NONE) || (ARDUHAL_LOG_LEVEL > ARDUHAL_LOG_LEVEL_NONE)
// static const char* TAG = "gdma_lcd_parallel16";
//#endif
static int _dmadesc_a_idx = 0;
static int _dmadesc_b_idx = 0;
@ -86,7 +86,7 @@
esp_rom_delay_us(100);
// uint32_t lcd_clkm_div_num = ((160000000 + 1) / _cfg.bus_freq);
// ESP_LOGI(TAG, "Clock divider is %d", lcd_clkm_div_num);
// ESP_LOGI("", "Clock divider is %d", lcd_clkm_div_num);
// Configure LCD clock. Since this program generates human-perceptible
// output and not data for LED matrices or NeoPixels, use almost the
@ -113,7 +113,7 @@
//LCD_CAM.lcd_clock.lcd_clkm_div_num = lcd_clkm_div_num;
LCD_CAM.lcd_clock.lcd_clkm_div_num = 3;
}
ESP_LOGI(TAG, "Clock divider is %d", LCD_CAM.lcd_clock.lcd_clkm_div_num);
ESP_LOGI("S3", "Clock divider is %d", LCD_CAM.lcd_clock.lcd_clkm_div_num);
LCD_CAM.lcd_clock.lcd_clkm_div_a = 1; // 0/1 fractional divide
@ -305,7 +305,7 @@
void Bus_Parallel16::enable_double_dma_desc(void)
{
ESP_LOGI(TAG, "Enabled support for secondary DMA buffer.");
ESP_LOGI("S3", "Enabled support for secondary DMA buffer.");
_double_dma_buffer = true;
}
@ -315,13 +315,13 @@
if (_dmadesc_a) heap_caps_free(_dmadesc_a); // free all dma descrptios previously
_dmadesc_count = len;
ESP_LOGD(TAG, "Allocating %d bytes memory for DMA descriptors.", sizeof(HUB75_DMA_DESCRIPTOR_T) * len);
ESP_LOGD("S3", "Allocating %d bytes memory for DMA descriptors.", sizeof(HUB75_DMA_DESCRIPTOR_T) * len);
_dmadesc_a= (HUB75_DMA_DESCRIPTOR_T*)heap_caps_malloc(sizeof(HUB75_DMA_DESCRIPTOR_T) * len, MALLOC_CAP_DMA);
if (_dmadesc_a == nullptr)
{
ESP_LOGE(TAG, "ERROR: Couldn't malloc _dmadesc_a. Not enough memory.");
ESP_LOGE("S3", "ERROR: Couldn't malloc _dmadesc_a. Not enough memory.");
return false;
}
@ -331,7 +331,7 @@
if (_dmadesc_b == nullptr)
{
ESP_LOGE(TAG, "ERROR: Couldn't malloc _dmadesc_b. Not enough memory.");
ESP_LOGE("S3", "ERROR: Couldn't malloc _dmadesc_b. Not enough memory.");
_double_dma_buffer = false;
}
}
@ -350,14 +350,12 @@
if (size > MAX_DMA_LEN) {
size = MAX_DMA_LEN;
ESP_LOGW(TAG, "Creating DMA descriptor which links to payload with size greater than MAX_DMA_LEN!");
ESP_LOGW("S3", "Creating DMA descriptor which links to payload with size greater than MAX_DMA_LEN!");
}
if ( dmadesc_b == true)
{
// ESP_LOGI(TAG, "Creating dma desc B %d", _dmadesc_b_idx);
_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);
@ -376,11 +374,10 @@
}
else
{
// ESP_LOGI(TAG, "Creating dma desc A %d", _dmadesc_a_idx);
if ( _dmadesc_a_idx >= _dmadesc_count)
{
ESP_LOGE(TAG, "Attempted to create more DMA descriptors than allocated. Expecting max %" PRIu32 " descriptors.", _dmadesc_count);
ESP_LOGE("S3", "Attempted to create more DMA descriptors than allocated. Expecting max %" PRIu32 " descriptors.", _dmadesc_count);
return;
}