nrf-hal icon indicating copy to clipboard operation
nrf-hal copied to clipboard

Implement `InputPin` regardless of mode

Open jonas-schievink opened this issue 3 years ago • 4 comments

This should resolve https://github.com/nrf-rs/nrf-hal/issues/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 avatar Jul 20 '21 16:07 jonas-schievink

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:

https://github.com/nrf-rs/nrf-hal/blob/19df1633e60bfd5d882a350a3fffd47592b517c6/nrf-hal-common/src/gpio.rs#L205

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

jonas-schievink avatar Jul 21 '21 13:07 jonas-schievink

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.

Dirbaio avatar Sep 10 '21 20:09 Dirbaio

Is IoPin https://github.com/rust-embedded/embedded-hal/pull/269 relevant?

https://github.com/rust-embedded/embedded-hal/releases/tag/v1.0.0-alpha.5

oddstr13 avatar Nov 23 '21 09:11 oddstr13

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) .

eflukx avatar Jun 22 '22 09:06 eflukx

Here is my attempt to implement this: https://github.com/nrf-rs/nrf-hal/pull/401

Finomnis avatar Sep 20 '22 23:09 Finomnis

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

Finomnis avatar Sep 28 '22 12:09 Finomnis