Skip to content

Several updates #63

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 11 commits into from
Sep 19, 2021
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/bors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ status = [
"build (stable, x86_64-unknown-linux-gnu)",
"build (stable, x86_64-unknown-linux-musl)",

"build (1.45.0, x86_64-unknown-linux-gnu)",
"build (1.46.0, x86_64-unknown-linux-gnu)",

"checks"
]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

include:
# MSRV
- rust: 1.45.0
- rust: 1.46.0
TARGET: x86_64-unknown-linux-gnu

# Test nightly but don't fail
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.45.0
toolchain: 1.46.0
components: clippy

- uses: actions-rs/clippy-check@v1
Expand Down
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Fix lsgpio example to output gpio line flags

## v0.5.0

- Update Tokio to 1.x. #[55]((https://github.com/rust-embedded/gpio-cdev/pull/55).
- Fix lsgpio example to output gpio line flags.
- Add `is_empty()` function for `Lines` struct.
- Add common trait implementations for public structures.
- Breaking change of `LineEventHandle::get_event()` which now expects `&mut self`.
- MSRV is now 1.45.0
- Updated `nix` to version `0.20`.
- MSRV is now 1.46.0.
- Updated `nix` to version `0.22`.
- Updated `quicli` to version `0.4`.
- Updated `bitflags` to version `1.3`.


## v0.4.0 - 2020-08-01
Expand Down Expand Up @@ -49,4 +51,4 @@ Adds the ability to create a collection of lines from a single chip and read or
- Initial release of the library with basic operations centered around operating
on a single line at a time.

[Unreleased]: https://github.com/posborne/rust-gpio-cdev/compare/0.1.0...HEAD
[Unreleased]: https://github.com/rust-embedded/gpio-cdev/compare/0.4.0...HEAD
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name = "gpio-cdev"
version = "0.4.0"
authors = ["Paul Osborne <[email protected]>", "Frank Pagliughi <[email protected]>"]
description = "Linux GPIO Character Device Support (/dev/gpiochipN)"
homepage = "https://github.com/posborne/rust-gpio-cdev"
repository = "https://github.com/posborne/rust-gpio-cdev"
homepage = "https://github.com/rust-embedded/gpio-cdev"
repository = "https://github.com/rust-embedded/gpio-cdev"
readme = "README.md"
categories = ["embedded", "hardware-support", "os", "os::unix-apis"]
keywords = ["linux", "gpio", "gpiochip", "embedded"]
Expand All @@ -20,9 +20,9 @@ name = "async_tokio"
required-features = ["async-tokio"]

[dependencies]
bitflags = "1.0"
bitflags = "1.3"
libc = "0.2"
nix = "0.20"
nix = "0.22"
tokio = { version = "1", features = ["io-std", "net"], optional = true }
futures = { version = "0.3", optional = true }

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# gpio-cdev

[![Build Status](https://travis-ci.org/rust-embedded/gpio-cdev.svg?branch=master)](https://travis-ci.org/rust-embedded/gpio-cdev)
[![Build Status](https://github.com/rust-embedded/gpio-cdev/workflows/Build/badge.svg)](https://github.com/rust-embedded/gpio-cdev/actions)
[![Version](https://img.shields.io/crates/v/gpio-cdev.svg)](https://crates.io/crates/gpio-cdev)
[![License](https://img.shields.io/crates/l/gpio-cdev.svg)](https://github.com/rust-embedded/gpio-cdev/blob/master/README.md#license)

Expand All @@ -19,7 +19,7 @@ GPIO Character Device](#sysfs-gpio-vs-gpio-character-device).

## Installation

Add the following to your Cargo.toml
Add the following to your `Cargo.toml`

```
[dependencies]
Expand All @@ -34,7 +34,7 @@ Note that the following features are available:
## Examples

There are several additional examples available in the [examples
directory](https://github.com/posborne/rust-gpio-cdev/tree/master/examples).
directory](https://github.com/rust-embedded/rust-gpio-cdev/tree/master/examples).

### Read State

Expand Down 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.45.0 and up. It *might*
This crate is guaranteed to compile on stable Rust 1.46.0 and up. It *might*
compile with older versions but that may change in any new patch release.

## License
Expand Down
6 changes: 1 addition & 5 deletions src/async_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ impl Stream for AsyncLineEventHandle {
// Continue
}
Ok(Ok(Some(event))) => return Poll::Ready(Some(Ok(event))),
Ok(Ok(None)) => {
return Poll::Ready(Some(Err(event_err(nix::Error::Sys(
nix::errno::Errno::EIO,
)))))
}
Ok(Ok(None)) => return Poll::Ready(Some(Err(event_err(nix::errno::Errno::EIO)))),
Ok(Err(err)) => return Poll::Ready(Some(Err(err.into()))),
}
}
Expand Down
41 changes: 22 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ mod async_tokio;
pub mod errors; // pub portion is deprecated
mod ffi;

#[derive(Debug)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum IoctlKind {
ChipInfo,
LineInfo,
Expand Down Expand Up @@ -165,9 +165,11 @@ struct InnerChip {
/// [`chips()`]: fn.chips.html
#[derive(Debug)]
pub struct Chip {
inner: Arc<Box<InnerChip>>,
inner: Arc<InnerChip>,
}

/// Iterator over chips
#[derive(Debug)]
pub struct ChipIterator {
readdir: ReadDir,
}
Expand All @@ -176,7 +178,7 @@ impl Iterator for ChipIterator {
type Item = Result<Chip>;

fn next(&mut self) -> Option<Result<Chip>> {
while let Some(entry) = self.readdir.next() {
for entry in &mut self.readdir {
match entry {
Ok(entry) => {
if entry
Expand Down Expand Up @@ -209,11 +211,11 @@ impl Chip {
/// Open the GPIO Chip at the provided path (e.g. `/dev/gpiochip<N>`)
pub fn new<P: AsRef<Path>>(path: P) -> Result<Chip> {
let f = File::open(path.as_ref())?;
let mut info: ffi::gpiochip_info = unsafe { mem::MaybeUninit::uninit().assume_init() };
let mut info: ffi::gpiochip_info = unsafe { mem::zeroed() };
ffi::gpio_get_chipinfo_ioctl(f.as_raw_fd(), &mut info)?;

Ok(Chip {
inner: Arc::new(Box::new(InnerChip {
inner: Arc::new(InnerChip {
file: f,
path: path.as_ref().to_path_buf(),
name: unsafe {
Expand All @@ -227,7 +229,7 @@ impl Chip {
.into_owned()
},
lines: info.lines,
})),
}),
})
}

Expand Down Expand Up @@ -297,8 +299,9 @@ impl Chip {
}

/// Iterator over GPIO Lines for a given chip.
#[derive(Debug)]
pub struct LineIterator {
chip: Arc<Box<InnerChip>>,
chip: Arc<InnerChip>,
idx: u32,
}

Expand Down Expand Up @@ -327,7 +330,7 @@ impl Iterator for LineIterator {
///
#[derive(Debug, Clone)]
pub struct Line {
chip: Arc<Box<InnerChip>>,
chip: Arc<InnerChip>,
offset: u32,
}

Expand Down Expand Up @@ -388,7 +391,7 @@ bitflags! {
}

/// In or Out
#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineDirection {
In,
Out,
Expand All @@ -403,7 +406,7 @@ unsafe fn cstrbuf_to_string(buf: &[libc::c_char]) -> Option<String> {
}

impl Line {
fn new(chip: Arc<Box<InnerChip>>, offset: u32) -> Result<Line> {
fn new(chip: Arc<InnerChip>, offset: u32) -> Result<Line> {
if offset >= chip.lines {
return Err(offset_err(offset));
}
Expand Down Expand Up @@ -560,8 +563,6 @@ impl Line {

Ok(LineEventHandle {
line: self.clone(),
handle_flags,
event_flags,
file: unsafe { File::from_raw_fd(request.fd) },
})
}
Expand Down Expand Up @@ -716,7 +717,7 @@ pub struct Lines {
}

impl Lines {
fn new(chip: Arc<Box<InnerChip>>, offsets: &[u32]) -> Result<Lines> {
fn new(chip: Arc<InnerChip>, offsets: &[u32]) -> Result<Lines> {
let res: Result<Vec<Line>> = offsets
.iter()
.map(|off| Line::new(chip.clone(), *off))
Expand All @@ -730,6 +731,11 @@ impl Lines {
self.lines[0].chip()
}

/// Get the number of lines in the collection
pub fn is_empty(&self) -> bool {
self.lines.is_empty()
}

/// Get the number of lines in the collection
pub fn len(&self) -> usize {
self.lines.len()
Expand Down Expand Up @@ -780,6 +786,7 @@ impl Lines {
lines: n as u32,
fd: 0,
};
#[allow(clippy::needless_range_loop)] // clippy does not understand this loop correctly
for i in 0..n {
request.lineoffsets[i] = self.lines[i].offset();
request.default_values[i] = default[i];
Expand All @@ -795,7 +802,6 @@ impl Lines {
let lines = self.lines.clone();
Ok(MultiLineHandle {
lines: Lines { lines },
flags,
file: unsafe { File::from_raw_fd(request.fd) },
})
}
Expand All @@ -821,7 +827,6 @@ impl Index<usize> for Lines {
#[derive(Debug)]
pub struct MultiLineHandle {
lines: Lines,
flags: LineRequestFlags,
file: File,
}

Expand Down Expand Up @@ -887,7 +892,7 @@ impl AsRawFd for MultiLineHandle {
/// Maps to kernel [`GPIOEVENT_EVENT_*`] definitions.
///
/// [`GPIOEVENT_EVENT_*`]: https://elixir.bootlin.com/linux/v4.9.127/source/include/uapi/linux/gpio.h#L136
#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum EventType {
RisingEdge,
FallingEdge,
Expand Down Expand Up @@ -947,8 +952,6 @@ impl LineEvent {
#[derive(Debug)]
pub struct LineEventHandle {
line: Line,
handle_flags: LineRequestFlags,
event_flags: EventRequestFlags,
file: File,
}

Expand All @@ -961,7 +964,7 @@ impl LineEventHandle {
pub fn get_event(&mut self) -> Result<LineEvent> {
match self.read_event() {
Ok(Some(event)) => Ok(event),
Ok(None) => Err(event_err(nix::Error::Sys(nix::errno::Errno::EIO))),
Ok(None) => Err(event_err(nix::errno::Errno::EIO)),
Err(e) => Err(e.into()),
}
}
Expand Down