Skip to content

Instantly share code, notes, and snippets.

@samguyer
Created May 31, 2018 02:40
Show Gist options
  • Save samguyer/4416ed1eba850d24955603cbd4467415 to your computer and use it in GitHub Desktop.
Save samguyer/4416ed1eba850d24955603cbd4467415 to your computer and use it in GitHub Desktop.
Code to run FastLED on separate core
// ===== FastLED Show task ========================================
// -- The core to run FastLED.show()
#define FASTLED_SHOW_CORE 0
bool gShowOnOtherCore = true;
// -- Task handles for use in the notifications
static TaskHandle_t FastLEDshowTaskHandle = 0;
static TaskHandle_t userTaskHandle = 0;
/** show() for ESP32
Call this function instead of FastLED.show(). It signals core 0 to issue a show,
then waits for a notification that it is done.
*/
void FastLEDshowESP32()
{
if ( ! gShowOnOtherCore) {
FastLED.show();
} else {
if (userTaskHandle == 0) {
//const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
// -- Store the handle of the current task, so that the show task can
// notify it when it's done
userTaskHandle = xTaskGetCurrentTaskHandle();
// -- Trigger the show task
xTaskNotifyGive(FastLEDshowTaskHandle);
// -- Wait to be notified that it's done
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
userTaskHandle = 0;
}
}
}
/** show Task
This function runs on core 0 and just waits for requests to call FastLED.show()
*/
void FastLEDshowTask(void *pvParameters)
{
//const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 500 );
// -- Run forever...
for (;;) {
// -- Wait for the trigger
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
// -- Do the show (synchronously)
uint32_t start = micros();
FastLED.show();
uint32_t finish = micros();
// Serial.println(finish-start);
// -- Notify the calling task
xTaskNotifyGive(userTaskHandle);
}
}
void setup()
{
// -- Create the FastLED show task
xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2048, NULL, 2, &FastLEDshowTaskHandle, FASTLED_SHOW_CORE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment