Skip to content

Commit

Permalink
Merge branch 'master' into mio-example
Browse files Browse the repository at this point in the history
  • Loading branch information
lthiery committed Feb 23, 2019
2 parents 637d144 + 409bab1 commit 931ec65
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
# Generated by Cargo
Cargo.lock
/target/

# Intellij IDEA
.idea
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: rust
sudo: false
rust:
- 1.21.0
- 1.26.0
- stable
- beta
- nightly
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [master] - Unreleased

### Changed

- Migrated to 'tokio' crate.

## [0.5.3] - 2018-04-19

### Fixed
Expand Down
64 changes: 64 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ readme = "README.md"

[features]
mio-evented = ["mio"]
tokio = ["futures", "tokio-core", "mio-evented"]
use_tokio = ["futures", "tokio", "mio-evented"]

[dependencies]
futures = { version = "0.1", optional = true }
nix = "0.10.0"
mio = { version = "0.6", optional = true }
tokio-core = { version = "0.1", optional = true }
tokio = { version = "0.1", optional = true }
51 changes: 29 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ You might want to also check out the
convenient way to associate names with pins and export them as part of system
boot. That project uses this library.

Install/Use
-----------
## Install/Use

To use `sysfs_gpio`, first add this to your `Cargo.toml`:

Expand All @@ -37,8 +36,7 @@ Then, add this to your crate root:
extern crate sysfs_gpio;
```

Example/API
-----------
## Example/API

Blinking an LED:

Expand Down Expand Up @@ -70,8 +68,7 @@ More Examples:
- [Poll several pins asynchronously with Tokio](examples/tokio.rs)
- [gpio-utils Project (uses most features)](https://github.com/rust-embedded/gpio-utils)

Features
--------
## Features

The following features are planned for the library:

Expand All @@ -83,19 +80,17 @@ The following features are planned for the library:
- [ ] Support for configuring whether a pin is active low/high
- [x] Support for configuring interrupts on GPIO
- [x] Support for polling on GPIO with configured interrupt
- [x] Support for asynchronous polling using `mio` or `tokio-core` (requires
enabling the `mio-evented` or `tokio` crate features, respectively)
- [x] Support for asynchronous polling using `mio` or `tokio` (requires
enabling the `mio-evented` or `use_tokio` crate features, respectively)

Cross Compiling
---------------
## Cross Compiling

Most likely, the machine you are running on is not your development
machine (although it could be). In those cases, you will need to
cross-compile. The [rust-cross guide](https://github.com/japaric/rust-cross)
provides excellent, detailed instructions for cross-compiling.

Running the Example
-------------------
## Running the Example

Cross-compiling can be done by specifying an appropriate target. You
can then move that to your device by whatever means and run it.
Expand All @@ -105,15 +100,27 @@ $ cargo build --target=arm-unknown-linux-gnueabihf --example blinky
$ scp target/arm-unknown-linux-gnueabihf/debug/examples/blinky ...
```

License
-------
## License

```
Copyright (c) 2015, Paul Osborne <[email protected]>
Licensed under either of

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
http://www.apache.org/license/LICENSE-2.0> or the MIT license
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
option. This file may not be copied, modified, or distributed
except according to those terms.
```
- 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
62 changes: 31 additions & 31 deletions examples/tokio.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
#[cfg(feature = "tokio")]
#[cfg(feature = "use_tokio")]
extern crate futures;
#[cfg(feature = "tokio")]
#[cfg(feature = "use_tokio")]
extern crate sysfs_gpio;
#[cfg(feature = "tokio")]
extern crate tokio_core;
#[cfg(feature = "use_tokio")]
extern crate tokio;

#[cfg(feature = "tokio")]
use futures::{Future, Stream};
#[cfg(feature = "tokio")]
use sysfs_gpio::{Direction, Edge, Pin};
#[cfg(feature = "tokio")]
#[cfg(feature = "use_tokio")]
use std::env;
#[cfg(feature = "tokio")]
use tokio_core::reactor::Core;

#[cfg(feature = "tokio")]
#[cfg(feature = "use_tokio")]
use futures::{Future, lazy, Stream};

#[cfg(feature = "use_tokio")]
use sysfs_gpio::{Direction, Edge, Pin};

#[cfg(feature = "use_tokio")]
fn stream(pin_nums: Vec<u64>) -> sysfs_gpio::Result<()> {
// NOTE: this currently runs forever and as such if
// the app is stopped (Ctrl-C), no cleanup will happen
// and the GPIO will be left exported. Not much
// can be done about this as Rust signal handling isn't
// really present at the moment. Revisit later.
let pins: Vec<_> = pin_nums.iter().map(|&p| (p, Pin::new(p))).collect();
let mut l = Core::new()?;
let handle = l.handle();
for &(i, ref pin) in pins.iter() {
pin.export()?;
pin.set_direction(Direction::In)?;
pin.set_edge(Edge::BothEdges)?;
handle.spawn(pin.get_value_stream(&handle)?
.for_each(move |val| {
println!("Pin {} changed value to {}", i, val);
Ok(())
})
.map_err(|_| ()));
}
// Wait forever for events
loop {
l.turn(None)
}
let task = lazy(move || {
for &(i, ref pin) in pins.iter() {
pin.export().unwrap();
pin.set_direction(Direction::In).unwrap();
pin.set_edge(Edge::BothEdges).unwrap();
tokio::spawn(pin.get_value_stream().unwrap()
.for_each(move |val| {
println!("Pin {} changed value to {}", i, val);
Ok(())
})
.map_err(|_| ()));
}
Ok(())
});
tokio::run(task);

Ok(())
}

#[cfg(feature = "tokio")]
#[cfg(feature = "use_tokio")]
fn main() {
let pins: Vec<u64> = env::args()
.skip(1)
Expand All @@ -54,7 +54,7 @@ fn main() {
}
}

#[cfg(not(feature = "tokio"))]
#[cfg(not(feature = "use_tokio"))]
fn main() {
println!("This example requires the `tokio` feature to be enabled.");
}
Loading

0 comments on commit 931ec65

Please sign in to comment.