Skip to content

ports/esp32: Treat Pin mode -1 as unchanged. - #19504

Open
giri256 wants to merge 1 commit into
micropython:masterfrom
giri256:fix/esp32-pin-mode-sentinel-19456
Open

giri256 wants to merge 1 commit into
micropython:masterfrom
giri256:fix/esp32-pin-mode-sentinel-19456

Conversation

@giri256

@giri256 giri256 commented Jul 22, 2026 •

Copy link
Copy Markdown

Summary

On the ESP32 port, machine.Pin documents mode=-1 as the sentinel for
leaving the current pin mode unchanged. The implementation instead forwarded
-1 to gpio_set_direction(), where its set bits could enable input, output,
and open-drain mode together.

This change:

  • uses -1 as the constructor's mode default;
  • treats both mode=-1 and mode=None as no-change values;
  • skips RTC deinitialization and gpio_set_direction() for the sentinel; and
  • adds ESP32 tests for both constructor and Pin.init() paths.

Fixes #19456.

Testing

  • All ESP32 IDF build matrices passed in the first upstream CI run.
  • Code formatting, codespell, ruff, coverage, and the remaining build/test
    matrices passed.
  • The code-size report shows no size change.
  • tools/ci.sh commit_formatting_run passes after correcting the commit
    prefix, message wrapping, author email, and sign-off.
  • The C source was formatted with the repository's uncrustify configuration.
  • The Python test passes ruff format --check and py_compile.

No ESP32 hardware was available locally, so the new hardware regression has not
been run on a physical board.

Trade-offs and Alternatives

The fix is limited to the documented no-change sentinel and preserves
mode=None compatibility. It has no reported code-size impact. Passing -1
through to ESP-IDF was rejected because it is not a valid no-change operation
there.

Generative AI

Generative AI tools were used to investigate, implement, test, and prepare this
PR.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Code size report:

Reference:  py/makeqstrdefs.py: Propagate out errors from parallel pp step. [b9cceaa]
Comparison: esp32: Treat Pin mode -1 as unchanged. [merge of 85da7df]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@codecov

codecov Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.55%. Comparing base (b9cceaa) to head (85da7df).
⚠️ Report is 371 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19504   +/-   ##
=======================================
  Coverage   98.55%   98.55%           
=======================================
  Files         179      179           
  Lines       23244    23244           
=======================================
  Hits        22908    22908           
  Misses        336      336           
Flag Coverage Δ
unix-coverage-32bit 98.55% <ø> (ø)
unix-coverage-64bit 98.48% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@projectgus

Copy link
Copy Markdown
Contributor

@giri256 Hi! Thanks for your contribution, but please edit the description to fill in the pull request template with an explanation of this change and to confirm you've met our Generative AI Policy.

@projectgus projectgus added port-esp32 needs-info This issue needs more information to be resolvable labels Jul 23, 2026
@giri256
giri256 force-pushed the fix/esp32-pin-mode-sentinel-19456 branch from 6ae3d9b to 50053db Compare July 23, 2026 01:47
Match the documented machine.Pin sentinel and the existing pull=-1
behavior.

Keep None accepted as a no-change value for compatibility, and add
coverage for both constructor and init paths.

Signed-off-by: Giridhar <[email protected]>
@giri256
giri256 force-pushed the fix/esp32-pin-mode-sentinel-19456 branch from 50053db to 85da7df Compare July 23, 2026 02:03
@projectgus projectgus removed the needs-info This issue needs more information to be resolvable label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

esp32: Pin(id, mode=-1) programs INPUT+OUTPUT+OPEN_DRAIN instead of "no change" (contradicts docs, inconsistent with pull=-1)

2 participants