Skip to content

Commit

Permalink
Merge pull request #166 from caemor/embbedded-hal-v1.0
Browse files Browse the repository at this point in the history
Update to embedded hal 1.0-rc.1
  • Loading branch information
caemor authored Sep 28, 2023
2 parents 97425d5 + d38d47b commit cff9130
Show file tree
Hide file tree
Showing 29 changed files with 457 additions and 578 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ jobs:
- name: Check Fmt
run: cargo fmt --all -- --check
- name: Build lib
run: cargo check --all-targets --verbose
- name: Clippy
run: cargo clippy --all-targets -- -D warnings -A clippy::new_ret_no_self
run: cargo check --lib --verbose
- name: Build examples
continue-on-error: true
run: cargo build --examples --all-targets --verbose
- name: Run tests
run: cargo test --verbose
- name: Build docs
run: cargo doc
- name: Clippy
continue-on-error: true
run: cargo clippy --all-targets -- -D warnings -A clippy::new_ret_no_self

14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ edition = "2021"
# travis-ci = { repository = "caemor/epd-waveshare" }

[dependencies]
embedded-graphics-core = { version = "0.3.2", optional = true}
embedded-hal = {version = "0.2.4", features = ["unproven"]}
embedded-graphics-core = { version = "0.4", optional = true }
embedded-hal = { version = "1.0.0-rc.1" }
bit_field = "0.10.1"

[dev-dependencies]
embedded-graphics = "0.7.1"
embedded-graphics = "0.8"

embedded-hal-mock = "0.8"
embedded-hal-mock = { git = "https://github.com/newAM/embedded-hal-mock", branch = "eh1-rc.1", default-features = false, features = [
"eh1",
] }
# embedded-hal-mock = "0.9"

[target.'cfg(unix)'.dev-dependencies]
linux-embedded-hal = "0.3"
# linux-embedded-hal = "0.3"
linux-embedded-hal = { git = "https://github.com/rust-embedded/linux-embedded-hal" }

[[example]]
name = "epd1in54_no_graphics"
Expand Down
18 changes: 9 additions & 9 deletions examples/epd1in54_no_graphics.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#![deny(warnings)]

