Skip to content

Commit 402863b

Browse files
zackeessuda-morris
authored andcommitted
feat(led_strip): update rmt example to guide the use of DMA
1 parent f72e811 commit 402863b

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

led_strip/examples/led_strip_rmt_ws2812/main/led_strip_rmt_ws2812_main.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,23 @@
1010
#include "esp_log.h"
1111
#include "esp_err.h"
1212

13-
// GPIO assignment
14-
#define LED_STRIP_GPIO_PIN 2
13+
// Set to 1 to use DMA for driving the LED strip, 0 otherwise
14+
// Please note the RMT DMA feature is only available on chips e.g. ESP32-S3/P4
15+
#define LED_STRIP_USE_DMA 0
16+
17+
#if LED_STRIP_USE_DMA
18+
// Numbers of the LED in the strip
19+
#define LED_STRIP_LED_COUNT 256
20+
#define LED_STRIP_MEMORY_BLOCK_WORDS 1024 // this determines the DMA block size
21+
#else
1522
// Numbers of the LED in the strip
1623
#define LED_STRIP_LED_COUNT 24
24+
#define LED_STRIP_MEMORY_BLOCK_WORDS 0 // let the driver choose a proper memory block size automatically
25+
#endif // LED_STRIP_USE_DMA
26+
27+
// GPIO assignment
28+
#define LED_STRIP_GPIO_PIN 2
29+
1730
// 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
1831
#define LED_STRIP_RMT_RES_HZ (10 * 1000 * 1000)
1932

@@ -36,9 +49,9 @@ led_strip_handle_t configure_led(void)
3649
led_strip_rmt_config_t rmt_config = {
3750
.clk_src = RMT_CLK_SRC_DEFAULT, // different clock source can lead to different power consumption
3851
.resolution_hz = LED_STRIP_RMT_RES_HZ, // RMT counter clock frequency
39-
.mem_block_symbols = 0, // the memory size of each RMT channel, 0 lets the driver decide.
52+
.mem_block_symbols = LED_STRIP_MEMORY_BLOCK_WORDS, // the memory block size used by the RMT channel
4053
.flags = {
41-
.with_dma = false, // DMA feature is available on chips like ESP32-S3/P4
54+
.with_dma = LED_STRIP_USE_DMA, // Using DMA can improve performance when driving more LEDs
4255
}
4356
};
4457

0 commit comments

Comments
 (0)