Skip to content

Commit 1646dc3

Browse files
Added gpio version specific code
1 parent f22649e commit 1646dc3

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

embassy-stm32/src/lptim/pwm.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use super::OutputPin;
1010
#[cfg(any(lptim_v2a, lptim_v2b))]
1111
use super::{channel::Channel, timer::ChannelDirection, Channel1Pin, Channel2Pin};
1212
use super::{BasicInstance, Instance};
13-
use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed};
13+
#[cfg(gpio_v2)]
14+
use crate::gpio::Pull;
15+
use crate::gpio::{AfType, AnyPin, OutputType, Speed};
1416
use crate::time::Hertz;
1517
use crate::Peripheral;
1618

@@ -33,13 +35,17 @@ pub struct PwmPin<'d, T, C> {
3335
///
3436
/// This configures the pwm pin settings
3537
pub struct PwmPinConfig {
38+
/// PWM Pin output type
3639
pub output_type: OutputType,
40+
/// PWM Pin speed
3741
pub speed: Speed,
42+
/// PWM Pin pull type
43+
#[cfg(gpio_v2)]
3844
pub pull: Pull,
3945
}
4046

4147
macro_rules! channel_impl {
42-
($new_chx:ident, $channel:ident, $pin_trait:ident) => {
48+
($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => {
4349
impl<'d, T: BasicInstance> PwmPin<'d, T, $channel> {
4450
#[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")]
4551
pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self {
@@ -66,6 +72,9 @@ macro_rules! channel_impl {
6672
pin.set_low();
6773
pin.set_as_af(
6874
pin.af_num(),
75+
#[cfg(gpio_v1)]
76+
AfType::output(pin_config.output_type, pin_config.speed),
77+
#[cfg(gpio_v2)]
6978
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
7079
);
7180
});
@@ -79,11 +88,11 @@ macro_rules! channel_impl {
7988
}
8089

8190
#[cfg(not(any(lptim_v2a, lptim_v2b)))]
82-
channel_impl!(new, Output, OutputPin);
91+
channel_impl!(new, new_with_config, Output, OutputPin);
8392
#[cfg(any(lptim_v2a, lptim_v2b))]
84-
channel_impl!(new_ch1, Ch1, Channel1Pin);
93+
channel_impl!(new_ch1, new_ch1_with_config, Ch1, Channel1Pin);
8594
#[cfg(any(lptim_v2a, lptim_v2b))]
86-
channel_impl!(new_ch2, Ch2, Channel2Pin);
95+
channel_impl!(new_ch2, new_ch2_with_config, Ch2, Channel2Pin);
8796

8897
/// PWM driver.
8998
pub struct Pwm<'d, T: Instance> {

embassy-stm32/src/timer/simple_pwm.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
77

88
use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer};
99
use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits};
10-
use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed};
10+
#[cfg(gpio_v2)]
11+
use crate::gpio::Pull;
12+
use crate::gpio::{AfType, AnyPin, OutputType, Speed};
1113
use crate::time::Hertz;
1214
use crate::Peripheral;
1315

@@ -32,13 +34,17 @@ pub struct PwmPin<'d, T, C> {
3234
///
3335
/// This configures the pwm pin settings
3436
pub struct PwmPinConfig {
37+
/// PWM Pin output type
3538
pub output_type: OutputType,
39+
/// PWM Pin speed
3640
pub speed: Speed,
41+
/// PWM Pin pull type
42+
#[cfg(gpio_v2)]
3743
pub pull: Pull,
3844
}
3945

4046
macro_rules! channel_impl {
41-
($new_chx:ident, $channel:ident, $pin_trait:ident) => {
47+
($new_chx:ident, $new_chx_with_config:ident, $channel:ident, $pin_trait:ident) => {
4248
impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> {
4349
#[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")]
4450
pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, output_type: OutputType) -> Self {
@@ -52,6 +58,7 @@ macro_rules! channel_impl {
5258
phantom: PhantomData,
5359
}
5460
}
61+
5562
#[doc = concat!("Create a new ", stringify!($channel), "_with_config PWM pin instance.")]
5663
pub fn $new_chx_with_config(
5764
pin: impl Peripheral<P = impl $pin_trait<T>> + 'd,
@@ -62,6 +69,9 @@ macro_rules! channel_impl {
6269
pin.set_low();
6370
pin.set_as_af(
6471
pin.af_num(),
72+
#[cfg(gpio_v1)]
73+
AfType::output(pin_config.output_type, pin_config.speed),
74+
#[cfg(gpio_v2)]
6575
AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
6676
);
6777
});
@@ -74,10 +84,10 @@ macro_rules! channel_impl {
7484
};
7585
}
7686

77-
channel_impl!(new_ch1, Ch1, Channel1Pin);
78-
channel_impl!(new_ch2, Ch2, Channel2Pin);
79-
channel_impl!(new_ch3, Ch3, Channel3Pin);
80-
channel_impl!(new_ch4, Ch4, Channel4Pin);
87+
channel_impl!(new_ch1, new_ch1_with_config, Ch1, Channel1Pin);
88+
channel_impl!(new_ch2, new_ch2_with_config, Ch2, Channel2Pin);
89+
channel_impl!(new_ch3, new_ch3_with_config, Ch3, Channel3Pin);
90+
channel_impl!(new_ch4, new_ch4_with_config, Ch4, Channel4Pin);
8191

8292
/// A single channel of a pwm, obtained from [`SimplePwm::split`],
8393
/// [`SimplePwm::channel`], [`SimplePwm::ch1`], etc.

0 commit comments

Comments
 (0)