Struct Unit

Source
#[non_exhaustive]
pub struct Unit<'d, const NUM: usize> { pub counter: Counter<'d, NUM>, pub channel0: Channel<'d, NUM, 0>, pub channel1: Channel<'d, NUM, 1>, /* private fields */ }
Available on crate feature unstable only.
Expand description

Represents a pulse counter unit.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§counter: Counter<'d, NUM>

The counter for PCNT unit.

§channel0: Channel<'d, NUM, 0>

The first channel in PCNT unit.

§channel1: Channel<'d, NUM, 1>

The second channel in PCNT unit.

Implementations§

Source§

impl<const NUM: usize> Unit<'_, NUM>

Source

pub fn set_low_limit(&self, value: Option<i16>) -> Result<(), InvalidLowLimit>

Configures a lower limit to the count value.

When the count drops to this value:

  • A low limit interrupt is triggered.
  • The count is reset to 0.

If None is specified, then no interrupt is triggered and the count wraps around after [i16::MIN].

Note: The specified value must be negative.

Source

pub fn set_high_limit(&self, value: Option<i16>) -> Result<(), InvalidHighLimit>

Configures a high limit to the count value.

When the count rises to this value:

  • A high limit interrupt is triggered.
  • The count is reset to 0.

If None is specified, then no interrupt is triggered and the count wraps around after [i16::MAX].

Note: The specified value must be positive.

Source

pub fn set_threshold0(&self, value: Option<i16>)

Configures a threshold value to trigger an interrupt.

When the count equals this value a threshold0 interrupt is triggered. If None is specified, then no interrupt is triggered.

Source

pub fn set_threshold1(&self, value: Option<i16>)

Configures a threshold value to trigger an interrupt.

When the count equals this value a threshold1 interrupt is triggered. If None is specified, then no interrupt is triggered.

Source

pub fn set_filter( &self, threshold: Option<u16>, ) -> Result<(), InvalidFilterThreshold>

Configures the glitch filter hardware of the unit.

threshold is the minimum number of APB_CLK cycles for a pulse to be considered valid. If it is None, the filter is disabled.

Note: This maximum possible threshold is 1023.

Source

pub fn clear(&self)

Resets the counter value to zero.

Source

pub fn pause(&self)

Pause the counter

Source

pub fn resume(&self)

Resume the counter

Source

pub fn events(&self) -> Events

Get the latest events for this unit.

Source

pub fn zero_mode(&self) -> ZeroMode

Get the mode of the last zero crossing

Source

pub fn listen(&self)

Enable interrupts for this unit.

Source

pub fn unlisten(&self, _cs: CriticalSection<'_>)

Disable interrupts for this unit.

Source

pub fn interrupt_is_set(&self) -> bool

Returns true if an interrupt is active for this unit.

Source

pub fn reset_interrupt(&self)

Clear the interrupt bit for this unit.

Source

pub fn value(&self) -> i16

Get the current counter value.

Trait Implementations§

Source§

impl<const NUM: usize> Drop for Unit<'_, NUM>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<const NUM: usize> Send for Unit<'_, NUM>

Auto Trait Implementations§

§

impl<'d, const NUM: usize> Freeze for Unit<'d, NUM>

§

impl<'d, const NUM: usize> RefUnwindSafe for Unit<'d, NUM>

§

impl<'d, const NUM: usize> !Sync for Unit<'d, NUM>

§

impl<'d, const NUM: usize> Unpin for Unit<'d, NUM>

§

impl<'d, const NUM: usize> UnwindSafe for Unit<'d, NUM>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T, U> TryFrom<U> for T
where 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>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.