Trait embedded_hal::adc::Channel
source · pub trait Channel<ADC> {
type ID;
// Required method
fn channel() -> Self::ID;
}
Expand description
A marker trait to identify MCU pins that can be used as inputs to an ADC channel.
This marker trait denotes an object, i.e. a GPIO pin, that is ready for use as an input to the ADC. As ADCs channels can be supplied by multiple pins, this trait defines the relationship between the physical interface and the ADC sampling buffer.
struct Adc1; // Example ADC with single bank of 8 channels
struct Gpio1Pin1<MODE>(PhantomData<MODE>);
struct Analog(()); // marker type to denote a pin in "analog" mode
// GPIO 1 pin 1 can supply an ADC channel when it is configured in Analog mode
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
}
struct Adc2; // ADC with two banks of 16 channels
struct Gpio2PinA<MODE>(PhantomData<MODE>);
struct AltFun(()); // marker type to denote some alternate function mode for the pin
// GPIO 2 pin A can supply an ADC channel when it's configured in some alternate function mode
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
}