aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/timer')
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs14
-rw-r--r--embassy-stm32/src/timer/input_capture.rs15
-rw-r--r--embassy-stm32/src/timer/low_level.rs8
-rw-r--r--embassy-stm32/src/timer/mod.rs4
-rw-r--r--embassy-stm32/src/timer/pwm_input.rs24
-rw-r--r--embassy-stm32/src/timer/qei.rs14
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs42
7 files changed, 40 insertions, 81 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs
index 02c01e900..f543bafab 100644
--- a/embassy-stm32/src/timer/complementary_pwm.rs
+++ b/embassy-stm32/src/timer/complementary_pwm.rs
@@ -2,7 +2,6 @@
2 2
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4 4
5use embassy_hal_internal::{into_ref, PeripheralRef};
6use stm32_metapac::timer::vals::Ckd; 5use stm32_metapac::timer::vals::Ckd;
7 6
8use super::low_level::{CountingMode, OutputPolarity, Timer}; 7use super::low_level::{CountingMode, OutputPolarity, Timer};
@@ -14,13 +13,13 @@ use super::{
14use crate::gpio::{AnyPin, OutputType}; 13use crate::gpio::{AnyPin, OutputType};
15use crate::time::Hertz; 14use crate::time::Hertz;
16use crate::timer::low_level::OutputCompareMode; 15use crate::timer::low_level::OutputCompareMode;
17use crate::Peripheral; 16use crate::Peri;
18 17
19/// Complementary PWM pin wrapper. 18/// Complementary PWM pin wrapper.
20/// 19///
21/// This wraps a pin to make it usable with PWM. 20/// This wraps a pin to make it usable with PWM.
22pub struct ComplementaryPwmPin<'d, T, C> { 21pub struct ComplementaryPwmPin<'d, T, C> {
23 _pin: PeripheralRef<'d, AnyPin>, 22 _pin: Peri<'d, AnyPin>,
24 phantom: PhantomData<(T, C)>, 23 phantom: PhantomData<(T, C)>,
25} 24}
26 25
@@ -28,8 +27,7 @@ macro_rules! complementary_channel_impl {
28 ($new_chx:ident, $channel:ident, $pin_trait:ident) => { 27 ($new_chx:ident, $channel:ident, $pin_trait:ident) => {
29 impl<'d, T: AdvancedInstance4Channel> ComplementaryPwmPin<'d, T, $channel> { 28 impl<'d, T: AdvancedInstance4Channel> ComplementaryPwmPin<'d, T, $channel> {
30 #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] 29 #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")]
31 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, output_type: OutputType) -> Self { 30 pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, output_type: OutputType) -> Self {
32 into_ref!(pin);
33 critical_section::with(|_| { 31 critical_section::with(|_| {
34 pin.set_low(); 32 pin.set_low();
35 pin.set_as_af( 33 pin.set_as_af(
@@ -38,7 +36,7 @@ macro_rules! complementary_channel_impl {
38 ); 36 );
39 }); 37 });
40 ComplementaryPwmPin { 38 ComplementaryPwmPin {
41 _pin: pin.map_into(), 39 _pin: pin.into(),
42 phantom: PhantomData, 40 phantom: PhantomData,
43 } 41 }
44 } 42 }
@@ -60,7 +58,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
60 /// Create a new complementary PWM driver. 58 /// Create a new complementary PWM driver.
61 #[allow(clippy::too_many_arguments)] 59 #[allow(clippy::too_many_arguments)]
62 pub fn new( 60 pub fn new(
63 tim: impl Peripheral<P = T> + 'd, 61 tim: Peri<'d, T>,
64 _ch1: Option<PwmPin<'d, T, Ch1>>, 62 _ch1: Option<PwmPin<'d, T, Ch1>>,
65 _ch1n: Option<ComplementaryPwmPin<'d, T, Ch1>>, 63 _ch1n: Option<ComplementaryPwmPin<'d, T, Ch1>>,
66 _ch2: Option<PwmPin<'d, T, Ch2>>, 64 _ch2: Option<PwmPin<'d, T, Ch2>>,
@@ -75,7 +73,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
75 Self::new_inner(tim, freq, counting_mode) 73 Self::new_inner(tim, freq, counting_mode)
76 } 74 }
77 75
78 fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self { 76 fn new_inner(tim: Peri<'d, T>, freq: Hertz, counting_mode: CountingMode) -> Self {
79 let mut this = Self { inner: Timer::new(tim) }; 77 let mut this = Self { inner: Timer::new(tim) };
80 78
81 this.inner.set_counting_mode(counting_mode); 79 this.inner.set_counting_mode(counting_mode);
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs
index b7c13343c..0450f14fa 100644
--- a/embassy-stm32/src/timer/input_capture.rs
+++ b/embassy-stm32/src/timer/input_capture.rs
@@ -5,8 +5,6 @@ use core::marker::PhantomData;
5use core::pin::Pin; 5use core::pin::Pin;
6use core::task::{Context, Poll}; 6use core::task::{Context, Poll};
7 7
8use embassy_hal_internal::{into_ref, PeripheralRef};
9
10use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer}; 8use super::low_level::{CountingMode, FilterValue, InputCaptureMode, InputTISelection, Timer};
11use super::{ 9use super::{
12 CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, 10 CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin,
@@ -15,7 +13,7 @@ use super::{
15use crate::gpio::{AfType, AnyPin, Pull}; 13use crate::gpio::{AfType, AnyPin, Pull};
16use crate::interrupt::typelevel::{Binding, Interrupt}; 14use crate::interrupt::typelevel::{Binding, Interrupt};
17use crate::time::Hertz; 15use crate::time::Hertz;
18use crate::Peripheral; 16use crate::Peri;
19 17
20/// Channel 1 marker type. 18/// Channel 1 marker type.
21pub enum Ch1 {} 19pub enum Ch1 {}
@@ -30,7 +28,7 @@ pub enum Ch4 {}
30/// 28///
31/// This wraps a pin to make it usable with capture. 29/// This wraps a pin to make it usable with capture.
32pub struct CapturePin<'d, T, C> { 30pub struct CapturePin<'d, T, C> {
33 _pin: PeripheralRef<'d, AnyPin>, 31 _pin: Peri<'d, AnyPin>,
34 phantom: PhantomData<(T, C)>, 32 phantom: PhantomData<(T, C)>,
35} 33}
36 34
@@ -38,11 +36,10 @@ macro_rules! channel_impl {
38 ($new_chx:ident, $channel:ident, $pin_trait:ident) => { 36 ($new_chx:ident, $channel:ident, $pin_trait:ident) => {
39 impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> { 37 impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> {
40 #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] 38 #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")]
41 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, pull: Pull) -> Self { 39 pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, pull: Pull) -> Self {
42 into_ref!(pin);
43 pin.set_as_af(pin.af_num(), AfType::input(pull)); 40 pin.set_as_af(pin.af_num(), AfType::input(pull));
44 CapturePin { 41 CapturePin {
45 _pin: pin.map_into(), 42 _pin: pin.into(),
46 phantom: PhantomData, 43 phantom: PhantomData,
47 } 44 }
48 } 45 }
@@ -63,7 +60,7 @@ pub struct InputCapture<'d, T: GeneralInstance4Channel> {
63impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> { 60impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
64 /// Create a new input capture driver. 61 /// Create a new input capture driver.
65 pub fn new( 62 pub fn new(
66 tim: impl Peripheral<P = T> + 'd, 63 tim: Peri<'d, T>,
67 _ch1: Option<CapturePin<'d, T, Ch1>>, 64 _ch1: Option<CapturePin<'d, T, Ch1>>,
68 _ch2: Option<CapturePin<'d, T, Ch2>>, 65 _ch2: Option<CapturePin<'d, T, Ch2>>,
69 _ch3: Option<CapturePin<'d, T, Ch3>>, 66 _ch3: Option<CapturePin<'d, T, Ch3>>,
@@ -75,7 +72,7 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
75 Self::new_inner(tim, freq, counting_mode) 72 Self::new_inner(tim, freq, counting_mode)
76 } 73 }
77 74
78 fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self { 75 fn new_inner(tim: Peri<'d, T>, freq: Hertz, counting_mode: CountingMode) -> Self {
79 let mut this = Self { inner: Timer::new(tim) }; 76 let mut this = Self { inner: Timer::new(tim) };
80 77
81 this.inner.set_counting_mode(counting_mode); 78 this.inner.set_counting_mode(counting_mode);
diff --git a/embassy-stm32/src/timer/low_level.rs b/embassy-stm32/src/timer/low_level.rs
index 5b0c95109..8fc32c1f3 100644
--- a/embassy-stm32/src/timer/low_level.rs
+++ b/embassy-stm32/src/timer/low_level.rs
@@ -8,7 +8,7 @@
8 8
9use core::mem::ManuallyDrop; 9use core::mem::ManuallyDrop;
10 10
11use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; 11use embassy_hal_internal::Peri;
12// Re-export useful enums 12// Re-export useful enums
13pub use stm32_metapac::timer::vals::{FilterValue, Sms as SlaveMode, Ts as TriggerSource}; 13pub use stm32_metapac::timer::vals::{FilterValue, Sms as SlaveMode, Ts as TriggerSource};
14 14
@@ -181,7 +181,7 @@ impl From<OutputPolarity> for bool {
181 181
182/// Low-level timer driver. 182/// Low-level timer driver.
183pub struct Timer<'d, T: CoreInstance> { 183pub struct Timer<'d, T: CoreInstance> {
184 tim: PeripheralRef<'d, T>, 184 tim: Peri<'d, T>,
185} 185}
186 186
187impl<'d, T: CoreInstance> Drop for Timer<'d, T> { 187impl<'d, T: CoreInstance> Drop for Timer<'d, T> {
@@ -192,9 +192,7 @@ impl<'d, T: CoreInstance> Drop for Timer<'d, T> {
192 192
193impl<'d, T: CoreInstance> Timer<'d, T> { 193impl<'d, T: CoreInstance> Timer<'d, T> {
194 /// Create a new timer driver. 194 /// Create a new timer driver.
195 pub fn new(tim: impl Peripheral<P = T> + 'd) -> Self { 195 pub fn new(tim: Peri<'d, T>) -> Self {
196 into_ref!(tim);
197
198 rcc::enable_and_reset::<T>(); 196 rcc::enable_and_reset::<T>();
199 197
200 Self { tim } 198 Self { tim }
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs
index 97740c2ed..765a3d9fa 100644
--- a/embassy-stm32/src/timer/mod.rs
+++ b/embassy-stm32/src/timer/mod.rs
@@ -2,7 +2,7 @@
2 2
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4 4
5use embassy_hal_internal::Peripheral; 5use embassy_hal_internal::PeripheralType;
6use embassy_sync::waitqueue::AtomicWaker; 6use embassy_sync::waitqueue::AtomicWaker;
7 7
8#[cfg(not(stm32l0))] 8#[cfg(not(stm32l0))]
@@ -66,7 +66,7 @@ impl State {
66 } 66 }
67} 67}
68 68
69trait SealedInstance: RccPeripheral + Peripheral<P = Self> { 69trait SealedInstance: RccPeripheral + PeripheralType {
70 /// Async state for this timer 70 /// Async state for this timer
71 fn state() -> &'static State; 71 fn state() -> &'static State;
72} 72}
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs
index e3eb6042a..98b798634 100644
--- a/embassy-stm32/src/timer/pwm_input.rs
+++ b/embassy-stm32/src/timer/pwm_input.rs
@@ -1,12 +1,10 @@
1//! PWM Input driver. 1//! PWM Input driver.
2 2
3use embassy_hal_internal::into_ref;
4
5use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; 3use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource};
6use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel}; 4use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel};
7use crate::gpio::{AfType, Pull}; 5use crate::gpio::{AfType, Pull};
8use crate::time::Hertz; 6use crate::time::Hertz;
9use crate::Peripheral; 7use crate::Peri;
10 8
11/// PWM Input driver. 9/// PWM Input driver.
12pub struct PwmInput<'d, T: GeneralInstance4Channel> { 10pub struct PwmInput<'d, T: GeneralInstance4Channel> {
@@ -16,34 +14,20 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> {
16 14
17impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { 15impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
18 /// Create a new PWM input driver. 16 /// Create a new PWM input driver.
19 pub fn new( 17 pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl Channel1Pin<T>>, pull: Pull, freq: Hertz) -> Self {
20 tim: impl Peripheral<P = T> + 'd,
21 pin: impl Peripheral<P = impl Channel1Pin<T>> + 'd,
22 pull: Pull,
23 freq: Hertz,
24 ) -> Self {
25 into_ref!(pin);
26
27 pin.set_as_af(pin.af_num(), AfType::input(pull)); 18 pin.set_as_af(pin.af_num(), AfType::input(pull));
28 19
29 Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) 20 Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2)
30 } 21 }
31 22
32 /// Create a new PWM input driver. 23 /// Create a new PWM input driver.
33 pub fn new_alt( 24 pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl Channel2Pin<T>>, pull: Pull, freq: Hertz) -> Self {
34 tim: impl Peripheral<P = T> + 'd,
35 pin: impl Peripheral<P = impl Channel2Pin<T>> + 'd,
36 pull: Pull,
37 freq: Hertz,
38 ) -> Self {
39 into_ref!(pin);
40
41 pin.set_as_af(pin.af_num(), AfType::input(pull)); 25 pin.set_as_af(pin.af_num(), AfType::input(pull));
42 26
43 Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) 27 Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1)
44 } 28 }
45 29
46 fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, ch1: Channel, ch2: Channel) -> Self { 30 fn new_inner(tim: Peri<'d, T>, freq: Hertz, ch1: Channel, ch2: Channel) -> Self {
47 let mut inner = Timer::new(tim); 31 let mut inner = Timer::new(tim);
48 32
49 inner.set_counting_mode(CountingMode::EdgeAlignedUp); 33 inner.set_counting_mode(CountingMode::EdgeAlignedUp);
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs
index fc5835414..bac290f28 100644
--- a/embassy-stm32/src/timer/qei.rs
+++ b/embassy-stm32/src/timer/qei.rs
@@ -2,13 +2,12 @@
2 2
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4 4
5use embassy_hal_internal::{into_ref, PeripheralRef};
6use stm32_metapac::timer::vals; 5use stm32_metapac::timer::vals;
7 6
8use super::low_level::Timer; 7use super::low_level::Timer;
9use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; 8use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel};
10use crate::gpio::{AfType, AnyPin, Pull}; 9use crate::gpio::{AfType, AnyPin, Pull};
11use crate::Peripheral; 10use crate::Peri;
12 11
13/// Counting direction 12/// Counting direction
14pub enum Direction { 13pub enum Direction {
@@ -25,7 +24,7 @@ pub enum Ch2 {}
25 24
26/// Wrapper for using a pin with QEI. 25/// Wrapper for using a pin with QEI.
27pub struct QeiPin<'d, T, Channel> { 26pub struct QeiPin<'d, T, Channel> {
28 _pin: PeripheralRef<'d, AnyPin>, 27 _pin: Peri<'d, AnyPin>,
29 phantom: PhantomData<(T, Channel)>, 28 phantom: PhantomData<(T, Channel)>,
30} 29}
31 30
@@ -33,14 +32,13 @@ macro_rules! channel_impl {
33 ($new_chx:ident, $channel:ident, $pin_trait:ident) => { 32 ($new_chx:ident, $channel:ident, $pin_trait:ident) => {
34 impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> { 33 impl<'d, T: GeneralInstance4Channel> QeiPin<'d, T, $channel> {
35 #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")] 34 #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")]
36 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self { 35 pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self {
37 into_ref!(pin);
38 critical_section::with(|_| { 36 critical_section::with(|_| {
39 pin.set_low(); 37 pin.set_low();
40 pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); 38 pin.set_as_af(pin.af_num(), AfType::input(Pull::None));
41 }); 39 });
42 QeiPin { 40 QeiPin {
43 _pin: pin.map_into(), 41 _pin: pin.into(),
44 phantom: PhantomData, 42 phantom: PhantomData,
45 } 43 }
46 } 44 }
@@ -58,11 +56,11 @@ pub struct Qei<'d, T: GeneralInstance4Channel> {
58 56
59impl<'d, T: GeneralInstance4Channel> Qei<'d, T> { 57impl<'d, T: GeneralInstance4Channel> Qei<'d, T> {
60 /// Create a new quadrature decoder driver. 58 /// Create a new quadrature decoder driver.
61 pub fn new(tim: impl Peripheral<P = T> + 'd, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self { 59 pub fn new(tim: Peri<'d, T>, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self {
62 Self::new_inner(tim) 60 Self::new_inner(tim)
63 } 61 }
64 62
65 fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self { 63 fn new_inner(tim: Peri<'d, T>) -> Self {
66 let inner = Timer::new(tim); 64 let inner = Timer::new(tim);
67 let r = inner.regs_gp16(); 65 let r = inner.regs_gp16();
68 66
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index c5a366cd5..54ab7d0d5 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -3,15 +3,13 @@
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::mem::ManuallyDrop; 4use core::mem::ManuallyDrop;
5 5
6use embassy_hal_internal::{into_ref, PeripheralRef};
7
8use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; 6use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer};
9use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits}; 7use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits};
10#[cfg(gpio_v2)] 8#[cfg(gpio_v2)]
11use crate::gpio::Pull; 9use crate::gpio::Pull;
12use crate::gpio::{AfType, AnyPin, OutputType, Speed}; 10use crate::gpio::{AfType, AnyPin, OutputType, Speed};
13use crate::time::Hertz; 11use crate::time::Hertz;
14use crate::Peripheral; 12use crate::Peri;
15 13
16/// Channel 1 marker type. 14/// Channel 1 marker type.
17pub enum Ch1 {} 15pub enum Ch1 {}
@@ -26,7 +24,7 @@ pub enum Ch4 {}
26/// 24///
27/// This wraps a pin to make it usable with PWM. 25/// This wraps a pin to make it usable with PWM.
28pub struct PwmPin<'d, T, C> { 26pub struct PwmPin<'d, T, C> {
29 _pin: PeripheralRef<'d, AnyPin>, 27 _pin: Peri<'d, AnyPin>,
30 phantom: PhantomData<(T, C)>, 28 phantom: PhantomData<(T, C)>,
31} 29}
32 30
@@ -47,24 +45,19 @@ macro_rules! channel_impl {
47 ($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => { 45 ($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => {
48 impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> { 46 impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> {
49 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] 47 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")]
50 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, output_type: OutputType) -> Self { 48 pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>, output_type: OutputType) -> Self {
51 into_ref!(pin);
52 critical_section::with(|_| { 49 critical_section::with(|_| {
53 pin.set_low(); 50 pin.set_low();
54 pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); 51 pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh));
55 }); 52 });
56 PwmPin { 53 PwmPin {
57 _pin: pin.map_into(), 54 _pin: pin.into(),
58 phantom: PhantomData, 55 phantom: PhantomData,
59 } 56 }
60 } 57 }
61 58
62 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with config.")] 59 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with config.")]
63 pub fn $new_chx_with_config( 60 pub fn $new_chx_with_config(pin: Peri<'d, impl $pin_trait<T>>, pin_config: PwmPinConfig) -> Self {
64 pin: impl Peripheral<P = impl $pin_trait<T>> + 'd,
65 pin_config: PwmPinConfig,
66 ) -> Self {
67 into_ref!(pin);
68 critical_section::with(|_| { 61 critical_section::with(|_| {
69 pin.set_low(); 62 pin.set_low();
70 pin.set_as_af( 63 pin.set_as_af(
@@ -76,7 +69,7 @@ macro_rules! channel_impl {
76 ); 69 );
77 }); 70 });
78 PwmPin { 71 PwmPin {
79 _pin: pin.map_into(), 72 _pin: pin.into(),
80 phantom: PhantomData, 73 phantom: PhantomData,
81 } 74 }
82 } 75 }
@@ -202,7 +195,7 @@ pub struct SimplePwm<'d, T: GeneralInstance4Channel> {
202impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { 195impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
203 /// Create a new simple PWM driver. 196 /// Create a new simple PWM driver.
204 pub fn new( 197 pub fn new(
205 tim: impl Peripheral<P = T> + 'd, 198 tim: Peri<'d, T>,
206 _ch1: Option<PwmPin<'d, T, Ch1>>, 199 _ch1: Option<PwmPin<'d, T, Ch1>>,
207 _ch2: Option<PwmPin<'d, T, Ch2>>, 200 _ch2: Option<PwmPin<'d, T, Ch2>>,
208 _ch3: Option<PwmPin<'d, T, Ch3>>, 201 _ch3: Option<PwmPin<'d, T, Ch3>>,
@@ -213,7 +206,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
213 Self::new_inner(tim, freq, counting_mode) 206 Self::new_inner(tim, freq, counting_mode)
214 } 207 }
215 208
216 fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self { 209 fn new_inner(tim: Peri<'d, T>, freq: Hertz, counting_mode: CountingMode) -> Self {
217 let mut this = Self { inner: Timer::new(tim) }; 210 let mut this = Self { inner: Timer::new(tim) };
218 211
219 this.inner.set_counting_mode(counting_mode); 212 this.inner.set_counting_mode(counting_mode);
@@ -331,14 +324,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
331 /// 324 ///
332 /// Note: 325 /// Note:
333 /// you will need to provide corresponding TIMx_UP DMA channel to use this method. 326 /// you will need to provide corresponding TIMx_UP DMA channel to use this method.
334 pub async fn waveform_up( 327 pub async fn waveform_up(&mut self, dma: Peri<'_, impl super::UpDma<T>>, channel: Channel, duty: &[u16]) {
335 &mut self,
336 dma: impl Peripheral<P = impl super::UpDma<T>>,
337 channel: Channel,
338 duty: &[u16],
339 ) {
340 into_ref!(dma);
341
342 #[allow(clippy::let_unit_value)] // eg. stm32f334 328 #[allow(clippy::let_unit_value)] // eg. stm32f334
343 let req = dma.request(); 329 let req = dma.request();
344 330
@@ -368,7 +354,7 @@ impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
368 }; 354 };
369 355
370 Transfer::new_write( 356 Transfer::new_write(
371 &mut dma, 357 dma,
372 req, 358 req,
373 duty, 359 duty,
374 self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u16, 360 self.inner.regs_1ch().ccr(channel.index()).as_ptr() as *mut u16,
@@ -399,11 +385,9 @@ macro_rules! impl_waveform_chx {
399 ($fn_name:ident, $dma_ch:ident, $cc_ch:ident) => { 385 ($fn_name:ident, $dma_ch:ident, $cc_ch:ident) => {
400 impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> { 386 impl<'d, T: GeneralInstance4Channel> SimplePwm<'d, T> {
401 /// Generate a sequence of PWM waveform 387 /// Generate a sequence of PWM waveform
402 pub async fn $fn_name(&mut self, dma: impl Peripheral<P = impl super::$dma_ch<T>>, duty: &[u16]) { 388 pub async fn $fn_name(&mut self, dma: Peri<'_, impl super::$dma_ch<T>>, duty: &[u16]) {
403 use crate::pac::timer::vals::Ccds; 389 use crate::pac::timer::vals::Ccds;
404 390
405 into_ref!(dma);
406
407 #[allow(clippy::let_unit_value)] // eg. stm32f334 391 #[allow(clippy::let_unit_value)] // eg. stm32f334
408 let req = dma.request(); 392 let req = dma.request();
409 393
@@ -443,7 +427,7 @@ macro_rules! impl_waveform_chx {
443 match self.inner.bits() { 427 match self.inner.bits() {
444 TimerBits::Bits16 => { 428 TimerBits::Bits16 => {
445 Transfer::new_write( 429 Transfer::new_write(
446 &mut dma, 430 dma,
447 req, 431 req,
448 duty, 432 duty,
449 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u16, 433 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u16,
@@ -458,7 +442,7 @@ macro_rules! impl_waveform_chx {
458 442
459 #[cfg(any(bdma, gpdma))] 443 #[cfg(any(bdma, gpdma))]
460 Transfer::new_write( 444 Transfer::new_write(
461 &mut dma, 445 dma,
462 req, 446 req,
463 duty, 447 duty,
464 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u32, 448 self.inner.regs_gp16().ccr(cc_channel.index()).as_ptr() as *mut u32,