Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for STM32 input capture filter #1964

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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