Skip to main content

Unit

Struct Unit 

Source
#[non_exhaustive]
pub struct Unit<'d> { pub counter: Counter<'d>, pub channel0: Channel<'d, 0>, pub channel1: Channel<'d, 1>, /* private fields */ }
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>

The counter for PCNT unit.

§channel0: Channel<'d, 0>

The first channel in PCNT unit.

§channel1: Channel<'d, 1>

The second channel in PCNT unit.

Implementations§

Source§

impl<'d> Unit<'d>

Source

pub fn new(unit: impl Instance + 'd) -> Self

Returns a new PCNT unit.

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].

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].

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.

The maximum possible threshold is 1023.

Source

pub fn clear(&self)

Resets the counter value to zero.

Source

pub fn pause(&self)

Pauses the counter.

Source

pub fn resume(&self)

Resumes the counter.

Source

pub fn events(&self) -> Events

Returns the latest events for this unit.

Source

pub fn zero_mode(&self) -> ZeroMode

Returns the mode of the last zero crossing.

Source

pub fn listen(&self)

Enables interrupts for this unit.

Source

pub fn unlisten(&self)

Disables interrupts for this unit.

Source

pub fn interrupt_is_set(&self) -> bool

Returns whether an interrupt is active for this unit.

Source

pub fn reset_interrupt(&self)

Clears the interrupt bit for this unit.

Source

pub fn value(&self) -> i16

Returns the current counter value.

Source

pub fn set_interrupt_handler(&mut self, handler: InterruptHandler)

Available on crate feature unstable only.

Registers a handler invoked when this unit’s interrupt status bit is set.

The hardware interrupt is shared by every unit in the same PCNT register block. This method installs a dispatcher on that interrupt and records handler for this unit only.

This method ignores handler priority.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Trait Implementations§

Source§

impl Drop for Unit<'_>

Available on crate feature unstable only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl InterruptConfigurable for Unit<'_>

Available on crate feature unstable only.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

fn set_interrupt_handler(&mut self, handler: InterruptHandler)

Registers an interrupt handler for the peripheral. Read more
Source§

impl Send for Unit<'_>

Available on crate feature unstable only.

Auto Trait Implementations§

§

impl<'d> !Sync for Unit<'d>

§

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

§

impl<'d> Freeze for Unit<'d>

§

impl<'d> RefUnwindSafe for Unit<'d>

§

impl<'d> Unpin for Unit<'d>

§

impl<'d> UnsafeUnpin for Unit<'d>

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.