From 73b54adf05fdec368f2e0fff1bcc38579560af42 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Tue, 4 Aug 2020 23:08:20 +0200 Subject: [PATCH] Make ADC Channel trait use a stateful method to get the IDs --- CHANGELOG.md | 2 ++ src/adc.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d3c4a147..93ffd102b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/src/adc.rs b/src/adc.rs index acc4aae5f..51c897c4a 100644 --- a/src/adc.rs +++ b/src/adc.rs @@ -20,7 +20,9 @@ use nb; /// impl Channel for Gpio1Pin1 { /// 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 @@ -31,7 +33,9 @@ use nb; /// impl Channel for Gpio2PinA { /// 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 { @@ -44,7 +48,7 @@ pub trait Channel { /// 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. @@ -69,8 +73,8 @@ pub trait Channel { /// { /// type Error = (); /// -/// fn try_read(&mut self, _pin: &mut PIN) -> nb::Result { -/// let chan = 1 << PIN::CHANNEL; +/// fn try_read(&mut self, pin: &mut PIN) -> nb::Result { +/// let chan = 1 << pin.channel(); /// self.power_up(); /// let result = self.do_conversion(chan); /// self.power_down();