8#if FL_PLATFORM_HAS_LARGE_MEMORY
11#define DEBUG_PRINT(x) do {} while(0)
12#define DEBUG_PRINTLN(x) do {} while(0)
32#include "platforms/is_platform.h"
34#include "platforms/esp/32/feature_flags/enabled.h"
35#if FASTLED_ESP32_HAS_PARLIO
36#include "platforms/esp/32/drivers/parlio/parlio_engine.h"
39#include "driver/parlio_tx.h"
45#include "esp_heap_caps.h"
46#include "freertos/FreeRTOS.h"
47#include "freertos/task.h"
79#if defined(FL_IS_ESP32) && FASTLED_ESP32_HAS_PARLIO
80struct ParlioRawTestState {
84ParlioRawTestState& parlioRawTestState() {
95template <
typename Cfg>
96auto setParlioRawTxEdge(Cfg& cfg,
int) ->
decltype(cfg.shift_edge, void()) {
97 cfg.shift_edge =
static_cast<decltype(cfg.shift_edge)
>(0);
99template <
typename Cfg>
100void setParlioRawTxEdge(Cfg& cfg,
long) {
101 cfg.sample_edge = PARLIO_SAMPLE_EDGE_POS;
124 if (name ==
"UART" || name ==
"LPUART" || name ==
"UART0") {
130 if (name ==
"FLEX_IO" || name ==
"LCD_RGB") {
133 if (name ==
"OBJECT_FLED" || name ==
"PARLIO" || name ==
"LCD_SPI" ||
134 name ==
"LCD_CLOCKLESS" || name ==
"I2S" || name ==
"I2S_SPI") {
142 info.
set(
"bus",
static_cast<int64_t
>(0));
144 info.
set(
"vendor_name", name.
c_str());
145 info.
set(
"device_name", name.
c_str());
146 info.
set(
"which",
static_cast<int64_t
>(0));
147 info.
set(
"is_noop",
false);
148 info.
set(
"notes",
"registered runtime driver");
150 runtime.
set(
"available",
true);
151 runtime.
set(
"initialized",
false);
152 runtime.
set(
"ready",
true);
153 runtime.
set(
"busy",
false);
154 runtime.
set(
"error",
"");
155 info.
set(
"runtime", runtime);
165 remote.bind(
"status", [
this](
const fl::json&
args) -> fl::json {
167 status.set(
"ready",
true);
169 status.set(
"rpcReady",
true);
171 status.set(
"pinTx",
static_cast<int64_t
>(
mState->pin_tx));
172 status.set(
"pinRx",
static_cast<int64_t
>(
mState->pin_rx));
181 remote.bind(
"debugTest", [](
const fl::json&
args) -> fl::json {
194 remote.bind(
"deliberateHang", [
this](
const fl::json&
args) -> fl::json {
196 mState->deliberate_hang_requested =
true;
199 response.set(
"message",
"device will hang after RPC returns; watchdog should reset within configured timeout");
200 response.set(
"hangDelayMs",
static_cast<int64_t
>(200));
201 response.set(
"watchdogExpected",
true);
206 remote.bind(
"drivers", [
this](
const fl::json&
args) -> fl::json {
208 for (fl::size i = 0; i <
mState->drivers_available.size(); i++) {
210 driver.
set(
"name",
mState->drivers_available[i].name.c_str());
211 driver.
set(
"priority",
static_cast<int64_t
>(
mState->drivers_available[i].priority));
212 driver.
set(
"enabled",
mState->drivers_available[i].enabled);
213 fl::json device = autoResearchDeviceJson(
mState->drivers_available[i].name);
214 driver.
set(
"bus_name", device[
"bus_name"]);
215 driver.
set(
"vendor_name", device[
"vendor_name"]);
216 driver.
set(
"device_name", device[
"device_name"]);
217 driver.
set(
"which", device[
"which"]);
218 driver.
set(
"is_noop", device[
"is_noop"]);
219 driver.
set(
"runtime", device[
"runtime"]);
237 remote.bind(
"runSingleTest", [
this](
const fl::json&
args) -> fl::json {
242 mRemote->sendAsyncResponse(
"runSingleTest", result);
244 return fl::json(
nullptr);
252 remote.bind(
"runParallelTest", [
this](
const fl::json&
args) -> fl::json {
255 mRemote->sendAsyncResponse(
"runParallelTest", result);
257 return fl::json(
nullptr);
265 remote.bind(
"ping", [](
const fl::json&
args) -> fl::json {
272 response.set(
"timestamp",
static_cast<int64_t
>(now));
273 response.set(
"uptimeMs",
static_cast<int64_t
>(now));
280 remote.bind(
"testNoSerial", [](
const fl::json&
args) -> fl::json {
283 response.set(
"message",
"RPC works from task context");
288 remote.bind(
"testRpConcurrency", [
this](
const fl::json&
args) -> fl::json {
290 mRemote->sendAsyncResponse(
"testRpConcurrency",
292 return fl::json(
nullptr);
297 remote.bind(
"testRpPioContention", [
this](
const fl::json&
args) -> fl::json {
299 mRemote->sendAsyncResponse(
"testRpPioContention",
301 return fl::json(
nullptr);
306 remote.bind(
"testRpPioParallelResources", [
this](
const fl::json&
args) -> fl::json {
307 mRemote->sendAsyncResponse(
"testRpPioParallelResources",
309 return fl::json(
nullptr);
315#if defined(FL_IS_ESP32) && FASTLED_ESP32_HAS_PARLIO
316 remote.bind(
"parlioMetrics", [](
const fl::json&
args) -> fl::json {
318 const auto m = fl::detail::ParlioEngine::getInstance().getDebugMetrics();
320 response.set(
"isrCount",
static_cast<int64_t
>(m.mIsrCount));
321 response.set(
"txDoneCount",
static_cast<int64_t
>(m.mTxDoneCount));
322 response.set(
"chunksQueued",
static_cast<int64_t
>(m.mChunksQueued));
323 response.set(
"chunksCompleted",
static_cast<int64_t
>(m.mChunksCompleted));
324 response.set(
"bytesTotal",
static_cast<int64_t
>(m.mBytesTotal));
325 response.set(
"bytesTransmitted",
static_cast<int64_t
>(m.mBytesTransmitted));
326 response.set(
"underruns",
static_cast<int64_t
>(m.mUnderrunCount));
327 response.set(
"errorCode",
static_cast<int64_t
>(m.mErrorCode));
328 response.set(
"hardwareIdle", m.mHardwareIdle);
329 response.set(
"transmissionActive", m.mTransmissionActive);
344#if defined(FL_IS_ESP32) && FASTLED_ESP32_HAS_PARLIO
345 remote.bind(
"parlioRawTest", [](
const fl::json&
args) -> fl::json {
356 if (
args.is_object()) {
357 if (
args.contains(
"pin") &&
args[
"pin"].is_int()) pin = (int)
args[
"pin"].as_int().value();
358 if (
args.contains(
"hz") &&
args[
"hz"].is_int()) hz = (int)
args[
"hz"].as_int().value();
359 if (
args.contains(
"width") &&
args[
"width"].is_int())
width = (int)
args[
"width"].as_int().value();
360 if (
args.contains(
"pattern") &&
args[
"pattern"].is_int()) pattern = (int)
args[
"pattern"].as_int().value();
361 if (
args.contains(
"qnb") &&
args[
"qnb"].is_int()) qnb = (int)
args[
"qnb"].as_int().value();
362 if (
args.contains(
"mts") &&
args[
"mts"].is_int()) mts = (int)
args[
"mts"].as_int().value();
363 if (
args.contains(
"burst") &&
args[
"burst"].is_int()) burst = (int)
args[
"burst"].as_int().value();
364 if (
args.contains(
"depth") &&
args[
"depth"].is_int()) depth = (int)
args[
"depth"].as_int().value();
365 if (
args.contains(
"chunks") &&
args[
"chunks"].is_int()) chunks = (int)
args[
"chunks"].as_int().value();
367 parlio_tx_unit_config_t cfg = {};
368 cfg.clk_src = PARLIO_CLK_SRC_DEFAULT;
369 cfg.data_width = (
size_t)width;
370 cfg.clk_in_gpio_num = (gpio_num_t)-1;
371 cfg.clk_out_gpio_num = (gpio_num_t)-1;
372 cfg.valid_gpio_num = (gpio_num_t)-1;
373 cfg.trans_queue_depth = (
size_t)depth;
374 cfg.max_transfer_size = (
size_t)mts;
375 cfg.output_clk_freq_hz = (
uint32_t)hz;
376 setParlioRawTxEdge(cfg, 0);
377 cfg.bit_pack_order = PARLIO_BIT_PACK_ORDER_MSB;
378 if (burst > 0) cfg.dma_burst_size = (
size_t)burst;
379 for (
int i = 0; i < 16; ++i) cfg.data_gpio_nums[i] = (gpio_num_t)-1;
380 cfg.data_gpio_nums[0] = (gpio_num_t)pin;
381 parlio_tx_unit_handle_t unit =
nullptr;
382 esp_err_t err = parlio_new_tx_unit(&cfg, &unit);
385 response.set(
"error", esp_err_to_name(err));
388 err = parlio_tx_unit_enable(unit);
389 uint8_t* buf = parlioRawTestState().buffer;
390 for (
int i = 0; i < 512; ++i) buf[i] = (uint8_t)pattern;
391 parlio_transmit_config_t tcfg = {};
393 tcfg.flags.queue_nonblocking = qnb ? 1 : 0;
398 esp_err_t terr = ESP_OK;
399 const size_t chunk_bytes = 512 / (chunks > 0 ? chunks : 1);
402 for (
int rep = 0; rep < 300 && terr == ESP_OK; ++rep) {
403 for (
int c = 0; c < chunks && terr == ESP_OK; ++c) {
404 terr = parlio_tx_unit_transmit(unit, buf + c * chunk_bytes, chunk_bytes * 8, &tcfg);
406 if (terr == ESP_OK) {
407 (void)parlio_tx_unit_wait_all_done(unit, 100);
409 vTaskDelay(pdMS_TO_TICKS(10));
411 esp_err_t werr = parlio_tx_unit_wait_all_done(unit, 1000);
412 parlio_tx_unit_disable(unit);
413 parlio_del_tx_unit(unit);
415 response.set(
"enableErr", esp_err_to_name(err));
416 response.set(
"txErr", esp_err_to_name(terr));
417 response.set(
"waitErr", esp_err_to_name(werr));
427#if defined(FL_IS_ESP32)
428 remote.bind(
"edgeProbe", [](
const fl::json&
args) -> fl::json {
431 bool passive =
false;
432 if (
args.is_object() &&
args.contains(
"pin") &&
args[
"pin"].is_int()) {
433 pin =
static_cast<int>(
args[
"pin"].as_int().value());
435 if (
args.is_object() &&
args.contains(
"passive") &&
args[
"passive"].is_bool()) {
436 passive =
args[
"passive"].as_bool().value();
440 response.set(
"pin",
static_cast<int64_t
>(pin));
445 remote.bind(
"edgeProbeRead", [](
const fl::json&
args) -> fl::json {
450 response.set(
"edges",
static_cast<int64_t
>(count));
455 for (
int k = 0; k < 8; ++k) live.
push_back(
static_cast<int64_t
>(rl[k]));
461 for (fl::u32 i = 1; i < count && i < 200; ++i) {
462 const fl::u32 prev = stamps[i - 1];
463 const fl::u32
cur = stamps[i];
464 const fl::u32 d_cycles = (
cur & 0x7FFFFFFFu) - (prev & 0x7FFFFFFFu);
465 const fl::u32 level = prev >> 31;
469 e.
set(
"level",
static_cast<int64_t
>(level));
470 e.
set(
"ns",
static_cast<int64_t
>(ns));
481#if defined(FL_IS_ESP32)
482 remote.bind(
"heapCheck", [](
const fl::json&
args) -> fl::json {
484 const bool intact = heap_caps_check_integrity_all(
true);
487 response.set(
"free",
static_cast<int64_t
>(heap_caps_get_free_size(MALLOC_CAP_8BIT)));
488 response.set(
"minFree",
static_cast<int64_t
>(heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT)));
489 response.set(
"largest",
static_cast<int64_t
>(heap_caps_get_largest_free_block(MALLOC_CAP_8BIT)));
490 response.set(
"loopStackHighWater",
static_cast<int64_t
>(uxTaskGetStackHighWaterMark(
nullptr)));
491#if configUSE_TRACE_FACILITY
496 TaskStatus_t statuses[16];
497 const UBaseType_t n = uxTaskGetSystemState(statuses, 16,
nullptr);
499 for (UBaseType_t i = 0; i < n; ++i) {
501 t.set(
"name", statuses[i].pcTaskName);
502 t.set(
"hw",
static_cast<int64_t
>(statuses[i].usStackHighWaterMark));
512 remote.bind(
"peekMem", [](
const fl::json&
args) -> fl::json {
514 if (!
args.is_object() || !
args.contains(
"addr") ||
515 !
args[
"addr"].is_int()) {
517 response.set(
"error",
"InvalidArgs");
518 response.set(
"message",
"Expected {addr: u32, count?: 1-16}");
524 if (
args.contains(
"count") &&
args[
"count"].is_int()) {
525 count =
static_cast<int>(
args[
"count"].as_int().value());
527 if (count < 1 || count > 16 || (addr & 3u) != 0) {
529 response.set(
"error",
"InvalidArgs");
530 response.set(
"message",
"count must be 1-16, addr 4-byte aligned");
535 reinterpret_cast<const volatile uint32_t*
>(addr);
536 for (
int i = 0; i < count; ++i) {
537 values.
push_back(
static_cast<int64_t
>(p[i]));
540 response.set(
"addr",
static_cast<int64_t
>(addr));
const fl::u32 * edgeProbeStamps(fl::u32 &count)
Timestamp buffer: entry = (level_before_edge << 31) | cycle_count.
fl::u32 edgeProbeState()
Probe task progress: 0=not started 1=started 2=triggered 3=sampled.
const fl::u32 * edgeProbeRmtLive()
RMT registers snapshotted at trigger time (INT_RAW, CH2STATUS, CH3STATUS, CH2_RX_CONF1).
fl::u32 edgeProbeSelfTestEdges()
Edges recorded by the arm-time pull-toggle self-test.
void edgeProbeArmMode(int pin, bool passive)
Passive variant: no pinMode/attachInterrupt/pull toggles — only the triggered tight-loop sampler task...
fl::u32 edgeProbeCpuMhz()
CPU frequency in MHz for cycle→ns conversion.
Full PARLIO encode bench for ESP32-P4 (post-byte-LUT, #2526 landed).
PARLIO ISR-streaming functional validation (#2548 deep-dive follow-up).
Issue #2994 repro: compounded per-sequence timing drift vs 3.10.3.
Wave8 expansion micro-benchmark for #2526.
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
fl::unique_ptr< fl::Remote > remote
fl::net::ble — BLE GATT transport layer for JSON-RPC
JSON adapter for bus_info.h.
SPI encoder configuration for clocked LED chipsets.
fl::json runParallelTestImpl(const fl::json &args)
fl::json runSingleTestImpl(const fl::json &args)
void bindSystemMethods(fl::Remote &remote)
fl::shared_ptr< AutoResearchState > mState
fl::unique_ptr< fl::Remote > mRemote
static fl::Watchdog & watchdog() FL_NO_EXCEPT
Access the unified cross-platform watchdog timer.
JSON-RPC server with scheduling support.
static T & instance() FL_NO_EXCEPT
ResetCause lastResetCause() const FL_NO_EXCEPT
const char * c_str() const FL_NO_EXCEPT
void set(const fl::string &key, const json &value) FL_NO_EXCEPT
void push_back(const json &value) FL_NO_EXCEPT
static json object() FL_NO_EXCEPT
static json array() FL_NO_EXCEPT
Task executor — runs registered task runners and manages the run loop.
Platform-abstracted heap memory query functions.
FastLED's Elegant JSON Library: fl::json
fl::json runRpPioParallelResourceTest(const fl::json &args)
Prove PIO0 + PIO1 simultaneous operation at the resource level (#3899).
fl::json runRpPioContentionTest()
Reproduce FastLED#1471's PIO state-machine contention on real RP silicon.
fl::json runRpConcurrencyTest()
Exercise the RP dual-core mutex and semaphore backends from both cores.
constexpr const char * chipName()
Status status() FL_NO_EXCEPT
Current connection state.
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
ResetCause
Cause of the previous boot. Call once early in setup().
expected< T, E > result
Alias for expected (Rust-style naming)
fl::string_view resetCauseName(ResetCause c) FL_NO_EXCEPT
Return a static-lifetime name for c — zero-cost, no allocation.
Promise-based fluent API for FastLED - standalone async primitives.
#define FL_EXTERN_C_BEGIN
Umbrella header for SIMD subsystem.
Unified cross-platform Watchdog Timer API for FastLED.