Skip to content

Commit 99eb1f5

Browse files
bors[bot]eldruin
andauthored
Merge #63
63: Several updates r=ryankurte a=eldruin - Update dependencies - Raise MSRV to 1.46.0 due to dependencies - Add common trait implementations for public structs - Update links - Update CI badge - Set a fixed version for clippy in CI Co-authored-by: Diego Barrios Romero <[email protected]>
2 parents c9c5625 + c8fb7c9 commit 99eb1f5

File tree

7 files changed

+41
-40
lines changed

7 files changed

+41
-40
lines changed

.github/bors.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ status = [
1717
"build (stable, x86_64-unknown-linux-gnu)",
1818
"build (stable, x86_64-unknown-linux-musl)",
1919

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

2222
"checks"
2323
]

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
include:
3535
# MSRV
36-
- rust: 1.45.0
36+
- rust: 1.46.0
3737
TARGET: x86_64-unknown-linux-gnu
3838

3939
# Test nightly but don't fail
@@ -107,7 +107,7 @@ jobs:
107107
- uses: actions-rs/toolchain@v1
108108
with:
109109
profile: minimal
110-
toolchain: 1.45.0
110+
toolchain: 1.46.0
111111
components: clippy
112112

113113
- uses: actions-rs/clippy-check@v1

CHANGELOG.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11-
- Fix lsgpio example to output gpio line flags
12-
1311
## v0.5.0
1412

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

2123

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

52-
[Unreleased]: https://github.com/posborne/rust-gpio-cdev/compare/0.1.0...HEAD
54+
[Unreleased]: https://github.com/rust-embedded/gpio-cdev/compare/0.4.0...HEAD

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name = "gpio-cdev"
33
version = "0.4.0"
44
authors = ["Paul Osborne <[email protected]>", "Frank Pagliughi <[email protected]>"]
55
description = "Linux GPIO Character Device Support (/dev/gpiochipN)"
6-
homepage = "https://github.com/posborne/rust-gpio-cdev"
7-
repository = "https://github.com/posborne/rust-gpio-cdev"
6+
homepage = "https://github.com/rust-embedded/gpio-cdev"
7+
repository = "https://github.com/rust-embedded/gpio-cdev"
88
readme = "README.md"
99
categories = ["embedded", "hardware-support", "os", "os::unix-apis"]
1010
keywords = ["linux", "gpio", "gpiochip", "embedded"]
@@ -20,9 +20,9 @@ name = "async_tokio"
2020
required-features = ["async-tokio"]
2121

2222
[dependencies]
23-
bitflags = "1.0"
23+
bitflags = "1.3"
2424
libc = "0.2"
25-
nix = "0.20"
25+
nix = "0.22"
2626
tokio = { version = "1", features = ["io-std", "net"], optional = true }
2727
futures = { version = "0.3", optional = true }
2828

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# gpio-cdev
22

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

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

2020
## Installation
2121

22-
Add the following to your Cargo.toml
22+
Add the following to your `Cargo.toml`
2323

