Skip to content

fix(autoresearch): segmented pin-discovery using FastLED pin map (#3446) - #3449

Merged
zackees merged 1 commit into
masterfrom
fix/3446-segmented-pin-discovery
Jun 30, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3446-segmented-pin-discovery

Conversation

@zackees

@zackees zackees commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes the auto-pin-discovery gap behind the user-reported (33, 34) short on classic ESP32 (#3446). Two coupled fixes:

1. Segmented host-side sweep

run_pin_discovery still scans one 8-pin window per RPC (firmware default stays at 0-8 — the historically-safe range). The auto_discover_pins host path now routes through a new run_pin_discovery_segmented wrapper that iterates five overlapping 8-pin windows covering the full classic-ESP32 GPIO range: (0-8, 8-16, 16-24, 24-32, 32-40). Overlap on the boundary pin keeps the straddling pairs reachable.

Why segmented:

  • A single 0-39 sweep would drive every reachable pin in one pass — hitting a strap/boot pin mid-sweep could reset the chip and lose the entire scan. Per-segment RPCs let the host catch a hang in window N, reconnect, log "GPIO 32-40 didn't respond", and continue with window N+1.
  • The scan log says exactly which window has the hit (or hung the chip).

2. Defer to FastLED's existing per-chip pin map

findConnectedPinsImpl no longer hard-codes pin numbers. It pulls FASTLED_UNUSABLE_PIN_MASK + SOC_GPIO_VALID_OUTPUT_GPIO_MASK straight from platforms/esp/32/core/fastpin_esp32.h — the same masks _ESPPIN<P>::validpin() enforces elsewhere — and consults them at runtime:

Category Mask source Behavior
reserved-by-FastLED FASTLED_UNUSABLE_PIN_MASK SPI flash (6-11), USB-JTAG (20), strap pins → pair skipped entirely
input-only SOC_GPIO_VALID_GPIO_MASK ∧ ¬_OUTPUT_GPIO_MASK GPIO34-39 on classic ESP32 → forward direction attempted; reverse skipped

Both filters surface in a new skippedPins: [{pin, reason}, ...] response field, which the Python log renders as "Skipped per FastLED pin-validity map: GPIO 6 (reserved-by-FastLED), …, GPIO 34 (input-only)". No more silent "no jumper found".

Validation

  • bash compile esp32dev --examples AutoResearch --no-filter — SUCCESS.
  • hardware: confirm segmented sweep finds the (33, 34) short on user's board.
  • CI matrix.

Why this matters

Before this PR: bash autoresearch esp32dev on a board with a real soldered short between GPIO 33 and 34 reports "AUTORESEARCH ABORTED - GPIO PRE-TEST FAILED" because the firmware-side scan never goes above pin 8.

After: the same command walks the five segments, the (32-40) window finds the pair, the host log says ✅ SEGMENTED PIN DISCOVERY: HIT in GPIO 32-40 with Found connected pins: TX (GPIO 33) → RX (GPIO 34).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Expanded pin auto-discovery to scan the full GPIO range in segmented passes, improving coverage without getting stuck on one bad range.
    • Added clearer reporting for skipped pins, including human-readable reasons when certain pins can’t be tested.
  • Bug Fixes

    • Prevents a single hung or crashed scan window from blocking the rest of the discovery process.
    • Avoids probing unsafe or reserved pins, reducing failed or invalid pin tests.

Two coupled fixes for the auto-pin-discovery flow that surfaced when
the user's ESP32-WROOM had a soldered short between GPIO 33 and 34 —
a pair completely invisible to the legacy 0-8 sweep.

1) **Segmented host-side sweep**

   `run_pin_discovery` still scans one 8-pin window per RPC, but
   `phases.py`'s `auto_discover_pins` path now routes through a new
   `run_pin_discovery_segmented` wrapper that iterates five
   overlapping 8-pin windows covering the full classic-ESP32 GPIO
   range: `(0-8, 8-16, 16-24, 24-32, 32-40)`. Overlap on the
   segment-boundary pin (8/16/24/32) keeps the straddling adjacent
   pairs reachable.

   Why segmented instead of one big sweep:

   * a single 0-39 RPC would drive every reachable pin in one pass —
     hitting a strap/boot pin mid-sweep could reset the chip and lose
     the entire scan. Per-segment RPCs let the host catch a hang in
     window N, reconnect, log "GPIO 32-40 didn't respond", and
     continue with window N+1.
   * the human-visible scan log says exactly which window contains
     the hit (or hung the chip), turning "I don't know why it failed"
     into actionable diagnostics.

2) **Defer to FastLED's existing per-chip pin validity table**

   `findConnectedPinsImpl` no longer hard-codes any pin numbers.
   It pulls `FASTLED_UNUSABLE_PIN_MASK` + `SOC_GPIO_VALID_OUTPUT_GPIO_MASK`
   straight from `platforms/esp/32/core/fastpin_esp32.h` — the same
   masks `_ESPPIN<P>::validpin()` enforces elsewhere — and consults
   them at runtime:

   * **reserved-by-FastLED** (`FASTLED_UNUSABLE_PIN_MASK`): SPI flash
     pads (6-11), USB-JTAG (20), per-chip strap pins. The pair is
     skipped entirely — driving any of them locks the chip up or
     corrupts the live flash transaction.
   * **input-only** (`SOC_GPIO_VALID_GPIO_MASK` but not
     `_OUTPUT_GPIO_MASK`): GPIO34-39 on classic ESP32. The pin can be
     used as RX, but `pinMode(p, OUTPUT)` is silently ignored — so
     the reverse direction test always false-negatives. The forward
     direction is still attempted.

   Both filters surface in a new `skippedPins: [{pin, reason}, ...]`
   field on the RPC response, which the Python log renders as
   `"Skipped per FastLED pin-validity map: GPIO 6 (reserved-by-FastLED),
   ..., GPIO 34 (input-only)"`. No more silent "no jumper found".

Local validation:

  bash compile esp32dev --examples AutoResearch --no-filter
  → SUCCESS (03m:42s)

Follow-up tasks (not in this PR):

* run the segmented sweep against the user's (33, 34) board to
  confirm the hit reaches the host log.
* extend the pin-map consult to non-ESP32 platforms (Teensy 4.x, RP2040)
  via their own `FastPin<P>::validpin()` tables.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit ec3f33c into master Jun 30, 2026
7 of 10 checks passed
@zackees
zackees deleted the fix/3446-segmented-pin-discovery branch June 30, 2026 20:11
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 48bdbd33-26a1-4246-9c8d-cacd6cd2aee9

📥 Commits

Reviewing files that changed from the base of the PR and between f4a537d and 916b0ae.

📒 Files selected for processing (3)
  • ci/autoresearch/gpio.py
  • ci/autoresearch/phases.py
  • examples/AutoResearch/AutoResearchRemote.cpp

📝 Walkthrough

Walkthrough

Adds segmented GPIO pin discovery to the autoresearch CI tooling, scanning overlapping 8-pin windows and isolating per-segment hangs/crashes. The AutoResearchRemote firmware sketch now uses FastLED's ESP32 pin validity/reservation masks to skip unsafe candidate pins during scanning and reports skip reasons via a new skippedPins RPC field, which the CI side parses and logs.

Changes

Segmented Pin Discovery and Skip Reporting

Layer / File(s) Summary
Firmware pin mask classification and skip recording
examples/AutoResearch/AutoResearchRemote.cpp
Adds ESP32 FastLED pin mask helpers (isFastLedValidOutputPin, isFastLedInputOnlyPin, isFastLedReservedPin), gates the adjacent-pin probing loop on these classifications, records skipped pins with reasons via a recordSkip lambda, and appends a skippedPins JSON array to the RPC response.
CI segmented discovery and skip log parsing
ci/autoresearch/gpio.py, ci/autoresearch/phases.py
Adds DEFAULT_PIN_DISCOVERY_SEGMENTS and run_pin_discovery_segmented to sweep overlapping 8-pin windows via run_pin_discovery, returning early on success and tracking crashed/hung segments; parses and logs skippedPins from RPC responses; updates phases.py to call the new segmented discovery function and imports.

Sequence Diagram(s)

sequenceDiagram
  participant phases_py as phases.py
  participant Segmented as run_pin_discovery_segmented
  participant Single as run_pin_discovery
  participant Firmware as AutoResearchRemote

  phases_py->>Segmented: auto_discover_pins(port)
  loop overlapping 8-pin windows
    Segmented->>Single: probe(start_pin, end_pin)
    Single->>Firmware: scan candidate pins via RPC
    Firmware->>Firmware: classify pins via FastLED masks, skip unsafe ones
    Firmware-->>Single: result + skippedPins
    Single-->>Segmented: PinDiscoveryResult
    alt success
      Segmented-->>phases_py: return success result
    else client crashed/hung
      Segmented->>Segmented: record crashed segment, continue
    end
  end
  Segmented-->>phases_py: failure result if all segments fail
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • FastLED/FastLED#2681: Both PRs rely on FastLED's ESP32 pin-validity/reservation masks to reject unsafe pins, with this PR propagating those decisions into findConnectedPinsImpl via skippedPins.
  • FastLED/FastLED#3245: Both PRs modify ci/autoresearch/gpio.py's run_pin_discovery recovery flow, with this PR's segmented discovery building on that same logic.

Poem

A rabbit hops through pins so wide,
Eight by eight, in overlapping stride,
Skip the strapped, skip the flash,
No more hangs to cause a crash,
🐰 Segment by segment, the wires align,
Through GPIO burrows, the signal is fine!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/3446-segmented-pin-discovery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant