As I was curious about the performance implications of this, I decided to attempt to benchmark the difference. To benchmark it, I added a "busy_wait()" function that performs some simple math in a loop until 40ms has passed and counts how many loops it gets through in that time. The busy wait function begins as soon as the rmt_transmit() function is called. My theory is that if the PIO is having to interrupt the program flow to feed the RMT buffer, that will reduce the number of times the loop executes. I also compared this to an 'unburdened' run where the RMT peripheral is not used at all. What I found is:A channel with DMA attached can offload the CPU by a lot.
- As expected, RMT transmit is not called, the loop executes the most number of times.
- When RMT transmit is called with DMA off, the loop slows down and fewer executions are counted.
- When RMT transmit is called with DMA on, the loop is slightly slower than with it turned off.
I have also tried this experiment:
- With more LEDs enabled than the default 24. I've tried up to 240.
- I've raised and lowered mem_block_symbols
- I've added DMA_ATTR to the buffer I'm passing to rmt_transmit
- I've added IRAM_ATTR to the encoder function