aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 16:14:00 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 16:16:29 +0200
commitb5ff7c5d60cd5cba905720b4b8f6cb8c73859ca6 (patch)
tree2b3975074c806fe2c2981b488e8f91be62be3660
parent042e11960e6018082801d4f268bbe0bdc62edfac (diff)
rename PwmPin::new_chX, update examples.
-rw-r--r--embassy-stm32/src/pwm/simple_pwm.rs20
-rw-r--r--examples/stm32f4/src/bin/pwm.rs5
-rw-r--r--examples/stm32g4/src/bin/pwm.rs5
-rw-r--r--examples/stm32h7/src/bin/pwm.rs5
4 files changed, 19 insertions, 16 deletions
diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs
index 5fcd1ed09..b045a2d78 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> {
20} 20}
21 21
22macro_rules! channel_impl { 22macro_rules! channel_impl {
23 ($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(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd) -> Self { 25 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd) -> Self {
26 into_ref!(pin); 26 into_ref!(pin);
27 critical_section::with(|_| unsafe { 27 critical_section::with(|_| unsafe {
28 pin.set_low(); 28 pin.set_low();
@@ -39,10 +39,10 @@ macro_rules! channel_impl {
39 }; 39 };
40} 40}
41 41
42channel_impl!(Ch1, Channel1Pin); 42channel_impl!(new_ch1, Ch1, Channel1Pin);
43channel_impl!(Ch2, Channel2Pin); 43channel_impl!(new_ch2, Ch2, Channel2Pin);
44channel_impl!(Ch3, Channel3Pin); 44channel_impl!(new_ch3, Ch3, Channel3Pin);
45channel_impl!(Ch4, Channel4Pin); 45channel_impl!(new_ch4, Ch4, Channel4Pin);
46 46
47pub struct SimplePwm<'d, T> { 47pub struct SimplePwm<'d, T> {
48 inner: PeripheralRef<'d, T>, 48 inner: PeripheralRef<'d, T>,
@@ -51,10 +51,10 @@ pub struct SimplePwm<'d, T> {
51impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { 51impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
52 pub fn new( 52 pub fn new(
53 tim: impl Peripheral<P = T> + 'd, 53 tim: impl Peripheral<P = T> + 'd,
54 _ch1: Option<PwmPin<T, Ch1>>, 54 _ch1: Option<PwmPin<'d, T, Ch1>>,
55 _ch2: Option<PwmPin<T, Ch2>>, 55 _ch2: Option<PwmPin<'d, T, Ch2>>,
56 _ch3: Option<PwmPin<T, Ch3>>, 56 _ch3: Option<PwmPin<'d, T, Ch3>>,
57 _ch4: Option<PwmPin<T, Ch4>>, 57 _ch4: Option<PwmPin<'d, T, Ch4>>,
58 freq: Hertz, 58 freq: Hertz,
59 ) -> Self { 59 ) -> Self {
60 Self::new_inner(tim, freq) 60 Self::new_inner(tim, freq)
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs
index c99f3cc26..b39bbbe28 100644
--- a/examples/stm32f4/src/bin/pwm.rs
+++ b/examples/stm32f4/src/bin/pwm.rs
@@ -5,7 +5,7 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm; 8use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::pwm::Channel; 9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::khz; 10use embassy_stm32::time::khz;
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
@@ -15,7 +15,8 @@ use {defmt_rtt as _, panic_probe as _};
15async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 let mut pwm = SimplePwm::new_1ch(p.TIM1, p.PE9, khz(10)); 18 let ch1 = PwmPin::new_ch1(p.PE9);
19 let mut pwm = SimplePwm::new(p.TIM1, Some(ch1), None, None, None, khz(10));
19 let max = pwm.get_max_duty(); 20 let max = pwm.get_max_duty();
20 pwm.enable(Channel::Ch1); 21 pwm.enable(Channel::Ch1);
21 22
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs
index 579e289b0..dc4e164ab 100644
--- a/examples/stm32g4/src/bin/pwm.rs
+++ b/examples/stm32g4/src/bin/pwm.rs
@@ -5,7 +5,7 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm; 8use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::pwm::Channel; 9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::khz; 10use embassy_stm32::time::khz;
11use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
@@ -15,7 +15,8 @@ use {defmt_rtt as _, panic_probe as _};
15async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!"); 16 info!("Hello World!");
17 17
18 let mut pwm = SimplePwm::new_1ch(p.TIM2, p.PA5, khz(10)); 18 let ch1 = PwmPin::new_ch1(p.PA5);
19 let mut pwm = SimplePwm::new(p.TIM2, Some(ch1), None, None, None, khz(10));
19 let max = pwm.get_max_duty(); 20 let max = pwm.get_max_duty();
20 pwm.enable(Channel::Ch1); 21 pwm.enable(Channel::Ch1);
21 22
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs
index f072c5375..730f637e9 100644
--- a/examples/stm32h7/src/bin/pwm.rs
+++ b/examples/stm32h7/src/bin/pwm.rs
@@ -5,7 +5,7 @@
5use defmt::*; 5use defmt::*;
6use embassy::executor::Spawner; 6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
8use embassy_stm32::pwm::simple_pwm::SimplePwm; 8use embassy_stm32::pwm::simple_pwm::{PwmPin, SimplePwm};
9use embassy_stm32::pwm::Channel; 9use embassy_stm32::pwm::Channel;
10use embassy_stm32::time::{khz, mhz}; 10use embassy_stm32::time::{khz, mhz};
11use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{Config, Peripherals};
@@ -27,7 +27,8 @@ pub fn config() -> Config {
27async fn main(_spawner: Spawner, p: Peripherals) { 27async fn main(_spawner: Spawner, p: Peripherals) {
28 info!("Hello World!"); 28 info!("Hello World!");
29 29
30 let mut pwm = SimplePwm::new_1ch(p.TIM3, p.PA6, khz(10)); 30 let ch1 = PwmPin::new_ch1(p.PA6);
31 let mut pwm = SimplePwm::new(p.TIM3, Some(ch1), None, None, None, khz(10));
31 let max = pwm.get_max_duty(); 32 let max = pwm.get_max_duty();
32 pwm.enable(Channel::Ch1); 33 pwm.enable(Channel::Ch1);
33 34