forked from Makuna/NeoPixelBus
Add P9813 support (#343)
Add support for the DMS MICROELECTRONICS P9813 LED driver Co-authored-by: feindsender <feindsender@users.noreply.github.com>
This commit is contained in:
@ -25,6 +25,7 @@ NeoWrgbTm1814Feature KEYWORD1
|
||||
DotStarBgrFeature KEYWORD1
|
||||
DotStarLbgrFeature KEYWORD1
|
||||
Lpd8806GrbFeature KEYWORD1
|
||||
P9813BgrFeature KEYWORD1
|
||||
SevenSegmentFeature KEYWORD1
|
||||
Neo800KbpsMethod KEYWORD1
|
||||
Neo400KbpsMethod KEYWORD1
|
||||
@ -377,6 +378,11 @@ Lpd8806SpiMethod KEYWORD1
|
||||
Lpd8806Spi20MhzMethod KEYWORD1
|
||||
Lpd8806Spi10MhzMethod KEYWORD1
|
||||
Lpd8806Spi2MhzMethod KEYWORD1
|
||||
P9813Method KEYWORD1
|
||||
P9813SpiMethod KEYWORD1
|
||||
P9813Spi20MhzMethod KEYWORD1
|
||||
P9813Spi10MhzMethod KEYWORD1
|
||||
P9813Spi2MhzMethod KEYWORD1
|
||||
NeoPixelAnimator KEYWORD1
|
||||
AnimUpdateCallback KEYWORD1
|
||||
AnimationParam KEYWORD1
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "NeoPixelBus",
|
||||
"keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, SK9822, APA106, LPD8806, WS2801 RGB, RGBW",
|
||||
"description": "A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102, LPD8806, SK9822, WS2801) easy. Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang. For Esp32 it has two base methods of sending NeoPixel data, i2s and RMT. For all platforms, there are two methods of sending DotStar data, hardware SPI and software SPI.",
|
||||
"keywords": "NeoPixel, WS2811, WS2812, WS2813, SK6812, DotStar, APA102, SK9822, APA106, LPD8806, P9813, WS2801 RGB, RGBW",
|
||||
"description": "A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102, LPD8806, SK9822, WS2801, P9813) easy. Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang. For Esp32 it has two base methods of sending NeoPixel data, i2s and RMT. For all platforms, there are two methods of sending DotStar data, hardware SPI and software SPI.",
|
||||
"homepage": "https://github.com/Makuna/NeoPixelBus/wiki",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -2,7 +2,7 @@ name=NeoPixelBus by Makuna
|
||||
version=2.5.7
|
||||
author=Michael C. Miller (makuna@live.com)
|
||||
maintainer=Michael C. Miller (makuna@live.com)
|
||||
sentence=A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102, LPD8806, SK9822, WS2801) easy.
|
||||
sentence=A library that makes controlling NeoPixels (APA106, WS2811, WS2812, WS2813 & SK6812) and DotStars (APA102, LPD8806, SK9822, WS2801, P9813) easy.
|
||||
paragraph=Supports most Arduino platforms, including async hardware support for Esp8266, Esp32, and Nrf52 (Nano 33 BLE). Support for RGBW pixels. Includes seperate RgbColor, RgbwColor, HslColor, and HsbColor objects. Includes an animator class that helps create asyncronous animations. Supports Matrix layout of pixels. Includes Gamma corretion object. For Esp8266 it has three methods of sending NeoPixel data, DMA, UART, and Bit Bang. For Esp32 it has two base methods of sending NeoPixel data, i2s and RMT. For all platforms, there are two methods of sending DotStar data, hardware SPI and software SPI.
|
||||
category=Display
|
||||
url=https://github.com/Makuna/NeoPixelBus/wiki
|
||||
|
@ -61,6 +61,7 @@ License along with NeoPixel. If not, see
|
||||
#include "internal/NeoTm1814ColorFeatures.h"
|
||||
#include "internal/DotStarColorFeatures.h"
|
||||
#include "internal/Lpd8806ColorFeatures.h"
|
||||
#include "internal/P9813ColorFeatures.h"
|
||||
#include "internal/NeoSegmentFeatures.h"
|
||||
|
||||
#include "internal/Layouts.h"
|
||||
@ -82,6 +83,7 @@ License along with NeoPixel. If not, see
|
||||
#include "internal/DotStarGenericMethod.h"
|
||||
#include "internal/Lpd8806GenericMethod.h"
|
||||
#include "internal/Ws2801GenericMethod.h"
|
||||
#include "internal/P9813GenericMethod.h"
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
|
||||
|
162
src/internal/P9813ColorFeatures.h
Normal file
162
src/internal/P9813ColorFeatures.h
Normal file
@ -0,0 +1,162 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
P9813ColorFeatures provides feature classes to describe color order and
|
||||
color depth for NeoPixelBus template class when used with P9813s
|
||||
|
||||
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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
#pragma once
|
||||
|
||||
class P98133Elements
|
||||
{
|
||||
public:
|
||||
static const size_t PixelSize = 4; // still requires 4 to be sent
|
||||
|
||||
static uint8_t* getPixelAddress(uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
return pPixels + indexPixel * PixelSize;
|
||||
}
|
||||
static const uint8_t* getPixelAddress(const uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
return pPixels + indexPixel * PixelSize;
|
||||
}
|
||||
|
||||
static void replicatePixel(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
|
||||
{
|
||||
uint8_t* pEnd = pPixelDest + (count * PixelSize);
|
||||
while (pPixelDest < pEnd)
|
||||
{
|
||||
*pPixelDest++ = pPixelSrc[0];
|
||||
*pPixelDest++ = pPixelSrc[1];
|
||||
*pPixelDest++ = pPixelSrc[2];
|
||||
*pPixelDest++ = pPixelSrc[3];
|
||||
}
|
||||
}
|
||||
|
||||
static void movePixelsInc(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
|
||||
{
|
||||
uint8_t* pEnd = pPixelDest + (count * PixelSize);
|
||||
while (pPixelDest < pEnd)
|
||||
{
|
||||
*pPixelDest++ = *pPixelSrc++;
|
||||
*pPixelDest++ = *pPixelSrc++;
|
||||
*pPixelDest++ = *pPixelSrc++;
|
||||
*pPixelDest++ = *pPixelSrc++;
|
||||
}
|
||||
}
|
||||
|
||||
static void movePixelsInc_P(uint8_t* pPixelDest, PGM_VOID_P pPixelSrc, uint16_t count)
|
||||
{
|
||||
uint8_t* pEnd = pPixelDest + (count * PixelSize);
|
||||
const uint8_t* pSrc = (const uint8_t*)pPixelSrc;
|
||||
while (pPixelDest < pEnd)
|
||||
{
|
||||
*pPixelDest++ = pgm_read_byte(pSrc++);
|
||||
*pPixelDest++ = pgm_read_byte(pSrc++);
|
||||
*pPixelDest++ = pgm_read_byte(pSrc++);
|
||||
*pPixelDest++ = pgm_read_byte(pSrc++);
|
||||
}
|
||||
}
|
||||
|
||||
static void movePixelsDec(uint8_t* pPixelDest, const uint8_t* pPixelSrc, uint16_t count)
|
||||
{
|
||||
uint8_t* pDestBack = pPixelDest + (count * PixelSize);
|
||||
const uint8_t* pSrcBack = pPixelSrc + (count * PixelSize);
|
||||
while (pDestBack > pPixelDest)
|
||||
{
|
||||
*--pDestBack = *--pSrcBack;
|
||||
*--pDestBack = *--pSrcBack;
|
||||
*--pDestBack = *--pSrcBack;
|
||||
*--pDestBack = *--pSrcBack;
|
||||
}
|
||||
}
|
||||
|
||||
typedef RgbColor ColorObject;
|
||||
};
|
||||
|
||||
class P98133ElementsNoSettings : public P98133Elements
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static const uint8_t* pixels(const uint8_t* pData)
|
||||
{
|
||||
return pData;
|
||||
}
|
||||
};
|
||||
|
||||
class P9813BgrFeature : public P98133ElementsNoSettings
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = 0xC0 | ((~color.B & 0xC0) >> 2) | ((~color.G & 0xC0) >> 4) | ((~color.R & 0xC0) >> 6);
|
||||
*p++ = color.B;
|
||||
*p++ = color.G;
|
||||
*p = color.R;
|
||||
}
|
||||
|
||||
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.B = *p++;
|
||||
color.G = *p++;
|
||||
color.R = *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);
|
||||
|
||||
pgm_read_byte(p++); // ignore the first byte
|
||||
color.B = pgm_read_byte(p++);
|
||||
color.G = pgm_read_byte(p++);
|
||||
color.R = pgm_read_byte(p);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
126
src/internal/P9813GenericMethod.h
Normal file
126
src/internal/P9813GenericMethod.h
Normal file
@ -0,0 +1,126 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for P9813s using general Pins (APA102).
|
||||
|
||||
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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#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<typename T_TWOWIRE> class P9813MethodBase
|
||||
{
|
||||
public:
|
||||
P9813MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
_sizeData(pixelCount * elementSize + settingsSize),
|
||||
_sizeEndFrame((pixelCount + 15) / 16), // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes)
|
||||
_wire(pinClock, pinData)
|
||||
{
|
||||
_data = static_cast<uint8_t*>(malloc(_sizeData));
|
||||
memset(_data, 0, _sizeData);
|
||||
}
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
P9813MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
P9813MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~P9813MethodBase()
|
||||
{
|
||||
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] = { 0x00 };
|
||||
|
||||
_wire.beginTransaction();
|
||||
|
||||
// start frame
|
||||
_wire.transmitBytes(startFrame, sizeof(startFrame));
|
||||
|
||||
// data
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
|
||||
// end frame
|
||||
_wire.transmitBytes(endFrame, sizeof(endFrame));
|
||||
|
||||
_wire.endTransaction();
|
||||
}
|
||||
|
||||
uint8_t* getData() const
|
||||
{
|
||||
return _data;
|
||||
};
|
||||
|
||||
size_t getDataSize() const
|
||||
{
|
||||
return _sizeData;
|
||||
};
|
||||
|
||||
private:
|
||||
const size_t _sizeData; // Size of '_data' buffer below
|
||||
const size_t _sizeEndFrame;
|
||||
|
||||
T_TWOWIRE _wire;
|
||||
uint8_t* _data; // Holds LED color values
|
||||
};
|
||||
|
||||
typedef P9813MethodBase<TwoWireBitBangImple> P9813Method;
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
#include "TwoWireSpiImple.h"
|
||||
typedef P9813MethodBase<TwoWireSpiImple<SpiSpeed20Mhz>> P9813Spi20MhzMethod;
|
||||
typedef P9813MethodBase<TwoWireSpiImple<SpiSpeed10Mhz>> P9813Spi10MhzMethod;
|
||||
typedef P9813MethodBase<TwoWireSpiImple<SpiSpeed2Mhz>> P9813Spi2MhzMethod;
|
||||
typedef P9813Spi10MhzMethod P9813SpiMethod;
|
||||
#endif
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user