2424
```
2525
[dependencies]
@@ -34,7 +34,7 @@ Note that the following features are available:
3434
## Examples
3535

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

3939
### Read State
4040

@@ -206,7 +206,7 @@ to be considered reliable.
206206

207207
## Minimum Supported Rust Version (MSRV)
208208

209-
This crate is guaranteed to compile on stable Rust 1.45.0 and up. It *might*
209+
This crate is guaranteed to compile on stable Rust 1.46.0 and up. It *might*
210210
compile with older versions but that may change in any new patch release.
211211

212212
## License

src/async_tokio.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,7 @@ impl Stream for AsyncLineEventHandle {
8888
// Continue
8989
}
9090
Ok(Ok(Some(event))) => return Poll::Ready(Some(Ok(event))),
91-
Ok(Ok(None)) => {
92-
return Poll::Ready(Some(Err(event_err(nix::Error::Sys(
93-
nix::errno::Errno::EIO,
94-
)))))
95-
}
91+
Ok(Ok(None)) => return Poll::Ready(Some(Err(event_err(nix::errno::Errno::EIO)))),
9692
Ok(Err(err)) => return Poll::Ready(Some(Err(err.into()))),
9793
}
9894
}

src/lib.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ mod async_tokio;
107107
pub mod errors; // pub portion is deprecated
108108
mod ffi;
109109

110-
#[derive(Debug)]
110+
#[derive(Debug, Clone, Copy, PartialEq)]
111111
pub enum IoctlKind {
112112
ChipInfo,
113113
LineInfo,
@@ -165,9 +165,11 @@ struct InnerChip {
165165
/// [`chips()`]: fn.chips.html
166166
#[derive(Debug)]
167167
pub struct Chip {
168-
inner: Arc<Box<InnerChip>>,
168+
inner: Arc<InnerChip>,
169169
}
170170

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

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

215217
Ok(Chip {
216-
inner: Arc::new(Box::new(InnerChip {
218+
inner: Arc::new(InnerChip {
217219
file: f,
218220
path: path.as_ref().to_path_buf(),
219221
name: unsafe {
@@ -227,7 +229,7 @@ impl Chip {
227229
.into_owned()
228230
},
229231
lines: info.lines,
230-
})),
232+
}),
231233
})
232234
}
233235

@@ -297,8 +299,9 @@ impl Chip {
297299
}
298300

299301
/// Iterator over GPIO Lines for a given chip.
302+
#[derive(Debug)]
300303
pub struct LineIterator {
301-
chip: Arc<Box<InnerChip>>,
304+
chip: Arc<InnerChip>,
302305
idx: u32,
303306
}
304307

@@ -327,7 +330,7 @@ impl Iterator for LineIterator {
327330
///
328331
#[derive(Debug, Clone)]
329332
pub struct Line {
330-
chip: Arc<Box<InnerChip>>,
333+
chip: Arc<InnerChip>,
331334
offset: u32,
332335
}
333336

@@ -388,7 +391,7 @@ bitflags! {
388391
}
389392

390393
/// In or Out
391-
#[derive(Debug, PartialEq)]
394+
#[derive(Debug, Clone, Copy, PartialEq)]
392395
pub enum LineDirection {
393396
In,
394397
Out,
@@ -403,7 +406,7 @@ unsafe fn cstrbuf_to_string(buf: &[libc::c_char]) -> Option<String> {
403406
}
404407

405408
impl Line {
406-
fn new(chip: Arc<Box<InnerChip>>, offset: u32) -> Result<Line> {
409+
fn new(chip: Arc<InnerChip>, offset: u32) -> Result<Line> {
407410
if offset >= chip.lines {
408411
return Err(offset_err(offset));
409412
}
@@ -560,8 +563,6 @@ impl Line {
560563

561564
Ok(LineEventHandle {
562565
line: self.clone(),
563-
handle_flags,
564-
event_flags,
565566
file: unsafe { File::from_raw_fd(request.fd) },
566567
})
567568
}
@@ -716,7 +717,7 @@ pub struct Lines {
716717
}
717718

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

734+
/// Get the number of lines in the collection
735+
pub fn is_empty(&self) -> bool {
736+
self.lines.is_empty()
737+
}
738+
733739
/// Get the number of lines in the collection
734740
pub fn len(&self) -> usize {
735741
self.lines.len()
@@ -780,6 +786,7 @@ impl Lines {
780786
lines: n as u32,
781787
fd: 0,
782788
};
789+
#[allow(clippy::needless_range_loop)] // clippy does not understand this loop correctly
783790
for i in 0..n {
784791
request.lineoffsets[i] = self.lines[i].offset();
785792
request.default_values[i] = default[i];
@@ -795,7 +802,6 @@ impl Lines {
795802
let lines = self.lines.clone();
796803
Ok(MultiLineHandle {
797804
lines: Lines { lines },
798-
flags,
799805
file: unsafe { File::from_raw_fd(request.fd) },
800806
})
801807
}
@@ -821,7 +827,6 @@ impl Index<usize> for Lines {
821827
#[derive(Debug)]
822828
pub struct MultiLineHandle {
823829
lines: Lines,
824-
flags: LineRequestFlags,
825830
file: File,
826831
}
827832

@@ -887,7 +892,7 @@ impl AsRawFd for MultiLineHandle {
887892
/// Maps to kernel [`GPIOEVENT_EVENT_*`] definitions.
888893
///
889894
/// [`GPIOEVENT_EVENT_*`]: https://elixir.bootlin.com/linux/v4.9.127/source/include/uapi/linux/gpio.h#L136
890-
#[derive(Debug, PartialEq)]
895+
#[derive(Debug, Clone, Copy, PartialEq)]
891896
pub enum EventType {
892897
RisingEdge,
893898
FallingEdge,
@@ -947,8 +952,6 @@ impl LineEvent {
947952
#[derive(Debug)]
948953
pub struct LineEventHandle {
949954
line: Line,
950-
handle_flags: LineRequestFlags,
951-
event_flags: EventRequestFlags,
952955
file: File,
953956
}
954957

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

0 commit comments

Comments
 (0)