33
33
//! }
34
34
//! ```
35
35
36
+ #[ cfg( feature = "device-selected" ) ]
36
37
use embedded_hal:: adc:: { Channel , OneShot } ;
37
38
38
- use crate :: stm32;
39
-
40
- use crate :: gpio:: * ;
39
+ #[ cfg( feature = "device-selected" ) ]
40
+ use crate :: { stm32, gpio:: * } ;
41
41
42
+ #[ cfg( feature = "device-selected" ) ]
42
43
/// Analog to Digital converter interface
43
44
pub struct Adc {
44
45
rb : stm32:: ADC ,
@@ -70,6 +71,7 @@ pub enum AdcSampleTime {
70
71
T_239 ,
71
72
}
72
73
74
+ #[ cfg( feature = "device-selected" ) ]
73
75
impl AdcSampleTime {
74
76
fn write_bits ( & self , adc : & mut stm32:: ADC ) {
75
77
unsafe {
@@ -117,6 +119,7 @@ pub enum AdcAlign {
117
119
LeftAsRM ,
118
120
}
119
121
122
+ #[ cfg( feature = "device-selected" ) ]
120
123
impl AdcAlign {
121
124
fn write_bits ( & self , adc : & mut stm32:: ADC ) {
122
125
adc. cfgr1 . write ( |w| {
@@ -147,6 +150,7 @@ pub enum AdcPrecision {
147
150
B_6 ,
148
151
}
149
152
153
+ #[ cfg( feature = "device-selected" ) ]
150
154
impl AdcPrecision {
151
155
fn write_bits ( & self , adc : & mut stm32:: ADC ) {
152
156
unsafe {
@@ -167,6 +171,7 @@ impl AdcPrecision {
167
171
}
168
172
}
169
173
174
+ #[ cfg( feature = "device-selected" ) ]
170
175
macro_rules! adc_pins {
171
176
( $( $pin: ty => $chan: expr) ,+ $( , ) * ) => {
172
177
$(
@@ -179,7 +184,7 @@ macro_rules! adc_pins {
179
184
} ;
180
185
}
181
186
182
- #[ cfg( any ( feature = "stm32f042" , feature = "stm32f030" , feature = "stm32f070" , ) ) ]
187
+ #[ cfg( feature = "device-selected" ) ]
183
188
adc_pins ! (
184
189
gpioa:: PA0 <Analog > => 0_u8 ,
185
190
gpioa:: PA1 <Analog > => 1_u8 ,
@@ -211,11 +216,13 @@ pub struct VTemp;
211
216
/// Internal voltage reference (ADC Channel 17)
212
217
pub struct VRef ;
213
218
219
+ #[ cfg( feature = "device-selected" ) ]
214
220
adc_pins ! (
215
221
VTemp => 16_u8 ,
216
222
VRef => 17_u8 ,
217
223
) ;
218
224
225
+ #[ cfg( feature = "device-selected" ) ]
219
226
impl VTemp {
220
227
/// Init a new VTemp
221
228
pub fn new ( ) -> Self {
@@ -236,6 +243,7 @@ impl VTemp {
236
243
}
237
244
}
238
245
246
+ #[ cfg( feature = "device-selected" ) ]
239
247
impl VRef {
240
248
/// Init a new VRef
241
249
pub fn new ( ) -> Self {
@@ -253,17 +261,17 @@ impl VRef {
253
261
}
254
262
}
255
263
256
- #[ cfg( any ( feature = "stm32f042" , ) ) ]
264
+ #[ cfg( feature = "stm32f042" ) ]
257
265
#[ derive( Debug ) ]
258
266
/// Battery reference voltage (ADC Channel 18)
259
267
pub struct VBat ;
260
268
261
- #[ cfg( any ( feature = "stm32f042" , ) ) ]
269
+ #[ cfg( feature = "stm32f042" ) ]
262
270
adc_pins ! (
263
271
VBat => 18_u8 ,
264
272
) ;
265
273
266
- #[ cfg( any ( feature = "stm32f042" , ) ) ]
274
+ #[ cfg( feature = "stm32f042" ) ]
267
275
impl VBat {
268
276
/// Init a new VBat
269
277
pub fn new ( ) -> Self {
@@ -282,6 +290,7 @@ impl VBat {
282
290
}
283
291
}
284
292
293
+ #[ cfg( feature = "device-selected" ) ]
285
294
impl Adc {
286
295
/// Init a new Adc
287
296
///
@@ -381,6 +390,7 @@ impl Adc {
381
390
}
382
391
}
383
392
393
+ #[ cfg( feature = "device-selected" ) ]
384
394
impl < WORD , PIN > OneShot < Adc , WORD , PIN > for Adc
385
395
where
386
396
WORD : From < u16 > ,
0 commit comments