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>
impl<TIMERX: CaptureOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> CaptureChannel<TIMERX, PIN, C>
Sourcepub fn disable(&mut self)
pub fn disable(&mut self)
Stops latching, leaving the channel configured and its last value intact.
Sourcepub fn select_edge(&mut self, edge: Edge)
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.
Sourcepub fn listen(&mut self)
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.
Sourcepub fn is_listening(&self) -> bool
pub fn is_listening(&self) -> bool
Whether this channel’s captures reach the NVIC.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Whether a timestamp is waiting to be read.
Sourcepub fn read(&mut self) -> Result<u16, Error>
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.
Sourcepub fn interval<const NOM: u64, const DENOM: u64>(
&self,
from: u16,
to: u16,
) -> Duration<u32, NOM, DENOM>
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.