Skip to content

Commit

Permalink
Merge #242
Browse files Browse the repository at this point in the history
242: Make ADC Channel trait use a stateful method to get the IDs r=therealprof a=eldruin

Closes #110 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
  • Loading branch information
bors[bot] and eldruin authored Aug 31, 2020
2 parents d81cf7c + 73b54ad commit 6167156
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
has been renamed `try_write_iter` for consistency.
- Updated `nb` dependency to version `1`.
- The watchdog API now uses move semantics. See [PR](https://github.com/rust-embedded/embedded-hal/pull/222).
- The ADC `Channel` trait now uses a stateful method to get the IDs.

## [v1.0.0-alpha.1] - 2020-06-16

Expand All @@ -39,6 +40,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
in trait implementations where methods cannot fail.
- A new [process](https://github.com/rust-embedded/embedded-hal#how-to-add-a-new-trait)
has been adopted for the addition of traits to the embedded-hal.
- The ADC `Channel` trait now uses a constant to represent the IDs.
- The minimum supported Rust version is 1.35 due to [this issue](https://github.com/rust-lang/rust/issues/54973).

## [v0.2.3] - 2019-05-09
Expand Down
14 changes: 9 additions & 5 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use nb;
/// impl Channel<Adc1> for Gpio1Pin1<Analog> {
/// type ID = u8; // ADC channels are identified numerically
///
/// const CHANNEL: u8 = 7_u8; // GPIO pin 1 is connected to ADC channel 7
/// fn channel(&self) -> Self::ID {
/// 7_u8 // GPIO pin 1 is connected to ADC channel 7
/// }
/// }
///
/// struct Adc2; // ADC with two banks of 16 channels
Expand All @@ -31,7 +33,9 @@ use nb;
/// impl Channel<Adc2> for Gpio2PinA<AltFun> {
/// type ID = (u8, u8); // ADC channels are identified by bank number and channel number
///
/// const CHANNEL: (u8, u8) = (0, 3); // bank 0 channel 3
/// fn channel(&self) -> Self::ID {
/// (0, 3) // bank 0 channel 3
/// }
/// }
/// ```
pub trait Channel<ADC> {
Expand All @@ -44,7 +48,7 @@ pub trait Channel<ADC> {

/// Get the specific ID that identifies this channel, for example `0_u8` for the first ADC
/// channel, if Self::ID is u8.
const CHANNEL: Self::ID;
fn channel(&self) -> Self::ID;
}

/// ADCs that sample on single channels per request, and do so at the time of the request.
Expand All @@ -69,8 +73,8 @@ pub trait Channel<ADC> {
/// {
/// type Error = ();
///
/// fn try_read(&mut self, _pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
/// let chan = 1 << PIN::CHANNEL;
/// fn try_read(&mut self, pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
/// let chan = 1 << pin.channel();
/// self.power_up();
/// let result = self.do_conversion(chan);
/// self.power_down();
Expand Down

0 comments on commit 6167156

Please sign in to comment.