19
19
//! | TX | PB6 | PB13 |
20
20
//! | RX | PB5 | PB12 |
21
21
22
- use crate :: afio:: MAPR ;
22
+ use crate :: afio:: Remap ;
23
23
use crate :: gpio:: { self , Alternate , Cr , Floating , Input , NoPin , PinMode , PullUp , PushPull } ;
24
24
use crate :: pac:: { self , RCC } ;
25
25
@@ -45,14 +45,10 @@ pub mod can1 {
45
45
use super :: * ;
46
46
47
47
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
+ ]
56
52
}
57
53
}
58
54
@@ -61,70 +57,66 @@ pub mod can2 {
61
57
use super :: * ;
62
58
63
59
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
+ ]
66
64
}
67
65
}
68
66
69
67
macro_rules! remap {
70
- ( $( $ ( # [ $attr : meta ] ) * $ TX: ident, $RX: ident => { $remapex : expr } ; ) +) => {
68
+ ( $PER : ty : [ $ ( $ TX: ident, $RX: ident => $remap : literal ; ) +] ) => {
71
69
pub enum Tx {
72
70
$(
73
- $( #[ $attr] ) *
74
71
$TX( gpio:: $TX<Alternate >) ,
75
72
) +
76
73
None ( NoPin <PushPull >) ,
77
74
}
78
75
pub enum Rx <PULL > {
79
76
$(
80
- $( #[ $attr] ) *
81
77
$RX( gpio:: $RX<Input <PULL >>) ,
82
78
) +
83
79
None ( NoPin <PULL >) ,
84
80
}
85
81
86
82
$(
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) ;
91
86
Self { tx: Tx :: $TX( p. 0 ) , rx: Rx :: $RX( p. 1 ) }
92
87
}
93
88
}
94
89
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 >>
97
91
where
98
92
Input <PULL >: PinMode ,
99
93
PULL : InMode ,
100
94
{
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 {
102
96
let mut cr = Cr ;
103
97
let tx = p. 0 . into_mode( & mut cr) ;
104
98
let rx = p. 1 . into_mode( & mut cr) ;
105
- p. 2 . modify_mapr ( $remapex ) ;
99
+ <$PER> :: remap ( p. 2 , $remap ) ;
106
100
Self { tx: Tx :: $TX( tx) , rx: Rx :: $RX( rx) }
107
101
}
108
102
}
109
103
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 {
113
106
let tx = p. 0 . into_mode( & mut Cr ) ;
114
- p. 1 . modify_mapr ( $remapex ) ;
107
+ <$PER> :: remap ( p. 1 , $remap ) ;
115
108
Self { tx: Tx :: $TX( tx) , rx: Rx :: None ( NoPin :: new( ) ) }
116
109
}
117
110
}
118
111
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 >>
121
113
where
122
114
Input <PULL >: PinMode ,
123
115
PULL : InMode ,
124
116
{
125
- fn from( p: ( gpio:: $RX, & mut MAPR ) ) -> Self {
117
+ fn from( p: ( gpio:: $RX, & mut <$PER as Remap > :: Mapr ) ) -> Self {
126
118
let rx = p. 0 . into_mode( & mut Cr ) ;
127
- p. 1 . modify_mapr ( $remapex ) ;
119
+ <$PER> :: remap ( p. 1 , $remap ) ;
128
120
Self { tx: Tx :: None ( NoPin :: new( ) ) , rx: Rx :: $RX( rx) }
129
121
}
130
122
}
0 commit comments