diff --git a/Cargo.toml b/Cargo.toml index 1161575..71c8490 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,23 +18,23 @@ travis-ci = { repository = "wezm/ssd1675" } codecov = { repository = "wezm/ssd1675" } [dependencies] -libm = "0.1.2" +libm = "0.2.1" [dependencies.embedded-hal] features = ["unproven"] -version = "0.2.2" +version = "0.2.3" [dependencies.embedded-graphics] optional = true -version = "0.4.4" +version = "0.5.2" [dependencies.linux-embedded-hal] optional = true -version = "0.2.1" +version = "0.3.0" [dependencies.profont] optional = true -version = "0.1" +version = "0.3.0" [features] default = ["graphics"] 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/graphics.rs b/src/graphics.rs index 7b1a84e..b6c2fcd 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -153,7 +153,7 @@ where { fn draw(&mut self, item_pixels: T) where - T: Iterator>, + T: IntoIterator>, { for Pixel(UnsignedCoord(x, y), colour) in item_pixels { if outside_display( @@ -175,7 +175,7 @@ where mod tests { use self::embedded_graphics::coord::Coord; use self::embedded_graphics::prelude::*; - use self::embedded_graphics::primitives::Rect; + use self::embedded_graphics::primitives::Rectangle; use self::embedded_graphics::Drawing; use super::*; use {Builder, Color, Dimensions, Display, DisplayInterface, GraphicDisplay, Rotation}; @@ -279,8 +279,8 @@ mod tests { GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer); display.draw( - Rect::new(Coord::new(0, 0), Coord::new(2, 2)) - .with_stroke(Some(Color::White)) + Rectangle::new(Coord::new(0, 0), Coord::new(2, 2)) + .stroke(Some(Color::White)) .into_iter(), ); } @@ -306,8 +306,8 @@ mod tests { GraphicDisplay::new(build_mock_display(), &mut black_buffer, &mut red_buffer); display.draw( - Rect::new(Coord::new(0, 0), Coord::new(2, 2)) - .with_stroke(Some(Color::Red)) + Rectangle::new(Coord::new(0, 0), Coord::new(2, 2)) + .stroke(Some(Color::Red)) .into_iter(), ); } diff --git a/src/interface.rs b/src/interface.rs index fc78ee0..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 @@ -96,10 +97,10 @@ pub struct Interface { impl Interface where SPI: hal::blocking::spi::Write, - CS: hal::digital::OutputPin, - BUSY: hal::digital::InputPin, - DC: hal::digital::OutputPin, - RESET: hal::digital::OutputPin, + CS: hal::digital::v2::OutputPin, + BUSY: hal::digital::v2::InputPin, + DC: hal::digital::v2::OutputPin, + RESET: hal::digital::v2::OutputPin, { /// Create a new Interface from embedded hal traits. pub fn new(spi: SPI, cs: CS, busy: BUSY, dc: DC, reset: RESET) -> Self { @@ -136,34 +137,37 @@ where impl DisplayInterface for Interface where SPI: hal::blocking::spi::Write, - CS: hal::digital::OutputPin, - BUSY: hal::digital::InputPin, - DC: hal::digital::OutputPin, - RESET: hal::digital::OutputPin, + CS: hal::digital::v2::OutputPin, + BUSY: hal::digital::v2::InputPin, + DC: hal::digital::v2::OutputPin, + RESET: hal::digital::v2::OutputPin, { 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) } fn busy_wait(&self) { - while self.busy.is_high() {} + while match self.busy.is_high() { + Ok(x) => x, + _ => false, + } {} } } 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;