Trait Pin

Source
pub trait Pin: Sealed {
    // Required method
    fn number(&self) -> u8;

    // Provided method
    fn degrade<'d>(self) -> AnyPin<'d>
       where Self: Sized + 'd { ... }
}
Expand description

Common trait implemented by pins

Required Methods§

Source

fn number(&self) -> u8

GPIO number

Provided Methods§

Source

fn degrade<'d>(self) -> AnyPin<'d>
where Self: Sized + 'd,

Type-erase this pin into an AnyPin.

This function converts pin singletons (GPIO0<'_>, …), which are all different types, into the same type. It is useful for creating arrays of pins, or avoiding generics.

§Example
use esp_hal::gpio::{AnyPin, Pin, Output, OutputConfig, Level};
use esp_hal::delay::Delay;

fn toggle_pins(pins: [AnyPin; 2], delay: &mut Delay) {
    let [red, blue] = pins;
    let mut red = Output::new(
        red,
        Level::High,
        OutputConfig::default(),
    );
    let mut blue = Output::new(
        blue,
        Level::Low,
        OutputConfig::default(),
    );

    loop {
        red.toggle();
        blue.toggle();
        delay.delay_millis(500);
    }
}

let pins: [AnyPin; 2] = [
   peripherals.GPIO5.degrade(),
   peripherals.GPIO6.degrade(),
];

let mut delay = Delay::new();
toggle_pins(pins, &mut delay);

Implementors§

Source§

impl Pin for GPIO0<'_>

Source§

impl Pin for GPIO1<'_>

Source§

impl Pin for GPIO2<'_>

Source§

impl Pin for GPIO3<'_>

Source§

impl Pin for GPIO4<'_>

Source§

impl Pin for GPIO5<'_>

Source§

impl Pin for GPIO6<'_>

Source§

impl Pin for GPIO7<'_>

Source§

impl Pin for GPIO8<'_>

Source§

impl Pin for GPIO9<'_>

Source§

impl Pin for GPIO10<'_>

Source§

impl Pin for GPIO11<'_>

Source§

impl Pin for GPIO12<'_>

Source§

impl Pin for GPIO13<'_>

Source§

impl Pin for GPIO14<'_>

Source§

impl Pin for GPIO15<'_>

Source§

impl Pin for GPIO16<'_>

Source§

impl Pin for GPIO17<'_>

Source§

impl Pin for GPIO18<'_>

Source§

impl Pin for GPIO19<'_>

Source§

impl Pin for GPIO20<'_>

Source§

impl Pin for GPIO21<'_>

Source§

impl Pin for GPIO22<'_>

Source§

impl Pin for GPIO23<'_>

Source§

impl Pin for GPIO24<'_>

Source§

impl Pin for GPIO25<'_>

Source§

impl Pin for GPIO26<'_>

Source§

impl Pin for GPIO27<'_>

Source§

impl Pin for GPIO28<'_>

Source§

impl Pin for GPIO29<'_>

Source§

impl Pin for GPIO30<'_>

Source§

impl Pin for AnyPin<'_>