@@ -6,11 +6,10 @@ use embedded_hal::prelude::*;
6
6
use nb:: block;
7
7
use void:: Void ;
8
8
9
+ #[ cfg( any( feature = "stm32f042" , feature = "stm32f030" ) ) ]
9
10
use crate :: stm32:: { RCC , USART1 , USART2 } ;
10
11
11
- use crate :: gpio:: gpioa:: { PA10 , PA14 , PA15 , PA2 , PA3 , PA9 } ;
12
- use crate :: gpio:: gpiob:: { PB6 , PB7 } ;
13
- use crate :: gpio:: { Alternate , AF0 , AF1 } ;
12
+ use crate :: gpio:: * ;
14
13
use crate :: rcc:: Clocks ;
15
14
use crate :: time:: Bps ;
16
15
@@ -40,41 +39,41 @@ pub enum Error {
40
39
pub trait Pins < USART > { }
41
40
42
41
#[ cfg( any( feature = "stm32f030" , feature = "stm32f042" ) ) ]
43
- impl Pins < USART1 > for ( PA9 < Alternate < AF1 > > , PA10 < Alternate < AF1 > > ) { }
42
+ impl Pins < USART1 > for ( gpioa :: PA9 < Alternate < AF1 > > , gpioa :: PA10 < Alternate < AF1 > > ) { }
44
43
#[ cfg( any( feature = "stm32f030" , feature = "stm32f042" ) ) ]
45
- impl Pins < USART1 > for ( PB6 < Alternate < AF0 > > , PB7 < Alternate < AF0 > > ) { }
44
+ impl Pins < USART1 > for ( gpiob :: PB6 < Alternate < AF0 > > , gpiob :: PB7 < Alternate < AF0 > > ) { }
46
45
#[ cfg( any( feature = "stm32f030" , feature = "stm32f042" ) ) ]
47
- impl Pins < USART1 > for ( PA9 < Alternate < AF1 > > , PB7 < Alternate < AF0 > > ) { }
46
+ impl Pins < USART1 > for ( gpioa :: PA9 < Alternate < AF1 > > , gpiob :: PB7 < Alternate < AF0 > > ) { }
48
47
#[ cfg( any( feature = "stm32f030" , feature = "stm32f042" ) ) ]
49
- impl Pins < USART1 > for ( PB6 < Alternate < AF0 > > , PA10 < Alternate < AF1 > > ) { }
48
+ impl Pins < USART1 > for ( gpiob :: PB6 < Alternate < AF0 > > , gpioa :: PA10 < Alternate < AF1 > > ) { }
50
49
51
50
#[ cfg( feature = "stm32f030x6" ) ]
52
- impl Pins < USART1 > for ( PA2 < Alternate < AF1 > > , PA3 < Alternate < AF1 > > ) { }
51
+ impl Pins < USART1 > for ( gpioa :: PA2 < Alternate < AF1 > > , gpioa :: PA3 < Alternate < AF1 > > ) { }
53
52
54
53
#[ cfg( any(
55
54
feature = "stm32f042" ,
56
55
feature = "stm32f030x8" ,
57
56
feature = "stm32f030xc" ,
58
57
) ) ]
59
- impl Pins < USART2 > for ( PA2 < Alternate < AF1 > > , PA3 < Alternate < AF1 > > ) { }
58
+ impl Pins < USART2 > for ( gpioa :: PA2 < Alternate < AF1 > > , gpioa :: PA3 < Alternate < AF1 > > ) { }
60
59
#[ cfg( any(
61
60
feature = "stm32f042" ,
62
61
feature = "stm32f030x8" ,
63
62
feature = "stm32f030xc" ,
64
63
) ) ]
65
- impl Pins < USART2 > for ( PA2 < Alternate < AF1 > > , PA15 < Alternate < AF1 > > ) { }
64
+ impl Pins < USART2 > for ( gpioa :: PA2 < Alternate < AF1 > > , gpioa :: PA15 < Alternate < AF1 > > ) { }
66
65
#[ cfg( any(
67
66
feature = "stm32f042" ,
68
67
feature = "stm32f030x8" ,
69
68
feature = "stm32f030xc" ,
70
69
) ) ]
71
- impl Pins < USART2 > for ( PA14 < Alternate < AF1 > > , PA15 < Alternate < AF1 > > ) { }
70
+ impl Pins < USART2 > for ( gpioa :: PA14 < Alternate < AF1 > > , gpioa :: PA15 < Alternate < AF1 > > ) { }
72
71
#[ cfg( any(
73
72
feature = "stm32f042" ,
74
73
feature = "stm32f030x8" ,
75
74
feature = "stm32f030xc" ,
76
75
) ) ]
77
- impl Pins < USART2 > for ( PA14 < Alternate < AF1 > > , PA3 < Alternate < AF1 > > ) { }
76
+ impl Pins < USART2 > for ( gpioa :: PA14 < Alternate < AF1 > > , gpioa :: PA3 < Alternate < AF1 > > ) { }
78
77
79
78
/// Serial abstraction
80
79
pub struct Serial < USART , PINS > {
@@ -93,6 +92,7 @@ pub struct Tx<USART> {
93
92
}
94
93
95
94
/// USART1
95
+ #[ cfg( any( feature = "stm32f042" , feature = "stm32f030" ) ) ]
96
96
impl < PINS > Serial < USART1 , PINS > {
97
97
pub fn usart1 ( usart : USART1 , pins : PINS , baud_rate : Bps , clocks : Clocks ) -> Self
98
98
where
@@ -133,6 +133,7 @@ impl<PINS> Serial<USART1, PINS> {
133
133
}
134
134
}
135
135
136
+ #[ cfg( any( feature = "stm32f042" , feature = "stm32f030" ) ) ]
136
137
impl embedded_hal:: serial:: Read < u8 > for Rx < USART1 > {
137
138
type Error = Error ;
138
139
@@ -157,6 +158,7 @@ impl embedded_hal::serial::Read<u8> for Rx<USART1> {
157
158
}
158
159
}
159
160
161
+ #[ cfg( any( feature = "stm32f042" , feature = "stm32f030" ) ) ]
160
162
impl embedded_hal:: serial:: Write < u8 > for Tx < USART1 > {
161
163
type Error = Void ;
162
164
@@ -187,6 +189,11 @@ impl embedded_hal::serial::Write<u8> for Tx<USART1> {
187
189
}
188
190
189
191
/// USART2
192
+ #[ cfg( any(
193
+ feature = "stm32f042" ,
194
+ feature = "stm32f030x8" ,
195
+ feature = "stm32f030x8"
196
+ ) ) ]
190
197
impl < PINS > Serial < USART2 , PINS > {
191
198
pub fn usart2 ( usart : USART2 , pins : PINS , baud_rate : Bps , clocks : Clocks ) -> Self
192
199
where
@@ -227,6 +234,11 @@ impl<PINS> Serial<USART2, PINS> {
227
234
}
228
235
}
229
236
237
+ #[ cfg( any(
238
+ feature = "stm32f042" ,
239
+ feature = "stm32f030x8" ,
240
+ feature = "stm32f030x8"
241
+ ) ) ]
230
242
impl embedded_hal:: serial:: Read < u8 > for Rx < USART2 > {
231
243
type Error = Error ;
232
244
@@ -251,6 +263,11 @@ impl embedded_hal::serial::Read<u8> for Rx<USART2> {
251
263
}
252
264
}
253
265
266
+ #[ cfg( any(
267
+ feature = "stm32f042" ,
268
+ feature = "stm32f030x8" ,
269
+ feature = "stm32f030x8"
270
+ ) ) ]
254
271
impl embedded_hal:: serial:: Write < u8 > for Tx < USART2 > {
255
272
type Error = Void ;
256
273
0 commit comments