FastLED 3.9.15
Loading...
Searching...
No Matches

◆ buildWave8ExpansionLUT()

FL_OPTIMIZE_FUNCTION Wave8BitExpansionLut fl::buildWave8ExpansionLUT ( const ChipsetTiming & timing)

Build a Wave8BitExpansionLut from chipset timing data.

Converts three-phase LED timing (T1, T2, T3) into a nibble lookup table for 8-pulse-per-bit waveform expansion. The timing is normalized to a period of 1.0 and mapped to 8 pulses per bit (packed into 1 byte).

Never call this from ISR handlers. This is something that should be called before entering ISR context.

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

Definition at line 250 of file wave8.cpp.hpp.

250 {
251 Wave8BitExpansionLut lut;
252
253 // Step 1: Calculate absolute times from ChipsetTiming format
254 // ChipsetTiming.T1 = T0H (high time for bit 0)
255 // ChipsetTiming.T2 = T1H - T0H (ADDITIONAL high time for bit 1)
256 // ChipsetTiming.T3 = T0L (low tail duration)
257 const u32 t0h = timing.T1; // T0H: bit 0 goes LOW here
258 const u32 t1h = timing.T1 + timing.T2; // T1H: bit 1 goes LOW here
259 const u32 period = timing.T1 + timing.T2 + timing.T3; // Total period
260
261 // Step 2: Normalize absolute times
262 const float t0h_norm = static_cast<float>(t0h) / period;
263 const float t1h_norm = static_cast<float>(t1h) / period;
264
265 // Step 3: Convert to pulse counts (fixed 8 pulses per bit)
266 // pulses_bit0: number of HIGH pulses for bit 0 (before it goes LOW at t0h)
267 // pulses_bit1: number of HIGH pulses for bit 1 (before it goes LOW at t1h)
268 u32 pulses_bit0 =
269 static_cast<u32>(t0h_norm * 8.0f + 0.5f); // round
270 u32 pulses_bit1 =
271 static_cast<u32>(t1h_norm * 8.0f + 0.5f); // round
272
273 // Clamp to valid range [0, 8]
274 if (pulses_bit0 > 8)
275 pulses_bit0 = 8;
276 if (pulses_bit1 > 8)
277 pulses_bit1 = 8;
278
279 // Step 4: Generate bit0 and bit1 waveforms (1 byte each, packed format)
280 // Each bit represents one pulse (MSB = first pulse)
281 u8 bit0_waveform = 0;
282 u8 bit1_waveform = 0;
283
284 // Bit 0: Set MSB bits for HIGH pulses
285 for (u32 i = 0; i < pulses_bit0; i++) {
286 bit0_waveform |= (0x80 >> i); // Set bit from MSB
287 }
288
289 // Bit 1: Set MSB bits for HIGH pulses
290 for (u32 i = 0; i < pulses_bit1; i++) {
291 bit1_waveform |= (0x80 >> i); // Set bit from MSB
292 }
293
294 // Step 5: Build LUT for all 16 nibbles
295 for (u8 nibble = 0; nibble < 16; nibble++) {
296 // For each nibble, generate 4 Wave8Bit (one per bit, MSB first)
297 for (int bit_pos = 3; bit_pos >= 0; bit_pos--) {
298 // Extract bit (MSB first: bit 3, 2, 1, 0)
299 const bool bit_set = (nibble >> bit_pos) & 1;
300 const u8 waveform = bit_set ? bit1_waveform : bit0_waveform;
301
302 // Store packed waveform to LUT entry
303 lut.lut[nibble][3 - bit_pos].data = waveform;
304 }
305 }
306
307 return lut;
308}
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.