Skip to content

Prepare release 0.1 #9

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
Sep 29, 2018
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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## 0.1.0 - 2018-09-28

- 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
37 changes: 37 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The Rust Code of Conduct

## Conduct

**Contact**: [Embedded Linux Team][team]

* We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristic.
* On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and welcoming environment for all.
* Please be kind and courteous. There's no need to be mean or rude.
* Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and numerous costs. There is seldom a right answer.
* Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and see how it works.
* We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We interpret the term "harassment" as including the definition in the [Citizen Code of Conduct](http://citizencodeofconduct.org/); if you have any lack of clarity about what might be included in that concept, please read their definition. In particular, we don't tolerate behavior that excludes people in socially marginalized groups.
* Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact one of the channel ops or any of the [Embedded Linux Team][team] immediately. Whether you're a regular contributor or a newcomer, we care about making this community a safe place for you and we've got your back.
* Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome.

## Moderation

These are the policies for upholding our community's standards of conduct.

1. Remarks that violate the Rust standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.)
2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed.
3. Moderators will first respond to such remarks with a warning.
4. If the warning is unheeded, the user will be "kicked," i.e., kicked out of the communication channel to cool off.
5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded.
6. Moderators may choose at their discretion to un-ban the user if it was a first offense and they offer the offended party a genuine apology.
7. If a moderator bans someone and you think it was unjustified, please take it up with that moderator, or with a different moderator, **in private**. Complaints about bans in-channel are not allowed.
8. Moderators are held to a higher standard than other community members. If a moderator creates an inappropriate situation, they should expect less leeway than others.

In the Rust community we strive to go the extra step to look out for each other. Don't just aim to be technically unimpeachable, try to be your best self. In particular, avoid flirting with offensive or sensitive issues, particularly if they're off-topic; this all too often leads to unnecessary fights, hurt feelings, and damaged trust; worse, it can drive people away from the community entirely.

And if someone takes issue with something you said or did, resist the urge to be defensive. Just stop doing what it was they complained about and apologize. Even if you feel you were misinterpreted or unfairly accused, chances are good there was something you could've communicated better — remember that it's your responsibility to make your fellow Rustaceans comfortable. Everyone wants to get along and we are all here first and foremost because we want to talk about cool technology. You will find that people will be eager to assume good intent and forgive as long as you earn their trust.

