From b8367d95d20da4edd149f207dd86665c3cc70588 Mon Sep 17 00:00:00 2001 From: chegewara Date: Sat, 17 Dec 2022 12:54:54 +0100 Subject: [PATCH] Add esp-idf standalone support, tested with esp-idf v5.0 --- CMakeLists.txt | 21 +++++++++-- src/ESP32-HUB75-MatrixPanel-I2S-DMA.h | 1 + src/ESP32-HUB75-MatrixPanel-leddrivers.cpp | 36 +++++++++++-------- src/platforms/esp32s3/gdma_lcd_parallel16.cpp | 9 +++-- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bac04f6..a617a71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,18 @@ # MIT License cmake_minimum_required(VERSION 3.5) +idf_build_get_property(target IDF_TARGET) +if(ARDUINO_ARCH_ESP32) + list(APPEND arduino_build arduino Adafruit-GFX-Library) +else() + list(APPEND esp_idf_build esp_lcd driver) +endif() idf_component_register(SRCS "src/platforms/esp32/esp32_i2s_parallel_dma.cpp" "src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp" "src/ESP32-HUB75-MatrixPanel-leddrivers.cpp" - INCLUDE_DIRS "." - REQUIRES arduino Adafruit-GFX-Library) + src/platforms/${target}/gdma_lcd_parallel16.cpp + INCLUDE_DIRS "./src" + PRIV_REQUIRES ${arduino_build} ${esp_idf_build} + ) # In case you are running into issues with "missing" header files from 3rd party libraries # you can add them to the REQUIRES section above. If you use some of the build options below @@ -16,6 +24,15 @@ idf_component_register(SRCS "src/platforms/esp32/esp32_i2s_parallel_dma.cpp" "sr # target_compile_options(${COMPONENT_TARGET} PUBLIC -DUSE_GFX_ROOT) # target_compile_options(${COMPONENT_TARGET} PUBLIC -DNO_GFX) +# esp-idf does not have any GFX library support yet, so we need to define NO_GFX +if(ARDUINO_ARCH_ESP32) +else() + target_compile_options(${COMPONENT_TARGET} PUBLIC -DNO_GFX) + if(${target} STREQUAL "esp32s3") + target_compile_options(${COMPONENT_TARGET} PUBLIC -DSPIRAM_FRAMEBUFFER) + endif() +endif() + # You can also use multiple options like this # target_compile_options(${COMPONENT_TARGET} PUBLIC -DNO_GFX -DNO_FAST_FUNCTIONS) diff --git a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h index a18b6bb..0a70e5d 100644 --- a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h +++ b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.h @@ -6,6 +6,7 @@ #include #include #include +#include "esp_attr.h" //#include #include "platforms/platform_detect.hpp" diff --git a/src/ESP32-HUB75-MatrixPanel-leddrivers.cpp b/src/ESP32-HUB75-MatrixPanel-leddrivers.cpp index 2c9139e..0bb20f7 100644 --- a/src/ESP32-HUB75-MatrixPanel-leddrivers.cpp +++ b/src/ESP32-HUB75-MatrixPanel-leddrivers.cpp @@ -3,10 +3,16 @@ */ -#include +#ifdef ARDUINO_ARCH_ESP32 + #include +#else + #include + #define LOW 0 + #define HIGH 1 +#endif #include "ESP32-HUB75-MatrixPanel-I2S-DMA.h" -#define CLK_PULSE digitalWrite(_cfg.gpio.clk, HIGH); digitalWrite(_cfg.gpio.clk, LOW); +#define CLK_PULSE gpio_set_level((gpio_num_t) _cfg.gpio.clk, HIGH); gpio_set_level((gpio_num_t) _cfg.gpio.clk, LOW); /** * @brief - pre-init procedures for specific led-drivers @@ -43,52 +49,52 @@ void MatrixPanel_I2S_DMA::fm6124init(const HUB75_I2S_CFG& _cfg) { bool REG2[16] = {0,0,0,0,0, 0,0,0,0,1,0, 0,0,0,0,0}; // a single bit enables the matrix output for (uint8_t _pin:{_cfg.gpio.r1, _cfg.gpio.r2, _cfg.gpio.g1, _cfg.gpio.g2, _cfg.gpio.b1, _cfg.gpio.b2, _cfg.gpio.clk, _cfg.gpio.lat, _cfg.gpio.oe}){ - pinMode(_pin, OUTPUT); - digitalWrite(_pin, LOW); + gpio_set_direction((gpio_num_t) _pin, GPIO_MODE_OUTPUT); + gpio_set_level((gpio_num_t) _pin, LOW); } - digitalWrite(_cfg.gpio.oe, HIGH); // Disable Display + gpio_set_level((gpio_num_t) _cfg.gpio.oe, HIGH); // Disable Display // Send Data to control register REG1 // this sets the matrix brightness actually for (int l = 0; l < PIXELS_PER_ROW; l++){ for (uint8_t _pin:{_cfg.gpio.r1, _cfg.gpio.r2, _cfg.gpio.g1, _cfg.gpio.g2, _cfg.gpio.b1, _cfg.gpio.b2}) - digitalWrite(_pin, REG1[l%16]); // we have 16 bits shifters and write the same value all over the matrix array + gpio_set_level((gpio_num_t) _pin, REG1[l%16]); // we have 16 bits shifters and write the same value all over the matrix array if (l > PIXELS_PER_ROW - 12){ // pull the latch 11 clocks before the end of matrix so that REG1 starts counting to save the value - digitalWrite(_cfg.gpio.lat, HIGH); + gpio_set_level((gpio_num_t) _cfg.gpio.lat, HIGH); } CLK_PULSE } // drop the latch and save data to the REG1 all over the FM6124 chips - digitalWrite(_cfg.gpio.lat, LOW); + gpio_set_level((gpio_num_t) _cfg.gpio.lat, LOW); // Send Data to control register REG2 (enable LED output) for (int l = 0; l < PIXELS_PER_ROW; l++){ for (uint8_t _pin:{_cfg.gpio.r1, _cfg.gpio.r2, _cfg.gpio.g1, _cfg.gpio.g2, _cfg.gpio.b1, _cfg.gpio.b2}) - digitalWrite(_pin, REG2[l%16]); // we have 16 bits shifters and we write the same value all over the matrix array + gpio_set_level((gpio_num_t) _pin, REG2[l%16]); // we have 16 bits shifters and we write the same value all over the matrix array if (l > PIXELS_PER_ROW - 13){ // pull the latch 12 clocks before the end of matrix so that reg2 stars counting to save the value - digitalWrite(_cfg.gpio.lat, HIGH); + gpio_set_level((gpio_num_t) _cfg.gpio.lat, HIGH); } CLK_PULSE } // drop the latch and save data to the REG1 all over the FM6126 chips - digitalWrite(_cfg.gpio.lat, LOW); + gpio_set_level((gpio_num_t) _cfg.gpio.lat, LOW); // blank data regs to keep matrix clear after manipulations for (uint8_t _pin:{_cfg.gpio.r1, _cfg.gpio.r2, _cfg.gpio.g1, _cfg.gpio.g2, _cfg.gpio.b1, _cfg.gpio.b2}) - digitalWrite(_pin, LOW); + gpio_set_level((gpio_num_t) _pin, LOW); for (int l = 0; l < PIXELS_PER_ROW; ++l){ CLK_PULSE } - digitalWrite(_cfg.gpio.lat, HIGH); + gpio_set_level((gpio_num_t) _cfg.gpio.lat, HIGH); CLK_PULSE - digitalWrite(_cfg.gpio.lat, LOW); - digitalWrite(_cfg.gpio.oe, LOW); // Enable Display + gpio_set_level((gpio_num_t) _cfg.gpio.lat, LOW); + gpio_set_level((gpio_num_t) _cfg.gpio.oe, LOW); // Enable Display CLK_PULSE } \ No newline at end of file diff --git a/src/platforms/esp32s3/gdma_lcd_parallel16.cpp b/src/platforms/esp32s3/gdma_lcd_parallel16.cpp index d9460e2..edea630 100644 --- a/src/platforms/esp32s3/gdma_lcd_parallel16.cpp +++ b/src/platforms/esp32s3/gdma_lcd_parallel16.cpp @@ -19,8 +19,11 @@ #if __has_include () // Stop compile errors: /src/platforms/esp32s3/gdma_lcd_parallel16.hpp:64:10: fatal error: hal/lcd_ll.h: No such file or directory +#ifdef ARDUINO_ARCH_ESP32 #include +#endif #include "gdma_lcd_parallel16.hpp" + #include "esp_attr.h" static const char* TAG = "gdma_lcd_parallel16"; @@ -80,9 +83,9 @@ esp_rom_delay_us(100); // uint32_t lcd_clkm_div_num = ((160000000 + 1) / _cfg.bus_freq); - ESP_LOGI(TAG, "Cpu frequecny is %d", getCpuFrequencyMhz()); + ESP_LOGI(TAG, "Cpu frequecny is %" PRIu16 "", CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ); - uint32_t lcd_clkm_div_num = ( ((getCpuFrequencyMhz()*1000000)+1) / _cfg.bus_freq ) / 4; + uint32_t lcd_clkm_div_num = ( ((CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ*1000000)+1) / _cfg.bus_freq ) / 4; //ESP_LOGI(TAG, "Clock divider is %d", lcd_clkm_div_num); @@ -378,7 +381,7 @@ if ( _dmadesc_a_idx >= _dmadesc_count) { - ESP_LOGE(TAG, "Attempted to create more DMA descriptors than allocated. Expecting max %d descriptors.", _dmadesc_count); + ESP_LOGE(TAG, "Attempted to create more DMA descriptors than allocated. Expecting max %" PRIu32 " descriptors.", _dmadesc_count); return; }