@@ -7,6 +7,13 @@ use crate::{
77use core:: { marker:: PhantomData , ops:: Deref } ;
88
99pub use super :: ext:: { Chan , Cmp } ;
10+ #[ derive( Debug , PartialEq , Clone , Copy ) ]
11+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
12+ pub enum SwapPins {
13+ Normal ,
14+ Swapped ,
15+ }
16+
1017use super :: {
1118 capture:: { self , HrCapt , HrCapture } ,
1219 control:: HrPwmCtrl ,
@@ -186,6 +193,10 @@ pub trait HrSlaveTimer: HrTimer {
186193 & mut self ,
187194 _event : & E ,
188195 ) ;
196+
197+ #[ cfg( feature = "stm32g4" ) ]
198+ /// This is only allowed while having register preload enabled (PREEN is set to 1)
199+ unsafe fn swap_outputs ( & self , _hr_control : & mut HrPwmCtrl , swap : SwapPins ) ;
189200}
190201
191202pub struct TimerSplitCapture < T , PSCL , CH1 , CH2 , DacRst : DacResetTrigger > {
@@ -373,6 +384,18 @@ where
373384 tim. rstr ( ) . modify ( |r, w| w. bits ( r. bits ( ) & !E :: BITS ) ) ;
374385 }
375386 }
387+
388+ #[ cfg( feature = "stm32g4" ) ]
389+ /// This is only allowed while having register preload enabled (PREEN is set to 1)
390+ unsafe fn swap_outputs ( & self , _hr_control : & mut HrPwmCtrl , swap : SwapPins ) {
391+ use super :: HRTIM_COMMON ;
392+
393+ // SAFETY: Since we hold _hr_control there is no risk for a race condition
394+ let common = unsafe { & * HRTIM_COMMON :: ptr ( ) } ;
395+ common
396+ . cr2 ( )
397+ . modify ( |_r, w| w. swp ( TIM :: T_X as u8 ) . bit ( swap == SwapPins :: Swapped ) ) ;
398+ }
376399}
377400
378401impl < TIM : InstanceX , PSCL , DacRst > HrSlaveTimerCpt
0 commit comments