2020//! | RX | PB5 | PB12 |
2121
2222use crate :: afio:: Remap ;
23- use crate :: gpio:: { self , Alternate , Cr , Floating , Input , NoPin , PinMode , PullUp , PushPull } ;
23+ use crate :: gpio:: { self , Alternate , Cr , Input , NoPin , PushPull } ;
2424use crate :: pac:: { self , RCC } ;
2525
26- pub trait InMode { }
27- impl InMode for Floating { }
28- impl InMode for PullUp { }
29-
3026pub struct Pins < TX , RX > {
3127 pub tx : TX ,
3228 pub rx : RX ,
@@ -72,50 +68,42 @@ macro_rules! remap {
7268 ) +
7369 None ( NoPin <PushPull >) ,
7470 }
75- pub enum Rx < PULL > {
71+ pub enum Rx {
7672 $(
77- $RX( gpio:: $RX<Input < PULL > >) ,
73+ $RX( gpio:: $RX<Input >) ,
7874 ) +
79- None ( NoPin <PULL >) ,
75+ None ( NoPin <PushPull >) ,
8076 }
8177
8278 $(
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 {
79+ impl From <( gpio:: $TX<Alternate >, gpio:: $RX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx > {
80+ fn from( p: ( gpio:: $TX<Alternate >, gpio:: $RX, & mut <$PER as Remap >:: Mapr ) ) -> Self {
8581 <$PER>:: remap( p. 2 , $remap) ;
8682 Self { tx: Tx :: $TX( p. 0 ) , rx: Rx :: $RX( p. 1 ) }
8783 }
8884 }
8985
90- impl <PULL > From <( gpio:: $TX, gpio:: $RX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx <PULL >>
91- where
92- Input <PULL >: PinMode ,
93- PULL : InMode ,
94- {
86+ impl From <( gpio:: $TX, gpio:: $RX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx > {
9587 fn from( p: ( gpio:: $TX, gpio:: $RX, & mut <$PER as Remap >:: Mapr ) ) -> Self {
9688 let mut cr = Cr ;
9789 let tx = p. 0 . into_mode( & mut cr) ;
98- let rx = p. 1 . into_mode ( & mut cr ) ;
90+ let rx = p. 1 ;
9991 <$PER>:: remap( p. 2 , $remap) ;
10092 Self { tx: Tx :: $TX( tx) , rx: Rx :: $RX( rx) }
10193 }
10294 }
10395
104- impl From <( gpio:: $TX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx < Floating > > {
96+ impl From <( gpio:: $TX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx > {
10597 fn from( p: ( gpio:: $TX, & mut <$PER as Remap >:: Mapr ) ) -> Self {
10698 let tx = p. 0 . into_mode( & mut Cr ) ;
10799 <$PER>:: remap( p. 1 , $remap) ;
108100 Self { tx: Tx :: $TX( tx) , rx: Rx :: None ( NoPin :: new( ) ) }
109101 }
110102 }
111103
112- impl <PULL > From <( gpio:: $RX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx <PULL >>
113- where
114- Input <PULL >: PinMode ,
115- PULL : InMode ,
116- {
104+ impl From <( gpio:: $RX, & mut <$PER as Remap >:: Mapr ) > for Pins <Tx , Rx > {
117105 fn from( p: ( gpio:: $RX, & mut <$PER as Remap >:: Mapr ) ) -> Self {
118- let rx = p. 0 . into_mode ( & mut Cr ) ;
106+ let rx = p. 0 ;
119107 <$PER>:: remap( p. 1 , $remap) ;
120108 Self { tx: Tx :: None ( NoPin :: new( ) ) , rx: Rx :: $RX( rx) }
121109 }
@@ -129,31 +117,25 @@ pub trait CanExt: Sized + Instance {
129117 fn can (
130118 self ,
131119 #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ,
132- pins : impl Into < Pins < Self :: Tx , Self :: Rx < Floating > > > ,
133- ) -> Can < Self , Floating > ;
134- fn can_loopback (
135- self ,
136- #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ,
137- ) -> Can < Self , Floating > ;
120+ pins : impl Into < Pins < Self :: Tx , Self :: Rx > > ,
121+ ) -> Can < Self > ;
122+ fn can_loopback ( self , #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ) -> Can < Self > ;
138123}
139124
140125impl < CAN : Instance > CanExt for CAN {
141126 fn can (
142127 self ,
143128 #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ,
144- pins : impl Into < Pins < Self :: Tx , Self :: Rx < Floating > > > ,
145- ) -> Can < Self , Floating > {
129+ pins : impl Into < Pins < Self :: Tx , Self :: Rx > > ,
130+ ) -> Can < Self > {
146131 Can :: new (
147132 self ,
148133 #[ cfg( not( feature = "connectivity" ) ) ]
149134 usb,
150135 pins,
151136 )
152137 }
153- fn can_loopback (
154- self ,
155- #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ,
156- ) -> Can < Self , Floating > {
138+ fn can_loopback ( self , #[ cfg( not( feature = "connectivity" ) ) ] usb : pac:: USB ) -> Can < Self > {
157139 Can :: new_loopback (
158140 self ,
159141 #[ cfg( not( feature = "connectivity" ) ) ]
@@ -164,35 +146,35 @@ impl<CAN: Instance> CanExt for CAN {
164146
165147pub trait Instance : crate :: rcc:: Enable {
166148 type Tx ;
167- type Rx < PULL > ;
149+ type Rx ;
168150}
169151impl Instance for pac:: CAN1 {
170152 type Tx = can1:: Tx ;
171- type Rx < PULL > = can1:: Rx < PULL > ;
153+ type Rx = can1:: Rx ;
172154}
173155#[ cfg( feature = "connectivity" ) ]
174156impl Instance for pac:: CAN2 {
175157 type Tx = can2:: Tx ;
176- type Rx < PULL > = can2:: Rx < PULL > ;
158+ type Rx = can2:: Rx ;
177159}
178160
179161/// Interface to the CAN peripheral.
180162#[ allow( unused) ]
181- pub struct Can < CAN : Instance , PULL = Floating > {
163+ pub struct Can < CAN : Instance > {
182164 can : CAN ,
183- pins : Option < Pins < CAN :: Tx , CAN :: Rx < PULL > > > ,
165+ pins : Option < Pins < CAN :: Tx , CAN :: Rx > > ,
184166}
185167
186- impl < CAN : Instance , PULL > Can < CAN , PULL > {
168+ impl < CAN : Instance > Can < CAN > {
187169 /// Creates a CAN interface.
188170 ///
189171 /// CAN shares SRAM with the USB peripheral. Take ownership of USB to
190172 /// prevent accidental shared usage.
191173 pub fn new (
192174 can : CAN ,
193175 #[ cfg( not( feature = "connectivity" ) ) ] _usb : pac:: USB ,
194- pins : impl Into < Pins < CAN :: Tx , CAN :: Rx < PULL > > > ,
195- ) -> Can < CAN , PULL > {
176+ pins : impl Into < Pins < CAN :: Tx , CAN :: Rx > > ,
177+ ) -> Can < CAN > {
196178 let rcc = unsafe { & ( * RCC :: ptr ( ) ) } ;
197179 CAN :: enable ( rcc) ;
198180
@@ -204,26 +186,26 @@ impl<CAN: Instance, PULL> Can<CAN, PULL> {
204186 pub fn new_loopback (
205187 can : CAN ,
206188 #[ cfg( not( feature = "connectivity" ) ) ] _usb : pac:: USB ,
207- ) -> Can < CAN , PULL > {
189+ ) -> Can < CAN > {
208190 let rcc = unsafe { & ( * RCC :: ptr ( ) ) } ;
209191 CAN :: enable ( rcc) ;
210192
211193 Can { can, pins : None }
212194 }
213195}
214196
215- unsafe impl < PULL > bxcan:: Instance for Can < pac:: CAN1 , PULL > {
197+ unsafe impl bxcan:: Instance for Can < pac:: CAN1 > {
216198 const REGISTERS : * mut bxcan:: RegisterBlock = pac:: CAN1 :: ptr ( ) as * mut _ ;
217199}
218200
219201#[ cfg( feature = "connectivity" ) ]
220- unsafe impl < PULL > bxcan:: Instance for Can < pac:: CAN2 , PULL > {
202+ unsafe impl bxcan:: Instance for Can < pac:: CAN2 > {
221203 const REGISTERS : * mut bxcan:: RegisterBlock = pac:: CAN2 :: ptr ( ) as * mut _ ;
222204}
223205
224- unsafe impl < PULL > bxcan:: FilterOwner for Can < pac:: CAN1 , PULL > {
206+ unsafe impl bxcan:: FilterOwner for Can < pac:: CAN1 > {
225207 const NUM_FILTER_BANKS : u8 = 28 ;
226208}
227209
228210#[ cfg( feature = "connectivity" ) ]
229- unsafe impl < PULL > bxcan:: MasterInstance for Can < pac:: CAN1 , PULL > { }
211+ unsafe impl bxcan:: MasterInstance for Can < pac:: CAN1 > { }
0 commit comments