Skip to content
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

Output port - take 2 #436

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions embedded-hal/src/digital.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,30 @@ impl<T: InputPin> InputPin for &T {
T::is_low(self)
}
}

/// A digital output "port"
///
/// `N` is number of pins in "port"
///
/// **NOTE** The "port" doesn't necessarily has to match a hardware GPIO port;
/// it could for instance be a 4-bit ports made up of non contiguous pins, say
/// `PA0`, `PA3`, `PA10` and `PA13`.
pub trait OutputPort<const N: usize>: ErrorType {
/// Outputs `N` least significant bits of `word` on the port pins
///
/// # Contract
///
/// The state of all the port pins will change atomically ("at the same time"). This usually
/// means that state of all the pins will be changed in a single register operation.
fn write(&mut self, word: u16) -> Result<(), Self::Error>;

/// Set all pins to `PinState::High`
fn all_high(&mut self) -> Result<(), Self::Error> {
self.write(!0)
}

/// Reset all pins to `PinState::Low`
fn all_low(&mut self) -> Result<(), Self::Error> {
self.write(0)
}
}