Adding support for input capture prefilter configuration

master
Ryan Summers 2021-02-09 14:36:50 +01:00
parent 31781a9d0e
commit 2e358dea26
2 changed files with 21 additions and 4 deletions

View File

@ -44,12 +44,12 @@ impl InputStamper {
) -> Self {
// Utilize the TIM5 CH4 as an input capture channel - use TI4 (the DI0 input trigger) as the
// capture source.
let input_capture =
let mut input_capture =
timer_channel.into_input_capture(timers::tim5::CaptureSource4::TI4);
// FIXME: hack in de-glitching filter
let regs = unsafe { &*hal::stm32::TIM5::ptr() };
regs.ccmr2_input().modify(|_, w| w.ic4f().bits(0b0011));
// Do not prescale the input capture signal - require 8 consecutive samples to record an
// incoming event - this prevents spurious glitches from triggering captures.
input_capture.configure_filter(timers::InputFilter::Div1N8);
Self {
capture_channel: input_capture,

View File

@ -48,6 +48,13 @@ pub enum SlaveMode {
Trigger = 0b0110,
}
/// Optional input capture preconditioning filter configurations.
#[allow(dead_code)]
pub enum InputFilter {
Div1N1 = 0b0000,
Div1N8 = 0b0011,
}
macro_rules! timer_channels {
($name:ident, $TY:ident, $size:ty) => {
paste::paste! {
@ -334,6 +341,16 @@ macro_rules! timer_channels {
let regs = unsafe { &*<$TY>::ptr() };
regs.sr.read().[< cc $index of >]().bit_is_set()
}
/// Configure the input capture input pre-filter.
///
/// # Args
/// * `filter` - The desired input filter stage configuration. Defaults to disabled.
#[allow(dead_code)]
pub fn configure_filter(&mut self, filter: super::InputFilter) {
let regs = unsafe { &*<$TY>::ptr() };
regs.[< $ccmrx _input >]().modify(|_, w| w.[< ic $index f >]().bits(filter as u8));
}
}
// Note(unsafe): This manually implements DMA support for input-capture channels. This