aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32
diff options
context:
space:
mode:
authorMatt Allen <[email protected]>2025-03-06 09:41:07 -0500
committerMatt Allen <[email protected]>2025-03-06 09:41:07 -0500
commit1646dc36f2cd85f41a8ad8370912ec33fa4cf5e9 (patch)
treebdff00c381ba63baff00c6ea959913732fd16038 /embassy-stm32
parentf22649e0082a9e9886d7fc2f1f8986682b4cc921 (diff)
Added gpio version specific code
Diffstat (limited to 'embassy-stm32')
-rw-r--r--embassy-stm32/src/lptim/pwm.rs19
-rw-r--r--embassy-stm32/src/timer/simple_pwm.rs22
2 files changed, 30 insertions, 11 deletions
diff --git a/embassy-stm32/src/lptim/pwm.rs b/embassy-stm32/src/lptim/pwm.rs
index 9f3803cd6..43ef178ef 100644
--- a/embassy-stm32/src/lptim/pwm.rs
+++ b/embassy-stm32/src/lptim/pwm.rs
@@ -10,7 +10,9 @@ use super::OutputPin;
10#[cfg(any(lptim_v2a, lptim_v2b))] 10#[cfg(any(lptim_v2a, lptim_v2b))]
11use super::{channel::Channel, timer::ChannelDirection, Channel1Pin, Channel2Pin}; 11use super::{channel::Channel, timer::ChannelDirection, Channel1Pin, Channel2Pin};
12use super::{BasicInstance, Instance}; 12use super::{BasicInstance, Instance};
13use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed}; 13#[cfg(gpio_v2)]
14use crate::gpio::Pull;
15use crate::gpio::{AfType, AnyPin, OutputType, Speed};
14use crate::time::Hertz; 16use crate::time::Hertz;
15use crate::Peripheral; 17use crate::Peripheral;
16 18
@@ -33,13 +35,17 @@ pub struct PwmPin<'d, T, C> {
33/// 35///
34/// This configures the pwm pin settings 36/// This configures the pwm pin settings
35pub struct PwmPinConfig { 37pub struct PwmPinConfig {
38 /// PWM Pin output type
36 pub output_type: OutputType, 39 pub output_type: OutputType,
40 /// PWM Pin speed
37 pub speed: Speed, 41 pub speed: Speed,
42 /// PWM Pin pull type
43 #[cfg(gpio_v2)]
38 pub pull: Pull, 44 pub pull: Pull,
39} 45}
40 46
41macro_rules! channel_impl { 47macro_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) => {
43 impl<'d, T: BasicInstance> PwmPin<'d, T, $channel> { 49 impl<'d, T: BasicInstance> PwmPin<'d, T, $channel> {
44 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] 50 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")]
45 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self { 51 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self {
@@ -66,6 +72,9 @@ macro_rules! channel_impl {
66 pin.set_low(); 72 pin.set_low();
67 pin.set_as_af( 73 pin.set_as_af(
68 pin.af_num(), 74 pin.af_num(),
75 #[cfg(gpio_v1)]
76 AfType::output(pin_config.output_type, pin_config.speed),
77 #[cfg(gpio_v2)]
69 AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull), 78 AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
70 ); 79 );
71 }); 80 });
@@ -79,11 +88,11 @@ macro_rules! channel_impl {
79} 88}
80 89
81#[cfg(not(any(lptim_v2a, lptim_v2b)))] 90#[cfg(not(any(lptim_v2a, lptim_v2b)))]
82channel_impl!(new, Output, OutputPin); 91channel_impl!(new, new_with_config, Output, OutputPin);
83#[cfg(any(lptim_v2a, lptim_v2b))] 92#[cfg(any(lptim_v2a, lptim_v2b))]
84channel_impl!(new_ch1, Ch1, Channel1Pin); 93channel_impl!(new_ch1, new_ch1_with_config, Ch1, Channel1Pin);
85#[cfg(any(lptim_v2a, lptim_v2b))] 94#[cfg(any(lptim_v2a, lptim_v2b))]
86channel_impl!(new_ch2, Ch2, Channel2Pin); 95channel_impl!(new_ch2, new_ch2_with_config, Ch2, Channel2Pin);
87 96
88/// PWM driver. 97/// PWM driver.
89pub struct Pwm<'d, T: Instance> { 98pub struct Pwm<'d, T: Instance> {
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs
index 7664a4dc0..5906df635 100644
--- a/embassy-stm32/src/timer/simple_pwm.rs
+++ b/embassy-stm32/src/timer/simple_pwm.rs
@@ -7,7 +7,9 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
7 7
8use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; 8use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer};
9use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits}; 9use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel, TimerBits};
10use crate::gpio::{AfType, AnyPin, OutputType, Pull, Speed}; 10#[cfg(gpio_v2)]
11use crate::gpio::Pull;
12use crate::gpio::{AfType, AnyPin, OutputType, Speed};
11use crate::time::Hertz; 13use crate::time::Hertz;
12use crate::Peripheral; 14use crate::Peripheral;
13 15
@@ -32,13 +34,17 @@ pub struct PwmPin<'d, T, C> {
32/// 34///
33/// This configures the pwm pin settings 35/// This configures the pwm pin settings
34pub struct PwmPinConfig { 36pub struct PwmPinConfig {
37 /// PWM Pin output type
35 pub output_type: OutputType, 38 pub output_type: OutputType,
39 /// PWM Pin speed
36 pub speed: Speed, 40 pub speed: Speed,
41 /// PWM Pin pull type
42 #[cfg(gpio_v2)]
37 pub pull: Pull, 43 pub pull: Pull,
38} 44}
39 45
40macro_rules! channel_impl { 46macro_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) => {
42 impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> { 48 impl<'d, T: GeneralInstance4Channel> PwmPin<'d, T, $channel> {
43 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] 49 #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")]
44 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, output_type: OutputType) -> Self { 50 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 {
52 phantom: PhantomData, 58 phantom: PhantomData,
53 } 59 }
54 } 60 }
61
55 #[doc = concat!("Create a new ", stringify!($channel), "_with_config PWM pin instance.")] 62 #[doc = concat!("Create a new ", stringify!($channel), "_with_config PWM pin instance.")]
56 pub fn $new_chx_with_config( 63 pub fn $new_chx_with_config(
57 pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, 64 pin: impl Peripheral<P = impl $pin_trait<T>> + 'd,
@@ -62,6 +69,9 @@ macro_rules! channel_impl {
62 pin.set_low(); 69 pin.set_low();
63 pin.set_as_af( 70 pin.set_as_af(
64 pin.af_num(), 71 pin.af_num(),
72 #[cfg(gpio_v1)]
73 AfType::output(pin_config.output_type, pin_config.speed),
74 #[cfg(gpio_v2)]
65 AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull), 75 AfType::output_pull(pin_config.output_type, pin_config.speed, pin_config.pull),
66 ); 76 );
67 }); 77 });
@@ -74,10 +84,10 @@ macro_rules! channel_impl {
74 }; 84 };
75} 85}
76 86
77channel_impl!(new_ch1, Ch1, Channel1Pin); 87channel_impl!(new_ch1, new_ch1_with_config, Ch1, Channel1Pin);
78channel_impl!(new_ch2, Ch2, Channel2Pin); 88channel_impl!(new_ch2, new_ch2_with_config, Ch2, Channel2Pin);
79channel_impl!(new_ch3, Ch3, Channel3Pin); 89channel_impl!(new_ch3, new_ch3_with_config, Ch3, Channel3Pin);
80channel_impl!(new_ch4, Ch4, Channel4Pin); 90channel_impl!(new_ch4, new_ch4_with_config, Ch4, Channel4Pin);
81 91
82/// A single channel of a pwm, obtained from [`SimplePwm::split`], 92/// A single channel of a pwm, obtained from [`SimplePwm::split`],
83/// [`SimplePwm::channel`], [`SimplePwm::ch1`], etc. 93/// [`SimplePwm::channel`], [`SimplePwm::ch1`], etc.