diff --git a/CMakeLists.txt b/CMakeLists.txt index 960acbe..6ac4a9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,12 +11,12 @@ set(srcs "platforms.cpp" "power_mgt.cpp" "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" ) +if(CONFIG_FASTLED_METHOD_RMT) + list(APPEND srcs "platforms/esp/32/clockless_rmt_esp32.cpp") +endif() + # 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") diff --git a/FastLED.h b/FastLED.h index ef57686..c2cd250 100644 --- a/FastLED.h +++ b/FastLED.h @@ -10,10 +10,6 @@ #endif #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/Kconfig.projbuild b/Kconfig.projbuild new file mode 100644 index 0000000..0cc3333 --- /dev/null +++ b/Kconfig.projbuild @@ -0,0 +1,13 @@ +menu "FastLED" + +choice FASTLED_METHOD + bool "Used method/implementation" + default FASTLED_METHOD_I2S + + config FASTLED_METHOD_I2S + bool "I2S" + config FASTLED_METHOD_RMT + bool "RMT" +endchoice + +endmenu diff --git a/platforms/esp/32/clockless_esp32.h b/platforms/esp/32/clockless_esp32.h new file mode 100644 index 0000000..f5bb0fd --- /dev/null +++ b/platforms/esp/32/clockless_esp32.h @@ -0,0 +1,30 @@ +/* + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +FASTLED_NAMESPACE_BEGIN + +__attribute__ ((always_inline)) inline static uint32_t __clock_cycles() { + uint32_t cyc; + __asm__ __volatile__ ("rsr %0,ccount":"=a" (cyc)); + return cyc; +} + +FASTLED_NAMESPACE_END diff --git a/platforms/esp/32/clockless_i2s_esp32.h b/platforms/esp/32/clockless_i2s_esp32.h index 2042148..08d25a0 100644 --- a/platforms/esp/32/clockless_i2s_esp32.h +++ b/platforms/esp/32/clockless_i2s_esp32.h @@ -110,17 +110,13 @@ extern "C" { #include "esp32/rom/lldesc.h" #include "esp_log.h" + +#include "clockless_esp32.h" #ifdef __cplusplus } #endif -__attribute__ ((always_inline)) inline static uint32_t __clock_cycles() { - uint32_t cyc; - __asm__ __volatile__ ("rsr %0,ccount":"=a" (cyc)); - return cyc; -} - #define FASTLED_HAS_CLOCKLESS 1 #define NUM_COLOR_CHANNELS 3 diff --git a/platforms/esp/32/clockless_rmt_esp32.cpp b/platforms/esp/32/clockless_rmt_esp32.cpp index 785670e..7306085 100644 --- a/platforms/esp/32/clockless_rmt_esp32.cpp +++ b/platforms/esp/32/clockless_rmt_esp32.cpp @@ -2,8 +2,6 @@ #define FASTLED_INTERNAL #include "FastLED.h" -#include "clockless_rmt_esp32.h" - //static const char *TAG = "FastLED"; #include "esp_idf_version.h" diff --git a/platforms/esp/32/clockless_rmt_esp32.h b/platforms/esp/32/clockless_rmt_esp32.h index 9e69cbc..5df111a 100644 --- a/platforms/esp/32/clockless_rmt_esp32.h +++ b/platforms/esp/32/clockless_rmt_esp32.h @@ -123,6 +123,8 @@ extern "C" { #include "esp_log.h" +#include "clockless_esp32.h" + extern void spi_flash_op_lock(void); extern void spi_flash_op_unlock(void); diff --git a/platforms/esp/32/fastled_esp32.h b/platforms/esp/32/fastled_esp32.h index 6e9a1c5..56dd1a3 100644 --- a/platforms/esp/32/fastled_esp32.h +++ b/platforms/esp/32/fastled_esp32.h @@ -1,14 +1,18 @@ #pragma once +#include "sdkconfig.h" + #include "fastpin_esp32.h" #ifdef FASTLED_ALL_PINS_HARDWARE_SPI #include "fastspi_esp32.h" #endif -#ifdef FASTLED_ESP32_I2S +#ifdef CONFIG_FASTLED_METHOD_I2S #include "clockless_i2s_esp32.h" -#else +#endif + +#ifdef CONFIG_FASTLED_METHOD_RMT #include "clockless_rmt_esp32.h" #endif