Skip to content

Commit

Permalink
bumped embedded hal to v1 and added no std support
Browse files Browse the repository at this point in the history
  • Loading branch information
FloppyDisck committed Dec 1, 2024
1 parent 2ec513f commit 9c153ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
13 changes: 5 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "i2c-multiplexer"
description = "An I2C Multiplexer library that supports the PCA9546 and TCA9546A chips"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
license = "MIT"
repository = "https://github.com/FloppyDisck/i2c-multiplexer"
Expand All @@ -16,13 +16,10 @@ default = []
bus = []

[dependencies]
embedded-svc = "0.22.0"
embedded-hal = "0.2.7"

crc = "3.0.0"
thiserror = "1.0.38"
embedded-hal = "1.0.0"
thiserror = { version = "2.0.3", default-features = false }

[dev-dependencies]
shared-bus = { version="0.2.5", features=['std'] }
embedded-hal-mock = "0.9.0"
shared-bus = { version= "0.3.1", features=['std'] }
embedded-hal-mock = "0.11.1"
rstest = "0.16.0"
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use thiserror::Error;

pub type Result<T> = std::result::Result<T, MultiplexerError>;
pub type Result<T> = core::result::Result<T, MultiplexerError>;

#[derive(Error, Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
pub enum MultiplexerError {
Expand Down
27 changes: 17 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![no_std]

#[cfg(feature = "bus")]
pub mod bus;
pub mod error;

use embedded_hal::blocking::i2c;
use embedded_hal::i2c::I2c;
use error::{MultiplexerError, Result};

pub mod prelude {
Expand Down Expand Up @@ -49,7 +51,7 @@ pub(crate) fn address_from_pins(a0: bool, a1: bool, a2: bool) -> u8 {

impl<I2C> Multiplexer<I2C>
where
I2C: i2c::WriteRead + i2c::Write + Send + Sync,
I2C: I2c + Send + Sync,
{
pub fn new(i2c: I2C) -> Self {
Self {
Expand Down Expand Up @@ -92,7 +94,7 @@ where

impl<I2C> Multiplexer<I2C>
where
I2C: i2c::WriteRead + i2c::Write + Send + Sync,
I2C: I2c + Send + Sync,
{
/// Disables all ports
pub fn with_ports_disabled(self) -> Result<Self> {
Expand Down Expand Up @@ -156,9 +158,16 @@ where
#[cfg(test)]
mod test {
use crate::prelude::*;
use embedded_hal_mock::i2c::Mock;
use embedded_hal_mock::common::Generic;
use embedded_hal_mock::eh1::i2c::{Mock, Transaction};
use rstest::*;

impl Multiplexer<Generic<Transaction>> {
fn done(mut self) {
self.i2c.done();
}
}

#[rstest]
#[case([true;4], 0b0000_1111)]
#[case([false;4], 0b0000_0000)]
Expand All @@ -174,11 +183,9 @@ mod test {
#[case([false, true, false], 0b1110_0010)]
#[case([true, false, true], 0b1110_0101)]
fn setup_address(#[case] addr: [bool; 3], #[case] result: u8) {
assert_eq!(
Multiplexer::new(Mock::new([]))
.with_address_pins(addr[0], addr[1], addr[2])
.address,
result
)
let i2c = Mock::new(&[]);
let multiplexer = Multiplexer::new(i2c).with_address_pins(addr[0], addr[1], addr[2]);
assert_eq!(multiplexer.address, result);
multiplexer.done();
}
}

0 comments on commit 9c153ae

Please sign in to comment.