Skip to content

Commit

Permalink
Added support for continuous and discontinuous scan mode (#247)
Browse files Browse the repository at this point in the history
* Added support for continuous and discontinuous scan mode

* Add changelog for #247
  • Loading branch information
katyo authored Sep 5, 2020
1 parent 4338126 commit 2f9f5da
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Add 16 bit dataframe size for `SPI`

### Added

- Add support for ADC continuous conversion
- Add supoort for ADC discontinuous mode

### Fixed

- Fix MonoTimer not working in debug mode.
Expand Down
31 changes: 31 additions & 0 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ macro_rules! adc_hal {
self.rb.sqr1.modify(|_, w| w.l().bits((len-1) as u8));
}

fn set_continuous_mode(&mut self, continuous: bool) {
self.rb.cr2.modify(|_, w| w.cont().bit(continuous));
}

fn set_discontinuous_mode(&mut self, channels_count: Option<u8>) {
self.rb.cr1.modify(|_, w| match channels_count {
Some(count) => w.discen().set_bit().discnum().bits(count),
None => w.discen().clear_bit(),
});
}

/**
Performs an ADC conversion
Expand Down Expand Up @@ -397,6 +408,14 @@ macro_rules! adc_hal {
fn set_regular_sequence (&mut self, channels: &[u8]) {
self.set_regular_sequence(channels);
}
#[inline(always)]
fn set_continuous_mode(&mut self, continuous: bool) {
self.set_continuous_mode(continuous);
}
#[inline(always)]
fn set_discontinuous_mode(&mut self, channels: Option<u8>) {
self.set_discontinuous_mode(channels);
}
}

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

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

0 comments on commit 2f9f5da

Please sign in to comment.