Skip to content

Commit 69607c7

Browse files
bors[bot]posborne
andauthored
Merge #40
40: Prep 0.4.0, Error changes, MSRV Bump r=nastevens a=posborne * Prep 0.4.0 Release * Deperecate odd errors module and expose via re-export at top-level (argument could be made to just rip the band-aid off here or to not make the change at all). * Fix testing to cover async changes and MSRV to be compatible with those (we are doing a major version bump so this is OK) * Add some more docs content for the async changes Co-authored-by: Paul Osborne <[email protected]>
2 parents 29c4f64 + f973028 commit 69607c7

18 files changed

+103
-107
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ matrix:
7272

7373
# MSRV
7474
- env: TARGET=x86_64-unknown-linux-gnu
75-
rust: 1.38.0
75+
rust: 1.39.0
7676
if: (branch = staging OR branch = trying) OR (type = pull_request AND branch = master)
7777

7878
before_install:

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11+
## v0.4.0 - 2020-08-01
12+
13+
- Removed pub "errors" module. Error now exposed at top level.
14+
- MSRV is now 1.39.0
15+
- Add support behind a feature flag for reading events from a line as a Stream via tokio. [#35](https://github.com/rust-embedded/gpio-cdev/pull/35).
16+
1117
## v0.3.0 - 2020-02-10
1218

1319
Refactored Errors:

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gpio-cdev"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = ["Paul Osborne <[email protected]>", "Frank Pagliughi <[email protected]>"]
55
description = "Linux GPIO Character Device Support (/dev/gpiochipN)"
66
homepage = "https://github.com/posborne/rust-gpio-cdev"

README.md

+34-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ Add the following to your Cargo.toml
2323

2424
```
2525
[dependencies]
26-
gpio-cdev = "0.2"
26+
gpio-cdev = "0.4"
2727
```
2828

29+
Note that the following features are available:
30+
31+
* `async-tokio`: Adds a Stream interface for consuming GPIO events in async code
32+
within a tokio runtime.
33+
2934
## Examples
3035

3136
There are several additional examples available in the [examples
@@ -58,7 +63,7 @@ use gpio_cdev::{Chip, LineRequestFlags, EventRequestFlags, EventType};
5863
// on gpiochip0 and mirror its state on another line. With this you
5964
// could, for instance, control the state of an LED with a button
6065
// if hooked up to the right pins on a raspberry pi.
61-
fn mirror_gpio(inputline: u32, outputline: u32) -> gpio_cdev::errors::Result<()> {
66+
fn mirror_gpio(inputline: u32, outputline: u32) -> Result<(), gpio_cdev::Error> {
6267
let mut chip = Chip::new("/dev/gpiochip0")?;
6368
let input = chip.get_line(inputline)?;
6469
let output = chip.get_line(outputline)?;
@@ -84,6 +89,32 @@ fn mirror_gpio(inputline: u32, outputline: u32) -> gpio_cdev::errors::Result<()>
8489
}
8590
```
8691

92+
### Async Usage
93+
94+
Note that this requires the addition of the `async-tokio` feature.
95+
96+
```rust
97+
use futures::stream::StreamExt;
98+
use gpio_cdev::{Chip, AsyncLineEventHandle};
99+
100+
async fn gpiomon(chip: String, line: u32) -> gpio_cdev::Result<()> {
101+
let mut chip = Chip::new(args.chip)?;
102+
let line = chip.get_line(args.line)?;
103+
let mut events = AsyncLineEventHandle::new(line.events(
104+
LineRequestFlags::INPUT,
105+
EventRequestFlags::BOTH_EDGES,
106+
"gpioevents",
107+
)?)?;
108+
109+
while let Some(event) = events.next().await {
110+
let event = event?;
111+
println!("GPIO Event: {:?}", event);
112+
}
113+
114+
Ok(())
115+
}
116+
```
117+
87118
## Sysfs GPIO vs GPIO Character Device
88119

89120
Compared to the sysfs gpio interface (as made available by the sysfs_gpio crate)
@@ -175,7 +206,7 @@ to be considered reliable.
175206

176207
## Minimum Supported Rust Version (MSRV)
177208

178-
This crate is guaranteed to compile on stable Rust 1.38.0 and up. It *might*
209+
This crate is guaranteed to compile on stable Rust 1.39.0 and up. It *might*
179210
compile with older versions but that may change in any new patch release.
180211

181212
## License

ci/script.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
set -ex
44

55
main() {
6-
cross build --target $TARGET
7-
cross build --target $TARGET --release
6+
cross build --target $TARGET --all-features
7+
cross build --target $TARGET --release --all-features
88

99
if [ ! -z $DISABLE_TESTS ]; then
1010
return
1111
fi
1212

13-
cross test --target $TARGET
14-
cross test --target $TARGET --release
13+
cross test --target $TARGET --all-features
14+
cross test --target $TARGET --release --all-features
1515

1616
# No main binary, so skip the 'cross run' portion
1717
# cross run --target $TARGET

examples/async_tokio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// except according to those terms.
88

99
use futures::stream::StreamExt;
10-
use gpio_cdev::*;
10+
use gpio_cdev::{AsyncLineEventHandle, Chip, EventRequestFlags, LineRequestFlags};
1111
use quicli::prelude::*;
1212

1313
#[derive(Debug, StructOpt)]
@@ -18,7 +18,7 @@ struct Cli {
1818
line: u32,
1919
}
2020

21-
async fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
21+
async fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
2222
let mut chip = Chip::new(args.chip)?;
2323
let line = chip.get_line(args.line)?;
2424
let mut events = AsyncLineEventHandle::new(line.events(

examples/blinky.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,11 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate gpio_cdev;
10-
#[macro_use]
11-
extern crate quicli;
12-
13-
use gpio_cdev::*;
9+
use gpio_cdev::{Chip, LineRequestFlags};
1410
use quicli::prelude::*;
1511
use std::thread::sleep;
1612
use std::time::{Duration, Instant};
1713

18-
1914
#[derive(Debug, StructOpt)]
2015
struct Cli {
2116
/// The gpiochip device (e.g. /dev/gpiochip0)
@@ -28,7 +23,7 @@ struct Cli {
2823
duration_ms: u64,
2924
}
3025

31-
fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
26+
fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
3227
let mut chip = Chip::new(args.chip)?;
3328

3429
// NOTE: we set the default value to the desired state so
@@ -49,7 +44,7 @@ fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
4944
Ok(())
5045
}
5146

52-
main!(|args: Cli| match do_main(args) {
47+
quicli::main!(|args: Cli| match do_main(args) {
5348
Ok(()) => {}
5449
Err(e) => {
5550
println!("Error: {:?}", e);

examples/driveoutput.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate gpio_cdev;
10-
#[macro_use]
11-
extern crate quicli;
12-
13-
use gpio_cdev::*;
9+
use gpio_cdev::{Chip, LineRequestFlags};
1410
use quicli::prelude::*;
1511

1612
#[derive(Debug, StructOpt)]
@@ -23,7 +19,7 @@ struct Cli {
2319
value: u8,
2420
}
2521

26-
fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
22+
fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
2723
let mut chip = Chip::new(args.chip)?;
2824

2925
// NOTE: we set the default value to the desired state so
@@ -44,7 +40,7 @@ fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
4440
Ok(())
4541
}
4642

47-
main!(|args: Cli| match do_main(args) {
43+
quicli::main!(|args: Cli| match do_main(args) {
4844
Ok(()) => {}
4945
Err(e) => {
5046
println!("Error: {:?}", e);

examples/gpioevents.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate gpio_cdev;
10-
#[macro_use]
11-
extern crate quicli;
12-
13-
use gpio_cdev::*;
9+
use gpio_cdev::{Chip, EventRequestFlags, LineRequestFlags};
1410
use quicli::prelude::*;
1511

16-
1712
#[derive(Debug, StructOpt)]
1813
struct Cli {
1914
/// The gpiochip device (e.g. /dev/gpiochip0)
@@ -22,7 +17,7 @@ struct Cli {
2217
line: u32,
2318
}
2419

25-
fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
20+
fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
2621
let mut chip = Chip::new(args.chip)?;
2722
let line = chip.get_line(args.line)?;
2823

@@ -37,7 +32,7 @@ fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
3732
Ok(())
3833
}
3934

40-
main!(|args: Cli| match do_main(args) {
35+
quicli::main!(|args: Cli| match do_main(args) {
4136
Ok(()) => {}
4237
Err(e) => {
4338
println!("Error: {:?}", e);

examples/multioutput.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate gpio_cdev;
10-
#[macro_use]
11-
extern crate quicli;
12-
13-
use gpio_cdev::*;
9+
use gpio_cdev::{Chip, LineRequestFlags};
1410
use quicli::prelude::*;
1511

1612
#[derive(Debug, StructOpt)]
@@ -28,7 +24,7 @@ struct Cli {
2824
// to set lines 0, 1, & 3 high
2925
// 2 & 4 low
3026
//
31-
fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
27+
fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
3228
let mut chip = Chip::new(args.chip)?;
3329
let mut offsets = Vec::new();
3430
let mut values = Vec::new();
@@ -52,7 +48,7 @@ fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
5248
Ok(())
5349
}
5450

55-
main!(|args: Cli| match do_main(args) {
51+
quicli::main!(|args: Cli| match do_main(args) {
5652
Ok(()) => {}
5753
Err(e) => {
5854
println!("Error: {:?}", e);

examples/multiread.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate gpio_cdev;
10-
#[macro_use]
11-
extern crate quicli;
12-
13-
use gpio_cdev::*;
9+
use gpio_cdev::{Chip, LineRequestFlags};
1410
use quicli::prelude::*;
1511

1612
#[derive(Debug, StructOpt)]
@@ -21,18 +17,18 @@ struct Cli {
2117
lines: Vec<u32>,
2218
}
2319

24-
fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
20+
fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
2521
let mut chip = Chip::new(args.chip)?;
26-
let ini_vals = vec![ 0; args.lines.len() ];
27-
let handle = chip
28-
.get_lines(&args.lines)?
29-
.request(LineRequestFlags::INPUT, &ini_vals, "multiread")?;
22+
let ini_vals = vec![0; args.lines.len()];
23+
let handle =
24+
chip.get_lines(&args.lines)?
25+
.request(LineRequestFlags::INPUT, &ini_vals, "multiread")?;
3026
println!("Values: {:?}", handle.get_values()?);
3127

3228
Ok(())
3329
}
3430

35-
main!(|args: Cli| match do_main(args) {
31+
quicli::main!(|args: Cli| match do_main(args) {
3632
Ok(()) => {}
3733
Err(e) => {
3834
println!("Error: {:?}", e);

examples/readall.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate gpio_cdev;
10-
#[macro_use]
11-
extern crate quicli;
12-
13-
use gpio_cdev::*;
9+
use gpio_cdev::{Chip, LineRequestFlags};
1410
use quicli::prelude::*;
1511

1612
#[derive(Debug, StructOpt)]
@@ -19,7 +15,7 @@ struct Cli {
1915
chip: String,
2016
}
2117

22-
fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
18+
fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
2319
let mut chip = Chip::new(args.chip)?;
2420
let ini_vals = vec![0; chip.num_lines() as usize];
2521
let handle = chip
@@ -30,7 +26,7 @@ fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
3026
Ok(())
3127
}
3228

33-
main!(|args: Cli| match do_main(args) {
29+
quicli::main!(|args: Cli| match do_main(args) {
3430
Ok(()) => {}
3531
Err(e) => {
3632
println!("Error: {:?}", e);

examples/readinput.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate gpio_cdev;
10-
#[macro_use]
11-
extern crate quicli;
12-
13-
use gpio_cdev::*;
9+
use gpio_cdev::{Chip, LineRequestFlags};
1410
use quicli::prelude::*;
1511

1612
#[derive(Debug, StructOpt)]
@@ -21,7 +17,7 @@ struct Cli {
2117
line: u32,
2218
}
2319

24-
fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
20+
fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
2521
let mut chip = Chip::new(args.chip)?;
2622
let handle = chip
2723
.get_line(args.line)?
@@ -31,7 +27,7 @@ fn do_main(args: Cli) -> std::result::Result<(), errors::Error> {
3127
Ok(())
3228
}
3329

34-
main!(|args: Cli| match do_main(args) {
30+
quicli::main!(|args: Cli| match do_main(args) {
3531
Ok(()) => {}
3632
Err(e) => {
3733
println!("Error: {:?}", e);

0 commit comments

Comments
 (0)