Skip to content

GPIO: Add support for tri-state mode #24

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

Open
hannobraun opened this issue Sep 17, 2018 · 2 comments
Open

GPIO: Add support for tri-state mode #24

hannobraun opened this issue Sep 17, 2018 · 2 comments

Comments

@hannobraun
Copy link
Contributor

Some use cases require switching a pin between output and floating mode on the fly. This is very inconvenient with the current API. The DWM1001 board support crate has an example that demonstrates this.

I believe the solution for this is to add a tri-state mode that implements the following trait:

pub trait TriStatePin {
    fn set_high(&mut self);
    fn set_low(&mut self);
    fn set_floating(&mut self);
}

Such an abstraction has been proposed before.

If we decide to implement this, we should submit the trait I suggested above to embedded-hal.

@Yatekii
Copy link
Contributor

Yatekii commented Feb 6, 2019

I see the use of this and would welcome an implementation.

Atm those functions do not alter the Pin type ofc, so forgive me the dumb question, but how can I, after, let's say a ::set_floating() of a Pin<Output> access a let's say ::is_low()? Also the generic type of that pin would not represent the actual pin state anymore after such a proposed TriStatePin operation if I understand everything right.

So do you think that is of no concern or do I missunderstand you?

If I understand everything correctly we maybe should rather return a converted Pin from the TriStatePin methods and make them consume self?

@hannobraun
Copy link
Contributor Author

I think we'd need a separate tri-state mode that is distinct from input or output mode. So you'd call into_tri_state_pin, which gets you a Pin<TriState>, which would then make the methods above available.

The lack of compile-time state tracking within the tri-state mode is intended, and indeed, is the whole point of why I suggested this. See the example I linked for an example of the compile-time state tracking getting into the way.

The methods I propose only cover the use case from my example, which doesn't require is_low/is_high. A complete implementation would include those within the tri-state mode.

hargoniX pushed a commit to hargoniX/nrf-hal that referenced this issue Jul 28, 2021
 Update examples/led_rtfm.rs to use RTFM v0.5
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

2 participants