Skip to content

ESP32 RMT4 driver blocks FastLED.show() - #1858

Closed
Jueff wants to merge 3 commits into
FastLED:masterfrom
Jueff:RMT4DriverChanges
Closed

Jueff wants to merge 3 commits into
FastLED:masterfrom
Jueff:RMT4DriverChanges

Conversation

@Jueff

@Jueff Jueff commented Jan 22, 2025

Copy link
Copy Markdown
Contributor

Fix for #1856, and maybe also for #1438

Changes:
1.) gTxSem is now triggered every time a channel has finished sending data. Adding a waiting controller to the freed channel is no longer done within the interrupt.
Now inside showPixel method a loop takes care about waiting for all controllers to be finished and/or assigning controllers to channel that got free.
2.) I protect access to RMT registers with a lock
3.) because of 1.) methods tx_start, startOnChannel and startNext no longer need the attribute IRAM_ATTR.

@Jueff Jueff changed the title ESP32 RMT4 driver block FastLED.show() ESP32 RMT4 driver blocks FastLED.show() Jan 22, 2025
@zackees

zackees commented Jan 24, 2025

Copy link
Copy Markdown
Member

So, instead of an interrupt, you just busy wait since the driver won't leave the show() block anyway until everything is done being written out?

@Jueff

Jueff commented Jan 24, 2025

Copy link
Copy Markdown
Contributor Author

still using the interrupts.
conde in doneOnChannel

   if (gNumDone == gNumControllers)
    {
        // -- If this is the last controller, signal that we are all done
        if (FASTLED_RMT_BUILTIN_DRIVER)
        {
            xSemaphoreGive(gTX_sem);
        }
        else
        {
            portBASE_TYPE HPTaskAwoken = 0;
            xSemaphoreGiveFromISR(gTX_sem, &HPTaskAwoken);
            if (HPTaskAwoken == pdTRUE)
                portYIELD_FROM_ISR();
        }
    }
    else
    {
        // -- Otherwise, if there are still controllers waiting, then
        //    start the next one on this channel
        if (gNext < gNumControllers)
        {
            startNext(channel);
        }
    }

replaced with

        if (FASTLED_RMT_BUILTIN_DRIVER)
        {
            xSemaphoreGive(gTX_sem);
        }
        else
        {
            portBASE_TYPE HPTaskAwoken = 0;
            xSemaphoreGiveFromISR(gTX_sem, &HPTaskAwoken);
            if (HPTaskAwoken == pdTRUE)
                portYIELD_FROM_ISR();
        }

With this change

  • gTX_sem is triggered every time a channel has finished sending data
  • startNext(channel) is no longer called

and belows loop inside showPixel

  • checks if all controllers are finished
  • call startChannel for waiting controllers
while (gNumDone != gNumControllers)
        {
          bool failed = !xSemaphoreTake(gTX_sem, FASTLED_RMT_MAX_TICKS_FOR_GTX_SEM);
          xSemaphoreGive(gTX_sem);
          if (failed) 
          {
              FASTLED_DEBUG("sending controller data failed: total %d sent: %d", gNumControllers, gNumDone);
              break;
          }
          
          if (gNext < gNumControllers) 
          {
            // find a free channel
            for (int i = 0; i < ESP32RMTController::gMaxChannel; i += ESP32RMTController::gMemBlocks)
            {
              if(gOnChannel[i] == NULL)
              {
                  ESP32RMTController::startNext(i);
                  continue;
              }
            }
          }
        }

@Jueff Jueff closed this Jan 24, 2025
@Jueff

Jueff commented Jan 24, 2025

Copy link
Copy Markdown
Contributor Author

Will place another PR with improved code.

@zackees

zackees commented Jan 24, 2025

Copy link
Copy Markdown
Member

Your previous code was merged. Please feel free to sync and add whatever improvements you have.

Consider me your file pointer with write access to this codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants