Skip to content

Commit 2eb671a

Browse files
committed
Remove policy type state machine, power policy now builds
1 parent e84f968 commit 2eb671a

File tree

12 files changed

+100
-420
lines changed

12 files changed

+100
-420
lines changed

embedded-service/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ defmt = { workspace = true, optional = true }
2121
document-features.workspace = true
2222
embassy-sync.workspace = true
2323
embassy-time.workspace = true
24+
embassy-futures.workspace = true
2425
embedded-batteries-async.workspace = true
2526
embedded-cfu-protocol.workspace = true
2627
embedded-hal-async.workspace = true
@@ -49,7 +50,6 @@ cortex-m.workspace = true
4950

5051
[dev-dependencies]
5152
critical-section = { workspace = true, features = ["std"] }
52-
embassy-futures.workspace = true
5353
embassy-sync = { workspace = true, features = ["std"] }
5454
embassy-time = { workspace = true, features = ["std"] }
5555
embassy-time-driver = { workspace = true }

embedded-service/src/power/policy/action/mod.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

embedded-service/src/power/policy/action/policy.rs

Lines changed: 0 additions & 246 deletions
This file was deleted.

embedded-service/src/power/policy/device.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! Device struct and methods
2-
use core::ops::DerefMut;
3-
42
use embassy_sync::mutex::Mutex;
53

6-
use super::{DeviceId, Error, action};
4+
use super::{DeviceId, Error};
75
use crate::power::policy::policy::EventReceiver;
86
use crate::power::policy::{ConsumerPowerCapability, ProviderPowerCapability};
97
use crate::sync::Lockable;
@@ -52,7 +50,7 @@ impl State {
5250
/// Internal device state for power policy
5351
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5452
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
55-
struct InternalState {
53+
pub struct InternalState {
5654
/// Current state of the device
5755
pub state: State,
5856
/// Current consumer capability
@@ -131,7 +129,7 @@ where
131129
/// Device ID
132130
id: DeviceId,
133131
/// Current state of the device
134-
state: Mutex<GlobalRawMutex, InternalState>,
132+
pub state: Mutex<GlobalRawMutex, InternalState>,
135133
/// Reference to hardware
136134
pub device: &'a C,
137135
/// Event receiver
@@ -194,40 +192,6 @@ where
194192
pub async fn is_provider(&self) -> bool {
195193
self.state().await.kind() == StateKind::ConnectedProvider
196194
}
197-
198-
/// Internal function to set device state
199-
pub(super) async fn set_state(&self, new_state: State) {
200-
let mut lock = self.state.lock().await;
201-
let state = lock.deref_mut();
202-
state.state = new_state;
203-
}
204-
205-
/// Try to provide access to the policy actions for the given state
206-
/// Implemented here for lifetime reasons
207-
pub(super) async fn try_policy_action<S: action::Kind>(
208-
&self,
209-
) -> Result<action::policy::Policy<'_, C, R, S>, Error> {
210-
let state = self.state().await.kind();
211-
if S::kind() != state {
212-
return Err(Error::InvalidState(S::kind(), state));
213-
}
214-
Ok(action::policy::Policy::new(self))
215-
}
216-
217-
/// Provide access to the current policy actions
218-
/// Implemented here for lifetime reasons
219-
pub(super) async fn policy_action(&self) -> action::policy::AnyState<'_, C, R> {
220-
match self.state().await.kind() {
221-
StateKind::Detached => action::policy::AnyState::Detached(action::policy::Policy::new(self)),
222-
StateKind::Idle => action::policy::AnyState::Idle(action::policy::Policy::new(self)),
223-
StateKind::ConnectedProvider => {
224-
action::policy::AnyState::ConnectedProvider(action::policy::Policy::new(self))
225-
}
226-
StateKind::ConnectedConsumer => {
227-
action::policy::AnyState::ConnectedConsumer(action::policy::Policy::new(self))
228-
}
229-
}
230-
}
231195
}
232196

233197
impl<C: Lockable, R: EventReceiver> intrusive_list::NodeContainer for Device<'static, C, R>

embedded-service/src/power/policy/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//! Power policy related data structures and messages
2-
pub mod action;
32
pub mod charger;
43
pub mod device;
54
pub mod flags;

0 commit comments

Comments
 (0)