From 083b8ab9f23529b3980f6d816cb3074963179c5e Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Apr 2022 12:35:14 -0700 Subject: [PATCH] Sm168xx (#563) * Base NeoSM168xxColorFeature support * Fix warnings --- keywords.txt | 2 + src/NeoPixelBus.h | 1 + src/internal/DotStarEsp32DmaSpiMethod.h | 2 +- src/internal/DotStarGenericMethod.h | 2 +- src/internal/Lpd6803GenericMethod.h | 2 +- src/internal/Lpd8806GenericMethod.h | 2 +- src/internal/NeoArmMethod.h | 2 +- src/internal/NeoAvrMethod.h | 2 +- src/internal/NeoEsp32I2sMethod.h | 2 +- src/internal/NeoEsp32RmtMethod.h | 2 +- src/internal/NeoEsp8266DmaMethod.h | 2 +- src/internal/NeoEsp8266UartMethod.h | 2 +- src/internal/NeoNrf52xMethod.h | 2 +- src/internal/NeoSm168xxColorFeatures.h | 128 ++++++++++++++++++++++++ src/internal/NeoTm1814ColorFeatures.h | 16 ++- src/internal/NeoTm1914ColorFeatures.h | 3 + src/internal/P9813GenericMethod.h | 2 +- src/internal/Tlc5947GenericMethod.h | 20 ++-- src/internal/TwoWireBitBangImpleAvr.h | 2 +- src/internal/TwoWireSpiImple.h | 22 ++-- 20 files changed, 182 insertions(+), 36 deletions(-) create mode 100644 src/internal/NeoSm168xxColorFeatures.h diff --git a/keywords.txt b/keywords.txt index 0b4cf05..6216d23 100644 --- a/keywords.txt +++ b/keywords.txt @@ -19,6 +19,7 @@ HtmlColor KEYWORD1 NeoNoSettings KEYWORD1 NeoTm1814Settings KEYWORD1 NeoTm1914Settings KEYWORD1 +NeoSm168xxSettings KEYWORD1 NeoSpiSettings KEYWORD1 NeoGrbFeature KEYWORD1 NeoGrbwFeature KEYWORD1 @@ -34,6 +35,7 @@ NeoRgbwUcs8904Feature KEYWORD1 NeoWrgbTm1814Feature KEYWORD1 NeoRgbTm1914Feature KEYWORD1 NeoGrbTm1914Feature KEYWORD1 +NeoRgbwSm168xxFeature KEYWORD1 DotStarBgrFeature KEYWORD1 DotStarLbgrFeature KEYWORD1 Lpd6803GrbFeature KEYWORD1 diff --git a/src/NeoPixelBus.h b/src/NeoPixelBus.h index e3ebbc0..d1a36d9 100644 --- a/src/NeoPixelBus.h +++ b/src/NeoPixelBus.h @@ -66,6 +66,7 @@ License along with NeoPixel. If not, see #include "internal/NeoColorFeatures.h" #include "internal/NeoTm1814ColorFeatures.h" #include "internal/NeoTm1914ColorFeatures.h" +#include "internal/NeoSm168xxColorFeatures.h" #include "internal/DotStarColorFeatures.h" #include "internal/Lpd8806ColorFeatures.h" #include "internal/Lpd6803ColorFeatures.h" diff --git a/src/internal/DotStarEsp32DmaSpiMethod.h b/src/internal/DotStarEsp32DmaSpiMethod.h index 1b6f3de..6795011 100644 --- a/src/internal/DotStarEsp32DmaSpiMethod.h +++ b/src/internal/DotStarEsp32DmaSpiMethod.h @@ -224,7 +224,7 @@ public: return _sizePixelData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { _speed.applySettings(settings); if (_spiHandle) diff --git a/src/internal/DotStarGenericMethod.h b/src/internal/DotStarGenericMethod.h index 81a4527..0d2f7c7 100644 --- a/src/internal/DotStarGenericMethod.h +++ b/src/internal/DotStarGenericMethod.h @@ -114,7 +114,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/src/internal/Lpd6803GenericMethod.h b/src/internal/Lpd6803GenericMethod.h index ecb7e49..778a4ef 100644 --- a/src/internal/Lpd6803GenericMethod.h +++ b/src/internal/Lpd6803GenericMethod.h @@ -110,7 +110,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/src/internal/Lpd8806GenericMethod.h b/src/internal/Lpd8806GenericMethod.h index c2372f2..074e8bc 100644 --- a/src/internal/Lpd8806GenericMethod.h +++ b/src/internal/Lpd8806GenericMethod.h @@ -110,7 +110,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/src/internal/NeoArmMethod.h b/src/internal/NeoArmMethod.h index ef1f7cf..e800112 100644 --- a/src/internal/NeoArmMethod.h +++ b/src/internal/NeoArmMethod.h @@ -101,7 +101,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/NeoAvrMethod.h b/src/internal/NeoAvrMethod.h index 685ab56..477abaf 100644 --- a/src/internal/NeoAvrMethod.h +++ b/src/internal/NeoAvrMethod.h @@ -197,7 +197,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/NeoEsp32I2sMethod.h b/src/internal/NeoEsp32I2sMethod.h index f7bc5ab..bd0cc16 100644 --- a/src/internal/NeoEsp32I2sMethod.h +++ b/src/internal/NeoEsp32I2sMethod.h @@ -217,7 +217,7 @@ public: return _sizeData; } - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/NeoEsp32RmtMethod.h b/src/internal/NeoEsp32RmtMethod.h index d584cc3..95db7f6 100644 --- a/src/internal/NeoEsp32RmtMethod.h +++ b/src/internal/NeoEsp32RmtMethod.h @@ -597,7 +597,7 @@ public: return _sizeData; } - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/NeoEsp8266DmaMethod.h b/src/internal/NeoEsp8266DmaMethod.h index 7a8a323..5865aa6 100644 --- a/src/internal/NeoEsp8266DmaMethod.h +++ b/src/internal/NeoEsp8266DmaMethod.h @@ -499,7 +499,7 @@ public: return _sizeData; } - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/NeoEsp8266UartMethod.h b/src/internal/NeoEsp8266UartMethod.h index 9ef2f4b..da61e7f 100644 --- a/src/internal/NeoEsp8266UartMethod.h +++ b/src/internal/NeoEsp8266UartMethod.h @@ -406,7 +406,7 @@ public: return this->_sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/NeoNrf52xMethod.h b/src/internal/NeoNrf52xMethod.h index da97fe7..3beea86 100644 --- a/src/internal/NeoNrf52xMethod.h +++ b/src/internal/NeoNrf52xMethod.h @@ -410,7 +410,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/NeoSm168xxColorFeatures.h b/src/internal/NeoSm168xxColorFeatures.h new file mode 100644 index 0000000..75e2fa9 --- /dev/null +++ b/src/internal/NeoSm168xxColorFeatures.h @@ -0,0 +1,128 @@ +/*------------------------------------------------------------------------- +NeoSm168xxColorFeatures provides feature classes to describe color order and +color depth for NeoPixelBus template class specific to the SM1680 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 NeoSm168xxSettings : public NeoRgbwCurrentSettings +{ +public: + NeoSm168xxSettings(uint16_t red, uint16_t green, uint16_t blue, uint16_t white) : + NeoRgbwCurrentSettings(red, green, blue, white) + { + } + + const static uint16_t MinCurrent = 60; + const static uint16_t MaxCurrent = 350; + + static uint16_t LimitCurrent(uint16_t value) + { + if (value < MinCurrent) + { + value = MinCurrent; + } + else if (value > MaxCurrent) + { + value = MaxCurrent; + } + return value; + } +}; + +class Neo4ByteElementsSm168xxSettings : public Neo4ByteElements +{ +private: + const static uint16_t EncodeDivisor = 19; + +public: + typedef NeoSm168xxSettings SettingsObject; + static const size_t SettingsSize = 2; + + static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings) + { + // settings are at the end of the data stream + uint8_t* pSet = pData + sizeData - SettingsSize; + + // four bits per element in RGBW order + *pSet++ = ((SettingsObject::LimitCurrent(settings.RedTenthMilliAmpere) - SettingsObject::MinCurrent) / EncodeDivisor) << 4 | + ((SettingsObject::LimitCurrent(settings.GreenTenthMilliAmpere) - SettingsObject::MinCurrent) / EncodeDivisor); + *pSet++ = ((SettingsObject::LimitCurrent(settings.BlueTenthMilliAmpere) - SettingsObject::MinCurrent) / EncodeDivisor) << 4 | + ((SettingsObject::LimitCurrent(settings.WhiteCurrent) - SettingsObject::MinCurrent) / EncodeDivisor); + + } + + 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; + } +}; + + +class NeoRgbwSm168xxFeature : public Neo4ByteElementsSm168xxSettings +{ +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; + } + + 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; + + 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.R = pgm_read_byte(p++); + color.G = pgm_read_byte(p++); + color.B = pgm_read_byte(p++); + color.W = pgm_read_byte(p); + + return color; + } + +}; + diff --git a/src/internal/NeoTm1814ColorFeatures.h b/src/internal/NeoTm1814ColorFeatures.h index 699b6ce..8fa181c 100644 --- a/src/internal/NeoTm1814ColorFeatures.h +++ b/src/internal/NeoTm1814ColorFeatures.h @@ -53,19 +53,23 @@ public: class Neo4ByteElementsTm1814Settings : public Neo4ByteElements { +private: + const static uint16_t EncodeDivisor = 5; + public: typedef NeoTm1814Settings SettingsObject; static const size_t SettingsSize = 8; - static void applySettings(uint8_t* pData, const SettingsObject& settings) + static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings) { + // settings are at the front of the data stream 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; + *pSet++ = (SettingsObject::LimitCurrent(settings.WhiteCurrent) - SettingsObject::MinCurrent) / EncodeDivisor; + *pSet++ = (SettingsObject::LimitCurrent(settings.RedTenthMilliAmpere) - SettingsObject::MinCurrent) / EncodeDivisor; + *pSet++ = (SettingsObject::LimitCurrent(settings.GreenTenthMilliAmpere) - SettingsObject::MinCurrent) / EncodeDivisor; + *pSet++ = (SettingsObject::LimitCurrent(settings.BlueTenthMilliAmpere) - SettingsObject::MinCurrent) / EncodeDivisor; uint8_t* pC1 = pData; @@ -78,11 +82,13 @@ public: static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData) { + // settings are at the front of the data stream return pData + SettingsSize; } static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData) { + // settings are at the front of the data stream return pData + SettingsSize; } }; diff --git a/src/internal/NeoTm1914ColorFeatures.h b/src/internal/NeoTm1914ColorFeatures.h index 25fdd50..5ea14bd 100644 --- a/src/internal/NeoTm1914ColorFeatures.h +++ b/src/internal/NeoTm1914ColorFeatures.h @@ -52,6 +52,7 @@ public: static void applySettings([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData, [[maybe_unused]] const SettingsObject& settings) { + // settings are at the front of the data stream uint8_t* pSet = pData; uint8_t mode = 0xff; @@ -86,11 +87,13 @@ public: static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData) { + // settings are at the front of the data stream return pData + SettingsSize; } static const uint8_t* pixels([[maybe_unused]] const uint8_t* pData, [[maybe_unused]] size_t sizeData) { + // settings are at the front of the data stream return pData + SettingsSize; } }; diff --git a/src/internal/P9813GenericMethod.h b/src/internal/P9813GenericMethod.h index 2fd1d4b..991d913 100644 --- a/src/internal/P9813GenericMethod.h +++ b/src/internal/P9813GenericMethod.h @@ -106,7 +106,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/src/internal/Tlc5947GenericMethod.h b/src/internal/Tlc5947GenericMethod.h index 501d913..7a61e55 100644 --- a/src/internal/Tlc5947GenericMethod.h +++ b/src/internal/Tlc5947GenericMethod.h @@ -45,9 +45,12 @@ public: // Write 2 channels into 3 bytes scaling 8-bit to 12-bit per channel for (int indexChannel = 0; indexChannel < TLC5947_MODULE_PWM_CHANNEL_COUNT; indexChannel += 2) { - *sendBufferPtr++ = *channelPtr; - *sendBufferPtr++ = (*channelPtr-- & 0xf0) | (*channelPtr >> 4); - *sendBufferPtr++ = ((*channelPtr << 4) & 0xf0) | (*channelPtr-- >> 4); + uint8_t ch1 = *channelPtr--; + uint8_t ch2 = *channelPtr--; + + *sendBufferPtr++ = ch1; + *sendBufferPtr++ = (ch1 & 0xf0) | (ch2 >> 4); + *sendBufferPtr++ = ((ch2 << 4) & 0xf0) | (ch2 >> 4); } } }; @@ -63,9 +66,12 @@ public: // Write 2 channels into 3 bytes using upper 12-bit of each channel for (int indexChannel = 0; indexChannel < TLC5947_MODULE_PWM_CHANNEL_COUNT; indexChannel += 2) { - *sendBufferPtr++ = *channelPtr >> 8; - *sendBufferPtr++ = (*channelPtr-- & 0xf0) | (*channelPtr >> 12); - *sendBufferPtr++ = *channelPtr-- >> 4; + uint8_t ch1 = *channelPtr--; + uint8_t ch2 = *channelPtr--; + + *sendBufferPtr++ = ch1 >> 8; + *sendBufferPtr++ = (ch1 & 0xf0) | (ch2 >> 12); + *sendBufferPtr++ = ch2 >> 4; } } }; @@ -168,7 +174,7 @@ public: return _sizeData; }; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { _wire.applySettings(settings); } diff --git a/src/internal/TwoWireBitBangImpleAvr.h b/src/internal/TwoWireBitBangImpleAvr.h index 5b475ac..80c324f 100644 --- a/src/internal/TwoWireBitBangImpleAvr.h +++ b/src/internal/TwoWireBitBangImpleAvr.h @@ -103,7 +103,7 @@ public: } } - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { } diff --git a/src/internal/TwoWireSpiImple.h b/src/internal/TwoWireSpiImple.h index d581555..546b6c8 100644 --- a/src/internal/TwoWireSpiImple.h +++ b/src/internal/TwoWireSpiImple.h @@ -34,7 +34,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed40Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 40000000L; }; @@ -45,7 +45,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed30Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 30000000L; }; @@ -56,7 +56,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed20Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 20000000L; }; @@ -67,7 +67,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed15Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 15000000L; }; @@ -78,7 +78,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed10Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 10000000L; }; @@ -89,7 +89,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed5Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 5000000L; }; @@ -100,7 +100,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed2Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 2000000L; }; @@ -111,7 +111,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed1Mhz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 1000000L; }; @@ -122,7 +122,7 @@ public: typedef NeoNoSettings SettingsObject; SpiSpeed500Khz() {}; - static void applySettings(const SettingsObject& settings) {} + static void applySettings([[maybe_unused]] const SettingsObject& settings) {} static const uint32_t Clock = 500000L; }; @@ -146,7 +146,7 @@ public: Clock(10000000) {}; - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { Clock = settings.Clock; } @@ -215,7 +215,7 @@ public: #endif } - void applySettings(const SettingsObject& settings) + void applySettings([[maybe_unused]] const SettingsObject& settings) { _speed.applySettings(settings); }