Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add free function to UsbAllocator #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jnthbdn
Copy link

@jnthbdn jnthbdn commented Dec 15, 2023

Allowing users to free the UsbBus from the UsbAllocator.

Copy link
Member

@eldruin eldruin left a comment

Choose a reason for hiding this comment

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

I am not sure it makes sense to allow this.
Maybe somebody else can comment like @ryan-summers ?

@ryan-summers
Copy link
Member

Yeah I'm also not sure this makes sense to allow. Can you elaborate on what the necessary use case is here?

@jnthbdn
Copy link
Author

jnthbdn commented Jan 30, 2024

Hello,

Thank you for your feedback. I've added this function to make the link with the PR725 (rp-rs/rp-hal#725) from rp-hal.
The problem is that creating a UsbBus requires ownership of two peripherals (USBCTRL_REGS and USBCTRL_DPRAM) and a clock. But if you want to stop the USB, it's not possible to recover these resources, and you end up, for example, with a Partially move error (in my case from the clockManager).

@ianrrees
Copy link
Contributor

ianrrees commented Mar 5, 2025

It would be nice to have the ability to tear down structures - I could imagine this being useful for implementing a low power device that usually keeps the USB peripheral powered down, for instance.

However, I see two issues with this implementation:

  1. Any allocated endpoints will essentially be left dangling. So, I think there would need to be destructors added to the endpoints, and some bookkeeping so that the free methods behave correctly.
  2. UsbDevice::build() calls UsbBusAllocator::freeze(), so it seems like the new free() wouldn't work as desired after build().

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants