@@ -25,7 +25,7 @@ fn main() -> Result<()> {
}
let mut lsettings = line::Settings::new()?;
- let lconfig = line::Config::new()?;
+ let mut lconfig = line::Config::new()?;
let mut offsets = Vec::<Offset>::new();
for arg in &args[2..] {
@@ -32,12 +32,12 @@ fn request_reconfigure_line(
rx: Receiver<()>,
) {
thread::spawn(move || {
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let lsettings = line::Settings::new().unwrap();
lconfig.add_line_settings(&[offset], lsettings).unwrap();
let rconfig = request::Config::new().unwrap();
- let request = chip
+ let mut request = chip
.lock()
.unwrap()
.request_lines(Some(&rconfig), &lconfig)
@@ -49,7 +49,7 @@ fn request_reconfigure_line(
// Wait for parent to signal
rx.recv().expect("Could not receive from channel");
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings.set_direction(Direction::Output).unwrap();
lconfig.add_line_settings(&[offset], lsettings).unwrap();
@@ -20,7 +20,7 @@ fn main() -> Result<()> {
}
let mut lsettings = line::Settings::new()?;
- let lconfig = line::Config::new()?;
+ let mut lconfig = line::Config::new()?;
let mut offsets = Vec::<Offset>::new();
for arg in &args[2..] {
@@ -34,7 +34,7 @@ fn main() -> Result<()> {
let path = format!("/dev/gpiochip{}", args[1]);
let chip = Chip::open(&path)?;
- let rconfig = request::Config::new()?;
+ let mut rconfig = request::Config::new()?;
rconfig.set_consumer(&args[0])?;
let request = chip.request_lines(Some(&rconfig), &lconfig)?;
@@ -24,7 +24,7 @@ fn main() -> Result<()> {
}
let mut lsettings = line::Settings::new()?;
- let lconfig = line::Config::new()?;
+ let mut lconfig = line::Config::new()?;
let mut offsets = Vec::<Offset>::new();
for arg in &args[2..] {
@@ -24,7 +24,7 @@ fn main() -> Result<()> {
return Err(Error::InvalidArguments);
}
- let lconfig = line::Config::new()?;
+ let mut lconfig = line::Config::new()?;
for arg in &args[2..] {
let pair: Vec<&str> = arg.split('=').collect();
@@ -51,7 +51,7 @@ fn main() -> Result<()> {
let path = format!("/dev/gpiochip{}", args[1]);
let chip = Chip::open(&path)?;
- let rconfig = request::Config::new()?;
+ let mut rconfig = request::Config::new()?;
rconfig.set_consumer(&args[0])?;
chip.request_lines(Some(&rconfig), &lconfig)?;
@@ -56,7 +56,7 @@ impl Config {
}
/// Add line settings for a set of offsets.
- pub fn add_line_settings(&self, offsets: &[Offset], settings: Settings) -> Result<()> {
+ pub fn add_line_settings(&mut self, offsets: &[Offset], settings: Settings) -> Result<&mut Self> {
// SAFETY: `gpiod_line_config` is guaranteed to be valid here.
let ret = unsafe {
gpiod::gpiod_line_config_add_line_settings(
@@ -73,7 +73,7 @@ impl Config {
errno::errno(),
))
} else {
- Ok(())
+ Ok(self)
}
}
@@ -95,7 +95,7 @@ impl Request {
}
/// Set the value of a single line associated with the request.
- pub fn set_value(&self, offset: Offset, value: Value) -> Result<()> {
+ pub fn set_value(&mut self, offset: Offset, value: Value) -> Result<&mut Self> {
// SAFETY: `gpiod_line_request` is guaranteed to be valid here.
let ret =
unsafe { gpiod::gpiod_line_request_set_value(self.request, offset, value.value()) };
@@ -106,12 +106,12 @@ impl Request {
errno::errno(),
))
} else {
- Ok(())
+ Ok(self)
}
}
/// Set values of a subset of lines associated with the request.
- pub fn set_values_subset(&self, map: ValueMap) -> Result<()> {
+ pub fn set_values_subset(&mut self, map: ValueMap) -> Result<&mut Self> {
let mut offsets = Vec::new();
let mut values = Vec::new();
@@ -136,12 +136,12 @@ impl Request {
errno::errno(),
))
} else {
- Ok(())
+ Ok(self)
}
}
/// Set values of all lines associated with the request.
- pub fn set_values(&self, values: &[Value]) -> Result<()> {
+ pub fn set_values(&mut self, values: &[Value]) -> Result<&mut Self> {
if values.len() != self.num_lines() as usize {
return Err(Error::InvalidArguments);
}
@@ -161,12 +161,12 @@ impl Request {
errno::errno(),
))
} else {
- Ok(())
+ Ok(self)
}
}
/// Update the configuration of lines associated with the line request.
- pub fn reconfigure_lines(&self, lconfig: &line::Config) -> Result<()> {
+ pub fn reconfigure_lines(&mut self, lconfig: &line::Config) -> Result<&mut Self> {
// SAFETY: `gpiod_line_request` is guaranteed to be valid here.
let ret =
unsafe { gpiod::gpiod_line_request_reconfigure_lines(self.request, lconfig.config) };
@@ -177,7 +177,7 @@ impl Request {
errno::errno(),
))
} else {
- Ok(())
+ Ok(self)
}
}
@@ -40,7 +40,7 @@ impl Config {
///
/// If the consumer string is too long, it will be truncated to the max
/// accepted length.
- pub fn set_consumer(&self, consumer: &str) -> Result<()> {
+ pub fn set_consumer(&mut self, consumer: &str) -> Result<&mut Self> {
let consumer = CString::new(consumer).map_err(|_| Error::InvalidString)?;
// SAFETY: `gpiod_request_config` is guaranteed to be valid here.
@@ -51,7 +51,7 @@ impl Config {
)
}
- Ok(())
+ Ok(self)
}
/// Get the consumer name configured in the request config.
@@ -73,9 +73,11 @@ impl Config {
}
/// Set the size of the kernel event buffer for the request.
- pub fn set_event_buffer_size(&self, size: usize) {
+ pub fn set_event_buffer_size(&mut self, size: usize) -> &mut Self {
// SAFETY: `gpiod_request_config` is guaranteed to be valid here.
unsafe { gpiod::gpiod_request_config_set_event_buffer_size(self.config, size as c_ulong) }
+
+ self
}
/// Get the edge event buffer size setting for the request config.
@@ -43,7 +43,7 @@ impl TestConfig {
}
}
- pub(crate) fn rconfig_set_consumer(&self, consumer: &str) {
+ pub(crate) fn rconfig_set_consumer(&mut self, consumer: &str) {
self.rconfig.set_consumer(consumer).unwrap();
}
@@ -100,7 +100,7 @@ impl TestConfig {
pub(crate) fn lconfig_add_settings(&mut self, offsets: &[Offset]) {
self.lconfig
.add_line_settings(offsets, self.lsettings.take().unwrap())
- .unwrap()
+ .unwrap();
}
pub(crate) fn request_lines(&mut self) -> Result<()> {
@@ -128,8 +128,8 @@ impl TestConfig {
self.lsettings.as_mut().unwrap()
}
- pub(crate) fn request(&self) -> &request::Request {
- self.request.as_ref().unwrap()
+ pub(crate) fn request(&mut self) -> &mut request::Request {
+ self.request.as_mut().unwrap()
}
}
@@ -24,12 +24,12 @@ mod info_event {
fn request_reconfigure_line(chip: Arc<Mutex<Chip>>, tx: Sender<()>, rx: Receiver<()>) {
thread::spawn(move || {
- let lconfig1 = line::Config::new().unwrap();
+ let mut lconfig1 = line::Config::new().unwrap();
let lsettings = line::Settings::new().unwrap();
lconfig1.add_line_settings(&[7], lsettings).unwrap();
let rconfig = request::Config::new().unwrap();
- let request = chip
+ let mut request = chip
.lock()
.unwrap()
.request_lines(Some(&rconfig), &lconfig1)
@@ -41,7 +41,7 @@ mod info_event {
// Wait for parent to signal
rx.recv().expect("Could not receive from channel");
- let lconfig2 = line::Config::new().unwrap();
+ let mut lconfig2 = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings.set_direction(Direction::Output).unwrap();
lconfig2.add_line_settings(&[7], lsettings).unwrap();
@@ -33,7 +33,7 @@ mod line_config {
.unwrap();
// Add settings for multiple lines
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
lconfig.add_line_settings(&[0, 1, 2], lsettings1).unwrap();
lconfig.add_line_settings(&[4, 5], lsettings2).unwrap();
@@ -123,7 +123,7 @@ mod line_request {
// Value read properly after reconfigure
let mut lsettings = line::Settings::new().unwrap();
lsettings.set_active_low(true);
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
lconfig.add_line_settings(&offsets, lsettings).unwrap();
request.reconfigure_lines(&lconfig).unwrap();
assert_eq!(request.value(7).unwrap(), Value::InActive);
@@ -153,22 +153,21 @@ mod line_request {
config.lconfig_val(Some(Direction::Output), Some(Value::InActive));
config.lconfig_add_settings(&offsets);
config.request_lines().unwrap();
- let request = config.request();
// Set single value
- request.set_value(1, Value::Active).unwrap();
+ config.request().set_value(1, Value::Active).unwrap();
assert_eq!(config.sim_val(0).unwrap(), SimValue::InActive);
assert_eq!(config.sim_val(1).unwrap(), SimValue::Active);
assert_eq!(config.sim_val(3).unwrap(), SimValue::InActive);
assert_eq!(config.sim_val(4).unwrap(), SimValue::InActive);
- request.set_value(1, Value::InActive).unwrap();
+ config.request().set_value(1, Value::InActive).unwrap();
assert_eq!(config.sim_val(1).unwrap(), SimValue::InActive);
// Set values of subset
let mut map = ValueMap::new();
map.insert(4, Value::Active);
map.insert(3, Value::Active);
- request.set_values_subset(map).unwrap();
+ config.request().set_values_subset(map).unwrap();
assert_eq!(config.sim_val(0).unwrap(), SimValue::InActive);
assert_eq!(config.sim_val(1).unwrap(), SimValue::InActive);
assert_eq!(config.sim_val(3).unwrap(), SimValue::Active);
@@ -177,12 +176,12 @@ mod line_request {
let mut map = ValueMap::new();
map.insert(4, Value::InActive);
map.insert(3, Value::InActive);
- request.set_values_subset(map).unwrap();
+ config.request().set_values_subset(map).unwrap();
assert_eq!(config.sim_val(3).unwrap(), SimValue::InActive);
assert_eq!(config.sim_val(4).unwrap(), SimValue::InActive);
// Set all values
- request
+ config.request()
.set_values(&[
Value::Active,
Value::InActive,
@@ -194,7 +193,7 @@ mod line_request {
assert_eq!(config.sim_val(1).unwrap(), SimValue::InActive);
assert_eq!(config.sim_val(3).unwrap(), SimValue::Active);
assert_eq!(config.sim_val(4).unwrap(), SimValue::InActive);
- request
+ config.request()
.set_values(&[
Value::InActive,
Value::InActive,
@@ -251,7 +250,7 @@ mod line_request {
// Reconfigure
let mut lsettings = line::Settings::new().unwrap();
lsettings.set_direction(Direction::Input).unwrap();
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
// The uAPI config has only 10 attribute slots, this should pass.
for offset in offsets {
@@ -285,10 +284,8 @@ mod line_request {
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.bias().unwrap(), None);
- let request = config.request();
-
// Reconfigure
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -297,11 +294,11 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.bias().unwrap(), Some(Bias::PullUp));
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -310,11 +307,11 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.bias().unwrap(), Some(Bias::PullDown));
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -323,7 +320,7 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.bias().unwrap(), Some(Bias::Disabled));
}
@@ -336,10 +333,8 @@ mod line_request {
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.drive().unwrap(), Drive::PushPull);
- let request = config.request();
-
// Reconfigure
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -348,11 +343,11 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.drive().unwrap(), Drive::PushPull);
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -361,11 +356,11 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.drive().unwrap(), Drive::OpenDrain);
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -374,7 +369,7 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.drive().unwrap(), Drive::OpenSource);
}
@@ -387,10 +382,8 @@ mod line_request {
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.edge_detection().unwrap(), None);
- let request = config.request();
-
// Reconfigure
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -399,11 +392,11 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.edge_detection().unwrap(), Some(Edge::Both));
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -412,11 +405,11 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.edge_detection().unwrap(), Some(Edge::Rising));
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -425,7 +418,7 @@ mod line_request {
])
.unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.edge_detection().unwrap(), Some(Edge::Falling));
}
@@ -438,22 +431,20 @@ mod line_request {
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.event_clock().unwrap(), EventClock::Monotonic);
- let request = config.request();
-
// Reconfigure
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings.set_event_clock(EventClock::Monotonic).unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.event_clock().unwrap(), EventClock::Monotonic);
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings.set_event_clock(EventClock::Realtime).unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
- request.reconfigure_lines(&lconfig).unwrap();
+ config.request().reconfigure_lines(&lconfig).unwrap();
let info = config.chip().line_info(0).unwrap();
assert_eq!(info.event_clock().unwrap(), EventClock::Realtime);
}
@@ -470,7 +461,7 @@ mod line_request {
let request = config.request();
// Reconfigure
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings.set_event_clock(EventClock::HTE).unwrap();
lconfig.add_line_settings(&[0], lsettings).unwrap();
@@ -491,7 +482,7 @@ mod line_request {
let request = config.request();
// Reconfigure
- let lconfig = line::Config::new().unwrap();
+ let mut lconfig = line::Config::new().unwrap();
let mut lsettings = line::Settings::new().unwrap();
lsettings
.set_prop(&[
@@ -27,7 +27,7 @@ mod request_config {
#[test]
fn initialized() {
const CONSUMER: &str = "foobar";
- let rconfig = request::Config::new().unwrap();
+ let mut rconfig = request::Config::new().unwrap();
rconfig.set_consumer(CONSUMER).unwrap();
rconfig.set_event_buffer_size(64);