Skip to content

Commit

Permalink
Merge pull request #127 from Makuna/DotStarImprovements
Browse files Browse the repository at this point in the history
DotStar and NoPin NeoPixel
  • Loading branch information
Makuna authored Sep 2, 2016
2 parents abacd3e + eb77795 commit 70e3611
Show file tree
Hide file tree
Showing 20 changed files with 174 additions and 51 deletions.
11 changes: 5 additions & 6 deletions examples/NeoPixelAnimation/NeoPixelAnimation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/NeoPixelBitmap/NeoPixelBitmap.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/NeoPixelBufferCylon/NeoPixelBufferCylon.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/NeoPixelCylon/NeoPixelCylon.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 4 additions & 6 deletions examples/NeoPixelFunFadeInOut/NeoPixelFunFadeInOut.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 4 additions & 6 deletions examples/NeoPixelFunLoop/NeoPixelFunLoop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions examples/NeoPixelFunRandomChange/NeoPixelFunRandomChange.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions examples/NeoPixelGamma/NeoPixelGamma.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
4 changes: 2 additions & 2 deletions examples/NeoPixelMosaicTest/NeoPixelMosaicTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion examples/NeoPixelRotateLoop/NeoPixelRotateLoop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions examples/NeoPixelTest/NeoPixelTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
2 changes: 2 additions & 0 deletions examples/NeoPixelTilesTest/NeoPixelTilesTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/NeoPixelTopologyTest/NeoPixelTopologyTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -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": "*"
}
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=NeoPixelBus by Makuna
version=2.2.0
version=2.2.1
author=Michael C. Miller ([email protected])
maintainer=Michael C. Miller ([email protected])
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=*
132 changes: 121 additions & 11 deletions src/internal/DotStarColorFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -93,7 +160,7 @@ class DotStar4Elements
typedef RgbwColor ColorObject;
};

class DotStarBgrFeature : public DotStar4Elements
class DotStarBgrFeature : public DotStar3Elements
{
public:
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
Expand Down Expand Up @@ -175,28 +242,28 @@ class DotStarLbgrFeature : public DotStar4Elements

};

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)
{
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;
}
Expand All @@ -206,11 +273,54 @@ class DotStarWbgrFeature : public DotStar4Elements
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;
}

};

2 changes: 1 addition & 1 deletion src/internal/DotStarSpiMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DotStarSpiMethod
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
Expand Down
2 changes: 1 addition & 1 deletion src/internal/NeoEsp8266DmaMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 70e3611

Please sign in to comment.