Skip to main content

CaptureChannel

Struct CaptureChannel 

Source
pub struct CaptureChannel<TIMERX, PIN, const C: u8> { /* private fields */ }
Expand description

One capture input of a timer, configured and ready to be armed.

Channels of one timer share the time base (PSC belongs to their common counter); the edge and the latched value are the channel’s own.

Latching reaches separate registers, but all the enables live in one: enabling a channel while another is enabled elsewhere — from an interrupt, say — can lose one of the writes.

Implementations§

Source§

impl<TIMERX: CaptureOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> CaptureChannel<TIMERX, PIN, C>

Source

pub fn enable(&mut self)

Arms the channel, from here on latching the counter on every edge.

Source

pub fn disable(&mut self)

Stops latching, leaving the channel configured and its last value intact.

Source

pub fn select_edge(&mut self, edge: Edge)

Changes which edge the channel latches on.

Takes effect immediately, so an edge arriving during the switch belongs to whichever setting won the race; discard measurements spanning the change.

Source

pub fn listen(&mut self)

Lets a capture raise an interrupt.

Turns waiting for an edge from a busy loop into a wake-up, and shrinks the window in which the next edge could overwrite an unread timestamp — see Error::Overcapture.

No separate clear: read takes the flag down, being the same call a handler makes to collect the timestamp. The whole timer shares one NVIC line, so a handler serving several channels tells them apart by is_listening and is_pending together — the flag alone will not do, since an untouched channel still compares against zero after reset and raises its flag once per rollover. Unmasking the line is the caller’s.

Source

pub fn unlisten(&mut self)

Stops captures from raising an interrupt. Leaves the NVIC alone.

Source

pub fn is_listening(&self) -> bool

Whether this channel’s captures reach the NVIC.

Source

pub fn is_pending(&self) -> bool

Whether a timestamp is waiting to be read.

Source

pub fn read(&mut self) -> Result<u16, Error>

Takes the timestamp of the last edge, if one has arrived.

Returns WouldBlock while no edge has been latched since the previous read, so it can be polled or waited on with nb::block!. Flags are cleared on the way out. The value is the counter at the moment of the edge, not an interval — those come from feeding two of these to interval.

§Errors

Error::Overcapture when a further edge arrived before this read: the timestamp belongs to the later edge, the earlier one is lost. The next read is sound again.

Source

pub fn interval<const NOM: u64, const DENOM: u64>( &self, from: u16, to: u16, ) -> Duration<u32, NOM, DENOM>

Converts the span between two timestamps into a duration.

Takes them in capture order and counts forward from the first, so a rollover in between costs nothing — the subtraction wraps exactly as the counter does. Spans longer than one counter cycle come back wrong; keep the prescaler large enough that the signal fits. The scale comes from the binding, as in elapsed.

Auto Trait Implementations§

§

impl<TIMERX, PIN, const C: u8> Freeze for CaptureChannel<TIMERX, PIN, C>
where TIMERX: Freeze, PIN: Freeze,

§

impl<TIMERX, PIN, const C: u8> RefUnwindSafe for CaptureChannel<TIMERX, PIN, C>
where TIMERX: RefUnwindSafe, PIN: RefUnwindSafe,

§

impl<TIMERX, PIN, const C: u8> Send for CaptureChannel<TIMERX, PIN, C>
where TIMERX: Send, PIN: Send,

§

impl<TIMERX, PIN, const C: u8> Sync for CaptureChannel<TIMERX, PIN, C>
where TIMERX: Sync, PIN: Sync,

§

impl<TIMERX, PIN, const C: u8> Unpin for CaptureChannel<TIMERX, PIN, C>
where TIMERX: Unpin, PIN: Unpin,

§

impl<TIMERX, PIN, const C: u8> UnsafeUnpin for CaptureChannel<TIMERX, PIN, C>
where TIMERX: UnsafeUnpin, PIN: UnsafeUnpin,

§

impl<TIMERX, PIN, const C: u8> UnwindSafe for CaptureChannel<TIMERX, PIN, C>
where TIMERX: UnwindSafe, PIN: UnwindSafe,

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, !>

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.