FastLED 3.10.10
Loading...
Searching...
No Matches
AutoResearchRemoteDriverMethods.cpp
Go to the documentation of this file.
1// LED driver test/benchmark RPC bindings. Today: Teensy 4.x FlexIO RX
2// validation (flexioRxBenchmark, flexioObjectFledTest, flexioRxLoopbackPing).
3// Platform-specific driver tests for other MCUs land here in the future —
4// the RPC layer is platform-agnostic; #if guards inside each binding gate
5// the platform-specific bodies.
6// Extracted from AutoResearchRemote.cpp as part of #3132 / meta #3127.
7
9#if FL_PLATFORM_HAS_LARGE_MEMORY
10
11// Legacy debug macros (no-ops, kept for debugTest RPC function)
12#define DEBUG_PRINT(x) do {} while(0)
13#define DEBUG_PRINTLN(x) do {} while(0)
14
15#include "AutoResearchRemote.h"
16#include "AutoResearchBle.h"
17#include "AutoResearchNet.h"
18#include "AutoResearchOta.h"
20#include "fl/system/heap.h"
21#include "Common.h"
22#include "AutoResearchTest.h"
23#include "AutoResearchHelpers.h"
24#include "fl/stl/sstream.h"
25#include "fl/stl/unique_ptr.h"
26#include "fl/stl/optional.h"
27#include "fl/stl/json.h"
28#include "fl/task/task.h"
29#include "fl/task/executor.h"
31#include "fl/stl/atomic.h"
32#include "fl/task/promise.h"
33#include "fl/math/simd.h"
34#include "AutoResearchSimd.h"
41#include "AutoResearchTimingDrift.h" // timingDriftTest RPC (#2994 repro)
42#include "fl/chipsets/spi.h"
43#include "fl/channels/config.h"
44#include "fl/stl/span.h"
45#include "fl/stl/singleton.h"
46#include <Arduino.h>
47#if defined(FL_IS_ESP32) // ok platform specific - fl::thread is synchronous on ESP32; this ABI regression requires competing FreeRTOS tasks
48#include "freertos/FreeRTOS.h" // ok platform specific - exercise the ESP-IDF local-static guard with real tasks
49#include "freertos/semphr.h" // ok platform specific - coordinate the two-task ABI regression without racy volatile counters
50#include "freertos/task.h" // ok platform specific - fl::thread does not launch tasks on this target
51#endif
52#if defined(FL_IS_ESP32) // ok platform specific - the explicit ESP32 SPI host probe needs this chip's peripheral count
53#include "platforms/esp/32/drivers/spi/spi_hw_base.h" // ok platform specific - FASTLED_ESP32_HAS_SPI3 rejects one-host chips
54#endif
55
56// #3428: FlexIO2 SPI mode bring-up smoke test (`flexioSpiSelfTest` RPC).
57// The header is Teensy 4.x-gated, but #include is safe on any platform
58// because all declarations sit inside `#if defined(FL_IS_TEENSY_4X)`.
59#include "platforms/arm/teensy/teensy4_common/drivers/flexio/flexio_spi_mode.h"
60
61// #3428: ObjectFLED DMA-bit-banged SPI mode bring-up smoke test
62// (`objectfledSpiSelfTest` RPC). Same Teensy 4.x-gating pattern.
63#include "platforms/arm/teensy/teensy4_common/drivers/objectfled/objectfled_spi_mode.h"
64
65#include "fl/net/ble.h"
66
67#include "fl/codec/h264.h"
68#include "fl/codec/mp4_parser.h"
70#include "fl/fx/frame.h"
71
72namespace {
73
74#if defined(FL_IS_ESP32) // ok platform specific - this regression checks ESP-IDF's process-wide C++ ABI guard implementation
75class ProbeSemaphore {
76public:
77 ProbeSemaphore() = default;
78 ~ProbeSemaphore() { reset(nullptr); }
79 ProbeSemaphore(const ProbeSemaphore&) = delete;
80 ProbeSemaphore& operator=(const ProbeSemaphore&) = delete;
81
82 SemaphoreHandle_t get() const { return mHandle; } // ok platform specific - core synchronization cannot supply handles for the real FreeRTOS tasks in this SDK guard probe
83 explicit operator bool() const { return mHandle != nullptr; }
84 void reset(SemaphoreHandle_t handle) { // ok platform specific - core synchronization cannot own the SDK semaphore used by this real FreeRTOS guard probe
85 if (mHandle) {
86 vSemaphoreDelete(mHandle); // ok platform specific - core synchronization has no ownership API for the real FreeRTOS semaphore required by this SDK guard probe
87 }
88 mHandle = handle;
89 }
90
91private:
92 SemaphoreHandle_t mHandle = nullptr; // ok platform specific - core synchronization cannot represent this real FreeRTOS semaphore used by the SDK guard probe
93};
94
95struct StaticInitProbe {
96 fl::atomic<int> constructions{0};
97 fl::atomic<int> contenders{0};
98 fl::atomic<bool> overlapped{false};
99 fl::atomic<TaskHandle_t> contender{nullptr}; // ok platform specific - the probe observes the SDK worker's actual blocked state
100 ProbeSemaphore entered;
101 ProbeSemaphore completed;
102 bool used = false;
103};
104
105// Tasks retain this state until completion, including on timeout.
106StaticInitProbe staticInitProbe;
107
108struct SlowStatic {
109 SlowStatic() {
110 const bool owner = staticInitProbe.constructions.fetch_add(1) == 0;
111 xSemaphoreGive(staticInitProbe.entered.get()); // ok platform specific - synchronize actual SDK tasks; fl::thread is not concurrent on ESP32
112 if (!owner) {
113 // Make duplicate initialization observable in the failing build.
114 vTaskDelay(pdMS_TO_TICKS(200)); // ok platform specific - require an actual FreeRTOS-blocked duplicate initializer for observation
115 return;
116 }
117 const TickType_t wait_start = xTaskGetTickCount(); // ok platform specific - measure the same scheduler clock used by the guard-state polling delay
118 const TickType_t wait_ticks = pdMS_TO_TICKS(2000); // ok platform specific - bound the real SDK contention wait in scheduler ticks
119 do {
120 const TaskHandle_t contender = staticInitProbe.contender.load(fl::memory_order_acquire); // ok platform specific - retain the SDK task identity through the guard-state sample
121 // Between arrival and completion, the worker can block only in
122 // this guard or this constructor's delay. Finished workers suspend
123 // rather than delete themselves, so the sampled handle stays valid.
124 const bool blocked = contender && eTaskGetState(contender) == eBlocked; // ok platform specific - no core API observes ESP-IDF's guard waiter state
125 if (staticInitProbe.contenders.load(fl::memory_order_acquire) == 2 && blocked) {
126 staticInitProbe.overlapped.store(true, fl::memory_order_release);
127 return;
128 }
129 vTaskDelay(1); // ok platform specific - yield to the actual SDK contender until guard entry is observed
130 } while (static_cast<TickType_t>(xTaskGetTickCount() - wait_start) < wait_ticks); // ok platform specific - scheduler-tick subtraction handles tick-counter wrap
131 }
132};
133
134SlowStatic& contendedStatic() {
135 static SlowStatic instance;
136 return instance;
137}
138
139void staticInitWorker(void*) {
140 staticInitProbe.contenders.fetch_add(1);
141 (void)contendedStatic();
142 xSemaphoreGive(staticInitProbe.completed.get()); // ok platform specific - synchronize actual SDK tasks; fl::thread is not concurrent on ESP32
143 // Retain the TCB until the RPC has sampled it and received both completions.
144 for (;;) {
145 vTaskSuspend(nullptr); // ok platform specific - keep the SDK task handle valid until the probe's explicit teardown
146 }
147}
148
149fl::json staticInitTest() {
151 result.set("success", false);
152 if (staticInitProbe.used) {
153 result.set("error", "ResetBoardBeforeStaticInitTest");
154 return result;
155 }
156 staticInitProbe.used = true;
157 staticInitProbe.entered.reset(xSemaphoreCreateBinary()); // ok platform specific - synchronize actual SDK tasks; fl::thread is not concurrent on ESP32
158 staticInitProbe.completed.reset(xSemaphoreCreateCounting(2, 0)); // ok platform specific - synchronize actual SDK tasks; fl::thread is not concurrent on ESP32
159 if (!staticInitProbe.entered || !staticInitProbe.completed) {
160 staticInitProbe.entered.reset(nullptr);
161 staticInitProbe.completed.reset(nullptr);
162 result.set("error", "SemaphoreAllocationFailed");
163 return result;
164 }
165 TaskHandle_t owner_task = nullptr; // ok platform specific - this RPC owns the SDK worker until explicit teardown
166 TaskHandle_t contender_task = nullptr; // ok platform specific - this RPC owns the SDK worker until explicit teardown
167 const bool owner_created = xTaskCreate(staticInitWorker, "static-owner", 4096, // ok platform specific - fl::thread has no concurrent ESP32 implementation
168 nullptr, 1, &owner_task) == pdPASS;
169 const bool entered = owner_created &&
170 xSemaphoreTake(staticInitProbe.entered.get(), pdMS_TO_TICKS(2000)) == pdTRUE; // ok platform specific - await the real SDK constructor before creating its contender
171 const bool contender_created = entered &&
172 xTaskCreate(staticInitWorker, "static-contender", 4096, // ok platform specific - fl::thread has no concurrent ESP32 implementation
173 nullptr, 1, &contender_task) == pdPASS;
174 staticInitProbe.contender.store(contender_task, fl::memory_order_release);
175 int completed = 0;
176 const int tasks = (owner_created ? 1 : 0) + (contender_created ? 1 : 0);
177 for (int i = 0; i < tasks; ++i) {
178 if (xSemaphoreTake(staticInitProbe.completed.get(), pdMS_TO_TICKS(3000)) == pdTRUE) { // ok platform specific - join actual SDK workers without a concurrent fl::thread backend
179 ++completed;
180 }
181 }
182 bool workers_suspended = false;
183 if (completed == tasks) {
184 // On SMP, completion can wake this RPC before a worker reaches its
185 // suspension. Wait a bounded time before deleting tasks or semaphores.
186 for (int attempt = 0; attempt < 100; ++attempt) {
187 const bool owner_suspended = !owner_task || eTaskGetState(owner_task) == eSuspended; // ok platform specific - no core API joins actual ESP32 FreeRTOS workers
188 const bool contender_suspended = !contender_task || eTaskGetState(contender_task) == eSuspended; // ok platform specific - no core API joins actual ESP32 FreeRTOS workers
189 if (owner_suspended && contender_suspended) {
190 workers_suspended = true;
191 break;
192 }
193 vTaskDelay(1); // ok platform specific - let the SDK workers quiesce before their handles are reclaimed
194 }
195 }
196 const int constructions = staticInitProbe.constructions.load(fl::memory_order_acquire);
197 const int contenders = staticInitProbe.contenders.load(fl::memory_order_acquire);
198 const bool overlapped = staticInitProbe.overlapped.load(fl::memory_order_acquire);
199 result.set("constructorEntered", entered);
200 result.set("constructions", constructions);
201 result.set("contenders", contenders);
202 result.set("completed", completed);
203 result.set("overlapped", overlapped);
204 result.set("workersSuspended", workers_suspended);
205 result.set("success", entered && completed == 2 && contenders == 2 &&
206 overlapped && constructions == 1 && workers_suspended);
207 // Keep handles alive unless every worker is suspended. This probe runs
208 // once per boot, so a timeout cannot accumulate allocations.
209 if (workers_suspended) {
210 staticInitProbe.contender.store(nullptr, fl::memory_order_release);
211 if (owner_task) {
212 vTaskDelete(owner_task); // ok platform specific - reclaim the quiescent SDK worker used to exercise ESP-IDF guards
213 }
214 if (contender_task) {
215 vTaskDelete(contender_task); // ok platform specific - reclaim the quiescent SDK worker used to exercise ESP-IDF guards
216 }
217 staticInitProbe.entered.reset(nullptr);
218 staticInitProbe.completed.reset(nullptr);
219 }
220 return result;
221}
222#endif
223
224#if defined(FL_IS_TEENSY_4X)
225struct FlexIoObjectFledState {
226 CRGB leds[100];
227};
228
229FlexIoObjectFledState& flexIoObjectFledState() {
231}
232#endif
233
234} // namespace
235
236#if defined(FL_AUTORESEARCH_MEMORY_BENCH)
237void bindMemoryBench(fl::Remote& remote);
238#endif
239
241 remote.bind("staticInitTest", [](const fl::json&) -> fl::json {
242#if defined(FL_IS_ESP32) // ok platform specific - fl::thread has no concurrent ESP32 implementation; directly test the vendor ABI
243 return staticInitTest();
244#else
245 fl::json result = fl::json::object();
246 result.set("success", false);
247 result.set("error", "Esp32Required");
248 return result;
249#endif
250 });
251#if defined(FL_AUTORESEARCH_MEMORY_BENCH)
252 bindMemoryBench(remote);
253#endif
254 // One physical data jumper checks either SPI host while a second APA102
255 // channel exercises the registration-order interaction from #4864.
256 remote.bind("dualSpiHostLoopback", [this](const fl::json& args) -> fl::json {
257 fl::json response = fl::json::object();
258#if !defined(FL_IS_ESP32) || !FASTLED_ESP32_HAS_SPI3 // ok platform specific - this probe requires two physical ESP32 SPI hosts
259 (void)this;
260 (void)args;
261 response.set("success", false);
262 response.set("error", "TwoSpiHostsUnavailable");
263 return response;
264#else
265 if (!args.is_object() || !args.contains("activeHost") ||
266 !args["activeHost"].is_int()) {
267 response.set("success", false);
268 response.set("error", "ExpectedActiveHost");
269 return response;
270 }
271 const int active_host = static_cast<int>(args["activeHost"].as_int().value());
272 if (active_host != 2 && active_host != 3) {
273 response.set("success", false);
274 response.set("error", "InvalidActiveHost");
275 return response;
276 }
277 const bool dummy_first = args.contains("dummyFirst") &&
278 args["dummyFirst"].is_bool() && args["dummyFirst"].as_bool().value();
279 constexpr int kLedCount = 100;
280 static bool already_run = false;
281 if (already_run) {
282 response.set("success", false);
283 response.set("error", "ResetBoardBeforeNextOrder");
284 return response;
285 }
286 already_run = true;
287 static CRGB active_leds[kLedCount];
288 static CRGB dummy_leds[kLedCount];
289 for (int i = 0; i < kLedCount; ++i) {
290 active_leds[i] = CRGB(static_cast<uint8_t>(i * 19 + 1),
291 static_cast<uint8_t>(i * 13 + 2),
292 static_cast<uint8_t>(i * 7 + 3));
293 dummy_leds[i] = CRGB::Black;
294 }
295 const auto register_active = [&]() {
296 FastLED.addLeds<APA102, 1, 3, RGB, DATA_RATE_KHZ(2400)>( // ok platform specific - test the public explicit ESP32 host API
297 active_leds, kLedCount, active_host == 2
298 ? fl::Esp32SpiBus::HOST2 : fl::Esp32SpiBus::HOST3); // ok platform specific - select the measured physical host
299 };
300 const auto register_dummy = [&]() {
301 FastLED.addLeds<APA102, 4, 5, RGB, DATA_RATE_KHZ(2400)>( // ok platform specific - register the other host as the dummy
302 dummy_leds, kLedCount, active_host == 2
303 ? fl::Esp32SpiBus::HOST3 : fl::Esp32SpiBus::HOST2); // ok platform specific - choose the host opposite the measured output
304 };
305 if (dummy_first) {
306 register_dummy();
307 register_active();
308 } else {
309 register_active();
310 register_dummy();
311 }
313 FastLED.show();
314 const bool primed = FastLED.wait(1000);
315 size_t captured = 0;
316 fl::RunResult diagnostics;
317 if (primed) {
318 captured = capture(mState->rx_channel, mState->rx_buffer,
319 kLedCount * 3, 1,
321 "SPI_UNIFIED", &diagnostics);
322 }
323 response.set("activeHost", active_host);
324 response.set("dummyFirst", dummy_first);
325 response.set("genericDecodedBytes", static_cast<int>(captured));
326 response.set("primed", primed);
327 response.set("rxWaitResult", diagnostics.captureWaitResult);
328 response.set("rxEdges", diagnostics.rawEdgesAfterWait);
329 response.set("rxBeginError", diagnostics.rxBeginError.c_str());
330 fl::EdgeTime edge_samples[256];
331 const size_t edge_count = mState->rx_channel->getRawEdgeTimes(
332 fl::span<fl::EdgeTime>(edge_samples, 256), 0);
333 response.set("rawEdges", static_cast<int>(edge_count));
334 constexpr size_t kVerifiedLeds = 8;
335 uint8_t first_bytes[kVerifiedLeds * 4] = {};
336 size_t bit_count = 0;
337 for (size_t i = 0; i < edge_count && bit_count < sizeof(first_bytes) * 8; ++i) {
338 const size_t bits = (edge_samples[i].ns + 208) / 416;
339 for (size_t j = 0; j < bits && bit_count < sizeof(first_bytes) * 8; ++j, ++bit_count) {
340 if (edge_samples[i].high) {
341 first_bytes[bit_count / 8] |=
342 static_cast<uint8_t>(1u << (7 - bit_count % 8));
343 }
344 }
345 }
346 int wire_mismatches = 0;
347 if (bit_count < sizeof(first_bytes) * 8) {
348 wire_mismatches = static_cast<int>(sizeof(first_bytes) * 8 - bit_count);
349 } else {
350 for (size_t i = 0; i < kVerifiedLeds; ++i) {
351 const size_t offset = i * 4;
352 wire_mismatches += first_bytes[offset] != 0xFF;
353 wire_mismatches += first_bytes[offset + 1] != active_leds[i].r;
354 wire_mismatches += first_bytes[offset + 2] != active_leds[i].g;
355 wire_mismatches += first_bytes[offset + 3] != active_leds[i].b;
356 }
357 }
358 response.set("verifiedLeds", static_cast<int>(kVerifiedLeds));
359 response.set("wireBits", static_cast<int>(bit_count));
360 response.set("wireMismatches", wire_mismatches);
361 response.set("first0", first_bytes[0]);
362 response.set("first1", first_bytes[1]);
363 response.set("first2", first_bytes[2]);
364 response.set("first3", first_bytes[3]);
365 response.set("first4", first_bytes[4]);
366 response.set("first5", first_bytes[5]);
367 response.set("first6", first_bytes[6]);
368 response.set("first7", first_bytes[7]);
369 if (edge_count >= 4) {
370 response.set("edge0Ns", static_cast<int>(edge_samples[0].ns));
371 response.set("edge1Ns", static_cast<int>(edge_samples[1].ns));
372 response.set("edge2Ns", static_cast<int>(edge_samples[2].ns));
373 response.set("edge3Ns", static_cast<int>(edge_samples[3].ns));
374 response.set("edge0High", edge_samples[0].high);
375 response.set("edge1High", edge_samples[1].high);
376 }
378 fl::string::from_literal("SPI_UNIFIED"));
379 const bool native_driver_found = static_cast<bool>(driver);
380 const bool native_driver_enabled = driver &&
382 response.set("nativeDriverFound", native_driver_found);
383 response.set("nativeDriverEnabled", native_driver_enabled);
384 response.set("success", primed && native_driver_enabled && wire_mismatches == 0);
385 return response;
386#endif
387 });
388 // Register "softSpiClockLoopback" — measures the software SPI clock rate
389 // (#5124). Build with FASTLED_FORCE_SOFTWARE_SPI; jumper GPIO 0 (APA102
390 // clock) to GPIO 1 (RX). Data goes to GPIO 2, unmeasured. Reports clock
391 // high/low widths from raw RX edges, skipping the first edge.
392 remote.bind("softSpiClockLoopback", [this](const fl::json& args) -> fl::json {
393 (void)args;
394 fl::json response = fl::json::object();
395 constexpr int kLedCount = 16;
396 static bool already_run = false;
397 if (already_run) {
398 response.set("success", false);
399 response.set("error", "ResetBoardBeforeNextRun");
400 return response;
401 }
402 already_run = true;
403#if !defined(FL_IS_ESP32) // ok platform specific - SPIOutput is the ESP32 SPIBusManager proxy here
404 (void)this;
405 response.set("success", false);
406 response.set("error", "Esp32Only");
407 return response;
408#else
409 // addLeds<APA102> goes through the Channels SPI driver, which never
410 // reaches SPIBusManager's software writer, so drive the legacy
411 // SPIOutput proxy directly: under FASTLED_FORCE_SOFTWARE_SPI it flushes
412 // through SPIBusManager::softwareSPIWrite.
413 struct SoftSpiProbe : public CPixelLEDController<RGB> {
414 fl::SPIOutput<2, 0, 250000> spi;
415 void init() FL_NO_EXCEPT override { spi.init(); }
416 void showPixels(PixelController<RGB>& pixels) FL_NO_EXCEPT override {
417 spi.select();
418 for (int i = 0; i < pixels.size() * 4; ++i) {
419 spi.writeByte(0x55);
420 }
421 spi.finalizeTransmission();
422 spi.release();
423 }
424 };
425 static SoftSpiProbe probe;
426 static CRGB leds[kLedCount];
427 FastLED.addLeds(&probe, leds, kLedCount);
428 fl::RunResult diagnostics;
429 capture(mState->rx_channel, mState->rx_buffer, kLedCount * 4, 1,
431 "SOFT_SPI_CLOCK", &diagnostics);
432 fl::SPIBusManager& manager = fl::getSPIBusManager();
433 response.set("buses", static_cast<int>(manager.getNumBuses()));
434 if (const fl::SPIBusInfo* bus = manager.getBusInfo(0)) {
435 response.set("busType", static_cast<int>(bus->bus_type));
436 response.set("busDevices", static_cast<int>(bus->num_devices));
437 response.set("busInitialized", bus->is_initialized);
438 }
439 response.set("rxBeginError", diagnostics.rxBeginError.c_str());
440 response.set("rxWaitResult", diagnostics.captureWaitResult);
441 fl::EdgeTime edges[256];
442 const size_t edge_count = mState->rx_channel->getRawEdgeTimes(
443 fl::span<fl::EdgeTime>(edges, 256), 0);
444 u32 high_sum = 0, low_sum = 0, high_n = 0, low_n = 0;
445 u32 high_min = 0xFFFFFFFFu, low_min = 0xFFFFFFFFu;
446 for (size_t i = 1; i < edge_count; ++i) {
447 const u32 ns = edges[i].ns;
448 if (ns > 100000u) {
449 continue; // frame gap, not a clock half-period
450 }
451 if (edges[i].high) {
452 high_sum += ns; ++high_n; high_min = fl::min(high_min, ns);
453 } else {
454 low_sum += ns; ++low_n; low_min = fl::min(low_min, ns);
455 }
456 }
457 const u32 high_avg = high_n ? high_sum / high_n : 0;
458 const u32 low_avg = low_n ? low_sum / low_n : 0;
459 const u32 period = high_avg + low_avg;
460 // Only a successful RX begin and wait with real clock edges counts.
461 const bool primed = diagnostics.rxBeginError.empty() &&
462 diagnostics.captureWaitResult == 0 && high_n >= 8 && low_n >= 8;
463 response.set("primed", primed);
464 response.set("rawEdges", static_cast<int>(edge_count));
465 response.set("highAvgNs", static_cast<int>(high_avg));
466 response.set("lowAvgNs", static_cast<int>(low_avg));
467 response.set("highMinNs", static_cast<int>(high_n ? high_min : 0));
468 response.set("lowMinNs", static_cast<int>(low_n ? low_min : 0));
469 response.set("periodNs", static_cast<int>(period));
470 response.set("measuredKhz", static_cast<int>(period ? 1000000u / period : 0));
471 response.set("requestedKhz", 250);
472 // Pass when the 250 kHz clock is no faster than requested (10% tolerance).
473 response.set("success", primed && period >= 3600u);
474 return response;
475#endif
476 });
477 // Register "flexioRxBenchmark" — square-wave validation for the new
478 // FlexIO RX backend (Phase 2 of FastLED#2764).
479 //
480 // Drives `tx_pin` with a `frequency_hz` square wave via the Teensy core's
481 // `analogWriteFrequency` PWM, configures an RxChannel on `rx_pin` using
482 // `RxBackend::FLEXIO`, captures for `duration_ms`, and reports per-period
483 // statistics: count, mean ns, σ ns, min ns, max ns.
484 //
485 // Args (positional, all optional with defaults):
486 // {
487 // "frequency_hz": int = 1000,
488 // "duration_ms": int = 100,
489 // "tx_pin": int = 3, // matches GPIO 3↔4 jumper
490 // "rx_pin": int = 4
491 // }
492 //
493 // Teensy-4-only because FLEXIO1 is iMXRT1062-specific. Other platforms
494 // get a clean "not supported" response so the RPC harness can still
495 // round-trip.
496 remote.bind("flexioRxBenchmark", [](const fl::json& args) -> fl::json {
497 fl::json response = fl::json::object();
498#if !defined(FL_IS_TEENSY_4X)
499 (void)args;
500 response.set("success", false);
501 response.set("error", "PlatformNotSupported");
502 response.set("message",
503 "flexioRxBenchmark is Teensy 4.x-only (FLEXIO1 capture).");
504 return response;
505#else
506 // Parse args
507 int frequency_hz = 1000;
508 int duration_ms = 100;
509 int tx_pin = 3;
510 int rx_pin = 4;
511 if (args.is_array() && args.size() >= 1 && args[0].is_object()) {
512 fl::json cfg = args[0];
513 if (cfg.contains("frequency_hz") && cfg["frequency_hz"].is_int()) {
514 frequency_hz = static_cast<int>(cfg["frequency_hz"].as_int().value());
515 }
516 if (cfg.contains("duration_ms") && cfg["duration_ms"].is_int()) {
517 duration_ms = static_cast<int>(cfg["duration_ms"].as_int().value());
518 }
519 if (cfg.contains("tx_pin") && cfg["tx_pin"].is_int()) {
520 tx_pin = static_cast<int>(cfg["tx_pin"].as_int().value());
521 }
522 if (cfg.contains("rx_pin") && cfg["rx_pin"].is_int()) {
523 rx_pin = static_cast<int>(cfg["rx_pin"].as_int().value());
524 }
525 }
526 if (frequency_hz < 1 || frequency_hz > 5000000 ||
527 duration_ms < 1 || duration_ms > 5000) {
528 response.set("success", false);
529 response.set("error", "InvalidArgs");
530 response.set("message",
531 "frequency_hz in [1, 5_000_000]; duration_ms in [1, 5000].");
532 return response;
533 }
534
535 // 1. Drive the TX pin with a square wave.
536 analogWriteFrequency(tx_pin, (float)frequency_hz);
537 analogWrite(tx_pin, 128); // 50% duty
538
539 // 2. Create the FlexIO RX channel.
540 // Width budget — size the edge buffer for the actual capture window:
541 // expected_edges = 2 * frequency_hz * duration_ms / 1000 (transitions)
542 // target = expected_edges * 1.5 (50% headroom for jitter/skew)
543 // Clamped to [1024, 16384] so the DMA buffer stays reasonable and
544 // matches the FlexIO RX driver's internal cap.
545 fl::RxChannelConfig rx_cfg(rx_pin, fl::RxBackend::FLEXIO);
546 const fl::u64 expected_edges =
547 (fl::u64)2 * (fl::u64)frequency_hz * (fl::u64)duration_ms / 1000ULL;
548 fl::u64 target = expected_edges + expected_edges / 2; // +50%
549 if (target < 1024ULL) target = 1024ULL;
550 if (target > 16384ULL) target = 16384ULL;
551 rx_cfg.edge_capacity = (size_t)target;
552 rx_cfg.start_low = false; // PWM output idles in either state, just track transitions
553 auto rx_channel = fl::RxChannel::create(rx_cfg);
554 if (!rx_channel) {
555 analogWrite(tx_pin, 0);
556 response.set("success", false);
557 response.set("error", "RxCreateFailed");
558 response.set("message",
559 "Failed to create FlexIO RX channel on pin (no FLEXIO1 mapping).");
560 return response;
561 }
562 if (!rx_channel->begin(rx_cfg)) {
563 analogWrite(tx_pin, 0);
564 response.set("success", false);
565 response.set("error", "RxBeginFailed");
566 response.set("message",
567 "RxChannel::begin() returned false (see device WARN log).");
568 return response;
569 }
570
571 // 3. Let it capture for the requested window.
572 rx_channel->wait((u32)duration_ms);
573
574 // 4. Stop the square wave so the line is quiet for stats computation.
575 analogWrite(tx_pin, 0);
576
577 // 5. Pull captured edges out.
578 fl::vector<fl::EdgeTime> edges;
579 edges.assign(rx_cfg.edge_capacity, fl::EdgeTime());
580 size_t edges_captured =
581 rx_channel->getRawEdgeTimes(fl::span<fl::EdgeTime>(edges), 0);
582 edges.resize(edges_captured);
583
584 // 6. Compute period statistics. A "period" = duration_high + duration_low
585 // for adjacent edges, so we iterate in pairs.
586 fl::u64 sum_ns = 0;
587 fl::u64 sum_sq_ns = 0;
588 fl::u32 min_ns = 0xFFFFFFFFu;
589 fl::u32 max_ns = 0;
590 size_t periods = 0;
591 for (size_t i = 0; i + 1 < edges_captured; i += 2) {
592 const fl::u32 period_ns =
593 (fl::u32)edges[i].ns + (fl::u32)edges[i + 1].ns;
594 if (period_ns == 0) continue;
595 sum_ns += period_ns;
596 sum_sq_ns += (fl::u64)period_ns * (fl::u64)period_ns;
597 if (period_ns < min_ns) min_ns = period_ns;
598 if (period_ns > max_ns) max_ns = period_ns;
599 ++periods;
600 }
601 fl::u32 mean_ns = 0;
602 fl::u32 sigma_ns = 0;
603 if (periods > 0) {
604 mean_ns = (fl::u32)(sum_ns / (fl::u64)periods);
605 const fl::u64 mean64 = (fl::u64)mean_ns;
606 const fl::u64 var =
607 periods > 0 ? (sum_sq_ns / (fl::u64)periods) - (mean64 * mean64)
608 : 0;
609 // Integer sqrt for σ — adequate for the tolerance ranges we
610 // assert in Phase 2 (σ < 100 ns at 100 kHz).
611 fl::u32 s = 0;
612 while ((fl::u64)(s + 1) * (fl::u64)(s + 1) <= var) ++s;
613 sigma_ns = s;
614 }
615 if (min_ns == 0xFFFFFFFFu) min_ns = 0;
616
617 response.set("success", true);
618 response.set("frequency_hz", static_cast<int64_t>(frequency_hz));
619 response.set("duration_ms", static_cast<int64_t>(duration_ms));
620 response.set("tx_pin", static_cast<int64_t>(tx_pin));
621 response.set("rx_pin", static_cast<int64_t>(rx_pin));
622 response.set("edges_captured", static_cast<int64_t>(edges_captured));
623 response.set("periods", static_cast<int64_t>(periods));
624 response.set("period_mean_ns", static_cast<int64_t>(mean_ns));
625 response.set("period_sigma_ns", static_cast<int64_t>(sigma_ns));
626 response.set("period_min_ns", static_cast<int64_t>(min_ns));
627 response.set("period_max_ns", static_cast<int64_t>(max_ns));
628 return response;
629#endif
630 });
631
632 // Register "flexioObjectFledTest" — end-to-end ObjectFLED TX → FlexIO RX
633 // loopback verification (Phase 3 of FastLED#2764).
634 //
635 // Drives a small WS2812 pattern through `Bus::FLEX_IO` slot 0 on `tx_pin`,
636 // captures the wire signal back through the new `RxBackend::FLEXIO` on
637 // `rx_pin`, decodes the bit stream against WS2812B-V5 timing, and reports
638 // how many bytes matched the transmitted pattern.
639 //
640 // Test cases (parent issue Phase 3 table):
641 // 0 — Red single LED (1 LED, 0xFF0000 → wire-order GRB 00,FF,00)
642 // 1 — RGB three-LED chain (3 LEDs)
643 // 2 — All zeros (1 LED, 0x000000 — T0H/T0L fidelity)
644 // 3 — All ones (1 LED, 0xFFFFFF — T1H/T1L fidelity)
645 // 4 — 100-LED alternating R/G/B (long capture, watchdog-safety)
646 //
647 // Args (positional, all optional):
648 // { "test_case": int = 0,
649 // "tx_pin": int = 3, // matches GPIO 3↔4 jumper
650 // "rx_pin": int = 4,
651 // "capture_ms": int = 50 }
652 //
653 // Returns:
654 // { success, test_case, num_leds, expected_bytes, decoded_bytes,
655 // matched, mismatched, edges_captured }
656 //
657 // Teensy-4-only — FLEXIO1 is iMXRT1062-specific. ObjectFLED also relies
658 // on Teensy 4-core APIs, so non-Teensy builds return `PlatformNotSupported`.
659 remote.bind("flexioObjectFledTest", [](const fl::json& args) -> fl::json {
660 fl::json response = fl::json::object();
661#if !defined(FL_IS_TEENSY_4X)
662 (void)args;
663 response.set("success", false);
664 response.set("error", "PlatformNotSupported");
665 response.set("message",
666 "flexioObjectFledTest is Teensy 4.x-only (FLEXIO1 RX + "
667 "Teensy-core ObjectFLED driver).");
668 return response;
669#else
670 // Parse args
671 int test_case = 0;
672 int tx_pin = 3;
673 int rx_pin = 4;
674 int capture_ms = 50;
675 if (args.is_array() && args.size() >= 1 && args[0].is_object()) {
676 fl::json cfg = args[0];
677 if (cfg.contains("test_case") && cfg["test_case"].is_int()) {
678 test_case = static_cast<int>(cfg["test_case"].as_int().value());
679 }
680 if (cfg.contains("tx_pin") && cfg["tx_pin"].is_int()) {
681 tx_pin = static_cast<int>(cfg["tx_pin"].as_int().value());
682 }
683 if (cfg.contains("rx_pin") && cfg["rx_pin"].is_int()) {
684 rx_pin = static_cast<int>(cfg["rx_pin"].as_int().value());
685 }
686 if (cfg.contains("capture_ms") && cfg["capture_ms"].is_int()) {
687 capture_ms = static_cast<int>(cfg["capture_ms"].as_int().value());
688 }
689 }
690 if (test_case < 0 || test_case > 4 ||
691 capture_ms < 1 || capture_ms > 5000) {
692 response.set("success", false);
693 response.set("error", "InvalidArgs");
694 response.set("message",
695 "test_case in [0,4]; capture_ms in [1, 5000].");
696 return response;
697 }
698
699 // 1. Build the test pattern. Fixed upper bound (100 LEDs) covers
700 // case 4 — the larger cases reuse the same static buffer.
701 CRGB* leds_buf = flexIoObjectFledState().leds;
702 int num_leds = 0;
703 switch (test_case) {
704 case 0:
705 num_leds = 1;
706 leds_buf[0] = CRGB::Red;
707 break;
708 case 1:
709 num_leds = 3;
710 leds_buf[0] = CRGB::Red;
711 leds_buf[1] = CRGB::Green;
712 leds_buf[2] = CRGB::Blue;
713 break;
714 case 2:
715 num_leds = 1;
716 leds_buf[0] = CRGB::Black;
717 break;
718 case 3:
719 num_leds = 1;
720 leds_buf[0] = CRGB(0xFF, 0xFF, 0xFF);
721 break;
722 case 4:
723 num_leds = 100;
724 for (int i = 0; i < 100; ++i) {
725 leds_buf[i] = (i % 3 == 0) ? CRGB::Red
726 : (i % 3 == 1) ? CRGB::Green
727 : CRGB::Blue;
728 }
729 break;
730 }
731
732 // 2. Build the expected wire-order byte stream (WS2812 is GRB).
733 fl::vector<u8> expected;
734 expected.reserve((size_t)num_leds * 3);
735 for (int i = 0; i < num_leds; ++i) {
736 expected.push_back(leds_buf[i].g);
737 expected.push_back(leds_buf[i].r);
738 expected.push_back(leds_buf[i].b);
739 }
740
741 // 3. Set up FlexIO RX. Size the edge buffer for 24 bits per LED ×
742 // 2 transitions per bit, with 25% headroom.
743 const size_t expected_edges = (size_t)num_leds * 24u * 2u;
744 size_t edge_capacity = expected_edges + expected_edges / 4u + 64u;
745 if (edge_capacity > 16384u) edge_capacity = 16384u;
746
747 fl::RxChannelConfig rx_cfg(rx_pin, fl::RxBackend::FLEXIO);
748 rx_cfg.edge_capacity = edge_capacity;
749 rx_cfg.start_low = true;
750 auto rx_channel = fl::RxChannel::create(rx_cfg);
751 if (!rx_channel || !rx_channel->begin(rx_cfg)) {
752 response.set("success", false);
753 response.set("error", "RxBeginFailed");
754 response.set("message",
755 "Failed to bring up FlexIO RX on the requested pin "
756 "(check kFlexIo1Pins[] mapping).");
757 return response;
758 }
759
760 // 4. Configure ObjectFLED TX via FastLED.add().
761 fl::ChannelOptions opts;
762 opts.mBus = fl::Bus::FLEX_IO;
763 opts.mBusWhich = 0;
764 auto resolved_timing = fl::makeTimingConfig<fl::TIMING_WS2812B_V5>();
765 auto resolved_encoder = fl::encoder_for<fl::TIMING_WS2812B_V5>();
766 fl::NamedTimingConfig timing_cfg(resolved_timing, "WS2812B-V5",
767 resolved_encoder);
768 fl::ChannelConfig tx_cfg(
769 tx_pin,
770 timing_cfg.timing,
771 fl::span<CRGB>(leds_buf, (size_t)num_leds),
772 RGB,
773 opts);
774 auto tx_channel = FastLED.add(tx_cfg);
775 if (!tx_channel) {
776 response.set("success", false);
777 response.set("error", "TxAddFailed");
778 response.set("message",
779 "FastLED.add() rejected the ObjectFLED ChannelConfig.");
780 return response;
781 }
782
783 // 5. Trigger TX. FastLED.show() schedules the DMA and returns once
784 // the frame has been queued. The RX wait must be long enough to
785 // cover BOTH the TX transmission time AND the capture-buffer
786 // fill — otherwise teardown happens mid-frame and the hardware
787 // can be left in a bad state. Compute a minimum from the actual
788 // WS2812 timing (1.25 µs per bit, 24 bits per LED, plus reset
789 // gap) and use the larger of the caller's `capture_ms` and that
790 // minimum.
791 FastLED.show();
792 const u32 ws2812_tx_us =
793 (u32)num_leds * 24u * 13u / 10u + 100u; // 1.25 µs/bit + reset
794 const u32 min_capture_ms = (ws2812_tx_us + 999u) / 1000u + 10u;
795 const u32 effective_capture_ms = ((u32)capture_ms > min_capture_ms)
796 ? (u32)capture_ms
797 : min_capture_ms;
798 rx_channel->wait(effective_capture_ms);
799
800 // 6. Decode the captured edge stream against WS2812 4-phase timing.
801 const fl::ChipsetTiming ws2812_timing =
803 fl::ChipsetTiming4Phase rx_timing =
804 fl::make4PhaseTiming(ws2812_timing);
805 fl::vector<u8> decoded;
806 decoded.assign(expected.size() + 16u, 0u);
807 auto decode_result =
808 rx_channel->decode(rx_timing, fl::span<u8>(decoded));
809
810 // 7. Compare decoded bytes against expected.
811 u32 decoded_bytes = 0u;
812 if (decode_result) {
813 decoded_bytes = decode_result.value();
814 }
815 const size_t cmp_n = (decoded_bytes < expected.size())
816 ? (size_t)decoded_bytes
817 : expected.size();
818 size_t matched = 0;
819 size_t mismatched = 0;
820 for (size_t i = 0; i < cmp_n; ++i) {
821 if (decoded[i] == expected[i]) ++matched; else ++mismatched;
822 }
823 if (decoded_bytes < expected.size()) {
824 mismatched += expected.size() - decoded_bytes;
825 }
826
827 // 8. Read raw edge count for diagnostics.
828 fl::vector<fl::EdgeTime> edges;
829 edges.assign(edge_capacity, fl::EdgeTime());
830 const size_t edges_captured =
831 rx_channel->getRawEdgeTimes(fl::span<fl::EdgeTime>(edges), 0);
832
833 // 9. Tear the TX channel back down so subsequent tests can use the
834 // same pin (FastLED.clear(ClearFlags::CHANNELS) matches the
835 // pattern used by runSingleTestImpl in this file).
837
838 response.set("success", mismatched == 0 && decoded_bytes == expected.size());
839 response.set("test_case", static_cast<int64_t>(test_case));
840 response.set("tx_pin", static_cast<int64_t>(tx_pin));
841 response.set("rx_pin", static_cast<int64_t>(rx_pin));
842 response.set("num_leds", static_cast<int64_t>(num_leds));
843 response.set("expected_bytes", static_cast<int64_t>(expected.size()));
844 response.set("decoded_bytes", static_cast<int64_t>(decoded_bytes));
845 response.set("matched", static_cast<int64_t>(matched));
846 response.set("mismatched", static_cast<int64_t>(mismatched));
847 response.set("edges_captured", static_cast<int64_t>(edges_captured));
848 return response;
849#endif
850 });
851
852 // Register "flexioRxLoopbackPing" — FastLED#3066 phase 1.7 diagnostic.
853 //
854 // Bypasses every clockless driver entirely and tests whether the
855 // FlexIO RX backend can capture HAND-DRIVEN GPIO transitions. Drives
856 // `tx_pin` as a plain `digitalWrite` HIGH/LOW square wave while
857 // `RxBackend::FLEXIO` is armed on `rx_pin`. If the captured buffer
858 // shows any non-zero data, IOMUX ALT4 + PINSEL routing is correct
859 // and the WS2812-loopback failure mode is downstream (timer/shifter
860 // bandwidth, decoder thresholds, etc.). If the buffer stays all
861 // zero with a 4-edge ground-truth pin toggle, the routing itself is
862 // broken — debug that BEFORE more timer/shifter config experiments.
863 //
864 // Wiring: same TX↔RX jumper as flexioObjectFledTest (defaults 3↔4).
865 //
866 // Args:
867 // { tx_pin?: 3, // any digital pin
868 // rx_pin?: 4, // must be in kFlexIo1Pins[]
869 // toggle_us?: 50, // half-period of the manual square wave
870 // edges?: 8 } // number of digitalWrite transitions
871 // Returns:
872 // { success, tx_pin, rx_pin, toggle_us, edges, edges_captured,
873 // capture_buffer_first8_hex: [...], notes }
874 //
875 // Teensy-4-only.
876 remote.bind("flexioRxLoopbackPing", [](const fl::json& args) -> fl::json {
877 fl::json response = fl::json::object();
878#if !defined(FL_IS_TEENSY_4X)
879 (void)args;
880 response.set("success", false);
881 response.set("error", "PlatformNotSupported");
882 response.set("message",
883 "flexioRxLoopbackPing is Teensy 4.x-only (FLEXIO1 RX).");
884 return response;
885#else
886 int tx_pin = 3;
887 int rx_pin = 4;
888 int toggle_us = 50;
889 int edges = 8;
890 if (args.is_array() && args.size() >= 1 && args[0].is_object()) {
891 const fl::json &cfg = args[0];
892 if (cfg.contains("tx_pin") && cfg["tx_pin"].is_int()) {
893 tx_pin = static_cast<int>(cfg["tx_pin"].as_int().value());
894 }
895 if (cfg.contains("rx_pin") && cfg["rx_pin"].is_int()) {
896 rx_pin = static_cast<int>(cfg["rx_pin"].as_int().value());
897 }
898 if (cfg.contains("toggle_us") && cfg["toggle_us"].is_int()) {
899 toggle_us = static_cast<int>(cfg["toggle_us"].as_int().value());
900 }
901 if (cfg.contains("edges") && cfg["edges"].is_int()) {
902 edges = static_cast<int>(cfg["edges"].as_int().value());
903 }
904 }
905 if (edges < 2 || edges > 64) {
906 response.set("success", false);
907 response.set("error", "InvalidEdges");
908 response.set("message", "edges must be in [2, 64]");
909 return response;
910 }
911
912 // 1. Arm FlexIO RX on rx_pin.
913 fl::RxChannelConfig rx_cfg(rx_pin, fl::RxBackend::FLEXIO);
914 rx_cfg.edge_capacity = 1024; // plenty for ~10 edges
915 rx_cfg.start_low = true;
916 auto rx_channel = fl::RxChannel::create(rx_cfg);
917 if (!rx_channel || !rx_channel->begin(rx_cfg)) {
918 response.set("success", false);
919 response.set("error", "RxBeginFailed");
920 response.set("message",
921 "FlexIO RX begin() failed (kFlexIo1Pins[] mapping?).");
922 return response;
923 }
924
925 // 2. Drive tx_pin as a plain GPIO output, toggle a known number of
926 // transitions. Start LOW so the first digitalWrite(HIGH) is a
927 // rising edge.
928 pinMode(tx_pin, OUTPUT);
929 digitalWrite(tx_pin, LOW);
930 delayMicroseconds(100); // let the line settle + RX arm fully
931
932 bool level = true;
933 for (int i = 0; i < edges; ++i) {
934 digitalWrite(tx_pin, level ? HIGH : LOW);
935 delayMicroseconds(toggle_us);
936 level = !level;
937 }
938
939 // FastLED#3066 iter 7 diagnostic: also probe SHIFTBUF[0] +
940 // SHIFTBUFBIS (bit-swapped) + SHIFTBUFBYS (byte-swapped) so we
941 // can see whether the captured bit lands in a bit position
942 // different from what the canonical SHIFTBUF[0] read produces.
943 {
944 constexpr uintptr_t kFLEXIO1_BASE_DIAG = 0x401AC000u;
945 volatile uint32_t *pin = (volatile uint32_t *)(kFLEXIO1_BASE_DIAG + 0x00C);
946 volatile uint32_t *shftstat = (volatile uint32_t *)(kFLEXIO1_BASE_DIAG + 0x010);
947 volatile uint32_t *timstat = (volatile uint32_t *)(kFLEXIO1_BASE_DIAG + 0x018);
948 volatile uint32_t *shftbuf = (volatile uint32_t *)(kFLEXIO1_BASE_DIAG + 0x200);
949 volatile uint32_t *shftbufbis = (volatile uint32_t *)(kFLEXIO1_BASE_DIAG + 0x280);
950 volatile uint32_t *shftbufbys = (volatile uint32_t *)(kFLEXIO1_BASE_DIAG + 0x300);
951 fl::json flexio_diag = fl::json::object();
952 flexio_diag.set("pin", static_cast<int64_t>(*pin));
953 flexio_diag.set("shiftstat", static_cast<int64_t>(*shftstat));
954 flexio_diag.set("timstat", static_cast<int64_t>(*timstat));
955 flexio_diag.set("shiftbuf0", static_cast<int64_t>(*shftbuf));
956 flexio_diag.set("shiftbufbis0", static_cast<int64_t>(*shftbufbis));
957 flexio_diag.set("shiftbufbys0", static_cast<int64_t>(*shftbufbys));
958 response.set("flexio1", flexio_diag);
959 }
960
961 // 3. Wait briefly for FlexIO RX to flush any pending DMA. The DMA
962 // is configured for completion-on-buffer-full; a partial fill
963 // won't trigger the ISR, so `wait()` will TIMEOUT — which is
964 // fine, we read the captured edges directly.
965 rx_channel->wait(50);
966
967 // 4. Read the captured edges via the public API.
968 fl::vector<fl::EdgeTime> captured_edges;
969 captured_edges.assign(64, fl::EdgeTime());
970 size_t edge_count =
971 rx_channel->getRawEdgeTimes(fl::span<fl::EdgeTime>(captured_edges), 0);
972
973 // 5. Restore tx_pin so subsequent tests can use it.
974 pinMode(tx_pin, INPUT);
975
976 response.set("success", true);
977 response.set("tx_pin", static_cast<int64_t>(tx_pin));
978 response.set("rx_pin", static_cast<int64_t>(rx_pin));
979 response.set("toggle_us", static_cast<int64_t>(toggle_us));
980 response.set("edges", static_cast<int64_t>(edges));
981 response.set("edges_captured", static_cast<int64_t>(edge_count));
982
983 // Dump the first 8 captured edge durations (ns) so the host can
984 // see whether they roughly match the requested toggle_us *
985 // 1000 ns expectation.
986 fl::json edges_arr = fl::json::array();
987 const size_t to_dump = (edge_count < 8u) ? edge_count : 8u;
988 for (size_t i = 0; i < to_dump; ++i) {
989 fl::json e = fl::json::object();
990 e.set("high", captured_edges[i].high);
991 e.set("ns", static_cast<int64_t>(captured_edges[i].ns));
992 edges_arr.push_back(e);
993 }
994 response.set("first_edges", edges_arr);
995 return response;
996#endif
997 });
998
999 remote.bind("legacyAsyncProbe", [](const fl::json& args) -> fl::json {
1001 });
1002 remote.bind("legacyAsyncErrorProbe", [](const fl::json& args) -> fl::json {
1004 });
1005
1006 // Register "timingDriftTest" — issue #2994 reproducer for compounded
1007 // per-sequence timing drift on master vs 3.10.3. Replays the reporter's
1008 // minimal sketch (35-LED WS2812B ring, setMaxRefreshRate(800),
1009 // millisDelay-gated 255-step fade, delay(1000) between sequences) and
1010 // returns per-sequence wall time so the host can build a histogram.
1011 // Args: [{pin, numLeds, iterations}] (all optional;
1012 // default pin=4, numLeds=35, iterations=10; iterations clamped to
1013 // autoresearch::timing_drift::kMaxIterations)
1014 remote.bind("timingDriftTest", [](const fl::json& args) -> fl::json {
1015 fl::json response = fl::json::object();
1016
1017 int pin = 4;
1018 int num_leds = 35;
1019 int iterations = 10;
1020
1021 fl::json config;
1022 if (args.is_object()) {
1023 config = args;
1024 } else if (args.is_array() && args.size() >= 1 && args[0].is_object()) {
1025 config = args[0];
1026 }
1027 if (!config.is_null()) {
1028 if (config.contains("pin") && config["pin"].is_int()) {
1029 pin = static_cast<int>(config["pin"].as_int().value());
1030 }
1031 if (config.contains("numLeds") && config["numLeds"].is_int()) {
1032 num_leds = static_cast<int>(config["numLeds"].as_int().value());
1033 }
1034 if (config.contains("iterations") && config["iterations"].is_int()) {
1035 iterations = static_cast<int>(config["iterations"].as_int().value());
1036 }
1037 }
1038
1039 auto r = autoresearch::timing_drift::run(pin, num_leds, iterations);
1040
1041 response.set("success", r.valid_pin);
1042 if (!r.valid_pin) {
1043 response.set("error", "InvalidPin");
1044 response.set("message",
1045 "pin is outside LegacyClocklessProxy range");
1046 response.set("pin", r.pin);
1047 return response;
1048 }
1049 response.set("pin", r.pin);
1050 response.set("num_leds", r.num_leds);
1051 response.set("iterations", r.iterations);
1052 response.set("cpu_mhz", static_cast<int64_t>(r.cpu_mhz));
1053 response.set("show_count", static_cast<int64_t>(r.show_count));
1054 response.set("show_min_us", static_cast<int64_t>(r.show_min_us));
1055 response.set("show_max_us", static_cast<int64_t>(r.show_max_us));
1056 response.set("show_total_us", static_cast<int64_t>(r.show_total_us));
1057
1058 fl::json iter_ms_arr = fl::json::array();
1059 for (int i = 0; i < r.iterations; ++i) {
1060 iter_ms_arr.push_back(static_cast<int64_t>(r.iter_ms[i]));
1061 }
1062 response.set("iter_ms", iter_ms_arr);
1063 return response;
1064 });
1065
1066 // Register "flexioSpiSelfTest" — #3428 bring-up smoke test for the
1067 // FlexIO2 SPI master mode. Exercises the full
1068 // lookup → init → show → wait → deinit path on a user-specified
1069 // (MOSI, SCLK) pin pair with a known byte pattern, then reports back
1070 // success/failure of each stage plus the resolved FlexIO2 pin indices
1071 // so a host-side test can diagnose routing and bring-up failures.
1072 //
1073 // This test does NOT need a logic analyzer or a connected APA102
1074 // strip — it confirms the driver runs without crashing the firmware,
1075 // pins route, init programs the shifter/timer, and DMA completes
1076 // within the bounded timeout. Full byte-level verification needs a
1077 // scope (see TODO markers in flexio_spi_mode.cpp.hpp).
1078 //
1079 // Args (positional, all optional):
1080 // { "mosi_pin": int = 10, // FlexIO2 pin 0 (default APA102 MOSI)
1081 // "sclk_pin": int = 12, // FlexIO2 pin 1 (default APA102 SCLK)
1082 // "clock_hz": int = 1000000, // 1 MHz default for safety
1083 // "num_bytes": int = 4 } // sent bytes 0xA5 0x5A 0xFF 0x00
1084 //
1085 // Returns:
1086 // { success, mosi_pin, sclk_pin, clock_hz, num_bytes,
1087 // lookup_ok, init_ok, show_ok, wait_ms,
1088 // mosi_flexio_pin, sclk_flexio_pin }
1089 //
1090 // Teensy 4.x-only.
1091 remote.bind("flexioSpiSelfTest", [](const fl::json& args) -> fl::json {
1092 fl::json response = fl::json::object();
1093#if !defined(FL_IS_TEENSY_4X)
1094 (void)args;
1095 response.set("success", false);
1096 response.set("error", "PlatformNotSupported");
1097 response.set("message",
1098 "flexioSpiSelfTest is Teensy 4.x-only (FlexIO2 SPI master mode).");
1099 return response;
1100#else
1101 // Parse args with defaults that work out-of-the-box on Teensy 4.x.
1102 // Note: the RPC framework signature `fl::json(const fl::json&)` makes
1103 // the framework strip the outer params array and pass `params[0]`
1104 // directly as `args`. So `args` is an OBJECT here, not an array --
1105 // some existing bindings in this file have the wrong `args.is_array()`
1106 // check (pre-existing bug, fix tracked separately) and silently use
1107 // their defaults always.
1108 int mosi_pin = 10; // FlexIO2 pin 0 (teensy pin 10)
1109 int sclk_pin = 12; // FlexIO2 pin 1 (teensy pin 12)
1110 int clock_hz = 1000000; // 1 MHz -- safe for bring-up
1111 int num_bytes = 4;
1112 if (args.is_object()) {
1113 const fl::json& cfg = args;
1114 if (cfg.contains("mosi_pin") && cfg["mosi_pin"].is_int()) {
1115 mosi_pin = static_cast<int>(cfg["mosi_pin"].as_int().value());
1116 }
1117 if (cfg.contains("sclk_pin") && cfg["sclk_pin"].is_int()) {
1118 sclk_pin = static_cast<int>(cfg["sclk_pin"].as_int().value());
1119 }
1120 if (cfg.contains("clock_hz") && cfg["clock_hz"].is_int()) {
1121 clock_hz = static_cast<int>(cfg["clock_hz"].as_int().value());
1122 }
1123 if (cfg.contains("num_bytes") && cfg["num_bytes"].is_int()) {
1124 num_bytes = static_cast<int>(cfg["num_bytes"].as_int().value());
1125 }
1126 }
1127
1128 response.set("mosi_pin", mosi_pin);
1129 response.set("sclk_pin", sclk_pin);
1130 response.set("clock_hz", static_cast<int64_t>(clock_hz));
1131 response.set("num_bytes", num_bytes);
1132
1133 // Validate input ranges BEFORE narrowing to u8/u32. Without these
1134 // guards, mosi_pin=270 wraps to pin 14 in static_cast<u8>(), and
1135 // a negative clock_hz wraps to a huge u32 that the SPI driver
1136 // would then clamp to the 25 MHz ceiling -- both silently produce
1137 // wrong-hardware behavior. Per coderabbitai review on PR #3431.
1138 if (num_bytes <= 0 || num_bytes > 64) {
1139 response.set("success", false);
1140 response.set("error", "InvalidArgs");
1141 response.set("message", "num_bytes must be in [1, 64].");
1142 return response;
1143 }
1144 if (mosi_pin < 0 || mosi_pin > 255 ||
1145 sclk_pin < 0 || sclk_pin > 255) {
1146 response.set("success", false);
1147 response.set("error", "InvalidArgs");
1148 response.set("message", "mosi_pin / sclk_pin must be in [0, 255].");
1149 return response;
1150 }
1151 if (clock_hz <= 0) {
1152 response.set("success", false);
1153 response.set("error", "InvalidArgs");
1154 response.set("message", "clock_hz must be > 0.");
1155 return response;
1156 }
1157
1158 // 1. Pin-pair lookup.
1159 fl::FlexIOSPIPinInfo pin_info{};
1160 bool lookup_ok = fl::flexio_spi_lookup_pins(
1161 static_cast<fl::u8>(mosi_pin),
1162 static_cast<fl::u8>(sclk_pin),
1163 &pin_info);
1164 response.set("lookup_ok", lookup_ok);
1165 if (!lookup_ok) {
1166 response.set("success", false);
1167 response.set("error", "PinNotRoutable");
1168 response.set("message",
1169 "(MOSI, SCLK) pair is not FlexIO2-routable; both pins "
1170 "must be in {6, 7, 8, 9, 10, 11, 12, 13, 32}.");
1171 return response;
1172 }
1173 response.set("mosi_flexio_pin",
1174 static_cast<int64_t>(pin_info.mosi_flexio_pin));
1175 response.set("sclk_flexio_pin",
1176 static_cast<int64_t>(pin_info.sclk_flexio_pin));
1177
1178 // 2. Init.
1179 bool init_ok = fl::flexio_spi_init(pin_info,
1180 static_cast<fl::u32>(clock_hz));
1181 response.set("init_ok", init_ok);
1182 if (!init_ok) {
1183 response.set("success", false);
1184 response.set("error", "InitFailed");
1185 response.set("message", "flexio_spi_init returned false.");
1186 return response;
1187 }
1188
1189 // 3. Send a known pattern. 0xA5 = 1010 0101 — easy to read on a
1190 // scope to verify MSB-first ordering (high bit shifts out first).
1191 // Fill the rest with alternating 0xFF / 0x00 so the wire toggles.
1192 fl::u8 buffer[64] = {0};
1193 for (int i = 0; i < num_bytes; ++i) {
1194 switch (i % 4) {
1195 case 0: buffer[i] = 0xA5; break;
1196 case 1: buffer[i] = 0x5A; break;
1197 case 2: buffer[i] = 0xFF; break;
1198 case 3: buffer[i] = 0x00; break;
1199 }
1200 }
1201
1202 const fl::u32 show_start_ms = millis();
1203 bool show_ok = fl::flexio_spi_show(buffer,
1204 static_cast<fl::u32>(num_bytes));
1205 response.set("show_ok", show_ok);
1206 if (!show_ok) {
1207 fl::flexio_spi_deinit();
1208 response.set("success", false);
1209 response.set("error", "ShowFailed");
1210 response.set("message", "flexio_spi_show returned false.");
1211 return response;
1212 }
1213
1214 // 4. Wait for completion.
1215 fl::flexio_spi_wait();
1216 const fl::u32 wait_ms = millis() - show_start_ms;
1217 response.set("wait_ms", static_cast<int64_t>(wait_ms));
1218
1219 // 5. Tear down.
1220 fl::flexio_spi_deinit();
1221
1222 response.set("success", true);
1223 return response;
1224#endif
1225 });
1226
1227 // Register "objectfledSpiSelfTest" — #3428 bring-up smoke test for the
1228 // ObjectFLED DMA-bit-banged SPI master mode. Exercises the full
1229 // lookup → init → show → wait → deinit path on a user-specified
1230 // (MOSI, SCLK) pin pair (both must be on GPIO6) with a known byte
1231 // pattern, reports back per-stage success + echoed args.
1232 //
1233 // Args (positional, all optional):
1234 // { "mosi_pin": int = 14, // GPIO6 bit 18 on T4.1
1235 // "sclk_pin": int = 15, // GPIO6 bit 19 on T4.1
1236 // "clock_hz": int = 1000000,
1237 // "num_bytes": int = 4 }
1238 //
1239 // Returns:
1240 // { success, mosi_pin, sclk_pin, clock_hz, num_bytes,
1241 // lookup_ok, init_ok, show_ok, wait_ms,
1242 // mosi_bit, sclk_bit, dma_* (10), tmr3_* (5), xbar1_ctrl1 }
1243 //
1244 // Teensy 4.x-only.
1245 remote.bind("objectfledSpiSelfTest", [](const fl::json& args) -> fl::json {
1246 fl::json response = fl::json::object();
1247#if !defined(FL_IS_TEENSY_4X)
1248 (void)args;
1249 response.set("success", false);
1250 response.set("error", "PlatformNotSupported");
1251 response.set("message",
1252 "objectfledSpiSelfTest is Teensy 4.x-only (FlexPWM2 + eDMA + GPIO6).");
1253 return response;
1254#else
1255 // Parse args. The RPC framework strips the outer params array
1256 // and passes params[0] directly as `args`, so `args` is an OBJECT
1257 // here (NOT an array).
1258 int mosi_pin = 14; // GPIO6 bit 18 on T4.1 (and T4.0)
1259 int sclk_pin = 15; // GPIO6 bit 19
1260 int clock_hz = 1000000; // 1 MHz -- safe for bring-up
1261 int num_bytes = 4;
1262 if (args.is_object()) {
1263 const fl::json& cfg = args;
1264 if (cfg.contains("mosi_pin") && cfg["mosi_pin"].is_int()) {
1265 mosi_pin = static_cast<int>(cfg["mosi_pin"].as_int().value());
1266 }
1267 if (cfg.contains("sclk_pin") && cfg["sclk_pin"].is_int()) {
1268 sclk_pin = static_cast<int>(cfg["sclk_pin"].as_int().value());
1269 }
1270 if (cfg.contains("clock_hz") && cfg["clock_hz"].is_int()) {
1271 clock_hz = static_cast<int>(cfg["clock_hz"].as_int().value());
1272 }
1273 if (cfg.contains("num_bytes") && cfg["num_bytes"].is_int()) {
1274 num_bytes = static_cast<int>(cfg["num_bytes"].as_int().value());
1275 }
1276 }
1277
1278 response.set("mosi_pin", mosi_pin);
1279 response.set("sclk_pin", sclk_pin);
1280 response.set("clock_hz", static_cast<int64_t>(clock_hz));
1281 response.set("num_bytes", num_bytes);
1282
1283 // Validate input ranges BEFORE narrowing to u8/u32.
1284 if (num_bytes <= 0 || num_bytes > 64) {
1285 response.set("success", false);
1286 response.set("error", "InvalidArgs");
1287 response.set("message", "num_bytes must be in [1, 64].");
1288 return response;
1289 }
1290 if (mosi_pin < 0 || mosi_pin > 255 ||
1291 sclk_pin < 0 || sclk_pin > 255) {
1292 response.set("success", false);
1293 response.set("error", "InvalidArgs");
1294 response.set("message", "mosi_pin / sclk_pin must be in [0, 255].");
1295 return response;
1296 }
1297 if (clock_hz <= 0) {
1298 response.set("success", false);
1299 response.set("error", "InvalidArgs");
1300 response.set("message", "clock_hz must be > 0.");
1301 return response;
1302 }
1303
1304 // 1. Pin-pair lookup.
1305 fl::ObjectFLEDSPIPinInfo pin_info{};
1306 bool lookup_ok = fl::objectfled_spi_lookup_pins(
1307 static_cast<fl::u8>(mosi_pin),
1308 static_cast<fl::u8>(sclk_pin),
1309 &pin_info);
1310 response.set("lookup_ok", lookup_ok);
1311 if (!lookup_ok) {
1312 response.set("success", false);
1313 response.set("error", "PinNotRoutable");
1314 response.set("message",
1315 "(MOSI, SCLK) pair is not on GPIO6 or otherwise invalid; "
1316 "both pins must be GPIO6-resident (T4.x: 0, 1, 14-27, "
1317 "T4.1 adds 38-41).");
1318 return response;
1319 }
1320 response.set("mosi_bit", static_cast<int64_t>(pin_info.mosi_bit));
1321 response.set("sclk_bit", static_cast<int64_t>(pin_info.sclk_bit));
1322
1323 // 2. Init.
1324 bool init_ok = fl::objectfled_spi_init(pin_info,
1325 static_cast<fl::u32>(clock_hz));
1326 response.set("init_ok", init_ok);
1327 if (!init_ok) {
1328 response.set("success", false);
1329 response.set("error", "InitFailed");
1330 response.set("message", "objectfled_spi_init returned false.");
1331 return response;
1332 }
1333
1334 // 3. Send a known pattern.
1335 fl::u8 buffer[64] = {0};
1336 for (int i = 0; i < num_bytes; ++i) {
1337 switch (i % 4) {
1338 case 0: buffer[i] = 0xA5; break;
1339 case 1: buffer[i] = 0x5A; break;
1340 case 2: buffer[i] = 0xFF; break;
1341 case 3: buffer[i] = 0x00; break;
1342 }
1343 }
1344
1345 const fl::u32 show_start_ms = millis();
1346 bool show_ok = fl::objectfled_spi_show(
1347 fl::span<const fl::u8>(buffer,
1348 static_cast<fl::size>(num_bytes)));
1349 response.set("show_ok", show_ok);
1350 if (!show_ok) {
1351 fl::objectfled_spi_deinit();
1352 response.set("success", false);
1353 response.set("error", "ShowFailed");
1354 response.set("message", "objectfled_spi_show returned false.");
1355 return response;
1356 }
1357
1358 // 4. Wait for completion.
1359 fl::objectfled_spi_wait();
1360 const fl::u32 wait_ms = millis() - show_start_ms;
1361 response.set("wait_ms", static_cast<int64_t>(wait_ms));
1362
1363 // 5. Snapshot DMA + QTimer3 + XBAR1 register state.
1364 fl::ObjectFLEDSPIDiagnostics diag{};
1365 fl::objectfled_spi_read_diagnostics(&diag);
1366 response.set("dma_channel", static_cast<int64_t>(diag.dma_channel));
1367 response.set("dma_erq", static_cast<int64_t>(diag.dma_erq));
1368 response.set("dma_int", static_cast<int64_t>(diag.dma_int));
1369 response.set("dma_err", static_cast<int64_t>(diag.dma_err));
1370 response.set("dma_es", static_cast<int64_t>(diag.dma_es));
1371 response.set("dma_citer", static_cast<int64_t>(diag.dma_citer));
1372 response.set("dma_biter", static_cast<int64_t>(diag.dma_biter));
1373 response.set("tmr3_cntr0", static_cast<int64_t>(diag.tmr3_cntr0));
1374 response.set("tmr3_csctrl0", static_cast<int64_t>(diag.tmr3_csctrl0));
1375 response.set("tmr3_sctrl0", static_cast<int64_t>(diag.tmr3_sctrl0));
1376 response.set("tmr3_ctrl0", static_cast<int64_t>(diag.tmr3_ctrl0));
1377 response.set("tmr3_enbl", static_cast<int64_t>(diag.tmr3_enbl));
1378 response.set("xbar1_ctrl1", static_cast<int64_t>(diag.xbar1_ctrl1));
1379
1380 // 6. Tear down.
1381 fl::objectfled_spi_deinit();
1382
1383 response.set("success", true);
1384 return response;
1385#endif
1386 });
1387}
1388
1389#endif // FL_PLATFORM_HAS_LARGE_MEMORY
CRGB leds[1]
Full PARLIO encode bench for ESP32-P4 (post-byte-LUT, #2526 landed).
PARLIO ISR-streaming functional validation (#2548 deep-dive follow-up).
size_t capture(fl::shared_ptr< fl::RxChannel > rx_channel, fl::span< uint8_t > rx_buffer, size_t expected_data_bytes, int tx_pin, const fl::ChipsetTimingConfig &timing, const char *driver_name, fl::RunResult *diagnostics=nullptr)
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.
@ CHANNELS
Remove all channels from controller list.
Definition FastLED.h:665
@ APA102
APA102 LED chipset.
Definition FastLED.h:301
fl::unique_ptr< fl::Remote > remote
Definition RpcClient.ino:43
fl::net::ble — BLE GATT transport layer for JSON-RPC
SPI encoder configuration for clocked LED chipsets.
fl::shared_ptr< AutoResearchState > mState
void bindDriverMethods(fl::Remote &remote)
void clear(bool writeData=false) FL_NO_EXCEPT
Clear the leds, wiping the local array of data.
static void add(fl::ChannelPtr channel) FL_NO_EXCEPT
Add a Channel-based LED controller (from ChannelPtr)
void show(fl::u8 scale) FL_NO_EXCEPT
Update all our controllers with the current led colors, using the passed in brightness.
void setBrightness(fl::u8 scale) FL_NO_EXCEPT
Set the global brightness scaling.
Definition FastLED.h:1650
void wait() FL_NO_EXCEPT
Wait for all channel bus transmissions to complete.
::CLEDController & addLeds(::CLEDController *pLed, CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0) FL_NO_EXCEPT
Add a CLEDController instance to the world.
static ChannelManager & registry() FL_NO_EXCEPT
Get the singleton WITHOUT registering platform default drivers.
fl::shared_ptr< IChannelDriver > findDriverByName(const fl::string &name) const FL_NO_EXCEPT
Silent counterpart to getDriverByName().
bool isDriverEnabled(const char *name) const FL_NO_EXCEPT
Check if a driver is enabled by name.
JSON-RPC server with scheduling support.
Definition remote.h:42
static RxChannelPtr create(const RxChannelConfig &config) FL_NO_EXCEPT
static T & instance() FL_NO_EXCEPT
Definition singleton.h:41
bool empty() const FL_NO_EXCEPT
const char * c_str() const FL_NO_EXCEPT
fl::optional< i64 > as_int() const FL_NO_EXCEPT
Definition json.h:398
void set(const fl::string &key, const json &value) FL_NO_EXCEPT
Definition json.h:873
bool is_null() const FL_NO_EXCEPT
Definition json.h:381
void push_back(const json &value) FL_NO_EXCEPT
Definition json.h:925
bool contains(size_t idx) const FL_NO_EXCEPT
Definition json.h:790
static json object() FL_NO_EXCEPT
Definition json.h:864
static json array() FL_NO_EXCEPT
Definition json.h:860
static string from_literal(const char *literal) FL_NO_EXCEPT
fl::size size() const FL_NO_EXCEPT
void reserve(fl::size n) FL_NO_EXCEPT
Definition vector.h:591
void resize(fl::size n) FL_NO_EXCEPT
Definition vector.h:593
void push_back(const T &value) FL_NO_EXCEPT
Definition vector.h:624
void assign(InputIt first, InputIt last) FL_NO_EXCEPT
Definition vector.h:638
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
constexpr EOrder RGB
Definition eorder.h:17
Task executor — runs registered task runners and manages the run loop.
#define DATA_RATE_KHZ
Definition fastspi.h:96
fl::CRGB CRGB
Definition crgb.h:25
Platform-abstracted heap memory query functions.
FastLED's Elegant JSON Library: fl::json
DriftResult run(int pin, int num_leds, int iterations)
fl::json legacyAsyncProbe(const fl::json &args)
Call after the regular driver test has registered the selected backend.
fl::json legacyAsyncErrorProbe(const fl::json &args)
::size_t size_t
Definition s16x16x4.h:21
unsigned char u8
Definition stdint.h:132
constexpr ChipsetTiming to_runtime_timing() FL_NO_EXCEPT
Convert enum-based timing type to runtime ChipsetTiming struct.
Definition led_timing.h:616
constexpr ChipsetTimingConfig makeTimingConfig() FL_NO_EXCEPT
Convert compile-time CHIPSET type to runtime timing config.
fl::u32 uint32_t
Definition s16x16x4.h:219
AtomicFake< T > atomic
Definition atomic.h:26
@ memory_order_acquire
Definition atomic.h:41
@ memory_order_release
Definition atomic.h:42
FL_DISABLE_WARNING_PUSH U constexpr common_type_t< T, U > min(T a, U b) FL_NO_EXCEPT
Definition math.h:71
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
ChipsetTiming4Phase make4PhaseTiming(const ChipsetTiming &timing_3phase, u32 tolerance_ns) FL_NO_EXCEPT
Create 4-phase RX timing from 3-phase chipset timing with tolerance.
Definition rx.cpp.hpp:78
void init(Context &ctx, int w, int h) FL_NO_EXCEPT
Definition engine.h:133
fl::uptr uintptr_t
Definition s16x16x4.h:223
@ FLEXIO
Teensy 4.x-only FlexIO capture backend (FLEXIO1 — FLEXIO2 is owned by the WS2812 TX driver)....
Definition types.h:14
@ FLEX_IO
Definition bus.h:40
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
void analogWrite(int pin, u16 val) FL_NO_EXCEPT
Write analog value to pin (PWM)
Definition pin.cpp.hpp:247
pair_element< I, T1, T2 >::type & get(pair< T1, T2 > &p) FL_NO_EXCEPT
Definition pair.h:119
constexpr ClocklessEncoder encoder_for() FL_NO_EXCEPT
Extract the encoder selector from a compile-time TIMING type.
fl::u64 u64
Definition s16x16x4.h:221
void digitalWrite(int pin, PinValue val) FL_NO_EXCEPT
Write digital value to pin.
Definition pin.cpp.hpp:51
void pinMode(int pin, PinMode mode) FL_NO_EXCEPT
Set pin mode (input, output, pull-up, pull-down)
Definition pin.cpp.hpp:398
void delayMicroseconds(u32 us) FL_NO_EXCEPT
Delay for a given number of microseconds.
unsigned char uint8_t
Definition s16x16x4.h:209
corkscrew_args args
Definition old.h:149
Promise-based fluent API for FastLED - standalone async primitives.
#define FL_NO_EXCEPT
Umbrella header for SIMD subsystem.
@ Green
<div style='background:#008000;width:4em;height:4em;'></div>
Definition crgb.h:565
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:629
@ Blue
<div style='background:#0000FF;width:4em;height:4em;'></div>
Definition crgb.h:519
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:517
u32 ns
Duration in nanoseconds (31 bits, max ~2.1s)
Definition rx.h:35
int captureWaitResult
RxWaitResult value, or -1 before wait.
int rawEdgesAfterWait
Raw edges visible after RX wait/decode.
fl::string rxBeginError
Machine-readable reason when RX begin() fails.