11 releases
0.1.0-alpha.11 | Jun 9, 2023 |
---|---|
0.1.0-alpha.9 | Jun 8, 2023 |
0.1.0-alpha.8 | Jun 4, 2023 |
0.1.0-alpha.7 | Jun 1, 2023 |
0.1.0-alpha.3 | May 26, 2023 |
#1392 in Hardware support
Used in iso-tp
48KB
1K
SLoC
async-hal
Async hardware abstraction layer for embedded devices
Examples
Blinky
use async_hal::delay::DelayMs;
let mut led = _;
let mut timer = _;
loop {
led.toggle();
timer.delay_ms(1_000).await?;
}
Serial port loopback
use async_hal::io;
let mut serial_tx = _;
let mut serial_rx = _;
loop {
io::copy_buf(&mut serial_tx, &mut serial_rx).await?
}
lib.rs
:
Async hardware abstraction layer for embedded devices.
This crate provides zero-cost utilities for async IO with #![no-std]
.
Two execution models are provided:
-
Interrupt mode: Multiple interrupts can each run a future using an
Executor
. Each future is polled on every interrupt and channels can be used to communicate between them. -
Thread mode: Interrupts wake a main function where a future is being polled with
block_on
.
Installation
The easiest way to get started is to enable all features.
[dependencies]
async-hal = { version = "...", features = ["full"] }
Or by using cargo add
cargo add async-hal --features full
Feature flags
Async-hal uses a set of feature flags to reduce the amount of compiled code. It
is possible to just enable certain features over others. By default, async-hal
does not enable any features but allows one to enable a subset for their use
case. Below is a list of the available feature flags. You may also notice
above each function, struct and trait there is listed one or more feature flags
that are required for that item to be used. If you are new to async-hal it is
recommended that you use the full
feature flag which will enable all public APIs.
Beware though that this will pull in many extra dependencies that you may not
need.
full
: Enables all features listed below exceptmock
andbxcan
.can
: Enables theasync_hal::can
module.delay
: Enables theasync_hal::delay
module.executor
: Enables theasync_hal::executor
module.io
: Enables theasync_hal::io
module.serial
: Enables theasync_hal::serial
module.nb
: Enables async wrappers for non-blocking interfaces (such as fromembedded_hal
).bxcan
: Enables CAN support for stm32 devices withbxcan
.
Dependencies
~0.9–1.2MB
~22K SLoC