Convert an unsigned tick delta (free-running 32-bit SCT counter, F_CPU ticks) to nanoseconds. F_CPU is the SCT clock when CLKMODE=0; on LPC845-BRK that is 30_000_000 Hz, giving 33.33 ns per tick. Compute with u64 to avoid mid-multiplication overflow at the long-period extreme: a full 32-bit tick wrap at 30 MHz is ~143 s = 1.43e11 ns, which fits u64 with margin. EdgeTime.ns is a 31-bit bitfield (ma
| 222 | // fits u64 with margin. EdgeTime.ns is a 31-bit bitfield (max ~2.1 s) so |
| 223 | // we saturate above that. |
| 224 | inline fl::u32 ticksToNs(fl::u32 ticks) FL_NOEXCEPT { |
| 225 | constexpr fl::u32 kFcpuMHz = (F_CPU + 500000u) / 1000000u; // 30 on LPC845 |
| 226 | fl::u64 ns64 = (static_cast<fl::u64>(ticks) * 1000u + (kFcpuMHz / 2)) / kFcpuMHz; |
| 227 | if (ns64 > 0x7FFFFFFFull) ns64 = 0x7FFFFFFFull; |
| 228 | return static_cast<fl::u32>(ns64); |
| 229 | } |
| 230 | |
| 231 | #if defined(FASTLED_LPC_RX_SCT_DMA) |
| 232 | // ============================================================================ |