diff --git a/src/internal/NeoUtil.h b/src/internal/NeoUtil.h index 8d74ca4..53afc57 100644 --- a/src/internal/NeoUtil.h +++ b/src/internal/NeoUtil.h @@ -67,7 +67,7 @@ static uint32_t getEspCycleCount(void) { uint32_t ccount; -#if defined(CONFIG_IDF_TARGET_ESP32C3) +#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) __asm__ __volatile__("csrr %0,0x7e2":"=r" (ccount)); //ccount = esp_cpu_get_ccount(); #else diff --git a/src/internal/features/DotStarL4ByteFeature.h b/src/internal/features/DotStarL4ByteFeature.h index a0cd6ad..bb01984 100644 --- a/src/internal/features/DotStarL4ByteFeature.h +++ b/src/internal/features/DotStarL4ByteFeature.h @@ -28,7 +28,7 @@ License along with NeoPixel. If not, see template class DotStarL4ByteFeature : - public NeoByteElements<4, RgbwColor, uint32_t> + public NeoElementsBase<4, RgbwColor> { public: static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color) diff --git a/src/internal/features/DotStarL4WordFeature.h b/src/internal/features/DotStarL4WordFeature.h index 5f27f34..da2465b 100644 --- a/src/internal/features/DotStarL4WordFeature.h +++ b/src/internal/features/DotStarL4WordFeature.h @@ -28,62 +28,30 @@ License along with NeoPixel. If not, see template class DotStarL4WordFeature : - public NeoWordElements<8, Rgbw64Color, uint32_t> + public NeoElementsBase<8, Rgbw64Color> { public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color) { - uint8_t* p = getPixelAddress(pPixels, indexPixel); + if (PixelSize <= pixelSize) + { + uint8_t* p = pixel; - uint8_t brightness = (color.W < 31 ? color.W : 31); + uint8_t brightness = (color.W < 31 ? color.W : 31); - // upper bit is always 1 and three 5 bit brightness - // {1}{5}{5}{5} - // 1rrr rrgg gggb bbbb - *p++ = 0x80 | (brightness << 2) | (brightness > 3); - *p++ = (brightness << 5) | (brightness); + // upper bit is always 1 and three 5 bit brightness + // {1}{5}{5}{5} + // 1rrr rrgg gggb bbbb + *p++ = 0x80 | (brightness << 2) | (brightness > 3); + *p++ = (brightness << 5) | (brightness); - // due to endianness the byte order must be copied to output - *p++ = color[V_IC_1] >> 8; - *p++ = color[V_IC_1] & 0xff; - *p++ = color[V_IC_2] >> 8; - *p++ = color[V_IC_2] & 0xff; - *p++ = color[V_IC_3] >> 8; - *p = color[V_IC_3] & 0xff; + // due to endianness the byte order must be copied to output + *p++ = color[V_IC_1] >> 8; + *p++ = color[V_IC_1] & 0xff; + *p++ = color[V_IC_2] >> 8; + *p++ = color[V_IC_2] & 0xff; + *p++ = color[V_IC_3] >> 8; + *p = color[V_IC_3] & 0xff; + } } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - p++; // ignore the first byte - color.W = (*p++) & 0x1F; // mask out all but lower five bits - - // due to endianness the byte order must be copied to output - color[V_IC_1] = (static_cast(*p++) << 8); - color[V_IC_1] |= *p++; - color[V_IC_2] = (static_cast(*p++) << 8); - color[V_IC_2] |= *p++; - color[V_IC_3] = (static_cast(*p++) << 8); - color[V_IC_3] |= *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); - - // PROGMEM unit of storage expected to be the same size as color element - // so no endianness issues to worry about - color.W = pgm_read_word(p++) & 0x001F; // mask out all but lower five bits - color[V_IC_1] = pgm_read_word(p++); - color[V_IC_2] = pgm_read_word(p++); - color[V_IC_3] = pgm_read_word(p); - - return color; - } - }; diff --git a/src/internal/features/DotStarX4ByteFeature.h b/src/internal/features/DotStarX4ByteFeature.h index 36a07ee..2c33641 100644 --- a/src/internal/features/DotStarX4ByteFeature.h +++ b/src/internal/features/DotStarX4ByteFeature.h @@ -28,7 +28,7 @@ License along with NeoPixel. If not, see template class DotStarX4ByteFeature : - public NeoByteElements<4, RgbColor, uint32_t> + public NeoElementsBase<4, RgbColor> { public: static void applyPixelColor(uint8_t* pixel, size_t pixelSize, ColorObject color) diff --git a/src/internal/features/DotStarX4WordFeature.h b/src/internal/features/DotStarX4WordFeature.h index 25f0f6e..87f3355 100644 --- a/src/internal/features/DotStarX4WordFeature.h +++ b/src/internal/features/DotStarX4WordFeature.h @@ -28,56 +28,24 @@ License along with NeoPixel. If not, see template class DotStarX4WordFeature : - public NeoWordElements<8, Rgb48Color, uint32_t> + public NeoElementsBase<8, Rgb48Color> { public: - static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + static void applyPixelColor(uint8_t* pixel, uint16_t pixelSize, ColorObject color) { - uint8_t* p = getPixelAddress(pPixels, indexPixel); + if (PixelSize <= pixelSize) + { + uint8_t* p = pixel; - *p++ = 0xff; // upper bit is always 1 and three 5 bit brightness at max - *p++ = 0xff; // {1}{5}{5}{5} - // due to endianness the byte order must be copied to output - *p++ = color[V_IC_1] >> 8; - *p++ = color[V_IC_1] & 0xff; - *p++ = color[V_IC_2] >> 8; - *p++ = color[V_IC_2] & 0xff; - *p++ = color[V_IC_3] >> 8; - *p = color[V_IC_3] & 0xff; + *p++ = 0xff; // upper bit is always 1 and three 5 bit brightness at max + *p++ = 0xff; // {1}{5}{5}{5} + // due to endianness the byte order must be copied to output + *p++ = color[V_IC_1] >> 8; + *p++ = color[V_IC_1] & 0xff; + *p++ = color[V_IC_2] >> 8; + *p++ = color[V_IC_2] & 0xff; + *p++ = color[V_IC_3] >> 8; + *p = color[V_IC_3] & 0xff; + } } - - static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint8_t* p = getPixelAddress(pPixels, indexPixel); - - p++; // ignore the first two bytes - p++; - - // due to endianness the byte order must be copied to output - color[V_IC_1] = (static_cast(*p++) << 8); - color[V_IC_1] |= *p++; - color[V_IC_2] = (static_cast(*p++) << 8); - color[V_IC_2] |= *p++; - color[V_IC_3] = (static_cast(*p++) << 8); - color[V_IC_3] |= *p; - - return color; - } - - static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) - { - ColorObject color; - const uint16_t* p = reinterpret_cast(getPixelAddress(reinterpret_cast(pPixels), indexPixel)); - - // PROGMEM unit of storage expected to be the same size as color element - // so no endianness issues to worry about - p++; // ignore the first word - color[V_IC_1] = pgm_read_word(p++); - color[V_IC_2] = pgm_read_word(p++); - color[V_IC_3] = pgm_read_word(p); - - return color; - } - }; diff --git a/src/internal/methods/NeoEsp32RmtMethod.h b/src/internal/methods/NeoEsp32RmtMethod.h index 7099ddc..77aee61 100644 --- a/src/internal/methods/NeoEsp32RmtMethod.h +++ b/src/internal/methods/NeoEsp32RmtMethod.h @@ -566,16 +566,16 @@ public: NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : _pin(pin), - _sizeDataSending(pixelCount* elementSize + settingsSize), - _pixelCount(pixelCount) + _pixelCount(pixelCount), + _sizeDataSending(pixelCount * elementSize + settingsSize) { construct(); } NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize, NeoBusChannel channel) : _pin(pin), - _sizeDataSending(pixelCount* elementSize + settingsSize), _pixelCount(pixelCount), + _sizeDataSending(pixelCount * elementSize + settingsSize), _channel(channel) { construct(); @@ -686,16 +686,15 @@ public: } private: - const uint8_t _pin; // output pin number - const uint16_t _pixelCount; // count of pixels in the strip - const size_t _sizeDataSending; // Size of '_data*' buffers + const uint8_t _pin; // output pin number + const uint16_t _pixelCount; // count of pixels in the strip + const size_t _sizeDataSending; // Size of '_data*' buffers const T_CHANNEL _channel; // holds instance for multi channel support // Holds data stream which include LED color values and other settings as needed uint8_t* _dataSending; // used for async send using RMT - void construct() { _dataSending = static_cast(malloc(_sizeDataSending)); diff --git a/src/internal/methods/NeoEspBitBangMethod.cpp b/src/internal/methods/NeoEspBitBangMethod.cpp index d3a4b5f..fe09da2 100644 --- a/src/internal/methods/NeoEspBitBangMethod.cpp +++ b/src/internal/methods/NeoEspBitBangMethod.cpp @@ -34,19 +34,6 @@ License along with NeoPixel. If not, see #include #endif -static inline uint32_t getCycleCount(void) -{ - uint32_t ccount; - -#if defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6) || defined(CONFIG_IDF_TARGET_ESP32H2) - __asm__ __volatile__("csrr %0,0x7e2":"=r" (ccount)); - //ccount = esp_cpu_get_ccount(); -#else - __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); -#endif - return ccount; -} - // Interrupt lock class, used for RAII interrupt disabling class InterruptLock {