use embedded_hal::prelude::*;
use embedded_hal::delay::DelayUs;
use epd_waveshare::{epd1in54::Epd1in54, prelude::*};
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Delay, Pin, Spidev,
Delay, SPIError, Spidev, 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<(), std::io::Error> {
fn main() -> Result<(), SPIError> {
// Configure SPI
// SPI settings are from eink-waveshare-rs documenation
let mut spi = Spidev::open("/dev/spidev0.0")?;
Expand All @@ -24,7 +24,7 @@ fn main() -> Result<(), std::io::Error> {
spi.configure(&options).expect("spi configuration");

// Configure Digital I/O Pin to be used as Chip Select for SPI
let cs_pin = Pin::new(26); //BCM7 CE0
let cs_pin = SysfsPin::new(26); //BCM7 CE0
cs_pin.export().expect("cs_pin export");
while !cs_pin.is_exported() {}
cs_pin
Expand All @@ -33,21 +33,21 @@ fn main() -> Result<(), std::io::Error> {
cs_pin.set_value(1).expect("cs_pin Value set to 1");

// Configure Busy Input Pin
let busy = Pin::new(5); //pin 29
let busy = SysfsPin::new(5); //pin 29
busy.export().expect("busy export");
while !busy.is_exported() {}
busy.set_direction(Direction::In).expect("busy Direction");
//busy.set_value(1).expect("busy Value set to 1");

// Configure Data/Command OutputPin
let dc = Pin::new(6); //pin 31 //bcm6
let dc = SysfsPin::new(6); //pin 31 //bcm6
dc.export().expect("dc export");
while !dc.is_exported() {}
dc.set_direction(Direction::Out).expect("dc Direction");
dc.set_value(1).expect("dc Value set to 1");

// Configure Reset OutputPin
let rst = Pin::new(16); //pin 36 //bcm16
let rst = SysfsPin::new(16); //pin 36 //bcm16
rst.export().expect("rst export");
while !rst.is_exported() {}
rst.set_direction(Direction::Out).expect("rst Direction");
Expand All @@ -58,7 +58,7 @@ fn main() -> Result<(), std::io::Error> {

// 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, cs_pin, busy, dc, rst, &mut delay, Some(5))?;
let mut epd = Epd1in54::new(&mut spi, busy, dc, rst, &mut delay, Some(5))?;

// Clear the full screen
epd.clear_frame(&mut spi, &mut delay)?;
Expand Down Expand Up @@ -98,7 +98,7 @@ fn main() -> Result<(), std::io::Error> {

// Display updated frame
epd.display_frame(&mut spi, &mut delay)?;
delay.delay_ms(5000u16);
delay.delay_ms(5000);

// Set the EPD to sleep
epd.sleep(&mut spi, &mut delay)?;
Expand Down
20 changes: 10 additions & 10 deletions examples/epd2in13_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use embedded_graphics::{
primitives::{Circle, Line, PrimitiveStyle},
text::{Baseline, Text, TextStyleBuilder},
};
use embedded_hal::prelude::*;
use embedded_hal::delay::DelayUs;
use epd_waveshare::{
color::*,
epd2in13_v2::{Display2in13, Epd2in13},
Expand All @@ -16,15 +16,15 @@ use epd_waveshare::{
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Delay, Pin, Spidev,
Delay, SPIError, Spidev, 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<(), std::io::Error> {
fn main() -> Result<(), SPIError> {
// Configure SPI
// Settings are taken from
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");
Expand All @@ -36,25 +36,25 @@ fn main() -> Result<(), std::io::Error> {
spi.configure(&options).expect("spi configuration");

// Configure Digital I/O Pin to be used as Chip Select for SPI
let cs = Pin::new(26); //BCM7 CE0
let cs = SysfsPin::new(26); //BCM7 CE0
cs.export().expect("cs export");
while !cs.is_exported() {}
cs.set_direction(Direction::Out).expect("CS Direction");
cs.set_value(1).expect("CS Value set to 1");

let busy = Pin::new(24); // GPIO 24, board J-18
let busy = SysfsPin::new(24); // GPIO 24, board J-18
busy.export().expect("busy export");
while !busy.is_exported() {}
busy.set_direction(Direction::In).expect("busy Direction");
//busy.set_value(1).expect("busy Value set to 1");

let dc = Pin::new(25); // GPIO 25, board J-22
let dc = SysfsPin::new(25); // GPIO 25, board J-22
dc.export().expect("dc export");
while !dc.is_exported() {}
dc.set_direction(Direction::Out).expect("dc Direction");
dc.set_value(1).expect("dc Value set to 1");

let rst = Pin::new(17); // GPIO 17, board J-11
let rst = SysfsPin::new(17); // GPIO 17, board J-11
rst.export().expect("rst export");
while !rst.is_exported() {}
rst.set_direction(Direction::Out).expect("rst Direction");
Expand All @@ -63,7 +63,7 @@ fn main() -> Result<(), std::io::Error> {
let mut delay = Delay {};

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

//println!("Test all the rotations");
let mut display = Display2in13::default();
Expand All @@ -84,7 +84,7 @@ fn main() -> Result<(), std::io::Error> {
epd2in13
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
delay.delay_ms(5000u16);
delay.delay_ms(5000);

//println!("Now test new graphics with default rotation and some special stuff:");
display.clear(Color::White).ok();
Expand Down Expand Up @@ -136,7 +136,7 @@ fn main() -> Result<(), std::io::Error> {
epd2in13
.update_and_display_frame(&mut spi, display.buffer(), &mut delay)
.expect("display frame new graphics");
delay.delay_ms(1_000u16);
delay.delay_ms(1_000);
}

// Show a spinning bar without any delay between frames. Shows how «fast»
Expand Down
22 changes: 11 additions & 11 deletions examples/epd2in13bc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use embedded_graphics::{
primitives::{Circle, Line, PrimitiveStyle},
text::{Baseline, Text, TextStyleBuilder},
};
use embedded_hal::prelude::*;
use embedded_hal::delay::DelayUs;
use epd_waveshare::{
color::*,
epd2in13bc::{Display2in13bc, Epd2in13bc},
Expand All @@ -16,7 +16,7 @@ use epd_waveshare::{
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Delay, Pin, Spidev,
Delay, SPIError, Spidev, SysfsPin,
};

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

fn main() -> Result<(), std::io::Error> {
let busy = Pin::new(24); // GPIO 24, board J-18
fn main() -> Result<(), SPIError> {
let busy = SysfsPin::new(24); // GPIO 24, board J-18
busy.export().expect("busy export");
while !busy.is_exported() {}
busy.set_direction(Direction::In).expect("busy Direction");

let dc = Pin::new(25); // GPIO 25, board J-22
let dc = SysfsPin::new(25); // GPIO 25, board J-22
dc.export().expect("dc export");
while !dc.is_exported() {}
dc.set_direction(Direction::Out).expect("dc Direction");
// dc.set_value(1).expect("dc Value set to 1");

let rst = Pin::new(17); // GPIO 17, board J-11
let rst = SysfsPin::new(17); // GPIO 17, board J-11
rst.export().expect("rst export");
while !rst.is_exported() {}
rst.set_direction(Direction::Out).expect("rst Direction");
// rst.set_value(1).expect("rst Value set to 1");

// Configure Digital I/O Pin to be used as Chip Select for SPI
let cs = Pin::new(26); // CE0, board J-24, GPIO 8 -> doesn work. use this from 2in19 example which works
let cs = SysfsPin::new(26); // CE0, board J-24, GPIO 8 -> doesn work. use this from 2in19 example which works
cs.export().expect("cs export");
while !cs.is_exported() {}
cs.set_direction(Direction::Out).expect("CS Direction");
Expand All @@ -71,8 +71,8 @@ fn main() -> Result<(), std::io::Error> {

let mut delay = Delay {};

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

println!("Test all the rotations");
let mut display = Display2in13bc::default();
Expand All @@ -98,7 +98,7 @@ fn main() -> Result<(), std::io::Error> {
.expect("display frame new graphics");

println!("First frame done. Waiting 5s");
delay.delay_ms(5000u16);
delay.delay_ms(5000);

println!("Now test new graphics with default rotation and three colors:");
display.clear(TriColor::White).ok();
Expand Down Expand Up @@ -148,7 +148,7 @@ fn main() -> Result<(), std::io::Error> {
.expect("display frame new graphics");

println!("Second frame done. Waiting 5s");
delay.delay_ms(5000u16);
delay.delay_ms(5000);

// clear both bw buffer and chromatic buffer
display.clear(TriColor::White).ok();
Expand Down
20 changes: 10 additions & 10 deletions examples/epd4in2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use embedded_graphics::{
primitives::{Circle, Line, PrimitiveStyleBuilder},
text::{Baseline, Text, TextStyleBuilder},
};
use embedded_hal::prelude::*;
use embedded_hal::delay::DelayUs;
use epd_waveshare::{
color::*,
epd4in2::{Display4in2, Epd4in2},
Expand All @@ -16,14 +16,14 @@ use epd_waveshare::{
use linux_embedded_hal::{
spidev::{self, SpidevOptions},
sysfs_gpio::Direction,
Delay, Pin, Spidev,
Delay, SPIError, Spidev, 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<(), std::io::Error> {
fn main() -> Result<(), SPIError> {
// Configure SPI
// Settings are taken from
let mut spi = Spidev::open("/dev/spidev0.0").expect("spidev directory");
Expand All @@ -35,25 +35,25 @@ fn main() -> Result<(), std::io::Error> {
spi.configure(&options).expect("spi configuration");

// Configure Digital I/O Pin to be used as Chip Select for SPI
let cs = Pin::new(26); //BCM7 CE0
let cs = SysfsPin::new(26); //BCM7 CE0
cs.export().expect("cs export");
while !cs.is_exported() {}
cs.set_direction(Direction::Out).expect("CS Direction");
cs.set_value(1).expect("CS Value set to 1");

let busy = Pin::new(5); //pin 29
let busy = SysfsPin::new(5); //pin 29
busy.export().expect("busy export");
while !busy.is_exported() {}
busy.set_direction(Direction::In).expect("busy Direction");
//busy.set_value(1).expect("busy Value set to 1");

let dc = Pin::new(6); //pin 31 //bcm6
let dc = SysfsPin::new(6); //pin 31 //bcm6
dc.export().expect("dc export");
while !dc.is_exported() {}
dc.set_direction(Direction::Out).expect("dc Direction");
dc.set_value(1).expect("dc Value set to 1");

let rst = Pin::new(16); //pin 36 //bcm16
let rst = SysfsPin::new(16); //pin 36 //bcm16
rst.export().expect("rst export");
while !rst.is_exported() {}
rst.set_direction(Direction::Out).expect("rst Direction");
Expand All @@ -62,7 +62,7 @@ fn main() -> Result<(), std::io::Error> {
let mut delay = Delay {};

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

println!("Test all the rotations");
let mut display = Display4in2::default();
Expand All @@ -83,7 +83,7 @@ fn main() -> Result<(), std::io::Error> {
epd4in2
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");
delay.delay_ms(5000u16);
delay.delay_ms(5000);

println!("Now test new graphics with default rotation and some special stuff");
display.clear(Color::White).ok();
Expand Down Expand Up @@ -143,7 +143,7 @@ fn main() -> Result<(), std::io::Error> {
.display_frame(&mut spi, &mut delay)
.expect("display frame new graphics");

delay.delay_ms(1_000u16);
delay.delay_ms(1_000);
}

println!("Finished tests - going to sleep");
Expand Down
Loading

0 comments on commit cff9130

Please sign in to comment.