FastLED 3.10.8
Loading...
Searching...
No Matches

◆ canUseWave3()

FL_OPTIMIZE_FUNCTION bool fl::canUseWave3 ( const ChipsetTiming & timing)

Check if a chipset timing is eligible for wave3 encoding.

Wave3 requires that normalized T0H and T1H round to exactly 1 and 2 ticks (or 2 and 1) out of 3, and both are in [1,2].

Parameters
timingChipsetTiming struct with T1, T2, T3 in nanoseconds
Returns
true if wave3 encoding is possible for this chipset

Definition at line 26 of file wave3.cpp.hpp.

26 {
27 const u32 period = timing.T1 + timing.T2 + timing.T3;
28 if (period == 0) {
29 return false;
30 }
31
32 // T0H = T1, T1H = T1 + T2
33 const float t0h_norm = static_cast<float>(timing.T1) / period;
34 const float t1h_norm = static_cast<float>(timing.T1 + timing.T2) / period;
35
36 // Round to nearest integer tick count out of 3
37 u32 ticks_bit0 = static_cast<u32>(t0h_norm * 3.0f + 0.5f);
38 u32 ticks_bit1 = static_cast<u32>(t1h_norm * 3.0f + 0.5f);
39
40 // Both must be in [1, 2] (need at least 1 high tick and 1 low tick)
41 if (ticks_bit0 < 1 || ticks_bit0 > 2) return false;
42 if (ticks_bit1 < 1 || ticks_bit1 > 2) return false;
43
44 // Must be different (one is 1-tick, other is 2-tick)
45 if (ticks_bit0 == ticks_bit1) return false;
46
47 return true;
48}
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.