Skip to content

Commit

Permalink
enhance: implement i2c for embedded-hal-async
Browse files Browse the repository at this point in the history
  • Loading branch information
marti157 committed Jun 9, 2024
1 parent 56de16c commit 7a8b6b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = [
"unproven",
] }
embedded-hal = { package = "embedded-hal", version = "1.0" }
embedded-hal-async = "1.0.0"

critical-section = { version = "1.1.2" }
defmt = { version = "0.3.5", optional = true }
Expand Down
24 changes: 24 additions & 0 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,30 @@ impl<'d, T: Instance, M: Mode> embedded_hal::i2c::I2c for I2c<'d, T, M> {
}
}

impl<'d, T: Instance> embedded_hal_async::i2c::I2c for I2c<'d, T, Async> {
async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> {
self.read(address, read).await
}

async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> {
self.write(address, write).await
}

async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
self.write_read(address, write, read).await
}

async fn transaction(
&mut self,
address: u8,
operations: &mut [embedded_hal_async::i2c::Operation<'_>],
) -> Result<(), Self::Error> {
let _ = address;
let _ = operations;
todo!()
}
}

// eh02 compatible

impl<'d, T: Instance, M: Mode> embedded_hal_02::blocking::i2c::Read for I2c<'d, T, M> {
Expand Down

0 comments on commit 7a8b6b8

Please sign in to comment.