-
Notifications
You must be signed in to change notification settings - Fork 181
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 Pull Without Output Requirement #345
Conversation
Being able to pull doesn't necessarily require being able to output.
This is not a correct solution, as it would only allow it to set if its in the state InputPin. We need a solution where both are possible |
Hmm darn. It looks like esp-hal just has separate function implementations for this inside the pin. Honestly I much prefer the approach they've taken with pins as drivers. |
Are there any pins under the "Pin" trait that aren't GPIO capable? |
If you ask to use it as a pullup / pulldown indicator, not every pin has pullup, pulldowns, but pin is generally used as a marker trait for all gpio's |
Playing devil's advocate, but wouldn't the current logic of "all pins capable of input or output" be equally as capable of including pins without pull capabilities? This change is valuable for the reasons listed in the first message as well as for making the downgrade_input() and downgrade_output() result types useful. I'm not really sure what the point of them is otherwise. That is to say, the type AnyInputPin, isn't something really worth using currently since functions that would be typically used against that type (like set_pull) don't work against it presently. I changed the code to require the trait of "Pin" and at least in my code, am experiencing the intended functionality with no ill-effects. |
Do you have a concrete problem at hand which does not work with the current code? If the other MCUs are not like that, we should revisit though. As for your relaxed
... which has the problem I outlined above though - you can call set pullup/pulldown on pins that don't have these. Why are you just not using |
Yeah, my issue is that I have a function which needs to accept any and only "inputs" as a parameter, and I am trying to change the pull of this pin as part of the function. If someone were to inadvertently pass this function an output, things would break. I'd like to reiterate that I don't understand the purpose of even having the AnyInputPin trait if functions which are supported by input pins cannot be run against pins which have this trait. Additionally, while I understand and agree that it is a problem that set_pull can be called against pins which cannot internally pull, this is already a bug that exists in the current unchanged code, for example, against gpio1 in your link. My change would potentially expand that existing peoblem to include input only non pulling pins, but does at least allow AnyInputPin to behave closer to expectations. To recap, there are two issues:
|
I do not understand your reasoning. On one hand, you want the type to enforce that the pin is input only, but on the other hand, you seem to be fine that - with your change - folks can call pullup/pulldown functions on pins that don't really have that functionality. I think we would be much better off by introducing two additional traits:
Also, you can use I think at the bottom of all of this is you trying to write your function as: fn my_f(pin: AnyInputPin) ... and somehow have ... where you probably want fn my_f(pin: impl InputPin + PullUpDown) // The new trait
Nit-picking? gpio1 is missing from the above pinout, but seems to be listed as a regular, all-capable pin here. Hence I've included it as a "normal" pin. If it is not, the easiest thing is to special-case it. |
This would be acceptable. |
If you want it sooner rather than later, you can re-arrange your PR in this direction then. |
It seems I could possibly avoid this as well by requiring pindrivers as the function inputs rather than pins themselves. Like below:
Would this approach be the preferred way to distinguish between Inputs and Outputs for the sake of functions? Unfortunately since I am running embassy which requires |
Of course. Or better yet - and with generics - It is another topic that
See above. It boils down to whether you want the peripheral, or the driver on top. e-hal BTW abstracts "drivers", not "peripherals".
Just use |
I appreciate the insight you put into this reply, I'll more carefully plan the approach here. In this case, should we close this PR? Anecdotally there may still be a purpose for this, but it would likely be a pretty niche-case right? |
Yeah. See, we used to have But not the most important thing in the world; definitely niche. I'm fine either way. Perhaps you can try to experiment a bit in your code, see how it goes and only then decide if you want to resurrect something like this. |
I'll close this for now and rework my approach. It'll be here in the closed PRs/search if someone else gets to it before I do, either way, this code is getting tossed and the trait would need to be added. Thanks! |
Being able to pull up or down doesn't necessarily require being able to output. This change allows better migration from other hal projects such as esp-hal where this kind of requirement is similar. While this does relax the gate on what kinds of pins can pull, it allows developers to write stricter functions when passing pins around.