Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tweedegolf/embedded-async-timer
Async timers for embedded devices in Rust
https://github.com/tweedegolf/embedded-async-timer
Last synced: about 1 month ago
JSON representation
Async timers for embedded devices in Rust
- Host: GitHub
- URL: https://github.com/tweedegolf/embedded-async-timer
- Owner: tweedegolf
- Created: 2020-07-07T10:49:58.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T14:40:18.000Z (over 3 years ago)
- Last Synced: 2024-10-31T12:13:11.065Z (2 months ago)
- Language: Rust
- Size: 16.6 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# embedded-async-timer
Async timers for embedded devices in Rust.This crate provides an interface and a generic implemention of a timer that can handle multiple
concurrent deadlines using the Future architecture provided by Rust. This crate also provides
two reference implementations for this interface for the STM32F103 and STM32L476.Using implementations for the `Timer` trait, you can instance an `AsyncTimer` that provides methods
to concurrently wait on a specific deadline or duration with a `Future`-compatible interface.
Using this crate you can implement device drivers that require delays. Using HAL crates that are
compatible with `embedded-async-timer` you can develop firmware that directly require delays or use
these aforementioned drivers.
For HAL RTC implementations with alarms it should be trivial to adapt them to implement the `Timer` trait.
View the STM32F103 example in the `impls` module for inspiration.**Note:** until `const_generics` lands the capacity for AsyncTimer is hard-coded.
**Note:** the current design assumes a `bare_metal`-like single core architecture that supports
`interrupt::free`-like blocks. In the future I would like to rewrite everything to no longer require this.**Note:** the priority queue used in this implementation is very likely to not be the most efficient choice of data structure.
I intend to experiment with various setups to make an informed performance consideration based on real
measurements given a small amount of concurrent timers.**State:** this crate has been tested with trivial examples on two embedded devices, but has not yet
been applied in production. It is beyond a simple proof of concept though. Our intention to provide a
basis for an async ecosystem. The quality might also be insufficient to run on production.
Also the current state of async-await might be such that it is practically unusable for memory constrained embedded devices.
We encourage developing async HAL drivers using this crate though.# Example
```rust
async {
let timer = AsyncTimer::new(rtc);
timer.wait(Duration::from_millis(500).into()).await;let mut interval = Interval::new(Duration::from_secs(1).into(), &timer);
loop {
interval.wait(&timer).await;
println!("ping");
}
}
```