20
20
//! | RX | PB5 | PB12 |
21
21
22
22
use 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 } ;
24
24
use crate :: pac:: { self , RCC } ;
25
25
26
- pub trait InMode { }
27
- impl InMode for Floating { }
28
- impl InMode for PullUp { }
29
-
30
26
pub struct Pins < TX , RX > {
31
27
pub tx : TX ,
32
28
pub rx : RX ,
@@ -72,50 +68,42 @@ macro_rules! remap {
72
68
) +
73
69
None ( NoPin <PushPull >) ,
74
70
}
75
- pub enum Rx < PULL > {
71
+ pub enum Rx {
76
72
$(
77
- $RX( gpio:: $RX<Input < PULL > >) ,
73
+ $RX( gpio:: $RX<Input >) ,
78
74
) +
79
- None ( NoPin <PULL >) ,
75
+ None ( NoPin <PushPull >) ,
80
76
}
81
77
82
78
$(
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 {
85
81
<$PER>:: remap( p. 2 , $remap) ;
86
82
Self { tx: Tx :: $TX( p. 0 ) , rx: Rx :: $RX( p. 1 ) }
87
83
}
88
84
}
89
85
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 > {
95
87
fn from( p: ( gpio:: $TX, gpio:: $RX, & mut <$PER as Remap >:: Mapr ) ) -> Self {
96
88
let mut cr = Cr ;
97
89
let tx = p. 0 . into_mode( & mut cr) ;
98
- let rx = p. 1 . into_mode ( & mut cr ) ;
90
+ let rx = p. 1 ;
99
91
<$PER>:: remap( p. 2 , $remap) ;
100
92
Self { tx: Tx :: $TX( tx) , rx: Rx :: $RX( rx) }
101
93
}
102
94
}
103
95
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 > {
105
97
fn from( p: ( gpio:: $TX, & mut <$PER as Remap >:: Mapr ) ) -> Self {
106
98
let tx = p. 0 . into_mode( & mut Cr ) ;
107
99
<$PER>:: remap( p. 1 , $remap) ;
108
100
Self { tx: Tx :: $TX( tx) , rx: Rx :: None ( NoPin :: new( ) ) }
109
101
}
110
102
}
111
103
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 > {
117
105
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 ;
119
107
<$PER>:: remap( p. 1 , $remap) ;
120
108
Self { tx: Tx :: None ( NoPin :: new( ) ) , rx: Rx :: $RX( rx) }
121
109
}
@@ -129,31 +117,25 @@ pub trait CanExt: Sized + Instance {
129
117
fn can (
130
118
self ,
131
119
#[ 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 > ;
138
123
}
139
124
140
125
impl < CAN : Instance > CanExt for CAN {
141
126
fn can (
142
127
self ,
143
128
#[ 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 > {
146
131
Can :: new (
147
132
self ,
148
133
#[ cfg( not( feature = "connectivity" ) ) ]
149
134
usb,
150
135
pins,
151
136
)
152
137
}
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 > {
157
139
Can :: new_loopback (
158
140
self ,
159
141
#[ cfg( not( feature = "connectivity" ) ) ]
@@ -164,35 +146,35 @@ impl<CAN: Instance> CanExt for CAN {
164
146
165
147
pub trait Instance : crate :: rcc:: Enable {
166
148
type Tx ;
167
- type Rx < PULL > ;
149
+ type Rx ;
168
150
}
169
151
impl Instance for pac:: CAN1 {
170
152
type Tx = can1:: Tx ;
171
- type Rx < PULL > = can1:: Rx < PULL > ;
153
+ type Rx = can1:: Rx ;
172
154
}
173
155
#[ cfg( feature = "connectivity" ) ]
174
156
impl Instance for pac:: CAN2 {
175
157
type Tx = can2:: Tx ;
176
- type Rx < PULL > = can2:: Rx < PULL > ;
158
+ type Rx = can2:: Rx ;
177
159
}
178
160
179
161
/// Interface to the CAN peripheral.
180
162
#[ allow( unused) ]
181
- pub struct Can < CAN : Instance , PULL = Floating > {
163
+ pub struct Can < CAN : Instance > {
182
164
can : CAN ,
183
- pins : Option < Pins < CAN :: Tx , CAN :: Rx < PULL > > > ,
165
+ pins : Option < Pins < CAN :: Tx , CAN :: Rx > > ,
184
166
}
185
167
186
- impl < CAN : Instance , PULL > Can < CAN , PULL > {
168
+ impl < CAN : Instance > Can < CAN > {
187
169
/// Creates a CAN interface.
188
170
///
189
171
/// CAN shares SRAM with the USB peripheral. Take ownership of USB to
190
172
/// prevent accidental shared usage.
191
173
pub fn new (
192
174
can : CAN ,
193
175
#[ 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 > {
196
178
let rcc = unsafe { & ( * RCC :: ptr ( ) ) } ;
197
179
CAN :: enable ( rcc) ;
198
180
@@ -204,26 +186,26 @@ impl<CAN: Instance, PULL> Can<CAN, PULL> {
204
186
pub fn new_loopback (
205
187
can : CAN ,
206
188
#[ cfg( not( feature = "connectivity" ) ) ] _usb : pac:: USB ,
207
- ) -> Can < CAN , PULL > {
189
+ ) -> Can < CAN > {
208
190
let rcc = unsafe { & ( * RCC :: ptr ( ) ) } ;
209
191
CAN :: enable ( rcc) ;
210
192
211
193
Can { can, pins : None }
212
194
}
213
195
}
214
196
215
- unsafe impl < PULL > bxcan:: Instance for Can < pac:: CAN1 , PULL > {
197
+ unsafe impl bxcan:: Instance for Can < pac:: CAN1 > {
216
198
const REGISTERS : * mut bxcan:: RegisterBlock = pac:: CAN1 :: ptr ( ) as * mut _ ;
217
199
}
218
200
219
201
#[ cfg( feature = "connectivity" ) ]
220
- unsafe impl < PULL > bxcan:: Instance for Can < pac:: CAN2 , PULL > {
202
+ unsafe impl bxcan:: Instance for Can < pac:: CAN2 > {
221
203
const REGISTERS : * mut bxcan:: RegisterBlock = pac:: CAN2 :: ptr ( ) as * mut _ ;
222
204
}
223
205
224
- unsafe impl < PULL > bxcan:: FilterOwner for Can < pac:: CAN1 , PULL > {
206
+ unsafe impl bxcan:: FilterOwner for Can < pac:: CAN1 > {
225
207
const NUM_FILTER_BANKS : u8 = 28 ;
226
208
}
227
209
228
210
#[ 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