The enforcement policies listed above apply to all official embedded WG venues; including official IRC channels (#rust-embedded); GitHub repositories under rust-embedded; and all forums under rust-embedded.org (forum.rust-embedded.org).

*Adapted from the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling) as well as the [Contributor Covenant v1.3.0](https://www.contributor-covenant.org/version/1/3/0/).*

[team]: https://github.com/rust-embedded/wg#the-embedded-linux-team
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ version = "0.1.0"
authors = ["Paul Osborne <[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"
readme = "README.md"
categories = ["embedded", "hardware-support", "os", "os::unix-apis"]
keywords = ["linux", "gpio", "gpiochip", "embedded"]
license = "MIT / Apache-2.0"
license = "MIT OR Apache-2.0"

[dependencies]
bitflags = "1.0"
error-chain = "0.12"
libc = "0.2"
nix = "0.10"
nix = "0.11"

[dev-dependencies]
quicli = "0.2"
97 changes: 97 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,78 @@ stabilized with Linux v4.4, deprecates the legacy sysfs interface to GPIOs that
planned to be removed from the upstream kernel after
year 2020 (which is coming up quickly).

Use of this API is encouraged over the sysfs API used by this crate's
predecessor [sysfs_gpio](https://crates.io/crates/sysfs_gpio) if you don't need
to target older kernels. For more information on differences see [Sysfs GPIO vs
GPIO Character Device](#sysfs-gpio-vs-gpio-character-device).

## Installation

Add the following to your Cargo.toml

```
[dependencies]
gpio-cdev = "0.1"
```

## Examples

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

### Read State

```rust
use gpio_cdev::{Chip, LineRequestFlags};

// Read the state of GPIO4 on a raspberry pi. /dev/gpiochip0
// maps to the driver for the SoC (builtin) GPIO controller.
let mut chip = Chip::new("/dev/gpiochip0")?;
let handle = chip
.get_line(4)?
.request(LineRequestFlags::INPUT, 0, "read-input")?;
for _ in 1..4 {
println!("Value: {:?}", handle.get_value()?);
}
```

### Mirror State (Read/Write)

```rust
use gpio_cdev::{Chip, LineRequestFlags, EventRequestFlags, EventType};

// Lines are offset within gpiochip0; see docs for more info on chips/lines
//
// This function will synchronously follow the state of one line
// on gpiochip0 and mirror its state on another line. With this you
// could, for instance, control the state of an LED with a button
// if hooked up to the right pins on a raspberry pi.
fn mirror_gpio(inputline: u32, outputline: u32) -> gpio_cdev::errors::Result<()> {
let mut chip = Chip::new("/dev/gpiochip0")?;
let input = chip.get_line(inputline)?;
let output = chip.get_line(outputline)?;
let output_handle = output.request(LineRequestFlags::OUTPUT, 0, "mirror-gpio")?;
for event in input.events(
LineRequestFlags::INPUT,
EventRequestFlags::BOTH_EDGES,
"mirror-gpio",
)? {
let evt = event?;
println!("{:?}", evt);
match evt.event_type() {
EventType::RisingEdge => {
output_handle.set_value(1)?;
}
EventType::FallingEdge => {
output_handle.set_value(0)?;
}
}
}

Ok(())
}
```

## Sysfs GPIO vs GPIO Character Device

Compared to the sysfs gpio interface (as made available by the sysfs_gpio crate)
Expand Down Expand Up @@ -98,3 +170,28 @@ using the queueing with timing information captured in the kernel. Previously,
would need to quickly handle the event notification, make another system call
to the value file to see the state, etc. which had far too many variables involved
to be considered reliable.

## License

Licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

## Code of Conduct

Contribution to this crate is organized under the terms of the [Rust Code of
Conduct][CoC], the maintainer of this crate, the [Embedded Linux Team][team], promises
to intervene to uphold that code of conduct.

[CoC]: CODE_OF_CONDUCT.md
[team]: https://github.com/rust-embedded/wg#the-embedded-linux-team
12 changes: 6 additions & 6 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ pub struct gpioevent_data {
pub id: libc::uint32_t,
}

ioctl!(read gpio_get_chipinfo_ioctl with 0xB4, 0x01; gpiochip_info);
ioctl!(readwrite gpio_get_lineinfo_ioctl with 0xB4, 0x02; gpioline_info);
ioctl!(readwrite gpio_get_linehandle_ioctl with 0xB4, 0x03; gpiohandle_request);
ioctl!(readwrite gpio_get_lineevent_ioctl with 0xB4, 0x04; gpioevent_request);
ioctl_read!(gpio_get_chipinfo_ioctl, 0xB4, 0x01, gpiochip_info);
ioctl_readwrite!(gpio_get_lineinfo_ioctl, 0xB4, 0x02, gpioline_info);
ioctl_readwrite!(gpio_get_linehandle_ioctl, 0xB4, 0x03, gpiohandle_request);
ioctl_readwrite!(gpio_get_lineevent_ioctl, 0xB4, 0x04, gpioevent_request);

ioctl!(readwrite gpiohandle_get_line_values_ioctl with 0xB4, 0x08; gpiohandle_data);
ioctl!(readwrite gpiohandle_set_line_values_ioctl with 0xB4, 0x09; gpiohandle_data);
ioctl_readwrite!(gpiohandle_get_line_values_ioctl, 0xB4, 0x08, gpiohandle_data);
ioctl_readwrite!(gpiohandle_set_line_values_ioctl, 0xB4, 0x09, gpiohandle_data);