mirror of
https://github.com/yuri91/ili9341-rs.git
synced 2024-11-21 22:30:59 +00:00
Add support for embedded-graphics-core 0.3
This commit is contained in:
parent
47d4a07469
commit
115fec7703
3 changed files with 95 additions and 0 deletions
|
@ -18,6 +18,13 @@ embedded-hal = "0.2.4"
|
||||||
optional = true
|
optional = true
|
||||||
version = "0.6.2"
|
version = "0.6.2"
|
||||||
|
|
||||||
|
[dependencies.embedded-graphics-core]
|
||||||
|
optional = true
|
||||||
|
version = "0.3"
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["graphics"]
|
default = ["graphics"]
|
||||||
graphics = ["embedded-graphics"]
|
graphics = ["embedded-graphics"]
|
||||||
|
graphics-core = ["embedded-graphics-core"]
|
||||||
|
|
||||||
|
|
85
src/graphics_core.rs
Normal file
85
src/graphics_core.rs
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
use crate::Ili9341;
|
||||||
|
|
||||||
|
use embedded_graphics_core::{
|
||||||
|
pixelcolor::{raw::RawU16, Rgb565},
|
||||||
|
prelude::*,
|
||||||
|
primitives::Rectangle,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl<IFACE, RESET> OriginDimensions for Ili9341<IFACE, RESET> {
|
||||||
|
fn size(&self) -> Size {
|
||||||
|
Size::new(self.width() as u32, self.height() as u32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<IFACE, RESET> DrawTarget for Ili9341<IFACE, RESET>
|
||||||
|
where
|
||||||
|
IFACE: display_interface::WriteOnlyDataCommand,
|
||||||
|
{
|
||||||
|
type Error = display_interface::DisplayError;
|
||||||
|
|
||||||
|
type Color = Rgb565;
|
||||||
|
|
||||||
|
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = Pixel<Self::Color>>,
|
||||||
|
{
|
||||||
|
for Pixel(point, color) in pixels {
|
||||||
|
if self.bounding_box().contains(point) {
|
||||||
|
let x = point.x as u16;
|
||||||
|
let y = point.y as u16;
|
||||||
|
|
||||||
|
self.draw_raw_iter(
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
core::iter::once(RawU16::from(color).into_inner()),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fill_contiguous<I>(&mut self, area: &Rectangle, colors: I) -> Result<(), Self::Error>
|
||||||
|
where
|
||||||
|
I: IntoIterator<Item = Self::Color>,
|
||||||
|
{
|
||||||
|
let drawable_area = area.intersection(&self.bounding_box());
|
||||||
|
|
||||||
|
if let Some(drawable_bottom_right) = drawable_area.bottom_right() {
|
||||||
|
let x0 = drawable_area.top_left.x as u16;
|
||||||
|
let y0 = drawable_area.top_left.y as u16;
|
||||||
|
let x1 = drawable_bottom_right.x as u16;
|
||||||
|
let y1 = drawable_bottom_right.y as u16;
|
||||||
|
|
||||||
|
if area == &drawable_area {
|
||||||
|
// All pixels are on screen
|
||||||
|
self.draw_raw_iter(
|
||||||
|
x0,
|
||||||
|
y0,
|
||||||
|
x1,
|
||||||
|
y1,
|
||||||
|
area.points()
|
||||||
|
.zip(colors)
|
||||||
|
.map(|(_, color)| RawU16::from(color).into_inner()),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// Some pixels are on screen
|
||||||
|
self.draw_raw_iter(
|
||||||
|
x0,
|
||||||
|
y0,
|
||||||
|
x1,
|
||||||
|
y1,
|
||||||
|
area.points()
|
||||||
|
.zip(colors)
|
||||||
|
.filter(|(point, _)| drawable_area.contains(*point))
|
||||||
|
.map(|(_, color)| RawU16::from(color).into_inner()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No pixels are on screen
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,9 @@ use display_interface::WriteOnlyDataCommand;
|
||||||
#[cfg(feature = "graphics")]
|
#[cfg(feature = "graphics")]
|
||||||
mod graphics;
|
mod graphics;
|
||||||
|
|
||||||
|
#[cfg(feature = "graphics-core")]
|
||||||
|
mod graphics_core;
|
||||||
|
|
||||||
pub use embedded_hal::spi::MODE_0 as SPI_MODE;
|
pub use embedded_hal::spi::MODE_0 as SPI_MODE;
|
||||||
|
|
||||||
pub use display_interface::DisplayError;
|
pub use display_interface::DisplayError;
|
||||||
|
|
Loading…
Reference in a new issue