Skip to content

Commit 7c3d9aa

Browse files
committed
Added support for continuous and discontinuous scan mode
1 parent 0f23be5 commit 7c3d9aa

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/adc.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ macro_rules! adc_hal {
344344
self.rb.sqr1.modify(|_, w| w.l().bits((len-1) as u8));
345345
}
346346

347+
fn set_continuous_mode(&mut self, continuous: bool) {
348+
self.rb.cr2.modify(|_, w| w.cont().bit(continuous));
349+
}
350+
351+
fn set_discontinuous_mode(&mut self, channels_count: Option<u8>) {
352+
self.rb.cr1.modify(|_, w| match channels_count {
353+
Some(count) => w.discen().set_bit().discnum().bits(count),
354+
None => w.discen().clear_bit(),
355+
});
356+
}
357+
347358
/**
348359
Performs an ADC conversion
349360
@@ -397,6 +408,14 @@ macro_rules! adc_hal {
397408
fn set_regular_sequence (&mut self, channels: &[u8]) {
398409
self.set_regular_sequence(channels);
399410
}
411+
#[inline(always)]
412+
fn set_continuous_mode(&mut self, continuous: bool) {
413+
self.set_continuous_mode(continuous);
414+
}
415+
#[inline(always)]
416+
fn set_discontinuous_mode(&mut self, channels: Option<u8>) {
417+
self.set_discontinuous_mode(channels);
418+
}
400419
}
401420

402421
impl<WORD, PIN> OneShot<$ADC, WORD, PIN> for Adc<$ADC>
@@ -526,6 +545,14 @@ pub trait ChannelTimeSequence {
526545
///
527546
/// Define a sequence of channels to be converted as a regular group.
528547
fn set_regular_sequence(&mut self, channels: &[u8]);
548+
/// Set ADC continuous conversion
549+
///
550+
/// When continuous conversion is enabled conversion does not stop at the last selected group channel but continues again from the first selected group channel.
551+
fn set_continuous_mode(&mut self, continuous: bool);
552+
/// Set ADC discontinuous mode
553+
///
554+
/// It can be used to convert a short sequence of conversions (up to 8) which is a part of the regular sequence of conversions.
555+
fn set_discontinuous_mode(&mut self, channels_count: Option<u8>);
529556
}
530557

531558
/// Set channel sequence and sample times for custom pins
@@ -540,6 +567,10 @@ pub trait ChannelTimeSequence {
540567
/// }
541568
/// fn set_sequence(&mut self) {
542569
/// self.set_regular_sequence(&[0, 2, 0, 2]);
570+
/// // Optionally we can set continuous scan mode
571+
/// self.set_continuous_mode(true);
572+
/// // Also we can use discontinuous conversion (3 channels per conversion)
573+
/// self.set_discontinuous_mode(Some(3));
543574
/// }
544575
/// }
545576
/// ```

0 commit comments

Comments
 (0)