Skip to content

Conversation

@tullom
Copy link
Contributor

@tullom tullom commented Jan 7, 2026

  • Removed static_cell dependency from Cargo.lock and Cargo.toml in examples and type-c-service.
  • Updated Type-C service methods to accept a reference to intrusive_list::IntrusiveList for better context management.
  • Modified various service methods to pass the controllers list where necessary, ensuring proper context usage.
  • Commented out unused code related to power policy channels and service initialization.
  • Adjusted the task closure to work with the updated service structure.
  • Enhanced error handling and logging throughout the service methods.

@tullom tullom self-assigned this Jan 7, 2026
@tullom tullom added the type-c Related to the type-c service or drivers. label Jan 7, 2026
@tullom tullom moved this to In progress in Embedded Controller Jan 7, 2026
@tullom tullom force-pushed the type-c/remove-global-statics branch 3 times, most recently from 35a66ba to ffb0e7e Compare January 7, 2026 23:25
…context handling

- Removed `static_cell` dependency from Cargo.lock and Cargo.toml in examples and type-c-service.
- Updated Type-C service methods to accept a reference to `intrusive_list::IntrusiveList` for better context management.
- Modified various service methods to pass the controllers list where necessary, ensuring proper context usage.
- Commented out unused code related to power policy channels and service initialization.
- Adjusted the task closure to work with the updated service structure.
- Enhanced error handling and logging throughout the service methods.
- Initializing the service will now register all PD controllers before
  running the type-c task

WIP
@tullom tullom force-pushed the type-c/remove-global-statics branch from 8c975f6 to 16aadd1 Compare January 10, 2026 00:17
@tullom tullom marked this pull request as ready for review January 10, 2026 00:27
@tullom tullom requested review from a team as code owners January 10, 2026 00:27
@tullom tullom moved this from In progress to In review in Embedded Controller Jan 10, 2026
Copy link

@asasine asasine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks functional so approved. All of my comments are therefore non-blocking.

  1. &'static -> &'a is a step for testability.
  2. Adding methods to Context and getting rid of the external public static functions is a usability improvement.
  3. Using self.controllers() instead of passing a field as an arg to your own methods is hygeine and usability.

/// Base storage
pub struct Storage<const N: usize, M: RawMutex> {
// Registration-related
context: &'static embedded_services::type_c::controller::Context,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be &'static or can it be a lifetime parameter?

async fn process_external_command(&self, command: &external::Command) -> external::Response<'static> {
async fn process_external_command(
&self,
controllers: &intrusive_list::IntrusiveList,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service stores the reference to &'a IntrusiveList so this doesn't need to be an arg to this method (or others like it); you can just refer to self.controllers() within this type's impls.

id: controller_id,
data: ControllerCommandData::Reset,
}))
pub async fn reset_controller(ctx: &Context, controller_id: ControllerId) -> Result<(), PdError> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature of these functions looks a lot like it should be a method on Context. Since the caller needs the Context object, they can simply context.reset_controller(id) rather than external::reset_controller(context, id)

impl Context {
    pub async fn reset_controller(&self, controller_id: ControllerId) -> Result<(), PdError> {
        // --snip--
    }
}

id: controller_id,
data: ControllerCommandData::Reset,
}))
pub async fn reset_controller(ctx: &Context, controller_id: ControllerId) -> Result<(), PdError> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ctx -> context here and elsewhere. Dont use abbreviations when not necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-c Related to the type-c service or drivers.

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants