Skip to content

Commit

Permalink
Make ADC Channel::channel() a constant and update MSRV to 1.35
Browse files Browse the repository at this point in the history
  • Loading branch information
eldruin committed Mar 14, 2020
1 parent 5bc0f0c commit ee56d1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- All traits have been marked as proven (`unproven` feature has been removed).
- All trait methods have been made fallible.
- All trait methods have been renamed `try_*` (i.e. `try_send`) for consistency.
- 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
13 changes: 4 additions & 9 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use nb;
/// impl Channel<Adc1> for Gpio1Pin1<Analog> {
/// type ID = u8; // ADC channels are identified numerically
///
/// fn channel() -> u8 { 7_u8 } // GPIO pin 1 is connected to ADC channel 7
/// const CHANNEL: u8 = 7_u8; // GPIO pin 1 is connected to ADC channel 7
/// }
///
/// struct Adc2; // ADC with two banks of 16 channels
Expand All @@ -31,7 +31,7 @@ use nb;
/// impl Channel<Adc2> for Gpio2PinA<AltFun> {
/// type ID = (u8, u8); // ADC channels are identified by bank number and channel number
///
/// fn channel() -> (u8, u8) { (0, 3) } // bank 0 channel 3
/// const CHANNEL: (u8, u8) = (0, 3); // bank 0 channel 3
/// }
/// ```
pub trait Channel<ADC> {
Expand All @@ -44,12 +44,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.
fn channel() -> Self::ID;

// `channel` is a function due to [this reported
// issue](https://github.com/rust-lang/rust/issues/54973). Something about blanket impls
// combined with `type ID; const CHANNEL: Self::ID;` causes problems.
//const CHANNEL: Self::ID;
const CHANNEL: Self::ID;
}

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

0 comments on commit ee56d1e

Please sign in to comment.