-
Notifications
You must be signed in to change notification settings - Fork 249
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
Allow reading the input state of pins in any function mode #689
Comments
I see one trade-off to consider: While we technically are able to implement If all pins impl Perhaps we shouldn't just impl |
The wrapper could be accessible via an
|
That’d be fine, and makes sense to me. Keeps the type safety, but still allows safely reading the state when necessary. |
I just noticed that we already have If we still want the |
For some reasons I cannot point yet, implementing On the other hand, the datasheet explicitly says:
So I'm not strongly against it. Alternatively, one can use |
I share that feeling. I think it's because we use the type-system to reach several goals, and some of those have divergent requirements:
In this case, implementing In my opinion, there are two valid approaches regarding
I don't see a good reasoning for the current middle ground. I prefer the first option, with the addition of something like |
asInput() does seem like it fits into the Rust type system a bit more. Generally the explicit modes do feel a lot better, and help the writer ensure they're actually doing the correct thing. It just makes sense to have a decently safe escape hatch, because reading an output is perfectly valid behavior, and the current solution of either a raw read or into_unchecked is much worse and much more error prone. |
On the actual chip, all input pins are always wired to the SIO block for inputs, no matter what mode the device is in. This means that no matter the function selected, reading the input state would be valid. It would be very nice if the InputPin trait could be implemented for all function types, as this doesn't break any of rust's safety rules.
I actually ran into a case where I needed to work around this. I was using a PWM Input, and needed to know when the falling edge was triggered. However, for the pin to be readable by PWM, it has to be in FunctionPwm mode, which doesn't allow reading the input. I actually had to use into_unchecked to turn the pin back into an input just so I could read it.
The text was updated successfully, but these errors were encountered: