FastLED 3.10.8
Loading...
Searching...
No Matches
ws2816.h
Go to the documentation of this file.
1#pragma once
2
17
18#include "fl/stl/stdint.h"
19#include "fl/stl/noexcept.h"
20#include "fl/stl/array.h"
21#include "fl/stl/pair.h"
22
23namespace fl {
24
25// NOTE: The old loadAndScale_WS2816_HD<RGB_ORDER>() function has been removed.
26// RGB reordering now happens upstream via ScaledPixelIteratorRGB16 adapter.
27// The encoder receives wire-ordered 16-bit RGB data (fl::array<u16, 3>).
28// For backward compatibility, WS2816Controller in chipsets.h still uses the
29// old pattern temporarily - it will be updated to use the new iterator pattern.
30
37inline pair<CRGB, CRGB> packWS2816Pixel(u16 s0, u16 s1, u16 s2) FL_NO_EXCEPT {
38 // Split each 16-bit channel into high/low bytes
39 u8 b0_hi = s0 >> 8;
40 u8 b0_lo = s0 & 0xFF;
41 u8 b1_hi = s1 >> 8;
42 u8 b1_lo = s1 & 0xFF;
43 u8 b2_hi = s2 >> 8;
44 u8 b2_lo = s2 & 0xFF;
45
46 // Pack into two CRGB pixels: [R_hi, R_lo, G_hi] and [G_lo, B_hi, B_lo]
47 return make_pair(
48 CRGB(b0_hi, b0_lo, b1_hi),
49 CRGB(b1_lo, b2_hi, b2_lo)
50 );
51}
52
61template <typename InputIterator, typename OutputIterator>
62void encodeWS2816(InputIterator first, InputIterator last, OutputIterator out) FL_NO_EXCEPT {
63 while (first != last) {
64 // Get 16-bit RGB in wire order (already scaled, color-corrected, brightness-adjusted)
65 const array<u16, 3>& rgb16 = *first;
66 u16 s0 = rgb16[0];
67 u16 s1 = rgb16[1];
68 u16 s2 = rgb16[2];
69
70 // Use the packing helper function
71 pair<CRGB, CRGB> packed = packWS2816Pixel(s0, s1, s2);
72 *out++ = packed.first;
73 *out++ = packed.second;
74
75 ++first;
76 }
77}
78
79} // namespace fl
A fixed-size array implementation similar to std::array.
Definition array.h:27
pair< typename fl::decay< T1 >::type, typename fl::decay< T2 >::type > make_pair(T1 &&t, T2 &&u) FL_NO_EXCEPT
Definition pair.h:97
unsigned char u8
Definition stdint.h:131
fl::CRGB CRGB
Definition video.h:18
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
void encodeWS2816(InputIterator first, InputIterator last, OutputIterator out) FL_NO_EXCEPT
Encode 16-bit RGB pixel data into dual 8-bit RGB format for WS2816.
Definition ws2816.h:62
pair< CRGB, CRGB > packWS2816Pixel(u16 s0, u16 s1, u16 s2) FL_NO_EXCEPT
Pack a single 16-bit RGB pixel into two 8-bit CRGB pixels for WS2816.
Definition ws2816.h:37
Base definition for an LED controller.
T1 first
Definition pair.h:17
T2 second
Definition pair.h:18