Software-based Debounced GPIO #52344
Labels
area: GPIO
Enhancement
Changes/Updates/Additions to existing features
RFC
Request For Comments: want input from the community
Introduction
Implement a generic, software-based GPIO debounce driver.
Problem description
Zephyr has GPIO flags for hardware-based debouncing filters. Zephyr currently doesn't support a software-based debounced GPIO driver.
Proposed change
Leverage Zephyr GPIO APIs to implement a software debounced GPIO driver. The algorithm for debouncing will follow closely with Linux gpio_keys implementation. Zephyr already has a gpio-keys device tree binding, but there's no backing driver for it.
Detailed RFC
Proposed change (Detailed)
Generic Debounce Driver API
The interface into the driver will follow Zephyr’s gpio_driver_api. The callback to handle the interrupt will specify the new pin state when it changes.
Device Tree
The Zephyr gpio-keys device tree definition will define the gpio_spec and debounce interval time, which is a subset of the linux gpio-keys schema. The default debounce_interval shall be 30 milliseconds. The chosen node will help identify what the debounced GPIO pin is used for, like in below example, a volume up button.
SW Debounce Algorithm High Level Flow
When bounces occur, steps 10 thru 12 in figure above, will keep rescheduling the debounce_change_call_deferred until GPIO pin level settles. At that point we can read the pin for the new state. If the state has changed, the driver will invoke the client’s registered callback with the new pin state.
Dependencies
GPIO
Alternatives
Considered including a
type
property in device tree nodes to identify volume up/down or recovery buttons. This is not needed with using chosen node, leading to a reduced memory footprint.The gpio-keys schema has a
linux,code
property. This is used for reporting input_events from the interrupt which are then passed to designated handlers with this code. This is similar to using a ‘type’ property above. Zephyr has an event implementation that can support this. This adds a thread and an additional layer between driver and client to notify when pin state changes.The text was updated successfully, but these errors were encountered: