diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..89e76dd --- /dev/null +++ b/src/error.rs @@ -0,0 +1,16 @@ +use core::fmt::{self, Debug}; +use hal::digital::v2::OutputPin; + +pub enum Error { + /// A GPIO could not be set. + Gpio(GPIO::Error), +} + +impl Debug for Error +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Error::Gpio(_) => write!(f, "GPIO error"), + } + } +} \ No newline at end of file diff --git a/src/interface.rs b/src/interface.rs index d56fc89..3eb0764 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -1,3 +1,4 @@ +use crate::Error; use hal; // Section 15.2 of the HINK-E0213A07 data sheet says to hold for 10ms @@ -143,23 +144,23 @@ where { type Error = SPI::Error; - fn reset>(&mut self, delay: &mut D) { - self.reset.set_low(); + fn reset>(&mut self, delay: &mut D){ + self.reset.set_low().map_err::, _>(Error::Gpio).unwrap(); delay.delay_ms(RESET_DELAY_MS); - self.reset.set_high(); + self.reset.set_high().map_err::, _>(Error::Gpio).unwrap(); delay.delay_ms(RESET_DELAY_MS); } fn send_command(&mut self, command: u8) -> Result<(), Self::Error> { - self.dc.set_low(); + self.dc.set_low().map_err::, _>(Error::Gpio).unwrap(); self.write(&[command])?; - self.dc.set_high(); + self.dc.set_high().map_err::, _>(Error::Gpio).unwrap(); Ok(()) } fn send_data(&mut self, data: &[u8]) -> Result<(), Self::Error> { - self.dc.set_high(); + self.dc.set_high().map_err::, _>(Error::Gpio).unwrap(); self.write(data) } diff --git a/src/lib.rs b/src/lib.rs index f366c05..ce4fc3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,12 +47,14 @@ mod color; pub mod command; pub mod config; pub mod display; +pub mod error; pub mod graphics; pub mod interface; pub use color::Color; pub use config::Builder; pub use display::{Dimensions, Display, Rotation}; +pub use error::Error; pub use graphics::GraphicDisplay; pub use interface::DisplayInterface; pub use interface::Interface;