Skip to content

feat(button): add hys_ctrl_mode for ESP32-P4 GPIO hysteresis support#712

Open
diplfranzhoepfinger wants to merge 1 commit into
espressif:masterfrom
diplfranzhoepfinger:feature/hys_ctrl_mode
Open

feat(button): add hys_ctrl_mode for ESP32-P4 GPIO hysteresis support#712
diplfranzhoepfinger wants to merge 1 commit into
espressif:masterfrom
diplfranzhoepfinger:feature/hys_ctrl_mode

Conversation

@diplfranzhoepfinger
Copy link
Copy Markdown

Description

The ESP32-P4 GPIO peripheral supports hardware input hysteresis (SOC_GPIO_SUPPORT_PIN_HYS_FILTER). The ESP-IDF gpio_config_t already exposes the hys_ctrl_mode field for this chip, but the button component never forwarded it — meaning users had no way to enable hysteresis for a GPIO button.

Problem: When a button signal rises or falls slowly through the GPIO switching threshold (e.g. with long cable capacitance or a weak pull resistor), the digital input toggles rapidly around that threshold. This produces a burst of spurious BUTTON_PRESS_DOWN / BUTTON_PRESS_UP events even though the user pressed or released the button only once.

Fix: Add an optional hys_ctrl_mode field to button_gpio_config_t. On ESP32-P4, setting GPIO_HYS_SOFT_ENABLE activates the hardware hysteresis filter before the signal reaches the GPIO input register, eliminating the glitch without any software workaround. The field is guarded by #if SOC_GPIO_SUPPORT_PIN_HYS_FILTER, so the struct layout and ABI are unchanged on all other chips.

Changes:

  • components/button/include/button_gpio.h — added #include "driver/gpio.h" and the new hys_ctrl_mode field (behind SOC_GPIO_SUPPORT_PIN_HYS_FILTER guard)
  • components/button/button_gpio.c — pass hys_ctrl_mode into gpio_config_t (behind same guard)
  • components/button/idf_component.yml — version bump 4.1.6 → 4.1.7
  • components/button/CHANGELOG.md — added v4.1.7 entry

Usage on ESP32-P4:

button_gpio_config_t gpio_cfg = {
    .gpio_num      = 0,
    .active_level  = 0,
#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
    .hys_ctrl_mode = GPIO_HYS_SOFT_ENABLE,
#endif
};

Existing code that does not set the field continues to work unchanged (calloc zero-initialises the struct, which maps to hysteresis disabled).

Related

Fixes #663

Testing

  • Compiled for esp32p4 target: gpio_conf.hys_ctrl_mode is picked up correctly, no warnings.
  • Compiled for esp32s3 / esp32c3 targets: #if SOC_GPIO_SUPPORT_PIN_HYS_FILTER evaluates to false, struct and .c code compile unchanged — no regressions.
  • Manual test on ESP32-P4 EVB: GPIO with a slow-rising edge (RC ~ 10 ms) previously produced 5–10 spurious events per press; with GPIO_HYS_SOFT_ENABLE exactly one BUTTON_PRESS_DOWN and one BUTTON_PRESS_UP event are received.

Checklist

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

Note on Tests: The existing test_apps/ GPIO button tests compile and pass unchanged. A dedicated unit test for the hysteresis path would require hardware (ESP32-P4) and a controlled slow-edge signal source, which is beyond the scope of a CI-only check — the manual test result is described above.

Extend button_gpio_config_t with hys_ctrl_mode (guarded by
SOC_GPIO_SUPPORT_PIN_HYS_FILTER) and pass it through to gpio_config().
On ESP32-P4, setting GPIO_HYS_SOFT_ENABLE prevents spurious
PRESS_DOWN/PRESS_UP events when the input signal glitches around the
switching threshold. No functional change on chips without hysteresis
support. Bumps version to 4.1.7.

Fixes espressif#663

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 4, 2026

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hys_ctrl_mode for BUTTON Component (AEGHB-1418)

3 participants