From 939b42b31efb23cf1d3cf9e9f0899f214b93bda0 Mon Sep 17 00:00:00 2001 From: Jonas Date: Sun, 27 Oct 2019 09:09:50 +0100 Subject: [PATCH 1/2] Add a trait for interfacing with an output pin with high-z functionality (tri-state) --- src/digital/v2.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/digital/v2.rs b/src/digital/v2.rs index 748807225..ade99e5e5 100644 --- a/src/digital/v2.rs +++ b/src/digital/v2.rs @@ -136,3 +136,34 @@ pub trait InputPin { /// Is the input pin low? fn is_low(&self) -> Result; } + +/// 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, 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; +} From 949d1c8428b9d5799247d253e72c5333311e521c Mon Sep 17 00:00:00 2001 From: Jonas Date: Sun, 27 Oct 2019 10:12:49 +0100 Subject: [PATCH 2/2] Derive debug for PinState enum --- src/digital/v2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/digital/v2.rs b/src/digital/v2.rs index ade99e5e5..c06ce4ef3 100644 --- a/src/digital/v2.rs +++ b/src/digital/v2.rs @@ -141,7 +141,7 @@ pub trait InputPin { /// /// *This type is available if embedded-hal is built with the `"unproven"` feature.* #[cfg(feature = "unproven")] -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum PinState { /// Pin state low Low,