aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/gpio.rs14
-rw-r--r--embassy-stm32/src/timer/complementary_pwm.rs16
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs6
-rw-r--r--examples/stm32f4/src/bin/pwm.rs3
-rw-r--r--examples/stm32f4/src/bin/pwm_complementary.rs5
-rw-r--r--examples/stm32g4/src/bin/pwm.rs3
-rw-r--r--examples/stm32h7/src/bin/pwm.rs3
7 files changed, 34 insertions, 16 deletions
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index cda597145..0cc269cfd 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -502,6 +502,20 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
502 } 502 }
503} 503}
504 504
505pub enum OutputType {
506 PushPull,
507 OpenDrain,
508}
509
510impl From<OutputType> for sealed::AFType {
511 fn from(value: OutputType) -> Self {
512 match value {
513 OutputType::OpenDrain => sealed::AFType::OutputOpenDrain,
514 OutputType::PushPull => sealed::AFType::OutputPushPull,
515 }
516 }
517}
518
505pub(crate) mod sealed { 519pub(crate) mod sealed {
506 use super::*; 520 use super::*;
507 521
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 });
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs
index 4f130c26b..1013a844e 100644
--- a/examples/stm32f4/src/bin/pwm.rs
+++ b/examples/stm32f4/src/bin/pwm.rs
@@ -4,6 +4,7 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::gpio::OutputType;
7use embassy_stm32::time::khz; 8use embassy_stm32::time::khz;
8use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; 9use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::timer::Channel; 10use embassy_stm32::timer::Channel;
@@ -15,7 +16,7 @@ async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default()); 16 let p = embassy_stm32::init(Default::default());
16 info!("Hello World!"); 17 info!("Hello World!");
17 18
18 let ch1 = PwmPin::new_ch1(p.PE9); 19 let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull);
19 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10)); 20 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10));
20 let max = pwm.get_max_duty(); 21 let max = pwm.get_max_duty();
21 pwm.enable(Channel::Ch1); 22 pwm.enable(Channel::Ch1);
diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs
index 8cc2a4117..83a3c7537 100644
--- a/examples/stm32f4/src/bin/pwm_complementary.rs
+++ b/examples/stm32f4/src/bin/pwm_complementary.rs
@@ -4,6 +4,7 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::gpio::OutputType;
7use embassy_stm32::time::khz; 8use embassy_stm32::time::khz;
8use embassy_stm32::timer::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin}; 9use embassy_stm32::timer::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin};
9use embassy_stm32::timer::simple_pwm::PwmPin; 10use embassy_stm32::timer::simple_pwm::PwmPin;
@@ -16,8 +17,8 @@ async fn main(_spawner: Spawner) {
16 let p = embassy_stm32::init(Default::default()); 17 let p = embassy_stm32::init(Default::default());
17 info!("Hello World!"); 18 info!("Hello World!");
18 19
19 let ch1 = PwmPin::new_ch1(p.PE9); 20 let ch1 = PwmPin::new_ch1(p.PE9, OutputType::PushPull);
20 let ch1n = ComplementaryPwmPin::new_ch1(p.PA7); 21 let ch1n = ComplementaryPwmPin::new_ch1(p.PA7, OutputType::PushPull);
21 let mut pwm = ComplementaryPwm::new( 22 let mut pwm = ComplementaryPwm::new(
22 p.TIM1, 23 p.TIM1,
23 Some(ch1), 24 Some(ch1),
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs
index b5a9b9952..01e9cb476 100644
--- a/examples/stm32g4/src/bin/pwm.rs
+++ b/examples/stm32g4/src/bin/pwm.rs
@@ -4,6 +4,7 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::gpio::OutputType;
7use embassy_stm32::time::khz; 8use embassy_stm32::time::khz;
8use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; 9use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::timer::Channel; 10use embassy_stm32::timer::Channel;
@@ -15,7 +16,7 @@ async fn main(_spawner: Spawner) {
15 let p = embassy_stm32::init(Default::default()); 16 let p = embassy_stm32::init(Default::default());
16 info!("Hello World!"); 17 info!("Hello World!");
17 18
18 let ch1 = PwmPin::new_ch1(p.PC0); 19 let ch1 = PwmPin::new_ch1(p.PC0, OutputType::PushPull);
19 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10)); 20 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10));
20 let max = pwm.get_max_duty(); 21 let max = pwm.get_max_duty();
21 pwm.enable(Channel::Ch1); 22 pwm.enable(Channel::Ch1);
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs
index adf2ea9ce..aa5ec1bcf 100644
--- a/examples/stm32h7/src/bin/pwm.rs
+++ b/examples/stm32h7/src/bin/pwm.rs
@@ -4,6 +4,7 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::gpio::OutputType;
7use embassy_stm32::time::{khz, mhz}; 8use embassy_stm32::time::{khz, mhz};
8use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; 9use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::timer::Channel; 10use embassy_stm32::timer::Channel;
@@ -24,7 +25,7 @@ async fn main(_spawner: Spawner) {
24 let p = embassy_stm32::init(config); 25 let p = embassy_stm32::init(config);
25 info!("Hello World!"); 26 info!("Hello World!");
26 27
27 let ch1 = PwmPin::new_ch1(p.PA6); 28 let ch1 = PwmPin::new_ch1(p.PA6, OutputType::PushPull);
28 let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10)); 29 let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10));
29 let max = pwm.get_max_duty(); 30 let max = pwm.get_max_duty();
30 pwm.enable(Channel::Ch1); 31 pwm.enable(Channel::Ch1);