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

Allow the underlying interface to be released consuming the DisplayProperties #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/interface/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ where
I2C: hal::blocking::i2c::Write<Error = CommE>,
{
type Error = Error<CommE, ()>;
type Interface = I2C;

fn init(&mut self) -> Result<(), Self::Error> {
Ok(())
Expand Down Expand Up @@ -82,4 +83,8 @@ where

Ok(())
}

fn release(self) -> Self::Interface {
self.i2c
}
}
4 changes: 4 additions & 0 deletions src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ 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>;
/// Send a batch of up to 8 commands to display.
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};
6 changes: 6 additions & 0 deletions src/interface/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ where
CS: OutputPin<Error = PinE>,
{
type Error = Error<CommE, PinE>;
type Interface = (SPI, DC, CS);

fn init(&mut self) -> Result<(), Self::Error> {
self.cs.set_high().map_err(Error::Pin)
Expand All @@ -58,4 +59,9 @@ where

self.cs.set_high().map_err(Error::Pin)
}

fn release(self) -> Self::Interface {
(self.spi, self.dc, self.cs)
}

}
5 changes: 5 additions & 0 deletions src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}