コンテンツにスキップ

embedded-hal-async — Crate 詳細

embedded-hal-async

Mature no_std

embedded-hal 1.0 と対になる async 版 HAL trait 群。I2C、SPI、delay などを async/await で抽象化し、Embassy などの非同期ランタイム上でドライバを共通化しやすくします。

Asynchronous Hardware Abstraction Layer traits for embedded systems.

embedded-hal-async は、blocking な embedded-hal と並ぶ async 版の標準 trait セットです。ドライバ crate がこの trait に対して実装されていると、Embassy などの executor 上で I/O 完了待ちの間に他タスクを進められます。

バージョン
1.0.0
ライセンス
MIT OR Apache-2.0
メンテナンス
活発に開発中

コード例

具体 HAL に依存せず、async I2C を実装した型なら同じドライバコードで扱えます。

async I2C ドライバを trait で受ける
#![no_std]
use embedded_hal_async::i2c::I2c;
pub async fn read_reg<I2C>(i2c: &mut I2C, addr: u8, reg: u8) -> Result<u8, I2C::Error>
where
I2C: I2c,
{
let mut buf = [0_u8; 1];
i2c.write_read(addr, &[reg], &mut buf).await?;
Ok(buf[0])
}

関連 Crates