Skip to content

Commit 40c121c

Browse files
author
Brandon Matthews
committed
Make Channel trait apply to a specific ADC via type parameter
1 parent 5a1afea commit 40c121c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/adc.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
#[cfg(feature = "unproven")]
44
use nb;
55

6-
// TODO Channel should be made generic over ADCs, but cannot due to [this reported
7-
// issue](https://github.com/rust-lang/rust/issues/54973). Something about blanket impls combined
8-
// with `type ID; const CHANNEL: Self::ID;` causes problems. So, for now, Channel can only be
9-
// impl'd once for a given pin.
10-
116
/// A marker trait to identify MCU pins that can be used as inputs to an ADC channel.
127
///
138
/// This marker trait denotes an object, i.e. a GPIO pin, that is ready for use as an input to the
@@ -41,16 +36,22 @@ use nb;
4136
/// }
4237
/// ```
4338
#[cfg(feature = "unproven")]
44-
pub trait Channel {
39+
pub trait Channel<ADC> {
4540
/// Channel ID type
4641
///
4742
/// A type used to identify this ADC channel. For example, if the ADC has eight channels, this
4843
/// might be a `u8`. If the ADC has multiple banks of channels, it could be a tuple, like
4944
/// `(u8: bank_id, u8: channel_id)`.
5045
type ID;
5146

52-
/// The specific ID that identifies this channel, for example `0` for the first ADC channel.
53-
const CHANNEL: Self::ID;
47+
/// Get the specific ID that identifies this channel, for example `0_u8` for the first ADC
48+
/// channel, if Self::ID is u8.
49+
fn channel() -> Self::ID;
50+
51+
// `channel` is a function due to [this reported
52+
// issue](https://github.com/rust-lang/rust/issues/54973). Something about blanket impls
53+
// combined with `type ID; const CHANNEL: Self::ID;` causes problems.
54+
//const CHANNEL: Self::ID;
5455
}
5556

5657
/// ADCs that sample on single channels per request, and do so at the time of the request.
@@ -85,7 +86,7 @@ pub trait Channel {
8586
/// }
8687
/// ```
8788
#[cfg(feature = "unproven")]
88-
pub trait OneShot<ADC, Word, Pin: Channel> {
89+
pub trait OneShot<ADC, Word, Pin: Channel<ADC>> {
8990
/// Error type returned by ADC methods
9091
type Error;
9192

0 commit comments

Comments
 (0)