Struct gpio_cdev::Line

source ·
pub struct Line { /* private fields */ }
Expand description

Access to a specific GPIO Line

GPIO Lines must be obtained through a parent Chip and represent an actual GPIO pin/line accessible via that chip. Not all accessible lines for a given chip may actually map to hardware depending on how the board is setup in the kernel.

Implementations§

source§

impl Line

source

pub fn info(&self) -> Result<LineInfo, Error>

Get info about the line from the kernel.

source

pub fn offset(&self) -> u32

Offset of this line within its parent chip

source

pub fn chip(&self) -> Chip

Get a handle to this chip’s parent

source

pub fn request( &self, flags: LineRequestFlags, default: u8, consumer: &str ) -> Result<LineHandle, Error>

Request access to interact with this line from the kernel

This is similar to the “export” operation present in the sysfs API with the key difference that we are also able to configure the GPIO with flags to specify how the line will be used at the time of request.

For an output, the default parameter specifies the value the line should have when it is configured as an output. The consumer string should describe the process consuming the line (this will be truncated to 31 characters if too long).

Errors

The main source of errors here is if the kernel returns an error to the ioctl performing the request here. This will result in an Error being returned with ErrorKind::Ioctl.

One possible cause for an error here would be if the line is already in use. One can check for this prior to making the request using is_kernel.

source

pub fn events( &self, handle_flags: LineRequestFlags, event_flags: EventRequestFlags, consumer: &str ) -> Result<LineEventHandle, Error>

Get an event handle that can be used as a blocking iterator over the events (state changes) for this Line

When used as an iterator, it blocks while there is not another event available from the kernel for this line matching the subscription criteria specified in the event_flags. The line will be configured with the specified handle_flags and consumer label.

Note that as compared with the sysfs interface, the character device interface maintains a queue of events in the kernel so events may happen (e.g. a line changing state faster than can be picked up in userspace in real-time). These events will be returned on the iterator in order with the event containing the associated timestamp attached with high precision within the kernel (from an ISR for most drivers).

Example
use gpio_cdev::{Chip, LineRequestFlags, EventRequestFlags};
use std::io;

let mut chip = Chip::new("/dev/gpiochip0")?;
let input = chip.get_line(0)?;

// Show all state changes for this line forever
for event in input.events(
    LineRequestFlags::INPUT,
    EventRequestFlags::BOTH_EDGES,
    "rust-gpio"
)? {
    println!("{:?}", event?);
}
source

pub fn async_events( &self, handle_flags: LineRequestFlags, event_flags: EventRequestFlags, consumer: &str ) -> Result<AsyncLineEventHandle, Error>

Available on crate feature async-tokio only.

Trait Implementations§

source§

impl Clone for Line

source§

fn clone(&self) -> Line

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Line

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Line

§

impl Send for Line

§

impl Sync for Line

§

impl Unpin for Line

§

impl UnwindSafe for Line

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.