Skip to content

Commit

Permalink
Code formatting cleanups; markdown corrections
Browse files Browse the repository at this point in the history
Improve formatting consistency
Fix comment/docstring/markdown typos
Remove unused file
  • Loading branch information
MartyMacGyver committed May 30, 2020
1 parent 8b38771 commit 26e818b
Show file tree
Hide file tree
Showing 66 changed files with 2,733 additions and 3,517 deletions.
52 changes: 26 additions & 26 deletions FastLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ CFastLED::CFastLED() {
}

CLEDController &CFastLED::addLeds(CLEDController *pLed,
struct CRGB *data,
int nLedsOrOffset, int nLedsIfOffset) {
struct CRGB *data,
int nLedsOrOffset, int nLedsIfOffset) {
int nOffset = (nLedsIfOffset > 0) ? nLedsOrOffset : 0;
int nLeds = (nLedsIfOffset > 0) ? nLedsIfOffset : nLedsOrOffset;

Expand Down Expand Up @@ -204,33 +204,33 @@ extern int noise_min;
extern int noise_max;

void CFastLED::countFPS(int nFrames) {
static int br = 0;
static uint32_t lastframe = 0; // millis();

if(br++ >= nFrames) {
uint32_t now = millis();
now -= lastframe;
if( now == 0 ) {
now = 1; // prevent division by zero below
}
m_nFPS = (br * 1000) / now;
br = 0;
lastframe = millis();
}
static int br = 0;
static uint32_t lastframe = 0; // millis();

if(br++ >= nFrames) {
uint32_t now = millis();
now -= lastframe;
if(now == 0) {
now = 1; // prevent division by zero below
}
m_nFPS = (br * 1000) / now;
br = 0;
lastframe = millis();
}
}

void CFastLED::setMaxRefreshRate(uint16_t refresh, bool constrain) {
if(constrain) {
// if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
// allowed to slow things down if constraining)
if(refresh > 0) {
m_nMinMicros = ( (1000000/refresh) > m_nMinMicros) ? (1000000/refresh) : m_nMinMicros;
}
} else if(refresh > 0) {
m_nMinMicros = 1000000 / refresh;
} else {
m_nMinMicros = 0;
}
if(constrain) {
// if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
// allowed to slow things down if constraining)
if(refresh > 0) {
m_nMinMicros = ((1000000 / refresh) > m_nMinMicros) ? (1000000 / refresh) : m_nMinMicros;
}
} else if(refresh > 0) {
m_nMinMicros = 1000000 / refresh;
} else {
m_nMinMicros = 0;
}
}

extern "C" int atexit(void (* /*func*/ )()) { return 0; }
Expand Down
18 changes: 9 additions & 9 deletions FastLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ class CFastLED {
}

#if defined(__FASTLED_HAS_FIBCC) && (__FASTLED_HAS_FIBCC == 1)
template<uint8_t NUM_LANES, template<uint8_t DATA_PIN, EOrder RGB_ORDER> class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER=RGB>
static CLEDController &addLeds(struct CRGB *data, int nLeds) {
static __FIBCC<CHIPSET, DATA_PIN, NUM_LANES, RGB_ORDER> c;
return addLeds(&c, data, nLeds);
}
template<uint8_t NUM_LANES, template<uint8_t DATA_PIN, EOrder RGB_ORDER> class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER=RGB>
static CLEDController &addLeds(struct CRGB *data, int nLeds) {
static __FIBCC<CHIPSET, DATA_PIN, NUM_LANES, RGB_ORDER> c;
return addLeds(&c, data, nLeds);
}
#endif

#ifdef FASTSPI_USE_DMX_SIMPLE
Expand Down Expand Up @@ -556,19 +556,19 @@ class CFastLED {
uint16_t getFPS() { return m_nFPS; }

/// Get how many controllers have been registered
/// @returns the number of controllers (strips) that have been added with addLeds
/// @returns the number of controllers (strips) that have been added with addLeds
int count();

/// Get a reference to a registered controller
/// @returns a reference to the Nth controller
/// @returns a reference to the Nth controller
CLEDController & operator[](int x);

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

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

Expand Down
13 changes: 7 additions & 6 deletions PORTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
=New platform porting guide=
New platform porting guide
==========================

== Fast porting for a new board on existing hardware ==
# Fast porting for a new board on existing hardware

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:

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

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.

== Setting up the basic files/folders ==
## Setting up the basic files/folders

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

== Porting fastpin.h ==
## Porting fastpin.h

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.

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.

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

== Porting fastspi.h ==
## Porting fastspi.h

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.

== Porting clockless.h ==
## Porting clockless.h

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.
32 changes: 16 additions & 16 deletions bitswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
/// Simplified form of bits rotating function. Based on code found here - http://www.hackersdelight.org/hdcodetxt/transpose8.c.txt - rotating
/// data into LSB for a faster write (the code using this data can happily walk the array backwards)
void transpose8x1_noinline(unsigned char *A, unsigned char *B) {
uint32_t x, y, t;
uint32_t x, y, t;

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

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

// pre-transform y
t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);
// pre-transform y
t = (y ^ (y >> 7)) & 0x00AA00AA; y = y ^ t ^ (t << 7);
t = (y ^ (y >>14)) & 0x0000CCCC; y = y ^ t ^ (t <<14);

// final transform
t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
x = t;
// final transform
t = (x & 0xF0F0F0F0) | ((y >> 4) & 0x0F0F0F0F);
y = ((x << 4) & 0xF0F0F0F0) | (y & 0x0F0F0F0F);
x = t;

*((uint32_t*)B) = y;
*((uint32_t*)(B+4)) = x;
*((uint32_t*)B) = y;
*((uint32_t*)(B+4)) = x;
}
10 changes: 3 additions & 7 deletions chipsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ template<uint8_t DATA_PIN, EOrder RGB_ORDER = RGB>
class PixieController : public CPixelLEDController<RGB_ORDER> {
SoftwareSerial Serial;
CMinWait<2000> mWait;

public:
PixieController() : Serial(-1, DATA_PIN) {}

Expand Down Expand Up @@ -92,8 +93,8 @@ class LPD8806Controller : public CPixelLEDController<RGB_ORDER> {
};

SPI mSPI;
public:

public:
LPD8806Controller() {}
virtual void init() {
mSPI.init();
Expand Down Expand Up @@ -123,6 +124,7 @@ class WS2801Controller : public CPixelLEDController<RGB_ORDER> {
typedef SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
SPI mSPI;
CMinWait<1000> mWaitDelay;

public:
WS2801Controller() {}

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

protected:

virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
mWaitDelay.wait();
mSPI.template writePixels<0, DATA_NOP, RGB_ORDER>(pixels);
Expand Down Expand Up @@ -166,7 +167,6 @@ class LPD6803Controller : public CPixelLEDController<RGB_ORDER> {
}

protected:

virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
mSPI.select();

Expand Down Expand Up @@ -232,7 +232,6 @@ class APA102Controller : public CPixelLEDController<RGB_ORDER> {
}

protected:

virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
mSPI.select();

Expand Down Expand Up @@ -297,7 +296,6 @@ class SK9822Controller : public CPixelLEDController<RGB_ORDER> {
}

protected:

virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
mSPI.select();

Expand Down Expand Up @@ -360,7 +358,6 @@ class P9813Controller : public CPixelLEDController<RGB_ORDER> {
}

protected:

virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
mSPI.select();

Expand Down Expand Up @@ -418,7 +415,6 @@ class SM16716Controller : public CPixelLEDController<RGB_ORDER> {
}

protected:

virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
// Make sure the FLAG_START_BIT flag is set to ensure that an extra 1 bit is sent at the start
// of each triplet of bytes for rgb data
Expand Down
106 changes: 53 additions & 53 deletions color.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,71 @@ FASTLED_NAMESPACE_BEGIN
/// definitions for color correction and light temperatures
///@{
typedef enum {
// Color correction starting points
// Color correction starting points

/// typical values for SMD5050 LEDs
///@{
/// typical values for SMD5050 LEDs
///@{
TypicalSMD5050=0xFFB0F0 /* 255, 176, 240 */,
TypicalLEDStrip=0xFFB0F0 /* 255, 176, 240 */,
///@}
///@}

/// typical values for 8mm "pixels on a string"
/// also for many through-hole 'T' package LEDs
///@{
Typical8mmPixel=0xFFE08C /* 255, 224, 140 */,
TypicalPixelString=0xFFE08C /* 255, 224, 140 */,
///@}
/// typical values for 8mm "pixels on a string"
/// also for many through-hole 'T' package LEDs
///@{
Typical8mmPixel=0xFFE08C /* 255, 224, 140 */,
TypicalPixelString=0xFFE08C /* 255, 224, 140 */,
///@}

/// uncorrected color
UncorrectedColor=0xFFFFFF
/// uncorrected color
UncorrectedColor=0xFFFFFF

} LEDColorCorrection;


typedef enum {
/// @name Black-body radiation light sources
/// Black-body radiation light sources emit a (relatively) continuous
/// spectrum, and can be described as having a Kelvin 'temperature'
///@{
/// 1900 Kelvin
Candle=0xFF9329 /* 1900 K, 255, 147, 41 */,
/// 2600 Kelvin
Tungsten40W=0xFFC58F /* 2600 K, 255, 197, 143 */,
/// 2850 Kelvin
Tungsten100W=0xFFD6AA /* 2850 K, 255, 214, 170 */,
/// 3200 Kelvin
Halogen=0xFFF1E0 /* 3200 K, 255, 241, 224 */,
/// 5200 Kelvin
CarbonArc=0xFFFAF4 /* 5200 K, 255, 250, 244 */,
/// 5400 Kelvin
HighNoonSun=0xFFFFFB /* 5400 K, 255, 255, 251 */,
/// 6000 Kelvin
DirectSunlight=0xFFFFFF /* 6000 K, 255, 255, 255 */,
/// 7000 Kelvin
OvercastSky=0xC9E2FF /* 7000 K, 201, 226, 255 */,
/// 20000 Kelvin
ClearBlueSky=0x409CFF /* 20000 K, 64, 156, 255 */,
///@}
/// @name Black-body radiation light sources
/// Black-body radiation light sources emit a (relatively) continuous
/// spectrum, and can be described as having a Kelvin 'temperature'
///@{
/// 1900 Kelvin
Candle=0xFF9329 /* 1900 K, 255, 147, 41 */,
/// 2600 Kelvin
Tungsten40W=0xFFC58F /* 2600 K, 255, 197, 143 */,
/// 2850 Kelvin
Tungsten100W=0xFFD6AA /* 2850 K, 255, 214, 170 */,
/// 3200 Kelvin
Halogen=0xFFF1E0 /* 3200 K, 255, 241, 224 */,
/// 5200 Kelvin
CarbonArc=0xFFFAF4 /* 5200 K, 255, 250, 244 */,
/// 5400 Kelvin
HighNoonSun=0xFFFFFB /* 5400 K, 255, 255, 251 */,
/// 6000 Kelvin
DirectSunlight=0xFFFFFF /* 6000 K, 255, 255, 255 */,
/// 7000 Kelvin
OvercastSky=0xC9E2FF /* 7000 K, 201, 226, 255 */,
/// 20000 Kelvin
ClearBlueSky=0x409CFF /* 20000 K, 64, 156, 255 */,
///@}

/// @name Gaseous light sources
/// Gaseous light sources emit discrete spectral bands, and while we can
/// approximate their aggregate hue with RGB values, they don't actually
/// have a proper Kelvin temperature.
///@{
WarmFluorescent=0xFFF4E5 /* 0 K, 255, 244, 229 */,
StandardFluorescent=0xF4FFFA /* 0 K, 244, 255, 250 */,
CoolWhiteFluorescent=0xD4EBFF /* 0 K, 212, 235, 255 */,
FullSpectrumFluorescent=0xFFF4F2 /* 0 K, 255, 244, 242 */,
GrowLightFluorescent=0xFFEFF7 /* 0 K, 255, 239, 247 */,
BlackLightFluorescent=0xA700FF /* 0 K, 167, 0, 255 */,
MercuryVapor=0xD8F7FF /* 0 K, 216, 247, 255 */,
SodiumVapor=0xFFD1B2 /* 0 K, 255, 209, 178 */,
MetalHalide=0xF2FCFF /* 0 K, 242, 252, 255 */,
HighPressureSodium=0xFFB74C /* 0 K, 255, 183, 76 */,
///@}
/// @name Gaseous light sources
/// Gaseous light sources emit discrete spectral bands, and while we can
/// approximate their aggregate hue with RGB values, they don't actually
/// have a proper Kelvin temperature.
///@{
WarmFluorescent=0xFFF4E5 /* 0 K, 255, 244, 229 */,
StandardFluorescent=0xF4FFFA /* 0 K, 244, 255, 250 */,
CoolWhiteFluorescent=0xD4EBFF /* 0 K, 212, 235, 255 */,
FullSpectrumFluorescent=0xFFF4F2 /* 0 K, 255, 244, 242 */,
GrowLightFluorescent=0xFFEFF7 /* 0 K, 255, 239, 247 */,
BlackLightFluorescent=0xA700FF /* 0 K, 167, 0, 255 */,
MercuryVapor=0xD8F7FF /* 0 K, 216, 247, 255 */,
SodiumVapor=0xFFD1B2 /* 0 K, 255, 209, 178 */,
MetalHalide=0xF2FCFF /* 0 K, 242, 252, 255 */,
HighPressureSodium=0xFFB74C /* 0 K, 255, 183, 76 */,
///@}

/// Uncorrected temperature 0xFFFFFF
UncorrectedTemperature=0xFFFFFF
/// Uncorrected temperature 0xFFFFFF
UncorrectedTemperature=0xFFFFFF
} ColorTemperature;

FASTLED_NAMESPACE_END
Expand Down
Loading

0 comments on commit 26e818b

Please sign in to comment.