22 #ifndef NEOPIXEL_FASTLED_H
23 #define NEOPIXEL_FASTLED_H
27 #elif defined(REELTWO_AVR)
29 #if !defined(LIB8_ATTINY)
30 #define SCALE8_AVRASM 1
31 #define CLEANUP_R1_AVRASM 1
35 #define SCALE8_AVRASM 0
44 WS2812B = NEO_GRB + NEO_KHZ800,
45 SK6812 = NEO_GRB + NEO_KHZ800,
46 SK6812CUSTOM = NEO_GRB + NEO_KHZ800
50 extern void hsv2rgb_rainbow(
const struct CHSV& hsv,
struct CRGB& rgb);
72 inline CHSV() __attribute__((always_inline))
77 inline CHSV( uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline))
83 inline CHSV(
const CHSV& rhs) __attribute__((always_inline))
90 inline CHSV& operator= (
const CHSV& rhs) __attribute__((always_inline))
98 inline CHSV& setHSV(uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline))
128 inline CRGB() __attribute__((always_inline))
133 inline CRGB( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline))
134 : g(ig), r(ir), b(ib)
139 inline CRGB& setHSV (uint8_t hue, uint8_t sat, uint8_t val) __attribute__((always_inline))
141 hsv2rgb_rainbow( CHSV(hue, sat, val), *
this);
146 inline CRGB& setRGB (uint8_t nr, uint8_t ng, uint8_t nb) __attribute__((always_inline))
156 typedef uint8_t fract8;
159 #define LIB8STATIC __attribute__ ((unused)) static inline
160 #define LIB8STATIC_ALWAYS_INLINE __attribute__ ((always_inline)) static inline
164 #define FASTLED_RAND16_2053 ((uint16_t)(2053))
165 #define FASTLED_RAND16_13849 ((uint16_t)(13849))
167 #define RAND16_SEED 1337
179 return (uint8_t)(((uint8_t)(rand16seed & 0xFF)) +
180 ((uint8_t)(rand16seed >> 8)));
186 uint8_t r = random8();
195 return (((uint16_t)i) * (1+(uint16_t)(scale))) >> 8;
196 #elif SCALE8_AVRASM == 1
197 #if defined(LIB8_ATTINY)
210 " sbrc %[scale], 0 \n\t"
211 " add %[work], %[i] \n\t"
217 : [work]
"+r" (work), [cnt]
"+r" (cnt)
218 : [scale]
"r" (scale), [i]
"r" (i)
232 "clr __zero_reg__ \n\t"
242 #error "No implementation for scale8 available."
247 LIB8STATIC uint8_t map8( uint8_t in, uint8_t rangeStart, uint8_t rangeEnd)
249 uint8_t rangeWidth = rangeEnd - rangeStart;
250 uint8_t out = scale8( in, rangeWidth);
258 #if CLEANUP_R1_AVRASM == 1
260 asm volatile(
"clr __zero_reg__ \n\t" : : :
"r1" );
268 return (((uint16_t)i) * ((uint16_t)(scale)+1)) >> 8;
269 #elif SCALE8_AVRASM == 1
289 #error "No implementation for scale8_LEAVING_R1_DIRTY available."
296 #if SCALE8_C == 1 || defined(LIB8_ATTINY)
297 uint8_t j = (((int)i * (
int)scale) >> 8) + ((i&&scale)?1:0);
301 #elif SCALE8_AVRASM == 1
306 " mul %[i], %[scale]\n\t"
309 " subi %[j], 0xFF\n\t"
312 : [i]
"a" (i), [scale]
"a" (scale)
317 #error "No implementation for scale8_video_LEAVING_R1_DIRTY available."
322 #define FORCE_REFERENCE(var) asm volatile( "" : : "r" (var) )
335 void hsv2rgb_rainbow(
const CHSV& hsv, CRGB& rgb)
345 const uint8_t Y1 = 1;
346 const uint8_t Y2 = 0;
350 const uint8_t G2 = 0;
354 const uint8_t Gscale = 0;
357 uint8_t hue = hsv.hue;
358 uint8_t sat = hsv.sat;
359 uint8_t val = hsv.val;
361 uint8_t offset = hue & 0x1F;
364 uint8_t offset8 = offset;
381 uint8_t third = scale8( offset8, (256 / 3));
385 if( ! (hue & 0x80) ) {
387 if( ! (hue & 0x40) ) {
390 if( ! (hue & 0x20) ) {
409 uint8_t twothirds = scale8( offset8, ((256 * 2) / 3));
418 if( ! (hue & 0x20) ) {
423 uint8_t twothirds = scale8( offset8, ((256 * 2) / 3));
424 r =
K171 - twothirds;
447 if( ! (hue & 0x40) ) {
449 if( ! ( hue & 0x20) ) {
455 uint8_t twothirds = scale8( offset8, ((256 * 2) / 3));
456 g =
K171 - twothirds;
469 if( ! (hue & 0x20) ) {
492 if( Gscale ) g = scale8_video_LEAVING_R1_DIRTY( g, Gscale);
498 r = 255; b = 255; g = 255;
501 if( r ) r = scale8_LEAVING_R1_DIRTY( r, sat);
502 if( g ) g = scale8_LEAVING_R1_DIRTY( g, sat);
503 if( b ) b = scale8_LEAVING_R1_DIRTY( b, sat);
506 uint8_t desat = 255 - sat;
507 desat = scale8( desat, desat);
509 uint8_t brightness_floor = desat;
510 r += brightness_floor;
511 g += brightness_floor;
512 b += brightness_floor;
519 val = scale8_video_LEAVING_R1_DIRTY( val, val);
524 if( r ) r = scale8_LEAVING_R1_DIRTY( r, val);
525 if( g ) g = scale8_LEAVING_R1_DIRTY( g, val);
526 if( b ) b = scale8_LEAVING_R1_DIRTY( b, val);