FastLED 3.6.0
Loading...
Searching...
No Matches
lib8tion.h File Reference

Detailed Description

Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.


Definition in file lib8tion.h.

#include "FastLED.h"
#include <stdint.h>
#include <string.h>
#include "lib8tion/math8.h"
#include "lib8tion/scale8.h"
#include "lib8tion/random8.h"
#include "lib8tion/trig8.h"

Go to the source code of this file.

Classes

union  IEEE754binary32_t
 typedef for IEEE754 "binary32" float type internals More...
 
class  q< T, F, I >
 Template class for representing fractional ints. More...
 
class  CEveryNTime
 Time interval checking class. More...
 

Macros

#define LIB8STATIC   __attribute__ ((unused)) static inline
 Define a LIB8TION member function as static inline with an "unused" attribute.
 
#define LIB8STATIC_ALWAYS_INLINE   __attribute__ ((always_inline)) static inline
 Define a LIB8TION member function as always static inline.
 
#define GET_MILLIS   millis
 The a number of functions need access to a millisecond counter in order to keep time.
 
#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME, TIMETYPE, TIMEGETTER)
 Preprocessor-based class "template" for CEveryNTime, used with EVERY_N_TIME timekeepers.
 
#define USE_GET_MILLISECOND_TIMER
 Set this flag to use the get_millisecond_timer() function in place of the default millis() function.
 
"EVERY_N_TIME" Macros

Check whether to excecute a block of code every N amount of time.

These are useful for limiting how often code runs. For example, you can use fill_rainbow() to fill a strip of LEDs with color, combined with an EVERY_N_MILLIS block to limit how fast the colors change:

static uint8_t hue = 0;
fill_rainbow(leds, NUM_LEDS, hue);
EVERY_N_MILLIS(20) { hue++; } // advances hue every 20 milliseconds
void fill_rainbow(struct CRGB *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue)
Fill a range of LEDs with a rainbow of colors.
#define EVERY_N_MILLIS(N)
Checks whether to execute a block of code every N milliseconds.
Definition lib8tion.h:1378

Note that in order for these to be accurate, the EVERY_N block must be evaluated at a regular basis.

#define EVERY_N_MILLIS(N)   EVERY_N_MILLIS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N milliseconds.
 
#define EVERY_N_MILLIS_I(NAME, N)   static CEveryNMillis NAME(N); if( NAME )
 Checks whether to execute a block of code every N milliseconds, using a custom instance name.
 
#define EVERY_N_SECONDS(N)   EVERY_N_SECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N seconds.
 
#define EVERY_N_SECONDS_I(NAME, N)   static CEveryNSeconds NAME(N); if( NAME )
 Checks whether to execute a block of code every N seconds, using a custom instance name.
 
#define EVERY_N_BSECONDS(N)   EVERY_N_BSECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N bseconds.
 
#define EVERY_N_BSECONDS_I(NAME, N)   static CEveryNBSeconds NAME(N); if( NAME )
 Checks whether to execute a block of code every N bseconds, using a custom instance name.
 
#define EVERY_N_MINUTES(N)   EVERY_N_MINUTES_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N minutes.
 
#define EVERY_N_MINUTES_I(NAME, N)   static CEveryNMinutes NAME(N); if( NAME )
 Checks whether to execute a block of code every N minutes, using a custom instance name.
 
#define EVERY_N_HOURS(N)   EVERY_N_HOURS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
 Checks whether to execute a block of code every N hours.
 
#define EVERY_N_HOURS_I(NAME, N)   static CEveryNHours NAME(N); if( NAME )
 Checks whether to execute a block of code every N hours, using a custom instance name.
 
#define EVERY_N_MILLISECONDS(N)   EVERY_N_MILLIS(N)
 Alias for EVERY_N_MILLIS.
 
#define EVERY_N_MILLISECONDS_I(NAME, N)   EVERY_N_MILLIS_I(NAME,N)
 Alias for EVERY_N_MILLIS_I.
 

Typedefs

typedef uint8_t fract8
 ANSI: unsigned short _Fract.
 
typedef int8_t sfract7
 ANSI: signed short _Fract.
 
typedef uint16_t fract16
 ANSI: unsigned _Fract.
 
typedef int16_t sfract15
 ANSI: signed _Fract.
 
typedef uint16_t accum88
 ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
 
typedef int16_t saccum78
 ANSI: signed short _Accum. 7 bits int, 8 bits fraction.
 
typedef uint32_t accum1616
 ANSI: signed _Accum. 16 bits int, 16 bits fraction.
 
typedef int32_t saccum1516
 ANSI: signed _Accum. 15 bits int, 16 bits fraction.
 
typedef uint16_t accum124
 no direct ANSI counterpart. 12 bits int, 4 bits fraction
 
typedef int32_t saccum114
 no direct ANSI counterpart. 1 bit int, 14 bits fraction
 
typedef q< uint8_t, 4, 4 > q44
 A 4.4 integer (4 bits integer, 4 bits fraction)
 
typedef q< uint8_t, 6, 2 > q62
 A 6.2 integer (6 bits integer, 2 bits fraction)
 
typedef q< uint16_t, 8, 8 > q88
 A 8.8 integer (8 bits integer, 8 bits fraction)
 
typedef q< uint16_t, 12, 4 > q124
 A 12.4 integer (12 bits integer, 4 bits fraction)
 

Functions

LIB8STATIC float sfract15ToFloat (sfract15 y)
 Conversion from 16-bit fixed point (sfract15) to IEEE754 32-bit float.
 
LIB8STATIC sfract15 floatToSfract15 (float f)
 Conversion from IEEE754 float in the range (-1,1) to 16-bit fixed point (sfract15).
 
void * memmove8 (void *dst, const void *src, uint16_t num)
 Faster alternative to memmove() on AVR.
 
void * memcpy8 (void *dst, const void *src, uint16_t num)
 Faster alternative to memcpy() on AVR.
 
void * memset8 (void *ptr, uint8_t value, uint16_t num)
 Faster alternative to memset() on AVR.
 
LIB8STATIC uint8_t lerp8by8 (uint8_t a, uint8_t b, fract8 frac)
 Linear interpolation between two unsigned 8-bit values, with 8-bit fraction.
 
LIB8STATIC uint16_t lerp16by16 (uint16_t a, uint16_t b, fract16 frac)
 Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
 
LIB8STATIC uint16_t lerp16by8 (uint16_t a, uint16_t b, fract8 frac)
 Linear interpolation between two unsigned 16-bit values, with 8-bit fraction.
 
LIB8STATIC int16_t lerp15by8 (int16_t a, int16_t b, fract8 frac)
 Linear interpolation between two signed 15-bit values, with 8-bit fraction.
 
LIB8STATIC int16_t lerp15by16 (int16_t a, int16_t b, fract16 frac)
 Linear interpolation between two signed 15-bit values, with 8-bit fraction.
 
LIB8STATIC uint8_t map8 (uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
 Map from one full-range 8-bit value into a narrower range of 8-bit values, possibly a range of hues.
 
LIB8STATIC uint8_t ease8InOutQuad (uint8_t i)
 8-bit quadratic ease-in / ease-out function.
 
LIB8STATIC uint16_t ease16InOutQuad (uint16_t i)
 16-bit quadratic ease-in / ease-out function.
 
LIB8STATIC fract8 ease8InOutCubic (fract8 i)
 8-bit cubic ease-in / ease-out function.
 
LIB8STATIC fract8 ease8InOutApprox (fract8 i)
 Fast, rough 8-bit ease-in/ease-out function.
 
LIB8STATIC uint8_t triwave8 (uint8_t in)
 Triangle wave generator.
 
LIB8STATIC uint8_t quadwave8 (uint8_t in)
 Quadratic waveform generator.
 
LIB8STATIC uint8_t cubicwave8 (uint8_t in)
 Cubic waveform generator.
 
LIB8STATIC uint8_t squarewave8 (uint8_t in, uint8_t pulsewidth=128)
 Square wave generator.
 
LIB8STATIC uint16_t beat88 (accum88 beats_per_minute_88, uint32_t timebase=0)
 Generates a 16-bit "sawtooth" wave at a given BPM, with BPM specified in Q8.8 fixed-point format.
 
LIB8STATIC uint16_t beat16 (accum88 beats_per_minute, uint32_t timebase=0)
 Generates a 16-bit "sawtooth" wave at a given BPM.
 
LIB8STATIC uint8_t beat8 (accum88 beats_per_minute, uint32_t timebase=0)
 Generates an 8-bit "sawtooth" wave at a given BPM.
 
LIB8STATIC uint16_t beatsin88 (accum88 beats_per_minute_88, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
 Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint16_t beatsin16 (accum88 beats_per_minute, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
 Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint8_t beatsin8 (accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
 Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint16_t seconds16 ()
 Return the current seconds since boot in a 16-bit value.
 
LIB8STATIC uint16_t minutes16 ()
 Return the current minutes since boot in a 16-bit value.
 
LIB8STATIC uint8_t hours8 ()
 Return the current hours since boot in an 8-bit value.
 
LIB8STATIC uint16_t div1024_32_16 (uint32_t in32)
 Helper routine to divide a 32-bit value by 1024, returning only the low 16 bits.
 
LIB8STATIC uint16_t bseconds16 ()
 Returns the current time-since-boot in "binary seconds", which are actually 1024/1000 of a second long.
 

CEveryNTime Base Classes

These macros define the time interval checking classes used in the EVERY_N_TIME time macros.

#define CEveryNMilliseconds   CEveryNMillis
 Alias for CEveryNMillis.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNMillis, uint32_t, GET_MILLIS)
 Create the CEveryNMillis class for millisecond intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNSeconds, uint16_t, seconds16)
 Create the CEveryNSeconds class for second intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNBSeconds, uint16_t, bseconds16)
 Create the CEveryNBSeconds class for bsecond intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNMinutes, uint16_t, minutes16)
 Create the CEveryNMinutes class for minutes intervals.
 
 INSTANTIATE_EVERY_N_TIME_PERIODS (CEveryNHours, uint8_t, hours8)
 Create the CEveryNHours class for hours intervals.
 

Macro Definition Documentation

◆ LIB8STATIC

#define LIB8STATIC   __attribute__ ((unused)) static inline

Define a LIB8TION member function as static inline with an "unused" attribute.

Definition at line 21 of file lib8tion.h.

◆ LIB8STATIC_ALWAYS_INLINE

#define LIB8STATIC_ALWAYS_INLINE   __attribute__ ((always_inline)) static inline

Define a LIB8TION member function as always static inline.

Definition at line 23 of file lib8tion.h.