@@ -317,7 +317,7 @@ pub type CCR4<T> = CCR<T, 3>;
317317pub struct DMAR < T > ( T ) ;
318318
319319mod sealed {
320- use super :: { BitFlags , Channel , Event , Flag , IdleState , Ocm , Polarity } ;
320+ use super :: { BitFlags , Event , Flag , IdleState , Ocm , Polarity } ;
321321 pub trait General {
322322 type Width : Into < u32 > + From < u16 > ;
323323 fn max_auto_reload ( ) -> u32 ;
@@ -364,14 +364,20 @@ mod sealed {
364364 }
365365
366366 pub trait WithPwm : WithPwmCommon {
367- fn preload_output_channel_in_mode ( & mut self , channel : Channel , mode : Ocm ) ;
367+ fn preload_output_channel_in_mode ( & mut self , c : u8 , mode : Ocm ) ;
368+ fn freeze_output_channel ( & mut self , c : u8 ) ;
368369 fn start_pwm ( & mut self ) ;
369370 }
370371
371372 pub trait MasterTimer : General {
372373 type Mms ;
373374 fn master_mode ( & mut self , mode : Self :: Mms ) ;
374375 }
376+
377+ pub trait Split {
378+ type Channels ;
379+ fn split ( ) -> Self :: Channels ;
380+ }
375381}
376382pub ( crate ) use sealed:: { Advanced , General , MasterTimer , WithPwm , WithPwmCommon } ;
377383
@@ -380,6 +386,27 @@ pub trait Instance:
380386{
381387}
382388
389+ use sealed:: Split ;
390+ macro_rules! split {
391+ ( $TIM: ty: 1 ) => {
392+ split!( $TIM, C1 ) ;
393+ } ;
394+ ( $TIM: ty: 2 ) => {
395+ split!( $TIM, C1 , C2 ) ;
396+ } ;
397+ ( $TIM: ty: 4 ) => {
398+ split!( $TIM, C1 , C2 , C3 , C4 ) ;
399+ } ;
400+ ( $TIM: ty, $( $C: ident) ,+) => {
401+ impl Split for $TIM {
402+ type Channels = ( $( PwmChannelDisabled <$TIM, $C>, ) +) ;
403+ fn split( ) -> Self :: Channels {
404+ ( $( PwmChannelDisabled :: <_, $C>:: new( ) , ) +)
405+ }
406+ }
407+ } ;
408+ }
409+
383410macro_rules! hal {
384411 ( $TIM: ty: [
385412 $Timer: ident,
@@ -389,6 +416,11 @@ macro_rules! hal {
389416 $( m: $timbase: ident, ) ?
390417 ] ) => {
391418 impl Instance for $TIM { }
419+ impl crate :: Steal for $TIM {
420+ unsafe fn steal( ) -> Self {
421+ Self :: steal( )
422+ }
423+ }
392424 pub type $Timer = Timer <$TIM>;
393425
394426 impl General for $TIM {
@@ -577,6 +609,7 @@ macro_rules! hal {
577609 ) ?
578610
579611 with_pwm!( $TIM: $cnum $( , $aoe) ?) ;
612+ split!( $TIM: $cnum) ;
580613 unsafe impl <const C : u8 > PeriAddress for CCR <$TIM, C > {
581614 #[ inline( always) ]
582615 fn address( & self ) -> u32 {
@@ -611,13 +644,13 @@ macro_rules! with_dmar {
611644}
612645
613646macro_rules! with_pwm {
614- ( $TIM: ty: [ $( $Cx: ident , $ccmrx_output: ident, $ocxpe: ident, $ocxm: ident; ) +] $( , $aoe: ident) ?) => {
647+ ( $TIM: ty: [ $( $Cx: literal , $ccmrx_output: ident, $ocxpe: ident, $ocxm: ident; ) +] $( , $aoe: ident) ?) => {
615648 impl WithPwm for $TIM {
616649 #[ inline( always) ]
617- fn preload_output_channel_in_mode( & mut self , channel : Channel , mode: Ocm ) {
618- match channel {
650+ fn preload_output_channel_in_mode( & mut self , c : u8 , mode: Ocm ) {
651+ match c {
619652 $(
620- Channel :: $Cx => {
653+ $Cx => {
621654 self . $ccmrx_output( )
622655 . modify( |_, w| w. $ocxpe( ) . set_bit( ) . $ocxm( ) . set( mode as _) ) ;
623656 }
@@ -626,6 +659,18 @@ macro_rules! with_pwm {
626659 _ => { } ,
627660 }
628661 }
662+ fn freeze_output_channel( & mut self , c: u8 ) {
663+ match c {
664+ $(
665+ $Cx => {
666+ self . $ccmrx_output( )
667+ . modify( |_, w| w. $ocxpe( ) . clear_bit( ) . $ocxm( ) . set( Ocm :: Frozen as _) ) ;
668+ }
669+ ) +
670+ #[ allow( unreachable_patterns) ]
671+ _ => { } ,
672+ }
673+ }
629674
630675 #[ inline( always) ]
631676 fn start_pwm( & mut self ) {
@@ -636,21 +681,21 @@ macro_rules! with_pwm {
636681 } ;
637682 ( $TIM: ty: 1 ) => {
638683 with_pwm!( $TIM: [
639- C1 , ccmr1_output, oc1pe, oc1m;
684+ 0 , ccmr1_output, oc1pe, oc1m;
640685 ] ) ;
641686 } ;
642687 ( $TIM: ty: 2 ) => {
643688 with_pwm!( $TIM: [
644- C1 , ccmr1_output, oc1pe, oc1m;
645- C2 , ccmr1_output, oc2pe, oc2m;
689+ 0 , ccmr1_output, oc1pe, oc1m;
690+ 1 , ccmr1_output, oc2pe, oc2m;
646691 ] ) ;
647692 } ;
648693 ( $TIM: ty: 4 $( , $aoe: ident) ?) => {
649694 with_pwm!( $TIM: [
650- C1 , ccmr1_output, oc1pe, oc1m;
651- C2 , ccmr1_output, oc2pe, oc2m;
652- C3 , ccmr2_output, oc3pe, oc3m;
653- C4 , ccmr2_output, oc4pe, oc4m;
695+ 0 , ccmr1_output, oc1pe, oc1m;
696+ 1 , ccmr1_output, oc2pe, oc2m;
697+ 2 , ccmr2_output, oc3pe, oc3m;
698+ 3 , ccmr2_output, oc4pe, oc4m;
654699 ] $( , $aoe) ?) ;
655700 } ;
656701}
0 commit comments