Trait unflappable::Debounce

source ·
pub trait Debounce {
    type Storage: From<u8> + BitAnd<Output = Self::Storage> + BitAndAssign + BitOr<Output = Self::Storage> + BitOrAssign + Not<Output = Self::Storage> + Shl<u8, Output = Self::Storage> + Shr<u8, Output = Self::Storage> + AddAssign + SubAssign + Eq + Copy;

    const MAX_COUNT: Self::Storage;
    const INIT_HIGH: bool;
}
Expand description

Static configuration of the debouncing algorithm.

Required Associated Types§

source

type Storage: From<u8> + BitAnd<Output = Self::Storage> + BitAndAssign + BitOr<Output = Self::Storage> + BitOrAssign + Not<Output = Self::Storage> + Shl<u8, Output = Self::Storage> + Shr<u8, Output = Self::Storage> + AddAssign + SubAssign + Eq + Copy

The storage type of the state. For most usages, u8 is plenty big enough. You almost certainly don’t need more than a u8.

Required Associated Constants§

source

const MAX_COUNT: Self::Storage

The number of samples required to mark a state change.

Unlike many debouncing algorithms, the integration approach doesn’t require a fixed number of consistent samples in a row. Rather, if in n + m samples we see n of the new state and m of the old state, a transition will be marked if the difference n - m reaches MAX_COUNT.

This should be configured based on the following formula: if d is the minimum debounce delay (in seconds), and f is the number of times the debouncer is polled per second, the MAX_COUNT should be set to the product d * f. For instance, if polling 100 times a second (100 Hz), with a minimum delay of 50 milliseconds, set this to 5.

Note: this must be non zero, and must be represented in two bits fewer than the storage you provide (e.g. if using u8, MAX_COUNT cannot exceed 0x3f. For the algorithm to perform any meaningful debouncing, it must be greater than 1.

source

const INIT_HIGH: bool

The initial state of the pin.

If INIT_HIGH is true, the debounced pin will start high and wait for the first falling edge. If this is false, the pin will start low and wait for the first debounced rising edge.

Implementors§

source§

impl Debounce for ActiveHigh

§

type Storage = u8

source§

const MAX_COUNT: Self::Storage = {transmute(0x04): <default::ActiveHigh as Debounce>::Storage}

source§

const INIT_HIGH: bool = false

source§

impl Debounce for ActiveLow

§

type Storage = u8

source§

const MAX_COUNT: Self::Storage = {transmute(0x04): <default::ActiveLow as Debounce>::Storage}

source§

const INIT_HIGH: bool = true

source§

impl Debounce for OriginalKuhn

§

type Storage = u8

source§

const MAX_COUNT: Self::Storage = {transmute(0x03): <default::OriginalKuhn as Debounce>::Storage}

source§

const INIT_HIGH: bool = false