2020//! | RX | PB5 | PB12 |
2121
2222use crate :: afio:: MAPR ;
23- use crate :: gpio:: { self , Alternate , Cr , Floating , Input , PinMode , PullUp } ;
23+ use crate :: gpio:: { self , Alternate , Cr , Floating , Input , NoPin , PinMode , PullUp , PushPull } ;
2424use crate :: pac:: { self , RCC } ;
2525
2626pub trait InMode { }
2727impl InMode for Floating { }
2828impl InMode for PullUp { }
2929
30+ pub struct Pins < TX , RX > {
31+ pub tx : TX ,
32+ pub rx : RX ,
33+ }
34+
35+ impl < TX , RX > From < ( TX , RX ) > for Pins < TX , RX > {
36+ fn from ( value : ( TX , RX ) ) -> Self {
37+ Self {
38+ tx : value. 0 ,
39+ rx : value. 1 ,
40+ }
41+ }
42+ }
43+
3044pub mod can1 {
3145 use super :: * ;
3246
3347 remap ! {
34- Pins : [
35- #[ cfg( not( feature = "connectivity" ) ) ]
36- All , Tx , Rx , PA12 , PA11 => { |_, w| unsafe { w. can_remap( ) . bits( 0 ) } } ;
37- #[ cfg( feature = "connectivity" ) ]
38- All , Tx , Rx , PA12 , PA11 => { |_, w| unsafe { w. can1_remap( ) . bits( 0 ) } } ;
39- #[ cfg( not( feature = "connectivity" ) ) ]
40- Remap , RemapTx , RemapRx , PB9 , PB8 => { |_, w| unsafe { w. can_remap( ) . bits( 10 ) } } ;
41- #[ cfg( feature = "connectivity" ) ]
42- Remap , RemapTx , RemapRx , PB9 , PB8 => { |_, w| unsafe { w. can1_remap( ) . bits( 10 ) } } ;
43- ]
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 ) } } ;
4456 }
4557}
4658
@@ -49,39 +61,39 @@ pub mod can2 {
4961 use super :: * ;
5062
5163 remap ! {
52- Pins : [
53- All , Tx , Rx , PB6 , PB5 => { |_, w| w. can2_remap( ) . bit( false ) } ;
54- Remap , RemapTx , RemapRx , PB13 , PB12 => { |_, w| w. can2_remap( ) . bit( true ) } ;
55- ]
64+ PB6 , PB5 => { |_, w| w. can2_remap( ) . bit( false ) } ;
65+ PB13 , PB12 => { |_, w| w. can2_remap( ) . bit( true ) } ;
5666 }
5767}
5868
5969macro_rules! remap {
60- ( $name: ident: [
61- $( $( #[ $attr: meta] ) * $rname: ident, $txonly: ident, $rxonly: ident, $TX: ident, $RX: ident => { $remapex: expr } ; ) +
62- ] ) => {
63- pub enum $name<PULL > {
70+ ( $( $( #[ $attr: meta] ) * $TX: ident, $RX: ident => { $remapex: expr } ; ) +) => {
71+ pub enum Tx {
6472 $(
6573 $( #[ $attr] ) *
66- $rname { tx: gpio:: $TX<Alternate >, rx: gpio:: $RX<Input <PULL >> } ,
67- $( #[ $attr] ) *
68- $txonly { tx: gpio:: $TX<Alternate > } ,
74+ $TX( gpio:: $TX<Alternate >) ,
75+ ) +
76+ None ( NoPin <PushPull >) ,
77+ }
78+ pub enum Rx <PULL > {
79+ $(
6980 $( #[ $attr] ) *
70- $rxonly { rx : gpio:: $RX<Input <PULL >> } ,
81+ $RX ( gpio:: $RX<Input <PULL >>) ,
7182 ) +
83+ None ( NoPin <PULL >) ,
7284 }
7385
7486 $(
7587 $( #[ $attr] ) *
76- impl <PULL : InMode > From <( gpio:: $TX<Alternate >, gpio:: $RX<Input <PULL >>, & mut MAPR ) > for $name< PULL > {
88+ impl <PULL : InMode > From <( gpio:: $TX<Alternate >, gpio:: $RX<Input <PULL >>, & mut MAPR ) > for Pins < Tx , Rx < PULL > > {
7789 fn from( p: ( gpio:: $TX<Alternate >, gpio:: $RX<Input <PULL >>, & mut MAPR ) ) -> Self {
7890 p. 2 . modify_mapr( $remapex) ;
79- Self :: $rname { tx: p. 0 , rx: p. 1 }
91+ Self { tx: Tx :: $TX ( p. 0 ) , rx: Rx :: $RX ( p. 1 ) }
8092 }
8193 }
8294
8395 $( #[ $attr] ) *
84- impl <PULL > From <( gpio:: $TX, gpio:: $RX, & mut MAPR ) > for $name< PULL >
96+ impl <PULL > From <( gpio:: $TX, gpio:: $RX, & mut MAPR ) > for Pins < Tx , Rx < PULL > >
8597 where
8698 Input <PULL >: PinMode ,
8799 PULL : InMode ,
@@ -91,29 +103,29 @@ macro_rules! remap {
91103 let tx = p. 0 . into_mode( & mut cr) ;
92104 let rx = p. 1 . into_mode( & mut cr) ;
93105 p. 2 . modify_mapr( $remapex) ;
94- Self :: $rname { tx, rx }
106+ Self { tx: Tx :: $TX ( tx ) , rx: Rx :: $RX ( rx ) }
95107 }
96108 }
97109
98110 $( #[ $attr] ) *
99- impl From <( gpio:: $TX, & mut MAPR ) > for $name< Floating > {
111+ impl From <( gpio:: $TX, & mut MAPR ) > for Pins < Tx , Rx < Floating > > {
100112 fn from( p: ( gpio:: $TX, & mut MAPR ) ) -> Self {
101113 let tx = p. 0 . into_mode( & mut Cr ) ;
102114 p. 1 . modify_mapr( $remapex) ;
103- Self :: $txonly { tx }
115+ Self { tx : Tx :: $TX ( tx ) , rx : Rx :: None ( NoPin :: new ( ) ) }
104116 }
105117 }
106118
107119 $( #[ $attr] ) *
108- impl <PULL > From <( gpio:: $RX, & mut MAPR ) > for $name< PULL >
120+ impl <PULL > From <( gpio:: $RX, & mut MAPR ) > for Pins < Tx , Rx < PULL > >
109121 where
110122 Input <PULL >: PinMode ,
111123 PULL : InMode ,
112124 {
113125 fn from( p: ( gpio:: $RX, & mut MAPR ) ) -> Self {
114126 let rx = p. 0 . into_mode( & mut Cr ) ;
115127 p. 1 . modify_mapr( $remapex) ;
116- Self :: $rxonly { rx }
128+ Self { tx : Tx :: None ( NoPin :: new ( ) ) , rx : Rx :: $RX ( rx ) }
117129 }
118130 }
119131 ) +
@@ -125,7 +137,7 @@ pub trait CanExt: Sized + Instance {
125137 fn can (
126138 self ,
127139 #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ,
128- pins : impl Into < Self :: Pins < Floating > > ,
140+ pins : impl Into < Pins < Self :: Tx , Self :: Rx < Floating > > > ,
129141 ) -> Can < Self , Floating > ;
130142 fn can_loopback (
131143 self ,
@@ -137,7 +149,7 @@ impl<CAN: Instance> CanExt for CAN {
137149 fn can (
138150 self ,
139151 #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ,
140- pins : impl Into < Self :: Pins < Floating > > ,
152+ pins : impl Into < Pins < Self :: Tx , Self :: Rx < Floating > > > ,
141153 ) -> Can < Self , Floating > {
142154 Can :: new (
143155 self ,
@@ -159,21 +171,24 @@ impl<CAN: Instance> CanExt for CAN {
159171}
160172
161173pub trait Instance : crate :: rcc:: Enable {
162- type Pins < PULL > ;
174+ type Tx ;
175+ type Rx < PULL > ;
163176}
164177impl Instance for pac:: CAN1 {
165- type Pins < PULL > = can1:: Pins < PULL > ;
178+ type Tx = can1:: Tx ;
179+ type Rx < PULL > = can1:: Rx < PULL > ;
166180}
167181#[ cfg( feature = "connectivity" ) ]
168182impl Instance for pac:: CAN2 {
169- type Pins < PULL > = can2:: Pins < PULL > ;
183+ type Tx = can2:: Tx ;
184+ type Rx < PULL > = can2:: Rx < PULL > ;
170185}
171186
172187/// Interface to the CAN peripheral.
173188#[ allow( unused) ]
174189pub struct Can < CAN : Instance , PULL = Floating > {
175190 can : CAN ,
176- pins : Option < CAN :: Pins < PULL > > ,
191+ pins : Option < Pins < CAN :: Tx , CAN :: Rx < PULL > > > ,
177192}
178193
179194impl < CAN : Instance , PULL > Can < CAN , PULL > {
@@ -184,7 +199,7 @@ impl<CAN: Instance, PULL> Can<CAN, PULL> {
184199 pub fn new (
185200 can : CAN ,
186201 #[ cfg( not( feature = "connectivity" ) ) ] _usb : pac:: USB ,
187- pins : impl Into < CAN :: Pins < PULL > > ,
202+ pins : impl Into < Pins < CAN :: Tx , CAN :: Rx < PULL > > > ,
188203 ) -> Can < CAN , PULL > {
189204 let rcc = unsafe { & ( * RCC :: ptr ( ) ) } ;
190205 CAN :: enable ( rcc) ;
0 commit comments