From f525b1d49d3021f8f70c093a3abf85a5d50dba26 Mon Sep 17 00:00:00 2001 From: Rumato Estorsky Date: Mon, 30 Sep 2019 18:33:28 +0300 Subject: [PATCH 1/2] Input/Output pin trait proposal --- src/digital/v2.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/digital/v2.rs b/src/digital/v2.rs index 748807225..9825ada4b 100644 --- a/src/digital/v2.rs +++ b/src/digital/v2.rs @@ -24,7 +24,7 @@ pub trait OutputPin { /// /// *This trait is available if embedded-hal is built with the `"unproven"` feature.* #[cfg(feature = "unproven")] -pub trait StatefulOutputPin : OutputPin { +pub trait StatefulOutputPin: OutputPin { /// Is the pin in drive high mode? /// /// *NOTE* this does *not* read the electrical state of the pin @@ -136,3 +136,26 @@ pub trait InputPin { /// Is the input pin low? fn is_low(&self) -> Result; } + +/// Describe pin that can switch its input/ouput mode on fly. +/// Should be used to communicate with custom protocols based hardware. +/// +/// *This trait is available if embedded-hal is built with the `"unproven"` feature.* +#[cfg(feature = "unproven")] +pub trait InputOutputPin: InputPin + OutputPin { + /// Switch pin into output mode, + /// Result::Ok value is true if pin mode was changed or false if pin already was in output mode. + /// + /// Expected behaviour after success result: + /// - OutputPin functions should work as for ouptut pin + /// - InputPin functions should return errors + fn mode_output(&mut self) -> Result; + + /// Switch pin into input mode without activating any pull up/down resistors, + /// Result::Ok value is true if pin mode was changed or false if pin already was in input mode. + /// + /// /// Expected behaviour after success result: + /// - InputPin functions should work as for ouptut pin + /// - OutputPin functions should return errors + fn mode_input(&mut self) -> Result; +} From c074a0ed6ac61f0f482caa0dd6f8024560e9da96 Mon Sep 17 00:00:00 2001 From: Rumato Estorsky Date: Mon, 30 Sep 2019 18:53:47 +0300 Subject: [PATCH 2/2] Quick fix for associated types inheritance --- src/digital/v2.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/digital/v2.rs b/src/digital/v2.rs index 9825ada4b..e83179d7a 100644 --- a/src/digital/v2.rs +++ b/src/digital/v2.rs @@ -142,14 +142,15 @@ pub trait InputPin { /// /// *This trait is available if embedded-hal is built with the `"unproven"` feature.* #[cfg(feature = "unproven")] -pub trait InputOutputPin: InputPin + OutputPin { +pub trait InputOutputPin: InputPin + OutputPin { /// Switch pin into output mode, + /// /// Result::Ok value is true if pin mode was changed or false if pin already was in output mode. /// /// Expected behaviour after success result: /// - OutputPin functions should work as for ouptut pin /// - InputPin functions should return errors - fn mode_output(&mut self) -> Result; + fn mode_output(&mut self) -> Result; /// Switch pin into input mode without activating any pull up/down resistors, /// Result::Ok value is true if pin mode was changed or false if pin already was in input mode. @@ -157,5 +158,5 @@ pub trait InputOutputPin: InputPin + OutputPin { /// /// Expected behaviour after success result: /// - InputPin functions should work as for ouptut pin /// - OutputPin functions should return errors - fn mode_input(&mut self) -> Result; + fn mode_input(&mut self) -> Result; }