From 23f3889167903c6e800f056517c2c831e73ed081 Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Thu, 28 Sep 2023 09:35:43 -0400 Subject: [PATCH] Add support for STM32 input capture filter --- embassy-stm32/src/timer/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index ea72b36ae..1d642ed37 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -56,6 +56,8 @@ pub(crate) mod sealed { } pub trait CaptureCompare16bitInstance: GeneralPurpose16bitInstance { + fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf); + fn clear_input_interrupt(&mut self, channel: Channel); fn enable_input_interrupt(&mut self, channel: Channel, enable: bool); @@ -93,6 +95,8 @@ pub(crate) mod sealed { } pub trait CaptureCompare32bitInstance: GeneralPurpose32bitInstance { + fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf); + fn clear_input_interrupt(&mut self, channel: Channel); fn enable_input_interrupt(&mut self, channel: Channel, enable: bool); @@ -338,6 +342,14 @@ macro_rules! impl_32bit_timer { macro_rules! impl_compare_capable_16bit { ($inst:ident) => { impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { + fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf) { + use sealed::GeneralPurpose16bitInstance; + let raw_channel = channel.raw(); + Self::regs_gp16() + .ccmr_input(raw_channel / 2) + .modify(|r| r.set_icf(raw_channel % 2, icf)); + } + fn clear_input_interrupt(&mut self, channel: Channel) { use sealed::GeneralPurpose16bitInstance; Self::regs_gp16() @@ -463,6 +475,14 @@ foreach_interrupt! { impl GeneralPurpose32bitInstance for crate::peripherals::$inst {} impl sealed::CaptureCompare32bitInstance for crate::peripherals::$inst { + fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf) { + use sealed::GeneralPurpose32bitInstance; + let raw_channel = channel.raw(); + Self::regs_gp32() + .ccmr_input(raw_channel / 2) + .modify(|r| r.set_icf(raw_channel % 2, icf)); + } + fn clear_input_interrupt(&mut self, channel: Channel) { use sealed::GeneralPurpose32bitInstance; Self::regs_gp32() @@ -591,6 +611,14 @@ foreach_interrupt! { } impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { + fn set_input_capture_filter(&mut self, channel: Channel, icf: vals::Icf) { + use crate::timer::sealed::AdvancedControlInstance; + let raw_channel = channel.raw(); + Self::regs_advanced() + .ccmr_input(raw_channel / 2) + .modify(|r| r.set_icf(raw_channel % 2, icf)); + } + fn clear_input_interrupt(&mut self, channel: Channel) { use crate::timer::sealed::AdvancedControlInstance; Self::regs_advanced()