1919//! | TX | PB6 | PB13 |
2020//! | RX | PB5 | PB12 |
2121
22- use crate :: afio:: MAPR ;
22+ use crate :: afio:: Remap ;
2323use crate :: gpio:: { self , Alternate , Cr , Floating , Input , NoPin , PinMode , PullUp , PushPull } ;
2424use crate :: pac:: { self , RCC } ;
2525
@@ -45,14 +45,10 @@ pub mod can1 {
4545 use super :: * ;
4646
4747 remap ! {
48- #[ cfg( not( feature = "connectivity" ) ) ]
49- PA12 , PA11 => { |_, w| unsafe { w. can_remap( ) . bits( 0 ) } } ;
50- #[ cfg( feature = "connectivity" ) ]
51- PA12 , PA11 => { |_, w| unsafe { w. can1_remap( ) . bits( 0 ) } } ;
52- #[ cfg( not( feature = "connectivity" ) ) ]
53- PB9 , PB8 => { |_, w| unsafe { w. can_remap( ) . bits( 10 ) } } ;
54- #[ cfg( feature = "connectivity" ) ]
55- PB9 , PB8 => { |_, w| unsafe { w. can1_remap( ) . bits( 10 ) } } ;
48+ pac:: CAN1 : [
49+ PA12 , PA11 => 0 ;
50+ PB9 , PB8 => 2 ;
51+ ]
5652 }
5753}
5854
@@ -61,70 +57,66 @@ pub mod can2 {
6157 use super :: * ;
6258
6359 remap ! {
64- PB6 , PB5 => { |_, w| w. can2_remap( ) . bit( false ) } ;
65- PB13 , PB12 => { |_, w| w. can2_remap( ) . bit( true ) } ;
60+ pac:: CAN2 : [
61+ PB6 , PB5 => 0 ;
62+ PB13 , PB12 => 1 ;
63+ ]
6664 }
6765}
6866
6967macro_rules! remap {
70- ( $( $ ( # [ $attr : meta ] ) * $ TX: ident, $RX: ident => { $remapex : expr } ; ) +) => {
68+ ( $PER : ty : [ $ ( $ TX: ident, $RX: ident => $remap : literal ; ) +] ) => {
7169 pub enum Tx {
7270 $(
73- $( #[ $attr] ) *
7471 $TX( gpio:: $TX<Alternate >) ,
7572 ) +
7673 None ( NoPin <PushPull >) ,
7774 }
7875 pub enum Rx <PULL > {
7976 $(
80- $( #[ $attr] ) *
8177 $RX( gpio:: $RX<Input <PULL >>) ,
8278 ) +
8379 None ( NoPin <PULL >) ,
8480 }
8581
8682 $(
87- $( #[ $attr] ) *
88- impl <PULL : InMode > From <( gpio:: $TX<Alternate >, gpio:: $RX<Input <PULL >>, & mut MAPR ) > for Pins <Tx , Rx <PULL >> {
89- fn from( p: ( gpio:: $TX<Alternate >, gpio:: $RX<Input <PULL >>, & mut MAPR ) ) -> Self {
90- p. 2 . modify_mapr( $remapex) ;
83+ impl <PULL : InMode > From <( gpio:: $TX<Alternate >, gpio:: $RX<Input <PULL >>, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx <PULL >> {
84+ fn from( p: ( gpio:: $TX<Alternate >, gpio:: $RX<Input <PULL >>, & mut <$PER as Remap >:: Mapr ) ) -> Self {
85+ <$PER>:: remap( p. 2 , $remap) ;
9186 Self { tx: Tx :: $TX( p. 0 ) , rx: Rx :: $RX( p. 1 ) }
9287 }
9388 }
9489
95- $( #[ $attr] ) *
96- impl <PULL > From <( gpio:: $TX, gpio:: $RX, & mut MAPR ) > for Pins <Tx , Rx <PULL >>
90+ impl <PULL > From <( gpio:: $TX, gpio:: $RX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx <PULL >>
9791 where
9892 Input <PULL >: PinMode ,
9993 PULL : InMode ,
10094 {
101- fn from( p: ( gpio:: $TX, gpio:: $RX, & mut MAPR ) ) -> Self {
95+ fn from( p: ( gpio:: $TX, gpio:: $RX, & mut <$PER as Remap > :: Mapr ) ) -> Self {
10296 let mut cr = Cr ;
10397 let tx = p. 0 . into_mode( & mut cr) ;
10498 let rx = p. 1 . into_mode( & mut cr) ;
105- p. 2 . modify_mapr ( $remapex ) ;
99+ <$PER> :: remap ( p. 2 , $remap ) ;
106100 Self { tx: Tx :: $TX( tx) , rx: Rx :: $RX( rx) }
107101 }
108102 }
109103
110- $( #[ $attr] ) *
111- impl From <( gpio:: $TX, & mut MAPR ) > for Pins <Tx , Rx <Floating >> {
112- fn from( p: ( gpio:: $TX, & mut MAPR ) ) -> Self {
104+ impl From <( gpio:: $TX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx <Floating >> {
105+ fn from( p: ( gpio:: $TX, & mut <$PER as Remap >:: Mapr ) ) -> Self {
113106 let tx = p. 0 . into_mode( & mut Cr ) ;
114- p. 1 . modify_mapr ( $remapex ) ;
107+ <$PER> :: remap ( p. 1 , $remap ) ;
115108 Self { tx: Tx :: $TX( tx) , rx: Rx :: None ( NoPin :: new( ) ) }
116109 }
117110 }
118111
119- $( #[ $attr] ) *
120- impl <PULL > From <( gpio:: $RX, & mut MAPR ) > for Pins <Tx , Rx <PULL >>
112+ impl <PULL > From <( gpio:: $RX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx <PULL >>
121113 where
122114 Input <PULL >: PinMode ,
123115 PULL : InMode ,
124116 {
125- fn from( p: ( gpio:: $RX, & mut MAPR ) ) -> Self {
117+ fn from( p: ( gpio:: $RX, & mut <$PER as Remap > :: Mapr ) ) -> Self {
126118 let rx = p. 0 . into_mode( & mut Cr ) ;
127- p. 1 . modify_mapr ( $remapex ) ;
119+ <$PER> :: remap ( p. 1 , $remap ) ;
128120 Self { tx: Tx :: None ( NoPin :: new( ) ) , rx: Rx :: $RX( rx) }
129121 }
130122 }
0 commit comments