-
Notifications
You must be signed in to change notification settings - Fork 202
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
Move reading functions from OutputPin trait to StatefulOutputPin #72
Changes from 2 commits
97fac76
3f61ef2
ac965a3
6549d73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,32 @@ | |
|
||
/// Single digital output pin | ||
pub trait OutputPin { | ||
/// Is the output pin high? | ||
fn is_high(&self) -> bool; | ||
|
||
/// Is the output pin low? | ||
fn is_low(&self) -> bool; | ||
|
||
/// Sets the pin low | ||
fn set_low(&mut self); | ||
|
||
/// Sets the pin high | ||
fn set_high(&mut self); | ||
} | ||
|
||
/// Output pin that can read its output state | ||
#[cfg(feature = "unproven")] | ||
trait StatefulOutputPin: OutputPin { | ||
/// Is the pin set to high? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A pin could also be logically floating so either it needs to be made clear that a tri-stated pin may not implement this trait or that the implicit assumption |
||
fn is_set_high(&self) -> bool; | ||
|
||
/// Is the pin set to low? | ||
fn is_set_low(&self) -> bool; | ||
|
||
/// Toggle pin output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry if I am late to the party. Can you override a method in a trait? On some cores toggle is exposed as a separate register / no read state is required. I'd propose having the toggle as a separate trait that you can implement on StatefulOutputPin if toggle function is not available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed in #31 (et al) I also think that different capabilities should be modelled in different composable (and mode dependent) traits instead of being munged together into a few traits that do a lot of things at once. Something like I only agreed to moving it out of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable. I'll remove it in favour of adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fn toggle(&mut self) { | ||
if self.is_set_low() { | ||
self.set_high(); | ||
} else { | ||
self.set_low(); | ||
} | ||
} | ||
} | ||
|
||
/// Single digital input pin | ||
#[cfg(feature = "unproven")] | ||
pub trait InputPin { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I've mentioned before there's a distinction between a logical state and an electrical state. It should be made clear that this is meant to represent the logical (or register) state of a pin and not the electrical state.