[][src]Trait embedded_hal::adc::Channel

pub trait Channel<ADC> {
    type ID;
    fn channel() -> Self::ID;
}

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
}

Associated Types

type ID

Channel ID type

A type used to identify this ADC channel. For example, if the ADC has eight channels, this might be a u8. If the ADC has multiple banks of channels, it could be a tuple, like (u8: bank_id, u8: channel_id).

Loading content...

Required methods

fn channel() -> Self::ID

Get the specific ID that identifies this channel, for example 0_u8 for the first ADC channel, if Self::ID is u8.

Loading content...

Implementors

Loading content...