From 333edf10f05a7deafdf307363aaa08828e11a533 Mon Sep 17 00:00:00 2001 From: Eric Trombly Date: Wed, 26 Feb 2020 11:39:39 -0600 Subject: [PATCH 1/3] update to hal v2 traits --- Cargo.toml | 10 +++++----- src/graphics.rs | 2 +- src/interface.rs | 21 ++++++++++++--------- 3 files changed, 18 insertions(+), 15 deletions(-) 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/graphics.rs b/src/graphics.rs index 7b1a84e..0ce08f0 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( diff --git a/src/interface.rs b/src/interface.rs index fc78ee0..d56fc89 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -96,10 +96,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,10 +136,10 @@ 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; @@ -164,6 +164,9 @@ where } fn busy_wait(&self) { - while self.busy.is_high() {} + while match self.busy.is_high() { + Ok(x) => x, + _ => false, + } {} } } From 67c2b90b2adb97d95cd53313a0368ce6e3322c3d Mon Sep 17 00:00:00 2001 From: Eric Trombly Date: Fri, 28 Feb 2020 07:37:54 -0600 Subject: [PATCH 2/3] change rect to rectangle in graphics.rs --- src/graphics.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index 0ce08f0..b6c2fcd 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -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(), ); } From f59959c55cde5efe203652dedb38a62984745b7a Mon Sep 17 00:00:00 2001 From: Eric Trombly Date: Fri, 28 Feb 2020 11:02:59 -0600 Subject: [PATCH 3/3] add custom error type to handle results --- src/error.rs | 16 ++++++++++++++++ src/interface.rs | 13 +++++++------ src/lib.rs | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 src/error.rs 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;