diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs index 5fcd1ed0..b045a2d7 100644 --- a/embassy-stm32/src/pwm/simple_pwm.rs +++ b/embassy-stm32/src/pwm/simple_pwm.rs @@ -20,9 +20,9 @@ pub struct PwmPin<'d, Perip, Channel> { } macro_rules! channel_impl { - ($channel:ident, $pin_trait:ident) => { + ($new_chx:ident, $channel:ident, $pin_trait:ident) => { impl<'d, Perip: CaptureCompare16bitInstance> PwmPin<'d, Perip, $channel> { - pub fn new(pin: impl Peripheral

> + 'd) -> Self { + pub fn $new_chx(pin: impl Peripheral

> + 'd) -> Self { into_ref!(pin); critical_section::with(|_| unsafe { pin.set_low(); @@ -39,10 +39,10 @@ macro_rules! channel_impl { }; } -channel_impl!(Ch1, Channel1Pin); -channel_impl!(Ch2, Channel2Pin); -channel_impl!(Ch3, Channel3Pin); -channel_impl!(Ch4, Channel4Pin); +channel_impl!(new_ch1, Ch1, Channel1Pin); +channel_impl!(new_ch2, Ch2, Channel2Pin); +channel_impl!(new_ch3, Ch3, Channel3Pin); +channel_impl!(new_ch4, Ch4, Channel4Pin); pub struct SimplePwm<'d, T> { inner: PeripheralRef<'d, T>, @@ -51,10 +51,10 @@ pub struct SimplePwm<'d, T> { impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { pub fn new( tim: impl Peripheral

+ 'd, - _ch1: Option>, - _ch2: Option>, - _ch3: Option>, - _ch4: Option>, + _ch1: Option>, + _ch2: Option>, + _ch3: Option>, + _ch4: Option>, freq: Hertz, ) -> Self { Self::new_inner(tim, freq) diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs index c99f3cc2..b39bbbe2 100644 --- a/examples/stm32f4/src/bin/pwm.rs +++ b/examples/stm32f4/src/bin/pwm.rs @@ -5,7 +5,7 @@ use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_stm32::pwm::simple_pwm::SimplePwm; +use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::pwm::Channel; use embassy_stm32::time::khz; use embassy_stm32::Peripherals; @@ -15,7 +15,8 @@ use {defmt_rtt as _, panic_probe as _}; async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); - let mut pwm = SimplePwm::new_1ch(p.TIM1, p.PE9, khz(10)); + let ch1 = PwmPin::new_ch1(p.PE9); + let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10)); let max = pwm.get_max_duty(); pwm.enable(Channel::Ch1); diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index 579e289b..dc4e164a 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs @@ -5,7 +5,7 @@ use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_stm32::pwm::simple_pwm::SimplePwm; +use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::pwm::Channel; use embassy_stm32::time::khz; use embassy_stm32::Peripherals; @@ -15,7 +15,8 @@ use {defmt_rtt as _, panic_probe as _}; async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); - let mut pwm = SimplePwm::new_1ch(p.TIM2, p.PA5, khz(10)); + let ch1 = PwmPin::new_ch1(p.PA5); + let mut pwm = SimplePwm::new(p.TIM2, Some(ch1), None, None, None, khz(10)); let max = pwm.get_max_duty(); pwm.enable(Channel::Ch1); diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index f072c537..730f637e 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs @@ -5,7 +5,7 @@ use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_stm32::pwm::simple_pwm::SimplePwm; +use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm}; use embassy_stm32::pwm::Channel; use embassy_stm32::time::{khz, mhz}; use embassy_stm32::{Config, Peripherals}; @@ -27,7 +27,8 @@ pub fn config() -> Config { async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); - let mut pwm = SimplePwm::new_1ch(p.TIM3, p.PA6, khz(10)); + let ch1 = PwmPin::new_ch1(p.PA6); + let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10)); let max = pwm.get_max_duty(); pwm.enable(Channel::Ch1);