Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 21 additions & 60 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ on:
- "gh-readonly-queue/**"
pull_request: # Run CI for PRs on any branch
merge_group: # Run CI for the GitHub merge queue

name: Build

env:
RUSTFLAGS: '--deny warnings'

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -32,86 +29,50 @@ jobs:
- s390x-unknown-linux-gnu
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl

include:
# MSRV
- rust: 1.82.0
- rust: 1.85.0
TARGET: x86_64-unknown-linux-gnu

# Test nightly but don't fail
- rust: nightly
TARGET: x86_64-unknown-linux-gnu
experimental: true

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
target: ${{ matrix.TARGET }}
override: true

- uses: actions/checkout@v4
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross --locked
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.TARGET }}

run: cross build --target=${{ matrix.TARGET }}
- name: Build all features
uses: actions-rs/cargo@v1
with:
command: build
args: --target=${{ matrix.TARGET }} --all-features

run: cross build --target=${{ matrix.TARGET }} --all-features
- name: Test
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --target=${{ matrix.TARGET }}

run: cross test --target=${{ matrix.TARGET }}
- name: Test all features
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --target=${{ matrix.TARGET }} --all-features

run: cross test --target=${{ matrix.TARGET }} --all-features
checks:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
components: rustfmt

- uses: Swatinem/rust-cache@v2
- name: Ensure rustfmt is installed
run: rustup component add rustfmt
- name: Doc
uses: actions-rs/cargo@v1
with:
command: doc

run: cargo doc
- name: Formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

run: cargo fmt --all -- --check
clippy:
runs-on: ubuntu-latest
env:
RUSTFLAGS: '--allow warnings'
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
profile: minimal
toolchain: 1.82.0
toolchain: 1.85.0
components: clippy

- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: Swatinem/rust-cache@v2
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Changed

- MSRV is now 1.82.0.
- MSRV is now 1.85.0.

## [v0.6.0] - 2023-09-11

Expand Down
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ name = "async_tokio"
required-features = ["async-tokio"]

[dependencies]
bitflags = "2.4"
bitflags = "2.13"
libc = "0.2"
nix = { version = "0.27", features = ["ioctl"] }
nix = { version = "0.31", features = ["ioctl"] }
tokio = { version = "1", features = ["io-std", "net"], optional = true }
futures = { version = "0.3", optional = true }

[dev-dependencies]
quicli = "0.4"
structopt = "0.3"
clap = { version = "4", features = ["derive"] }
anyhow = "1.0"
tokio = { version = "1", features = ["io-std", "rt-multi-thread", "macros", "net"] }
nix = { version = "0.27", features = ["ioctl", "poll"] }
nix = { version = "0.31", features = ["ioctl", "poll"] }

[package.metadata.docs.rs]
# To build locally:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ to be considered reliable.

## Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.82.0 and up. It *might*
This crate is guaranteed to compile on stable Rust 1.85.0 and up. It *might*
compile with older versions but that may change in any new patch release.

## License
Expand Down
17 changes: 7 additions & 10 deletions examples/async_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use clap::Parser;
use futures::stream::StreamExt;
use gpio_cdev::{AsyncLineEventHandle, Chip, EventRequestFlags, LineRequestFlags};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
/// The gpiochip device (e.g. /dev/gpiochip0)
chip: String,
Expand All @@ -27,18 +27,15 @@ async fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
"gpioevents",
)?)?;

loop {
match events.next().await {
Some(event) => println!("{:?}", event?),
None => break,
};
while let Some(event) = events.next().await {
println!("{:?}", event?);
}

Ok(())
}

#[tokio::main]
async fn main() {
let args = Cli::from_args();
do_main(args).await.unwrap();
async fn main() -> std::result::Result<(), gpio_cdev::Error> {
let args = Cli::parse();
do_main(args).await
}
14 changes: 5 additions & 9 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use clap::Parser;
use gpio_cdev::{Chip, LineRequestFlags};
use quicli::prelude::*;
use std::thread::sleep;
use std::time::{Duration, Instant};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
/// The gpiochip device (e.g. /dev/gpiochip0)
chip: String,
Expand Down Expand Up @@ -45,10 +44,7 @@ fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
Ok(())
}

fn main() -> CliResult {
let args = Cli::from_args();
do_main(args).or_else(|e| {
error!("{:?}", e);
Ok(())
})
fn main() -> std::result::Result<(), gpio_cdev::Error> {
let args = Cli::parse();
do_main(args)
}
14 changes: 5 additions & 9 deletions examples/driveoutput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use clap::Parser;
use gpio_cdev::{Chip, LineRequestFlags};
use quicli::prelude::*;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
/// The gpiochip device (e.g. /dev/gpiochip0)
chip: String,
Expand Down Expand Up @@ -41,10 +40,7 @@ fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
Ok(())
}

fn main() -> CliResult {
let args = Cli::from_args();
do_main(args).or_else(|e| {
error!("{:?}", e);
Ok(())
})
fn main() -> std::result::Result<(), gpio_cdev::Error> {
let args = Cli::parse();
do_main(args)
}
14 changes: 5 additions & 9 deletions examples/gpioevents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use clap::Parser;
use gpio_cdev::{Chip, EventRequestFlags, LineRequestFlags};
use quicli::prelude::*;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
struct Cli {
/// The gpiochip device (e.g. /dev/gpiochip0)
chip: String,
Expand All @@ -33,10 +32,7 @@ fn do_main(args: Cli) -> std::result::Result<(), gpio_cdev::Error> {
Ok(())
}

fn main() -> CliResult {
let args = Cli::from_args();
do_main(args).or_else(|e| {
error!("{:?}", e);
Ok(())
})
fn main() -> std::result::Result<(), gpio_cdev::Error> {
let args = Cli::parse();
do_main(args)
}
84 changes: 41 additions & 43 deletions examples/lsgpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,54 @@ fn main() {
}
};

for chip in chip_iterator {
if let Ok(chip) = chip {
println!(
"GPIO chip: {}, \"{}\", \"{}\", {} GPIO Lines",
chip.path().to_string_lossy(),
chip.name(),
chip.label(),
chip.num_lines()
);
for line in chip.lines() {
match line.info() {
Ok(info) => {
let mut flags = vec![];
for chip in chip_iterator.flatten() {
println!(
"GPIO chip: {}, \"{}\", \"{}\", {} GPIO Lines",
chip.path().to_string_lossy(),
chip.name(),
chip.label(),
chip.num_lines()
);
for line in chip.lines() {
match line.info() {
Ok(info) => {
let mut flags = vec![];

if info.is_kernel() {
flags.push("kernel");
}
if info.is_kernel() {
flags.push("kernel");
}

if info.direction() == LineDirection::Out {
flags.push("output");
}
if info.direction() == LineDirection::Out {
flags.push("output");
}

if info.is_active_low() {
flags.push("active-low");
}
if info.is_open_drain() {
flags.push("open-drain");
}
if info.is_open_source() {
flags.push("open-source");
}
if info.is_active_low() {
flags.push("active-low");
}
if info.is_open_drain() {
flags.push("open-drain");
}
if info.is_open_source() {
flags.push("open-source");
}

let usage = if !flags.is_empty() {
format!("[{}]", flags.join(" "))
} else {
"".to_owned()
};
let usage = if !flags.is_empty() {
format!("[{}]", flags.join(" "))
} else {
"".to_owned()
};

println!(
"\tline {lineno:>3}: {name} {consumer} {usage}",
lineno = info.line().offset(),
name = info.name().unwrap_or("unused"),
consumer = info.consumer().unwrap_or("unused"),
usage = usage,
);
}
Err(e) => println!("\tError getting line info: {:?}", e),
println!(
"\tline {lineno:>3}: {name} {consumer} {usage}",
lineno = info.line().offset(),
name = info.name().unwrap_or("unused"),
consumer = info.consumer().unwrap_or("unused"),
usage = usage,
);
}
Err(e) => println!("\tError getting line info: {:?}", e),
}
println!();
}
println!();
}
}
Loading
Loading