3#ifndef __INC_LIB8TION_H
4#define __INC_LIB8TION_H
9#ifndef __INC_LED_SYSDEFS_H
10#error WTH? led_sysdefs needs to be included first
30#if defined(FASTLED_TEENSY3)
34#define QADD8_ARM_DSP_ASM 1
35#define QADD7_ARM_DSP_ASM 1
62#elif defined(ARDUINO_ARCH_APOLLO3)
104#define QADD8_AVRASM 1
105#define QADD7_AVRASM 1
106#define QSUB8_AVRASM 1
111#define AVG8R_AVRASM 1
113#define AVG16_AVRASM 1
114#define AVG16R_AVRASM 1
115#define AVG15_AVRASM 1
119#if !defined(LIB8_ATTINY)
121#define SCALE16BY8_C 0
127#define SCALE8_AVRASM 1
128#define SCALE16BY8_AVRASM 1
129#define SCALE16_AVRASM 1
131#define QMUL8_AVRASM 1
132#define EASE8_AVRASM 1
133#define CLEANUP_R1_AVRASM 1
134#define BLEND8_AVRASM 1
138#define SCALE16BY8_C 1
144#define SCALE8_AVRASM 0
145#define SCALE16BY8_AVRASM 0
146#define SCALE16_AVRASM 0
148#define QMUL8_AVRASM 0
149#define EASE8_AVRASM 0
150#define BLEND8_AVRASM 0
166#define SCALE16BY8_C 1
441 uint8_t delta = b - a;
442 uint8_t scaled =
scale8( delta, frac);
445 uint8_t delta = a - b;
446 uint8_t scaled =
scale8( delta, frac);
458 uint16_t delta = b - a;
459 uint16_t scaled =
scale16(delta, frac);
462 uint16_t delta = a - b;
463 uint16_t scaled =
scale16( delta, frac);
475 uint16_t delta = b - a;
479 uint16_t delta = a - b;
492 uint16_t delta = b - a;
496 uint16_t delta = a - b;
509 uint16_t delta = b - a;
510 uint16_t scaled =
scale16( delta, frac);
513 uint16_t delta = a - b;
514 uint16_t scaled =
scale16( delta, frac);
543 uint8_t rangeWidth = rangeEnd - rangeStart;
544 uint8_t out =
scale8( in, rangeWidth);
561#if (EASE8_C == 1) || defined(FASTLED_DOXYGEN)
568 uint8_t jj =
scale8( j, j);
569 uint8_t jj2 = jj << 1;
576#elif EASE8_AVRASM == 1
593 "clr __zero_reg__ \n"
602#error "No implementation for ease8InOutQuad available."
614 uint16_t jj2 = jj << 1;
629 uint16_t r1 = (3 * (uint16_t)(ii)) - ( 2 * (uint16_t)(iii));
652#if (EASE8_C == 1) || defined(FASTLED_DOXYGEN)
658 }
else if( i > (255 - 64)) {
673#elif EASE8_AVRASM == 1
678 " subi %[i], 64 \n\t"
679 " cpi %[i], 128 \n\t"
680 " brcc Lshift_%= \n\t"
683 " mov __tmp_reg__, %[i] \n\t"
684 " lsr __tmp_reg__ \n\t"
685 " add %[i], __tmp_reg__ \n\t"
686 " subi %[i], 224 \n\t"
687 " rjmp Ldone_%= \n\t"
692 " subi %[i], 96 \n\t"
703#error "No implementation for ease8 available."
733 uint8_t out = in << 1;
786 if( in < pulsewidth || (pulsewidth == 255)) {
805#if ((defined(ARDUINO) || defined(SPARK) || defined(FASTLED_HAS_MILLIS)) && !defined(USE_GET_MILLISECOND_TIMER)) || defined(FASTLED_DOXYGEN)
819#define GET_MILLIS millis
821uint32_t get_millisecond_timer();
822#define GET_MILLIS get_millisecond_timer
889 return (((
GET_MILLIS()) - timebase) * beats_per_minute_88 * 280) >> 16;
898 if( beats_per_minute < 256) beats_per_minute <<= 8;
899 return beat88(beats_per_minute, timebase);
907 return beat16( beats_per_minute, timebase) >> 8;
922 uint32_t timebase = 0, uint16_t phase_offset = 0)
924 uint16_t beat =
beat88( beats_per_minute_88, timebase);
925 uint16_t beatsin = (
sin16( beat + phase_offset) + 32768);
926 uint16_t rangewidth = highest - lowest;
927 uint16_t scaledbeat =
scale16( beatsin, rangewidth);
928 uint16_t result = lowest + scaledbeat;
940 uint32_t timebase = 0, uint16_t phase_offset = 0)
942 uint16_t beat =
beat16( beats_per_minute, timebase);
943 uint16_t beatsin = (
sin16( beat + phase_offset) + 32768);
944 uint16_t rangewidth = highest - lowest;
945 uint16_t scaledbeat =
scale16( beatsin, rangewidth);
946 uint16_t result = lowest + scaledbeat;
958 uint32_t timebase = 0, uint8_t phase_offset = 0)
960 uint8_t beat =
beat8( beats_per_minute, timebase);
961 uint8_t beatsin =
sin8( beat + phase_offset);
962 uint8_t rangewidth = highest - lowest;
963 uint8_t scaledbeat =
scale8( beatsin, rangewidth);
964 uint8_t result = lowest + scaledbeat;
994 m16 = (ms / (60000L)) & 0xFFFF;
1004 h8 = (ms / (3600000L)) & 0xFF;
1033 " mov %B[out],%C[in] \n\t"
1034 " mov %A[out],%B[in] \n\t"
1039 out16 = (in32 >> 10) & 0xFFFF;
1059#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME,TIMETYPE,TIMEGETTER) \
1062 TIMETYPE mPrevTrigger; \
1065 NAME() { reset(); mPeriod = 1; }; \
1066 NAME(TIMETYPE period) { reset(); setPeriod(period); }; \
1067 void setPeriod( TIMETYPE period) { mPeriod = period; }; \
1068 TIMETYPE getTime() { return (TIMETYPE)(TIMEGETTER()); }; \
1069 TIMETYPE getPeriod() { return mPeriod; }; \
1070 TIMETYPE getElapsed() { return getTime() - mPrevTrigger; } \
1071 TIMETYPE getRemaining() { return mPeriod - getElapsed(); } \
1072 TIMETYPE getLastTriggerTime() { return mPrevTrigger; } \
1074 bool isReady = (getElapsed() >= mPeriod); \
1075 if( isReady ) { reset(); } \
1078 void reset() { mPrevTrigger = getTime(); }; \
1079 void trigger() { mPrevTrigger = getTime() - mPeriod; }; \
1081 operator bool() { return ready(); } \
1089#if defined(FASTLED_DOXYGEN)
1117 TIMETYPE
getTime() {
return (TIMETYPE)(TIMEGETTER()); };
1134 if( isReady ) {
reset(); }
1165#define CEveryNMilliseconds CEveryNMillis
1181 if( isReady ) {
reset(); }
1242template<
typename timeType,timeType (*timeGetter)()>
1243class CEveryNTimePeriods {
1245 timeType mPrevTrigger;
1248 CEveryNTimePeriods() { reset(); mPeriod = 1; };
1249 CEveryNTimePeriods(timeType period) { reset(); setPeriod(period); };
1250 void setPeriod( timeType period) { mPeriod = period; };
1251 timeType getTime() {
return (timeType)(timeGetter()); };
1252 timeType getPeriod() {
return mPeriod; };
1253 timeType getElapsed() {
return getTime() - mPrevTrigger; }
1254 timeType getRemaining() {
return mPeriod - getElapsed(); }
1255 timeType getLastTriggerTime() {
return mPrevTrigger; }
1257 bool isReady = (getElapsed() >= mPeriod);
1258 if( isReady ) { reset(); }
1261 void reset() { mPrevTrigger = getTime(); };
1262 void trigger() { mPrevTrigger = getTime() - mPeriod; };
1264 operator bool() {
return ready(); }
1266typedef CEveryNTimePeriods<uint16_t,seconds16> CEveryNSeconds;
1267typedef CEveryNTimePeriods<uint16_t,bseconds16> CEveryNBSeconds;
1268typedef CEveryNTimePeriods<uint32_t,millis> CEveryNMillis;
1269typedef CEveryNTimePeriods<uint16_t,minutes16> CEveryNMinutes;
1270typedef CEveryNTimePeriods<uint8_t,hours8> CEveryNHours;
1290#define CONCAT_HELPER( x, y ) x##y
1291#define CONCAT_MACRO( x, y ) CONCAT_HELPER( x, y )
1297#define EVERY_N_MILLIS(N) EVERY_N_MILLIS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1301#define EVERY_N_MILLIS_I(NAME,N) static CEveryNMillis NAME(N); if( NAME )
1306#define EVERY_N_SECONDS(N) EVERY_N_SECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1310#define EVERY_N_SECONDS_I(NAME,N) static CEveryNSeconds NAME(N); if( NAME )
1315#define EVERY_N_BSECONDS(N) EVERY_N_BSECONDS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1319#define EVERY_N_BSECONDS_I(NAME,N) static CEveryNBSeconds NAME(N); if( NAME )
1324#define EVERY_N_MINUTES(N) EVERY_N_MINUTES_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1328#define EVERY_N_MINUTES_I(NAME,N) static CEveryNMinutes NAME(N); if( NAME )
1333#define EVERY_N_HOURS(N) EVERY_N_HOURS_I(CONCAT_MACRO(PER, __COUNTER__ ),N)
1337#define EVERY_N_HOURS_I(NAME,N) static CEveryNHours NAME(N); if( NAME )
1341#define EVERY_N_MILLISECONDS(N) EVERY_N_MILLIS(N)
1343#define EVERY_N_MILLISECONDS_I(NAME,N) EVERY_N_MILLIS_I(NAME,N)
1346#define EVERY_N_MILLISECONDS_DYNAMIC(PERIOD_FUNC) EVERY_N_MILLISECONDS_DYNAMIC_I(CONCAT_MACRO(__dynamic_millis_timer, __COUNTER__ ), (PERIOD_FUNC))
1349#define EVERY_N_MILLISECONDS_DYNAMIC_I(NAME, PERIOD_FUNC) \
1350 static CEveryNMillisDynamic NAME(1); \
1351 NAME.setPeriod(PERIOD_FUNC); \
1355#define EVERY_N_MILLISECONDS_RANDOM(MIN, MAX) \
1356 EVERY_N_MILLISECONDS_RANDOM_I( \
1357 CONCAT_MACRO(_permRand, __COUNTER__), MIN, MAX)
1359#define EVERY_N_MILLISECONDS_RANDOM_I(NAME, MIN, MAX) \
1360 static CEveryNMillisRandom NAME(MIN, MAX); \
1369#ifdef FASTLED_DOXYGEN
1373#define USE_GET_MILLISECOND_TIMER
UIButton trigger("Trigger")
central include file for FastLED, defines the CFastLED class/object
void setPeriod(uint32_t period)
uint32_t getLastTriggerTime()
uint32_t getPeriod() const
CEveryNMillisDynamic(uint32_t period)
CEveryNMillisRandom(uint32_t minPeriod, uint32_t maxPeriod)
void trigger()
Reset the timestamp so it is ready() on next call.
TIMETYPE mPeriod
Timing interval to check.
CEveryNTime(TIMETYPE period)
Constructor.
TIMETYPE getLastTriggerTime()
Get the timestamp of the most recent trigger event.
CEveryNTime()
Default constructor.
TIMETYPE getTime()
Get the current time according to the class' timekeeper.
TIMETYPE getElapsed()
Get the time elapsed since the last trigger event.
void setPeriod(TIMETYPE period)
Set the time interval between triggers.
bool ready()
Check if the time interval has elapsed.
void reset()
Reset the timestamp to the current time.
TIMETYPE getPeriod()
Get the time interval between triggers.
TIMETYPE mPrevTrigger
Timestamp of the last time the class was "ready".
TIMETYPE getRemaining()
Get the time until the next trigger event.
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 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 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 uint16_t beat16(accum88 beats_per_minute, uint32_t timebase=0)
Generates a 16-bit "sawtooth" wave at a given BPM.
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 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 ease16InOutQuad(uint16_t i)
16-bit quadratic ease-in / ease-out function.
LIB8STATIC fract8 ease8InOutApprox(fract8 i)
Fast, rough 8-bit ease-in/ease-out function.
LIB8STATIC uint8_t ease8InOutQuad(uint8_t i)
8-bit quadratic ease-in / ease-out function.
LIB8STATIC fract8 ease8InOutCubic(fract8 i)
8-bit cubic ease-in / ease-out function.
LIB8STATIC sfract15 floatToSfract15(float f)
Conversion from IEEE754 float in the range (-1,1) to 16-bit fixed point (sfract15).
LIB8STATIC float sfract15ToFloat(sfract15 y)
Conversion from 16-bit fixed point (sfract15) to IEEE754 32-bit float.
int16_t sfract15
ANSI: signed _Fract.
uint16_t accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
uint8_t fract8
ANSI: unsigned short _Fract.
uint16_t fract16
ANSI: unsigned _Fract.
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 uint16_t random16()
Generate a 16-bit random number.
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
LIB8STATIC uint16_t scale16(uint16_t i, fract16 scale)
Scale a 16-bit unsigned value by an 16-bit value, which is treated as the numerator of a fraction who...
LIB8STATIC_ALWAYS_INLINE uint16_t scale16by8(uint16_t i, fract8 scale)
Scale a 16-bit unsigned value by an 8-bit value, which is treated as the numerator of a fraction whos...
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
#define INSTANTIATE_EVERY_N_TIME_PERIODS(NAME, TIMETYPE, TIMEGETTER)
Preprocessor-based class "template" for CEveryNTime, used with EVERY_N_TIME timekeepers.
LIB8STATIC uint16_t minutes16()
Return the current minutes since boot in a 16-bit value.
LIB8STATIC uint16_t bseconds16()
Returns the current time-since-boot in "binary seconds", which are actually 1024/1000 of a second lon...
#define GET_MILLIS
The a number of functions need access to a millisecond counter in order to keep time.
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 uint8_t hours8()
Return the current hours since boot in an 8-bit value.
LIB8STATIC uint16_t seconds16()
Return the current seconds since boot in a 16-bit value.
#define sin16
Platform-independent alias of the fast sin implementation.
#define sin8
Platform-independent alias of the fast sin implementation.
#define LIB8STATIC
Define a LIB8TION member function as static inline with an "unused" attribute.
Defines static inlining macros for lib8tion functions.
Defines fractional types used for lib8tion functions.
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
#define FASTLED_NAMESPACE_END
Fast, efficient random number generators specifically designed for high-performance LED programming.
Fast, efficient 8-bit scaling functions specifically designed for high-performance LED programming.
Fast, efficient 8-bit trigonometry functions specifically designed for high-performance LED programmi...