MCPcopy Create free account
hub / github.com/FastLED/FastLED / encodeAPA102

Function encodeAPA102

src/fl/chipsets/encoders/apa102.h:45–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43/// @note APA102 uses BGR wire order: pixel[0]=Blue, pixel[1]=Green, pixel[2]=Red
44template <typename InputIterator, typename OutputIterator>
45void encodeAPA102(InputIterator first, InputIterator last, OutputIterator out,
46 u8 global_brightness = 31) FL_NOEXCEPT {
47 // Clamp brightness to 5-bit range
48 global_brightness = global_brightness & 0x1F;
49
50 // Start frame: 4 bytes of 0x00
51 *out++ = 0x00;
52 *out++ = 0x00;
53 *out++ = 0x00;
54 *out++ = 0x00;
55
56 // LED data: brightness header + BGR (count pixels as we go)
57 size_t num_leds = 0;
58 while (first != last) {
59 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
60 *out++ = 0xE0 | global_brightness;
61 *out++ = pixel[0]; // Index 0 (BGR order: Blue)
62 *out++ = pixel[1]; // Index 1 (BGR order: Green)
63 *out++ = pixel[2]; // Index 2 (BGR order: Red)
64 ++first;
65 ++num_leds;
66 }
67
68 // End frame: ⌈num_leds/32⌉ DWords of 0xFF
69 size_t end_dwords = (num_leds / 32) + 1;
70 for (size_t i = 0; i < end_dwords * 4; i++) {
71 *out++ = 0xFF;
72 }
73}
74
75/// @brief Encode pixel data in APA102 format with per-LED brightness
76/// @tparam InputIterator Iterator yielding fl::array<u8, 3> (3 bytes in wire order)

Callers 2

writeAPA102Method · 0.85
apa102.hppFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected