@@ -317,7 +317,7 @@ pub type CCR4<T> = CCR<T, 3>;
317
317
pub struct DMAR < T > ( T ) ;
318
318
319
319
mod sealed {
320
- use super :: { BitFlags , Channel , Event , Flag , IdleState , Ocm , Polarity } ;
320
+ use super :: { BitFlags , Event , Flag , IdleState , Ocm , Polarity } ;
321
321
pub trait General {
322
322
type Width : Into < u32 > + From < u16 > ;
323
323
fn max_auto_reload ( ) -> u32 ;
@@ -364,14 +364,20 @@ mod sealed {
364
364
}
365
365
366
366
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 ) ;
368
369
fn start_pwm ( & mut self ) ;
369
370
}
370
371
371
372
pub trait MasterTimer : General {
372
373
type Mms ;
373
374
fn master_mode ( & mut self , mode : Self :: Mms ) ;
374
375
}
376
+
377
+ pub trait Split {
378
+ type Channels ;
379
+ fn split ( ) -> Self :: Channels ;
380
+ }
375
381
}
376
382
pub ( crate ) use sealed:: { Advanced , General , MasterTimer , WithPwm , WithPwmCommon } ;
377
383
@@ -380,6 +386,27 @@ pub trait Instance:
380
386
{
381
387
}
382
388
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
+
383
410
macro_rules! hal {
384
411
( $TIM: ty: [
385
412
$Timer: ident,
@@ -389,6 +416,11 @@ macro_rules! hal {
389
416
$( m: $timbase: ident, ) ?
390
417
] ) => {
391
418
impl Instance for $TIM { }
419
+ impl crate :: Steal for $TIM {
420
+ unsafe fn steal( ) -> Self {
421
+ Self :: steal( )
422
+ }
423
+ }
392
424
pub type $Timer = Timer <$TIM>;
393
425
394
426
impl General for $TIM {
@@ -577,6 +609,7 @@ macro_rules! hal {
577
609
) ?
578
610
579
611
with_pwm!( $TIM: $cnum $( , $aoe) ?) ;
612
+ split!( $TIM: $cnum) ;
580
613
unsafe impl <const C : u8 > PeriAddress for CCR <$TIM, C > {
581
614
#[ inline( always) ]
582
615
fn address( & self ) -> u32 {
@@ -611,13 +644,13 @@ macro_rules! with_dmar {
611
644
}
612
645
613
646
macro_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) ?) => {
615
648
impl WithPwm for $TIM {
616
649
#[ 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 {
619
652
$(
620
- Channel :: $Cx => {
653
+ $Cx => {
621
654
self . $ccmrx_output( )
622
655
. modify( |_, w| w. $ocxpe( ) . set_bit( ) . $ocxm( ) . set( mode as _) ) ;
623
656
}
@@ -626,6 +659,18 @@ macro_rules! with_pwm {
626
659
_ => { } ,
627
660
}
628
661
}
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
+ }
629
674
630
675
#[ inline( always) ]
631
676
fn start_pwm( & mut self ) {
@@ -636,21 +681,21 @@ macro_rules! with_pwm {
636
681
} ;
637
682
( $TIM: ty: 1 ) => {
638
683
with_pwm!( $TIM: [
639
- C1 , ccmr1_output, oc1pe, oc1m;
684
+ 0 , ccmr1_output, oc1pe, oc1m;
640
685
] ) ;
641
686
} ;
642
687
( $TIM: ty: 2 ) => {
643
688
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;
646
691
] ) ;
647
692
} ;
648
693
( $TIM: ty: 4 $( , $aoe: ident) ?) => {
649
694
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;
654
699
] $( , $aoe) ?) ;
655
700
} ;
656
701
}
0 commit comments