FastLED 3.9.15
Loading...
Searching...
No Matches

◆ setup()

void setup ( )

Definition at line 375 of file AutoResearch.ino.

375 {
376 // Initialize serial buffers with platform-specific configuration
377 // Must be called BEFORE Serial.begin()
379 fl::serial_begin(115200);
380#if defined(ARDUINO_USB_CDC_ON_BOOT) && ARDUINO_USB_CDC_ON_BOOT
381 // Make HWCDC writes drop instead of block when no host is reading.
382 // Without this, Serial.print() on ESP32-C3/C6/H2 can stall up to ~2s
383 // per call once the TX ring fills with no host draining it.
384 // See FastLED issue #2668 and arduino-esp32 PR #7583.
385 // Redundant with fl::serial_begin() which already sets this on HWCDC,
386 // kept as defense-in-depth for sketches that bypass fl::serial_begin.
387 Serial.setTxTimeoutMs(0); // ok serial - platform-specific TX timeout, no fl:: equivalent
388#endif
389 uint32_t serial_wait_start = millis();
390 while (!fl::serial_ready() && (millis() - serial_wait_start) < AUTORESEARCH_SERIAL_WAIT_MS); // Wait for serial monitor (early exits when connected)
391
392 FL_WARN("[SETUP] AutoResearch sketch starting - serial output active");
393
394 // Note: the unified watchdog is armed lazily by FL_WATCHDOG_AUTO() at the
395 // top of loop() — no explicit setup() call needed. The macro prints the
396 // prior-boot reset info via ResetInfo::describe() and pauses 3 s on crash
397 // before the new timer arms. Per-platform boot diagnostics (Teensy 4
398 // SRC_SRSR bit decode + bundled CrashReport, ESP32 panic backtrace, etc.)
399 // are emitted by the platform watchdog impl from Watchdog::begin() — see
400 // src/fl/wdt/watchdog.h and src/platforms/*/watchdog_*.impl.hpp.
401
402 // Initialize RX buffer dynamically (uses PSRAM if available, falls back to heap)
404
405 // Initialize global autoresearch state
409 g_autoresearch_state->default_pin_tx = DEFAULT_PIN_TX;
410 g_autoresearch_state->default_pin_rx = DEFAULT_PIN_RX;
413
414 const char* loop_back_mode = PIN_TX == PIN_RX ? "INTERNAL" : "JUMPER WIRE";
415
416 // Build header and platform/hardware info
417 fl::sstream ss;
418 ss << "\n╔════════════════════════════════════════════════════════════════╗\n";
419 ss << "║ FastLED AutoResearch - Test Matrix Configuration ║\n";
420 ss << "╚════════════════════════════════════════════════════════════════╝\n";
421
422 // Platform information
423 ss << "\n[PLATFORM]\n";
424 ss << " Chip: " << autoresearch::chipName() << "\n";
425
426 // Hardware configuration - machine-parseable for --expect autoresearch
427 ss << "\n[HARDWARE]\n";
428 ss << " TX Pin: " << PIN_TX << "\n"; // --expect "TX Pin: 0"
429 ss << " RX Pin: " << PIN_RX << "\n"; // --expect "RX Pin: 1"
430 ss << " RX Device: " << fl::toString(RX_BACKEND) << "\n";
431 ss << " Loopback Mode: " << loop_back_mode << "\n";
432 ss << " Color Order: RGB\n";
433 ss << " RX Buffer Size: " << RX_BUFFER_SIZE << " bytes";
434 FL_PRINT(ss.str());
435
436 // SIMD validation suite, Wave8 expansion micro-bench, and full PARLIO
437 // encode bench are RPC-driven — invoke via the `testSimd`,
438 // `wave8ExpandBenchmark`, and `parlioEncodeBenchmark` handlers in
439 // AutoResearchRemote.cpp. Do not add boot-time invocation blocks here;
440 // if RPC routing is broken on a platform, fix the routing (see #2541).
441
442 // ========================================================================
443 // RX Channel Setup
444 // ========================================================================
445
446 ss.clear();
447 ss << "\n[RX SETUP] Creating RX channel for LED autoresearch\n";
448 ss << "[RX CREATE] Creating RX channel on PIN " << PIN_RX
449 << " (" << (40000000 / 1000000) << "MHz, " << RX_BUFFER_SIZE << " symbols)";
450 FL_PRINT(ss.str());
451
453
454 if (!g_autoresearch_state->rx_channel) {
455 ss.clear();
456 ss << "[RX SETUP]: Failed to create RX channel\n";
457 ss << "[RX SETUP]: Check that RMT peripheral is available and not in use";
458 FL_ERROR(ss.str());
459 FL_ERROR("Sanity check failed - RX channel creation failed");
460 return;
461 }
462
463 ss.clear();
464 ss << "[RX CREATE] ✓ RX channel created successfully (will be initialized with config in begin())\n";
465 ss << "[RX SETUP] ✓ RX channel ready for LED autoresearch";
466 FL_PRINT(ss.str());
467
468 // PARLIO streaming validation (#2548) is now RPC-driven via the
469 // `parlioStreamValidate` handler registered in AutoResearchRemote.cpp.
470
471 // ========================================================================
472 // Remote RPC Function Registration (EARLY - before GPIO baseline test)
473 // ========================================================================
474 // IMPORTANT: Register RPC functions BEFORE the GPIO baseline test so that
475 // even if setup() fails early, the testGpioConnection command can be used
476 // to diagnose hardware connection issues.
477
478 ss.clear();
479 ss << "\n[REMOTE RPC] Registering JSON RPC functions for dynamic control";
480 FL_PRINT(ss.str());
481
482 // Initialize RemoteControl singleton and register all RPC functions
484
485 FL_PRINT("[REMOTE RPC] ✓ RPC system initialized (testGpioConnection available)");
486
487 // ========================================================================
488 // Async Task Setup - JSON-RPC Processing
489 // ========================================================================
490 FL_PRINT("[ASYNC] Setting up JSON-RPC async task (10ms interval)");
492 FL_PRINT("[ASYNC] ✓ JSON-RPC task registered with scheduler");
493
494 // Stub: register self-running autoresearch client (no-op on ESP32)
497
498 // ========================================================================
499 // GPIO Baseline Test - Verify GPIO→GPIO path works before testing PARLIO
500 // ========================================================================
501 ss.clear();
502 ss << "\n[GPIO BASELINE TEST] Testing GPIO " << PIN_TX << " → GPIO " << PIN_RX << " connectivity";
503 FL_PRINT(ss.str());
504
505 // GPIO baseline test moved to loop() - wait for RPC start signal before testing
506 // This allows JSON-RPC commands (testGpioConnection, findConnectedPins) to run first
507 FL_WARN("[GPIO BASELINE TEST] Deferred to loop() - waiting for RPC start signal");
508
509 // Post-#2428 the channel driver registry no longer auto-populates. This
510 // example needs every available driver enrolled with ChannelManager so the
511 // discovery + autoresearch loop below can enumerate them.
512 FastLED.enableAllDrivers();
513
514 // List all available drivers and store globally
515 g_autoresearch_state->drivers_available = FastLED.getDriverInfos();
516 ss.clear();
517 ss << "\n[DRIVER DISCOVERY]\n";
518 ss << " Found " << g_autoresearch_state->drivers_available.size() << " driver(s) available:\n";
519 for (fl::size i = 0; i < g_autoresearch_state->drivers_available.size(); i++) {
520 ss << " " << (i+1) << ". " << g_autoresearch_state->drivers_available[i].name.c_str()
521 << " (priority: " << g_autoresearch_state->drivers_available[i].priority
522 << ", enabled: " << (g_autoresearch_state->drivers_available[i].enabled ? "yes" : "no") << ")\n";
523 }
524 FL_PRINT(ss.str());
525
526 // Validate that expected drivers are available for this platform
528
529 // Emit JSON-RPC ready event for Python orchestration
530 fl::json readyData = fl::json::object();
531 readyData.set("ready", true);
532 readyData.set("setupTimeMs", static_cast<int64_t>(millis()));
533 readyData.set("drivers", static_cast<int64_t>(g_autoresearch_state->drivers_available.size()));
534 readyData.set("pinTx", static_cast<int64_t>(PIN_TX));
535 readyData.set("pinRx", static_cast<int64_t>(PIN_RX));
536 printStreamRaw("ready", readyData);
537
538 // Human-readable diagnostics (not machine-parsed)
539 FL_PRINT("\n[SETUP COMPLETE] AutoResearch ready - awaiting JSON-RPC commands");
540 delay(2000);
541}
fl::shared_ptr< AutoResearchState > g_autoresearch_state
constexpr int DEFAULT_PIN_RX
constexpr int RX_BUFFER_SIZE
#define PIN_TX
const fl::RxBackend RX_BACKEND
#define PIN_RX
constexpr int DEFAULT_PIN_TX
fl::vector_psram< uint8_t > g_rx_buffer_storage
void init_serial_buffers()
static constexpr uint32_t AUTORESEARCH_SERIAL_WAIT_MS
fl::shared_ptr< fl::RxChannel > createRxDevice(int pin)
void autoResearchExpectedEngines()
AutoResearch that expected engines are available for this platform Prints ERROR if any expected engin...
void printStreamRaw(const char *messageType, const fl::json &data)
Print JSONL stream message directly to Serial, bypassing fl::println.
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
void registerFunctions(fl::shared_ptr< AutoResearchState > state)
Register all RPC functions with shared autoresearch state.
static AutoResearchRemoteControl & instance() FL_NOEXCEPT
Definition singleton.h:41
void set(const fl::string &key, const json &value) FL_NOEXCEPT
Definition json.h:701
static json object() FL_NOEXCEPT
Definition json.h:692
string str() const FL_NOEXCEPT
Definition strstream.h:43
void clear() FL_NOEXCEPT
Definition strstream.h:358
#define FL_WARN(X)
Definition log.h:276
#define FL_ERROR(X)
Definition log.h:219
#define FL_PRINT(X)
Print without prefix (like FL_WARN but without "WARN: " prefix) Uses sstream for dynamic formatting (...
Definition log.h:457
fl::task::Handle setupRpcAsyncTask(AutoResearchRemoteControl &remote_control, int interval_ms=10)
Setup async task for JSON-RPC processing.
void maybeRegisterStubAutorun(AutoResearchRemoteControl &, fl::shared_ptr< AutoResearchState > state)
On FL_IS_STUB: register a one-shot async task that drives autoresearch.
constexpr const char * chipName()
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
void delay(u32 ms, bool run_async=true) FL_NOEXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
Definition delay.h:98
void serial_begin(u32 baudRate)
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
bool serial_ready()
const char * toString(RxDeviceType type) FL_NOEXCEPT
Convert RxDeviceType to human-readable string.
Definition rx.h:177
#define Serial
Definition serial.h:304

References AUTORESEARCH_SERIAL_WAIT_MS, autoResearchExpectedEngines(), autoresearch::chipName(), fl::sstream::clear(), createRxDevice(), DEFAULT_PIN_RX, DEFAULT_PIN_TX, FastLED, FL_ERROR, FL_PRINT, FL_WARN, g_autoresearch_state, g_rx_buffer_storage, init_serial_buffers(), fl::Singleton< AutoResearchRemoteControl >::instance(), fl::make_shared(), autoresearch::maybeRegisterStubAutorun(), fl::json::object(), PIN_RX, PIN_TX, printStreamRaw(), AutoResearchRemoteControl::registerFunctions(), RX_BACKEND, RX_BUFFER_SIZE, Serial, fl::serial_begin(), fl::serial_ready(), fl::json::set(), autoresearch::setupRpcAsyncTask(), fl::sstream::str(), and fl::toString().

+ Here is the call graph for this function: