FastLED 3.10.8
Loading...
Searching...
No Matches

◆ buildWave3ExpansionLUT()

FL_OPTIMIZE_FUNCTION Wave3BitExpansionLut fl::buildWave3ExpansionLUT ( const ChipsetTiming & timing)

Build a Wave3BitExpansionLut from chipset timing data.

Converts three-phase LED timing (T1, T2, T3) into a nibble lookup table for 3-tick-per-bit waveform expansion. Each nibble maps to 12 bits.

Parameters
timingChipsetTiming struct containing T1, T2, T3 in nanoseconds
Returns
Populated Wave3BitExpansionLut lookup table (32 bytes)

Definition at line 70 of file wave3.cpp.hpp.

70 {
71 Wave3BitExpansionLut lut;
72
73 const u32 period = timing.T1 + timing.T2 + timing.T3;
74
75 // T0H = T1, T1H = T1 + T2
76 const float t0h_norm = static_cast<float>(timing.T1) / period;
77 const float t1h_norm = static_cast<float>(timing.T1 + timing.T2) / period;
78
79 // Round to nearest integer tick count out of 3
80 u32 ticks_bit0 = static_cast<u32>(t0h_norm * 3.0f + 0.5f);
81 u32 ticks_bit1 = static_cast<u32>(t1h_norm * 3.0f + 0.5f);
82
83 // Clamp to valid range [0, 3]
84 if (ticks_bit0 > 3) ticks_bit0 = 3;
85 if (ticks_bit1 > 3) ticks_bit1 = 3;
86
87 // Generate 3-bit patterns for bit 0 and bit 1
88 // Pattern has ticks_bitN high bits followed by (3 - ticks_bitN) low bits
89 // MSB first within the 3-bit field
90 u8 pattern_bit0 = 0;
91 u8 pattern_bit1 = 0;
92
93 for (u32 i = 0; i < ticks_bit0; i++) {
94 pattern_bit0 |= (0x4 >> i); // Set bits from MSB: 0x4=100, 0x6=110, 0x7=111
95 }
96 for (u32 i = 0; i < ticks_bit1; i++) {
97 pattern_bit1 |= (0x4 >> i);
98 }
99
100 // Build LUT for all 16 nibbles
101 // Each nibble maps to 12 bits (4 LED bits × 3 ticks each)
102 for (u8 nibble = 0; nibble < 16; nibble++) {
103 u16 pattern = 0;
104 // Process bits MSB first (bit 3, 2, 1, 0)
105 for (int bit_pos = 3; bit_pos >= 0; bit_pos--) {
106 bool bit_set = (nibble >> bit_pos) & 1;
107 u8 tick_pattern = bit_set ? pattern_bit1 : pattern_bit0;
108 pattern = (pattern << 3) | (tick_pattern & 0x7);
109 }
110 lut.lut[nibble] = pattern;
111 }
112
113 return lut;
114}
unsigned char u8
Definition stdint.h:131
u32 T2
Additional high time for bit 1 (nanoseconds)
Definition led_timing.h:88
u32 T3
Low tail duration (nanoseconds)
Definition led_timing.h:89
u32 T1
High time for bit 0 (nanoseconds)
Definition led_timing.h:87

References FL_NO_EXCEPT.