Skip to content

Represent line levels as a bool #5

@fpagliughi

Description

@fpagliughi
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<()> { ... }
    ...

Activity

posborne

posborne commented on Sep 26, 2018

@posborne
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

fpagliughi commented on Sep 30, 2018

@fpagliughi
ContributorAuthor

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

rubberduck203 commented on Aug 18, 2020

@rubberduck203

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

ryankurte commented on Aug 22, 2020

@ryankurte

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @posborne@ryankurte@rubberduck203@fpagliughi

        Issue actions

          Represent line levels as a bool · Issue #5 · rust-embedded/gpio-cdev