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§
Provided Methods§
Sourcefn degrade<'d>(self) -> AnyPin<'d>where
    Self: Sized + 'd,
 
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::{
    delay::Delay,
    gpio::{AnyPin, Level, Output, OutputConfig, Pin},
};
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.GPIO4.degrade()];
let mut delay = Delay::new();
toggle_pins(pins, &mut delay);