aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-07-29 12:01:32 -0500
committerxoviat <[email protected]>2023-07-29 12:01:32 -0500
commit0d7b005252a0168c779292bf9457f1a654e42386 (patch)
treed40cca936ab61f4a6e5fa709cc7911a10c7b21ad /embassy-stm32/src/timer
parentfcbfd224a729c38d5ff94d94a25321a819254630 (diff)
stm32/pwm: add output type control
Diffstat (limited to 'embassy-stm32/src/timer')
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs16
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs6
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::*;
7use super::*; 7use super::*;
8#[allow(unused_imports)] 8#[allow(unused_imports)]
9use crate::gpio::sealed::{AFType, Pin}; 9use crate::gpio::sealed::{AFType, Pin};
10use crate::gpio::AnyPin; 10use crate::gpio::{AnyPin, OutputType};
11use crate::time::Hertz; 11use crate::time::Hertz;
12use crate::Peripheral; 12use crate::Peripheral;
13 13
@@ -17,13 +17,13 @@ pub struct ComplementaryPwmPin<'d, Perip, Channel> {
17} 17}
18 18
19macro_rules! complementary_channel_impl { 19macro_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
39complementary_channel_impl!(new_ch1, Ch1, Channel1Pin, Channel1ComplementaryPin); 39complementary_channel_impl!(new_ch1, Ch1, Channel1ComplementaryPin);
40complementary_channel_impl!(new_ch2, Ch2, Channel2Pin, Channel2ComplementaryPin); 40complementary_channel_impl!(new_ch2, Ch2, Channel2ComplementaryPin);
41complementary_channel_impl!(new_ch3, Ch3, Channel3Pin, Channel3ComplementaryPin); 41complementary_channel_impl!(new_ch3, Ch3, Channel3ComplementaryPin);
42complementary_channel_impl!(new_ch4, Ch4, Channel4Pin, Channel4ComplementaryPin); 42complementary_channel_impl!(new_ch4, Ch4, Channel4ComplementaryPin);
43 43
44pub struct ComplementaryPwm<'d, T> { 44pub 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};
5use super::*; 5use super::*;
6#[allow(unused_imports)] 6#[allow(unused_imports)]
7use crate::gpio::sealed::{AFType, Pin}; 7use crate::gpio::sealed::{AFType, Pin};
8use crate::gpio::AnyPin; 8use crate::gpio::{AnyPin, OutputType};
9use crate::time::Hertz; 9use crate::time::Hertz;
10use crate::Peripheral; 10use crate::Peripheral;
11 11
@@ -22,11 +22,11 @@ pub struct PwmPin<'d, Perip, Channel> {
22macro_rules! channel_impl { 22macro_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 });