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

Implement InputPin regardless of mode #340

Closed
wants to merge 1 commit into from
Closed

Implement InputPin regardless of mode #340

wants to merge 1 commit into from

Conversation

jonas-schievink
Copy link
Contributor

This should resolve #339

I think this is fine, since you can always read any pin regardless of configuration (even for disconnected pins, their value will just be floating).

@jonas-schievink
Copy link
Contributor Author

Ah, it seems like this doesn't work without also setting cnf.input().connected() for all output modes. Apparently we already do this for push-pull outputs for some reason:

w.input().connect(); // AJM - hack for SPI

Not sure why though? And what are the consequences of doing this anyways? Higher power usage?

@Dirbaio
Copy link
Member

Dirbaio commented Sep 10, 2021

Not sure why though? And what are the consequences of doing this anyways? Higher power usage?

gpios have an "input buffer" you can connect/disconnect. If you don't connect it, you read garbage. You can enable output and input at the same time. For PushPull outputs you just read what you write. For OpenDrain you can drive the line low or you can listen whether the other device drives it down.

Enabling input when not needed wastes power. The Product Specification doesn't say how much though :( . Probably very little.

I think always implementing InputPin is a bit of a footgun though. Too easy to configure a PushPull output and accidentally pass it to a driver that requires InputPin. IMO it should be something the user explicitly opts in. Embassy has a FlexPin for this, which allows using input+output at the same time.

@oddstr13
Copy link
Contributor

@eflukx
Copy link

eflukx commented Jun 22, 2022

Is IoPin rust-embedded/embedded-hal#269 relevant?

Seems reasonable if that's the path the embedded-wg goes, nrf-hal follows along?

Currently I'm in need of this kind of pin handling (in my case tri-stating GPIO pins, not using them as inputs per se), for handling charlieplexed LEDs and a device with a bit too much leakage on its IO-pins (i.e. floating the pins lowers idle/quiescent current draw) .

@Finomnis
Copy link
Contributor

Finomnis commented Sep 20, 2022

Here is my attempt to implement this: #401

@Finomnis
Copy link
Contributor

@jonas-schievink Can probably be closed; was superseded by #401

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

Successfully merging this pull request may close these issues.

Can't use with onewire due to InputPin + OutputPin requirement
5 participants