FastLED 3.10.8
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 252 of file wave8.cpp.hpp.

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