From 22746479f6562b3f132e817a343494cb4082c197 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Mar 2024 11:38:45 -0700 Subject: [PATCH] Compiles with IDF5 (#789) --- src/internal/NeoMethods.h | 6 ++- src/internal/features/DotStarX4ByteFeature.h | 2 +- src/internal/features/P9813BgrFeature.h | 2 +- src/internal/methods/Esp32_i2s.c | 54 +++++++++++--------- src/internal/methods/NeoEsp32I2sMethod.h | 3 +- src/internal/methods/NeoEsp32I2sXMethod.h | 1 + src/internal/methods/NeoEsp32RmtMethod.cpp | 5 +- src/internal/methods/NeoEsp32RmtMethod.h | 1 + src/internal/methods/NeoEspBitBangMethod.cpp | 6 ++- 9 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/internal/NeoMethods.h b/src/internal/NeoMethods.h index 89d2c28..827d1e2 100644 --- a/src/internal/NeoMethods.h +++ b/src/internal/NeoMethods.h @@ -53,12 +53,16 @@ License along with NeoPixel. If not, see #elif defined(ARDUINO_ARCH_ESP32) +#if !defined(ARDUINO_ESP32C6_DEV) && !defined(ARDUINO_ESP32H2_DEV) #include "methods/NeoEsp32I2sMethod.h" #include "methods/NeoEsp32RmtMethod.h" -#include "methods/NeoEspBitBangMethod.h" #include "methods/DotStarEsp32DmaSpiMethod.h" #include "methods/NeoEsp32I2sXMethod.h" +#include "methods/NeoEspBitBangMethod.h" +#endif + + #elif defined(ARDUINO_ARCH_NRF52840) // must be before __arm__ #include "methods/NeoNrf52xMethod.h" diff --git a/src/internal/features/DotStarX4ByteFeature.h b/src/internal/features/DotStarX4ByteFeature.h index 2d2aeb7..f277d82 100644 --- a/src/internal/features/DotStarX4ByteFeature.h +++ b/src/internal/features/DotStarX4ByteFeature.h @@ -59,7 +59,7 @@ public: ColorObject color; const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); - pgm_read_byte(p++); // ignore the first byte + p++; // ignore the first byte color[V_IC_1] = pgm_read_byte(p++); color[V_IC_2] = pgm_read_byte(p++); color[V_IC_3] = pgm_read_byte(p); diff --git a/src/internal/features/P9813BgrFeature.h b/src/internal/features/P9813BgrFeature.h index c81fda6..c66d08e 100644 --- a/src/internal/features/P9813BgrFeature.h +++ b/src/internal/features/P9813BgrFeature.h @@ -60,7 +60,7 @@ public: ColorObject color; const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); - pgm_read_byte(p++); // ignore the first byte + p++; // ignore the first byte color.B = pgm_read_byte(p++); color.G = pgm_read_byte(p++); color.R = pgm_read_byte(p); diff --git a/src/internal/methods/Esp32_i2s.c b/src/internal/methods/Esp32_i2s.c index 76293c8..4c41ffe 100644 --- a/src/internal/methods/Esp32_i2s.c +++ b/src/internal/methods/Esp32_i2s.c @@ -14,15 +14,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#if defined(ARDUINO_ARCH_ESP32) +// ESP32 C3 & S3 I2S is not supported yet due to significant changes to interface +#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(ARDUINO_ESP32C3_DEV) && !defined(ARDUINO_ESP32S3_DEV) && !defined(ARDUINO_ESP32C6_DEV) && !defined(ARDUINO_ESP32H2_DEV) #include "sdkconfig.h" // this sets useful config symbols, like CONFIG_IDF_TARGET_ESP32C3 -// ESP32 C3 & S3 I2S is not supported yet due to significant changes to interface -#if defined(ARDUINO_ARCH_ESP32) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) - - - #include #include #include "stdlib.h" @@ -45,18 +41,27 @@ #include "soc/io_mux_reg.h" #include "soc/rtc_cntl_reg.h" #include "soc/i2s_struct.h" + #if defined(CONFIG_IDF_TARGET_ESP32) /* included here for ESP-IDF v4.x compatibility */ #include "soc/dport_reg.h" #endif + #include "soc/sens_reg.h" #include "driver/gpio.h" #include "driver/i2s.h" +#if ESP_IDF_VERSION_MAJOR>=5 +#include "rom/gpio.h" +#include "esp_private/periph_ctrl.h" +#endif + #if !defined(CONFIG_IDF_TARGET_ESP32S3) #include "driver/dac.h" #endif + + #include "Esp32_i2s.h" #include "esp32-hal.h" @@ -65,7 +70,7 @@ esp_err_t i2sSetSampleRate(uint8_t bus_num, uint32_t sample_rate, bool parallel_ #define MATRIX_DETACH_OUT_SIG 0x100 -#if ESP_IDF_VERSION_MAJOR<=4 +#if ESP_IDF_VERSION_MAJOR<=5 #define I2S_BASE_CLK (160000000L) #endif @@ -101,14 +106,14 @@ typedef struct #define I2s_Is_Sending 2 #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) -static i2s_bus_t I2S[I2S_NUM_MAX] = +// (SOC_I2S_NUM == 2) +static i2s_bus_t I2S[SOC_I2S_NUM] = { {&I2S0, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle}, {&I2S1, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle} }; #else -static i2s_bus_t I2S[I2S_NUM_MAX] = +static i2s_bus_t I2S[SOC_I2S_NUM] = { {&I2S0, -1, -1, -1, -1, NULL, NULL, I2S_DMA_BLOCK_COUNT_DEFAULT, I2s_Is_Idle} }; @@ -130,7 +135,7 @@ inline void dmaItemInit(lldesc_t* item, uint8_t* posData, size_t sizeData, lldes bool i2sInitDmaItems(uint8_t bus_num, uint8_t* data, size_t dataSize, bool parallel_mode, size_t bytes_per_sample) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return false; } @@ -201,7 +206,7 @@ bool i2sInitDmaItems(uint8_t bus_num, uint8_t* data, size_t dataSize, bool paral bool i2sDeinitDmaItems(uint8_t bus_num) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return false; } @@ -219,7 +224,7 @@ esp_err_t i2sSetClock(uint8_t bus_num, uint8_t bck, uint8_t bits) { - if (bus_num >= I2S_NUM_MAX || div_a > 63 || div_b > 63 || bck > 63) + if (bus_num >= SOC_I2S_NUM || div_a > 63 || div_b > 63 || bck > 63) { return ESP_FAIL; } @@ -268,7 +273,7 @@ void i2sSetPins(uint8_t bus_num, int8_t busSampleSize, bool invert) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return; } @@ -356,7 +361,7 @@ void i2sSetClkWsPins(uint8_t bus_num, bool invertWs) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return; } @@ -387,7 +392,7 @@ void i2sSetClkWsPins(uint8_t bus_num, bool i2sWriteDone(uint8_t bus_num) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return false; } @@ -405,7 +410,7 @@ void i2sInit(uint8_t bus_num, uint8_t* data, size_t dataSize) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return; } @@ -420,7 +425,7 @@ void i2sInit(uint8_t bus_num, } #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) +// (SOC_I2S_NUM == 2) if (bus_num) { periph_module_enable(PERIPH_I2S1_MODULE); @@ -545,7 +550,7 @@ void i2sInit(uint8_t bus_num, int i2sIntSource; #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) +// (SOC_I2S_NUM == 2) if (bus_num == 1) { i2sIntSource = ETS_I2S1_INTR_SOURCE; @@ -707,7 +712,7 @@ esp_err_t i2sSetSampleRate(uint8_t bus_num, bool parallel_mode, size_t bytes_per_sample) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return ESP_FAIL; } @@ -784,7 +789,7 @@ void IRAM_ATTR i2sDmaISR(void* arg) bool i2sWrite(uint8_t bus_num) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return false; } @@ -913,7 +918,7 @@ void DumpI2s_fifo_conf(const char* label, i2s_dev_t* bus) bool i2sDump(uint8_t bus_num) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return false; } @@ -1009,7 +1014,7 @@ bool i2sGetClks(uint8_t bus_num, uint8_t* clkm_div_b, uint8_t* clkm_div_a) { - if (bus_num >= I2S_NUM_MAX) + if (bus_num >= SOC_I2S_NUM) { return false; } @@ -1031,6 +1036,5 @@ bool i2sGetClks(uint8_t bus_num, } #endif -#endif // !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -#endif // defined(ARDUINO_ARCH_ESP32) +#endif // defined(ARDUINO_ARCH_ESP32) ** !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) diff --git a/src/internal/methods/NeoEsp32I2sMethod.h b/src/internal/methods/NeoEsp32I2sMethod.h index 97e304a..b981b7d 100644 --- a/src/internal/methods/NeoEsp32I2sMethod.h +++ b/src/internal/methods/NeoEsp32I2sMethod.h @@ -32,6 +32,7 @@ License along with NeoPixel. If not, see extern "C" { +#include #include "Esp32_i2s.h" } @@ -313,7 +314,7 @@ typedef NeoEsp32I2sMethodBase NeoEsp32I2s0Apa106InvertedMethod; #if !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S3) -// (I2S_NUM_MAX == 2) +// (SOC_I2S_NUM == 2) typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Ws2812xMethod; typedef NeoEsp32I2sMethodBase NeoEsp32I2s1Ws2805Method; diff --git a/src/internal/methods/NeoEsp32I2sXMethod.h b/src/internal/methods/NeoEsp32I2sXMethod.h index be0d975..8473abb 100644 --- a/src/internal/methods/NeoEsp32I2sXMethod.h +++ b/src/internal/methods/NeoEsp32I2sXMethod.h @@ -31,6 +31,7 @@ License along with NeoPixel. If not, see extern "C" { +#include #include "Esp32_i2s.h" } diff --git a/src/internal/methods/NeoEsp32RmtMethod.cpp b/src/internal/methods/NeoEsp32RmtMethod.cpp index 596b19c..cf2950c 100644 --- a/src/internal/methods/NeoEsp32RmtMethod.cpp +++ b/src/internal/methods/NeoEsp32RmtMethod.cpp @@ -27,14 +27,13 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ +#if defined(ARDUINO_ARCH_ESP32) && !defined(ARDUINO_ESP32C6_DEV) && !defined(ARDUINO_ESP32H2_DEV) + #include #include "../NeoSettings.h" #include "../NeoBusChannel.h" #include "NeoEsp32RmtMethod.h" -#ifdef ARDUINO_ARCH_ESP32 - - // translate NeoPixelBuffer into RMT buffer // this is done on the fly so we don't require a send buffer in raw RMT format // which would be 32x larger than the primary buffer diff --git a/src/internal/methods/NeoEsp32RmtMethod.h b/src/internal/methods/NeoEsp32RmtMethod.h index 753a90a..bf1ca48 100644 --- a/src/internal/methods/NeoEsp32RmtMethod.h +++ b/src/internal/methods/NeoEsp32RmtMethod.h @@ -45,6 +45,7 @@ Esp32-hal-rmt.c extern "C" { +#include #include } diff --git a/src/internal/methods/NeoEspBitBangMethod.cpp b/src/internal/methods/NeoEspBitBangMethod.cpp index cbc446e..7021dd6 100644 --- a/src/internal/methods/NeoEspBitBangMethod.cpp +++ b/src/internal/methods/NeoEspBitBangMethod.cpp @@ -24,10 +24,14 @@ License along with NeoPixel. If not, see . -------------------------------------------------------------------------*/ -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) +#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) && !defined(ARDUINO_ESP32C6_DEV) && !defined(ARDUINO_ESP32H2_DEV) #include +#if ESP_IDF_VERSION_MAJOR>=5 +#include +#endif + static inline uint32_t getCycleCount(void) { uint32_t ccount;