gpiocdev-embedded-hal

Crates.iogpiocdev-embedded-hal
lib.rsgpiocdev-embedded-hal
version0.1.1
sourcesrc
created_at2024-02-20 03:20:25.211369
updated_at2024-05-23 00:04:26.869683
descriptionA library providing embedded-hal wrappers around gpiocdev Requests
homepage
repositoryhttps://github.com/warthog618/gpiocdev-rs
max_upload_size
id1145938
size98,087
Kent Gibson (warthog618)

documentation

README

gpiocdev-embedded-hal

Build Status github crate LICENSE

A Rust library implementing embedded-hal traits for GPIO lines on Linux platforms using the GPIO character device using gpiocdev.

Example Usage

Reading line value:

    use embedded_hal::digital::InputPin;

    // request the line
    let mut pin = gpiocdev_embedded_hal::Input::new("/dev/gpiochip0", 23)?;
    // get the value
    if pin.is_high()? {
         println!("Input is high.");
    }

Setting a line:

    use embedded_hal::digital::OutputPin;
    use embedded_hal::digital::PinState;

    // request the line
    let mut pin = gpiocdev_embedded_hal::Output::new("/dev/gpiochip0", 23, PinState::High)?;

    // do something...

    // change value later
    pin.set_low()?;

Requesting a line by name:

    use embedded_hal::digital::InputPin;

    let mut pin = gpiocdev_embedded_hal::InputPin::from_name("GPIO23")?;

Waiting for events on a line:

    use embedded_hal::digital::InputPin;
    use embedded_hal_async::digital::Wait;

    // request the line
    let mut pin = gpiocdev_embedded_hal::tokio::Input::new("/dev/gpiochip0", 23)?;

    // wait for line edge events
    pin.wait_for_any_edge().await?;

Working examples can be found in the examples directory.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 387

cargo fmt