diff --git a/src/interface/i2c.rs b/src/interface/i2c.rs index 543cb3b..3f1e6ca 100644 --- a/src/interface/i2c.rs +++ b/src/interface/i2c.rs @@ -26,6 +26,7 @@ where I2C: hal::blocking::i2c::Write, { type Error = Error; + type Interface = I2C; fn init(&mut self) -> Result<(), Self::Error> { Ok(()) @@ -82,4 +83,8 @@ where Ok(()) } + + fn release(self) -> Self::Interface { + self.i2c + } } diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 6c7c471..9b18e70 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -55,6 +55,8 @@ pub mod spi; pub trait DisplayInterface { /// Interface error type type Error; + /// Underlying interface type + type Interface; /// Initialize device. fn init(&mut self) -> Result<(), Self::Error>; @@ -62,6 +64,8 @@ pub trait DisplayInterface { fn send_commands(&mut self, cmd: &[u8]) -> Result<(), Self::Error>; /// Send data to display. fn send_data(&mut self, buf: &[u8]) -> Result<(), Self::Error>; + /// Release the interface + fn release(self) -> Self::Interface; } pub use self::{i2c::I2cInterface, spi::SpiInterface}; diff --git a/src/interface/spi.rs b/src/interface/spi.rs index 5a44918..4366669 100644 --- a/src/interface/spi.rs +++ b/src/interface/spi.rs @@ -33,6 +33,7 @@ where CS: OutputPin, { type Error = Error; + type Interface = (SPI, DC, CS); fn init(&mut self) -> Result<(), Self::Error> { self.cs.set_high().map_err(Error::Pin) @@ -58,4 +59,9 @@ where self.cs.set_high().map_err(Error::Pin) } + + fn release(self) -> Self::Interface { + (self.spi, self.dc, self.cs) + } + } diff --git a/src/properties.rs b/src/properties.rs index c37b654..4bd808c 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -167,4 +167,9 @@ where pub fn set_contrast(&mut self, contrast: u8) -> Result<(), DI::Error> { Command::Contrast(contrast).send(&mut self.iface) } + + /// Release the underlying interface + pub fn release_interface(self) -> DI::Interface { + self.iface.release() + } }