Skip to content

Commit 6167156

Browse files
bors[bot]eldruin
andauthored
Merge #242
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 <[email protected]>
2 parents d81cf7c + 73b54ad commit 6167156

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
has been renamed `try_write_iter` for consistency.
2222
- Updated `nb` dependency to version `1`.
2323
- The watchdog API now uses move semantics. See [PR](https://github.com/rust-embedded/embedded-hal/pull/222).
24+
- The ADC `Channel` trait now uses a stateful method to get the IDs.
2425

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

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

4446
## [v0.2.3] - 2019-05-09

src/adc.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ use nb;
2020
/// impl Channel<Adc1> for Gpio1Pin1<Analog> {
2121
/// type ID = u8; // ADC channels are identified numerically
2222
///
23-
/// const CHANNEL: u8 = 7_u8; // GPIO pin 1 is connected to ADC channel 7
23+
/// fn channel(&self) -> Self::ID {
24+
/// 7_u8 // GPIO pin 1 is connected to ADC channel 7
25+
/// }
2426
/// }
2527
///
2628
/// struct Adc2; // ADC with two banks of 16 channels
@@ -31,7 +33,9 @@ use nb;
3133
/// impl Channel<Adc2> for Gpio2PinA<AltFun> {
3234
/// type ID = (u8, u8); // ADC channels are identified by bank number and channel number
3335
///
34-
/// const CHANNEL: (u8, u8) = (0, 3); // bank 0 channel 3
36+
/// fn channel(&self) -> Self::ID {
37+
/// (0, 3) // bank 0 channel 3
38+
/// }
3539
/// }
3640
/// ```
3741
pub trait Channel<ADC> {
@@ -44,7 +48,7 @@ pub trait Channel<ADC> {
4448

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

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

0 commit comments

Comments
 (0)