From cf298d4096991c9ae0caed3aca48ec8a595b1eca Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 11 Jan 2020 16:23:05 -0800 Subject: [PATCH] Tm1814 (#329) * Esp32 --- keywords.txt | 42 +++++++-- src/NeoPixelBus.h | 56 +++++++++--- src/internal/NeoAvrMethod.h | 65 ++++++------- src/internal/NeoColorFeatures.h | 47 ++++++++-- src/internal/NeoEsp32RmtMethod.h | 72 +++++++++++---- src/internal/NeoPixelAvr.c | 48 +++++----- src/internal/NeoSettings.h | 62 +++++++++++++ src/internal/NeoTm1814ColorFeatures.h | 126 ++++++++++++++++++++++++++ src/internal/RgbColor.h | 14 +++ src/internal/RgbwColor.h | 16 ++++ 10 files changed, 443 insertions(+), 105 deletions(-) create mode 100644 src/internal/NeoSettings.h create mode 100644 src/internal/NeoTm1814ColorFeatures.h diff --git a/keywords.txt b/keywords.txt index a6c19a1..687f408 100644 --- a/keywords.txt +++ b/keywords.txt @@ -13,12 +13,15 @@ RgbColor KEYWORD1 HslColor KEYWORD1 HsbColor KEYWORD1 HtmlColor KEYWORD1 +NeoNoSettings KEYWORD1 +NeoTm1814Settings KEYWORD1 NeoGrbFeature KEYWORD1 NeoGrbwFeature KEYWORD1 NeoRgbwFeature KEYWORD1 NeoRgbFeature KEYWORD1 NeoBrgFeature KEYWORD1 NeoRbgFeature KEYWORD1 +NeoWrgbTm1814Feature KEYWORD1 DotStarBgrFeature KEYWORD1 DotStarLbgrFeature KEYWORD1 Lpd8806GrbFeature KEYWORD1 @@ -30,6 +33,7 @@ NeoWs2812xMethod KEYWORD1 NeoWs2812Method KEYWORD1 NeoWs2811Method KEYWORD1 NeoSk6812Method KEYWORD1 +NeoTm1814Method KEYWORD1 NeoLc8812Method KEYWORD1 NeoApa106Method KEYWORD1 Neo800KbpsInvertedMethod KEYWORD1 @@ -39,6 +43,7 @@ NeoWs2812xInvertedMethod KEYWORD1 NeoWs2812InvertedMethod KEYWORD1 NeoWs2811InvertedMethod KEYWORD1 NeoSk6812InvertedMethod KEYWORD1 +NeoTm1814InvertedMethod KEYWORD1 NeoLc8812InvertedMethod KEYWORD1 NeoApa106InvertedMethod KEYWORD1 NeoEsp8266DmaWs2812xMethod KEYWORD1 @@ -151,109 +156,125 @@ NeoEsp32I2s1Sk6812Method KEYWORD1 NeoEsp32I2s1800KbpsMethod KEYWORD1 NeoEsp32I2s1400KbpsMethod KEYWORD1 NeoEsp32I2s1Apa106Method KEYWORD1 -NeoEsp32I2s0Ws2812xInvertdMethod KEYWORD1 -NeoEsp32I2s0Sk6812InvertdMethod KEYWORD1 -NeoEsp32I2s0800KbpsInvertdMethod KEYWORD1 -NeoEsp32I2s0400KbpsInvertdMethod KEYWORD1 -NeoEsp32I2s0Apa106InvertdMethod KEYWORD1 -NeoEsp32I2s1Ws2812xInvertdMethod KEYWORD1 -NeoEsp32I2s1Sk6812InvertdMethod KEYWORD1 -NeoEsp32I2s1800KbpsInvertdMethod KEYWORD1 -NeoEsp32I2s1400KbpsInvertdMethod KEYWORD1 -NeoEsp32I2s1Apa106InvertdMethod KEYWORD1 +NeoEsp32I2s0Ws2812xInvertedMethod KEYWORD1 +NeoEsp32I2s0Sk6812InvertedMethod KEYWORD1 +NeoEsp32I2s0800KbpsInvertedMethod KEYWORD1 +NeoEsp32I2s0400KbpsInvertedMethod KEYWORD1 +NeoEsp32I2s0Apa106InvertedMethod KEYWORD1 +NeoEsp32I2s1Ws2812xInvertedMethod KEYWORD1 +NeoEsp32I2s1Sk6812InvertedMethod KEYWORD1 +NeoEsp32I2s1800KbpsInvertedMethod KEYWORD1 +NeoEsp32I2s1400KbpsInvertedMethod KEYWORD1 +NeoEsp32I2s1Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt0Ws2811Method KEYWORD1 NeoEsp32Rmt0Ws2812xMethod KEYWORD1 NeoEsp32Rmt0Sk6812Method KEYWORD1 +NeoEsp32Rmt0Tm1814Method KEYWORD1 NeoEsp32Rmt0Apa106Method KEYWORD1 NeoEsp32Rmt0800KbpsMethod KEYWORD1 NeoEsp32Rmt0400KbpsMethod KEYWORD1 NeoEsp32Rmt1Ws2811Method KEYWORD1 NeoEsp32Rmt1Ws2812xMethod KEYWORD1 NeoEsp32Rmt1Sk6812Method KEYWORD1 +NeoEsp32Rmt1Tm1814Method KEYWORD1 NeoEsp32Rmt1Apa106Method KEYWORD1 NeoEsp32Rmt1800KbpsMethod KEYWORD1 NeoEsp32Rmt1400KbpsMethod KEYWORD1 NeoEsp32Rmt2Ws2811Method KEYWORD1 NeoEsp32Rmt2Ws2812xMethod KEYWORD1 NeoEsp32Rmt2Sk6812Method KEYWORD1 +NeoEsp32Rmt2Tm1814Method KEYWORD1 NeoEsp32Rmt2Apa106Method KEYWORD1 NeoEsp32Rmt2800KbpsMethod KEYWORD1 NeoEsp32Rmt2400KbpsMethod KEYWORD1 NeoEsp32Rmt3Ws2811Method KEYWORD1 NeoEsp32Rmt3Ws2812xMethod KEYWORD1 NeoEsp32Rmt3Sk6812Method KEYWORD1 +NeoEsp32Rmt3Tm1814Method KEYWORD1 NeoEsp32Rmt3Apa106Method KEYWORD1 NeoEsp32Rmt3800KbpsMethod KEYWORD1 NeoEsp32Rmt3400KbpsMethod KEYWORD1 NeoEsp32Rmt4Ws2811Method KEYWORD1 NeoEsp32Rmt4Ws2812xMethod KEYWORD1 NeoEsp32Rmt4Sk6812Method KEYWORD1 +NeoEsp32Rmt4Tm1814Method KEYWORD1 NeoEsp32Rmt4Apa106Method KEYWORD1 NeoEsp32Rmt4800KbpsMethod KEYWORD1 NeoEsp32Rmt4400KbpsMethod KEYWORD1 NeoEsp32Rmt5Ws2811Method KEYWORD1 NeoEsp32Rmt5Ws2812xMethod KEYWORD1 NeoEsp32Rmt5Sk6812Method KEYWORD1 +NeoEsp32Rmt5Tm1814Method KEYWORD1 NeoEsp32Rmt5Apa106Method KEYWORD1 NeoEsp32Rmt5800KbpsMethod KEYWORD1 NeoEsp32Rmt5400KbpsMethod KEYWORD1 NeoEsp32Rmt6Ws2811Method KEYWORD1 NeoEsp32Rmt6Ws2812xMethod KEYWORD1 NeoEsp32Rmt6Sk6812Method KEYWORD1 +NeoEsp32Rmt6Tm1814Method KEYWORD1 NeoEsp32Rmt6Apa106Method KEYWORD1 NeoEsp32Rmt6800KbpsMethod KEYWORD1 NeoEsp32Rmt6400KbpsMethod KEYWORD1 NeoEsp32Rmt7Ws2811Method KEYWORD1 NeoEsp32Rmt7Ws2812xMethod KEYWORD1 NeoEsp32Rmt7Sk6812Method KEYWORD1 +NeoEsp32Rmt7Tm1814Method KEYWORD1 NeoEsp32Rmt7Apa106Method KEYWORD1 NeoEsp32Rmt7800KbpsMethod KEYWORD1 NeoEsp32Rmt7400KbpsMethod KEYWORD1 NeoEsp32Rmt0Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt0Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt0Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt0Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt0Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt0800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt0400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt1Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt1Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt1Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt1Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt1Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt1800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt1400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt2Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt2Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt2Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt2Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt2Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt2800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt2400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt3Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt3Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt3Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt3Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt3Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt3800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt3400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt4Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt4Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt4Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt4Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt4Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt4800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt4400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt5Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt5Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt5Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt5Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt5Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt5800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt5400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt6Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt6Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt6Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt6Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt6Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt6800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt6400KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt7Ws2811InvertedMethod KEYWORD1 NeoEsp32Rmt7Ws2812xInvertedMethod KEYWORD1 NeoEsp32Rmt7Sk6812InvertedMethod KEYWORD1 +NeoEsp32Rmt7Tm1814InvertedMethod KEYWORD1 NeoEsp32Rmt7Apa106InvertedMethod KEYWORD1 NeoEsp32Rmt7800KbpsInvertedMethod KEYWORD1 NeoEsp32Rmt7400KbpsInvertedMethod KEYWORD1 @@ -397,6 +418,7 @@ CalculateBrightness KEYWORD2 Dim KEYWORD2 Darken KEYWORD2 Lighten KEYWORD2 +SetPixelSettings KEYWORD2 LinearBlend KEYWORD2 BilinearBlend KEYWORD2 IsAnimating KEYWORD2 diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index c716249..929b8c5 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -48,6 +48,8 @@ License along with NeoPixel. If not, see #include "internal/NeoHueBlend.h" +#include "internal/NeoSettings.h" + #include "internal/RgbColor.h" #include "internal/HslColor.h" #include "internal/HsbColor.h" @@ -56,6 +58,7 @@ License along with NeoPixel. If not, see #include "internal/SegmentDigit.h" #include "internal/NeoColorFeatures.h" +#include "internal/NeoTm1814ColorFeatures.h" #include "internal/DotStarColorFeatures.h" #include "internal/Lpd8806ColorFeatures.h" #include "internal/NeoSegmentFeatures.h" @@ -120,21 +123,21 @@ public: NeoPixelBus(uint16_t countPixels, uint8_t pin) : _countPixels(countPixels), _state(0), - _method(pin, countPixels, T_COLOR_FEATURE::PixelSize) + _method(pin, countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize) { } NeoPixelBus(uint16_t countPixels, uint8_t pinClock, uint8_t pinData) : _countPixels(countPixels), _state(0), - _method(pinClock, pinData, countPixels, T_COLOR_FEATURE::PixelSize) + _method(pinClock, pinData, countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize) { } NeoPixelBus(uint16_t countPixels) : _countPixels(countPixels), _state(0), - _method(countPixels, T_COLOR_FEATURE::PixelSize) + _method(countPixels, T_COLOR_FEATURE::PixelSize, T_COLOR_FEATURE::SettingsSize) { } @@ -145,7 +148,7 @@ public: operator NeoBufferContext() { Dirty(); // we assume you are playing with bits - return NeoBufferContext(_method.getPixels(), _method.getPixelsSize()); + return NeoBufferContext(_pixels(), _method.getDataSize()); } void Begin() @@ -195,12 +198,12 @@ public: uint8_t* Pixels() { - return _method.getPixels(); + return _pixels(); }; size_t PixelsSize() const { - return _method.getPixelsSize(); + return _method.getDataSize() - T_COLOR_FEATURE::SettingsSize; }; size_t PixelSize() const @@ -217,7 +220,7 @@ public: { if (indexPixel < _countPixels) { - T_COLOR_FEATURE::applyPixelColor(_method.getPixels(), indexPixel, color); + T_COLOR_FEATURE::applyPixelColor(_pixels(), indexPixel, color); Dirty(); } }; @@ -226,7 +229,7 @@ public: { if (indexPixel < _countPixels) { - return T_COLOR_FEATURE::retrievePixelColor(_method.getPixels(), indexPixel); + return T_COLOR_FEATURE::retrievePixelColor(_pixels(), indexPixel); } else { @@ -239,7 +242,7 @@ public: void ClearTo(typename T_COLOR_FEATURE::ColorObject color) { uint8_t temp[T_COLOR_FEATURE::PixelSize]; - uint8_t* pixels = _method.getPixels(); + uint8_t* pixels = _pixels(); T_COLOR_FEATURE::applyPixelColor(temp, 0, color); @@ -255,7 +258,7 @@ public: first <= last) { uint8_t temp[T_COLOR_FEATURE::PixelSize]; - uint8_t* pixels = _method.getPixels(); + uint8_t* pixels = _pixels(); uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, first); T_COLOR_FEATURE::applyPixelColor(temp, 0, color); @@ -354,18 +357,43 @@ public: SetPixelColor(indexPixelOne, colorTwo); SetPixelColor(indexPixelTwo, colorOne); }; + + void SetPixelSettings(const typename T_COLOR_FEATURE::SettingsObject& settings) + { + T_COLOR_FEATURE::applySettings(_method.getData(), settings); + Dirty(); + }; + uint32_t CalcTotalMilliAmpere(const typename T_COLOR_FEATURE::ColorObject::SettingsObject& settings) + { + uint32_t total = 0; // in 1/10th milliamps + + for (uint16_t index = 0; index < _countPixels; index++) + { + auto color = GetPixelColor(index); + total += color.CalcTotalTenthMilliAmpere(settings); + } + + return total / 10; // return millamps + } + protected: const uint16_t _countPixels; // Number of RGB LEDs in strip uint8_t _state; // internal state T_METHOD _method; + uint8_t* _pixels() + { + // get pixels data within the data stream + return T_COLOR_FEATURE::pixels(_method.getData()); + } + void _rotateLeft(uint16_t rotationCount, uint16_t first, uint16_t last) { // store in temp uint8_t temp[rotationCount * T_COLOR_FEATURE::PixelSize]; - uint8_t* pixels = _method.getPixels(); + uint8_t* pixels = _pixels(); uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, first); @@ -386,7 +414,7 @@ protected: uint16_t front = first + shiftCount; uint16_t count = last - front + 1; - uint8_t* pixels = _method.getPixels(); + uint8_t* pixels = _pixels(); uint8_t* pFirst = T_COLOR_FEATURE::getPixelAddress(pixels, first); uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, front); @@ -399,7 +427,7 @@ protected: { // store in temp uint8_t temp[rotationCount * T_COLOR_FEATURE::PixelSize]; - uint8_t* pixels = _method.getPixels(); + uint8_t* pixels = _pixels(); uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, last - (rotationCount - 1)); @@ -420,7 +448,7 @@ protected: uint16_t front = first + shiftCount; uint16_t count = last - front + 1; - uint8_t* pixels = _method.getPixels(); + uint8_t* pixels = _pixels(); uint8_t* pFirst = T_COLOR_FEATURE::getPixelAddress(pixels, first); uint8_t* pFront = T_COLOR_FEATURE::getPixelAddress(pixels, front); diff --git a/src/internal/NeoAvrMethod.h b/src/internal/NeoAvrMethod.h index 96aa47c..7d097ba 100644 --- a/src/internal/NeoAvrMethod.h +++ b/src/internal/NeoAvrMethod.h @@ -31,39 +31,39 @@ License along with NeoPixel. If not, see extern "C" { - void send_pixels_8mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pinMask); - void send_pixels_8mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pinMask); - void send_pixels_8mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask); - void send_pixels_12mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pinMask); - void send_pixels_12mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pinMask); - void send_pixels_12mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask); - void send_pixels_16mhz_800(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask); - void send_pixels_16mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask); + void send_data_8mhz_800_PortD(uint8_t* data, size_t sizeData, uint8_t pinMask); + void send_data_8mhz_800_PortB(uint8_t* data, size_t sizeData, uint8_t pinMask); + void send_data_8mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); + void send_data_12mhz_800_PortD(uint8_t* data, size_t sizeData, uint8_t pinMask); + void send_data_12mhz_800_PortB(uint8_t* data, size_t sizeData, uint8_t pinMask); + void send_data_12mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); + void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); + void send_data_16mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask); } class NeoAvrSpeed800KbpsBase { public: - static void send_pixels(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask) + static void send_data(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { #if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) // 8Mhz CPU #ifdef PORTD // PORTD isn't present on ATtiny85, etc. if (port == &PORTD) - send_pixels_8mhz_800_PortD(pixels, sizePixels, pinMask); + send_data_8mhz_800_PortD(data, sizeData, pinMask); else if (port == &PORTB) #endif // PORTD - send_pixels_8mhz_800_PortB(pixels, sizePixels, pinMask); + send_data_8mhz_800_PortB(data, sizeData, pinMask); #elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) // 12Mhz CPU #ifdef PORTD // PORTD if (port == &PORTD) - send_pixels_12mhz_800_PortD(pixels, sizePixels, pinMask); + send_data_12mhz_800_PortD(data, sizeData, pinMask); else if (port == &PORTB) #endif // PORTD - send_pixels_12mhz_800_PortB(pixels, sizePixels, pinMask); + send_data_12mhz_800_PortB(data, sizeData, pinMask); #elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU - send_pixels_16mhz_800(pixels, sizePixels, port, pinMask); + send_data_16mhz_800(data, sizeData, port, pinMask); #else #error "CPU SPEED NOT SUPPORTED" #endif @@ -92,16 +92,16 @@ public: class NeoAvrSpeed400Kbps { public: - static void send_pixels(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask) + static void send_data(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { #if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) // 8Mhz CPU - send_pixels_8mhz_400(pixels, sizePixels, port, pinMask); + send_data_8mhz_400(data, sizeData, port, pinMask); #elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) // 12Mhz CPU - send_pixels_12mhz_400(pixels, sizePixels, port, pinMask); + send_data_12mhz_400(data, sizeData, port, pinMask); #elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU - send_pixels_16mhz_400(pixels, sizePixels, port, pinMask); + send_data_16mhz_400(data, sizeData, port, pinMask); #else #error "CPU SPEED NOT SUPPORTED" #endif @@ -112,16 +112,16 @@ public: template class NeoAvrMethodBase { public: - NeoAvrMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) : + NeoAvrMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), _pin(pin), _port(NULL), _pinMask(0) { pinMode(pin, OUTPUT); - _sizePixels = pixelCount * elementSize; - _pixels = (uint8_t*)malloc(_sizePixels); - memset(_pixels, 0, _sizePixels); + _data = (uint8_t*)malloc(_sizeData); + memset(_data, 0, _sizeData); _port = portOutputRegister(digitalPinToPort(pin)); _pinMask = digitalPinToBitMask(pin); @@ -131,7 +131,7 @@ public: { pinMode(_pin, INPUT); - free(_pixels); + free(_data); } bool IsReadyToUpdate() const @@ -165,7 +165,7 @@ public: noInterrupts(); // Need 100% focus on instruction timing - T_SPEED::send_pixels(_pixels, _sizePixels, _port, _pinMask); + T_SPEED::send_data(_data, _sizeData, _port, _pinMask); interrupts(); @@ -173,22 +173,23 @@ public: _endTime = micros(); } - uint8_t* getPixels() const + uint8_t* getData() const { - return _pixels; + return _data; }; - size_t getPixelsSize() const + size_t getDataSize() const { - return _sizePixels; + return _sizeData; }; private: - uint32_t _endTime; // Latch timing reference - size_t _sizePixels; // Size of '_pixels' buffer below - uint8_t* _pixels; // Holds LED color values - uint8_t _pin; // output pin number + const size_t _sizeData; // size of _data below + const uint8_t _pin; // output pin number + uint32_t _endTime; // Latch timing reference + uint8_t* _data; // Holds data stream which include LED color values and other settings as needed + volatile uint8_t* _port; // Output PORT register uint8_t _pinMask; // Output PORT bitmask }; diff --git a/src/internal/NeoColorFeatures.h b/src/internal/NeoColorFeatures.h index ab6c6b0..257c682 100644 --- a/src/internal/NeoColorFeatures.h +++ b/src/internal/NeoColorFeatures.h @@ -1,5 +1,5 @@ /*------------------------------------------------------------------------- -NeoPixelFeatures provides feature classes to describe color order and +NeoColorFeatures provides feature classes to describe color order and color depth for NeoPixelBus template class Written by Michael C. Miller. @@ -147,7 +147,40 @@ public: typedef RgbwColor ColorObject; }; -class NeoGrbFeature : public Neo3Elements + +class Neo3ElementsNoSettings : public Neo3Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t* pData, const SettingsObject& settings) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } +}; + +class Neo4ElementsNoSettings : public Neo4Elements +{ +public: + typedef NeoNoSettings SettingsObject; + static const size_t SettingsSize = 0; + + static void applySettings(uint8_t* pData, const SettingsObject& settings) + { + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData; + } +}; + +class NeoGrbFeature : public Neo3ElementsNoSettings { public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) @@ -185,7 +218,7 @@ public: }; -class NeoGrbwFeature : public Neo4Elements +class NeoGrbwFeature : public Neo4ElementsNoSettings { public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) @@ -227,7 +260,7 @@ public: }; -class NeoRgbwFeature : public Neo4Elements +class NeoRgbwFeature : public Neo4ElementsNoSettings { public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) @@ -268,7 +301,7 @@ public: }; -class NeoRgbFeature : public Neo3Elements +class NeoRgbFeature : public Neo3ElementsNoSettings { public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) @@ -306,7 +339,7 @@ public: }; -class NeoBrgFeature : public Neo3Elements +class NeoBrgFeature : public Neo3ElementsNoSettings { public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) @@ -344,7 +377,7 @@ public: }; -class NeoRbgFeature : public Neo3Elements +class NeoRbgFeature : public Neo3ElementsNoSettings { public: static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) diff --git a/src/internal/NeoEsp32RmtMethod.h b/src/internal/NeoEsp32RmtMethod.h index bf487c0..c047a83 100644 --- a/src/internal/NeoEsp32RmtMethod.h +++ b/src/internal/NeoEsp32RmtMethod.h @@ -117,6 +117,15 @@ public: const static uint16_t RmtDurationReset = FromNs(80000); // 80us }; +// normal is inverted signal +class NeoEsp32RmtSpeedTm1814 : public NeoEsp32RmtInvertedSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(360, 890); + const static uint32_t RmtBit1 = Item32Val(720, 530); + const static uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + class NeoEsp32RmtSpeed800Kbps : public NeoEsp32RmtSpeedBase { public: @@ -165,6 +174,15 @@ public: const static uint16_t RmtDurationReset = FromNs(80000); // 80us }; +// normal is inverted signal +class NeoEsp32RmtInvertedSpeedTm1814 : public NeoEsp32RmtSpeedBase +{ +public: + const static uint32_t RmtBit0 = Item32Val(360, 890); + const static uint32_t RmtBit1 = Item32Val(720, 530); + const static uint16_t RmtDurationReset = FromNs(200000); // 200us +}; + class NeoEsp32RmtInvertedSpeed800Kbps : public NeoEsp32RmtInvertedSpeedBase { public: @@ -240,15 +258,14 @@ public: template class NeoEsp32RmtMethodBase { public: - NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize) : + NeoEsp32RmtMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize, size_t settingsSize) : + _sizeData(pixelCount * elementSize + settingsSize), _pin(pin) { - _pixelsSize = pixelCount * elementSize; + _dataEditing = static_cast(malloc(_sizeData)); + memset(_dataEditing, 0x00, _sizeData); - _pixelsEditing = static_cast(malloc(_pixelsSize)); - memset(_pixelsEditing, 0x00, _pixelsSize); - - _pixelsSending = static_cast(malloc(_pixelsSize)); + _dataSending = static_cast(malloc(_sizeData)); // no need to initialize it, it gets overwritten on every send } @@ -260,8 +277,8 @@ public: ESP_ERROR_CHECK(rmt_driver_uninstall(T_CHANNEL::RmtChannelNumber)); - free(_pixelsEditing); - free(_pixelsSending); + free(_dataEditing); + free(_dataSending); } @@ -301,37 +318,38 @@ public: if (ESP_OK == ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_wait_tx_done(T_CHANNEL::RmtChannelNumber, 10000 / portTICK_PERIOD_MS))) { // now start the RMT transmit with the editing buffer before we swap - ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_write_sample(T_CHANNEL::RmtChannelNumber, _pixelsEditing, _pixelsSize, false)); + ESP_ERROR_CHECK_WITHOUT_ABORT(rmt_write_sample(T_CHANNEL::RmtChannelNumber, _dataEditing, _sizeData, false)); if (maintainBufferConsistency) { // copy editing to sending, // this maintains the contract that "colors present before will // be the same after", otherwise GetPixelColor will be inconsistent - memcpy(_pixelsSending, _pixelsEditing, _pixelsSize); + memcpy(_dataSending, _dataEditing, _sizeData); } // swap so the user can modify without affecting the async operation - std::swap(_pixelsSending, _pixelsEditing); + std::swap(_dataSending, _dataEditing); } } - uint8_t* getPixels() const + uint8_t* getData() const { - return _pixelsEditing; + return _dataEditing; }; - size_t getPixelsSize() const + size_t getDataSize() const { - return _pixelsSize; + return _sizeData; } private: + const size_t _sizeData; // Size of '_data*' buffers const uint8_t _pin; // output pin number - size_t _pixelsSize; // Size of '_pixels' buffer - uint8_t* _pixelsEditing; // Holds LED color values exposed for get and set - uint8_t* _pixelsSending; // Holds LED color values used to async send using RMT + // Holds data stream which include LED color values and other settings as needed + uint8_t* _dataEditing; // exposed for get and set + uint8_t* _dataSending; // used for async send using RMT // stranslate NeoPixelBuffer into RMT buffer @@ -397,6 +415,7 @@ private: typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsMethod; @@ -404,6 +423,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsMethod; @@ -411,6 +431,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsMethod; @@ -418,6 +439,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsMethod; @@ -425,6 +447,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsMethod; @@ -432,6 +455,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsMethod; @@ -439,6 +463,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsMethod; @@ -446,6 +471,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812Method; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106Method; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsMethod; @@ -454,6 +480,7 @@ typedef NeoEsp32RmtMethodBase NeoE typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt0400KbpsInvertedMethod; @@ -461,6 +488,7 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt1400KbpsInvertedMethod; @@ -468,6 +496,7 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt2400KbpsInvertedMethod; @@ -475,6 +504,7 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt3400KbpsInvertedMethod; @@ -482,6 +512,7 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt4400KbpsInvertedMethod; @@ -489,6 +520,7 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt5400KbpsInvertedMethod; @@ -496,6 +528,7 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt6400KbpsInvertedMethod; @@ -503,6 +536,7 @@ typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2811InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Ws2812xInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Sk6812InvertedMethod; +typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Tm1814InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7Apa106InvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7800KbpsInvertedMethod; typedef NeoEsp32RmtMethodBase NeoEsp32Rmt7400KbpsInvertedMethod; @@ -514,6 +548,7 @@ typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2812xMethod; typedef NeoEsp32Rmt6800KbpsMethod NeoWs2812Method; typedef NeoEsp32Rmt6Ws2812xMethod NeoWs2811Method; typedef NeoEsp32Rmt6Sk6812Method NeoSk6812Method; +typedef NeoEsp32Rmt6Tm1814Method NeoTm1814Method; typedef NeoEsp32Rmt6Sk6812Method NeoLc8812Method; typedef NeoEsp32Rmt6Apa106Method NeoApa106Method; @@ -525,6 +560,7 @@ typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2812xInvertedMethod; typedef NeoEsp32Rmt6Ws2812xInvertedMethod NeoWs2811InvertedMethod; typedef NeoEsp32Rmt6800KbpsInvertedMethod NeoWs2812InvertedMethod; typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoSk6812InvertedMethod; +typedef NeoEsp32Rmt6Tm1814InvertedMethod NeoTm1814InvertedMethod; typedef NeoEsp32Rmt6Sk6812InvertedMethod NeoLc8812InvertedMethod; typedef NeoEsp32Rmt6Apa106InvertedMethod NeoApa106InvertedMethod; diff --git a/src/internal/NeoPixelAvr.c b/src/internal/NeoPixelAvr.c index 09ad113..84e9893 100644 --- a/src/internal/NeoPixelAvr.c +++ b/src/internal/NeoPixelAvr.c @@ -55,10 +55,10 @@ License along with NeoPixel. If not, see #if (F_CPU >= 7400000UL) && (F_CPU <= 9500000UL) // 8Mhz CPU #ifdef PORTD // PORTD isn't present on ATtiny85, etc. -void send_pixels_8mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pinMask) +void send_data_8mhz_800_PortD(uint8_t* data, size_t sizeData, uint8_t pinMask) { - volatile size_t i = sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile size_t i = sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low @@ -180,10 +180,10 @@ void send_pixels_8mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pinM } #endif -void send_pixels_8mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pinMask) +void send_data_8mhz_800_PortB(uint8_t* data, size_t sizeData, uint8_t pinMask) { - volatile size_t i = sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile size_t i = sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low @@ -271,10 +271,10 @@ void send_pixels_8mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pinM [lo] "r" (lo)); } -void send_pixels_8mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask) +void send_data_8mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { - volatile size_t i = sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile size_t i = sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low @@ -331,10 +331,10 @@ void send_pixels_8mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* #elif (F_CPU >= 11100000UL) && (F_CPU <= 14300000UL) // 12Mhz CPU #ifdef PORTD // PORTD isn't present on ATtiny85, etc. -void send_pixels_12mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pinMask) +void send_data_12mhz_800_PortD(uint8_t* data, size_t sizeData, uint8_t pinMask) { - volatile size_t i = sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile size_t i = sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low @@ -404,10 +404,10 @@ void send_pixels_12mhz_800_PortD(uint8_t* pixels, size_t sizePixels, uint8_t pin } #endif -void send_pixels_12mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pinMask) +void send_data_12mhz_800_PortB(uint8_t* data, size_t sizeData, uint8_t pinMask) { - volatile uint16_t i = (uint16_t)sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile uint16_t i = (uint16_t)sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low @@ -466,10 +466,10 @@ void send_pixels_12mhz_800_PortB(uint8_t* pixels, size_t sizePixels, uint8_t pin [lo] "r" (lo)); } -void send_pixels_12mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask) +void send_data_12mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { - volatile uint16_t i = (uint16_t)sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile uint16_t i = (uint16_t)sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low @@ -522,10 +522,10 @@ void send_pixels_12mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* #elif (F_CPU >= 15400000UL) && (F_CPU <= 19000000L) // 16Mhz CPU -void send_pixels_16mhz_800(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask) +void send_data_16mhz_800(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { - volatile uint16_t i = (uint16_t)sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile uint16_t i = (uint16_t)sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low @@ -577,10 +577,10 @@ void send_pixels_16mhz_800(uint8_t* pixels, size_t sizePixels, volatile uint8_t* [lo] "r" (lo)); } -void send_pixels_16mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask) +void send_data_16mhz_400(uint8_t* data, size_t sizeData, volatile uint8_t* port, uint8_t pinMask) { - volatile size_t i = sizePixels; // Loop counter - volatile uint8_t* ptr = pixels; // Pointer to next byte + volatile size_t i = sizeData; // Loop counter + volatile uint8_t* ptr = data; // Pointer to next byte volatile uint8_t b = *ptr++; // Current byte value volatile uint8_t hi; // PORT w/output bit set high volatile uint8_t lo; // PORT w/output bit set low diff --git a/src/internal/NeoSettings.h b/src/internal/NeoSettings.h new file mode 100644 index 0000000..1af9f82 --- /dev/null +++ b/src/internal/NeoSettings.h @@ -0,0 +1,62 @@ +/*------------------------------------------------------------------------- +NeoSettings provides settings classes to describe settings + +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 NeoNoSettings +{ +}; + +class NeoRgbCurrentSettings +{ +public: + NeoRgbCurrentSettings(uint16_t red, uint16_t green, uint16_t blue) : + RedTenthMilliAmpere(red), + GreenTenthMilliAmpere(green), + BlueTenthMilliAmpere(blue) + { + } + + uint16_t RedTenthMilliAmpere; // in 1/10th ma + uint16_t GreenTenthMilliAmpere; // in 1/10th ma + uint16_t BlueTenthMilliAmpere; // in 1/10th ma +}; + +class NeoRgbwCurrentSettings +{ +public: + NeoRgbwCurrentSettings(uint16_t red, uint16_t green, uint16_t blue, uint16_t white) : + RedTenthMilliAmpere(red), + GreenTenthMilliAmpere(green), + BlueTenthMilliAmpere(blue), + WhiteCurrent(white) + { + } + + uint16_t RedTenthMilliAmpere; // in 1/10th ma + uint16_t GreenTenthMilliAmpere; // in 1/10th ma + uint16_t BlueTenthMilliAmpere; // in 1/10th ma + uint16_t WhiteCurrent; // in 1/10th ma +}; \ No newline at end of file diff --git a/src/internal/NeoTm1814ColorFeatures.h b/src/internal/NeoTm1814ColorFeatures.h new file mode 100644 index 0000000..729b560 --- /dev/null +++ b/src/internal/NeoTm1814ColorFeatures.h @@ -0,0 +1,126 @@ +/*------------------------------------------------------------------------- +NeoTm1814ColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class specific to the TM1814 chip + +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 NeoTm1814Settings : public NeoRgbwCurrentSettings +{ +public: + NeoTm1814Settings(uint16_t red, uint16_t green, uint16_t blue, uint16_t white) : + NeoRgbwCurrentSettings(red, green, blue, white) + { + } + + const static uint16_t MinCurrent = 65; + const static uint16_t MaxCurrent = 380; + + static uint16_t LimitCurrent(uint16_t value) + { + if (value < MinCurrent) + { + value = MinCurrent; + } + else if (value > MaxCurrent) + { + value = MaxCurrent; + } + return value; + } +}; + +class Neo4ElementsTm1814Settings : public Neo4Elements +{ +public: + typedef NeoTm1814Settings SettingsObject; + static const size_t SettingsSize = 8; + + static void applySettings(uint8_t* pData, const SettingsObject& settings) + { + uint8_t* pSet = pData; + + // C1 + *pSet++ = (SettingsObject::LimitCurrent(settings.WhiteCurrent) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.RedTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.GreenTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; + *pSet++ = (SettingsObject::LimitCurrent(settings.BlueTenthMilliAmpere) - SettingsObject::MinCurrent) / 5; + + uint8_t* pC1 = pData; + + // C2 + for (uint8_t elem = 0; elem < 4; elem++) + { + *pSet++ = ~(*pC1++); + } + } + + static uint8_t* pixels(uint8_t* pData) + { + return pData + SettingsSize; + } +}; + + +class NeoWrgbTm1814Feature : public Neo4ElementsTm1814Settings +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + *p++ = color.W; + *p++ = color.R; + *p++ = color.G; + *p = color.B; + } + + static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + uint8_t* p = getPixelAddress(pPixels, indexPixel); + + color.W = *p++; + color.R = *p++; + color.G = *p++; + color.B = *p; + + return color; + } + + static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel); + + color.W = pgm_read_byte(p++); + color.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p); + + return color; + } + +}; + diff --git a/src/internal/RgbColor.h b/src/internal/RgbColor.h index 994189a..1f05aa4 100644 --- a/src/internal/RgbColor.h +++ b/src/internal/RgbColor.h @@ -26,6 +26,7 @@ License along with NeoPixel. If not, see #pragma once #include +#include "NeoSettings.h" struct HslColor; struct HsbColor; @@ -38,6 +39,8 @@ struct HtmlColor; // ------------------------------------------------------------------------ struct RgbColor { + typedef NeoRgbCurrentSettings SettingsObject; + // ------------------------------------------------------------------------ // Construct a RgbColor using R, G, B values (0-255) // ------------------------------------------------------------------------ @@ -145,6 +148,17 @@ struct RgbColor float x, float y); + uint32_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) + { + auto total = 0; + + total += R * settings.RedTenthMilliAmpere / 255; + total += G * settings.GreenTenthMilliAmpere / 255; + total += B * settings.BlueTenthMilliAmpere / 255; + + return total; + } + // ------------------------------------------------------------------------ // Red, Green, Blue color members (0-255) where // (0,0,0) is black and (255,255,255) is white diff --git a/src/internal/RgbwColor.h b/src/internal/RgbwColor.h index 66e3bd1..f51fee1 100644 --- a/src/internal/RgbwColor.h +++ b/src/internal/RgbwColor.h @@ -38,6 +38,8 @@ struct HsbColor; // ------------------------------------------------------------------------ struct RgbwColor { + typedef NeoRgbwCurrentSettings SettingsObject; + // ------------------------------------------------------------------------ // Construct a RgbwColor using R, G, B, W values (0-255) // ------------------------------------------------------------------------ @@ -173,6 +175,18 @@ struct RgbwColor float x, float y); + uint16_t CalcTotalTenthMilliAmpere(const SettingsObject& settings) + { + auto total = 0; + + total += R * settings.RedTenthMilliAmpere / 255; + total += G * settings.GreenTenthMilliAmpere / 255; + total += B * settings.BlueTenthMilliAmpere / 255; + total += W * settings.WhiteCurrent / 255; + + return total; + } + // ------------------------------------------------------------------------ // Red, Green, Blue, White color members (0-255) where // (0,0,0,0) is black and (255,255,255, 0) and (0,0,0,255) is white @@ -182,5 +196,7 @@ struct RgbwColor uint8_t G; uint8_t B; uint8_t W; + + };