Skip to content

Commit c887102

Browse files
NandoBongersNando Bongers
andauthored
ADC claim optional reset (#52)
* Added the pwm configuration for TIM20 * Added the pwm configuration for TIM20 * ADC optional reset Co-authored-by: Nando Bongers <[email protected]>
1 parent cc683ca commit c887102

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

examples/adc-continious-dma.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ fn main() -> ! {
4646

4747
info!("Setup Adc1");
4848
let mut delay = cp.SYST.delay(&rcc.clocks);
49-
let mut adc = dp.ADC1.claim(ClockSource::SystemClock, &rcc, &mut delay);
49+
let mut adc = dp
50+
.ADC1
51+
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
5052

5153
adc.enable_temperature(&dp.ADC12_COMMON);
5254
adc.set_continuous(Continuous::Continuous);

examples/adc-continious.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ fn main() -> ! {
4040

4141
info!("Setup Adc1");
4242
let mut delay = cp.SYST.delay(&rcc.clocks);
43-
let mut adc = dp.ADC1.claim(ClockSource::SystemClock, &rcc, &mut delay);
43+
let mut adc = dp
44+
.ADC1
45+
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
4446

4547
adc.enable_temperature(&dp.ADC12_COMMON);
4648
adc.enable_vref(&dp.ADC12_COMMON);

examples/adc-one-shot-dma.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ fn main() -> ! {
4747

4848
info!("Setup Adc1");
4949
let mut delay = cp.SYST.delay(&rcc.clocks);
50-
let mut adc = dp.ADC1.claim(ClockSource::SystemClock, &rcc, &mut delay);
50+
let mut adc = dp
51+
.ADC1
52+
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
5153

5254
adc.enable_temperature(&dp.ADC12_COMMON);
5355
adc.set_continuous(Continuous::Single);

examples/adc-one-shot.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ fn main() -> ! {
3333

3434
info!("Setup Adc1");
3535
let mut delay = cp.SYST.delay(&rcc.clocks);
36-
let mut adc = dp.ADC1.claim(ClockSource::SystemClock, &rcc, &mut delay);
36+
let mut adc = dp
37+
.ADC1
38+
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
3739

3840
info!("Setup Gpio");
3941

src/adc.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,13 @@ impl From<ClockSource> for u8 {
10071007
/// used to create an ADC instance from the stm32::Adc
10081008
pub trait AdcClaim<TYPE> {
10091009
/// create a disabled ADC instance from the stm32::Adc
1010-
fn claim(self, cs: ClockSource, rcc: &Rcc, delay: &mut impl DelayUs<u8>)
1011-
-> Adc<TYPE, Disabled>;
1010+
fn claim(
1011+
self,
1012+
cs: ClockSource,
1013+
rcc: &Rcc,
1014+
delay: &mut impl DelayUs<u8>,
1015+
reset: bool,
1016+
) -> Adc<TYPE, Disabled>;
10121017

10131018
/// create an enabled ADC instance from the stm32::Adc
10141019
fn claim_and_configure(
@@ -1017,6 +1022,7 @@ pub trait AdcClaim<TYPE> {
10171022
rcc: &Rcc,
10181023
config: config::AdcConfig,
10191024
delay: &mut impl DelayUs<u8>,
1025+
reset: bool,
10201026
) -> Adc<TYPE, Configured>;
10211027
}
10221028

@@ -1701,11 +1707,11 @@ macro_rules! adc {
17011707
/// * `reset` - should a reset be performed. This is provided because on some devices multiple ADCs share the same common reset
17021708
/// TODO: fix needing SYST
17031709
#[inline(always)]
1704-
fn claim(self, cs: ClockSource, rcc: &Rcc, delay: &mut impl DelayUs<u8>) -> Adc<stm32::$adc_type, Disabled> {
1710+
fn claim(self, cs: ClockSource, rcc: &Rcc, delay: &mut impl DelayUs<u8>, reset: bool) -> Adc<stm32::$adc_type, Disabled> {
17051711
unsafe {
17061712
let rcc_ptr = &(*stm32::RCC::ptr());
17071713
stm32::$adc_type::enable(rcc_ptr);
1708-
stm32::$adc_type::reset(rcc_ptr);
1714+
if reset {stm32::$adc_type::reset(rcc_ptr);}
17091715
}
17101716
Self::configure_clock_source(cs, rcc);
17111717

@@ -1725,8 +1731,8 @@ macro_rules! adc {
17251731

17261732
/// claims and configures the Adc
17271733
#[inline(always)]
1728-
fn claim_and_configure(self, cs: ClockSource, rcc: &Rcc, config: config::AdcConfig, delay: &mut impl DelayUs<u8>) -> Adc<stm32::$adc_type, Configured> {
1729-
let mut adc = self.claim(cs, rcc, delay);
1734+
fn claim_and_configure(self, cs: ClockSource, rcc: &Rcc, config: config::AdcConfig, delay: &mut impl DelayUs<u8>, reset :bool) -> Adc<stm32::$adc_type, Configured> {
1735+
let mut adc = self.claim(cs, rcc, delay, reset);
17301736
adc.adc.config = config;
17311737

17321738
// If the user specified a VDDA, use that over the internally determined value.

0 commit comments

Comments
 (0)