embassy-nrf

Crates

git

Versions

nrf52833

Flavors

Skip to main content

Qdec

Struct Qdec 

Source
pub struct Qdec<'d> { /* private fields */ }
Expand description

Quadrature decoder driver.

Implementations§

Source§

impl<'d> Qdec<'d>

Source

pub fn new<T: Instance>( qdec: Peri<'d, T>, a: Peri<'d, impl GpioPin>, b: Peri<'d, impl GpioPin>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, config: Config, ) -> Self

Create a new QDEC.

Source

pub fn new_with_led<T: Instance>( qdec: Peri<'d, T>, a: Peri<'d, impl GpioPin>, b: Peri<'d, impl GpioPin>, led: Peri<'d, impl GpioPin>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, config: Config, ) -> Self

Create a new QDEC, with a pin for LED output.

Source

pub async fn read(&mut self) -> i16

Perform an asynchronous read of the decoder. The returned future can be awaited to obtain the number of steps accumulated since the previous read.

This method is cancel-safe: if the future is dropped before it completes, no counts are lost; they stay in the accumulator and are returned by the next read.

§Example
use embassy_nrf::qdec::{self, Qdec};
use embassy_nrf::{bind_interrupts, peripherals};

bind_interrupts!(struct Irqs {
    QDEC => qdec::InterruptHandler<peripherals::QDEC>;
});

let config = qdec::Config::default();
let mut q = Qdec::new(p.QDEC, p.P0_31, p.P0_30, Irqs, config);
let delta = q.read().await;

Auto Trait Implementations§

§

impl<'d> !RefUnwindSafe for Qdec<'d>

§

impl<'d> !UnwindSafe for Qdec<'d>

§

impl<'d> Freeze for Qdec<'d>

§

impl<'d> Send for Qdec<'d>

§

impl<'d> Sync for Qdec<'d>

§

impl<'d> Unpin for Qdec<'d>

§

impl<'d> UnsafeUnpin for Qdec<'d>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.