Skip to content

Commit

Permalink
Ported the Max170xx-rs crate to use Hal 1.0.0 (#4)
Browse files Browse the repository at this point in the history
* switching over i2c trait to hal 1.0.0

* updated the tests

* Updating changelong and ran cargo fmt
  • Loading branch information
Paumanok committed Apr 29, 2024
1 parent 08a3717 commit f052a36
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro_rules! impl_common {

impl<I2C, E> $ic<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Create new instance of the device.
pub fn new(i2c: I2C) -> Self {
Expand Down
8 changes: 4 additions & 4 deletions src/max17043_44.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -8,7 +8,7 @@ macro_rules! impl_common_4x {
($ic:ident) => {
impl<I2C, E> $ic<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Get state of charge of the cell as calculated by the ModelGauge
/// algorithm as a percentage.
Expand All @@ -29,7 +29,7 @@ impl_common_4x!(Max17044);

impl<I2C, E> Max17043<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Get battery voltage
pub fn voltage(&mut self) -> Result<f32, Error<E>> {
Expand All @@ -40,7 +40,7 @@ where

impl<I2C, E> Max17044<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Get battery voltage
pub fn voltage(&mut self) -> Result<f32, Error<E>> {
Expand Down
12 changes: 6 additions & 6 deletions src/max170x8_x9.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -10,7 +10,7 @@ macro_rules! impl_common_x8_x9 {
($ic:ident) => {
impl<I2C, E> $ic<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Get state of charge of the cell as calculated by the ModelGauge
/// algorithm as a percentage.
Expand All @@ -26,7 +26,7 @@ macro_rules! impl_common_x8_x9 {
}
impl<I2C, E> $ic<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Set table values.
///
Expand Down Expand Up @@ -61,7 +61,7 @@ macro_rules! impl_common_x8 {
($ic:ident) => {
impl<I2C, E> $ic<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Get battery voltage in Volts
pub fn voltage(&mut self) -> Result<f32, Error<E>> {
Expand All @@ -78,7 +78,7 @@ macro_rules! impl_common_x9 {
($ic:ident) => {
impl<I2C, E> $ic<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Get battery voltage in Volts
pub fn voltage(&mut self) -> Result<f32, Error<E>> {
Expand All @@ -95,7 +95,7 @@ macro_rules! impl_common_48_49 {
($ic:ident) => {
impl<I2C, E> $ic<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::I2c<Error = E>,
{
/// Get the approximate charge or discharge rate of the battery
/// in percentage / hour
Expand Down
2 changes: 1 addition & 1 deletion src/register_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro_rules! impl_register_access {
($name:ident) => {
impl<I2C, E> $name<I2C>
where
I2C: i2c::Write<Error = E> + i2c::WriteRead<Error = E>,
I2C: i2c::I2c<Error = E>,
{
pub(crate) fn write_register(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion tests/base/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit f052a36

Please sign in to comment.