Skip to content

Make ADC Channel trait use a stateful method to get the IDs #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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