Compute how many DMA transfers (= captured edges) have landed in the channel's ring. The CHANNEL.XFERCFG register exposes the live residual count and the CFGVALID flag (UM11029 §16.6 Table 321): While the channel is armed, residual = (N-1) - K where K = writes done On natural completion (K == N), CFGVALID drops to 0 and residual = 0
| 286 | // * While the channel is armed, residual = (N-1) - K where K = writes done |
| 287 | // * On natural completion (K == N), CFGVALID drops to 0 and residual = 0 |
| 288 | inline fl::u32 dmaChannelEdgeCount(fl::u32 ch) FL_NOEXCEPT { |
| 289 | const fl::u32 cfgnow = dma(kDmaChXferCfg(ch)); |
| 290 | const fl::u32 residual = (cfgnow >> 16) & 0x3FFu; |
| 291 | const bool completed = (cfgnow & kXferCfgValid) == 0; |
| 292 | if (completed) { |
| 293 | return static_cast<fl::u32>(kDmaRingSize); |
| 294 | } |
| 295 | if (residual >= kDmaRingSize) { |
| 296 | return 0; |
| 297 | } |
| 298 | return static_cast<fl::u32>(kDmaRingSize) - 1u - residual; |
| 299 | } |
| 300 | #endif // FASTLED_LPC_RX_SCT_DMA |
| 301 | |
| 302 | } // namespace |