FastLED 3.9.15
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 69 of file wave3.cpp.hpp.

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