mirror of
https://github.com/yuri91/ili9341-rs.git
synced 2024-11-21 14:30:58 +00:00
Implement embedded_graphics
This commit is contained in:
parent
743f127aa5
commit
e7ab490e53
2 changed files with 37 additions and 1 deletions
10
Cargo.toml
10
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 <y.iozzelli@gmail.com>"]
|
||||
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"]
|
||||
|
|
28
src/lib.rs
28
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<E, SPI, CS, DC, RESET> Drawing for Ili9341<SPI, CS, DC, RESET>
|
||||
where
|
||||
SPI: spi::Transfer<u8, Error = E> + spi::Write<u8, Error = E>,
|
||||
CS: OutputPin,
|
||||
DC: OutputPin,
|
||||
RESET: OutputPin,
|
||||
E: Debug,
|
||||
{
|
||||
fn draw<T>(&mut self, item_pixels: T)
|
||||
where
|
||||
T: Iterator<Item = drawable::Pixel>,
|
||||
{
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue