-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract embassy support into
esp-hal-embassy
package (#1595)
* Extract embassy support into `esp-hal-embassy` package * Update relevant packages/examples/tests to get CI green again * Add back `defmt` support * Re-export `Executor` and `InterruptExecutor` rather than making `executor` module public * Document the `esp-hal-embassy` package * Update `CHANGELOG.md` * Hack together a "fix" for the `SYSTIMER` time driver * Make `clippy` shut up
- Loading branch information
1 parent
cb91828
commit 48e3e91
Showing
54 changed files
with
659 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
[package] | ||
name = "esp-hal-embassy" | ||
version = "0.1.0" | ||
edition = "2021" | ||
rust-version = "1.76.0" | ||
description = "Embassy support for esp-hal" | ||
repository = "https://github.com/esp-rs/esp-hal" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[package.metadata.docs.rs] | ||
default-target = "riscv32imac-unknown-none-elf" | ||
features = ["esp32c6", "time-timg0"] | ||
|
||
[dependencies] | ||
critical-section = "1.1.2" | ||
defmt = { version = "0.3.8", optional = true } | ||
document-features = "0.2.8" | ||
embassy-executor = "0.5.0" | ||
embassy-time-driver = "0.1.0" | ||
esp-hal = { version = "0.17.0", path = "../esp-hal" } | ||
portable-atomic = "1.6.0" | ||
|
||
[build-dependencies] | ||
cfg-if = "1.0.0" | ||
esp-build = { version = "0.1.0", path = "../esp-build" } | ||
esp-metadata = { version = "0.1.0", path = "../esp-metadata" } | ||
|
||
[features] | ||
esp32 = ["esp-hal/esp32"] | ||
esp32c2 = ["esp-hal/esp32c2"] | ||
esp32c3 = ["esp-hal/esp32c3"] | ||
esp32c6 = ["esp-hal/esp32c6"] | ||
esp32h2 = ["esp-hal/esp32h2"] | ||
esp32s2 = ["esp-hal/esp32s2"] | ||
esp32s3 = ["esp-hal/esp32s3"] | ||
|
||
## Implement `defmt::Format` on certain types. | ||
defmt = ["dep:defmt", "embassy-executor/defmt", "esp-hal/defmt"] | ||
## Use the executor-integrated `embassy-time` timer queue. | ||
integrated-timers = ["embassy-executor/integrated-timers"] | ||
|
||
#! ### Time Driver Feature Flags | ||
## SYSTIMER (16MHz) | ||
time-systimer-16mhz = ["embassy-time-driver/tick-hz-16_000_000"] | ||
## SYSTIMER (80MHz) | ||
time-systimer-80mhz = ["embassy-time-driver/tick-hz-80_000_000"] | ||
## TIMG0 (1MHz) | ||
time-timg0 = ["embassy-time-driver/tick-hz-1_000_000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# esp-hal-embassy | ||
|
||
[![Crates.io](https://img.shields.io/crates/v/esp-hal-embassy?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp-hal-embassy) | ||
[![docs.rs](https://img.shields.io/docsrs/esp-hal-embassy?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp-hal-embassy) | ||
![MSRV](https://img.shields.io/badge/MSRV-1.76-blue?labelColor=1C2C2E&style=flat-square) | ||
![Crates.io](https://img.shields.io/crates/l/esp-hal-embassy?labelColor=1C2C2E&style=flat-square) | ||
[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) | ||
|
||
[Embassy] support for `esp-hal`. | ||
|
||
[embassy]: https://github.com/embassy-rs/embassy | ||
|
||
## [Documentation] | ||
|
||
[documentation]: https://docs.rs/esp-hal-embassy/ | ||
|
||
## Minimum Supported Rust Version (MSRV) | ||
|
||
This crate is guaranteed to compile on stable Rust 1.76 and up. It _might_ | ||
compile with older versions but that may change in any new patch release. | ||
|
||
## License | ||
|
||
Licensed under either of: | ||
|
||
- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) | ||
- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) | ||
|
||
at your option. | ||
|
||
### Contribution | ||
|
||
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in | ||
the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without | ||
any additional terms or conditions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use std::{error::Error, str::FromStr}; | ||
|
||
use esp_build::assert_unique_used_features; | ||
use esp_metadata::{Chip, Config}; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
// NOTE: update when adding new device support! | ||
// Ensure that exactly one chip has been specified: | ||
assert_unique_used_features!( | ||
"esp32", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32s2", "esp32s3" | ||
); | ||
|
||
// If the `embassy` feature is enabled, ensure that a time driver implementation | ||
// is available: | ||
cfg_if::cfg_if! { | ||
if #[cfg(feature = "esp32")] { | ||
assert_unique_used_features!("time-timg0"); | ||
} else if #[cfg(feature = "esp32s2")] { | ||
assert_unique_used_features!("time-systimer-80mhz", "time-timg0"); | ||
} else { | ||
assert_unique_used_features!("time-systimer-16mhz", "time-timg0"); | ||
} | ||
} | ||
|
||
// NOTE: update when adding new device support! | ||
// Determine the name of the configured device: | ||
let device_name = if cfg!(feature = "esp32") { | ||
"esp32" | ||
} else if cfg!(feature = "esp32c2") { | ||
"esp32c2" | ||
} else if cfg!(feature = "esp32c3") { | ||
"esp32c3" | ||
} else if cfg!(feature = "esp32c6") { | ||
"esp32c6" | ||
} else if cfg!(feature = "esp32h2") { | ||
"esp32h2" | ||
} else if cfg!(feature = "esp32s2") { | ||
"esp32s2" | ||
} else if cfg!(feature = "esp32s3") { | ||
"esp32s3" | ||
} else { | ||
unreachable!() // We've confirmed exactly one known device was selected | ||
}; | ||
|
||
// Load the configuration file for the configured device: | ||
let chip = Chip::from_str(device_name)?; | ||
let config = Config::for_chip(&chip); | ||
|
||
// Define all necessary configuration symbols for the configured device: | ||
config.define_symbols(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
esp-hal/src/embassy/executor/mod.rs → esp-hal-embassy/src/executor/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.