Skip to content

Commit 26e222e

Browse files
committed
Merged changes from main FastLED repo (upstream)
2 parents 2fa8bb4 + 2fbac71 commit 26e222e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+3475
-2750
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
html/
21
*.gch
32
*~
3+
/.vscode
4+
/docs/html
5+
/docs/latex

PORTING.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
=New platform porting guide=
1+
New platform porting guide
2+
==========================
23

3-
== Fast porting for a new board on existing hardware ==
4+
# Fast porting for a new board on existing hardware
45

56
Sometimes "porting" FastLED simply consists of supplying new pin definitions for the given platform. For example, platforms/avr/fastpin_avr.h contains various pin definitions for all the AVR variant chipsets/boards that FastLED supports. Defining a set of pins involves setting up a set of definitions - for example here's one full set from the avr fastpin file:
67

@@ -26,7 +27,7 @@ The ```_FL_IO``` macro is used to define the port registers for the platform whi
2627

2728
The ```HAS_HARDWARE_PIN_SUPPORT``` define tells the rest of the FastLED library that there is hardware pin support available. There may be other platform specific defines for things like hardware SPI ports and such.
2829

29-
== Setting up the basic files/folders ==
30+
## Setting up the basic files/folders
3031

3132
* Create platform directory (e.g. platforms/arm/kl26)
3233
* Create configuration header led_sysdefs_arm_kl26.h:
@@ -38,18 +39,18 @@ The ```HAS_HARDWARE_PIN_SUPPORT``` define tells the rest of the FastLED library
3839
* Modify led_sysdefs.h to conditionally include platform sysdefs header file
3940
* Modify platforms.h to conditionally include platform fastled header
4041

41-
== Porting fastpin.h ==
42+
## Porting fastpin.h
4243

4344
The heart of the FastLED library is the fast pin accesss. This is a templated class that provides 1-2 cycle pin access, bypassing digital write and other such things. As such, this will usually be the first bit of the library that you will want to port when moving to a new platform. Once you have FastPIN up and running then you can do some basic work like testing toggles or running bit-bang'd SPI output.
4445

4546
There's two low level FastPin classes. There's the base FastPIN template class, and then there is FastPinBB which is for bit-banded access on those MCUs that support bitbanding. Note that the bitband class is optional and primarily useful in the implementation of other functionality internal to the platform. This file is also where you would do the pin to port/bit mapping defines.
4647

4748
Explaining how the macros work and should be used is currently beyond the scope of this document.
4849

49-
== Porting fastspi.h ==
50+
## Porting fastspi.h
5051

5152
This is where you define the low level interface to the hardware SPI system (including a writePixels method that does a bunch of housekeeping for writing led data). Use the fastspi_nop.h file as a reference for the methods that need to be implemented. There are ofteh other useful methods that can help with the internals of the SPI code, I recommend taking a look at how the various platforms implement their SPI classes.
5253

53-
== Porting clockless.h ==
54+
## Porting clockless.h
5455

5556
This is where you define the code for the clockless controllers. Across ARM platforms this will usually be fairly similar - though different arm platforms will have different clock sources that you can/should use.

docs/Doxyfile

+392-199
Large diffs are not rendered by default.

