Trait Pin

Source
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§

Source

fn number(&self) -> u8

GPIO number

Provided Methods§

Source

fn degrade(self) -> AnyPin
where 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);

Implementors§

Source§

impl Pin for AnyPin

Source§

impl Pin for GpioPin<0>

Source§

impl Pin for GpioPin<1>

Source§

impl Pin for GpioPin<2>

Source§

impl Pin for GpioPin<3>

Source§

impl Pin for GpioPin<4>

Source§

impl Pin for GpioPin<5>

Source§

impl Pin for GpioPin<6>

Source§

impl Pin for GpioPin<7>

Source§

impl Pin for GpioPin<8>

Source§

impl Pin for GpioPin<9>

Source§

impl Pin for GpioPin<10>

Source§

impl Pin for GpioPin<11>

Source§

impl Pin for GpioPin<12>

Source§

impl Pin for GpioPin<13>

Source§

impl Pin for GpioPin<14>

Source§

impl Pin for GpioPin<15>

Source§

impl Pin for GpioPin<16>

Source§

impl Pin for GpioPin<17>

Source§

impl Pin for GpioPin<18>

Source§

impl Pin for GpioPin<19>

Source§

impl Pin for GpioPin<20>

Source§

impl Pin for GpioPin<21>

Source§

impl Pin for GpioPin<22>

Source§

impl Pin for GpioPin<23>

Source§

impl Pin for GpioPin<24>

Source§

impl Pin for GpioPin<25>

Source§

impl Pin for GpioPin<26>

Source§

impl Pin for GpioPin<27>

Source§

impl Pin for GpioPin<28>

Source§

impl Pin for GpioPin<29>

Source§

impl Pin for GpioPin<30>