From f052a3643b1a99a737beb0ee8cf9994b13d8f7e9 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Mon, 29 Apr 2024 02:08:07 -0400 Subject: [PATCH] Ported the Max170xx-rs crate to use Hal 1.0.0 (#4) * switching over i2c trait to hal 1.0.0 * updated the tests * Updating changelong and ran cargo fmt --- CHANGELOG.md | 5 +++++ Cargo.toml | 6 +++--- src/common.rs | 2 +- src/max17043_44.rs | 8 ++++---- src/max170x8_x9.rs | 12 ++++++------ src/register_access.rs | 2 +- tests/base/mod.rs | 2 +- tests/integration.rs | 2 +- 8 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 526ee83..0740dd1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ... +## 0.1.2 - 2024-4-18 +- Embedded-hal was raised to 1.0.0 +- linux-embedded-hal raised to 0.4 for embedded-hal 1.0.0 support +- embedded-hal-mock specify embedded-hal 1.0.0 feature set + ## 0.1.1 - 2023-12-11 ### Changed diff --git a/Cargo.toml b/Cargo.toml index e8e2606..127e085 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,11 +21,11 @@ include = [ edition = "2021" [dependencies] -embedded-hal = "0.2.7" +embedded-hal = "1.0.0" [dev-dependencies] -linux-embedded-hal = "0.3" -embedded-hal-mock = "0.9" +linux-embedded-hal = "0.4" +embedded-hal-mock = {version="0.10.0", default-features=false, features=['eh1']} [profile.release] lto = true diff --git a/src/common.rs b/src/common.rs index a8993aa..6070da3 100644 --- a/src/common.rs +++ b/src/common.rs @@ -10,7 +10,7 @@ macro_rules! impl_common { impl $ic where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Create new instance of the device. pub fn new(i2c: I2C) -> Self { diff --git a/src/max17043_44.rs b/src/max17043_44.rs index 3ba629c..2f316f7 100644 --- a/src/max17043_44.rs +++ b/src/max17043_44.rs @@ -1,5 +1,5 @@ use crate::{Command, Error, Register, ADDR}; -use embedded_hal::blocking::i2c; +use embedded_hal::i2c; impl_common!(Max17043); impl_common!(Max17044); @@ -8,7 +8,7 @@ macro_rules! impl_common_4x { ($ic:ident) => { impl $ic where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Get state of charge of the cell as calculated by the ModelGauge /// algorithm as a percentage. @@ -29,7 +29,7 @@ impl_common_4x!(Max17044); impl Max17043 where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Get battery voltage pub fn voltage(&mut self) -> Result> { @@ -40,7 +40,7 @@ where impl Max17044 where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Get battery voltage pub fn voltage(&mut self) -> Result> { diff --git a/src/max170x8_x9.rs b/src/max170x8_x9.rs index 402bffa..96292ae 100644 --- a/src/max170x8_x9.rs +++ b/src/max170x8_x9.rs @@ -1,5 +1,5 @@ use crate::{Command, Error, Register, ADDR}; -use embedded_hal::blocking::i2c; +use embedded_hal::i2c; impl_common!(Max17048); impl_common!(Max17049); @@ -10,7 +10,7 @@ macro_rules! impl_common_x8_x9 { ($ic:ident) => { impl $ic where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Get state of charge of the cell as calculated by the ModelGauge /// algorithm as a percentage. @@ -26,7 +26,7 @@ macro_rules! impl_common_x8_x9 { } impl $ic where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Set table values. /// @@ -61,7 +61,7 @@ macro_rules! impl_common_x8 { ($ic:ident) => { impl $ic where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Get battery voltage in Volts pub fn voltage(&mut self) -> Result> { @@ -78,7 +78,7 @@ macro_rules! impl_common_x9 { ($ic:ident) => { impl $ic where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Get battery voltage in Volts pub fn voltage(&mut self) -> Result> { @@ -95,7 +95,7 @@ macro_rules! impl_common_48_49 { ($ic:ident) => { impl $ic where - I2C: i2c::WriteRead + i2c::Write, + I2C: i2c::I2c, { /// Get the approximate charge or discharge rate of the battery /// in percentage / hour diff --git a/src/register_access.rs b/src/register_access.rs index 15ee61d..a25e8b3 100644 --- a/src/register_access.rs +++ b/src/register_access.rs @@ -21,7 +21,7 @@ macro_rules! impl_register_access { ($name:ident) => { impl $name where - I2C: i2c::Write + i2c::WriteRead, + I2C: i2c::I2c, { pub(crate) fn write_register( &mut self, diff --git a/tests/base/mod.rs b/tests/base/mod.rs index aff2c14..44fd32b 100644 --- a/tests/base/mod.rs +++ b/tests/base/mod.rs @@ -1,4 +1,4 @@ -use embedded_hal_mock::i2c::{Mock as I2cMock, Transaction as I2cTrans}; +use embedded_hal_mock::eh1::i2c::{Mock as I2cMock, Transaction as I2cTrans}; use max170xx::{Max17043, Max17044, Max17048, Max17049, Max17058, Max17059}; pub const ADDR: u8 = 0b011_0110; diff --git a/tests/integration.rs b/tests/integration.rs index ee3189e..98c80a4 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -3,7 +3,7 @@ use crate::base::{ destroy_43, destroy_44, destroy_48, destroy_49, destroy_58, destroy_59, new_43, new_44, new_48, new_49, new_58, new_59, Command, Register, ADDR, }; -use embedded_hal_mock::i2c::Transaction as I2cTrans; +use embedded_hal_mock::eh1::i2c::Transaction as I2cTrans; macro_rules! get_float { ($name:ident, $create:ident, $destroy:ident, $method:ident, $reg:ident, $v0:expr, $v1:expr, $expected:expr) => {