Skip to content

Commit 1d812ae

Browse files
update feature gates
1 parent 9ea3dcf commit 1d812ae

File tree

2 files changed

+34
-51
lines changed

2 files changed

+34
-51
lines changed

src/adc.rs

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,37 @@
1-
//! # Work in Progress
21
//! API for the ADC (Analog to Digital Converter)
32
//!
4-
//! Note that the more specific your hardware selection is
5-
//! (e.g. stm32f303**xc** instead of just stm32f303)
6-
//! the more functionality is accessible
7-
//! (in this case: ADC3 and ADC4 additionaly to ADC1 and ADC2).
8-
//!
93
//! # Examples
10-
//! For a simple, working example check `adc.rs` in the examples folder.
4+
//! Check `adc.rs` in the examples folder.
5+
//! It can be built for the STM32F3Discovery running
6+
//! `cargo build --example adc --features=stm32f303xc`
7+
use crate::{
8+
gpio::Analog,
9+
rcc::{Clocks, AHB},
10+
};
1111
use cortex_m::asm;
1212
use embedded_hal::adc::{Channel, OneShot};
13-
#[cfg(feature = "stm32f303")]
14-
use stm32f3::stm32f303::adc1_2::ccr::CKMODE_A;
1513

16-
use crate::rcc::{Clocks, AHB};
17-
18-
#[cfg(feature = "stm32f303")]
14+
use crate::{
15+
gpio::{gpioa, gpiob, gpioc},
16+
pac::{ADC1, ADC1_2, ADC2},
17+
};
18+
use stm32f3::stm32f303::adc1_2::ccr::CKMODE_A;
1919
const MAX_ADVREGEN_STARTUP_US: u32 = 10;
2020

21-
#[cfg(feature = "stm32f303")]
22-
use crate::gpio::{gpioa, gpiob, gpioc, Analog};
23-
24-
#[cfg(any(
25-
feature = "stm32f303xb",
26-
feature = "stm32f303xc",
27-
feature = "stm32f303xd",
28-
feature = "stm32f303xe",
29-
))]
30-
use crate::gpio::{gpiod, gpioe, gpiof};
31-
32-
#[cfg(feature = "stm32f303")]
33-
use crate::pac::{ADC1, ADC1_2, ADC2};
34-
3521
#[cfg(any(
3622
feature = "stm32f303xb",
3723
feature = "stm32f303xc",
3824
feature = "stm32f303xd",
3925
feature = "stm32f303xe",
4026
))]
41-
use crate::pac::{ADC3, ADC3_4, ADC4};
27+
use crate::{
28+
gpio::{gpiod, gpioe, gpiof},
29+
pac::{ADC3, ADC3_4, ADC4},
30+
};
4231

4332
/// ADC configuration
44-
///
45-
/// TODO: Remove `pub` from the register block once all functionalities are implemented.
46-
/// Leave it here until then as it allows easy access to the registers.
33+
// TODO: Remove `pub` from the register block once all functionalities are implemented.
34+
// Leave it here until then as it allows easy access to the registers.
4735
pub struct Adc<ADC> {
4836
pub rb: ADC,
4937
clocks: Clocks,
@@ -54,11 +42,11 @@ pub struct Adc<ADC> {
5442
/// ADC sampling time
5543
///
5644
/// Each channel can be sampled with a different sample time.
57-
/// For Sampletime T_n the total conversion time (in ADC clock cycles) is
58-
/// 12.5 + (n + .5)
59-
///
60-
/// TODO: there are boundaries on how this can be set depending on the hardware.
61-
/// Check them and implement a sample time setting mechanism.
45+
/// There is always an overhead of 13 ADC clock cycles.
46+
/// E.g. For Sampletime T_19 the total conversion time (in ADC clock cycles) is
47+
/// 13 + 19 = 32 ADC Clock Cycles
48+
// TODO: there are boundaries on how this can be set depending on the hardware.
49+
// Check them and implement a sample time setting mechanism.
6250
pub enum SampleTime {
6351
T_1,
6452
T_2,
@@ -94,16 +82,14 @@ impl SampleTime {
9482

9583
#[derive(Clone, Copy, PartialEq)]
9684
/// ADC operation mode
97-
///
98-
/// TODO: Implement other modes (DMA, Differential,…)
85+
// TODO: Implement other modes (DMA, Differential,…)
9986
pub enum OperationMode {
10087
OneShot,
10188
}
10289

10390
#[derive(Clone, Copy, PartialEq)]
10491
/// ADC CKMODE
105-
///
106-
/// TODO: Add ASYNCHRONOUS mode
92+
// TODO: Add ASYNCHRONOUS mode
10793
pub enum CKMODE {
10894
// ASYNCHRONOUS = 0,
10995
SYNCDIV1 = 1,
@@ -119,7 +105,7 @@ impl Default for CKMODE {
119105

120106
// ADC3_2 returns a pointer to a adc1_2 type, so this from is ok for both.
121107
#[cfg(feature = "stm32f303")]
122-
impl From<CKMODE> for stm32f3::stm32f303::adc1_2::ccr::CKMODE_A {
108+
impl From<CKMODE> for CKMODE_A {
123109
fn from(ckmode: CKMODE) -> Self {
124110
match ckmode {
125111
//CKMODE::ASYNCHRONOUS => CKMODE_A::ASYNCHRONOUS,
@@ -289,10 +275,9 @@ adc_pins!(ADC4,
289275
gpiod::PD14<Analog> => 11_u8,
290276
);
291277

292-
/// Abstract implementation of ADC functionality
293-
///
294-
/// Do not use directly. See adc12_hal for a applicable Macro.
295-
/// TODO: Extend/generalize beyond f303
278+
// Abstract implementation of ADC functionality
279+
// Do not use directly. See adc12_hal for a applicable Macro.
280+
// TODO: Extend/generalize beyond f303
296281
macro_rules! adc_hal {
297282
($(
298283
$ADC:ident: ($adcx:ident, $ADC_COMMON:ident),
@@ -474,9 +459,8 @@ macro_rules! adc_hal {
474459
}
475460
}
476461

477-
/// Macro to implement ADC functionallity for ADC1 and ADC2
478-
///
479-
/// TODO: Extend/differentiate beyond f303.
462+
// Macro to implement ADC functionallity for ADC1 and ADC2
463+
// TODO: Extend/differentiate beyond f303.
480464
macro_rules! adc12_hal {
481465
($(
482466
$ADC:ident: ($adcx:ident),
@@ -504,9 +488,8 @@ macro_rules! adc12_hal {
504488
}
505489
}
506490

507-
/// Macro to implement ADC functionallity for ADC3 and ADC4
508-
///
509-
/// TODO: Extend/differentiate beyond f303.
491+
// Macro to implement ADC functionallity for ADC3 and ADC4
492+
// TODO: Extend/differentiate beyond f303.
510493
#[cfg(any(
511494
feature = "stm32f303xb",
512495
feature = "stm32f303xc",

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub use crate::pac as stm32;
120120
#[cfg(feature = "rt")]
121121
pub use crate::pac::interrupt;
122122

123-
#[cfg(feature = "device-selected")]
123+
#[cfg(feature = "stm32f303")]
124124
pub mod adc;
125125
#[cfg(feature = "device-selected")]
126126
pub mod delay;

0 commit comments

Comments
 (0)