You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 15, 2021. It is now read-only.
This means its members claim to implement the embedded_hal::digital::InputPin trait, and so the compiler will let you call is_high() and is_low() on them.
But split() doesn't do anything to enable the input buffer for each pin (which is disabled by default), so these calls won't return meaningful information until you explicitly call one of the .into_xxx_input() methods.
In general the typestate system for these PIN types means the compiler prevents you making mistakes like this, so I think it would be better to either
have split() reconfigure all the pins as floating input; or
have a third mode for the PIN types which doesn't implement either input or output traits, and have Parts use those types.
The second change isn't fully backwards compatible, but if it makes a program stop compiling it's probably revealing a bug.
There's also a weakness that nothing stops you arbitrarily configuring the GPIO pins before calling split(), leading to another way for the typestates to get out of sync with the hardware. Either of the changes above would remove that weakness too.
The text was updated successfully, but these errors were encountered:
I took the second approach while experimenting with alternative typestate implementations in embrio-nrf51 (which was strongly inspired by nrf51-hal's implementation). It definitely seems like the correct solution to me.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
GPIO.split()
returns aParts
struct, whose members have types likePIN0<Input<Floating>>
:https://docs.rs/nrf51-hal/0.6.2/nrf51_hal/gpio/gpio/struct.Parts.html
This means its members claim to implement the
embedded_hal::digital::InputPin
trait, and so the compiler will let you callis_high()
andis_low()
on them.But
split()
doesn't do anything to enable the input buffer for each pin (which is disabled by default), so these calls won't return meaningful information until you explicitly call one of the.into_xxx_input()
methods.In general the typestate system for these PIN types means the compiler prevents you making mistakes like this, so I think it would be better to either
split()
reconfigure all the pins as floating input; orParts
use those types.The second change isn't fully backwards compatible, but if it makes a program stop compiling it's probably revealing a bug.
There's also a weakness that nothing stops you arbitrarily configuring the GPIO pins before calling
split()
, leading to another way for the typestates to get out of sync with the hardware. Either of the changes above would remove that weakness too.The text was updated successfully, but these errors were encountered: