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

A builder of line requests.

Apply mutators to specify the request configuration, then use request to request the lines from the kernel.

Most mutators operate on the request configuration as per the Config.

Examples

Request and read a basic input line:

let l3 = Request::builder()
    .on_chip("/dev/gpiochip0")
    .with_line(3)
    .request()?;
let value = l3.value(3)?;

Several lines in one request:

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

More complex configurations can be built separately and provided to the Builder:

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)?;

Implementations

Perform the request.

Sends the request to the kernel using the appropriate uAPI call.

On success returns the Request that provides access to the requested lines.

This is the terminal operation for the Builder.

Replace the request configuration with the new one provided.

Get a snapshot of the current request configuration.

Can be applied to other requests with with_config or Request::from_config.

Specify the consumer label to be applied to the request, and so to all lines in the request.

If not specified, a label “gpiocdev-pPID is applied by request, where PID is the process id of the application.

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

Set the event buffer size for edge events buffered in the kernel.

This method is only required in unusual circumstances.

The size provides a hint to the kernel as to the size of the buffer to store edge events until they are read from the Request. The default size is 16 times the number of lines in the request. The default size is typically sufficient unless the hardware may generate bursts of events faster than the application can service them.

Altering the buffer size does NOT affect latency. Buffering is provided in the kernel to reduce the likelihood of event loss when user space is slow servicing events. In all cases the events are provided to user space as quickly as user space allows.

Set the event buffer size for edge events buffered in user space.

This method is only required in unusual circumstances.

The size defines the number of events that may be buffered in user space by the Request.edge_events iterator. The user space buffer is a performance optimisation to reduce the number of system calls required to read events.

Altering the buffer size does NOT affect latency. In all cases the events are provided to user space as quickly as user space allows.

Set the chip from which to request lines.

This applies to all lines in the request. It is not possible to request lines from different chips in the same request.

The Builder locks to the first chip provided to it, for example by on_chip or with_found_line. Any subsequent attempts to change the chip will result in an error when request is called.

The chip is identified by a path which must resolve to a GPIO character device.

Set the selected lines to input.

This is a short form of with_direction(Input).

This is the default direction setting.

Set the selected lines to output with the given value.

This is a short form of with_direction(Output) and with_value(value) that allows the direction and value to be set in the one call.

Set the selected lines to active low.

Set the selected lines to active high.

This is the default active level setting.

Set the bias setting for the selected lines.

Set the debounce period for the selected lines.

A value of zero means no debounce.

Implicitly sets the selected lines as inputs, if they weren’t already, and removes any output specific settings.

Set the direction of the selected lines.

Setting to input removes any output specific settings.

Setting to output removes any input specific settings.

Set the drive setting for the selected lines.

Implicitly sets the selected lines as outputs, if they weren’t already, and removes any input specific settings.

Set the edge detection for the selected lines.

Implicitly sets the lines as inputs and removes any output specific settings.

Set the clock source for edge events on the selected lines.

Add a found line to the request.

The line must be on the same chip as any existing lines in the request, else the line is ignored and an error returned when request is called.

Note that all configuration mutators applied subsequently only apply to this line.

Examples
let led0 = gpiocdev::find_named_line("LED0").unwrap();
let req = Request::builder()
    .with_found_line(&led0)
    .as_output(Value::Active)
    .request()?;

Add a set of found lines to the request.

The lines must be on the same chip as any existing lines in the request, else the line is ignored and an error returned when request is called.

Note that all configuration mutators applied subsequently only apply to these lines.

Examples
let buttons = gpiocdev::find_named_lines(&["BUTTON0","BUTTON1"], true)?;
let req = Request::builder()
    .with_found_lines(&buttons)
    .with_edge_detection(EdgeDetection::BothEdges)
    .request()?;

Add a line to the request.

Note that all configuration mutators applied subsequently only apply to this line.

Remove a lines from the request.

Add a set of lines to the request.

Note that all configuration mutators applied subsequently only apply to this subset of lines.

Remove a set of lines from the request.

Set the value of the selected lines.

Apply the configuration based on a snapshot from a single line.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. 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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.