From a9e06f875973f98cd8f62cc03a2a3c691d9ae264 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 18 Sep 2024 11:19:18 -0700 Subject: [PATCH] compiles --- src/internal/NeoMethods.h | 2 +- .../ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.cpp | 5 ++- .../methods/ESP/ESP32/NeoEsp32RmtSpeed.h | 35 +++++++----------- .../methods/ESP/ESP32/NeoEsp32RmtXMethod.h | 37 +++++++------------ 4 files changed, 32 insertions(+), 47 deletions(-) diff --git a/src/internal/NeoMethods.h b/src/internal/NeoMethods.h index d8bd8df..4acbbab 100644 --- a/src/internal/NeoMethods.h +++ b/src/internal/NeoMethods.h @@ -63,7 +63,7 @@ License along with NeoPixel. If not, see #include "methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.h" #else #if !defined(CONFIG_IDF_TARGET_ESP32C2) -#include "methods/ESP/ESP32/NeoEsp32RmtMethod.h" // every other SOC +#include "methods/ESP/ESP32/NeoEsp32RmtXMethod.h" // every other SOC #else //CONFIG_IDF_TARGET_ESP32C2 #include "methods/ESP/ESP32/NeoEsp32SpiMethod.h" // ESP32C2 #endif //CONFIG_IDF_TARGET_ESP32C2 diff --git a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.cpp b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.cpp index cd147bb..8f91436 100644 --- a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.cpp +++ b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.cpp @@ -29,6 +29,8 @@ License along with NeoPixel. If not, see #include +#if ESP_IDF_VERSION_MAJOR < 5 + #if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C6) && !defined(CONFIG_IDF_TARGET_ESP32H2) #include "../../../../NeoSettings.h" @@ -373,4 +375,5 @@ void NeoEsp32RmtInvertedSpeedGs1903::Translate(const void* src, RmtBit0, RmtBit1, RmtDurationReset); } -#endif \ No newline at end of file +#endif +#endif diff --git a/src/internal/methods/ESP/ESP32/NeoEsp32RmtSpeed.h b/src/internal/methods/ESP/ESP32/NeoEsp32RmtSpeed.h index f86e354..9d9e217 100644 --- a/src/internal/methods/ESP/ESP32/NeoEsp32RmtSpeed.h +++ b/src/internal/methods/ESP/ESP32/NeoEsp32RmtSpeed.h @@ -29,46 +29,40 @@ License along with NeoPixel. If not, see class NeoEsp32RmtSpeed { public: - // next section is probably not needed anymore for IDF 5.1 + // // ClkDiv of 2 provides for good resolution and plenty of reset resolution; but // a ClkDiv of 1 will provide enough space for the longest reset and does show // little better pulse accuracy const static uint8_t RmtClockDivider = 2; + const static uint32_t RmtCpu = 80000000L; // 80 mhz RMT clock + const static uint32_t NsPerSecond = 1000000000L; + const static uint32_t RmtTicksPerSecond = (RmtCpu / RmtClockDivider); + const static uint32_t NsPerRmtTick = (NsPerSecond / RmtTicksPerSecond); // about 25 inline constexpr static uint32_t FromNs(uint32_t ns) { return ns / NsPerRmtTick; } - -protected: - const static uint32_t RmtCpu = 80000000L; // 80 mhz RMT clock - const static uint32_t NsPerSecond = 1000000000L; - const static uint32_t RmtTicksPerSecond = (RmtCpu / RmtClockDivider); - const static uint32_t NsPerRmtTick = (NsPerSecond / RmtTicksPerSecond); // about 25 - // end of deprecated section - -}; - -class NeoEsp32RmtSpeedBase : public NeoEsp32RmtSpeed -{ -public: // this is used rather than the rmt_symbol_word_t as you can't correctly initialize // it as a static constexpr within the template inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow) { return (FromNs(nsLow) << 16) | (1 << 15) | (FromNs(nsHigh)); } + + +}; + +class NeoEsp32RmtSpeedBase : public NeoEsp32RmtSpeed +{ +public: + const static bool Inverted = false; }; class NeoEsp32RmtInvertedSpeedBase : public NeoEsp32RmtSpeed { public: - // this is used rather than the rmt_symbol_word_t as you can't correctly initialize - // it as a static constexpr within the template - inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow) - { - return (FromNs(nsLow) << 16) | (1 << 31) | (FromNs(nsHigh)); - } + const static bool Inverted = true; }; class NeoEsp32RmtSpeedWs2811 : public NeoEsp32RmtSpeedBase @@ -237,4 +231,3 @@ public: const static uint16_t RmtDurationReset = FromNs(80000); // 80us }; -#endif diff --git a/src/internal/methods/ESP/ESP32/NeoEsp32RmtXMethod.h b/src/internal/methods/ESP/ESP32/NeoEsp32RmtXMethod.h index f5146d0..da1b19e 100644 --- a/src/internal/methods/ESP/ESP32/NeoEsp32RmtXMethod.h +++ b/src/internal/methods/ESP/ESP32/NeoEsp32RmtXMethod.h @@ -28,18 +28,6 @@ License along with NeoPixel. If not, see #if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C2) -/* General Reference documentation for the APIs used in this implementation -LOW LEVEL: (what is actually used) -DOCS: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/rmt.html -EXAMPLE: https://github.com/espressif/esp-idf/blob/826ff7186ae07dc81e960a8ea09ebfc5304bfb3b/examples/peripherals/rmt_tx/main/rmt_tx_main.c - -HIGHER LEVEL: -NO TRANSLATE SUPPORT so this was not used -NOTE: https://github.com/espressif/arduino-esp32/commit/50d142950d229b8fabca9b749dc4a5f2533bc426 -Esp32-hal-rmt.h -Esp32-hal-rmt.c -*/ - #include #include "NeoEsp32RmtSpeed.h" @@ -53,8 +41,6 @@ extern "C" #include "esp_check.h" } -#define RMT_LED_STRIP_RESOLUTION_HZ 40000000 // 40MHz resolution - setting of the "old" driver - struct led_strip_encoder_config_t { uint32_t resolution; /*!< Encoder resolution, in Hz */ @@ -192,7 +178,7 @@ template class NeoEsp32RmtMethodBase public: typedef NeoNoSettings SettingsObject; - NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize, NeoBusChannel channel = 0) : + NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize, NeoBusChannel channel = NeoBusChannel_0) : _sizeData(pixelCount* elementSize + settingsSize), _pin(pin), _channel(NULL) @@ -228,14 +214,14 @@ public: config.clk_src = RMT_CLK_SRC_DEFAULT; config.gpio_num = static_cast(_pin); config.mem_block_symbols = 192; // memory block size, 64 * 4 = 256 Bytes - config.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ; // 1 MHz tick resolution, i.e., 1 tick = 1 µs + config.resolution_hz = T_SPEED::RmtTicksPerSecond; // 1 MHz tick resolution, i.e., 1 tick = 1 µs config.trans_queue_depth = 4; // set the number of transactions that can pend in the background - config.flags.invert_out = false; // do not invert output signal + config.flags.invert_out = T_SPEED::Inverted; // do not invert output signal config.flags.with_dma = false; // do not need DMA backend ret += rmt_new_tx_channel(&config, &_channel); led_strip_encoder_config_t encoder_config = {}; - encoder_config.resolution = RMT_LED_STRIP_RESOLUTION_HZ; + encoder_config.resolution = T_SPEED::RmtTicksPerSecond; _tx_config.loop_count = 0; //no loop @@ -259,7 +245,8 @@ public: { // AddLog(2,"__ %u", _sizeData); // now start the RMT transmit with the editing buffer before we swap - esp_err_t ret = rmt_transmit(_channel, _led_encoder, _dataEditing, _sizeData, &_tx_config); // 3 for _sizeData + // esp_err_t ret = + rmt_transmit(_channel, _led_encoder, _dataEditing, _sizeData, &_tx_config); // 3 for _sizeData // AddLog(2,"rmt_transmit: %u", ret); if (maintainBufferConsistency) { @@ -317,6 +304,13 @@ private: } }; +// NOTE: While these are multi-instance auto channel selecting, there are limits +// to the number of times based on the specific ESP32 model it is compiled for +// ESP32 - 8x (beyond 4x may experience issues) +// ESP32S2 - 4x +// ESP32C3 - 2x +// ESP32S3 - 4x + // normal typedef NeoEsp32RmtMethodBase NeoEsp32RmtXWs2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtXWs2812xMethod; @@ -329,8 +323,6 @@ typedef NeoEsp32RmtMethodBase NeoEsp32RmtXTx1812Method; typedef NeoEsp32RmtMethodBase NeoEsp32RmtX800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtX400KbpsMethod; -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) -#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C3) // inverted typedef NeoEsp32RmtMethodBase NeoEsp32RmtXWs2811InvertedMethod; @@ -344,9 +336,6 @@ typedef NeoEsp32RmtMethodBase NeoEsp32RmtXTx1812 typedef NeoEsp32RmtMethodBase NeoEsp32RmtX800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32RmtX400KbpsInvertedMethod; -#endif // !defined(CONFIG_IDF_TARGET_ESP32S2) -#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32C6) - #if defined(NEOPIXEL_ESP32_RMT_DEFAULT) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32S3)