From e7a2a92be1a763cee982490585a1a2802b463bbf Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Sun, 27 Aug 2023 16:58:17 +0800 Subject: [PATCH] Update embedded-hal to 1.0 Signed-off-by: Daniel Schaefer --- Cargo.toml | 2 +- examples/adafruit_rgb/Cargo.toml | 2 +- examples/ledmatrix/Cargo.toml | 2 +- examples/ledmatrix/examples/main.rs | 2 +- src/devices.rs | 48 ++++++++++++++--------------- src/lib.rs | 26 ++++++++-------- 6 files changed, 40 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bcda029..58d1578 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/FrameworkComputer/is31fl3741-rs" readme = "README.md" [dependencies] -embedded-hal = "0.2.7" +embedded-hal = "1.0.0" embedded-graphics-core = { optional = true, version = "0.4.0" } [package.metadata.docs.rs] diff --git a/examples/adafruit_rgb/Cargo.toml b/examples/adafruit_rgb/Cargo.toml index 96a77cb..2b43493 100644 --- a/examples/adafruit_rgb/Cargo.toml +++ b/examples/adafruit_rgb/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] is31fl3741 = { path = "../../", features = [ "adafruit_rgb_13x9", "embedded_graphics" ] } -embedded-hal = "0.2.7" +embedded-hal = "1.0.0" cortex-m-rt = "0.7.3" cortex-m = "0.7.7" fugit = "0.3.7" diff --git a/examples/ledmatrix/Cargo.toml b/examples/ledmatrix/Cargo.toml index 01a82ba..b34bdb5 100644 --- a/examples/ledmatrix/Cargo.toml +++ b/examples/ledmatrix/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] is31fl3741 = { path = "../../", features = ["framework_ledmatrix"] } -embedded-hal = "0.2.7" +embedded-hal = "1.0.0" cortex-m-rt = "0.7.3" cortex-m = "0.7.7" fugit = "0.3.7" diff --git a/examples/ledmatrix/examples/main.rs b/examples/ledmatrix/examples/main.rs index 3e4ed4b..351f7ca 100644 --- a/examples/ledmatrix/examples/main.rs +++ b/examples/ledmatrix/examples/main.rs @@ -3,7 +3,7 @@ #![no_main] #![allow(clippy::needless_range_loop)] -use embedded_hal::digital::v2::{InputPin, OutputPin}; +use embedded_hal::digital::{InputPin, OutputPin}; //use rp2040_hal::{ // gpio::bank0::Gpio29, //}; diff --git a/src/devices.rs b/src/devices.rs index 4db5db6..0983fc5 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -1,13 +1,11 @@ // #[cfg_attr(docsrs, doc(cfg(feature = "adafruit_rgb_13x9")))] -#[allow(unused_imports)] -use crate::{Error, IS31FL3741}; +use crate::{Is31Error, IS31FL3741}; #[allow(unused_imports)] use core::convert::TryFrom; #[allow(unused_imports)] -use embedded_hal::blocking::delay::DelayMs; -use embedded_hal::blocking::i2c::Read; +use embedded_hal::delay::DelayNs; #[allow(unused_imports)] -use embedded_hal::blocking::i2c::Write; +use embedded_hal::i2c::{Error, I2c}; #[cfg(feature = "adafruit_rgb_13x9")] pub struct AdafruitRGB13x9 { @@ -18,10 +16,9 @@ pub struct AdafruitRGB13x9 { use embedded_graphics_core::{pixelcolor::Rgb888, prelude::*, primitives::Rectangle}; #[cfg(all(feature = "adafruit_rgb_13x9", feature = "embedded_graphics"))] -impl Dimensions for AdafruitRGB13x9 +impl Dimensions for AdafruitRGB13x9 where - I2C: Write, - I2C: Read, + I2C: I2c, { fn bounding_box(&self) -> Rectangle { Rectangle::new(Point::zero(), Size::new(13, 9)) @@ -29,14 +26,12 @@ where } #[cfg(all(feature = "adafruit_rgb_13x9", feature = "embedded_graphics"))] -impl DrawTarget for AdafruitRGB13x9 +impl DrawTarget for AdafruitRGB13x9 where - I2C: Write, - I2C: Read, - I2cError:, + I2C: I2c, { type Color = Rgb888; - type Error = Error; + type Error = Is31Error; fn draw_iter(&mut self, pixels: I) -> Result<(), Self::Error> where @@ -57,10 +52,9 @@ where } #[cfg(feature = "adafruit_rgb_13x9")] -impl AdafruitRGB13x9 +impl AdafruitRGB13x9 where - I2C: Write, - I2C: Read, + I2C: I2c, { pub fn unwrap(self) -> I2C { self.device.i2c @@ -208,7 +202,14 @@ where } } - pub fn pixel_rgb(&mut self, x: u8, y: u8, r: u8, g: u8, b: u8) -> Result<(), Error> { + pub fn pixel_rgb( + &mut self, + x: u8, + y: u8, + r: u8, + g: u8, + b: u8, + ) -> Result<(), Is31Error> { let x = x + y * 13; self.device.pixel(x, 2, r)?; self.device.pixel(x, 1, g)?; @@ -216,11 +217,11 @@ where Ok(()) } - pub fn setup>(&mut self, delay: &mut DEL) -> Result<(), Error> { + pub fn setup(&mut self, delay: &mut DEL) -> Result<(), Is31Error> { self.device.setup(delay) } - pub fn fill_rgb(&mut self, r: u8, g: u8, b: u8) -> Result<(), Error> { + pub fn fill_rgb(&mut self, r: u8, g: u8, b: u8) -> Result<(), Is31Error> { for x in 0..13 { for y in 0..9 { self.pixel_rgb(x, y, r, g, b)?; @@ -555,10 +556,9 @@ pub struct LedMatrix { } #[cfg(feature = "framework_ledmatrix")] -impl LedMatrix +impl LedMatrix where - I2C: Write, - I2C: Read, + I2C: I2c, { pub fn unwrap(self) -> I2C { self.device.i2c @@ -581,14 +581,14 @@ where } } - pub fn setup>(&mut self, delay: &mut DEL) -> Result<(), Error> { + pub fn setup(&mut self, delay: &mut DEL) -> Result<(), Is31Error> { self.device.setup(delay)?; Ok(()) } /// Fills the matrix with a _raw_ brightness value, i.e. without gamma /// correction, to show the native PWM values. - pub fn fill_brightness(&mut self, brightness: u8) -> Result<(), Error> { + pub fn fill_brightness(&mut self, brightness: u8) -> Result<(), Is31Error> { for x in 0..self.device.width { for y in 0..self.device.height { self.device.pixel(x, y, brightness)?; diff --git a/src/lib.rs b/src/lib.rs index 15a0569..638016f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,9 +3,8 @@ /// Preconfigured devices pub mod devices; -use embedded_hal::blocking::delay::DelayMs; -use embedded_hal::blocking::i2c::Read; -use embedded_hal::blocking::i2c::Write; +use embedded_hal::delay::DelayNs; +use embedded_hal::i2c::{Error, I2c}; /// A struct to integrate with a new IS31FL3741 powered device. pub struct IS31FL3741 { @@ -23,10 +22,9 @@ pub struct IS31FL3741 { pub calc_pixel: fn(x: u8, y: u8) -> (u8, u8), } -impl IS31FL3741 +impl IS31FL3741 where - I2C: Write, - I2C: Read, + I2C: I2c, { /// Fill all pixels of the display at once. The brightness should range from 0 to 255. pub fn fill_matrix(&mut self, brightnesses: &[u8]) -> Result<(), I2cError> { @@ -64,7 +62,7 @@ where /// 2. The chip will be put in shutdown mode /// 3. The chip will be configured to use the maximum voltage /// 4. The chip will be taken out of shutdown mode - pub fn setup>(&mut self, delay: &mut DEL) -> Result<(), Error> { + pub fn setup(&mut self, delay: &mut DEL) -> Result<(), Is31Error> { self.reset(delay)?; self.shutdown(true)?; delay.delay_ms(10); @@ -84,12 +82,12 @@ where /// Set the brightness at a specific x,y coordinate. Just like the [fill method](Self::fill) /// the brightness should range from 0 to 255. If the coordinate is out of range then the /// function will return an error of [InvalidLocation](Error::InvalidLocation). - pub fn pixel(&mut self, x: u8, y: u8, brightness: u8) -> Result<(), Error> { + pub fn pixel(&mut self, x: u8, y: u8, brightness: u8) -> Result<(), Is31Error> { if x > self.width { - return Err(Error::InvalidLocation(x)); + return Err(Is31Error::InvalidLocation(x)); } if y > self.height { - return Err(Error::InvalidLocation(y)); + return Err(Is31Error::InvalidLocation(y)); } let (pixel, frame) = (self.calc_pixel)(x, y); let bank = if frame == 0 { Page::Pwm1 } else { Page::Pwm2 }; @@ -106,7 +104,7 @@ where /// Send a reset message to the slave device. Delay is something that your device's HAL should /// provide which allows for the process to sleep for a certain amount of time (in this case 10 /// MS to perform a reset). - pub fn reset>(&mut self, delay: &mut DEL) -> Result<(), I2cError> { + pub fn reset(&mut self, delay: &mut DEL) -> Result<(), I2cError> { self.write_register(Page::Config, addresses::RESET_REGISTER, addresses::RESET)?; delay.delay_ms(10); Ok(()) @@ -207,15 +205,15 @@ pub mod addresses { } #[derive(Clone, Copy, Debug)] -pub enum Error { +pub enum Is31Error { I2cError(I2cError), InvalidLocation(u8), InvalidFrame(u8), } -impl From for Error { +impl From for Is31Error { fn from(error: E) -> Self { - Error::I2cError(error) + Is31Error::I2cError(error) } }