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

TriStatePin proposal #157

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/digital/v2.rs
Expand Up @@ -136,3 +136,34 @@ pub trait InputPin {
/// Is the input pin low?
fn is_low(&self) -> Result<bool, Self::Error>;
}

/// The states of a tri-state pin
///
/// *This type is available if embedded-hal is built with the `"unproven"` feature.*
#[cfg(feature = "unproven")]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PinState {
/// Pin state low
Low,
/// Pin state high
High,
/// The pin is set to high impedance mode
Floating,
}

/// A tri-state (low, high, floating) pin
///
/// *This trait is available if embedded-hal is built with the `"unproven"` feature.*
#[cfg(feature = "unproven")]
pub trait TriStatePin {
/// Error type
type Error;

/// Changes the state of the pin
fn set(&mut self, state: PinState) -> Result<(), Self::Error>;

/// Gets the state of the pin.
///
/// *NOTE* this does *not* read the electrical state of the pin
fn state(&self) -> Result<PinState, Self::Error>;
}