From 6e703c952618aac48a5d4b9c7605bde8e0429e15 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 (alpha) Wait for official release. Signed-off-by: Daniel Schaefer --- Cargo.toml | 2 +- src/devices.rs | 35 ++++++++++++++++++++--------------- src/lib.rs | 26 +++++++++++++------------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 18e6009..6f066af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/stillinbeta/is31fl3741" readme = "README.md" [dependencies] -embedded-hal = "0.2.7" +embedded-hal = "1.0.0-alpha.11" embedded-graphics-core = { optional = true, version = "0.4.0" } [package.metadata.docs.rs] diff --git a/src/devices.rs b/src/devices.rs index 301f19f..602836f 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -1,12 +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::delay::DelayUs; #[allow(unused_imports)] -use embedded_hal::blocking::i2c::Write; +use embedded_hal::i2c::{Error, I2c}; #[cfg(feature = "adafruit_rgb_13x9")] pub struct AdafruitRGB13x9 { @@ -17,9 +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: I2c, { fn bounding_box(&self) -> Rectangle { Rectangle::new(Point::zero(), Size::new(13, 9)) @@ -27,13 +26,12 @@ where } #[cfg(all(feature = "adafruit_rgb_13x9", feature = "embedded_graphics"))] -impl DrawTarget for AdafruitRGB13x9 +impl DrawTarget for AdafruitRGB13x9 where - I2C: Write, - I2cError:, + I2C: I2c, { type Color = Rgb888; - type Error = Error; + type Error = Is31Error; fn draw_iter(&mut self, pixels: I) -> Result<(), Self::Error> where @@ -54,9 +52,9 @@ where } #[cfg(feature = "adafruit_rgb_13x9")] -impl AdafruitRGB13x9 +impl AdafruitRGB13x9 where - I2C: Write, + I2C: I2c, { pub fn unwrap(self) -> I2C { self.device.i2c @@ -204,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)?; @@ -212,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)?; diff --git a/src/lib.rs b/src/lib.rs index 1167555..0abca12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,9 +2,8 @@ #![doc = include_str!("../README.md")] /// Preconfigured devices pub mod devices; - -use embedded_hal::blocking::delay::DelayMs; -use embedded_hal::blocking::i2c::Write; +use embedded_hal::delay::DelayUs; +use embedded_hal::i2c::{Error, I2c}; /// A struct to integrate with a new IS31FL3741 powered device. pub struct IS31FL3741 { @@ -22,9 +21,9 @@ pub struct IS31FL3741 { pub calc_pixel: fn(x: u8, y: u8) -> (u8, u8), } -impl IS31FL3741 +impl IS31FL3741 where - I2C: Write, + I2C: I2c, { /// Fill the display with a single brightness. The brightness should range from 0 to 255. pub fn fill(&mut self, brightness: u8) -> Result<(), I2cError> { @@ -46,7 +45,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); @@ -55,15 +54,16 @@ where self.shutdown(false)?; Ok(()) } + /// 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 }; @@ -80,7 +80,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(()) @@ -151,15 +151,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) } }