Skip to content

Commit

Permalink
Configure via esp-config
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Dec 17, 2024
1 parent fa124d8 commit 29ae895
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
6 changes: 0 additions & 6 deletions esp-hal-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ defmt = ["dep:defmt", "embassy-executor?/defmt", "esp-hal/defmt"]
log = ["dep:log"]
## Provide `Executor` and `InterruptExecutor`
executors = ["dep:embassy-executor", "esp-hal/__esp_hal_embassy"]
## Use a single generic timer queue that can be used with any executor. If not set, the crate
## provides an executor-integrated timer queue which does not need a set capacity.
generic-queue = ["embassy-time-queue-driver/_generic-queue"]
## Use a single, global timer queue. This option only needs a single alarm, no matter how many
## executors are used. Ignored if `generic-queue` is set.
single-queue = []

[lints.rust]
unexpected_cfgs = "allow"
Expand Down
49 changes: 38 additions & 11 deletions esp-hal-embassy/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{error::Error, str::FromStr};
use std::{error::Error as StdError, str::FromStr};

use esp_build::assert_unique_used_features;
use esp_config::{generate_config, Validator, Value};
use esp_config::{generate_config, Error, Validator, Value};
use esp_metadata::{Chip, Config};

fn main() -> Result<(), Box<dyn Error>> {
fn main() -> Result<(), Box<dyn StdError>> {
// NOTE: update when adding new device support!
// Ensure that exactly one chip has been specified:
assert_unique_used_features!(
Expand Down Expand Up @@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn Error>> {
config.define_symbols();

// emit config
generate_config(
let crate_config = generate_config(
"esp_hal_embassy",
&[(
"low-power-wait",
Expand All @@ -52,22 +52,49 @@ fn main() -> Result<(), Box<dyn Error>> {
"The size of the generic queue. Only used if `generic-queue` is enabled.",
Value::Integer(64),
Some(Validator::PositiveInteger),
)],
),
(
"timer-queue",
"The flavour of the timer queue provided by this crate. Accepts one of 'single-integrated', 'multiple-integrated' or 'generic'. Integrated queues require the 'executors' feature to be enabled.",
Value::String(if cfg!(feature = "executors") {
String::from("single-integrated")
} else {
String::from("generic")
}),
Some(Validator::Custom(Box::new(|value| {
let Value::String(string) = value else {
return Err(Error::Validation(String::from("Expected a string")));
};

match string.as_str() {
"single-integrated" => Ok(()), // preferred for ease of use
"multiple-integrated" => Ok(()), // preferred for performance
"generic" => Ok(()), // allows using embassy-time without the embassy executors
_ => Err(Error::Validation(format!("Expected 'single-integrated', 'multiple-integrated' or 'generic', found {string}")))
}
})))
)
],
true,
);

println!("cargo:rustc-check-cfg=cfg(integrated_timers)");
println!("cargo:rustc-check-cfg=cfg(single_queue)");
println!("cargo:rustc-check-cfg=cfg(generic_timers)");

if cfg!(feature = "generic-queue") {
println!("cargo:rustc-cfg=generic_timers");
println!("cargo:rustc-cfg=single_queue");
} else {
println!("cargo:rustc-cfg=integrated_timers");
if cfg!(feature = "single-queue") {
match &crate_config["ESP_HAL_EMBASSY_TIMER_QUEUE"] {
Value::String(s) if s.as_str() == "single-integrated" => {
println!("cargo:rustc-cfg=integrated_timers");
println!("cargo:rustc-cfg=single_queue");
}
Value::String(s) if s.as_str() == "multiple-integrated" => {
println!("cargo:rustc-cfg=integrated_timers");
}
Value::String(s) if s.as_str() == "generic" => {
println!("cargo:rustc-cfg=generic-timers");
println!("cargo:rustc-cfg=single_queue");
}
_ => unreachable!(),
}

Ok(())
Expand Down
3 changes: 0 additions & 3 deletions hil-test/tests/embassy_interrupt_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
//! code.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES:
//% FEATURES: esp-hal-embassy/single-queue
//% FEATURES: esp-hal-embassy/generic-queue

#![no_std]
#![no_main]
Expand Down
3 changes: 0 additions & 3 deletions hil-test/tests/embassy_interrupt_spi_dma.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Reproduction and regression test for a sneaky issue.
//% CHIPS: esp32 esp32s2 esp32s3 esp32c3 esp32c6 esp32h2
//% FEATURES:
//% FEATURES: esp-hal-embassy/single-queue
//% FEATURES: esp-hal-embassy/generic-queue

#![no_std]
#![no_main]
Expand Down
3 changes: 0 additions & 3 deletions hil-test/tests/embassy_timers_executors.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Embassy timer and executor Test
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES:
//% FEATURES: esp-hal-embassy/single-queue
//% FEATURES: esp-hal-embassy/generic-queue

#![no_std]
#![no_main]
Expand Down
3 changes: 0 additions & 3 deletions hil-test/tests/gpio_custom_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
//! async API works for user handlers automatically.
//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES:
//% FEATURES: esp-hal-embassy/single-queue
//% FEATURES: esp-hal-embassy/generic-queue

#![no_std]
#![no_main]
Expand Down
3 changes: 0 additions & 3 deletions qa-test/src/bin/embassy_executor_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Embassy executor benchmark, used to try out optimization ideas.
//% CHIPS: esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
//% FEATURES:
// FEATURES: esp-hal-embassy/single-queue
// FEATURES: esp-hal-embassy/generic-queue

#![no_std]
#![no_main]
Expand Down

0 comments on commit 29ae895

Please sign in to comment.