diff --git a/examples/Hd108Test/Hd108Test.ino b/examples/Hd108Test/Hd108Test.ino new file mode 100755 index 0000000..94e9965 --- /dev/null +++ b/examples/Hd108Test/Hd108Test.ino @@ -0,0 +1,84 @@ +// DotStarTest +// This example will cycle between showing four pixels as Red, Green, Blue, White +// and then showing those pixels as Black. +// +// There is serial output of the current state so you can confirm and follow along +// + +#include + +const uint16_t PixelCount = 4; // this example assumes 4 pixels, making it smaller will cause a failure + +// make sure to set this to the correct pins +const uint8_t DotClockPin = 9; +const uint8_t DotDataPin = 8; + +uint16_t colorSaturation=32768; + +// for software bit bang, with Rgb48Color +NeoPixelBus strip(PixelCount, DotClockPin, DotDataPin); + +// for hardware SPI (best performance but must use hardware pins) +//NeoPixelBus strip(PixelCount); + +// Rgbw64Color implementation +// NeoPixelBus strip(PixelCount, DotClockPin, DotDataPin); + +Rgb48Color red(colorSaturation, 0, 0); +Rgb48Color green(0, colorSaturation, 0); +Rgb48Color blue(0, 0, colorSaturation); +Rgb48Color white(colorSaturation); +Rgb48Color black(0); + +// for use with RGB DotStars when using the luminance/brightness global value +// note that its range is only 0 - 31 (31 is full bright) and +// also note that it is not useful for POV displays as it will cause more flicker +Rgbw64Color redL(colorSaturation, 0, 0, 31); // use white value to store luminance +Rgbw64Color greenL(0, colorSaturation, 0, 31); // use white value to store luminance +Rgbw64Color blueL(0, 0, colorSaturation, 31); // use white value to store luminance +Rgbw64Color whiteL(colorSaturation, colorSaturation, colorSaturation, colorSaturation / 8); // luminance is only 0-31 + +void setup() +{ + Serial.begin(115200); + while (!Serial); // wait for serial attach + + Serial.println(); + Serial.println("Initializing..."); + Serial.flush(); + + // this resets all the neopixels to an off state + strip.Begin(); + strip.ClearTo(black); + strip.Show(); + + Serial.println(); + Serial.println("Running..."); +} + +void loop() +{ + delay(5000); + + Serial.println("Colors R, G, B, W..."); + + // set the colors, + strip.SetPixelColor(0, red); + strip.SetPixelColor(1, green); + strip.SetPixelColor(2, blue); + strip.SetPixelColor(3, white); + strip.Show(); + + + delay(5000); + + Serial.println("Off ..."); + + // turn off the pixels + strip.SetPixelColor(0, black); + strip.SetPixelColor(1, black); + strip.SetPixelColor(2, black); + strip.SetPixelColor(3, black); + strip.Show(); + +} \ No newline at end of file diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index 5e30714..61167d7 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -330,6 +330,15 @@ public: void SetPixelSettings(const typename T_COLOR_FEATURE::SettingsObject& settings) { T_COLOR_FEATURE::applySettings(_method.getData(), _method.getDataSize(), settings); + if (_method.SwapBuffers()) + { + // some methods have two internal buffers + // so need to swap so settings are stored in both copies + // + T_COLOR_FEATURE::applySettings(_method.getData(), _method.getDataSize(), settings); + // swap back to minimize inconsistencies + _method.SwapBuffers(); + } Dirty(); }; diff --git a/src/internal/animations/NeoEase.h b/src/internal/animations/NeoEase.h index 7c8e171..7f040cf 100644 --- a/src/internal/animations/NeoEase.h +++ b/src/internal/animations/NeoEase.h @@ -211,9 +211,8 @@ public: } else { - return (-0.5f * (cos(PI * (unitValue-0.5f)) + 1.0f)); + return (-0.5f * cos(PI * (unitValue - 0.5f)) + 1.0f); } - } static float ExponentialIn(float unitValue) diff --git a/src/internal/animations/NeoPixelAnimator.cpp b/src/internal/animations/NeoPixelAnimator.cpp index 446bc4a..1cbfba3 100644 --- a/src/internal/animations/NeoPixelAnimator.cpp +++ b/src/internal/animations/NeoPixelAnimator.cpp @@ -25,6 +25,7 @@ License along with NeoPixel. If not, see -------------------------------------------------------------------------*/ #include +#include "../NeoUtil.h" #include "NeoPixelAnimator.h" NeoPixelAnimator::NeoPixelAnimator(uint16_t countAnimations, uint16_t timeScale) : diff --git a/src/internal/features/DotStarLrgbFeatures.h b/src/internal/features/DotStarLrgbFeatures.h index d70a203..a88dceb 100644 --- a/src/internal/features/DotStarLrgbFeatures.h +++ b/src/internal/features/DotStarLrgbFeatures.h @@ -73,4 +73,11 @@ class DotStarLbgr64Feature : { }; -typedef DotStarLbgr64Feature Hd108LbgrFeature; \ No newline at end of file +class DotStarLrgb64Feature : + public DotStarL4WordFeature, + public NeoElementsNoSettings +{ +}; + +typedef DotStarLbgr64Feature Hd108LbgrFeature; +typedef DotStarLrgb64Feature Hd108LrgbFeature; \ No newline at end of file diff --git a/src/internal/features/DotStarRgbFeatures.h b/src/internal/features/DotStarRgbFeatures.h index cf5513e..313ab74 100644 --- a/src/internal/features/DotStarRgbFeatures.h +++ b/src/internal/features/DotStarRgbFeatures.h @@ -74,4 +74,11 @@ class DotStarBgr48Feature : { }; +class DotStarRgb48Feature : + public DotStarX4WordFeature, + public NeoElementsNoSettings +{ +}; + typedef DotStarBgr48Feature Hd108BgrFeature; +typedef DotStarRgb48Feature Hd108RgbFeature; diff --git a/src/internal/features/Tlc59711RgbFeatures.h b/src/internal/features/Tlc59711RgbFeatures.h index aec9183..f3bfba9 100644 --- a/src/internal/features/Tlc59711RgbFeatures.h +++ b/src/internal/features/Tlc59711RgbFeatures.h @@ -161,14 +161,20 @@ private: }; -class Tlc59711RgbFeature : +class Tlc59711RgbFeature : // RGB only public Neo3WordFeature, public Tlc59711ElementsSettings { }; -class Tlc59711RgbwFeature : +class Tlc59711RgbwFeature : // RGB + warmer white public Neo4WordFeature, public Tlc59711ElementsSettings { }; + +class Tlc59711RgbwcFeature : // RGB + warmer white + cooler white in that order + public Neo5WordFeature, + public Tlc59711ElementsSettings +{ +}; diff --git a/src/internal/methods/ARM/NeoArmMethod.h b/src/internal/methods/ARM/NeoArmMethod.h index dba4000..2ea403b 100644 --- a/src/internal/methods/ARM/NeoArmMethod.h +++ b/src/internal/methods/ARM/NeoArmMethod.h @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------- NeoPixel library helper functions for ARM MCUs. -Teensy 3.0, 3.1, LC, Arduino Due +Teensy 3.0, 3.1, 3.5, 3.6, 4.0, 4.1, LC, Arduino Due Written by Michael C. Miller. Some work taken from the Adafruit NeoPixel library. @@ -97,6 +97,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; @@ -119,8 +124,8 @@ private: uint8_t _pin; // output pin number }; -// Teensy 3.0 or 3.1 (3.2) or 3.5 or 3.6 -#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) +// Teensy +#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined (__IMXRT1062__) || defined (__IMXRT1052__) class NeoArmMk20dxSpeedProps800KbpsBase { @@ -199,10 +204,15 @@ public: uint8_t pix; uint8_t mask; - volatile uint8_t* set = portSetRegister(pin); - volatile uint8_t* clr = portClearRegister(pin); + volatile auto set = portSetRegister(pin); + volatile auto clr = portClearRegister(pin); uint32_t cyc; +#if defined(KINETISK) || defined(KINETISL) + uint8_t msk = 1; +#else + uint32_t msk = digitalPinToBitMask(pin); +#endif ARM_DEMCR |= ARM_DEMCR_TRCENA; ARM_DWT_CTRL |= ARM_DWT_CTRL_CYCCNTENA; @@ -216,7 +226,7 @@ public: while (ARM_DWT_CYCCNT - cyc < T_SPEEDPROPS::Cycles); cyc = ARM_DWT_CYCCNT; - *set = 1; + *set = msk; if (pix & mask) { while (ARM_DWT_CYCCNT - cyc < T_SPEEDPROPS::CyclesT1h); @@ -225,7 +235,7 @@ public: { while (ARM_DWT_CYCCNT - cyc < T_SPEEDPROPS::CyclesT0h); } - *clr = 1; + *clr = msk; } } } @@ -550,7 +560,7 @@ typedef NeoArm400KbpsMethod NeoArmApa106Method; typedef NeoArmWs2805Method NeoArmWs2814Method; typedef NeoArmTm1814InvertedMethod NeoArmTm1914InvertedMethod; -#elif defined(ARDUINO_STM32_FEATHER) || defined(ARDUINO_ARCH_STM32L4) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32F1)// FEATHER WICED (120MHz) +#elif defined(ARDUINO_ARCH_STM32) || defined(ARDUINO_STM32_FEATHER) || defined(ARDUINO_ARCH_STM32L4) || defined(ARDUINO_ARCH_STM32F4) || defined(ARDUINO_ARCH_STM32F1)// FEATHER WICED (120MHz) class NeoArmStm32SpeedProps800KbpsBase { @@ -695,7 +705,21 @@ public: volatile uint32_t* set = &(GPIO->BRR); volatile uint32_t* clr = &(GPIO->BSRR); +#elif defined(STM32WLE5xx) + const unsigned long GPIO_BASE_ADDR = 0x48000000UL; + const unsigned long GPIO_BASE_OFFSET = 0x00000400UL; + const uint32_t GPIO_NUMBER = 16; + + uint32_t pinMask = 1 << (pin % GPIO_NUMBER); + + GPIO_TypeDef* GPIO = reinterpret_cast(GPIO_BASE_ADDR + ((pin / GPIO_NUMBER) * GPIO_BASE_OFFSET)); + + volatile uint32_t* set = &(GPIO->BRR); + volatile uint32_t* clr = &(GPIO->BSRR); +#else +#error "SPECIFIC STM32 CHIP NOT ACCOUNTED FOR" #endif + for (;;) { if (p & bitMask) diff --git a/src/internal/methods/ARM/NeoNrf52xMethod.h b/src/internal/methods/ARM/NeoNrf52xMethod.h index 82a6ca4..d4f8bcc 100644 --- a/src/internal/methods/ARM/NeoNrf52xMethod.h +++ b/src/internal/methods/ARM/NeoNrf52xMethod.h @@ -429,6 +429,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/AVR/NeoAvrMethod.h b/src/internal/methods/AVR/NeoAvrMethod.h index fe8468a..53d471c 100644 --- a/src/internal/methods/AVR/NeoAvrMethod.h +++ b/src/internal/methods/AVR/NeoAvrMethod.h @@ -244,6 +244,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/DotStarGenericMethod.h b/src/internal/methods/DotStarGenericMethod.h index 17e3405..714fdce 100644 --- a/src/internal/methods/DotStarGenericMethod.h +++ b/src/internal/methods/DotStarGenericMethod.h @@ -110,6 +110,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sMethod.h b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sMethod.h index 17ee4b0..7cf5c20 100644 --- a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sMethod.h +++ b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sMethod.h @@ -283,6 +283,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sXMethod.h b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sXMethod.h index fd628fa..ecc304a 100644 --- a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sXMethod.h +++ b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32I2sXMethod.h @@ -841,6 +841,11 @@ public: return true; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.h b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.h index 0304d46..6ef2ae9 100644 --- a/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.h +++ b/src/internal/methods/ESP/ESP32/Core_2_x/NeoEsp32RmtMethod.h @@ -651,6 +651,12 @@ public: return false; } + bool SwapBuffers() + { + std::swap(_dataSending, _dataEditing); + return true; + } + uint8_t* getData() const { return _dataEditing; diff --git a/src/internal/methods/ESP/ESP32/DotStarEsp32DmaSpiMethod.h b/src/internal/methods/ESP/ESP32/DotStarEsp32DmaSpiMethod.h index 4f69194..a105e43 100644 --- a/src/internal/methods/ESP/ESP32/DotStarEsp32DmaSpiMethod.h +++ b/src/internal/methods/ESP/ESP32/DotStarEsp32DmaSpiMethod.h @@ -188,6 +188,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data + _sizeStartFrame; diff --git a/src/internal/methods/ESP/ESP32/NeoEsp32LcdXMethod.h b/src/internal/methods/ESP/ESP32/NeoEsp32LcdXMethod.h index 7541a7a..268790f 100644 --- a/src/internal/methods/ESP/ESP32/NeoEsp32LcdXMethod.h +++ b/src/internal/methods/ESP/ESP32/NeoEsp32LcdXMethod.h @@ -658,6 +658,11 @@ public: return true; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/ESP/ESP8266/NeoEsp8266DmaMethod.h b/src/internal/methods/ESP/ESP8266/NeoEsp8266DmaMethod.h index d372e1e..766426d 100644 --- a/src/internal/methods/ESP/ESP8266/NeoEsp8266DmaMethod.h +++ b/src/internal/methods/ESP/ESP8266/NeoEsp8266DmaMethod.h @@ -271,6 +271,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/ESP/ESP8266/NeoEsp8266I2sDmx512Method.h b/src/internal/methods/ESP/ESP8266/NeoEsp8266I2sDmx512Method.h index a98e34d..9dc717d 100644 --- a/src/internal/methods/ESP/ESP8266/NeoEsp8266I2sDmx512Method.h +++ b/src/internal/methods/ESP/ESP8266/NeoEsp8266I2sDmx512Method.h @@ -213,6 +213,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data + T_SPEED::HeaderSize; diff --git a/src/internal/methods/ESP/ESP8266/NeoEsp8266UartMethod.h b/src/internal/methods/ESP/ESP8266/NeoEsp8266UartMethod.h index be3e7a3..48cd3ca 100644 --- a/src/internal/methods/ESP/ESP8266/NeoEsp8266UartMethod.h +++ b/src/internal/methods/ESP/ESP8266/NeoEsp8266UartMethod.h @@ -205,6 +205,11 @@ protected: ptr = const_cast(T_UARTCONTEXT::FillUartFifo(T_UARTFEATURE::Index, ptr, end)); } } + + bool SwapUartBuffers() + { + return false; + } }; // this template method class is used to glue uart feature and context for @@ -274,6 +279,12 @@ protected: std::swap(_dataSending, _data); } + bool SwapUartBuffers() + { + std::swap(_dataSending, _data); + return true; + } + private: T_UARTCONTEXT _context; @@ -420,6 +431,11 @@ public: return false; } + bool SwapBuffers() + { + return this->SwapUartBuffers(); + } + uint8_t* getData() const { return this->_data; diff --git a/src/internal/methods/ESP/NeoEspBitBangMethod.h b/src/internal/methods/ESP/NeoEspBitBangMethod.h index 952d8e0..01acd5d 100644 --- a/src/internal/methods/ESP/NeoEspBitBangMethod.h +++ b/src/internal/methods/ESP/NeoEspBitBangMethod.h @@ -262,6 +262,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Hd108GenericMethod.h b/src/internal/methods/Hd108GenericMethod.h index aa8ddea..223b2a9 100644 --- a/src/internal/methods/Hd108GenericMethod.h +++ b/src/internal/methods/Hd108GenericMethod.h @@ -78,7 +78,7 @@ public: void Update(bool) { - const uint8_t startFrame[4] = { 0x00 }; + const uint8_t startFrame[16] = { 0x00 }; const uint8_t endFrame[4] = { 0xff }; _wire.beginTransaction(); @@ -101,6 +101,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Lpd6803GenericMethod.h b/src/internal/methods/Lpd6803GenericMethod.h index 2e95e7e..a57dcee 100644 --- a/src/internal/methods/Lpd6803GenericMethod.h +++ b/src/internal/methods/Lpd6803GenericMethod.h @@ -106,6 +106,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Lpd8806GenericMethod.h b/src/internal/methods/Lpd8806GenericMethod.h index b28e575..757ed93 100644 --- a/src/internal/methods/Lpd8806GenericMethod.h +++ b/src/internal/methods/Lpd8806GenericMethod.h @@ -106,6 +106,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Mbi6033GenericMethod.h b/src/internal/methods/Mbi6033GenericMethod.h index 1cef6a7..fdbf8ad 100644 --- a/src/internal/methods/Mbi6033GenericMethod.h +++ b/src/internal/methods/Mbi6033GenericMethod.h @@ -129,6 +129,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/P9813GenericMethod.h b/src/internal/methods/P9813GenericMethod.h index b014e1e..43f454c 100644 --- a/src/internal/methods/P9813GenericMethod.h +++ b/src/internal/methods/P9813GenericMethod.h @@ -102,6 +102,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/PixieStreamMethod.h b/src/internal/methods/PixieStreamMethod.h index 3dd5368..8ad9b43 100644 --- a/src/internal/methods/PixieStreamMethod.h +++ b/src/internal/methods/PixieStreamMethod.h @@ -86,6 +86,11 @@ public: return true; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Rp2040/NeoRp2040x4Method.h b/src/internal/methods/Rp2040/NeoRp2040x4Method.h index a8ee727..8ba02fe 100644 --- a/src/internal/methods/Rp2040/NeoRp2040x4Method.h +++ b/src/internal/methods/Rp2040/NeoRp2040x4Method.h @@ -271,6 +271,12 @@ Serial.println(); return false; } + bool SwapBuffers() + { + std::swap(_dataSending, _dataEditing); + return true; + } + uint8_t* getData() const { return _dataEditing; diff --git a/src/internal/methods/Sm16716GenericMethod.h b/src/internal/methods/Sm16716GenericMethod.h index 065fb9c..6fa97fd 100644 --- a/src/internal/methods/Sm16716GenericMethod.h +++ b/src/internal/methods/Sm16716GenericMethod.h @@ -109,6 +109,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Tlc5947GenericMethod.h b/src/internal/methods/Tlc5947GenericMethod.h index 60aee68..caa713b 100644 --- a/src/internal/methods/Tlc5947GenericMethod.h +++ b/src/internal/methods/Tlc5947GenericMethod.h @@ -170,6 +170,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Tlc59711GenericMethod.h b/src/internal/methods/Tlc59711GenericMethod.h index 1841b30..8ad5810 100644 --- a/src/internal/methods/Tlc59711GenericMethod.h +++ b/src/internal/methods/Tlc59711GenericMethod.h @@ -157,6 +157,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data; diff --git a/src/internal/methods/Ws2801GenericMethod.h b/src/internal/methods/Ws2801GenericMethod.h index ccb69a2..965fa60 100644 --- a/src/internal/methods/Ws2801GenericMethod.h +++ b/src/internal/methods/Ws2801GenericMethod.h @@ -108,6 +108,11 @@ public: return false; } + bool SwapBuffers() + { + return false; + } + uint8_t* getData() const { return _data;