From 7a0296ef5574d3f2540cf1530cee4bb1c6f64800 Mon Sep 17 00:00:00 2001 From: raldone01 Date: Sat, 3 Apr 2021 15:10:55 +0200 Subject: [PATCH] Add menuconfig option to choose between rmt and i2s. Also remove the define hacks. --- components/FastLED-idf/CMakeLists.txt | 14 ++++---- components/FastLED-idf/FastLED.h | 8 ----- components/FastLED-idf/Kconfig | 10 ------ components/FastLED-idf/Kconfig.projbuild | 9 +++++ .../platforms/esp/32/clockless_rmt_esp32.cpp | 35 +++++++++---------- 5 files changed, 34 insertions(+), 42 deletions(-) delete mode 100644 components/FastLED-idf/Kconfig create mode 100644 components/FastLED-idf/Kconfig.projbuild diff --git a/components/FastLED-idf/CMakeLists.txt b/components/FastLED-idf/CMakeLists.txt index 210e63c..4b2c05e 100644 --- a/components/FastLED-idf/CMakeLists.txt +++ b/components/FastLED-idf/CMakeLists.txt @@ -13,13 +13,15 @@ set(srcs "wiring.cpp" "hal/esp32-hal-misc.c" "hal/esp32-hal-gpio.c" -# remove the following if you want I2S instead of RMT hardware, just put a pound in front -# "platforms/esp/32/clockless_rmt_esp32.cpp" + "platforms/esp/32/clockless_rmt_esp32.cpp" ) -# everything needs the ESP32 flag, not sure why this won't work -# going to hack by adding the ESP32 define in the h file - #`target_compile_options(${COMPONENT_LIB} PRIVATE "-DESP32") - idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "." "./hal" ) + +# target_compile_options(${COMPONENT_LIB} PRIVATE "-DESP32") won't work because the esp-idf uses a custom component system +idf_build_set_property(COMPILE_OPTIONS -DESP32 APPEND) +idf_build_set_property(COMPILE_OPTIONS -DFASTLED_NO_PINMAP APPEND) +if (CONFIG_FASTLED_ESP32_I2S) + idf_build_set_property(COMPILE_OPTIONS "-DFASTLED_ESP32_I2S" APPEND) +endif() diff --git a/components/FastLED-idf/FastLED.h b/components/FastLED-idf/FastLED.h index a9a8e22..2694ac4 100644 --- a/components/FastLED-idf/FastLED.h +++ b/components/FastLED-idf/FastLED.h @@ -4,14 +4,6 @@ ///@file FastLED.h /// central include file for FastLED, defines the CFastLED class/object -// BB hack -#define ESP32 -#define FASTLED_NO_PINMAP - -// prefer I2S? Comment this in. -// Not the default because haven't tried it as much, does work -#define FASTLED_ESP32_I2S - #include "esp32-hal.h" #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) diff --git a/components/FastLED-idf/Kconfig b/components/FastLED-idf/Kconfig deleted file mode 100644 index a09d8bf..0000000 --- a/components/FastLED-idf/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -menu "Fast LED" - - config FAST_LED_TEST - bool "Create a Fast LED option in case I need to later" - default n - help - I don't know if I'm going to have to add menuconfig options in the future. - Maybe I will. If I do, this is the template for doing it. - -endmenu diff --git a/components/FastLED-idf/Kconfig.projbuild b/components/FastLED-idf/Kconfig.projbuild new file mode 100644 index 0000000..1ec7b88 --- /dev/null +++ b/components/FastLED-idf/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "FastLED" + + config FASTLED_ESP32_I2S + bool "Use I2S instead of RMT" + default y + help + Removes the RMT sources and uses RMT instead of I2S. + +endmenu diff --git a/components/FastLED-idf/platforms/esp/32/clockless_rmt_esp32.cpp b/components/FastLED-idf/platforms/esp/32/clockless_rmt_esp32.cpp index fa657f8..e8a07c2 100644 --- a/components/FastLED-idf/platforms/esp/32/clockless_rmt_esp32.cpp +++ b/components/FastLED-idf/platforms/esp/32/clockless_rmt_esp32.cpp @@ -1,5 +1,4 @@ - - +#ifndef FASTLED_ESP32_I2S #define FASTLED_INTERNAL #include "FastLED.h" @@ -11,7 +10,7 @@ class ESP32RMTController; // -- Array of all controllers -// This array is filled at the time controllers are registered +// This array is filled at the time controllers are registered // (Usually when the sketch calls addLeds) static ESP32RMTController * gControllers[FASTLED_RMT_MAX_CONTROLLERS]; @@ -89,7 +88,7 @@ void IRAM_ATTR memorybuf_int( int i, char sep) { if ( maxbuf == 0 ) return; // for speed, just make sure I have 12 bytes, even though maybe I need fewer - // 12 is the number because I need a null which I will fill with sep, and + // 12 is the number because I need a null which I will fill with sep, and // there's always the chance of a minus if (maxbuf <= 12) return; @@ -204,9 +203,9 @@ static inline void fastled_set_mem_owner(rmt_channel_t channel, uint8_t owner) ESP32RMTController::ESP32RMTController(int DATA_PIN, int T1, int T2, int T3) - : mPixelData(0), - mSize(0), - mCur(0), + : mPixelData(0), + mSize(0), + mCur(0), mWhichHalf(0), mBuffer(0), mBufferSize(0), @@ -285,7 +284,7 @@ void ESP32RMTController::init() rmt_tx.gpio_num = gpio_num_t(0); // The particular pin will be assigned later #endif - rmt_tx.mem_block_num = MEM_BLOCK_NUM; + rmt_tx.mem_block_num = MEM_BLOCK_NUM; rmt_tx.clk_div = DIVIDER; rmt_tx.tx_config.loop_en = false; rmt_tx.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW; @@ -298,7 +297,7 @@ void ESP32RMTController::init() if (FASTLED_RMT_BUILTIN_DRIVER) { ESP_ERROR_CHECK( rmt_driver_install(rmt_channel, 0, 0) ); - } + } else { // -- Set up the RMT to send 32 bits of the pulse buffer and then @@ -390,7 +389,7 @@ void ESP32RMTController::showPixels() #if FASTLED_ESP32_SHOWTIMING == 1 // the interrupts may have dumped things to the buffer. Print it. - // warning: this does a fairly large stack allocation. + // warning: this does a fairly large stack allocation. char mb[MEMORYBUF_SIZE+1]; int mb_len = MEMORYBUF_SIZE; memorybuf_get(mb, &mb_len); @@ -479,12 +478,12 @@ void ESP32RMTController::tx_start() // In the case of the build-in driver, they specify the RMT channel // so we use the arg instead -void ESP32RMTController::doneOnRMTChannel(rmt_channel_t channel, void * arg) +void ESP32RMTController::doneOnRMTChannel(rmt_channel_t channel, void * arg) { doneOnChannel((int) arg, (void *) 0); } -// -- A controller is done +// -- A controller is done // This function is called when a controller finishes writing // its data. It is called either by the custom interrupt // handler (below), or as a callback from the built-in @@ -518,7 +517,7 @@ void ESP32RMTController::doneOnChannel(int channel, void * arg) } } } - + // -- Custom interrupt handler // This interrupt handler handles two cases: a controller is // done writing its data, or a controller needs to fill the @@ -588,7 +587,7 @@ bool IRAM_ATTR ESP32RMTController::timingOk() { memorybuf_add( g_bail_str ); #endif /* FASTLED_ESP32_SHOWTIMING == 1 */ - // how do we bail out? It seems if we simply call rmt_tx_stop, + // how do we bail out? It seems if we simply call rmt_tx_stop, // we'll still flicker on the end. Setting mCur to mSize has the side effect // of triggering the other code that says "we're finished" @@ -633,8 +632,8 @@ void IRAM_ATTR ESP32RMTController::fillNext() // set the owner to SW --- current driver does this but its not clear it matters fastled_set_mem_owner(mRMT_channel, RMT_MEM_OWNER_SW); - - // Shift bits out, MSB first, setting RMTMEM.chan[n].data32[x] to the + + // Shift bits out, MSB first, setting RMTMEM.chan[n].data32[x] to the // rmt_item32_t value corresponding to the buffered bit value for (int i=0; i < PULSES_PER_FILL / 32; i++) { @@ -682,7 +681,7 @@ void IRAM_ATTR ESP32RMTController::fillNext() // -- Init pulse buffer // Set up the buffer that will hold all of the pulse items for this -// controller. +// controller. // This function is only used when the built-in RMT driver is chosen void ESP32RMTController::initPulseBuffer(int size_in_bytes) { @@ -714,4 +713,4 @@ void ESP32RMTController::convertByte(uint32_t byteval) mCurPulse++; } } - +#endif // FASTLED_ESP32_I2S