Skip to content

Commit e2c7ef4

Browse files
committed
Replace gpio_cdev with gpiocdev.
1 parent 6203207 commit e2c7ef4

File tree

4 files changed

+126
-162
lines changed

4 files changed

+126
-162
lines changed

Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ edition = "2018"
1414

1515
[features]
1616
gpio_sysfs = ["sysfs_gpio"]
17-
gpio_cdev = ["gpio-cdev"]
18-
async-tokio = ["gpio-cdev/async-tokio", "dep:embedded-hal-async", "tokio/time", "tokio/rt", "gpiocdev/async_tokio"]
17+
gpio_cdev = ["dep:gpiocdev"]
18+
async-tokio = ["dep:embedded-hal-async", "tokio/time", "tokio/rt", "gpiocdev?/async_tokio"]
1919
i2c = ["i2cdev"]
2020
spi = ["spidev"]
2121

@@ -25,8 +25,7 @@ default = [ "gpio_cdev", "gpio_sysfs", "i2c", "spi" ]
2525
embedded-hal = "1"
2626
embedded-hal-nb = "1"
2727
embedded-hal-async = { version = "1", optional = true }
28-
gpio-cdev = { version = "0.6.0", optional = true }
29-
gpiocdev = { version = "0.6.0" }
28+
gpiocdev = { version = "0.6.1", optional = true }
3029
sysfs_gpio = { version = "0.6.1", optional = true }
3130
i2cdev = { version = "0.6.0", optional = true }
3231
nb = "1"

examples/gpio-wait.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,28 @@ use std::time::Duration;
33

44
use embedded_hal::digital::{InputPin, OutputPin, PinState};
55
use embedded_hal_async::digital::Wait;
6-
use gpio_cdev::{Chip, LineRequestFlags};
6+
use gpiocdev::Request;
77
use linux_embedded_hal::CdevPin;
88
use tokio::time::{sleep, timeout};
99

1010
// This example assumes that input/output pins are shorted.
11+
const CHIP: &str = "/dev/gpiochip0";
1112
const INPUT_LINE: u32 = 4;
1213
const OUTPUT_LINE: u32 = 17;
1314

1415
#[tokio::main]
1516
async fn main() -> Result<(), Box<dyn Error>> {
16-
let mut chip = Chip::new("/dev/gpiochip0")?;
17-
let input = chip.get_line(INPUT_LINE)?;
18-
let output = chip.get_line(OUTPUT_LINE)?;
19-
20-
let mut input_pin =
21-
CdevPin::new(input.request(LineRequestFlags::INPUT, 0, "")?)?.into_input_pin()?;
22-
let mut output_pin = CdevPin::new(output.request(LineRequestFlags::OUTPUT, 0, "")?)?
23-
.into_output_pin(PinState::Low)?;
17+
let input = Request::builder()
18+
.on_chip(CHIP)
19+
.with_line(INPUT_LINE)
20+
.request()?;
21+
let output = Request::builder()
22+
.on_chip(CHIP)
23+
.with_line(OUTPUT_LINE)
24+
.request()?;
25+
26+
let mut input_pin = CdevPin::new(input)?.into_input_pin()?;
27+
let mut output_pin = CdevPin::new(output)?.into_output_pin(PinState::Low)?;
2428

2529
timeout(Duration::from_secs(10), async move {
2630
let set_output = tokio::spawn(async move {
@@ -30,7 +34,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
3034
});
3135

3236
println!("Waiting for input to go high.");
33-
3437
input_pin.wait_for_high().await?;
3538

3639
assert!(input_pin.is_high()?);

0 commit comments

Comments
 (0)