mirror of
https://github.com/yuri91/ili9341-rs.git
synced 2024-11-25 08:00:59 +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]
|
[package]
|
||||||
name = "ili9341"
|
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"
|
description = "A platform agnostic driver to interface with the ILI9341 (ald ILI9340C) TFT LCD display"
|
||||||
authors = ["Yuri Iozzelli <y.iozzelli@gmail.com>"]
|
authors = ["Yuri Iozzelli <y.iozzelli@gmail.com>"]
|
||||||
categories = ["embedded", "hardware-support", "no-std"]
|
categories = ["embedded", "hardware-support", "no-std"]
|
||||||
|
@ -11,3 +11,11 @@ repository = "https://github.com/yuri91/ili9341-rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embedded-hal = "0.2.1"
|
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;
|
extern crate embedded_hal as hal;
|
||||||
|
|
||||||
|
#[cfg(feature = "graphics")]
|
||||||
|
extern crate embedded_graphics;
|
||||||
|
|
||||||
use hal::blocking::spi;
|
use hal::blocking::spi;
|
||||||
use hal::blocking::delay::DelayMs;
|
use hal::blocking::delay::DelayMs;
|
||||||
use hal::spi::{Mode, Phase, Polarity};
|
use hal::spi::{Mode, Phase, Polarity};
|
||||||
use hal::digital::OutputPin;
|
use hal::digital::OutputPin;
|
||||||
|
|
||||||
use core::iter::IntoIterator;
|
use core::iter::IntoIterator;
|
||||||
|
use core::fmt::Debug;
|
||||||
|
|
||||||
/// SPI mode
|
/// SPI mode
|
||||||
pub const MODE: Mode = 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)]
|
#[derive(Clone, Copy)]
|
||||||
enum Command {
|
enum Command {
|
||||||
SoftwareReset = 0x01,
|
SoftwareReset = 0x01,
|
||||||
|
|
Loading…
Reference in a new issue