Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arlyon/fix compile #210

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
[package]
authors = ["Christoph Groß <caemor@mailbox.org>"]
authors = [
"Christoph Groß <caemor@mailbox.org>",
"Dirk Van Haerenborgh <vhdirk@gmail.com>",
]
categories = ["embedded", "hardware-support", "no-std"]
description = "An embedded-hal based driver for ePaper displays from Waveshare formerly published as eink-waveshare-rs"
documentation = "https://docs.rs/epd-waveshare"
homepage = "https://github.com/caemor/epd-waveshare"
homepage = "https://github.com/vhdirk/epd-waveshare-async"
keywords = ["ePaper", "Display", "epd", "eink"]
license = "ISC"
name = "epd-waveshare"
name = "epd-waveshare-async"
readme = "README.md"
repository = "https://github.com/Caemor/epd-waveshare.git"
repository = "https://github.com/vhdirk/epd-waveshare-async.git"
version = "0.5.0"
edition = "2021"

Expand All @@ -17,14 +20,18 @@ edition = "2021"

[dependencies]
embedded-graphics-core = { version = "0.4", optional = true }
embedded-hal = "1.0.0"
bit_field = "0.10.1"
embedded-hal = { version = "1.0" }
embedded-hal-async = { version = "1.0" }
bit_field = "0.10.2"

