From 905a1c840672ac4448919db7e2618c34cefd9df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Flemstr=C3=B6m?= Date: Tue, 17 Dec 2019 10:55:56 +0100 Subject: [PATCH 1/2] Upgrade to embedded-graphics 0.6.0-alpha.2 --- Cargo.toml | 2 +- src/lib.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e32a910..57ce53f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ embedded-hal = "0.2.2" [dependencies.embedded-graphics] optional = true -version = "0.4.7" +version = "0.6.0-alpha.2" [features] default = ["graphics"] diff --git a/src/lib.rs b/src/lib.rs index 4277436..8966a9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,13 +5,13 @@ 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::blocking::spi; use hal::digital::OutputPin; +use hal::spi::{Mode, Phase, Polarity}; -use core::iter::IntoIterator; use core::fmt::Debug; +use core::iter::IntoIterator; /// SPI mode pub const MODE: Mode = Mode { @@ -279,10 +279,10 @@ where #[cfg(feature = "graphics")] use embedded_graphics::drawable; #[cfg(feature = "graphics")] -use embedded_graphics::{drawable::Pixel, pixelcolor::PixelColorU16, Drawing}; +use embedded_graphics::{drawable::Pixel, pixelcolor::Rgb565, Drawing}; #[cfg(feature = "graphics")] -impl Drawing for Ili9341 +impl Drawing for Ili9341 where SPI: spi::Transfer + spi::Write, CS: OutputPin, @@ -292,15 +292,15 @@ where { fn draw(&mut self, item_pixels: T) where - T: Iterator>, + T: IntoIterator>, { for Pixel(pos, color) in item_pixels { self.draw_raw( - pos.0 as u16, - pos.1 as u16, - pos.0 as u16, - pos.1 as u16, - if color == PixelColorU16(0) { + pos.x as u16, + pos.y as u16, + pos.x as u16, + pos.y as u16, + if color == Rgb565::new(0, 0, 0) { &[0xff, 0xff] } else { &[0, 0] From 6d82f813bc58fb98370dfa1f1474efbdf5e56bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Flemstr=C3=B6m?= Date: Tue, 17 Dec 2019 11:06:54 +0100 Subject: [PATCH 2/2] Add color support --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8966a9e..c1aac72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -295,16 +295,16 @@ where T: IntoIterator>, { for Pixel(pos, color) in item_pixels { + use embedded_graphics::pixelcolor::raw::RawData; + self.draw_raw( pos.x as u16, pos.y as u16, pos.x as u16, pos.y as u16, - if color == Rgb565::new(0, 0, 0) { - &[0xff, 0xff] - } else { - &[0, 0] - }, + &embedded_graphics::pixelcolor::raw::RawU16::from(color) + .into_inner() + .to_le_bytes(), ) .expect("Failed to communicate with device"); }