Skip to content

Commit 4610b00

Browse files
finger563Copilot
andauthored
fix(led_strip): Update LedStrip to support DMA (#583)
* fix(led_strip): Update LedStrip to support DMA * Update components/led_strip/include/led_strip.hpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update components/led_strip/include/led_strip.hpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update components/led_strip/include/led_strip.hpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * improve led strip some more (dependent on logger change) * fix sa? * remove unneeded suppression * address comments * fix sa * fix sa * clean up refactor to use span instead of raw pointer+size --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f155f4f commit 4610b00

7 files changed

Lines changed: 214 additions & 42 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
idf_component_register(
22
INCLUDE_DIRS "include"
33
SRC_DIRS "src"
4-
REQUIRES "base_component" "color"
4+
REQUIRES "heap" "base_component" "color"
55
)

components/led_strip/README.md

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ You can use it directly with an SPI driver to talk to APA102 LED strips, or you
88
can use it with a RMT driver (such as the `Rmt` component) to talk to WS2812,
99
WS2811, WS2813, SK6812, etc. LED strips.
1010

11+
## Usage
12+
13+
The Config struct accepts `std::span<const uint8_t>` for start and end frames,
14+
allowing efficient use of memory. For backwards compatibility, you can:
15+
16+
- Use empty frames: `.start_frame = {}`
17+
- Use the predefined `LedStrip::APA102_START_FRAME` vector (auto-converts to span)
18+
- Use `std::array` with CTAD: `.start_frame = std::array{0x00, 0x00, 0x00, 0x00}`
19+
- Pass any existing vector or array that will be converted to a span
20+
1121
## Example
1222

1323
The [example](./example) shows the use of the `LedStrip` class to control a 5x5

components/led_strip/example/main/led_strip_example.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ extern "C" void app_main(void) {
118118
});
119119

120120
//! [led strip ex1]
121-
// create the rmt object
121+
// create the rmt object with DMA enabled for better performance
122122
espp::Rmt rmt(espp::Rmt::Config{
123123
.gpio_num = NEO_BFF_IO,
124+
.clock_src = RMT_CLK_SRC_DEFAULT,
125+
.dma_enabled = true,
126+
.block_size = 1024,
124127
.resolution_hz = SK6805_FREQ_HZ,
128+
.transaction_queue_depth = 2,
125129
.log_level = espp::Logger::Verbosity::INFO,
126130
});
127131

@@ -138,14 +142,16 @@ extern "C" void app_main(void) {
138142
rmt.transmit(data, len);
139143
};
140144

141-
// now create the LedStrip object
145+
// now create the LedStrip object with DMA support
142146
espp::LedStrip led_strip(espp::LedStrip::Config{
143147
.num_leds = NEO_BFF_NUM_LEDS,
144148
.write = neopixel_write,
145149
.send_brightness = false,
146150
.byte_order = espp::LedStrip::ByteOrder::GRB,
147151
.start_frame = {},
148152
.end_frame = {},
153+
.use_dma = true,
154+
.dma_allocation_flags = MALLOC_CAP_DMA,
149155
.log_level = espp::Logger::Verbosity::INFO,
150156
});
151157

0 commit comments

Comments
 (0)