Skip to content

Commit

Permalink
Update embedded-hal to 1.0
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Schaefer <[email protected]>
  • Loading branch information
JohnAZoidberg committed Oct 14, 2024
1 parent 4a84b89 commit e7a2a92
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/adafruit_rgb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/ledmatrix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/ledmatrix/examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
//};
Expand Down
48 changes: 24 additions & 24 deletions src/devices.rs
Original file line number Diff line number Diff line change
@@ -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<I2C> {
Expand All @@ -18,25 +16,22 @@ pub struct AdafruitRGB13x9<I2C> {
use embedded_graphics_core::{pixelcolor::Rgb888, prelude::*, primitives::Rectangle};

#[cfg(all(feature = "adafruit_rgb_13x9", feature = "embedded_graphics"))]
impl<I2C, I2cError> Dimensions for AdafruitRGB13x9<I2C>
impl<I2C: I2c, I2cError: Error> Dimensions for AdafruitRGB13x9<I2C>
where
I2C: Write<Error = I2cError>,
I2C: Read<Error = I2cError>,
I2C: I2c<Error = I2cError>,
{
fn bounding_box(&self) -> Rectangle {
Rectangle::new(Point::zero(), Size::new(13, 9))
}
}

#[cfg(all(feature = "adafruit_rgb_13x9", feature = "embedded_graphics"))]
impl<I2C, I2cError> DrawTarget for AdafruitRGB13x9<I2C>
impl<I2C: I2c, I2cError: Error> DrawTarget for AdafruitRGB13x9<I2C>
where
I2C: Write<Error = I2cError>,
I2C: Read<Error = I2cError>,
I2cError:,
I2C: I2c<Error = I2cError>,
{
type Color = Rgb888;
type Error = Error<I2cError>;
type Error = Is31Error<I2cError>;

fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where
Expand All @@ -57,10 +52,9 @@ where
}

#[cfg(feature = "adafruit_rgb_13x9")]
impl<I2C, I2cError> AdafruitRGB13x9<I2C>
impl<I2C: I2c, I2cError: Error> AdafruitRGB13x9<I2C>
where
I2C: Write<Error = I2cError>,
I2C: Read<Error = I2cError>,
I2C: I2c<Error = I2cError>,
{
pub fn unwrap(self) -> I2C {
self.device.i2c
Expand Down Expand Up @@ -208,19 +202,26 @@ where
}
}

pub fn pixel_rgb(&mut self, x: u8, y: u8, r: u8, g: u8, b: u8) -> Result<(), Error<I2cError>> {
pub fn pixel_rgb(
&mut self,
x: u8,
y: u8,
r: u8,
g: u8,
b: u8,
) -> Result<(), Is31Error<I2cError>> {
let x = x + y * 13;
self.device.pixel(x, 2, r)?;
self.device.pixel(x, 1, g)?;
self.device.pixel(x, 0, b)?;
Ok(())
}

pub fn setup<DEL: DelayMs<u8>>(&mut self, delay: &mut DEL) -> Result<(), Error<I2cError>> {
pub fn setup<DEL: DelayNs>(&mut self, delay: &mut DEL) -> Result<(), Is31Error<I2cError>> {
self.device.setup(delay)
}

pub fn fill_rgb(&mut self, r: u8, g: u8, b: u8) -> Result<(), Error<I2cError>> {
pub fn fill_rgb(&mut self, r: u8, g: u8, b: u8) -> Result<(), Is31Error<I2cError>> {
for x in 0..13 {
for y in 0..9 {
self.pixel_rgb(x, y, r, g, b)?;
Expand Down Expand Up @@ -555,10 +556,9 @@ pub struct LedMatrix<I2C> {
}

#[cfg(feature = "framework_ledmatrix")]
impl<I2C, I2cError> LedMatrix<I2C>
impl<I2C: I2c, I2cError: Error> LedMatrix<I2C>
where
I2C: Write<Error = I2cError>,
I2C: Read<Error = I2cError>,
I2C: I2c<Error = I2cError>,
{
pub fn unwrap(self) -> I2C {
self.device.i2c
Expand All @@ -581,14 +581,14 @@ where
}
}

pub fn setup<DEL: DelayMs<u8>>(&mut self, delay: &mut DEL) -> Result<(), Error<I2cError>> {
pub fn setup<DEL: DelayNs>(&mut self, delay: &mut DEL) -> Result<(), Is31Error<I2cError>> {
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<I2cError>> {
pub fn fill_brightness(&mut self, brightness: u8) -> Result<(), Is31Error<I2cError>> {
for x in 0..self.device.width {
for y in 0..self.device.height {
self.device.pixel(x, y, brightness)?;
Expand Down
26 changes: 12 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I2C> {
Expand All @@ -23,10 +22,9 @@ pub struct IS31FL3741<I2C> {
pub calc_pixel: fn(x: u8, y: u8) -> (u8, u8),
}

impl<I2C, I2cError> IS31FL3741<I2C>
impl<I2C: I2c, I2cError: Error> IS31FL3741<I2C>
where
I2C: Write<Error = I2cError>,
I2C: Read<Error = I2cError>,
I2C: I2c<Error = I2cError>,
{
/// 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> {
Expand Down Expand Up @@ -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<DEL: DelayMs<u8>>(&mut self, delay: &mut DEL) -> Result<(), Error<I2cError>> {
pub fn setup<DEL: DelayNs>(&mut self, delay: &mut DEL) -> Result<(), Is31Error<I2cError>> {
self.reset(delay)?;
self.shutdown(true)?;
delay.delay_ms(10);
Expand All @@ -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<I2cError>> {
pub fn pixel(&mut self, x: u8, y: u8, brightness: u8) -> Result<(), Is31Error<I2cError>> {
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 };
Expand All @@ -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<DEL: DelayMs<u8>>(&mut self, delay: &mut DEL) -> Result<(), I2cError> {
pub fn reset<DEL: DelayNs>(&mut self, delay: &mut DEL) -> Result<(), I2cError> {
self.write_register(Page::Config, addresses::RESET_REGISTER, addresses::RESET)?;
delay.delay_ms(10);
Ok(())
Expand Down Expand Up @@ -207,15 +205,15 @@ pub mod addresses {
}

#[derive(Clone, Copy, Debug)]
pub enum Error<I2cError> {
pub enum Is31Error<I2cError> {
I2cError(I2cError),
InvalidLocation(u8),
InvalidFrame(u8),
}

impl<E> From<E> for Error<E> {
impl<E> From<E> for Is31Error<E> {
fn from(error: E) -> Self {
Error::I2cError(error)
Is31Error::I2cError(error)
}
}

Expand Down

0 comments on commit e7a2a92

Please sign in to comment.