日本語版 READMEはこちら English specification: SPEC.md
Lightweight helpers for running FreeRTOS tasks from Arduino on ESP32.
- Start tasks with either a C-style function (
start) or a C++ functor/lambda loop (startLoop) - Cooperative stop via
requestStop()andisStopRequested() - Configure stack size, priority, and CPU core per task
- Auto-generated task names when none are provided
- Minimal logging with ESP-IDF
ESP_LOG*macros
- Arduino core for ESP32 3.x
- C++17 capable toolchain (as provided by Arduino-ESP32)
#include <ESP32TaskKit.h>
ESP32TaskKit::Task worker;
void setup() {
Serial.begin(115200);
// Loop task example
worker.startLoop([] {
Serial.println("working...");
delay(100);
return true; // continue
}, ESP32TaskKit::TaskConfig{}, 500); // run every 500 ms
}
void loop() {
// Request stop after 5 seconds
static uint32_t start = millis();
if (worker.isRunning() && millis() - start > 5000) {
worker.requestStop();
}
delay(200);
}ESP32TaskKit::Task worker;
void WorkerTask(void *pv) {
for (;;) {
if (worker.isStopRequested()) {
break; // exit when stop requested
}
// do work
delay(200);
}
}
void setup() {
worker.start(&WorkerTask);
}examples/01_BasicLoop— simplest loop taskexamples/02_CStyleTask— basic C-style taskexamples/03_RequestStop— requestStop with startLoopexamples/04_RequestStopCStyle— requestStop with C-style taskexamples/05_TwoTasks— two loop tasksexamples/06_CustomName— custom task namesexamples/07_InlineConfig— inline TaskConfig usageexamples/08_TaskState— query FreeRTOS task state/info from loopexamples/09_TaskList— dump task list viavTaskListexamples/10_TaskStatusArray— inspect tasks viapxGetTaskStatusArray/uxTaskGetSystemStateexamples/11_RunTimeStats— show runtime statistics viavTaskGetRunTimeStatsexamples/12_TaskSystemState— enumerate tasks viauxTaskGetSystemStateexamples/13_LoopWithArgs— call a helper with GPIO arguments fromstartLoopexamples/14_CStyleArgs— FreeRTOS-stylestartwith task arguments for GPIO toggle
isRunning()reports the library-managed state (not directlyeTaskGetState).- Cooperative stop:
requestStop()only sets a flag; user code should exit loops whenisStopRequested()becomes true. - This library targets Arduino for ESP32 and is not intended for ESP-IDF standalone use.
- ESP32AutoTask — Entry-level helper that runs tasks automatically when you define functions such as
LoopCore0_Low. Great for a few simple tasks; not designed for large task counts. - ESP32TaskKit — This library. Use it when you want explicit FreeRTOS task creation with C++ classes and per-task configuration.
- ESP32SyncKit — C++ wrappers for FreeRTOS Queue / Notify / Semaphore / Mutex. Combine it with any task manager (including this kit) when you need to exchange data or signals between tasks or interrupts.
See LICENSE.