diff --git a/src/internal/NeoColorFeatures.h b/src/internal/NeoColorFeatures.h index c953f88..12ea4e9 100644 --- a/src/internal/NeoColorFeatures.h +++ b/src/internal/NeoColorFeatures.h @@ -32,6 +32,7 @@ License along with NeoPixel. If not, see #include "features/Neo3ByteElements.h" #include "features/Neo4ByteElements.h" #include "features/Neo6ByteElements.h" +#include "features/Neo6Byte4xxElements.h" #include "features/Neo8ByteElements.h" #include "features/NeoBgrFeature.h" #include "features/NeoBrgFeature.h" @@ -43,6 +44,7 @@ License along with NeoPixel. If not, see #include "features/NeoRgbFeature.h" #include "features/NeoRgbw64Feature.h" #include "features/NeoRgbwFeature.h" +#include "features/NeoRgbwxxFeature.h" #include "features/NeoSm168xxColorFeatures.h" #include "features/NeoTm1814ColorFeatures.h" #include "features/NeoTm1914ColorFeatures.h" diff --git a/src/internal/features/Neo6Byte4xxElements.h b/src/internal/features/Neo6Byte4xxElements.h new file mode 100644 index 0000000..14961aa --- /dev/null +++ b/src/internal/features/Neo6Byte4xxElements.h @@ -0,0 +1,116 @@ +/*------------------------------------------------------------------------- +Neo6Byte4xxElements provides feature base classes to describe color elements +for NeoPixelBus Color Feature template classes. While it takes 6 bytes, it +only uses four and ignores the last two + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + + +class Neo6Byte4xxElements +{ +public: + static const size_t PixelSize = 6; + + static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel) + { + return pPixels + indexPixel * PixelSize; + } + + static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint16_t* pDest = reinterpret_cast(pPixelDest); + const uint16_t* pSrc = reinterpret_cast(pPixelSrc); + const uint16_t* pEnd = pDest + (count * PixelSize / sizeof(*pDest)); + + while (pDest < pEnd) + { + *pDest++ = *pSrc; + } + } + + static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint16_t* pDest = reinterpret_cast(pPixelDest); + const uint16_t* pSrc = reinterpret_cast(pPixelSrc); + const uint16_t* pEnd = pDest + (count * PixelSize / sizeof(*pDest)); + + while (pDest < pEnd) + { + *pDest++ = *pSrc++; + } + } + + static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count) + { + uint16_t* pDest = reinterpret_cast(pPixelDest); + const uint16_t* pSrc = reinterpret_cast(pPixelSrc); + const uint16_t* pEnd = pDest + (count * PixelSize / sizeof(*pDest)); + + while (pDest < pEnd) + { + *pDest++ = pgm_read_word(pSrc++); + } + } + + static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count) + { + uint16_t* pDest = reinterpret_cast(pPixelDest); + const uint16_t* pSrc = reinterpret_cast(pPixelSrc); + uint16_t* pDestBack = pDest + (count * PixelSize / sizeof(*pDest)); + const uint16_t* pSrcBack = pSrc + (count * PixelSize / sizeof(*pSrc)); + + while (pDestBack > pDest) + { + *--pDestBack = *--pSrcBack; + } + } + + typedef RgbwColor ColorObject; +}; + +class Neo6Byte4xxElementsNoSettings : public Neo6Byte4xxElements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings) + { + } + + static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData) + { + return pData; + } + + static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData) + { + return pData; + } +}; \ No newline at end of file diff --git a/src/internal/features/NeoRgbwxxFeature.h b/src/internal/features/NeoRgbwxxFeature.h new file mode 100644 index 0000000..cd167ab --- /dev/null +++ b/src/internal/features/NeoRgbwxxFeature.h @@ -0,0 +1,72 @@ +/*------------------------------------------------------------------------- +NeoRgbwxxFeature provides feature classes to describe color order and +color depth for NeoPixelBus template class + +Written by Michael C. Miller. + +I invest time and resources providing this open source code, +please support me by dontating (see https://github.com/Makuna/NeoPixelBus) + +------------------------------------------------------------------------- +This file is part of the Makuna/NeoPixelBus library. + +NeoPixelBus is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation, either version 3 of +the License, or (at your option) any later version. + +NeoPixelBus is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with NeoPixel. If not, see +. +-------------------------------------------------------------------------*/ +#pragma once + +class NeoRgbwxxFeature : public Neo6Byte4xxElementsNoSettings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.R; + *p++ = color.G; + *p++ = color.B; + *p++ = color.W; + // zero the xx, this maybe unnecessary though, but its thorough + *p++ = 0; + *p = 0; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.R = *p++; + color.G = *p++; + color.B = *p++; + color.W = *p; + // ignore the xx + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(reinterpret_cast(pPixels), indexPixel); + + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + // ignore the xx + + return color; + } +};