diff --git a/src/internal/NeoColorFeatures.h b/src/internal/NeoColorFeatures.h index f822441..8d9f13f 100644 --- a/src/internal/NeoColorFeatures.h +++ b/src/internal/NeoColorFeatures.h @@ -37,8 +37,6 @@ License along with NeoPixel. If not, see #include "features/Neo3Byte777Feature.h" #include "features/Neo4ByteFeature.h" #include "features/Neo5ByteFeature.h" -#include "features/DotStarX4ByteFeature.h" -#include "features/DotStarL4ByteFeature.h" #include "features/Neo6ByteFeature.h" #include "features/Neo6xByteFeature.h" #include "features/Neo6xxByteFeature.h" @@ -46,6 +44,11 @@ License along with NeoPixel. If not, see #include "features/Neo4WordFeature.h" #include "features/Neo5WordFeature.h" +#include "features/DotStarX4ByteFeature.h" +#include "features/DotStarL4ByteFeature.h" +#include "features/DotStarX4WordFeature.h" +#include "features/DotStarL4WordFeature.h" + // NeoPixel Features // #include "features/NeoRgbFeatures.h" diff --git a/src/internal/NeoMethods.h b/src/internal/NeoMethods.h index 827d1e2..31a595f 100644 --- a/src/internal/NeoMethods.h +++ b/src/internal/NeoMethods.h @@ -37,6 +37,7 @@ License along with NeoPixel. If not, see #include "methods/Tlc59711GenericMethod.h" #include "methods/Sm16716GenericMethod.h" #include "methods/Mbi6033GenericMethod.h" +#include "methods/Hd108GenericMethod.h" //Adafruit Pixie via UART, not platform specific // diff --git a/src/internal/features/DotStarL4ByteFeature.h b/src/internal/features/DotStarL4ByteFeature.h index 2e1699d..a0cd6ad 100644 --- a/src/internal/features/DotStarL4ByteFeature.h +++ b/src/internal/features/DotStarL4ByteFeature.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -DotStarL4Feature provides feature base class to describe color order for +DotStarL4ByteFeature provides feature base class to describe color order for 3 color but 4 byte features when used with DotStars, exposing Luminance as W Written by Michael C. Miller. @@ -27,8 +27,8 @@ License along with NeoPixel. If not, see #pragma once template -class DotStarL4Feature : - public NeoElementsBase<4, RgbwColor> +class DotStarL4ByteFeature : + public NeoByteElements<4, RgbwColor, uint32_t> { 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 new file mode 100644 index 0000000..5f27f34 --- /dev/null +++ b/src/internal/features/DotStarL4WordFeature.h @@ -0,0 +1,89 @@ +/*------------------------------------------------------------------------- +DotStarL4WordFeature provides feature base class to describe color order for + 3 color but 4 byte features when used with DotStars, exposing Luminance as W + +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 + +template +class DotStarL4WordFeature : + public NeoWordElements<8, Rgbw64Color, uint32_t> +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + 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); + + // 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/DotStarLrgbFeatures.h b/src/internal/features/DotStarLrgbFeatures.h index 17c6d4f..adc352f 100644 --- a/src/internal/features/DotStarLrgbFeatures.h +++ b/src/internal/features/DotStarLrgbFeatures.h @@ -26,40 +26,51 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +// Byte features class DotStarLrgbFeature : - public DotStarL4Feature, + public DotStarL4ByteFeature, public NeoElementsNoSettings { }; class DotStarLrbgFeature : - public DotStarL4Feature, + public DotStarL4ByteFeature, public NeoElementsNoSettings { }; class DotStarLgrbFeature : - public DotStarL4Feature, + public DotStarL4ByteFeature, public NeoElementsNoSettings { }; class DotStarLgbrFeature : - public DotStarL4Feature, + public DotStarL4ByteFeature, public NeoElementsNoSettings { }; class DotStarLbrgFeature : - public DotStarL4Feature, + public DotStarL4ByteFeature, public NeoElementsNoSettings { }; class DotStarLbgrFeature : - public DotStarL4Feature, + public DotStarL4ByteFeature, public NeoElementsNoSettings { -}; \ No newline at end of file +}; + +// Word features + +class DotStarLbgr64Feature : + public DotStarL4WordFeature, + public NeoElementsNoSettings +{ +}; + +typedef DotStarLbgr64Feature Hd108LbgrFeature; \ No newline at end of file diff --git a/src/internal/features/DotStarRgbFeatures.h b/src/internal/features/DotStarRgbFeatures.h index 158e579..d5f2186 100644 --- a/src/internal/features/DotStarRgbFeatures.h +++ b/src/internal/features/DotStarRgbFeatures.h @@ -26,40 +26,52 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #pragma once +// Byte features + class DotStarRgbFeature : - public DotStarX4Feature, + public DotStarX4ByteFeature, public NeoElementsNoSettings { }; class DotStarRbgFeature : - public DotStarX4Feature, + public DotStarX4ByteFeature, public NeoElementsNoSettings { }; class DotStarGbrFeature : - public DotStarX4Feature, + public DotStarX4ByteFeature, public NeoElementsNoSettings { }; class DotStarGrbFeature : - public DotStarX4Feature, + public DotStarX4ByteFeature, public NeoElementsNoSettings { }; class DotStarBrgFeature : - public DotStarX4Feature, + public DotStarX4ByteFeature, public NeoElementsNoSettings { }; class DotStarBgrFeature : - public DotStarX4Feature, + public DotStarX4ByteFeature, public NeoElementsNoSettings { }; + +// Word features + +class DotStarBgr48Feature : + public DotStarX4WordFeature, + public NeoElementsNoSettings +{ +}; + +typedef DotStarBgr48Feature Hd108BgrFeature; diff --git a/src/internal/features/DotStarX4ByteFeature.h b/src/internal/features/DotStarX4ByteFeature.h index 6a981c5..36a07ee 100644 --- a/src/internal/features/DotStarX4ByteFeature.h +++ b/src/internal/features/DotStarX4ByteFeature.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -DotStarX4Feature provides feature base class to describe color order for +DotStarX4ByteFeature provides feature base class to describe color order for 3 color but 4 byte features when used with DotStars Written by Michael C. Miller. @@ -27,8 +27,8 @@ License along with NeoPixel. If not, see #pragma once template -class DotStarX4Feature : - public NeoElementsBase<4, RgbColor> +class DotStarX4ByteFeature : + public NeoByteElements<4, RgbColor, uint32_t> { 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 new file mode 100644 index 0000000..25f0f6e --- /dev/null +++ b/src/internal/features/DotStarX4WordFeature.h @@ -0,0 +1,83 @@ +/*------------------------------------------------------------------------- +DotStarX4WordFeature provides feature base class to describe color order for + 3 color but 4 byte features when used with DotStars + +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 + +template +class DotStarX4WordFeature : + public NeoWordElements<8, Rgb48Color, uint32_t> +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *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/Hd108GenericMethod.h b/src/internal/methods/Hd108GenericMethod.h new file mode 100644 index 0000000..9eba23d --- /dev/null +++ b/src/internal/methods/Hd108GenericMethod.h @@ -0,0 +1,166 @@ +/*------------------------------------------------------------------------- +NeoPixel library helper functions for HD108 using general Pins. + +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 + +// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set +#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__) +#include "TwoWireBitBangImpleAvr.h" +#else +#include "TwoWireBitBangImple.h" +#endif + + +template class Hd108MethodBase +{ +public: + typedef typename T_TWOWIRE::SettingsObject SettingsObject; + + Hd108MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), + _wire(pinClock, pinData) + { + _data = static_cast(malloc(_sizeData)); + // data cleared later in Begin() + } + +#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) + Hd108MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + Hd108MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize) + { + } +#endif + + ~Hd108MethodBase() + { + free(_data); + } + + bool IsReadyToUpdate() const + { + return true; // dot stars don't have a required delay + } + +#if defined(ARDUINO_ARCH_ESP32) + void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss) + { + _wire.begin(sck, miso, mosi, ss); + } +#endif + + void Initialize() + { + _wire.begin(); + } + + void Update(bool) + { + const uint8_t startFrame[4] = { 0x00 }; + const uint8_t endFrame[4] = { 0xff }; + + _wire.beginTransaction(); + + // start frame + _wire.transmitBytes(startFrame, sizeof(startFrame)); + + // data + _wire.transmitBytes(_data, _sizeData); + + // end frame + _wire.transmitBytes(endFrame, sizeof(endFrame)); + + _wire.endTransaction(); + } + + bool AlwaysUpdate() + { + // this method requires update to be called only if changes to buffer + return false; + } + + uint8_t* getData() const + { + return _data; + }; + + size_t getDataSize() const + { + return _sizeData; + }; + + void applySettings([[maybe_unused]] const SettingsObject& settings) + { + _wire.applySettings(settings); + } + +private: + const size_t _sizeData; // Size of '_data' buffer below + + T_TWOWIRE _wire; + uint8_t* _data; // Holds LED color values +}; + +typedef Hd108MethodBase Hd108Method; + +#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny) +#include "TwoWireSpiImple.h" +typedef Hd108MethodBase> Hd108Spi40MhzMethod; +typedef Hd108MethodBase> Hd108Spi20MhzMethod; +typedef Hd108MethodBase> Hd108Spi10MhzMethod; +typedef Hd108MethodBase> Hd108Spi5MhzMethod; +typedef Hd108MethodBase> Hd108Spi2MhzMethod; +typedef Hd108MethodBase> Hd108Spi1MhzMethod; +typedef Hd108MethodBase> Hd108Spi500KhzMethod; +typedef Hd108MethodBase> Hd108SpiHzMethod; + +typedef Hd108Spi10MhzMethod Hd108SpiMethod; +#endif + +#if defined(ARDUINO_ARCH_ESP32) +// Give option to use Vspi alias of Spi class if wanting to specify which SPI peripheral is used on the ESP32 +typedef Hd108MethodBase> Hd108Esp32Vspi40MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Vspi20MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Vspi10MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Vspi5MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Vspi2MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Vspi1MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Vspi500KhzMethod; +typedef Hd108MethodBase> Hd108Esp32VspiHzMethod; + +typedef Hd108Spi10MhzMethod Hd108Esp32VspiMethod; + +#include "TwoWireHspiImple.h" +typedef Hd108MethodBase> Hd108Esp32Hspi40MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Hspi20MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Hspi10MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Hspi5MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Hspi2MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Hspi1MhzMethod; +typedef Hd108MethodBase> Hd108Esp32Hspi500KhzMethod; +typedef Hd108MethodBase> Hd108Esp32HspiHzMethod; + +typedef Hd108Esp32Hspi10MhzMethod Hd108Esp32HspiMethod; +#endif