Skip to content

Feature request: more responsive debouncing for keypad scanners #8777

@xs5871

Description

@xs5871

I guess this falls under feature request:

I've been looking into implementing a more responsive debouncing algorithm for
the keypad module. The motivation should be obvious: the current implementation
is a scan rate limiter which effectively implies a random input delay between 0
and interval seconds, which can be undesirable in various applications.

What I have implemented and tested as a minimum impact improvement is an
additional parameter debounce_cycles to the scanner initialisation that allows
scans to skip a number of scan cycles after a state change, i.e. per-key greedy
symmetric debouncing.

KeyMatrix default signature for illustration:

KeyMatrix(
    row_pins=[...],
    col_pins=[...],
    interval=0.02,
    debounce_cycles=0,
)

It doesn't add a significant amount of ROM/RAM requirements compared to the
current implementation aside from the additional QSTR, and setting the default
debounce_cycles=0 makes the interface backwards compatible.
That could be reduced to a single parameter enforcing a scannig rate of let's
say 1ms, but personally I like that the scanning interval is adjustable to the
application and hardware, especially considering that the common use for
keypad is keyboards and controllers and the USB polling interval is 8ms or
more anyway.

Now, before submitting a PR I'd like to hear some opinions on that.

  • Would that be considered a worthwhile feature in general?
  • Is the additional parameter preferable to a single parameter solution that
    will break backwards compatibility (and potantially waste CPU cycles with
    agressive scanning)?
  • Is greedy symmetric debouncing good enough? Making it defered debouncing
    shouldn't affect the complexity and footprint, but further granularity will.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions