Browse Source

Update embedded-graphics and update epd4in2-blue-pill-exampleg

v0.4
Caemor 3 years ago
parent
commit
dcaed6fb3e
  1. 7
      Cargo.toml
  2. 2
      README.md
  3. 12
      examples/epd1in54_full/src/main.rs
  4. 12
      examples/epd2in9_full/src/main.rs
  5. 22
      examples/epd4in2_full/src/main.rs
  6. 4
      examples/epd4in2_full_blue_pill/Cargo.toml
  7. 122
      examples/epd4in2_full_blue_pill/src/main.rs
  8. 22
      examples/epd4in2_var_display_buffer/src/main.rs
  9. 22
      examples/epd7in5_full/src/main.rs
  10. 22
      examples/epd7in5_v2_full/src/main.rs
  11. 9
      src/color.rs
  12. 54
      src/epd1in54/graphics.rs
  13. 2
      src/epd1in54/mod.rs
  14. 17
      src/epd1in54b/graphics.rs
  15. 17
      src/epd2in9/graphics.rs
  16. 2
      src/epd2in9/mod.rs
  17. 54
      src/epd4in2/graphics.rs
  18. 53
      src/epd7in5/graphics.rs
  19. 58
      src/epd7in5_v2/graphics.rs
  20. 101
      src/graphics.rs
  21. 2
      src/lib.rs

7
Cargo.toml

@ -17,6 +17,9 @@ edition = "2018"
# `branch` is optional; default is `master`
travis-ci = { repository = "caemor/epd-waveshare" }
[dependencies]
embedded-graphics = { version = "0.6.0-beta.2", optional = true}
[features]
default = ["epd1in54", "epd1in54b", "epd2in9", "epd4in2", "epd7in5", "epd7in5_v2", "graphics"]
@ -30,9 +33,7 @@ epd7in5_v2 = []
# offers an alternative fast full lut for type_a displays, but the refresh isnt as clean looking
type_a_alternative_faster_lut = []
[dependencies.embedded-graphics]
optional = true
version = "0.5.2"
[dependencies.embedded-hal]
features = ["unproven"]

2
README.md

@ -25,7 +25,7 @@ display.draw(
Font12x16::render_str("Hello Rust!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);

12
examples/epd1in54_full/src/main.rs

@ -1,6 +1,6 @@
#![deny(warnings)]
use embedded_graphics::{coord::Coord, fonts::Font6x8, prelude::*, Drawing};
use embedded_graphics::{fonts::Font6x8, prelude::*, Drawing, Point::Point};
use embedded_hal::prelude::*;
use epd_waveshare::{
epd1in54::{Display1in54, EPD1in54},
@ -82,7 +82,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 0!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -91,7 +91,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 90!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -100,7 +100,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 180!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -109,7 +109,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 270!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -134,7 +134,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(5 + i * 6, 50))
.translate(Point::new(5 + i * 6, 50))
.into_iter(),
);

12
examples/epd2in9_full/src/main.rs

@ -1,6 +1,6 @@
#![deny(warnings)]
use embedded_graphics::{coord::Coord, fonts::Font6x8, prelude::*, Drawing};
use embedded_graphics::{fonts::Font6x8, prelude::*, Drawing, Point::Point};
use embedded_hal::prelude::*;
use epd_waveshare::{
epd2in9::{Display2in9, EPD2in9},
@ -86,7 +86,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 0!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -95,7 +95,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 90!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -104,7 +104,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 180!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -113,7 +113,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 270!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -138,7 +138,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(5 + i * 6, 50))
.translate(Point::new(5 + i * 6, 50))
.into_iter(),
);

22
examples/epd4in2_full/src/main.rs

@ -1,11 +1,11 @@
#![deny(warnings)]
use embedded_graphics::{
coord::Coord,
fonts::{Font12x16, Font6x8},
prelude::*,
primitives::{Circle, Line},
Drawing,
Point::Point,
};
use embedded_hal::prelude::*;
use epd_waveshare::{
@ -77,7 +77,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 0!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -86,7 +86,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 90!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -95,7 +95,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 180!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -104,7 +104,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 270!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -119,17 +119,17 @@ fn run() -> Result<(), std::io::Error> {
// draw a analog clock
display.draw(
Circle::new(Coord::new(64, 64), 64)
Circle::new(Point::new(64, 64), 64)
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(0, 64))
let _ = Line::new(Point::new(64, 64), Point::new(0, 64))
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(80, 80))
let _ = Line::new(Point::new(64, 64), Point::new(80, 80))
.stroke(Some(Color::Black))
.into_iter(),
);
@ -143,7 +143,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::White),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(175, 250))
.translate(Point::new(175, 250))
.into_iter(),
);
@ -156,7 +156,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(50, 200))
.translate(Point::new(50, 200))
.into_iter(),
);
@ -172,7 +172,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(5 + i * 12, 50))
.translate(Point::new(5 + i * 12, 50))
.into_iter(),
);

4
examples/epd4in2_full_blue_pill/Cargo.toml

@ -10,8 +10,8 @@ edition = "2018"
#epd_waveshare = { path = "../../"}
epd-waveshare = { path = "../../", default-features = false, features = ["epd4in2", "graphics"]}
embedded-graphics = "0.5.2"
embedded-hal = { version = "0.2.2", features = ["unproven"] }
embedded-graphics = "0.6.0-beta.2"
embedded-hal = { version = "0.2.3", features = ["unproven"] }
stm32f1xx-hal = { version = "0.2", features = ["rt", "stm32f103" ] }
cortex-m = "0.5.0"

122
examples/epd4in2_full_blue_pill/src/main.rs

@ -10,13 +10,15 @@ use stm32f1xx_hal::prelude::*;
use stm32f1xx_hal::{delay, spi};
use embedded_graphics::{
coord::Coord,
fonts::{Font12x16, Font6x8},
fonts::{Font12x16, Font6x8, Text},
pixelcolor::BinaryColor,
prelude::*,
primitives::{Circle, Line},
Drawing,
style::{PrimitiveStyle, Styled},
text_style, DrawTarget,
};
use epd_waveshare::{
color::*,
epd4in2::Display4in2,
graphics::{Display, DisplayRotation},
prelude::*,
@ -68,41 +70,18 @@ fn main() -> ! {
//println!("Test all the rotations");
let mut display = Display4in2::default();
display.set_rotation(DisplayRotation::Rotate0);
display.draw(
Font6x8::render_str("Rotate 0!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.into_iter(),
);
draw_text(&mut display, "Rotate 0!", 5, 50);
display.set_rotation(DisplayRotation::Rotate90);
display.draw(
Font6x8::render_str("Rotate 90!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.into_iter(),
);
draw_text(&mut display, "Rotate 90!", 5, 50);
display.set_rotation(DisplayRotation::Rotate180);
display.draw(
Font6x8::render_str("Rotate 180!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.into_iter(),
);
draw_text(&mut display, "Rotate 180!", 5, 50);
display.set_rotation(DisplayRotation::Rotate270);
display.draw(
Font6x8::render_str("Rotate 270!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.into_iter(),
);
draw_text(&mut display, "Rotate 270!", 5, 50);
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
epd4in2
@ -114,47 +93,33 @@ fn main() -> ! {
display.clear_buffer(Color::White);
// draw a analog clock
display.draw(
Circle::new(Coord::new(64, 64), 64)
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(0, 64))
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(80, 80))
.stroke(Some(Color::Black))
.into_iter(),
);
Circle::new(Point::new(64, 64), 64)
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
Line::new(Point::new(64, 64), Point::new(0, 64))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
Line::new(Point::new(64, 64), Point::new(80, 80))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
// draw white on black background
display.draw(
Font6x8::render_str("It's working-WoB!")
// Using Style here
.style(Style {
fill_color: Some(Color::Black),
stroke_color: Some(Color::White),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(175, 250))
.into_iter(),
);
let _ = Text::new("It's working-WoB!", Point::new(175, 250))
.into_styled(text_style!(
font = Font6x8,
text_color = White,
background_color = Black
))
.draw(&mut display);
// use bigger/different font
display.draw(
Font12x16::render_str("It's working-BoW!")
// Using Style here
.style(Style {
fill_color: Some(Color::White),
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(50, 200))
.into_iter(),
);
let _ = Text::new("It's working-WoB!", Point::new(50, 200))
.into_styled(text_style!(
font = Font12x16,
text_color = White,
background_color = Black
))
.draw(&mut display);
// a moving `Hello World!`
let limit = 10;
@ -163,16 +128,7 @@ fn main() -> ! {
for i in 0..limit {
//println!("Moving Hello World. Loop {} from {}", (i + 1), limit);
display.draw(
Font6x8::render_str(" Hello World! ")
.style(Style {
fill_color: Some(Color::White),
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(5 + i * 12, 50))
.into_iter(),
);
draw_text(&mut display, " Hello World! ", 5 + i * 12, 50);
epd4in2.update_frame(&mut spi, &display.buffer()).unwrap();
epd4in2
@ -190,3 +146,13 @@ fn main() -> ! {
cortex_m::asm::wfi();
}
}
fn draw_text(display: &mut Display4in2, text: &str, x: i32, y: i32) {
let _ = Text::new(text, Point::new(x, y))
.into_styled(text_style!(
font = Font6x8,
text_color = Black,
background_color = White
))
.draw(display);
}

22
examples/epd4in2_var_display_buffer/src/main.rs

@ -1,11 +1,11 @@
#![deny(warnings)]
use embedded_graphics::{
coord::Coord,
fonts::{Font12x16, Font6x8},
prelude::*,
primitives::{Circle, Line},
Drawing,
Point::Point,
};
use embedded_hal::prelude::*;
use epd_waveshare::{
@ -81,7 +81,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 0!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -90,7 +90,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 90!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -99,7 +99,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 180!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -108,7 +108,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 270!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -125,17 +125,17 @@ fn run() -> Result<(), std::io::Error> {
// draw a analog clock
display.draw(
Circle::new(Coord::new(64, 64), 64)
Circle::new(Point::new(64, 64), 64)
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(0, 64))
let _ = Line::new(Point::new(64, 64), Point::new(0, 64))
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(80, 80))
let _ = Line::new(Point::new(64, 64), Point::new(80, 80))
.stroke(Some(Color::Black))
.into_iter(),
);
@ -149,7 +149,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::White),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(175, 250))
.translate(Point::new(175, 250))
.into_iter(),
);
@ -162,7 +162,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(50, 200))
.translate(Point::new(50, 200))
.into_iter(),
);
@ -178,7 +178,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(5 + i * 12, 50))
.translate(Point::new(5 + i * 12, 50))
.into_iter(),
);

22
examples/epd7in5_full/src/main.rs

@ -1,11 +1,11 @@
#![deny(warnings)]
use embedded_graphics::{
coord::Coord,
fonts::{Font12x16, Font6x8},
prelude::*,
primitives::{Circle, Line},
Drawing,
Point::Point,
};
use embedded_hal::prelude::*;
use epd_waveshare::{
@ -76,7 +76,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 0!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -85,7 +85,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 90!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -94,7 +94,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 180!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -103,7 +103,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 270!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -118,17 +118,17 @@ fn run() -> Result<(), std::io::Error> {
// draw a analog clock
display.draw(
Circle::new(Coord::new(64, 64), 64)
Circle::new(Point::new(64, 64), 64)
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(0, 64))
let _ = Line::new(Point::new(64, 64), Point::new(0, 64))
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(80, 80))
let _ = Line::new(Point::new(64, 64), Point::new(80, 80))
.stroke(Some(Color::Black))
.into_iter(),
);
@ -142,7 +142,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::White),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(175, 250))
.translate(Point::new(175, 250))
.into_iter(),
);
@ -155,7 +155,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(50, 200))
.translate(Point::new(50, 200))
.into_iter(),
);
@ -171,7 +171,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(5 + i * 12, 50))
.translate(Point::new(5 + i * 12, 50))
.into_iter(),
);

22
examples/epd7in5_v2_full/src/main.rs

@ -1,11 +1,11 @@
#![deny(warnings)]
use embedded_graphics::{
coord::Coord,
fonts::{Font12x16, Font6x8},
prelude::*,
primitives::{Circle, Line},
Drawing,
Point::Point,
};
use embedded_hal::prelude::*;
use epd_waveshare::{
@ -76,7 +76,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 0!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -85,7 +85,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 90!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -94,7 +94,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 180!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -103,7 +103,7 @@ fn run() -> Result<(), std::io::Error> {
Font6x8::render_str("Rotate 270!")
.stroke(Some(Color::Black))
.fill(Some(Color::White))
.translate(Coord::new(5, 50))
.translate(Point::new(5, 50))
.into_iter(),
);
@ -118,17 +118,17 @@ fn run() -> Result<(), std::io::Error> {
// draw a analog clock
display.draw(
Circle::new(Coord::new(64, 64), 64)
Circle::new(Point::new(64, 64), 64)
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(0, 64))
Line::new(Point::new(64, 64), Point::new(0, 64))
.stroke(Some(Color::Black))
.into_iter(),
);
display.draw(
Line::new(Coord::new(64, 64), Coord::new(80, 80))
Line::new(Point::new(64, 64), Point::new(80, 80))
.stroke(Some(Color::Black))
.into_iter(),
);
@ -142,7 +142,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::White),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(175, 250))
.translate(Point::new(175, 250))
.into_iter(),
);
@ -155,7 +155,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(50, 200))
.translate(Point::new(50, 200))
.into_iter(),
);
@ -171,7 +171,7 @@ fn run() -> Result<(), std::io::Error> {
stroke_color: Some(Color::Black),
stroke_width: 0u8, // Has no effect on fonts
})
.translate(Coord::new(5 + i * 12, 50))
.translate(Point::new(5 + i * 12, 50))
.into_iter(),
);

9
src/color.rs

@ -1,5 +1,9 @@
//! B/W Color for EPDs
use embedded_graphics::pixelcolor::BinaryColor;
pub use BinaryColor::Off as White;
pub use BinaryColor::On as Black;
/// Only for the Black/White-Displays
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Color {
@ -51,11 +55,6 @@ impl Color {
}
}
#[cfg(feature = "graphics")]
use embedded_graphics::prelude::*;
#[cfg(feature = "graphics")]
impl PixelColor for Color {}
impl From<u8> for Color {
fn from(value: u8) -> Self {
Color::from_u8(value)

54
src/epd1in54/graphics.rs

@ -1,6 +1,6 @@
use crate::epd1in54::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
use crate::graphics::{Display, DisplayRotation};
use crate::prelude::*;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
/// Full size buffer for use with the 1in54 EPD
@ -22,12 +22,15 @@ impl Default for Display1in54 {
}
}
impl Drawing<Color> for Display1in54 {
fn draw<T>(&mut self, item_pixels: T)
where
T: IntoIterator<Item = Pixel<Color>>,
{
self.draw_helper(WIDTH, HEIGHT, item_pixels);
impl DrawTarget<BinaryColor> for Display1in54 {
type Error = core::convert::Infallible;
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
self.draw_helper(WIDTH, HEIGHT, pixel)
}
fn size(&self) -> Size {
Size::new(WIDTH, HEIGHT)
}
}
@ -52,10 +55,9 @@ impl Display for Display1in54 {
#[cfg(test)]
mod tests {
use super::*;
use crate::color::Color;
use crate::color::{Black, Color};
use crate::graphics::{Display, DisplayRotation};
use embedded_graphics::coord::Coord;
use embedded_graphics::primitives::Line;
use embedded_graphics::{primitives::Line, style::PrimitiveStyle};
// test buffer length
#[test]
@ -76,11 +78,9 @@ mod tests {
#[test]
fn graphics_rotation_0() {
let mut display = Display1in54::default();
display.draw(
Line::new(Coord::new(0, 0), Coord::new(7, 0))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(0, 0), Point::new(7, 0))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -95,11 +95,9 @@ mod tests {
fn graphics_rotation_90() {
let mut display = Display1in54::default();
display.set_rotation(DisplayRotation::Rotate90);
display.draw(
Line::new(Coord::new(0, 192), Coord::new(0, 199))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(0, 192), Point::new(0, 199))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -114,11 +112,9 @@ mod tests {
fn graphics_rotation_180() {
let mut display = Display1in54::default();
display.set_rotation(DisplayRotation::Rotate180);
display.draw(
Line::new(Coord::new(192, 199), Coord::new(199, 199))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(192, 199), Point::new(199, 199))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -136,11 +132,9 @@ mod tests {
fn graphics_rotation_270() {
let mut display = Display1in54::default();
display.set_rotation(DisplayRotation::Rotate270);
display.draw(
Line::new(Coord::new(199, 0), Coord::new(199, 7))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(199, 0), Point::new(199, 7))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();

2
src/epd1in54/mod.rs

@ -21,7 +21,7 @@
//! Font6x8::render_str("Hello World!")
//! .stroke(Some(Color::Black))
//! .fill(Some(Color::White))
//! .translate(Coord::new(5, 50))
//! .translate(Point::new(5, 50))
//! .into_iter(),
//! );
//!

17
src/epd1in54b/graphics.rs

@ -1,6 +1,6 @@
use crate::epd1in54b::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
use crate::graphics::{Display, DisplayRotation};
use crate::prelude::*;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
pub struct Display1in54b {
@ -18,12 +18,15 @@ impl Default for Display1in54b {
}
}
impl Drawing<Color> for Display1in54b {
fn draw<T>(&mut self, item_pixels: T)
where
T: IntoIterator<Item = Pixel<Color>>,
{
self.draw_helper(WIDTH, HEIGHT, item_pixels);
impl DrawTarget<BinaryColor> for Display1in54b {
type Error = core::convert::Infallible;
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
self.draw_helper(WIDTH, HEIGHT, pixel)
}
fn size(&self) -> Size {
Size::new(WIDTH, HEIGHT)
}
}

17
src/epd2in9/graphics.rs

@ -1,6 +1,6 @@
use crate::epd2in9::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
use crate::graphics::{Display, DisplayRotation};
use crate::prelude::*;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
/// Display with Fullsize buffer for use with the 2in9 EPD
@ -22,12 +22,15 @@ impl Default for Display2in9 {
}
}
impl Drawing<Color> for Display2in9 {
fn draw<T>(&mut self, item_pixels: T)
where
T: IntoIterator<Item = Pixel<Color>>,
{
self.draw_helper(WIDTH, HEIGHT, item_pixels);
impl DrawTarget<BinaryColor> for Display2in9 {
type Error = core::convert::Infallible;
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
self.draw_helper(WIDTH, HEIGHT, pixel)
}
fn size(&self) -> Size {
Size::new(WIDTH, HEIGHT)
}
}

2
src/epd2in9/mod.rs

@ -23,7 +23,7 @@
//! Font6x8::render_str("Hello World!")
//! .stroke(Some(Color::Black))
//! .fill(Some(Color::White))
//! .translate(Coord::new(5, 50))
//! .translate(Point::new(5, 50))
//! .into_iter(),
//! );
//!

54
src/epd4in2/graphics.rs

@ -1,6 +1,6 @@
use crate::epd4in2::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
use crate::graphics::{Display, DisplayRotation};
use crate::prelude::*;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
/// Full size buffer for use with the 4in2 EPD
@ -22,12 +22,15 @@ impl Default for Display4in2 {
}
}
impl Drawing<Color> for Display4in2 {
fn draw<T>(&mut self, item_pixels: T)
where
T: IntoIterator<Item = Pixel<Color>>,
{
self.draw_helper(WIDTH, HEIGHT, item_pixels);
impl DrawTarget<BinaryColor> for Display4in2 {
type Error = core::convert::Infallible;
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
self.draw_helper(WIDTH, HEIGHT, pixel)
}
fn size(&self) -> Size {
Size::new(WIDTH, HEIGHT)
}
}
@ -52,11 +55,11 @@ impl Display for Display4in2 {
#[cfg(test)]
mod tests {
use super::*;
use crate::color::Black;
use crate::color::Color;
use crate::epd4in2;
use crate::graphics::{Display, DisplayRotation};
use embedded_graphics::coord::Coord;
use embedded_graphics::primitives::Line;
use embedded_graphics::{primitives::Line, style::PrimitiveStyle};
// test buffer length
#[test]
@ -77,11 +80,9 @@ mod tests {
#[test]
fn graphics_rotation_0() {
let mut display = Display4in2::default();
display.draw(
Line::new(Coord::new(0, 0), Coord::new(7, 0))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(0, 0), Point::new(7, 0))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -96,11 +97,9 @@ mod tests {
fn graphics_rotation_90() {
let mut display = Display4in2::default();
display.set_rotation(DisplayRotation::Rotate90);
display.draw(
Line::new(Coord::new(0, 392), Coord::new(0, 399))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(0, 392), Point::new(0, 399))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -115,11 +114,10 @@ mod tests {
fn graphics_rotation_180() {
let mut display = Display4in2::default();
display.set_rotation(DisplayRotation::Rotate180);
display.draw(
Line::new(Coord::new(392, 299), Coord::new(399, 299))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(392, 299), Point::new(399, 299))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -137,11 +135,9 @@ mod tests {
fn graphics_rotation_270() {
let mut display = Display4in2::default();
display.set_rotation(DisplayRotation::Rotate270);
display.draw(
Line::new(Coord::new(299, 0), Coord::new(299, 7))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(299, 0), Point::new(299, 7))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();

53
src/epd7in5/graphics.rs

@ -1,6 +1,6 @@
use crate::epd7in5::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
use crate::graphics::{Display, DisplayRotation};
use crate::prelude::*;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
/// Full size buffer for use with the 7in5 EPD
@ -22,12 +22,15 @@ impl Default for Display7in5 {
}
}
impl Drawing<Color> for Display7in5 {
fn draw<T>(&mut self, item_pixels: T)
where
T: IntoIterator<Item = Pixel<Color>>,
{
self.draw_helper(WIDTH, HEIGHT, item_pixels);
impl DrawTarget<BinaryColor> for Display7in5 {
type Error = core::convert::Infallible;
fn draw_pixel(&mut self, pixel: Pixel<BinaryColor>) -> Result<(), Self::Error> {
self.draw_helper(WIDTH, HEIGHT, pixel)
}
fn size(&self) -> Size {
Size::new(WIDTH, HEIGHT)
}
}
@ -52,11 +55,11 @@ impl Display for Display7in5 {
#[cfg(test)]
mod tests {
use super::*;
use crate::color::Black;
use crate::color::Color;
use crate::epd7in5;
use crate::graphics::{Display, DisplayRotation};
use embedded_graphics::coord::Coord;
use embedded_graphics::primitives::Line;
use embedded_graphics::{primitives::Line, style::PrimitiveStyle};
// test buffer length
#[test]
@ -77,11 +80,9 @@ mod tests {
#[test]
fn graphics_rotation_0() {
let mut display = Display7in5::default();
display.draw(
Line::new(Coord::new(0, 0), Coord::new(7, 0))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(0, 0), Point::new(7, 0))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -96,11 +97,9 @@ mod tests {
fn graphics_rotation_90() {
let mut display = Display7in5::default();
display.set_rotation(DisplayRotation::Rotate90);
display.draw(
Line::new(Coord::new(0, 632), Coord::new(0, 639))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(0, 632), Point::new(0, 639))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -115,11 +114,9 @@ mod tests {
fn graphics_rotation_180() {
let mut display = Display7in5::default();
display.set_rotation(DisplayRotation::Rotate180);
display.draw(
Line::new(Coord::new(632, 383), Coord::new(639, 383))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(632, 383), Point::new(639, 383))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();
@ -134,11 +131,9 @@ mod tests {
fn graphics_rotation_270() {
let mut display = Display7in5::default();
display.set_rotation(DisplayRotation::Rotate270);
display.draw(
Line::new(Coord::new(383, 0), Coord::new(383, 7))
.stroke(Some(Color::Black))
.into_iter(),
);
let _ = Line::new(Point::new(383, 0), Point::new(383, 7))
.into_styled(PrimitiveStyle::with_stroke(Black, 1))
.draw(&mut display);
let buffer = display.buffer();

58
src/epd7in5_v2/graphics.rs

@ -1,6 +1,6 @@
use crate::epd7in5_v2::{DEFAULT_BACKGROUND_COLOR, HEIGHT, WIDTH};
use crate::graphics::{Display, DisplayRotation};
use crate::prelude::*;
use embedded_graphics::pixelcolor::BinaryColor;
use embedded_graphics::prelude::*;
/// Full size buffer for use with the 7in5 EPD
@ -22,12 +22,15 @@ impl Default for Display7in5 {
}
}
impl Drawing<Color> for Display7in5 {
fn draw<T>