pub struct Request { /* private fields */ }
Expand description

An active request of a set of lines.

Requests are built by the Builder, which itself can be constructed by builder.

Output Lifetime

The value of an output line is only guaranteed for the lifetime of the request. If the request is dropped then the output value becomes indeterminate - it may remain unchanged or it may reset to the default value (depending on a number of factors including the kernel driver for your hardware and whether other lines on the chip are still requested).

So keep the request alive to be sure of the output value.

Event Buffering

Events are buffered both in the kernel and in user space. The purpose of the kernel event buffer is to store events that may occur in a burst at a faster rate than they can be handled by the user space process. The kernel event buffer can be customised to some extent by the with_kernel_event_buffer_size option.

A number of options are available for user space buffering, i.e. where the events are to be written when they are read from the kernel.

The read_edge_event reads a single event onto the stack.

The EdgeEventBuffer provides buffering on the heap, and can reduce reading overheads by reading multiple events from the kernel at once. The edge_events iterator uses an EdgeEventBuffer, the size of which is controlled by with_user_event_buffer_size

It is also possible to read multiple events into a user specified location using read_edge_events_into_slice. As with EdgeEventBuffer this may reduce read overheads when reading a burst of events from the kernel. The edge_event_size method provides the size required to store a single event to allow sizing of custom slices.

Reading Output Values

Note that reading back output values using value or values is dependent on driver and hardware support and so cannot be guaranteed to work, though frequently it does. Test with your particular hardware to be sure.

Implementations

Start building a new request.

Examples
let req = Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_lines(&[3,5])
    .request()?;
let mut values = Values::default();
req.values(&mut values)?;

Start building a new request using the provided config.

Examples
let mut cfg = Config::default();
cfg.with_line(5).as_output(Value::Active);
let req = Request::from_config(cfg)
    .on_chip("/dev/gpiochip0")
    .request()?;

Get the values for a subset of the requested lines.

The keys indicate the lines to get. Keys that are not requested offsets are ignored. If no keys are set then all requested lines are returned.

Examples
let req = Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_lines(&[3,5,6,8])
    .request()?;
// subset of lines
let mut values = Values::from_offsets(&[3,8]);
req.values(&mut values)?;
// all requested lines
let mut values = Values::default();
req.values(&mut values)?;

Get the value for one line in the request.

Examples
let req = Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_lines(&[3,5])
    .request()?;
let v5 = req.value(5)?;

Set the values for a subset of the requested lines.

Examples
let req = Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_lines(&[3,5,6,8])
    .as_output(Active)
    .request()?;
let mut values = Values::default();
values.set(5, Inactive).set(6, Inactive);
req.set_values(&values)?;

Set the value for one line in the request.

Examples
let mut cfg = Config::default();
cfg.with_line(5).as_output(Value::Active);
let req = Request::from_config(cfg)
    .on_chip("/dev/gpiochip0")
    .request()?;
req.set_value(5,Value::Inactive)?;

Get a snapshot of the requested configuration.

This is the configuration currently applied to the hardware.

Get a snapshot of the requested configuration for a particular line.

This is the configuration currently applied to the line.

Reconfigure the request with the an updated configuration.

Note that lines cannot be added or removed from the request. Any additional lines in new_cfg will be ignored, and any missing lines will retain their existing configuration.

An iterator for events from the request.

By default the events are read from the kernel individually.

The iterator can be backed by a user space buffer using the Builder.with_user_event_buffer_size option in the builder.

Examples
let req = Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_consumer("watcher")
    .with_line(23)
    .with_edge_detection(EdgeDetection::BothEdges)
    .request()?;

for event in req.edge_events() {
    println!("{:?}", event?);
}

Returns true when the request has edge events available to read using read_edge_event.

Wait for an edge event to be available.

Returns true if read_edge_event will return an event without blocking.

Read a single edge event from the request.

Will block until an edge event is available.

This is a convenience function. Reading events using edge_events or a buffer created using new_edge_event_buffer may be more performant.

Create an edge event buffer.

  • capacity - The number of events that can be buffered.

Read edge events from the kernel into a user space [u8] slice.

This is a helper function for the special case where the user prefers to manage the buffer containing raw events, e.g. to place it in a specific location in memory.

This will read in edge_event_size sized chunks so buf must be at least as large as one event.

This function will block if no events are available to read.

  • buf - The slice to contain the raw events.

Read an edge event from a [u8] slice.

This is a helper function for the special case where the user prefers to manage the buffer containing raw events, e.g. to place it in a specific location in memory.

Assumes the buffer has been previously populated by a call to read_edge_events_into_slice.

  • buf - The slice containing the raw event.

The number of bytes required to buffer a single event read from the request.

This can be used to size an external [u8] slice to read events into. The slice size should be a multiple of this size.

Trait Implementations

Extracts the raw file descriptor. Read more
Converts this type into a shared reference of the (usually inferred) input type.
Formats the value using the given formatter. Read more

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

Returns the argument unchanged.

Calls U::from(self).

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

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.