Skip to content

Commit e4cb12c

Browse files
committed
Add examples, license, code of conduct to readme
The CoC assumes this will be rolled into rust-embedded which should come in the near future. Signed-off-by: Paul Osborne <[email protected]>
1 parent 866b645 commit e4cb12c

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

CODE_OF_CONDUCT.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# The Rust Code of Conduct
2+
3+
## Conduct
4+
5+
**Contact**: [Embedded Linux Team][team]
6+
7+
* 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.
8+
* On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and welcoming environment for all.
9+
* Please be kind and courteous. There's no need to be mean or rude.
10+
* 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.
11+
* 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.
12+
* 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.
13+
* 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.
14+
* Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome.
15+
16+
## Moderation
17+
18+
These are the policies for upholding our community's standards of conduct.
19+
20+
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.)
21+
2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed.
22+
3. Moderators will first respond to such remarks with a warning.
23+
4. If the warning is unheeded, the user will be "kicked," i.e., kicked out of the communication channel to cool off.
24+
5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded.
25+
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.
26+
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.
27+
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.
28+
29+
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.
30+
31+
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.
32+
33+
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).
34+
35+
*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/).*
36+
37+
[team]: https://github.com/rust-embedded/wg#the-embedded-linux-team

README.md

+97
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,78 @@ stabilized with Linux v4.4, deprecates the legacy sysfs interface to GPIOs that
1212
planned to be removed from the upstream kernel after
1313
year 2020 (which is coming up quickly).
1414

15+
Use of this API is encouraged over the sysfs API used by this crate's
16+
predecessor [sysfs_gpio](https://crates.io/crates/sysfs_gpio) if you don't need
17+
to target older kernels. For more information on differences see [Sysfs GPIO vs
18+
GPIO Character Device](#sysfs-gpio-vs-gpio-character-device).
19+
20+
## Installation
21+
22+
Add the following to your Cargo.toml
23+
24+
```
25+
[dependencies]
26+
gpio-cdev = "0.1"
27+
```
28+
29+
## Examples
30+
31+
There are several additional examples available in the [examples
32+
directory](https://github.com/posborne/rust-gpio-cdev/tree/master/examples).
33+
34+
### Read State
35+
36+
```rust
37+
use gpio_cdev::{Chip, LineRequestFlags};
38+
39+
// Read the state of GPIO4 on a raspberry pi. /dev/gpiochip0
40+
// maps to the driver for the SoC (builtin) GPIO controller.
41+
let mut chip = Chip::new("/dev/gpiochip0")?;
42+
let handle = chip
43+
.get_line(4)?
44+
.request(LineRequestFlags::INPUT, 0, "read-input")?;
45+
for _ in 1..4 {
46+
println!("Value: {:?}", handle.get_value()?);
47+
}
48+
```
49+
50+
### Mirror State (Read/Write)
51+
52+
```rust
53+
use gpio_cdev::{Chip, LineRequestFlags, EventRequestFlags, EventType};
54+
55+
// Lines are offset within gpiochip0; see docs for more info on chips/lines
56+
//
57+
// This function will synchronously follow the state of one line
58+
// on gpiochip0 and mirror its state on another line. With this you
59+
// could, for instance, control the state of an LED with a button
60+
// if hooked up to the right pins on a raspberry pi.
61+
fn mirror_gpio(inputline: u32, outputline: u32) -> gpio_cdev::errors::Result<()> {
62+
let mut chip = Chip::new("/dev/gpiochip0")?;
63+
let input = chip.get_line(inputline)?;
64+
let output = chip.get_line(outputline)?;
65+
let output_handle = output.request(LineRequestFlags::OUTPUT, 0, "mirror-gpio")?;
66+
for event in input.events(
67+
LineRequestFlags::INPUT,
68+
EventRequestFlags::BOTH_EDGES,
69+
"mirror-gpio",
70+
)? {
71+
let evt = event?;
72+
println!("{:?}", evt);
73+
match evt.event_type() {
74+
EventType::RisingEdge => {
75+
output_handle.set_value(1)?;
76+
}
77+
EventType::FallingEdge => {
78+
output_handle.set_value(0)?;
79+
}
80+
}
81+
}
82+
83+
Ok(())
84+
}
85+
```
86+
1587
## Sysfs GPIO vs GPIO Character Device
1688

1789
Compared to the sysfs gpio interface (as made available by the sysfs_gpio crate)
@@ -98,3 +170,28 @@ using the queueing with timing information captured in the kernel. Previously,
98170
would need to quickly handle the event notification, make another system call
99171
to the value file to see the state, etc. which had far too many variables involved
100172
to be considered reliable.
173+
174+
## License
175+
176+
Licensed under either of
177+
178+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
179+
http://www.apache.org/licenses/LICENSE-2.0)
180+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
181+
182+
at your option.
183+
184+
### Contribution
185+
186+
Unless you explicitly state otherwise, any contribution intentionally submitted
187+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
188+
dual licensed as above, without any additional terms or conditions.
189+
190+
## Code of Conduct
191+
192+
Contribution to this crate is organized under the terms of the [Rust Code of
193+
Conduct][CoC], the maintainer of this crate, the [Embedded Linux Team][team], promises
194+
to intervene to uphold that code of conduct.
195+
196+
[CoC]: CODE_OF_CONDUCT.md
197+
[team]: https://github.com/rust-embedded/wg#the-embedded-linux-team

0 commit comments

Comments
 (0)