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 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)
.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
sourceimpl Config
impl Config
sourcepub fn on_chip<P: Into<PathBuf>>(&mut self, path: P) -> &mut Self
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.
sourcepub fn as_input(&mut self) -> &mut Self
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.
sourcepub fn as_output(&mut self, value: Value) -> &mut Self
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.
sourcepub fn as_active_low(&mut self) -> &mut Self
pub fn as_active_low(&mut self) -> &mut Self
Set the selected lines to active low.
sourcepub fn as_active_high(&mut self) -> &mut Self
pub fn as_active_high(&mut self) -> &mut Self
Set the selected lines to active high.
This is the default active level setting.
sourcepub fn with_bias<B: Into<Option<Bias>>>(&mut self, bias: B) -> &mut Self
pub fn with_bias<B: Into<Option<Bias>>>(&mut self, bias: B) -> &mut Self
Set the bias setting for the selected lines.
sourcepub fn with_debounce_period(&mut self, period: Duration) -> &mut Self
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.
sourcepub fn with_direction(&mut self, direction: Direction) -> &mut Self
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 en existing output line, first request it as_is
,
then reconfigure it as an output with an appropriate value.
sourcepub fn with_drive(&mut self, drive: Drive) -> &mut Self
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.
sourcepub fn with_edge_detection<E: Into<Option<EdgeDetection>>>(
&mut self,
edge: E
) -> &mut Self
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.
sourcepub fn with_event_clock(&mut self, event_clock: EventClock) -> &mut Self
pub fn with_event_clock(&mut self, event_clock: EventClock) -> &mut Self
Set the clock source for edge events on the selected lines.
sourcepub fn with_found_line(&mut self, line: &FoundLine) -> Result<&mut Self>
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);
sourcepub fn with_found_lines<'a>(
&mut self,
lines: &HashMap<&'a str, FoundLine>
) -> Result<&mut Self>
pub fn with_found_lines<'a>(
&mut self,
lines: &HashMap<&'a 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);
sourcepub fn with_line(&mut self, offset: Offset) -> &mut Self
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.
sourcepub fn without_line(&mut self, offset: Offset) -> &mut Self
pub fn without_line(&mut self, offset: Offset) -> &mut Self
Remove a lines from the config.
sourcepub fn with_lines(&mut self, offsets: &[Offset]) -> &mut Self
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.
sourcepub fn without_lines(&mut self, offsets: &[Offset]) -> &mut Self
pub fn without_lines(&mut self, offsets: &[Offset]) -> &mut Self
Remove a set of lines from the config.
sourcepub fn with_value(&mut self, value: Value) -> &mut Self
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.
sourcepub fn from_line_config(&mut self, lc: &Config) -> &mut Self
pub fn from_line_config(&mut self, lc: &Config) -> &mut Self
Apply the configuration based on the snapshot from a single line.
sourcepub fn line_config(&self, offset: Offset) -> Option<&Config>
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.
sourcepub fn lines(&self) -> &Offsets
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
.