@@ -21,53 +21,47 @@ impl<CH1, CH2> From<(CH1, CH2)> for InPins<CH1, CH2> {
21
21
}
22
22
}
23
23
24
- pub struct Pins4 < CH1 , CH2 , CH3 , CH4 > {
25
- pub c1 : CH1 ,
26
- pub c2 : CH2 ,
27
- pub c3 : CH3 ,
28
- pub c4 : CH4 ,
29
- }
30
-
31
- impl < CH1 , CH2 , CH3 , CH4 > From < ( CH1 , CH2 , CH3 , CH4 ) > for Pins4 < CH1 , CH2 , CH3 , CH4 > {
32
- fn from ( value : ( CH1 , CH2 , CH3 , CH4 ) ) -> Self {
33
- Self {
34
- c1 : value. 0 ,
35
- c2 : value. 1 ,
36
- c3 : value. 2 ,
37
- c4 : value. 3 ,
24
+ pinsx ! ( Pins2 : ( CH1 , c1, C1 ) , ( CH2 , c2, C2 ) ) ;
25
+ pinsx ! ( Pins3 : ( CH1 , c1, C1 ) , ( CH2 , c2, C2 ) , ( CH3 , c3, C3 ) ) ;
26
+ pinsx ! ( Pins4 : ( CH1 , c1, C1 ) , ( CH2 , c2, C2 ) , ( CH3 , c3, C3 ) , ( CH4 , c4, C4 ) ) ;
27
+
28
+ macro_rules! pinsx {
29
+ ( $name: ident: $( ( $CH: ident, $c: ident, $C: ident) ) ,+) => {
30
+ pub struct $name<$( $CH) ,+> {
31
+ $(
32
+ pub $c: $CH,
33
+ ) +
38
34
}
39
- }
40
- }
41
35
42
- pub struct Pins3 < CH1 , CH2 , CH3 > {
43
- pub c1 : CH1 ,
44
- pub c2 : CH2 ,
45
- pub c3 : CH3 ,
46
- }
47
-
48
- impl < CH1 , CH2 , CH3 > From < ( CH1 , CH2 , CH3 ) > for Pins3 < CH1 , CH2 , CH3 > {
49
- fn from ( value : ( CH1 , CH2 , CH3 ) ) -> Self {
50
- Self {
51
- c1 : value. 0 ,
52
- c2 : value. 1 ,
53
- c3 : value. 2 ,
36
+ impl <$( $CH) ,+> From <( $( $CH) ,+) > for $name<$( $CH) ,+> {
37
+ fn from( value: ( $( $CH) ,+) ) -> Self {
38
+ let ( $( $c) ,+) = value;
39
+ Self {
40
+ $(
41
+ $c,
42
+ ) +
43
+ }
44
+ }
54
45
}
55
- }
56
- }
57
46
58
- pub struct Pins2 < CH1 , CH2 > {
59
- pub c1 : CH1 ,
60
- pub c2 : CH2 ,
61
- }
62
-
63
- impl < CH1 , CH2 > From < ( CH1 , CH2 ) > for Pins2 < CH1 , CH2 > {
64
- fn from ( value : ( CH1 , CH2 ) ) -> Self {
65
- Self {
66
- c1 : value. 0 ,
67
- c2 : value. 1 ,
47
+ impl <TIM , $( $CH) ,+> Pins <TIM > for $name<$( $CH) ,+>
48
+ where
49
+ $(
50
+ $CH: Pins <TIM >,
51
+ ) +
52
+ {
53
+ const C1 : bool = false $( || $CH:: C1 ) +;
54
+ const C2 : bool = false $( || $CH:: C2 ) +;
55
+ const C3 : bool = false $( || $CH:: C3 ) +;
56
+ const C4 : bool = false $( || $CH:: C4 ) +;
57
+ type Channels = ( $( $CH:: Channels ) ,+) ;
58
+ fn split( ) -> Self :: Channels {
59
+ ( $( $CH:: split( ) ) ,+)
60
+ }
68
61
}
69
- }
62
+ } ;
70
63
}
64
+ use pinsx;
71
65
72
66
#[ cfg( any( feature = "stm32f100" , feature = "stm32f103" , feature = "connectivity" ) ) ]
73
67
pub mod tim1 {
@@ -375,17 +369,6 @@ macro_rules! remap_combo {
375
369
( $TIM: ty; $C1: ident, $C2: ident, $C3: ident, $C4: ident: [
376
370
$( $P0: ident, $P1: ident, $P2: ident, $P3: ident $( => $MAPR: ident { $remapex: expr } ) ?; ) +
377
371
] ) => {
378
- impl Pins <$TIM> for Pins4 <Ch1 , Ch2 , Ch3 , Ch4 > {
379
- const $C1: bool = true ;
380
- const $C2: bool = true ;
381
- const $C3: bool = true ;
382
- const $C4: bool = true ;
383
- type Channels = ( PwmChannel <$TIM, $C1>, PwmChannel <$TIM, $C2>, PwmChannel <$TIM, $C3>, PwmChannel <$TIM, $C4>) ;
384
- fn split( ) -> Self :: Channels {
385
- ( PwmChannel :: new( ) , PwmChannel :: new( ) , PwmChannel :: new( ) , PwmChannel :: new( ) )
386
- }
387
- }
388
-
389
372
$(
390
373
impl From <( gpio:: $P0<Alternate >, gpio:: $P1<Alternate >, gpio:: $P2<Alternate >, gpio:: $P3<Alternate > $( , & mut $MAPR) ?) > for Pins4 <Ch1 , Ch2 , Ch3 , Ch4 > {
391
374
fn from( p: ( gpio:: $P0<Alternate >, gpio:: $P1<Alternate >, gpio:: $P2<Alternate >, gpio:: $P3<Alternate > $( , & mut $MAPR) ?) ) -> Self {
@@ -410,16 +393,6 @@ macro_rules! remap_combo {
410
393
( $TIM: ty; ( $C1: ident, $Ch1: ident) , ( $C2: ident, $Ch2: ident) , ( $C3: ident, $Ch3: ident) : [
411
394
$( $P0: ident, $P1: ident, $P2: ident $( => $MAPR: ident { $remapex: expr } ) ?; ) +
412
395
] ) => {
413
- impl Pins <$TIM> for Pins3 <$Ch1, $Ch2, $Ch3> {
414
- const $C1: bool = true ;
415
- const $C2: bool = true ;
416
- const $C3: bool = true ;
417
- type Channels = ( PwmChannel <$TIM, $C1>, PwmChannel <$TIM, $C2>, PwmChannel <$TIM, $C3>) ;
418
- fn split( ) -> Self :: Channels {
419
- ( PwmChannel :: new( ) , PwmChannel :: new( ) , PwmChannel :: new( ) )
420
- }
421
- }
422
-
423
396
$(
424
397
impl From <( gpio:: $P0<Alternate >, gpio:: $P1<Alternate >, gpio:: $P2<Alternate > $( , & mut $MAPR) ?) > for Pins3 <$Ch1, $Ch2, $Ch3> {
425
398
fn from( p: ( gpio:: $P0<Alternate >, gpio:: $P1<Alternate >, gpio:: $P2<Alternate > $( , & mut $MAPR) ?) ) -> Self {
@@ -443,15 +416,6 @@ macro_rules! remap_combo {
443
416
( $TIM: ty; ( $C1: ident, $Ch1: ident) , ( $C2: ident, $Ch2: ident) : [
444
417
$( $P0: ident, $P1: ident $( => $MAPR: ident { $remapex: expr } ) ?; ) +
445
418
] ) => {
446
- impl Pins <$TIM> for Pins2 <$Ch1, $Ch2> {
447
- const $C1: bool = true ;
448
- const $C2: bool = true ;
449
- type Channels = ( PwmChannel <$TIM, $C1>, PwmChannel <$TIM, $C2>) ;
450
- fn split( ) -> Self :: Channels {
451
- ( PwmChannel :: new( ) , PwmChannel :: new( ) )
452
- }
453
- }
454
-
455
419
$(
456
420
impl From <( gpio:: $P0<Alternate >, gpio:: $P1<Alternate > $( , & mut $MAPR) ?) > for Pins2 <$Ch1, $Ch2> {
457
421
fn from( p: ( gpio:: $P0<Alternate >, gpio:: $P1<Alternate > $( , & mut $MAPR) ?) ) -> Self {
0 commit comments