pub trait HrCapture {
// Required methods
fn get_last(&self) -> (u16, CountingDirection);
fn clear_interrupt(&mut self);
fn is_pending(&self) -> bool;
// Provided methods
fn get(&mut self) -> Option<(u16, CountingDirection)> { ... }
fn get_signed(&mut self, period: u16) -> Option<i32> { ... }
fn get_last_signed(&self, period: u16) -> i32 { ... }
}
Expand description
Trait for capture channels used for capturing edges
let capture: HrCapt<_, _, _> = todo!();
if capture.is_pending() {
let (value, dir) = capture.get_last();
capture.clear_interrupt();
defmt::info!("Edge captured at counter value: {}, with: {}", value, dir);
}
or alternatively
let capture: HrCapt<_, _, _> = todo!();
if let Some((value, dir)) = capture.get() {
defmt::info!("Edge captured at counter value: {}, with: {}", value, dir);
}
Required Methods§
fn get_last(&self) -> (u16, CountingDirection)
fn clear_interrupt(&mut self)
fn is_pending(&self) -> bool
Provided Methods§
Sourcefn get(&mut self) -> Option<(u16, CountingDirection)>
fn get(&mut self) -> Option<(u16, CountingDirection)>
Try to get the capture value
Returns none if edge has been captured since last time
NOTE: This function will use Self::is_pending
to chech if there is a value available and
Self::clear_interrupt
to clear it.
Sourcefn get_signed(&mut self, period: u16) -> Option<i32>
fn get_signed(&mut self, period: u16) -> Option<i32>
Get number of ticks relative to beginning of up counting
where captures during down counting count as negative (before the upcount)
Counter
---------------------------------- <--- period
\ ^ /
\ | /
\ | /
\ | /
Down count \ | / Up count
\|/
<-------------- 0 --------------> t
Negative result | positive result
NOTE: This function will use Self::is_pending
to check if there is a value available and
Self::clear_interrupt
to clear it.
Sourcefn get_last_signed(&self, period: u16) -> i32
fn get_last_signed(&self, period: u16) -> i32
Get number of ticks relative to beginning of up counting
where captures during down counting count as negative (before the upcount)
Counter
---------------------------------- <--- period
\ ^ /
\ | /
\ | /
\ | /
Down count \ | / Up count
\|/
<-------------- 0 --------------> t
Negative result | positive result