diff options
| author | xoviat <[email protected]> | 2023-07-29 12:01:32 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-07-29 12:01:32 -0500 |
| commit | 0d7b005252a0168c779292bf9457f1a654e42386 (patch) | |
| tree | d40cca936ab61f4a6e5fa709cc7911a10c7b21ad /embassy-stm32/src/timer | |
| parent | fcbfd224a729c38d5ff94d94a25321a819254630 (diff) | |
stm32/pwm: add output type control
Diffstat (limited to 'embassy-stm32/src/timer')
| -rw-r--r-- | embassy-stm32/src/timer/complementary_pwm.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/simple_pwm.rs | 6 |
2 files changed, 11 insertions, 11 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index 64bb32c39..48cb610f1 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -7,7 +7,7 @@ use super::simple_pwm::*; | |||
| 7 | use super::*; | 7 | use super::*; |
| 8 | #[allow(unused_imports)] | 8 | #[allow(unused_imports)] |
| 9 | use crate::gpio::sealed::{AFType, Pin}; | 9 | use crate::gpio::sealed::{AFType, Pin}; |
| 10 | use crate::gpio::AnyPin; | 10 | use crate::gpio::{AnyPin, OutputType}; |
| 11 | use crate::time::Hertz; | 11 | use crate::time::Hertz; |
| 12 | use crate::Peripheral; | 12 | use crate::Peripheral; |
| 13 | 13 | ||
| @@ -17,13 +17,13 @@ pub struct ComplementaryPwmPin<'d, Perip, Channel> { | |||
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | macro_rules! complementary_channel_impl { | 19 | macro_rules! complementary_channel_impl { |
| 20 | ($new_chx:ident, $channel:ident, $pin_trait:ident, $complementary_pin_trait:ident) => { | 20 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { |
| 21 | impl<'d, Perip: CaptureCompare16bitInstance> ComplementaryPwmPin<'d, Perip, $channel> { | 21 | impl<'d, Perip: CaptureCompare16bitInstance> ComplementaryPwmPin<'d, Perip, $channel> { |
| 22 | pub fn $new_chx(pin: impl Peripheral<P = impl $complementary_pin_trait<Perip>> + 'd) -> Self { | 22 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd, output_type: OutputType) -> Self { |
| 23 | into_ref!(pin); | 23 | into_ref!(pin); |
| 24 | critical_section::with(|_| { | 24 | critical_section::with(|_| { |
| 25 | pin.set_low(); | 25 | pin.set_low(); |
| 26 | pin.set_as_af(pin.af_num(), AFType::OutputPushPull); | 26 | pin.set_as_af(pin.af_num(), output_type.into()); |
| 27 | #[cfg(gpio_v2)] | 27 | #[cfg(gpio_v2)] |
| 28 | pin.set_speed(crate::gpio::Speed::VeryHigh); | 28 | pin.set_speed(crate::gpio::Speed::VeryHigh); |
| 29 | }); | 29 | }); |
| @@ -36,10 +36,10 @@ macro_rules! complementary_channel_impl { | |||
| 36 | }; | 36 | }; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | complementary_channel_impl!(new_ch1, Ch1, Channel1Pin, Channel1ComplementaryPin); | 39 | complementary_channel_impl!(new_ch1, Ch1, Channel1ComplementaryPin); |
| 40 | complementary_channel_impl!(new_ch2, Ch2, Channel2Pin, Channel2ComplementaryPin); | 40 | complementary_channel_impl!(new_ch2, Ch2, Channel2ComplementaryPin); |
| 41 | complementary_channel_impl!(new_ch3, Ch3, Channel3Pin, Channel3ComplementaryPin); | 41 | complementary_channel_impl!(new_ch3, Ch3, Channel3ComplementaryPin); |
| 42 | complementary_channel_impl!(new_ch4, Ch4, Channel4Pin, Channel4ComplementaryPin); | 42 | complementary_channel_impl!(new_ch4, Ch4, Channel4ComplementaryPin); |
| 43 | 43 | ||
| 44 | pub struct ComplementaryPwm<'d, T> { | 44 | pub struct ComplementaryPwm<'d, T> { |
| 45 | inner: PeripheralRef<'d, T>, | 45 | inner: PeripheralRef<'d, T>, |
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index 514796930..e0a817929 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs | |||
| @@ -5,7 +5,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef}; | |||
| 5 | use super::*; | 5 | use super::*; |
| 6 | #[allow(unused_imports)] | 6 | #[allow(unused_imports)] |
| 7 | use crate::gpio::sealed::{AFType, Pin}; | 7 | use crate::gpio::sealed::{AFType, Pin}; |
| 8 | use crate::gpio::AnyPin; | 8 | use crate::gpio::{AnyPin, OutputType}; |
| 9 | use crate::time::Hertz; | 9 | use crate::time::Hertz; |
| 10 | use crate::Peripheral; | 10 | use crate::Peripheral; |
| 11 | 11 | ||
| @@ -22,11 +22,11 @@ pub struct PwmPin<'d, Perip, Channel> { | |||
| 22 | macro_rules! channel_impl { | 22 | macro_rules! channel_impl { |
| 23 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 23 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { |
| 24 | impl<'d, Perip: CaptureCompare16bitInstance> PwmPin<'d, Perip, $channel> { | 24 | impl<'d, Perip: CaptureCompare16bitInstance> PwmPin<'d, Perip, $channel> { |
| 25 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd) -> Self { | 25 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd, output_type: OutputType) -> Self { |
| 26 | into_ref!(pin); | 26 | into_ref!(pin); |
| 27 | critical_section::with(|_| { | 27 | critical_section::with(|_| { |
| 28 | pin.set_low(); | 28 | pin.set_low(); |
| 29 | pin.set_as_af(pin.af_num(), AFType::OutputPushPull); | 29 | pin.set_as_af(pin.af_num(), output_type.into()); |
| 30 | #[cfg(gpio_v2)] | 30 | #[cfg(gpio_v2)] |
| 31 | pin.set_speed(crate::gpio::Speed::VeryHigh); | 31 | pin.set_speed(crate::gpio::Speed::VeryHigh); |
| 32 | }); | 32 | }); |
