diff --git a/Cargo.toml b/Cargo.toml index dfd8636..b017427 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ili9341" -version = "0.1.4" +version = "0.1.5" description = "A platform agnostic driver to interface with the ILI9341 (ald ILI9340C) TFT LCD display" authors = ["Yuri Iozzelli "] categories = ["embedded", "hardware-support", "no-std"] @@ -11,3 +11,11 @@ repository = "https://github.com/yuri91/ili9341-rs" [dependencies] embedded-hal = "0.2.1" + +[dependencies.embedded-graphics] +version = "0.1.1" +optional = true + +[features] +default = ["graphics"] +graphics = ["embedded-graphics"] diff --git a/src/lib.rs b/src/lib.rs index e8db679..e178cbc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,12 +2,16 @@ extern crate embedded_hal as hal; +#[cfg(feature = "graphics")] +extern crate embedded_graphics; + use hal::blocking::spi; use hal::blocking::delay::DelayMs; use hal::spi::{Mode, Phase, Polarity}; use hal::digital::OutputPin; use core::iter::IntoIterator; +use core::fmt::Debug; /// SPI mode pub const MODE: Mode = Mode { @@ -246,6 +250,30 @@ where } } +#[cfg(feature = "graphics")] +use embedded_graphics::Drawing; +#[cfg(feature = "graphics")] +use embedded_graphics::drawable; + +#[cfg(feature = "graphics")] +impl Drawing for Ili9341 +where + SPI: spi::Transfer + spi::Write, + CS: OutputPin, + DC: OutputPin, + RESET: OutputPin, + E: Debug, +{ + fn draw(&mut self, item_pixels: T) + where + T: Iterator, + { + for (pos, color) in item_pixels { + self.draw_raw(pos.0 as u16, pos.0 as u16, pos.1 as u16, pos.1 as u16, if color != 0 {&[1]} else {&[0]}).expect("Failed to communicate with device"); + } + } +} + #[derive(Clone, Copy)] enum Command { SoftwareReset = 0x01,