Merge pull request #265 from quartiq/rs/timer-input-filter-config

Adding support for input capture prefilter configuration
This commit is contained in:
Robert Jördens 2021-02-09 15:03:30 +01:00 committed by GitHub
commit 03cbd99aee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 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,18 @@ 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) {
// Note(unsafe): This channel owns all access to the specific timer channel.
// Only atomic operations on completed on the timer registers.
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