[dev-dependencies]
embedded-graphics = "0.8"
embedded-hal-mock = { version = "=0.10.0", default-features = false, features = [
embedded-graphics = "0.8.1"
embedded-hal-bus = { version = "0.2.0", features = ["async"] }
embassy-time = { version = "0.3.1" }
embedded-hal-mock = { version = "0.11.1", default-features = false, features = [
"eh1",
] }
anyhow = { version = "1.0", default-features = false }

[target.'cfg(unix)'.dev-dependencies]
linux-embedded-hal = "0.4.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ let text_style = TextStyleBuilder::new().baseline(Baseline::Top).build();

// Draw some text at a certain point using the specified text style
let _ = Text::with_text_style("It's working-WoB!", Point::new(175, 250), style, text_style)
.draw(&mut display);
.draw(&mut display).await;

// Going to sleep
epd4in2.sleep(&mut spi, &mut delay)
epd4in2.sleep(&mut spi).await
```
> Check the complete example [here](./examples/epd4in2.rs).

Expand Down
47 changes: 30 additions & 17 deletions examples/epd1in54_no_graphics.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#![deny(warnings)]

use anyhow;
use embedded_hal::delay::DelayNs;
use epd_waveshare::{epd1in54::Epd1in54, prelude::*};
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Delay, SPIError, SpidevDevice, SysfsPin,
Delay, SpidevDevice, SysfsPin,
};

// activate spi, gpio in raspi-config
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues

fn main() -> Result<(), SPIError> {
fn main() -> Result<(), anyhow::Error> {
// Configure SPI
// SPI settings are from eink-waveshare-rs documenation
let mut spi = SpidevDevice::open("/dev/spidev0.0")?;
let mut spi = SpidevDevice::open("/dev/spidev0.0").map_err(anyhow::Error::msg)?;
let options = SpidevOptions::new()
.bits_per_word(8)
.max_speed_hz(4_000_000)
Expand Down Expand Up @@ -58,50 +59,62 @@ fn main() -> Result<(), SPIError> {

// Setup of the needed pins is finished here
// Now the "real" usage of the eink-waveshare-rs crate begins
let mut epd = Epd1in54::new(&mut spi, busy, dc, rst, &mut delay, Some(5))?;
let mut epd =
Epd1in54::new(&mut spi, busy, dc, rst, Some(5)).await.map_err(anyhow::Error::msg)?;

// Clear the full screen
epd.clear_frame(&mut spi, &mut delay)?;
epd.display_frame(&mut spi, &mut delay)?;
epd.clear_frame(&mut spi).await
.map_err(anyhow::Error::msg)?;
epd.display_frame(&mut spi).await
.map_err(anyhow::Error::msg)?;

// Speeddemo
epd.set_lut(&mut spi, &mut delay, Some(RefreshLut::Quick))?;
epd.set_lut(&mut spi, Some(RefreshLut::Quick)).await
.map_err(anyhow::Error::msg)?;
let small_buffer = [Color::Black.get_byte_value(); 32]; //16x16
let number_of_runs = 1;
for i in 0..number_of_runs {
let offset = i * 8 % 150;
epd.update_partial_frame(
&mut spi,
&mut delay,
&small_buffer,
25 + offset,
25 + offset,
16,
16,
)?;
epd.display_frame(&mut spi, &mut delay)?;
).await
.map_err(anyhow::Error::msg)?;
epd.display_frame(&mut spi).await
.map_err(anyhow::Error::msg)?;
}

// Clear the full screen
epd.clear_frame(&mut spi, &mut delay)?;
epd.display_frame(&mut spi, &mut delay)?;
epd.clear_frame(&mut spi).await
.map_err(anyhow::Error::msg)?;
epd.display_frame(&mut spi).await
.map_err(anyhow::Error::msg)?;

// Draw some squares
let small_buffer = [Color::Black.get_byte_value(); 3200]; //160x160
epd.update_partial_frame(&mut spi, &mut delay, &small_buffer, 20, 20, 160, 160)?;
epd.update_partial_frame(&mut spi, &small_buffer, 20, 20, 160, 160).await
.map_err(anyhow::Error::msg)?;

let small_buffer = [Color::White.get_byte_value(); 800]; //80x80
epd.update_partial_frame(&mut spi, &mut delay, &small_buffer, 60, 60, 80, 80)?;
epd.update_partial_frame(&mut spi, &small_buffer, 60, 60, 80, 80).await
.map_err(anyhow::Error::msg)?;

let small_buffer = [Color::Black.get_byte_value(); 8]; //8x8
epd.update_partial_frame(&mut spi, &mut delay, &small_buffer, 96, 96, 8, 8)?;
epd.update_partial_frame(&mut spi, &small_buffer, 96, 96, 8, 8).await
.map_err(anyhow::Error::msg)?;

// Display updated frame
epd.display_frame(&mut spi, &mut delay)?;
epd.display_frame(&mut spi).await
.map_err(anyhow::Error::msg)?;
delay.delay_ms(5000);

// Set the EPD to sleep
epd.sleep(&mut spi, &mut delay)?;
epd.sleep(&mut spi, &mut delay).await
.map_err(anyhow::Error::msg)?;

Ok(())
}
28 changes: 17 additions & 11 deletions examples/epd2in13_v2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(warnings)]

use anyhow;
use embedded_graphics::{
mono_font::MonoTextStyleBuilder,
prelude::*,
Expand All @@ -16,15 +17,15 @@ use epd_waveshare::{
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Delay, SPIError, SpidevDevice, SysfsPin,
Delay, SpidevDevice, SysfsPin,
};

// The pins in this example are for the Universal e-Paper Raw Panel Driver HAT
// activate spi, gpio in raspi-config
// needs to be run with sudo because of some sysfs_gpio permission problems and follow-up timing problems
// see https://github.com/rust-embedded/rust-sysfs-gpio/issues/5 and follow-up issues

fn main() -> Result<(), SPIError> {
fn main() -> Result<(), anyhow::Error> {
// Configure SPI
// Settings are taken from
let mut spi = SpidevDevice::open("/dev/spidev0.0").expect("spidev directory");
Expand Down Expand Up @@ -63,7 +64,7 @@ fn main() -> Result<(), SPIError> {
let mut delay = Delay {};

let mut epd2in13 =
Epd2in13::new(&mut spi, busy, dc, rst, &mut delay, None).expect("eink initalize error");
Epd2in13::new(&mut spi, busy, dc, rst, None).expect("eink initalize error");

//println!("Test all the rotations");
let mut display = Display2in13::default();
Expand All @@ -80,9 +81,11 @@ fn main() -> Result<(), SPIError> {
display.set_rotation(DisplayRotation::Rotate270);
draw_text(&mut display, "Rotate 270!", 5, 50);

epd2in13.update_frame(&mut spi, display.buffer(), &mut delay)?;
epd2in13
.display_frame(&mut spi, &mut delay)
.update_frame(&mut spi, display.buffer()).await
.map_err(anyhow::Error::msg)?;
epd2in13
.display_frame(&mut spi, &mut delay).await
.expect("display frame new graphics");
delay.delay_ms(5000);

Expand Down Expand Up @@ -124,9 +127,10 @@ fn main() -> Result<(), SPIError> {
// Demonstrating how to use the partial refresh feature of the screen.
// Real animations can be used.
epd2in13
.set_refresh(&mut spi, &mut delay, RefreshLut::Quick)
.unwrap();
epd2in13.clear_frame(&mut spi, &mut delay).unwrap();
.set_refresh(&mut spi, &mut delay, RefreshLut::Quick).await
.map_err(anyhow::Error::msg)?;
epd2in13.clear_frame(&mut spi, &mut delay).await
.map_err(anyhow::Error::msg)?;

// a moving `Hello World!`
let limit = 10;
Expand All @@ -143,8 +147,8 @@ fn main() -> Result<(), SPIError> {
// the screen can refresh for this kind of change (small single character)
display.clear(Color::White).ok();
epd2in13
.update_and_display_frame(&mut spi, display.buffer(), &mut delay)
.unwrap();
.update_and_display_frame(&mut spi, display.buffer(), &mut delay).await
.map_err(anyhow::Error::msg)?;

let spinner = ["|", "/", "-", "\\"];
for i in 0..10 {
Expand All @@ -156,7 +160,9 @@ fn main() -> Result<(), SPIError> {
}

println!("Finished tests - going to sleep");
epd2in13.sleep(&mut spi, &mut delay)
epd2in13
.sleep(&mut spi).await
.map_err(anyhow::Error::msg)
}

fn draw_text(display: &mut Display2in13, text: &str, x: i32, y: i32) {
Expand Down
45 changes: 27 additions & 18 deletions examples/epd2in13bc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#![deny(warnings)]

use anyhow;
use embedded_graphics::{
mono_font::MonoTextStyleBuilder,
prelude::*,
primitives::{Circle, Line, PrimitiveStyle},
text::{Baseline, Text, TextStyleBuilder},
};
use embedded_hal::delay::DelayNs;
use epd_waveshare::{
use epd_waveshare_async::{
color::*,
epd2in13bc::{Display2in13bc, Epd2in13bc},
graphics::DisplayRotation,
Expand All @@ -16,7 +17,7 @@ use epd_waveshare::{
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Delay, SPIError, SpidevDevice, SysfsPin,
Delay, SpidevDevice, SysfsPin,
};

// activate spi, gpio in raspi-config
Expand All @@ -34,7 +35,7 @@ use linux_embedded_hal::{
//
// after finishing, put the display to sleep

fn main() -> Result<(), SPIError> {
fn main() -> Result<(), anyhow::Error> {
let busy = SysfsPin::new(24); // GPIO 24, board J-18
busy.export().expect("busy export");
while !busy.is_exported() {}
Expand Down Expand Up @@ -72,7 +73,7 @@ fn main() -> Result<(), SPIError> {
let mut delay = Delay {};

let mut epd2in13 =
Epd2in13bc::new(&mut spi, busy, dc, rst, &mut delay, None).expect("eink initalize error");
Epd2in13bc::new(&mut spi, busy, dc, rst, None).expect("eink initalize error");

println!("Test all the rotations");
let mut display = Display2in13bc::default();
Expand Down Expand Up @@ -137,12 +138,13 @@ fn main() -> Result<(), SPIError> {

// we used three colors, so we need to update both bw-buffer and chromatic-buffer

epd2in13.update_color_frame(
&mut spi,
&mut delay,
display.bw_buffer(),
display.chromatic_buffer(),
)?;
epd2in13
.update_color_frame(
&mut spi,
display.bw_buffer(),
display.chromatic_buffer(),
).await
.map_err(anyhow::Error::msg)?;
epd2in13
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
Expand All @@ -152,16 +154,23 @@ fn main() -> Result<(), SPIError> {

// clear both bw buffer and chromatic buffer
display.clear(TriColor::White).ok();
epd2in13.update_color_frame(
&mut spi,
&mut delay,
display.bw_buffer(),
display.chromatic_buffer(),
)?;
epd2in13.display_frame(&mut spi, &mut delay)?;
epd2in13
.update_color_frame(
&mut spi,
display.bw_buffer(),
display.chromatic_buffer(),
).await
.map_err(anyhow::Error::msg)?;
epd2in13
.display_frame(&mut spi)
.await
.map_err(anyhow::Error::msg)?;

println!("Finished tests - going to sleep");
epd2in13.sleep(&mut spi, &mut delay)
epd2in13
.sleep(&mut spi)
.await
.map_err(anyhow::Error::msg)
}

fn draw_text(display: &mut Display2in13bc, text: &str, x: i32, y: i32) {
Expand Down
Loading
Loading