feat(button): add hys_ctrl_mode for ESP32-P4 GPIO hysteresis support#712
Open
diplfranzhoepfinger wants to merge 1 commit into
Open
feat(button): add hys_ctrl_mode for ESP32-P4 GPIO hysteresis support#712diplfranzhoepfinger wants to merge 1 commit into
diplfranzhoepfinger wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The ESP32-P4 GPIO peripheral supports hardware input hysteresis (
SOC_GPIO_SUPPORT_PIN_HYS_FILTER). The ESP-IDFgpio_config_talready exposes thehys_ctrl_modefield for this chip, but thebuttoncomponent 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_UPevents even though the user pressed or released the button only once.Fix: Add an optional
hys_ctrl_modefield tobutton_gpio_config_t. On ESP32-P4, settingGPIO_HYS_SOFT_ENABLEactivates 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 newhys_ctrl_modefield (behindSOC_GPIO_SUPPORT_PIN_HYS_FILTERguard)components/button/button_gpio.c— passhys_ctrl_modeintogpio_config_t(behind same guard)components/button/idf_component.yml— version bump 4.1.6 → 4.1.7components/button/CHANGELOG.md— added v4.1.7 entryUsage on ESP32-P4:
Existing code that does not set the field continues to work unchanged (
calloczero-initialises the struct, which maps to hysteresis disabled).Related
Fixes #663
Testing
esp32p4target:gpio_conf.hys_ctrl_modeis picked up correctly, no warnings.esp32s3/esp32c3targets:#if SOC_GPIO_SUPPORT_PIN_HYS_FILTERevaluates to false, struct and.ccode compile unchanged — no regressions.GPIO_HYS_SOFT_ENABLEexactly oneBUTTON_PRESS_DOWNand oneBUTTON_PRESS_UPevent are received.Checklist