Struct ruspiro_gpio::Gpio[][src]

pub struct Gpio { /* fields omitted */ }
Expand description

GPIO peripheral representation

Implementations

Get a new intance of the GPIO peripheral and do some initialization to ensure a valid state of all pins uppon initialization

Get a new pin for further usage, the function of the pin is initially undefined/unknown Returns an Err(str) if the pin is already in use, otherwise an Ok(Pin)

Example

if let Ok(pin) = GPIO.with_mut(|gpio| gpio.get_pin(17) ) {
  // do something with the pin
}

Release an used pin to allow re-usage for example with different configuration The pin’s state after release is considered unknown

Example

GPIO.with_mut(|gpio| gpio.free_pin(17) );

Register an event handler to be executed whenever the event occurs on the GPIO Pin specified. Event handler can only be registered for a Pin<Input,_>. The function/closure provided might be called several times. It’s allowed to move mutable context into the closure used. *HINT: Interrupts need to be globaly enabled.

Example

GPIO.with_mut(|gpio| {
    let pin = gpio.get_pin(12).unwrap().into_input();
    let mut counter: u32 = 0;
    gpio.register_recurring_event_handler(
        &pin,
        GpioEvent::RisingEdge,
        move || {
            counter += 1;
            println!("GPIO Event raised {} time(s)", counter);
        }
    );
});

Register an event handler to be executed at the first occurence of the specified event on the given GPIO Pin. The event handler can only be registered for a Pin<Input,_>. The function/closure provided will be called only once. *HINT: Interrupts need to be globaly enabled.

Example

GPIO.with_mut(|gpio| {
    let pin = gpio.get_pin(12).unwrap().into_input();
    gpio.register_oneshot_event_handler(
        &pin,
        GpioEvent::RisingEdge,
        move || {
            println!("GPIO Event raised");
        }
    );
});

Remove the event handler and deactivate any event detection for the GPIO Pin specified. Removing event handler is only available on a Pin<Input,_>.

Example

GPIO.with_mut(|gpio| {
    let pin = gpio.get_pin(12).unwrap().into_input();
    gpio.remove_event_handler(&pin);
});

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.