Struct Config

Source
pub struct Config { /* private fields */ }
Expand description

The configuration for a request for one or more lines.

The configuration for a subset of lines is updated by selecting the lines and then calling the appropriate mutators. If no lines are selected then the mutators modify the base configuration that lines inherit when they are first added.

§Examples

use gpiocdev::line::{Bias::*, Value::*};
use gpiocdev::request::Config;

let cfg = Config::default()
    .as_input()
    .with_bias(PullUp)
    // -- base config ends here - just before lines are first added.
    .with_lines(&[3, 5, 8]) // lines 3,5,8 will be input with pull-up bias...
    // -- config added here would apply to lines 3,5 and 8
    .with_line(3) // make line 3 pull-down instead...
    .with_bias(PullDown)
    .with_line(4) // and line 4 an output set inactive (and pull-up from the base config)
    .as_output(Inactive);

Note that the configuration is applied to hardware via a call to Builder.request or Request.reconfigure. Changes to the Config object, either before or after that only update the configuration in memory in preparation for the next application.

Implementations§

Source§

impl Config

Source

pub fn on_chip<P: Into<PathBuf>>(&mut self, path: P) -> &mut Self

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 chip is identified by a path which must resolve to a GPIO character device.

Source

pub fn chip(&self) -> &Path

Return the path of the chip for this configuration.

Source

pub fn as_input(&mut self) -> &mut Self

Set the selected lines to input.

This is a short form of with_direction(Input).

This is the default direction setting.

Source

pub fn as_is(&mut self) -> &mut Self

Do not set the direction of the selected lines.

Source

pub fn as_output(&mut self, value: Value) -> &mut Self

Set the selected lines to output with the given value.

This is a long form of with_direction(Output) that allows the value to be set in the same call.

Source

pub fn as_active_low(&mut self) -> &mut Self

Set the selected lines to active low.

Source

pub fn as_active_high(&mut self) -> &mut Self

Set the selected lines to active high.

This is the default active level setting.

Source

pub fn with_bias<B: Into<Option<Bias>>>(&mut self, bias: B) -> &mut Self

Set the bias setting for the selected lines.

Source

pub fn with_debounce_period(&mut self, period: Duration) -> &mut Self

Set the debounce period for the selected lines.

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

Source

pub fn with_direction(&mut self, direction: Direction) -> &mut Self

Set the direction of the selected lines.

Setting to input removes any output specific settings.

Setting to output removes any input specific settings.

Note that selecting a line as output will default its value to inactive. To provide a value use with_value, or use as_output(value) instead.

To determine the state of an existing output line, first request it as_is, then reconfigure it as an output with an appropriate value.

Source

pub fn with_drive(&mut self, drive: Drive) -> &mut Self

Set the drive setting for the selected lines.

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

Source

pub fn with_edge_detection<E: Into<Option<EdgeDetection>>>( &mut self, edge: E, ) -> &mut Self

Set the edge detection for the selected lines.

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

Source

pub fn with_event_clock<E: Into<Option<EventClock>>>( &mut self, event_clock: E, ) -> &mut Self

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

Source

pub fn with_found_line(&mut self, line: &FoundLine) -> Result<&mut Self>

Add a found line to the config.

The line must be on the same chip as any existing lines in the request.

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

§Examples
let led0 = gpiocdev::find_named_line("LED0").unwrap();
let mut cfg = Config::default();
cfg.with_found_line(&led0)?
   .as_output(Value::Active);
Source

pub fn with_found_lines( &mut self, lines: &HashMap<&str, FoundLine>, ) -> Result<&mut Self>

Add a set of found lines to the config.

The lines must be on the same chip as any existing lines in the request.

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

§Examples
let buttons = gpiocdev::find_named_lines(&["BUTTON0","BUTTON1"], true)?;
let mut cfg = Config::default();
cfg.with_found_lines(&buttons)?
   .with_edge_detection(EdgeDetection::BothEdges);
Source

pub fn with_line(&mut self, offset: Offset) -> &mut Self

Add a line to the config.

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

Source

pub fn without_line(&mut self, offset: Offset) -> &mut Self

Remove a line from the config.

Source

pub fn with_lines(&mut self, offsets: &[Offset]) -> &mut Self

Add a set of lines to the config.

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

Passing empty offsets re-selects the base config for subsequent mutations.

Source

pub fn without_lines(&mut self, offsets: &[Offset]) -> &mut Self

Remove a set of lines from the config.

Source

pub fn with_output_lines(&mut self, values: &Values) -> &mut Self

Add a set of output lines, with values, to the config.

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

Passing empty values re-selects the base config for subsequent mutations.

Source

pub fn with_value(&mut self, value: Value) -> &mut Self

Set the value of the selected lines.

This is only relevant for output lines and is ignored for input lines.

Source

pub fn from_line_config(&mut self, lc: &Config) -> &mut Self

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

Source

pub fn line_config(&self, offset: Offset) -> Option<&Config>

Get the requested configuration for a particular line.

This is the configuration that would be applied to the line if request were to be called.

Source

pub fn lines(&self) -> &Offsets

Returns the set of lines described by the Config.

Lines are in the order first added by calls to with_line or with_lines.

Source

pub fn num_lines(&self) -> usize

Returns the number of lines currently described by the Config.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Config

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Config

Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more