-
Notifications
You must be signed in to change notification settings - Fork 213
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
TriStatePin proposal #157
base: master
Are you sure you want to change the base?
TriStatePin proposal #157
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thejpster (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This seems straightforward enough, but I wonder if it needs an RFC before we go to unproven implementation. @jamesmunns can you stick this on the agenda for Tuesday? |
Lol. I'm an idiot. There is an RFC! You even linked to it... Still, I'd like to discuss this on Tuesday as I'm not quite sure of the process for merging. |
So, what is the status on this? Have there been any discussions? It would be great to have this on master. |
we've just landed (i feel like the type-state approach is possibly less ergonomic than that proposed here, but it should be pretty easy to implement a more convenient wrapper over it with an API like this) cc. @eldruin |
Hello- Maybe I'm missing something, but I think I've bumped into a usecase that requires this or something like it. Threw together a quick example: enum Things {
Thing1,
Thing2,
Thing3,
}
let there_is_no_tri = pins.gpio13.into_floating_input();
let thing_closure = |thing: Things| -> () {
match thing {
Things::Thing1 => { there_is_no_tri.into_floating_input(); () }
Things::Thing2 => there_is_no_tri.into_push_pull_output().set_low().unwrap(),
_ => unimplemented!(),
};
};
thing_closure(Things::Thing1);
thing_closure(Things::Thing2); This code produces an error:
Since Just as an example of something that DOES currently work: let mut boring_pin = pins.gpio13.into_push_pull_output();
let mut thing_closure = |thing: Things| -> () {
match thing {
Things::Thing1 => boring_pin.set_high().unwrap(),
Things::Thing2 => boring_pin.set_low().unwrap(),
_ => unimplemented!(),
};
};
thing_closure(Things::Thing1);
thing_closure(Things::Thing2); With this change, I'm pretty sure I could do this, and it would work fine. let mut tristate_pin = pins.gpio13.into_tristate_output();
let mut thing_closure = |thing: Things| -> () {
match thing {
Things::Thing1 => boring_pin.set( PinState::Floating ).unwrap(),
Things::Thing2 => boring_pin.set( PinState::Low).unwrap(),
_ => unimplemented!(),
};
};
thing_closure(Things::Thing1);
thing_closure(Things::Thing2); One thing to note is that PinState already exists now because of IoPin, so you'd have to use some other enum (and perhaps have |
I have simply added the enum variant as per the proposal in #31, since it seemed to be the most popular.
I am in the middle of implementing a charlieplexing crate for use in a project of mine (custom board using an stm32l051) and would therefore need this trait.
To try it out I implemented the trait for the stm32l0xx-hal in a branch together with an example application, and got the charlieplexing working as a proof of concept on my custom board driving 30 leds.
The charlieplexing crate is far from done, but I think the trait is going to work great, so to get the wheels spinning and allow for more opinions, I thought I might as well open a pull request right away...