FastLED 3.10.6
Loading...
Searching...
No Matches

◆ encodeSK9822()

template<typename InputIterator, typename OutputIterator>
void fl::encodeSK9822 ( InputIterator first,
InputIterator last,
OutputIterator out,
u8 global_brightness = 31 )

Encode pixel data in SK9822 format with global brightness.

Template Parameters
InputIteratorIterator yielding fl::array<u8, 3> (3 bytes in wire order)
OutputIteratorOutput iterator accepting uint8_t
Parameters
firstIterator to first pixel
lastIterator past last pixel
outOutput iterator for encoded bytes
global_brightnessGlobal 5-bit brightness (0-31), default 31
Note
SK9822 uses BGR wire order: pixel[0]=Blue, pixel[1]=Green, pixel[2]=Red

Definition at line 37 of file sk9822.h.

38 {
39 // Clamp brightness to 5-bit range
40 global_brightness = global_brightness & 0x1F;
41
42 // Start frame: 4 bytes of 0x00
43 *out++ = 0x00;
44 *out++ = 0x00;
45 *out++ = 0x00;
46 *out++ = 0x00;
47
48 // LED data: brightness header + BGR (count as we go)
49 size_t num_leds = 0;
50 while (first != last) {
51 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
52 *out++ = 0xE0 | global_brightness;
53 *out++ = pixel[0]; // Index 0 (BGR order: Blue)
54 *out++ = pixel[1]; // Index 1 (BGR order: Green)
55 *out++ = pixel[2]; // Index 2 (BGR order: Red)
56 ++first;
57 ++num_leds;
58 }
59
60 // The vendor datasheet requires all ones for the end clocks. These clocks
61 // shift the final LED frame through a long cascade; a zero frame is not a
62 // substitute because it is itself a valid start-frame pattern.
63 size_t end_dwords = (num_leds / 32) + 1;
64 for (size_t i = 0; i < end_dwords * 4; i++) {
65 *out++ = 0xFF;
66 }
67}
A fixed-size array implementation similar to std::array.
Definition array.h:27

References FL_NO_EXCEPT.

Referenced by fl::PixelIterator::writeSK9822().

+ Here is the caller graph for this function: