From 2a3cd1ae0147d02cbcdc9cf83e75950ea05b6e28 Mon Sep 17 00:00:00 2001 From: Caemor <11088935+caemor@users.noreply.github.com> Date: Mon, 26 Oct 2020 21:09:49 +0100 Subject: [PATCH] Update lib to embedded_hal 1.0a2 --- Cargo.toml | 2 +- examples/epd1in54_no_graphics.rs | 1 - src/epd1in54/mod.rs | 2 +- src/epd1in54b/mod.rs | 4 ++-- src/epd2in13_v2/mod.rs | 2 +- src/epd2in9/mod.rs | 2 +- src/epd2in9bc/mod.rs | 4 ++-- src/epd4in2/mod.rs | 4 ++-- src/epd7in5/mod.rs | 4 ++-- src/epd7in5_v2/mod.rs | 2 +- src/interface.rs | 32 ++++++++++++++++---------------- src/traits.rs | 2 +- 12 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb127c6..b81cc72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ edition = "2018" [dependencies] embedded-graphics = { version = "0.6.1", optional = true} -embedded-hal = {version = "0.2.3", features = ["unproven"]} +embedded-hal = "1.0.0-alpha.2" bit_field = "0.10.1" [dev-dependencies] diff --git a/examples/epd1in54_no_graphics.rs b/examples/epd1in54_no_graphics.rs index 7fd30ae..7fd2025 100644 --- a/examples/epd1in54_no_graphics.rs +++ b/examples/epd1in54_no_graphics.rs @@ -1,6 +1,5 @@ #![deny(warnings)] -use embedded_hal::prelude::*; use epd_waveshare::{epd1in54::EPD1in54, prelude::*}; use linux_embedded_hal::{ spidev::{self, SpidevOptions}, diff --git a/src/epd1in54/mod.rs b/src/epd1in54/mod.rs index e4f833f..849edff 100644 --- a/src/epd1in54/mod.rs +++ b/src/epd1in54/mod.rs @@ -51,7 +51,7 @@ const IS_BUSY_LOW: bool = false; use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::*, + digital::*, }; use crate::type_a::{ diff --git a/src/epd1in54b/mod.rs b/src/epd1in54b/mod.rs index 11fd985..0a2a835 100644 --- a/src/epd1in54b/mod.rs +++ b/src/epd1in54b/mod.rs @@ -2,7 +2,7 @@ use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::*, + digital::*, }; use crate::interface::DisplayInterface; @@ -64,7 +64,7 @@ where // power on self.command(spi, Command::POWER_ON)?; - delay.delay_ms(5); + delay.try_delay_ms(5); self.wait_until_idle(); // set the panel settings diff --git a/src/epd2in13_v2/mod.rs b/src/epd2in13_v2/mod.rs index b636c9f..6d963a1 100644 --- a/src/epd2in13_v2/mod.rs +++ b/src/epd2in13_v2/mod.rs @@ -10,7 +10,7 @@ use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::{InputPin, OutputPin}, + digital::{InputPin, OutputPin}, }; use crate::buffer_len; diff --git a/src/epd2in9/mod.rs b/src/epd2in9/mod.rs index 46a9155..fb9477d 100644 --- a/src/epd2in9/mod.rs +++ b/src/epd2in9/mod.rs @@ -51,7 +51,7 @@ const IS_BUSY_LOW: bool = false; use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::*, + digital::*, }; use crate::type_a::{ diff --git a/src/epd2in9bc/mod.rs b/src/epd2in9bc/mod.rs index 9bab93b..4616c63 100644 --- a/src/epd2in9bc/mod.rs +++ b/src/epd2in9bc/mod.rs @@ -55,7 +55,7 @@ //!``` use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::*, + digital::*, }; use crate::interface::DisplayInterface; @@ -119,7 +119,7 @@ where // power on self.command(spi, Command::POWER_ON)?; - delay.delay_ms(5); + delay.try_delay_ms(5); self.wait_until_idle(); // set the panel settings diff --git a/src/epd4in2/mod.rs b/src/epd4in2/mod.rs index 8894132..388f64f 100644 --- a/src/epd4in2/mod.rs +++ b/src/epd4in2/mod.rs @@ -51,7 +51,7 @@ use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::*, + digital::*, }; use crate::interface::DisplayInterface; @@ -120,7 +120,7 @@ where // power on self.command(spi, Command::POWER_ON)?; - delay.delay_ms(5); + delay.try_delay_ms(5); self.wait_until_idle(); // set the panel settings diff --git a/src/epd7in5/mod.rs b/src/epd7in5/mod.rs index cdc142e..34a19f5 100644 --- a/src/epd7in5/mod.rs +++ b/src/epd7in5/mod.rs @@ -8,7 +8,7 @@ use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::{InputPin, OutputPin}, + digital::{InputPin, OutputPin}, }; use crate::color::Color; @@ -70,7 +70,7 @@ where // Power on self.command(spi, Command::POWER_ON)?; - delay.delay_ms(5); + delay.try_delay_ms(5); self.wait_until_idle(); // Set the clock frequency to 50Hz (default) diff --git a/src/epd7in5_v2/mod.rs b/src/epd7in5_v2/mod.rs index 3c0fcc4..3e3618e 100644 --- a/src/epd7in5_v2/mod.rs +++ b/src/epd7in5_v2/mod.rs @@ -12,7 +12,7 @@ use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::{InputPin, OutputPin}, + digital::{InputPin, OutputPin}, }; use crate::color::Color; diff --git a/src/interface.rs b/src/interface.rs index 58fbebb..70b8b47 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -2,7 +2,7 @@ use crate::traits::Command; use core::marker::PhantomData; use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::*, + digital::*, }; /// The Connection Interface of all (?) Waveshare EPD-Devices @@ -43,7 +43,7 @@ where /// Enables direct interaction with the device with the help of [data()](DisplayInterface::data()) pub(crate) fn cmd(&mut self, spi: &mut SPI, command: T) -> Result<(), SPI::Error> { // low for commands - let _ = self.dc.set_low(); + let _ = self.dc.try_set_low(); // Transfer the command over spi self.write(spi, &[command.address()]) @@ -54,7 +54,7 @@ where /// Enables direct interaction with the device with the help of [command()](EPD4in2::command()) pub(crate) fn data(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { // high for data - let _ = self.dc.set_high(); + let _ = self.dc.try_set_high(); // Transfer data (u8-array) over spi self.write(spi, data) @@ -83,7 +83,7 @@ where repetitions: u32, ) -> Result<(), SPI::Error> { // high for data - let _ = self.dc.set_high(); + let _ = self.dc.try_set_high(); // Transfer data (u8) over spi for _ in 0..repetitions { self.write(spi, &[val])?; @@ -94,21 +94,21 @@ where // spi write helper/abstraction function fn write(&mut self, spi: &mut SPI, data: &[u8]) -> Result<(), SPI::Error> { // activate spi with cs low - let _ = self.cs.set_low(); + let _ = self.cs.try_set_low(); // transfer spi data // Be careful!! Linux has a default limit of 4096 bytes per spi transfer // see https://raspberrypi.stackexchange.com/questions/65595/spi-transfer-fails-with-buffer-size-greater-than-4096 if cfg!(target_os = "linux") { for data_chunk in data.chunks(4096) { - spi.write(data_chunk)?; + spi.try_write(data_chunk)?; } } else { - spi.write(data)?; + spi.try_write(data)?; } // deativate spi with cs high - let _ = self.cs.set_high(); + let _ = self.cs.try_set_high(); Ok(()) } @@ -151,8 +151,8 @@ where /// Most likely there was a mistake with the 2in9 busy connection /// //TODO: use the #cfg feature to make this compile the right way for the certain types pub(crate) fn is_busy(&self, is_busy_low: bool) -> bool { - (is_busy_low && self.busy.is_low().unwrap_or(false)) - || (!is_busy_low && self.busy.is_high().unwrap_or(false)) + (is_busy_low && self.busy.try_is_low().unwrap_or(false)) + || (!is_busy_low && self.busy.try_is_high().unwrap_or(false)) } /// Resets the device. @@ -163,14 +163,14 @@ where /// Most displays seem to require keeping it low for 10ms, but the 7in5_v2 only seems to reset /// properly with 2ms pub(crate) fn reset>(&mut self, delay: &mut DELAY, duration: u8) { - let _ = self.rst.set_high(); - delay.delay_ms(10); + let _ = self.rst.try_set_high(); + delay.try_delay_ms(10); - let _ = self.rst.set_low(); - delay.delay_ms(duration); - let _ = self.rst.set_high(); + let _ = self.rst.try_set_low(); + delay.try_delay_ms(duration); + let _ = self.rst.try_set_high(); //TODO: the upstream libraries always sleep for 200ms here // 10ms works fine with just for the 7in5_v2 but this needs to be validated for other devices - delay.delay_ms(200); + delay.try_delay_ms(200); } } diff --git a/src/traits.rs b/src/traits.rs index 360e63c..e12fb9f 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -2,7 +2,7 @@ use crate::color::Color; use core::marker::Sized; use embedded_hal::{ blocking::{delay::*, spi::Write}, - digital::v2::*, + digital::*, }; /// All commands need to have this trait which gives the address of the command