-
Notifications
You must be signed in to change notification settings - Fork 215
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
digital::OutputPin providing toggle method #68
Comments
Please see my last comment on #29 |
Do you mean #29 (comment) ? |
@DoumanAsh, yes, if there will be methods to read back the previously set state of the OutputPin, then a toggle() method would fit there nicely (even with a default implementation). |
I'm not sure I understand you... Should I hold on this idea for now? 😅 |
If a microcontroller hardware does not support to read back the values you have set earlier on an output pin, you may not have is_high/is_low and toggle functions on the OutputPin trait.
OutputPin then usable on any hardware, StatefulOutputPin usable only where it has HW support. |
I see, that's nice idea and if it is already on someone plan then there is no need for me to put toggle method, if we're going to split OutputPin like that. |
@tib888 Storing the state is a not so great idea because it might end up being wrong. Also there're MCUs which can toggle a pin in hardware without knowledge what state it is in, e.g. my arch enemy ATSAMD20. |
@therealprof Correct me if I'm wrong, but I don't think tib's suggesting storing software state, but rather having
That's a good point, and I don't think the current proposal would allow this to be easily leveraged on a platform which both allows blind toggling and disallows output readback. Do such platforms exist? My gut feeling is that this is OK. Your particular example (ATSAMD20) would fit in well, since it seems to have output readback functionality -- so it's GPIO pins would have |
@austinglaser I can also see the problem the other way around. There're chips which don't allow you to read the value back in output mode and others which may allow to read back the registers but not the actual state. I think the only safe way to implement all of this is to have separate traits for all different possibilities so if a MCU doesn't support a certain variant the compiler will throw an error. A driver can then simply use a composition of traits to make sure the HAL is actually able to provide all required capabilities. I was also thinking of writing a separate |
I agree. I like the idea of structuring it so there's some hierarchy of supertraits -- such as the way the proposed Would your proposed solution separate the |
I would not necessarily create "supertraits". I'd just have seperate traits for independent features so you can use trait bounds to say something like:
or:
(and come up with a clever name to distinguish between hardware and register state).
Yes. |
I suppose then you could have an opt-in default Additionally, I like that this keeps the IO traits very focused -- I think that'll pay dividends in the future as more esoteric pin modes (open drain being my personal favorite example) get implemented. I'm sold! |
As mentioned I was thinking of doing a |
Closing as it is now part of 0.2 |
68: Prepare 0.4.0-alpha.1 release r=ryankurte a=eldruin Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
I'm not sure of future for the trait, but I found myself writing own convenience like
toggle
which is basicallyI feel like this could be provided method for the trait, unless there is plans for
OutputPin
to have more than two variantsThe text was updated successfully, but these errors were encountered: