From 663c6492f4ca259c7cc75764bd349dd3f60c9844 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Wed, 10 Feb 2021 17:33:24 -0800 Subject: [PATCH] Color and Init (#425) --- keywords.txt | 1 + src/internal/Lpd6803ColorFeatures.h | 52 ++++++++++++++++++++++++++--- src/internal/Lpd6803GenericMethod.h | 12 ++++++- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/keywords.txt b/keywords.txt index 7042087..60650c6 100644 --- a/keywords.txt +++ b/keywords.txt @@ -29,6 +29,7 @@ DotStarLbgrFeature KEYWORD1 Lpd6803GrbFeature KEYWORD1 Lpd6803GbrFeature KEYWORD1 Lpd6803BrgFeature KEYWORD1 +Lpd6803RgbFeature KEYWORD1 Lpd8806GrbFeature KEYWORD1 Lpd8806BrgFeature KEYWORD1 P9813BgrFeature KEYWORD1 diff --git a/src/internal/Lpd6803ColorFeatures.h b/src/internal/Lpd6803ColorFeatures.h index bcd9a5c..9a4d751 100644 --- a/src/internal/Lpd6803ColorFeatures.h +++ b/src/internal/Lpd6803ColorFeatures.h @@ -103,10 +103,6 @@ public: } } - typedef RgbColor ColorObject; - - -protected: static void encodePixel(uint8_t c1, uint8_t c2, uint8_t c3, uint16_t* color555) { *color555 = (0x8000 | @@ -121,6 +117,9 @@ protected: *c2 = (color555 >> 2) & 0xf8; *c3 = (color555 << 3) & 0xf8; } + + + typedef RgbColor ColorObject; }; class Lpd6803BrgFeature : public Lpd68033Elements @@ -255,3 +254,48 @@ public: } }; + +class Lpd6803RgbFeature : public Lpd68033Elements +{ +public: + static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color) + { + uint8_t* p = getPixelAddress(pPixels, indexPixel); + uint16_t color555; + + encodePixel(color.R, color.G, color.B, &color555); + *p++ = color555 >> 8; + *p = color555 & 0xff; + } + + static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel) + { + ColorObject color; + const uint8_t* p = getPixelAddress(pPixels, indexPixel); + + uint16_t color555; + + color555 = ((*p++) << 8); + color555 |= (*p); + + decodePixel(color555, &color.R, &color.G, &color.B); + + 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); + + uint16_t color555; + + color555 = (pgm_read_byte(p++) << 8); + color555 |= pgm_read_byte(p); + + decodePixel(color555, &color.R, &color.G, &color.B); + + return color; + } +}; + diff --git a/src/internal/Lpd6803GenericMethod.h b/src/internal/Lpd6803GenericMethod.h index 0914264..75640eb 100644 --- a/src/internal/Lpd6803GenericMethod.h +++ b/src/internal/Lpd6803GenericMethod.h @@ -43,7 +43,17 @@ public: _wire(pinClock, pinData) { _data = static_cast(malloc(_sizeData)); - memset(_data, 0, _sizeData); + + // requires specific memory init + memset(_data, 0, _sizeData); // is not good enough + uint16_t* pPixel = reinterpret_cast(_data + settingsSize); + uint16_t* pPixelEnd = pPixel + (_sizeData / elementSize); + + while (pPixel < pPixelEnd) + { + Lpd68033Elements::encodePixel(0, 0, 0, pPixel); + pPixel++; + } } #if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)