|
1 | 1 | //! Analog-digital conversion traits |
2 | 2 |
|
3 | | -/// A marker trait to identify MCU pins that can be used as inputs to an ADC channel. |
4 | | -/// |
5 | | -/// This marker trait denotes an object, i.e. a GPIO pin, that is ready for use as an input to the |
6 | | -/// ADC. As ADCs channels can be supplied by multiple pins, this trait defines the relationship |
7 | | -/// between the physical interface and the ADC sampling buffer. |
8 | | -/// |
9 | | -/// ``` |
10 | | -/// # use core::marker::PhantomData; |
11 | | -/// # use embedded_hal::adc::nb::Channel; |
12 | | -/// |
13 | | -/// struct Adc1; // Example ADC with single bank of 8 channels |
14 | | -/// struct Gpio1Pin1<MODE>(PhantomData<MODE>); |
15 | | -/// struct Analog(()); // marker type to denote a pin in "analog" mode |
16 | | -/// |
17 | | -/// // GPIO 1 pin 1 can supply an ADC channel when it is configured in Analog mode |
18 | | -/// impl Channel<Adc1> for Gpio1Pin1<Analog> { |
19 | | -/// type ID = u8; // ADC channels are identified numerically |
20 | | -/// |
21 | | -/// fn channel(&self) -> Self::ID { |
22 | | -/// 7_u8 // GPIO pin 1 is connected to ADC channel 7 |
23 | | -/// } |
24 | | -/// } |
25 | | -/// |
26 | | -/// struct Adc2; // ADC with two banks of 16 channels |
27 | | -/// struct Gpio2PinA<MODE>(PhantomData<MODE>); |
28 | | -/// struct AltFun(()); // marker type to denote some alternate function mode for the pin |
29 | | -/// |
30 | | -/// // GPIO 2 pin A can supply an ADC channel when it's configured in some alternate function mode |
31 | | -/// impl Channel<Adc2> for Gpio2PinA<AltFun> { |
32 | | -/// type ID = (u8, u8); // ADC channels are identified by bank number and channel number |
33 | | -/// |
34 | | -/// fn channel(&self) -> Self::ID { |
35 | | -/// (0, 3) // bank 0 channel 3 |
36 | | -/// } |
37 | | -/// } |
38 | | -/// ``` |
39 | | -pub trait Channel<ADC> { |
40 | | - /// Channel ID type |
41 | | - /// |
42 | | - /// A type used to identify this ADC channel. For example, if the ADC has eight channels, this |
43 | | - /// might be a `u8`. If the ADC has multiple banks of channels, it could be a tuple, like |
44 | | - /// `(u8: bank_id, u8: channel_id)`. |
45 | | - type ID: Copy; |
46 | | - |
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) -> Self::ID; |
50 | | -} |
| 3 | +pub use super::Channel; |
51 | 4 |
|
52 | 5 | /// ADCs that sample on single channels per request, and do so at the time of the request. |
53 | 6 | /// |
|
0 commit comments