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