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.
250 {
251 Wave8BitExpansionLut lut;
252
253
254
255
256
257 const u32 t0h = timing.
T1;
258 const u32 t1h = timing.
T1 + timing.
T2;
259 const u32 period = timing.
T1 + timing.
T2 + timing.
T3;
260
261
262 const float t0h_norm = static_cast<float>(t0h) / period;
263 const float t1h_norm = static_cast<float>(t1h) / period;
264
265
266
267
268 u32 pulses_bit0 =
269 static_cast<u32>(t0h_norm * 8.0f + 0.5f);
270 u32 pulses_bit1 =
271 static_cast<u32>(t1h_norm * 8.0f + 0.5f);
272
273
274 if (pulses_bit0 > 8)
275 pulses_bit0 = 8;
276 if (pulses_bit1 > 8)
277 pulses_bit1 = 8;
278
279
280
281 u8 bit0_waveform = 0;
282 u8 bit1_waveform = 0;
283
284
285 for (u32 i = 0; i < pulses_bit0; i++) {
286 bit0_waveform |= (0x80 >> i);
287 }
288
289
290 for (u32 i = 0; i < pulses_bit1; i++) {
291 bit1_waveform |= (0x80 >> i);
292 }
293
294
295 for (
u8 nibble = 0; nibble < 16; nibble++) {
296
297 for (int bit_pos = 3; bit_pos >= 0; bit_pos--) {
298
299 const bool bit_set = (nibble >> bit_pos) & 1;
300 const u8 waveform = bit_set ? bit1_waveform : bit0_waveform;
301
302
303 lut.lut[nibble][3 - bit_pos].data = waveform;
304 }
305 }
306
307 return lut;
308}
u32 T2
Additional high time for bit 1 (nanoseconds)
u32 T3
Low tail duration (nanoseconds)
u32 T1
High time for bit 0 (nanoseconds)