~couch/unflappable

A batteries-included embedded-hal InputPin debouncer.
df3a919c — Andrew Dona-Couch 1 year, 11 months ago
readme: comparison
1c2d8fd1 — Andrew Dona-Couch 1 year, 11 months ago
readme: add embedded-controls to comparison table
3a0ce4ef — Andrew Dona-Couch 1 year, 11 months ago
readme: add bounced to comparison table

clone

read-only
https://git.sr.ht/~couch/unflappable
read/write
git@git.sr.ht:~couch/unflappable

You can also use your local clone with git send-email.

#unflappable

A batteries-included embedded-hal InputPin debouncer.

#Quickstart

Add the following to your Cargo.toml:

[dependencies]
unflappable = "0.2"

Create an uninitialized Debouncer in static storage.

use unflappable::{debouncer_uninit, Debouncer, default::ActiveLow};
static DEBOUNCER: Debouncer<PinType, ActiveLow> = debouncer_uninit!();

Initialize the Debouncer with your input pin, returning the Debounced pin. Use this pin just as you would any other InputPin, such as passing ownership to another abstraction.

let debounced_pin = unsafe { DEBOUNCER.init(input_pin) }?;

Regularly poll the Debouncer, perhaps in an interrupt service routine.

unsafe {
    DEBOUNCER.poll()?;
}

#Documentation

#API Docs

API docs are hosted on docs.rs:

API Documentation

#Minimum Supported Rust Version

This crate makes use of trait bounds on a const fn, which requires Rust 1.61.

#Comparison to other debounce crates

There are a handful of debouncing crates targeting embedded Rust development. How does this one compare to the others?

  • Crate: unflappable
    • Wraps InputPin: Yes
    • Can move wrapped pin: Yes
    • Algorithm: Integration-based by Kuhn
    • State overhead: u8
  • Crate: debounced-pin
    • Wraps InputPin: Yes
    • Can move wrapped pin: No
    • Algorithm: Differentiation-based by Greensted
    • State overhead: u8 + enum
  • Crate: embedded-controls
    • Wraps switch_hal::InputSwitch: Yes
    • Can move wrapped pin: No
    • Algorithm: Timestamp-based
    • State overhead: timestamp + enum
  • Crate: bounced
    • Wraps InputPin: No
    • Can move wrapped pin: N/A
    • Algorithm: configurable
      • Integration-based similar to Kuhn
      • State overhead: 2 * u8
      • Shifting-based
      • State overhead: 2 ^ u8
  • Crate: debouncr
    • Wraps InputPin: No
    • Can move wrapped pin: N/A
    • Algorithm: Differentiation-based by Ganssle
    • State overhead: u8
  • Crate: debouncing
    • Wraps InputPin: No
    • Can move wrapped pin: N/A
    • Algorithm: Differentiation-based by Hackaday
    • State overhead: u8 + dynamically-allocated Vec

#Contributing

I'm happy to see any and all contributions, including bug reports, usability suggestions, patches, or angry yet well-intentioned rants. You are encouraged to report issues to the official issue tracker and send any questions or patches to the mailing list. Pull requests to the GitHub mirror are also acceptable.

Do not follow this link