DotStar and NoPin NeoPixel

removed the need to provide the pin argument for Esp8266 NeoPixelBus
where it was ignored.
Added another DotStar color feature.
Fixed DotStar color features to use RgbColor when there is no need for
RgbwColor.
This commit is contained in:
Michael Miller
2016-09-02 10:32:10 -07:00
parent abacd3e965
commit eb77795f65
20 changed files with 174 additions and 51 deletions

View File

@ -26,14 +26,13 @@ const uint16_t PixelCount = 4; // make sure to set this to the number of pixels
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// For Esp8266, the Pin is ignored and it uses GPIO3.
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
// There are other Esp8266 alternative methods that provide more pin options, but also have
// other side effects.
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266Uart800KbpsMethod also ignores the pin parameter and uses GPI02
//NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266Uart800KbpsMethod will work with all but pin 16, but is not stable with WiFi
// being active
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
//
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
// NeoPixel animation time management object
NeoPixelAnimator animations(PixelCount, NEO_CENTISECONDS);

View File

@ -24,6 +24,8 @@ const uint16_t PixelPin = 2;
const uint16_t AnimCount = 1; // we only need one
NeoPixelBus<MyPixelColorFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<MyPixelColorFeature, Neo800KbpsMethod> strip(PixelCount);
NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object
// our NeoBitmapFile will use the same color feature as NeoPixelBus and

View File

@ -23,6 +23,8 @@ const uint16_t PixelPin = 2;
const uint16_t AnimCount = 1; // we only need one
NeoPixelBus<MyPixelColorFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<MyPixelColorFeature, Neo800KbpsMethod> strip(PixelCount);
NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object
// sprite sheet stored in progmem using the same pixel feature as the NeoPixelBus

View File

@ -15,6 +15,8 @@ const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignore
const RgbColor CylonEyeColor(HtmlColor(0x7f0000));
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
NeoPixelAnimator animations(2); // only ever need 2 animations

View File

@ -13,14 +13,12 @@ const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignore
const uint8_t AnimationChannels = 1; // we only need one as all the pixels are animated at once
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// For Esp8266, the Pin is ignored and it uses GPIO3.
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
// There are other Esp8266 alternative methods that provide more pin options, but also have
// other side effects.
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266Uart800KbpsMethod also ignores the pin parameter and uses GPI02
//NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266Uart800KbpsMethod will work with all but pin 16, but is not stable with WiFi
// being active
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
//
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
NeoPixelAnimator animations(AnimationChannels); // NeoPixel animation management object

View File

@ -26,14 +26,12 @@ const uint16_t NextPixelMoveDuration = 1000 / PixelCount; // how fast we move th
NeoGamma<NeoGammaTableMethod> colorGamma; // for any fade animations, best to correct gamma
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// For Esp8266, the Pin is ignored and it uses GPIO3.
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
// There are other Esp8266 alternative methods that provide more pin options, but also have
// other side effects.
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266Uart800KbpsMethod also ignores the pin parameter and uses GPI02
//NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266BitBang800KbpsMethod will work with all but pin 16, but is not stable with WiFi
// being active
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
//
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
// what is stored for state is specific to the need, in this case, the colors and
// the pixel to animate;

View File

@ -11,14 +11,12 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// For Esp8266, the Pin is ignored and it uses GPIO3.
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
// There are other Esp8266 alternative methods that provide more pin options, but also have
// other side effects.
//NeoPixelBus<NeoGrbFeature, NeoEsp8266Uart800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266Uart800KbpsMethod also ignores the pin parameter and uses GPI02
//NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> strip(PixelCount, PixelPin);
// NeoEsp8266Uart800KbpsMethod will work with all but pin 16, but is not stable with WiFi
// being active
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
//
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
NeoPixelAnimator animations(PixelCount); // NeoPixel animation management object

View File

@ -16,6 +16,8 @@ const uint16_t PixelCount = 16; // make sure to set this to the number of pixels
const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignored for Esp8266
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
// uncomment only one of these to compare memory use or speed
//

View File

@ -36,8 +36,8 @@ NeoMosaic <MyPanelLayout> mosaic(
TileHeight);
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
RgbColor red(128, 0, 0);
RgbColor green(0, 128, 0);

View File

@ -19,7 +19,8 @@ const float MaxLightness = 0.4f; // max lightness at the head of the tail (0.5f
NeoGamma<NeoGammaTableMethod> colorGamma; // for any fade animations, best to correct gamma
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
NeoPixelAnimator animations(AnimCount); // NeoPixel animation management object

View File

@ -22,6 +22,13 @@ const uint8_t PixelPin = 2; // make sure to set this to the correct pin, ignore
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbFeature, Neo400KbpsMethod> strip(PixelCount, PixelPin);
// For Esp8266, the Pin is omitted and it uses GPIO3 due to DMA hardware use.
// There are other Esp8266 alternative methods that provide more pin options, but also have
// other side effects.
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
//
// NeoEsp8266Uart800KbpsMethod uses GPI02 instead
// You can also use one of these for Esp8266,
// each having their own restrictions
//

View File

@ -42,6 +42,8 @@ NeoTiles <MyPanelLayout, MyTilesLayout> tiles(
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
RgbColor red(128, 0, 0);
RgbColor green(0, 128, 0);

View File

@ -31,6 +31,8 @@ NeoTopology<MyPanelLayout> topo(PanelWidth, PanelHeight);
NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
//NeoPixelBus<NeoRgbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
// for esp8266 omit the pin
//NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount);
RgbColor red(128, 0, 0);
RgbColor green(0, 128, 0);

View File

@ -1,14 +1,14 @@
{
"name": "NeoPixelBus",
"keywords": "NeoPixel, WS2811, WS2812, SK6812, DotStar, ADA102, RGB, RGBW",
"description": "A library that makes controlling NeoPixels (WS2811, WS2812 & SK6812) and DotStars (ADA102) easy. Supports most Arduino platforms. 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 data, DMA, UART, and Bit Bang.",
"description": "A library that makes controlling NeoPixels (WS2811, WS2812 & SK6812) and DotStars (ADA102) easy. Supports most Arduino platforms. 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; and two methods of sending DotStar data, hardware SPI and software SPI.",
"homepage": "https://github.com/Makuna/NeoPixelBus/wiki",
"repository":
{
"type": "git",
"url": "https://github.com/Makuna/NeoPixelBus"
},
"version": "2.2.0",
"version": "2.2.1",
"frameworks": "arduino",
"platforms": "*"
}

View File

@ -1,9 +1,9 @@
name=NeoPixelBus by Makuna
version=2.2.0
version=2.2.1
author=Michael C. Miller (makuna@live.com)
maintainer=Michael C. Miller (makuna@live.com)
sentence=A library that makes controlling NeoPixels (WS2811, WS2812 & SK6812) and DotStars (ADA102) easy.
paragraph=Supports most Arduino platforms, and especially Esp8266. 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 data, DMA, UART, and Bit Bang.
paragraph=Supports most Arduino platforms, and especially Esp8266. 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; and two methods of sending DotStar data, hardware SPI and software SPI.
category=Display
url=https://github.com/Makuna/NeoPixelBus/wiki
architectures=*

View File

@ -26,6 +26,73 @@ License along with NeoPixel. If not, see
-------------------------------------------------------------------------*/
#pragma once
class DotStar3Elements
{
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 DotStar4Elements
{
public:
@ -93,7 +160,7 @@ public:
typedef RgbwColor ColorObject;
};
class DotStarBgrFeature : public DotStar4Elements
class DotStarBgrFeature : public DotStar3Elements
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
@ -175,17 +242,17 @@ public:
};
class DotStarWbgrFeature : public DotStar4Elements
class DotStarGrbFeature : public DotStar3Elements
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
*p++ = color.W;
*p++ = color.B;
*p++ = 0xff; // upper three bits are always 111 and brightness at max
*p++ = color.G;
*p = color.R;
*p++ = color.R;
*p = color.B;
}
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
@ -193,10 +260,10 @@ public:
ColorObject color;
uint8_t* p = getPixelAddress(pPixels, indexPixel);
color.W = *p++;
color.B = *p++;
p++; // ignore the first byte
color.G = *p++;
color.R = *p;
color.R = *p++;
color.B = *p;
return color;
}
@ -206,11 +273,54 @@ public:
ColorObject color;
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
color.W = pgm_read_byte(p++);
color.B = pgm_read_byte(p++);
pgm_read_byte(p++); // ignore the first byte
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p);
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};
class DotStarLgrbFeature : public DotStar4Elements
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
{
uint8_t* p = getPixelAddress(pPixels, indexPixel);
*p++ = 0xE0 | min(color.W, 31); // upper three bits are always 111
*p++ = color.G;
*p++ = color.R;
*p = color.B;
}
static ColorObject retrievePixelColor(uint8_t* pPixels, uint16_t indexPixel)
{
ColorObject color;
uint8_t* p = getPixelAddress(pPixels, indexPixel);
color.W = (*p++) & 0x1F; // mask out upper three bits
color.G = *p++;
color.R = *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++) & 0x1F; // mask out upper three bits
color.G = pgm_read_byte(p++);
color.R = pgm_read_byte(p++);
color.B = pgm_read_byte(p);
return color;
}
};

View File

@ -54,7 +54,7 @@ public:
SPI.begin();
#if defined(ARDUINO_ARCH_ESP8266)
SPI.setFrequency(8000000L);
SPI.setFrequency(20000000L);
#elif defined(ARDUINO_ARCH_AVR)
SPI.setClockDivider(SPI_CLOCK_DIV2); // 8 MHz (6 MHz on Pro Trinket 3V)
#else

View File

@ -91,7 +91,7 @@ const uint8_t c_I2sPin = 3; // due to I2S hardware, the pin used is restricted t
template<typename T_SPEED> class NeoEsp8266DmaMethodBase
{
public:
NeoEsp8266DmaMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize)
NeoEsp8266DmaMethodBase(uint16_t pixelCount, size_t elementSize)
{
uint16_t dmaPixelSize = c_dmaBytesPerPixelBytes * elementSize;

View File

@ -54,7 +54,7 @@ static inline void enqueue(uint8_t byte)
static const uint8_t* esp8266_uart1_async_buf;
static const uint8_t* esp8266_uart1_async_buf_end;
NeoEsp8266Uart::NeoEsp8266Uart(uint8_t pin, uint16_t pixelCount, size_t elementSize)
NeoEsp8266Uart::NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize)
{
_sizePixels = pixelCount * elementSize;
_pixels = (uint8_t*)malloc(_sizePixels);
@ -130,8 +130,8 @@ const uint8_t* ICACHE_RAM_ATTR NeoEsp8266Uart::FillUartFifo(const uint8_t* pixel
return pixels;
}
NeoEsp8266AsyncUart::NeoEsp8266AsyncUart(uint8_t pin, uint16_t pixelCount, size_t elementSize)
: NeoEsp8266Uart(pin, pixelCount, elementSize)
NeoEsp8266AsyncUart::NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize)
: NeoEsp8266Uart(pixelCount, elementSize)
{
_asyncPixels = (uint8_t*)malloc(_sizePixels);
}

View File

@ -34,7 +34,7 @@ License along with NeoPixel. If not, see
class NeoEsp8266Uart
{
protected:
NeoEsp8266Uart(uint8_t pin, uint16_t pixelCount, size_t elementSize);
NeoEsp8266Uart(uint16_t pixelCount, size_t elementSize);
~NeoEsp8266Uart();
@ -61,7 +61,7 @@ protected:
class NeoEsp8266AsyncUart: public NeoEsp8266Uart
{
protected:
NeoEsp8266AsyncUart(uint8_t pin, uint16_t pixelCount, size_t elementSize);
NeoEsp8266AsyncUart(uint16_t pixelCount, size_t elementSize);
~NeoEsp8266AsyncUart();
@ -97,8 +97,8 @@ template<typename T_SPEED, typename T_BASE>
class NeoEsp8266UartMethodBase: public T_BASE
{
public:
NeoEsp8266UartMethodBase(uint8_t pin, uint16_t pixelCount, size_t elementSize)
: T_BASE(pin, pixelCount, elementSize)
NeoEsp8266UartMethodBase(uint16_t pixelCount, size_t elementSize)
: T_BASE(pixelCount, elementSize)
{
}