pub trait Pin: Sealed {
// Required method
fn number(&self) -> u8;
// Provided method
fn degrade(self) -> AnyPin
where Self: Sized { ... }
}
Expand description
Common trait implemented by pins
Required Methods§
Provided Methods§
Sourcefn degrade(self) -> AnyPinwhere
Self: Sized,
fn degrade(self) -> AnyPinwhere
Self: Sized,
Type-erase (degrade) this pin into an AnyPin
.
This converts pin singletons (GpioPin<0>
, …), 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);