Skip to content

Commit

Permalink
Merge pull request #1964 from dberlin/main
Browse files Browse the repository at this point in the history
Add support for STM32 input capture filter
  • Loading branch information
xoviat authored Sep 28, 2023
2 parents b1b32f0 + 23f3889 commit ee55910
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions embassy-stm32/src/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ee55910

Please sign in to comment.