11//! Analog-digital conversion traits
22
3- #[ cfg( feature = "unproven" ) ]
43use nb;
54
65/// A marker trait to identify MCU pins that can be used as inputs to an ADC channel.
109/// between the physical interface and the ADC sampling buffer.
1110///
1211/// ```
13- /// # use std ::marker::PhantomData;
12+ /// # use core ::marker::PhantomData;
1413/// # use embedded_hal::adc::Channel;
1514///
1615/// struct Adc1; // Example ADC with single bank of 8 channels
@@ -21,7 +20,7 @@ use nb;
2120/// impl Channel<Adc1> for Gpio1Pin1<Analog> {
2221/// type ID = u8; // ADC channels are identified numerically
2322///
24- /// fn channel() -> u8 { 7_u8 } // GPIO pin 1 is connected to ADC channel 7
23+ /// const CHANNEL: u8 = 7_u8; // GPIO pin 1 is connected to ADC channel 7
2524/// }
2625///
2726/// struct Adc2; // ADC with two banks of 16 channels
@@ -32,10 +31,9 @@ use nb;
3231/// impl Channel<Adc2> for Gpio2PinA<AltFun> {
3332/// type ID = (u8, u8); // ADC channels are identified by bank number and channel number
3433///
35- /// fn channel() -> (u8, u8) { (0, 3) } // bank 0 channel 3
34+ /// const CHANNEL: (u8, u8) = (0, 3); // bank 0 channel 3
3635/// }
3736/// ```
38- #[ cfg( feature = "unproven" ) ]
3937pub trait Channel < ADC > {
4038 /// Channel ID type
4139 ///
@@ -46,12 +44,7 @@ pub trait Channel<ADC> {
4644
4745 /// Get the specific ID that identifies this channel, for example `0_u8` for the first ADC
4846 /// 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;
47+ const CHANNEL : Self :: ID ;
5548}
5649
5750/// ADCs that sample on single channels per request, and do so at the time of the request.
@@ -76,16 +69,15 @@ pub trait Channel<ADC> {
7669/// {
7770/// type Error = ();
7871///
79- /// fn read (&mut self, _pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
80- /// let chan = 1 << PIN::channel() ;
72+ /// fn try_read (&mut self, _pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
73+ /// let chan = 1 << PIN::CHANNEL ;
8174/// self.power_up();
8275/// let result = self.do_conversion(chan);
8376/// self.power_down();
8477/// Ok(result.into())
8578/// }
8679/// }
8780/// ```
88- #[ cfg( feature = "unproven" ) ]
8981pub trait OneShot < ADC , Word , Pin : Channel < ADC > > {
9082 /// Error type returned by ADC methods
9183 type Error ;
@@ -94,5 +86,5 @@ pub trait OneShot<ADC, Word, Pin: Channel<ADC>> {
9486 ///
9587 /// This method takes a `Pin` reference, as it is expected that the ADC will be able to sample
9688 /// whatever channel underlies the pin.
97- fn read ( & mut self , pin : & mut Pin ) -> nb:: Result < Word , Self :: Error > ;
89+ fn try_read ( & mut self , pin : & mut Pin ) -> nb:: Result < Word , Self :: Error > ;
9890}
0 commit comments