@@ -10,6 +10,7 @@ pub use traits::Instance;
1010use crate :: gpio:: { AfType , AnyPin , OutputType , Speed } ;
1111use crate :: rcc;
1212use crate :: time:: Hertz ;
13+ pub use crate :: timer:: simple_pwm:: PwmPinConfig ;
1314
1415/// HRTIM burst controller instance.
1516pub struct BurstController < T : Instance > {
@@ -73,7 +74,7 @@ pub struct ComplementaryPwmPin<'d, T, C> {
7374}
7475
7576macro_rules! advanced_channel_impl {
76- ( $new_chx: ident, $channel: tt, $ch_num: expr, $pin_trait: ident, $complementary_pin_trait: ident) => {
77+ ( $new_chx: ident, $new_chx_with_config : ident , $ channel: tt, $ch_num: expr, $pin_trait: ident, $complementary_pin_trait: ident) => {
7778 impl <' d, T : Instance > PwmPin <' d, T , $channel<T >> {
7879 #[ doc = concat!( "Create a new " , stringify!( $channel) , " PWM pin instance." ) ]
7980 pub fn $new_chx( pin: Peri <' d, impl $pin_trait<T >>) -> Self {
@@ -86,6 +87,21 @@ macro_rules! advanced_channel_impl {
8687 phantom: PhantomData ,
8788 }
8889 }
90+
91+ #[ doc = concat!( "Create a new " , stringify!( $channel) , " PWM pin instance with a specific configuration." ) ]
92+ pub fn $new_chx_with_config(
93+ pin: Peri <' d, impl $pin_trait<T >>,
94+ pin_config: PwmPinConfig ,
95+ ) -> Self {
96+ critical_section:: with( |_| {
97+ pin. set_low( ) ;
98+ set_as_af!( pin, AfType :: output( pin_config. output_type, pin_config. speed) ) ;
99+ } ) ;
100+ PwmPin {
101+ _pin: pin. into( ) ,
102+ phantom: PhantomData ,
103+ }
104+ }
89105 }
90106
91107 impl <' d, T : Instance > ComplementaryPwmPin <' d, T , $channel<T >> {
@@ -100,6 +116,21 @@ macro_rules! advanced_channel_impl {
100116 phantom: PhantomData ,
101117 }
102118 }
119+
120+ #[ doc = concat!( "Create a new " , stringify!( $channel) , " complementary PWM pin instance with a specific configuration." ) ]
121+ pub fn $new_chx_with_config(
122+ pin: Peri <' d, impl $complementary_pin_trait<T >>,
123+ pin_config: PwmPinConfig ,
124+ ) -> Self {
125+ critical_section:: with( |_| {
126+ pin. set_low( ) ;
127+ set_as_af!( pin, AfType :: output( pin_config. output_type, pin_config. speed) ) ;
128+ } ) ;
129+ ComplementaryPwmPin {
130+ _pin: pin. into( ) ,
131+ phantom: PhantomData ,
132+ }
133+ }
103134 }
104135
105136 impl <T : Instance > SealedAdvancedChannel <T > for $channel<T > {
@@ -111,13 +142,55 @@ macro_rules! advanced_channel_impl {
111142 } ;
112143}
113144
114- advanced_channel_impl ! ( new_cha, ChA , 0 , ChannelAPin , ChannelAComplementaryPin ) ;
115- advanced_channel_impl ! ( new_chb, ChB , 1 , ChannelBPin , ChannelBComplementaryPin ) ;
116- advanced_channel_impl ! ( new_chc, ChC , 2 , ChannelCPin , ChannelCComplementaryPin ) ;
117- advanced_channel_impl ! ( new_chd, ChD , 3 , ChannelDPin , ChannelDComplementaryPin ) ;
118- advanced_channel_impl ! ( new_che, ChE , 4 , ChannelEPin , ChannelEComplementaryPin ) ;
145+ advanced_channel_impl ! (
146+ new_cha,
147+ new_cha_with_config,
148+ ChA ,
149+ 0 ,
150+ ChannelAPin ,
151+ ChannelAComplementaryPin
152+ ) ;
153+ advanced_channel_impl ! (
154+ new_chb,
155+ new_chb_with_config,
156+ ChB ,
157+ 1 ,
158+ ChannelBPin ,
159+ ChannelBComplementaryPin
160+ ) ;
161+ advanced_channel_impl ! (
162+ new_chc,
163+ new_chc_with_config,
164+ ChC ,
165+ 2 ,
166+ ChannelCPin ,
167+ ChannelCComplementaryPin
168+ ) ;
169+ advanced_channel_impl ! (
170+ new_chd,
171+ new_chd_with_config,
172+ ChD ,
173+ 3 ,
174+ ChannelDPin ,
175+ ChannelDComplementaryPin
176+ ) ;
177+ advanced_channel_impl ! (
178+ new_che,
179+ new_che_with_config,
180+ ChE ,
181+ 4 ,
182+ ChannelEPin ,
183+ ChannelEComplementaryPin
184+ ) ;
119185#[ cfg( hrtim_v2) ]
120- advanced_channel_impl ! ( new_chf, ChF , 5 , ChannelFPin , ChannelFComplementaryPin ) ;
186+ advanced_channel_impl ! (
187+ new_chf,
188+ new_chf_with_config,
189+ ChF ,
190+ 5 ,
191+ ChannelFPin ,
192+ ChannelFComplementaryPin
193+ ) ;
121194
122195/// Struct used to divide a high resolution timer into multiple channels
123196pub struct AdvancedPwm < ' d , T : Instance > {
0 commit comments