Skip to content

Fix codeowners + update dependencies + raise MSRV #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* rust-embedded/embedded-linux
* @rust-embedded/embedded-linux
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

include:
# MSRV
- rust: 1.65.0
- rust: 1.70.0
TARGET: x86_64-unknown-linux-gnu

# Test nightly but don't fail
Expand Down Expand Up @@ -109,10 +109,9 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.65.0
toolchain: 1.70.0
components: clippy

- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Changed

- Updated `mio` to version `1`.
- Updated `nix` to version `0.26`.
- Minimum supported Rust version updated to 1.70.0

## [0.6.2] - 2024-05-13

- Minimum supported Rust version updated to 1.65.0
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ homepage = "https://github.com/rust-embedded/rust-sysfs-gpio"
documentation = "https://docs.rs/sysfs_gpio/"
description = "Provides access to GPIOs using the Linux sysfs interface."
readme = "README.md"
edition = "2018"
edition = "2021"

[features]
mio-evented = ["mio"]
async-tokio = ["futures", "tokio", "mio-evented"]

[dependencies]
futures = { version = "0.3", optional = true }
nix = "0.23"
mio = { version = "0.8", optional = true, features = ["os-ext"]}
nix = "0.26"
mio = { version = "1", optional = true, features = ["os-ext"]}
tokio = { version = "1", optional = true, features = ["net"] }

[dev-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)

Copyright (c) 2015 Paul Osborne
Copyright (c) 2021 The Rust Embedded Linux Team
Copyright (c) 2021-2025 The Rust Embedded Linux Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -20,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sysfs_gpio

[![Build Status](https://github.com/rust-embedded/rust-sysfs-gpio/workflows/CI/badge.svg)](https://github.com/rust-embedded/rust-sysfs-gpio/actions)
[![Version](https://img.shields.io/crates/v/sysfs-gpio.svg)](https://crates.io/crates/sysfs-gpio)
![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.65+-blue.svg)
![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.70+-blue.svg)
[![License](https://img.shields.io/crates/l/sysfs-gpio.svg)](https://github.com/rust-embedded/rust-sysfs-gpio/blob/master/README.md#license)

- [API Documentation](https://docs.rs/sysfs_gpio)
Expand Down Expand Up @@ -85,7 +85,7 @@ The following features are planned for the library:

## Minimum Supported Rust Version (MSRV)

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

## Cross Compiling
Expand Down
42 changes: 20 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@
//! use std::thread::sleep;
//! use std::time::Duration;
//!
//! fn main() {
//! let my_led = Pin::new(127); // number depends on chip, etc.
//! my_led.with_exported(|| {
//! my_led.set_direction(Direction::Out).unwrap();
//! loop {
//! my_led.set_value(0).unwrap();
//! sleep(Duration::from_millis(200));
//! my_led.set_value(1).unwrap();
//! sleep(Duration::from_millis(200));
//! }
//! }).unwrap();
//! }
//! let my_led = Pin::new(127); // number depends on chip, etc.
//! my_led.with_exported(|| {
//! my_led.set_direction(Direction::Out).unwrap();
//! loop {
//! my_led.set_value(0).unwrap();
//! sleep(Duration::from_millis(200));
//! my_led.set_value(1).unwrap();
//! sleep(Duration::from_millis(200));
//! }
//! }).unwrap();
//! ```

#![cfg_attr(feature = "async-tokio", allow(deprecated))]
Expand Down Expand Up @@ -247,7 +245,7 @@ impl Pin {
/// This function will error out if the kernel does not support the GPIO
/// sysfs interface (i.e. `/sys/class/gpio` does not exist).
pub fn is_exported(&self) -> bool {
fs::metadata(&format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok()
fs::metadata(format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok()
}

/// Export the GPIO
Expand Down Expand Up @@ -276,7 +274,7 @@ impl Pin {
/// }
/// ```
pub fn export(&self) -> Result<()> {
if fs::metadata(&format!("/sys/class/gpio/gpio{}", self.pin_num)).is_err() {
if fs::metadata(format!("/sys/class/gpio/gpio{}", self.pin_num)).is_err() {
let mut export_file = File::create("/sys/class/gpio/export")?;
export_file.write_all(format!("{}", self.pin_num).as_bytes())?;
}
Expand All @@ -290,7 +288,7 @@ impl Pin {
/// exported, it will return without error. That is, whenever
/// this function returns Ok, the GPIO is not exported.
pub fn unexport(&self) -> Result<()> {
if fs::metadata(&format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok() {
if fs::metadata(format!("/sys/class/gpio/gpio{}", self.pin_num)).is_ok() {
let mut unexport_file = File::create("/sys/class/gpio/unexport")?;
unexport_file.write_all(format!("{}", self.pin_num).as_bytes())?;
}
Expand Down Expand Up @@ -501,15 +499,15 @@ impl Pin {

#[test]
fn extract_pin_fom_path_test() {
let tok1 = Pin::extract_pin_from_path(&"/sys/class/gpio/gpio951");
let tok1 = Pin::extract_pin_from_path("/sys/class/gpio/gpio951");
assert_eq!(951, tok1.unwrap());
let tok2 = Pin::extract_pin_from_path(&"/sys/CLASS/gpio/gpio951/");
let tok2 = Pin::extract_pin_from_path("/sys/CLASS/gpio/gpio951/");
assert_eq!(951, tok2.unwrap());
let tok3 = Pin::extract_pin_from_path(&"../../devices/soc0/gpiochip3/gpio/gpio124");
let tok3 = Pin::extract_pin_from_path("../../devices/soc0/gpiochip3/gpio/gpio124");
assert_eq!(124, tok3.unwrap());
let err1 = Pin::extract_pin_from_path(&"/sys/CLASS/gpio/gpio");
let err1 = Pin::extract_pin_from_path("/sys/CLASS/gpio/gpio");
assert!(err1.is_err());
let err2 = Pin::extract_pin_from_path(&"/sys/class/gpio/gpioSDS");
let err2 = Pin::extract_pin_from_path("/sys/class/gpio/gpioSDS");
assert!(err2.is_err());
}
#[cfg(not(target_os = "wasi"))]
Expand All @@ -532,7 +530,7 @@ impl PinPoller {
/// Create a new PinPoller for the provided pin number
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn new(pin_num: u64) -> Result<PinPoller> {
let devfile: File = File::open(&format!("/sys/class/gpio/gpio{}/value", pin_num))?;
let devfile: File = File::open(format!("/sys/class/gpio/gpio{}/value", pin_num))?;
let devfile_fd = devfile.as_raw_fd();
let epoll_fd = epoll_create()?;
let mut event = EpollEvent::new(EpollFlags::EPOLLPRI | EpollFlags::EPOLLET, 0u64);
Expand Down Expand Up @@ -609,7 +607,7 @@ pub struct AsyncPinPoller {
#[cfg(feature = "mio-evented")]
impl AsyncPinPoller {
fn new(pin_num: u64) -> Result<Self> {
let devfile = File::open(&format!("/sys/class/gpio/gpio{}/value", pin_num))?;
let devfile = File::open(format!("/sys/class/gpio/gpio{}/value", pin_num))?;
Ok(AsyncPinPoller { devfile })
}
}
Expand Down
Loading