[−][src]Struct unflappable::Debouncer
A pin debouncer.
Since this needs to be shared between the main application code and the interupt service routine, it is generally put into a static.
For technical reasons the zero value of the storage type
Debounce::Storage
must be
provided this type's constructor. For this reason, the preferred
way to create a Debouncer
is with the macro
debouncer_uninit!
.
use unflappable::{debouncer_uninit, Debouncer, default::ActiveLow}; static PIN_DEBOUNCER: Debouncer<PinType, ActiveLow> = debouncer_uninit!();
Later, in your main application code, you can initialize it with
the relevant input pin. This returns the Debounced
pin for your use.
let debounced_pin = unsafe { DEBOUNCER.init(input_pin) }?;
Finally, make sure to arrange for regular polling of the Debouncer
.
unsafe { DEBOUNCER.poll()?; }
Implementations
impl<Pin: InputPin, Cfg: Debounce> Debouncer<Pin, Cfg>
[src]
pub unsafe fn init(&self, pin: Pin) -> Result<Debounced<Cfg>, InitError>
[src]
Initialize the pin debouncer for a given input pin.
Returns an error if the Debouncer
has already be initialized.
Safety
For this call to be safe, you must ensure that it is not run
concurrently with a call to any unsafe method of this type,
including init()
itself. The usual way to do this is by
calling init()
once before enabling interrupts.
Examples
let debounced_pin = unsafe { DEBOUNCER.init(input_pin) }?;
pub unsafe fn poll(&self) -> Result<(), PollError<Pin::Error>>
[src]
Poll the pin debouncer.
This should be done on a regular basis at roughly the frequency
used in the calculation of MAX_COUNT
.
Safety
For this method to be safe, you must ensure that it is not run
concurrently with a call to any unsafe method of this type,
including poll()
itself. The usual way to do this is to call
poll()
from a single interrupt service routine, and not
enable interrupts until after the call to init()
returns.
Examples
unsafe { DEBOUNCER.poll()?; }
pub const fn uninit(zero: Cfg::Storage) -> Self
[src]
Create a new, uninitialized pin debouncer.
For technical reasons, you must pass in the zero value of the
storage type Debounce::Storage
,
so prefer the macro debouncer_uninit!
.
pub unsafe fn deinit<'a>(
&self,
pin: Debounced<'a, Cfg>
) -> Result<Pin, DeinitError<'a, Cfg>>
[src]
&self,
pin: Debounced<'a, Cfg>
) -> Result<Pin, DeinitError<'a, Cfg>>
Destroy the debounced pin, returning the original input pin.
You must pass in the debounced pin produced from the call to
init()
. Returns an error if called with a
Debounced
pin not associated with this Debouncer
.
Restores this Debouncer
to the uninitialized state.
Safety
For this method to be safe, you must ensure that it is not run
concurrently with a call to any unsafe method of this type,
including deinit()
itself.
If you only ever poll()
in an interrupt service routine, you
call this method in main application code, your architecture
guarantees that main application code never preempts an
interrupt service routine, and you disable interrupts before
calling it, this will be safe.
Trait Implementations
Auto Trait Implementations
impl<Pin, Cfg> Send for Debouncer<Pin, Cfg> where
Cfg: Send,
Pin: Send,
<Cfg as Debounce>::Storage: Send,
Cfg: Send,
Pin: Send,
<Cfg as Debounce>::Storage: Send,
impl<Pin, Cfg> Unpin for Debouncer<Pin, Cfg> where
Cfg: Unpin,
Pin: Unpin,
<Cfg as Debounce>::Storage: Unpin,
Cfg: Unpin,
Pin: Unpin,
<Cfg as Debounce>::Storage: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,