examples/ColorPalette/ColorPalette.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void FillLEDsFromPaletteColors( uint8_t colorIndex)
6262
{
6363
uint8_t brightness = 255;
6464

65-
for( int i = 0; i < NUM_LEDS; i++) {
65+
for( int i = 0; i < NUM_LEDS; ++i) {
6666
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
6767
colorIndex += 3;
6868
}
@@ -101,7 +101,7 @@ void ChangePalettePeriodically()
101101
// This function fills the palette with totally random colors.
102102
void SetupTotallyRandomPalette()
103103
{
104-
for( int i = 0; i < 16; i++) {
104+
for( int i = 0; i < 16; ++i) {
105105
currentPalette[i] = CHSV( random8(), 255, random8());
106106
}
107107
}

examples/XYMatrix/XYMatrix.ino

+21-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const uint8_t kMatrixHeight = 16;
3030

3131
// Param for different pixel layouts
3232
const bool kMatrixSerpentineLayout = true;
33+
const bool kMatrixVertical = false;
3334
// Set 'kMatrixSerpentineLayout' to false if your pixels are
3435
// laid out all running the same way, like this:
3536
//
@@ -88,17 +89,29 @@ uint16_t XY( uint8_t x, uint8_t y)
8889
uint16_t i;
8990

9091
if( kMatrixSerpentineLayout == false) {
91-
i = (y * kMatrixWidth) + x;
92+
if (kMatrixVertical == false) {
93+
i = (y * kMatrixWidth) + x;
94+
} else {
95+
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
96+
}
9297
}
9398

9499
if( kMatrixSerpentineLayout == true) {
95-
if( y & 0x01) {
96-
// Odd rows run backwards
97-
uint8_t reverseX = (kMatrixWidth - 1) - x;
98-
i = (y * kMatrixWidth) + reverseX;
99-
} else {
100-
// Even rows run forwards
101-
i = (y * kMatrixWidth) + x;
100+
if (kMatrixVertical == false) {
101+
if( y & 0x01) {
102+
// Odd rows run backwards
103+
uint8_t reverseX = (kMatrixWidth - 1) - x;
104+
i = (y * kMatrixWidth) + reverseX;
105+
} else {
106+
// Even rows run forwards
107+
i = (y * kMatrixWidth) + x;
108+
}
109+
} else { // vertical positioning
110+
if ( x & 0x01) {
111+
i = kMatrixHeight * (kMatrixWidth - (x+1))+y;
112+
} else {
113+
i = kMatrixHeight * (kMatrixWidth - x) - (y+1);
114+
}
102115
}
103116
}
104117

src/FastLED.cpp

+27-27
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ CFastLED::CFastLED() {
3131
}
3232

3333
CLEDController &CFastLED::addLeds(CLEDController *pLed,
34-
struct CRGB *data,
35-
int nLedsOrOffset, int nLedsIfOffset) {
34+
struct CRGB *data,
35+
int nLedsOrOffset, int nLedsIfOffset) {
3636
int nOffset = (nLedsIfOffset > 0) ? nLedsOrOffset : 0;
3737
int nLeds = (nLedsIfOffset > 0) ? nLedsIfOffset : nLedsOrOffset;
3838

@@ -67,7 +67,7 @@ int CFastLED::count() {
6767
int x = 0;
6868
CLEDController *pCur = CLEDController::head();
6969
while( pCur) {
70-
x++;
70+
++x;
7171
pCur = pCur->next();
7272
}
7373
return x;
@@ -204,33 +204,33 @@ extern int noise_min;
204204
extern int noise_max;
205205

206206
void CFastLED::countFPS(int nFrames) {
207-
static int br = 0;
208-
static uint32_t lastframe = 0; // millis();
209-
210-
if(br++ >= nFrames) {
211-
uint32_t now = millis();
212-
now -= lastframe;
213-
if( now == 0 ) {
214-
now = 1; // prevent division by zero below
215-
}
216-
m_nFPS = (br * 1000) / now;
217-
br = 0;
218-
lastframe = millis();
219-
}
207+
static int br = 0;
208+
static uint32_t lastframe = 0; // millis();
209+
210+
if(br++ >= nFrames) {
211+
uint32_t now = millis();
212+
now -= lastframe;
213+
if(now == 0) {
214+
now = 1; // prevent division by zero below
215+
}
216+
m_nFPS = (br * 1000) / now;
217+
br = 0;
218+
lastframe = millis();
219+
}
220220
}
221221

222222
void CFastLED::setMaxRefreshRate(uint16_t refresh, bool constrain) {
223-
if(constrain) {
224-
// if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
225-
// allowed to slow things down if constraining)
226-
if(refresh > 0) {
227-
m_nMinMicros = ( (1000000/refresh) > m_nMinMicros) ? (1000000/refresh) : m_nMinMicros;
228-
}
229-
} else if(refresh > 0) {
230-
m_nMinMicros = 1000000 / refresh;
231-
} else {
232-
m_nMinMicros = 0;
233-
}
223+
if(constrain) {
224+
// if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
225+
// allowed to slow things down if constraining)
226+
if(refresh > 0) {
227+
m_nMinMicros = ((1000000 / refresh) > m_nMinMicros) ? (1000000 / refresh) : m_nMinMicros;
228+
}
229+
} else if(refresh > 0) {
230+
m_nMinMicros = 1000000 / refresh;
231+
} else {
232+
m_nMinMicros = 0;
233+
}
234234
}
235235

236236
extern "C" int atexit(void (* /*func*/ )()) { return 0; }

src/FastLED.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ class CFastLED {
316316
}
317317

318318
#if defined(__FASTLED_HAS_FIBCC) && (__FASTLED_HAS_FIBCC == 1)
319-
template<uint8_t NUM_LANES, template<uint8_t DATA_PIN, EOrder RGB_ORDER> class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER=RGB>
320-
static CLEDController &addLeds(struct CRGB *data, int nLeds) {
321-
static __FIBCC<CHIPSET, DATA_PIN, NUM_LANES, RGB_ORDER> c;
322-
return addLeds(&c, data, nLeds);
323-
}
319+
template<uint8_t NUM_LANES, template<uint8_t DATA_PIN, EOrder RGB_ORDER> class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER=RGB>
320+
static CLEDController &addLeds(struct CRGB *data, int nLeds) {
321+
static __FIBCC<CHIPSET, DATA_PIN, NUM_LANES, RGB_ORDER> c;
322+
return addLeds(&c, data, nLeds);
323+
}
324324
#endif
325325

326326
#ifdef FASTSPI_USE_DMX_SIMPLE
@@ -556,19 +556,19 @@ class CFastLED {
556556
uint16_t getFPS() { return m_nFPS; }
557557

558558
/// Get how many controllers have been registered
559-
/// @returns the number of controllers (strips) that have been added with addLeds
559+
/// @returns the number of controllers (strips) that have been added with addLeds
560560
int count();
561561

562562
/// Get a reference to a registered controller
563-
/// @returns a reference to the Nth controller
563+
/// @returns a reference to the Nth controller
564564
CLEDController & operator[](int x);
565565

566566
/// Get the number of leds in the first controller
567-
/// @returns the number of LEDs in the first controller
567+
/// @returns the number of LEDs in the first controller
568568
int size() { return (*this)[0].size(); }
569569

570570
/// Get a pointer to led data for the first controller
571-
/// @returns pointer to the CRGB buffer for the first controller
571+
/// @returns pointer to the CRGB buffer for the first controller
572572
CRGB *leds() { return (*this)[0].leds(); }
573573
};
574574

src/bitswap.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
/// Simplified form of bits rotating function. Based on code found here - http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt - rotating
55
/// data into LSB for a faster write (the code using this data can happily walk the array backwards)
66
void transpose8x1_noinline(unsigned char *A, unsigned char *B) {
7-
uint32_t x, y, t;
7+
uint32_t x, y, t;
88

9-
// Load the array and pack it into x and y.
10-
y = *(unsigned int*)(A);
11-
x = *(unsigned int*)(A+4);
9+
// Load the array and pack it into x and y.
10+
y = *(unsigned int*)(A);
11+
x = *(unsigned int*)(A+4);
1212

13-
// pre-transform x
14-
t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
15-
t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
13+
// pre-transform x
14+
t = (x ^ (x >> 7)) & 0x00AA00AA; x = x ^ t ^ (t << 7);
15+
t = (x ^ (x >>14)) & 0x0000CCCC; x = x ^ t ^ (t <<14);
1616

17-
// pre-transform y
18-
t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
19-
t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
17+
// pre-transform y
18+
t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
19+
t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
2020

21-
// final transform
22-
t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
23-
y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
24-
x = t;
21+
// final transform
22+
t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
23+
y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
24+
x = t;
2525

26-
*((uint32_t*)B) = y;
27-
*((uint32_t*)(B+4)) = x;
26+
*((uint32_t*)B) = y;
27+
*((uint32_t*)(B+4)) = x;
2828
}

src/bitswap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ __attribute__((always_inline)) inline void swapbits8(bitswap_type in, bitswap_ty
126126
// SWAPSB(b.c,1);
127127
// SWAPSB(b.d,0);
128128

129-
for(int i = 0; i < 8; i++) {
129+
for(int i = 0; i < 8; ++i) {
130130
just8bits work;
131131
work.a3 = in.word[0] >> 31;
132132
work.a2 = in.word[0] >> 23;
@@ -145,7 +145,7 @@ __attribute__((always_inline)) inline void swapbits8(bitswap_type in, bitswap_ty
145145
/// Slow version of the 8 byte by 8 bit rotation
146146
__attribute__((always_inline)) inline void slowswap(unsigned char *A, unsigned char *B) {
147147

148-
for(int row = 0; row < 7; row++) {
148+
for(int row = 0; row < 7; ++row) {
149149
uint8_t x = A[row];
150150

151151
uint8_t bit = (1<<row);

src/chipsets.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FASTLED_NAMESPACE_BEGIN
1616
#if defined(ARDUINO) //&& defined(SoftwareSerial_h)
1717

1818

19-
#if defined(SoftwareSerial_h)
19+
#if defined(SoftwareSerial_h) || defined(__SoftwareSerial_h)
2020
#include <SoftwareSerial.h>
2121

2222
#define HAS_PIXIE
@@ -28,6 +28,7 @@ template<uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
2828
class PixieController : public CPixelLEDController<RGB_ORDER> {
2929
SoftwareSerial Serial;
3030
CMinWait<2000> mWait;
31+
3132
public:
3233
PixieController() : Serial(-1, DATA_PIN) {}
3334

@@ -92,8 +93,8 @@ class LPD8806Controller : public CPixelLEDController<RGB_ORDER> {
9293
};
9394

9495
SPI mSPI;
95-
public:
9696

97+
public:
9798
LPD8806Controller() {}
9899
virtual void init() {
99100
mSPI.init();
@@ -123,6 +124,7 @@ class WS2801Controller : public CPixelLEDController<RGB_ORDER> {
123124
typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
124125
SPI mSPI;
125126
CMinWait<1000> mWaitDelay;
127+
126128
public:
127129
WS2801Controller() {}
128130

@@ -132,7 +134,6 @@ class WS2801Controller : public CPixelLEDController<RGB_ORDER> {
132134
}
133135

134136
protected:
135-
136137
virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
137138
mWaitDelay.wait();
138139
mSPI.template writePixels<0, DATA_NOP, RGB_ORDER>(pixels);
@@ -166,7 +167,6 @@ class LPD6803Controller : public CPixelLEDController<RGB_ORDER> {
166167
}
167168

168169
protected:
169-
170170
virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
171171
mSPI.select();
172172

@@ -232,7 +232,6 @@ class APA102Controller : public CPixelLEDController<RGB_ORDER> {
232232
}
233233

234234
protected:
235-
236235
virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
237236
mSPI.select();
238237

@@ -297,7 +296,6 @@ class SK9822Controller : public CPixelLEDController<RGB_ORDER> {
297296
}
298297

299298
protected:
300-
301299
virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
302300
mSPI.select();
303301

@@ -360,7 +358,6 @@ class P9813Controller : public CPixelLEDController<RGB_ORDER> {
360358
}
361359

362360
protected:
363-
364361
virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
365362
mSPI.select();
366363

@@ -418,7 +415,6 @@ class SM16716Controller : public CPixelLEDController<RGB_ORDER> {
418415
}
419416

420417
protected:
421-
422418
virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
423419
// Make sure the FLAG_START_BIT flag is set to ensure that an extra 1 bit is sent at the start
424420
// of each triplet of bytes for rgb data
@@ -458,7 +454,7 @@ class SM16716Controller : public CPixelLEDController<RGB_ORDER> {
458454

459455
// We want to force all avr's to use the Trinket controller when running at 8Mhz, because even the 328's at 8Mhz
460456
// need the more tightly defined timeframes.
461-
#if (CLOCKLESS_FREQUENCY == 8000000 || CLOCKLESS_FREQUENCY == 16000000 || CLOCKLESS_FREQUENCY == 24000000) // || CLOCKLESS_FREQUENCY == 48000000 || CLOCKLESS_FREQUENCY == 96000000) // 125ns/clock
457+
#if defined(__LGT8F__) || (CLOCKLESS_FREQUENCY == 8000000 || CLOCKLESS_FREQUENCY == 16000000 || CLOCKLESS_FREQUENCY == 24000000) // || CLOCKLESS_FREQUENCY == 48000000 || CLOCKLESS_FREQUENCY == 96000000) // 125ns/clock
462458
#define FMUL (CLOCKLESS_FREQUENCY/8000000)
463459

464460
// GE8822

0 commit comments

Comments
 (0)