Freenove / Freenove_WS2812_Lib_for_ESP32

GNU Lesser General Public License v3.0
45 stars 17 forks source link

Multiple setLedCount() function calls uses all RMT channels #10

Closed KarlErikMander closed 3 months ago

KarlErikMander commented 8 months ago

Hello

I have noticed that calling the setLedCount() function multiple times will result in RMT channels all being used up. Example of the problem captured from the Serial console using ESP32 -DCORE_DEBUG_LEVEL=5

[ 25220][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 1 - 1 RAM Blocks - pin 26
[ 26786][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 2 - 1 RAM Blocks - pin 26
[ 27666][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 3 - 1 RAM Blocks - pin 26
[ 28616][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 4 - 1 RAM Blocks - pin 26
[ 29527][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 5 - 1 RAM Blocks - pin 26
[ 30237][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 6 - 1 RAM Blocks - pin 26
[ 31037][D][esp32-hal-rmt.c:615] rmtInit():  -- TX RMT - CH 7 - 1 RAM Blocks - pin 26
[ 31687][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels
[ 32687][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels
[ 33267][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels
[ 33967][E][esp32-hal-rmt.c:578] rmtInit(): rmInit Failed - not enough channels

I found that adding following change to the library fixes it. PS I have no experience with RMT so I dont know if it is the best fix but it works!

void Freenove_ESP32_WS2812::setLedCount(u16 n)
{
    ledCounts = n;
    rmtDeinit(rmt_send); // Deinitialize the RMT channel before begin() initilizes RMT channel again.
    begin();
}

PS your library has alot of functions and I am very happy!!

Zhentao-Lin commented 8 months ago

Thank you for your suggestion, we will verify the problem.