diff --git a/platform/dev-imxrt/Cargo.toml b/platform/dev-imxrt/Cargo.toml index f1755ec..561de4d 100644 --- a/platform/dev-imxrt/Cargo.toml +++ b/platform/dev-imxrt/Cargo.toml @@ -35,6 +35,9 @@ perf = "deny" suspicious = "deny" style = "deny" +[features] +dual-fuel-gauge = ["platform-common/dual-fuel-gauge"] + [dependencies] cortex-m = { version = "0.7.7", features = [ "inline-asm", diff --git a/platform/dev-mcxa/Cargo.toml b/platform/dev-mcxa/Cargo.toml index c8d8304..19918d6 100644 --- a/platform/dev-mcxa/Cargo.toml +++ b/platform/dev-mcxa/Cargo.toml @@ -35,6 +35,9 @@ perf = "deny" suspicious = "deny" style = "deny" +[features] +dual-fuel-gauge = ["platform-common/dual-fuel-gauge"] + [dependencies] cortex-m = { version = "0.7.7", features = [ "inline-asm", diff --git a/platform/dev-mec/Cargo.toml b/platform/dev-mec/Cargo.toml index b2be771..e29296e 100644 --- a/platform/dev-mec/Cargo.toml +++ b/platform/dev-mec/Cargo.toml @@ -35,6 +35,9 @@ perf = "deny" suspicious = "deny" style = "deny" +[features] +dual-fuel-gauge = ["platform-common/dual-fuel-gauge"] + [dependencies] cortex-m = { version = "0.7.7", features = [ "inline-asm", diff --git a/platform/dev-npcx/Cargo.toml b/platform/dev-npcx/Cargo.toml index d59917d..343671c 100644 --- a/platform/dev-npcx/Cargo.toml +++ b/platform/dev-npcx/Cargo.toml @@ -35,6 +35,9 @@ perf = "deny" suspicious = "deny" style = "deny" +[features] +dual-fuel-gauge = ["platform-common/dual-fuel-gauge"] + [dependencies] cortex-m = { version = "0.7.7", features = [ "critical-section-single-core", diff --git a/platform/dev-qemu/Cargo.toml b/platform/dev-qemu/Cargo.toml index 4bfea21..1bf20a3 100644 --- a/platform/dev-qemu/Cargo.toml +++ b/platform/dev-qemu/Cargo.toml @@ -40,6 +40,7 @@ style = "deny" ignored = ["riscv-rt"] [features] +dual-fuel-gauge = ["platform-common/dual-fuel-gauge"] time-alarm-wake = ["dep:time-alarm-service-interface"] time-alarm-power-input = ["time-alarm-wake"] diff --git a/platform/platform-common/Cargo.toml b/platform/platform-common/Cargo.toml index 2cc4ed6..91fb321 100644 --- a/platform/platform-common/Cargo.toml +++ b/platform/platform-common/Cargo.toml @@ -70,6 +70,7 @@ defmt = "0.3.6" ignored = ["defmt"] [features] +dual-fuel-gauge = ["mock"] mock = [ "battery-service/mock", "thermal-service/mock", diff --git a/platform/platform-common/src/mock/battery.rs b/platform/platform-common/src/mock/battery.rs index ce92761..44c9ce8 100644 --- a/platform/platform-common/src/mock/battery.rs +++ b/platform/platform-common/src/mock/battery.rs @@ -8,8 +8,8 @@ use static_cell::StaticCell; /// The fuel gauge, behind a mutex so the service and the driving task can share it. type FuelGauge = Mutex; -/// Two registered fuel gauges: battery `0` is a 3S pack, battery `1` a 2S pack. -type Reg = bs::ArrayRegistration<'static, FuelGauge, 2>; +const FUEL_GAUGE_COUNT: usize = if cfg!(feature = "dual-fuel-gauge") { 2 } else { 1 }; +type Reg = bs::ArrayRegistration<'static, FuelGauge, FUEL_GAUGE_COUNT>; pub type BatteryService = bs::Service<'static, Reg>; pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService { @@ -18,14 +18,19 @@ pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService { static FUEL_GAUGE_0: StaticCell = StaticCell::new(); let fuel_gauge_0: &'static FuelGauge = FUEL_GAUGE_0.init(Mutex::new(MockFuelGauge::new())); - static FUEL_GAUGE_1: StaticCell = StaticCell::new(); - let fuel_gauge_1: &'static FuelGauge = FUEL_GAUGE_1.init(Mutex::new(MockFuelGauge::new_2s())); + let fuel_gauges = [ + fuel_gauge_0, + #[cfg(feature = "dual-fuel-gauge")] + { + static FUEL_GAUGE_1: StaticCell = StaticCell::new(); + let fuel_gauge_1: &'static FuelGauge = FUEL_GAUGE_1.init(Mutex::new(MockFuelGauge::new_2s())); + fuel_gauge_1 + }, + ]; - let service = bs::Service::new(bs::ArrayRegistration { - fuel_gauges: [fuel_gauge_0, fuel_gauge_1], - }); + let service = bs::Service::new(bs::ArrayRegistration { fuel_gauges }); - for (battery_id, fuel_gauge) in [fuel_gauge_0, fuel_gauge_1].into_iter().enumerate() { + for (battery_id, fuel_gauge) in fuel_gauges.into_iter().enumerate() { bs::mock::init_state_machine(fuel_gauge) .await .expect("Failed to initialize battery state machine"); @@ -36,7 +41,7 @@ pub async fn init(spawner: embassy_executor::Spawner) -> BatteryService { service } -#[embassy_executor::task(pool_size = 2)] +#[embassy_executor::task(pool_size = FUEL_GAUGE_COUNT)] pub async fn update_data_task(battery_id: u8, fuel_gauge: &'static FuelGauge) -> ! { let mut failures: u32 = 0; let mut count: usize = 0;