Skip to content
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

Represent line levels as a bool #5

Open
fpagliughi opened this issue Sep 14, 2018 · 4 comments
Open

Represent line levels as a bool #5

fpagliughi opened this issue Sep 14, 2018 · 4 comments

Comments

@fpagliughi
Copy link
Contributor

I know the char driver(s) expose bits as u8 values, but it might be easier to manipulate the values as booleans. Should we consider:

impl LineHandle {
    pub fn get_value(&self) -> Result<bool> { ... }
    pub fn set_value(&self, value: bool) -> Result<()> { ... }
    ...
@posborne
Copy link
Member

The actual value (0, non-zero) is modeling "active" state for the line which can be inverted in the kernel via the active-low setting. I could see is_active and set_active as an API that modeled what this is in the kernel being something that make sense. This could be in addition to the value or as a full replacement.

@fpagliughi
Copy link
Contributor Author

Whenever I wrap a C library or API in a language that has a bool type (C++, Rust, etc), I usually prefer to convert the C integer boolean (0, non-zero) to a bool to be a little more explicit about the possible values, and remove ambiguities. But it's no big deal either way.

@rubberduck203
Copy link

Possibly relevant. I've been working on a reusable abstraction for logic levels.
The idea is to abstract over whether an I/O line is active high or low and only expose whether or not it is currently asserted.

https://github.com/rubberduck203/switch-hal

@ryankurte
Copy link

i can't find it right now but i believe there is discussion about introducing a LogicLevel (or similar) enum along with some more gpio accessors somewhere amongst our issues and PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants