Skip to content

Conversation

@AidenHu
Copy link
Contributor

@AidenHu AidenHu commented Nov 26, 2025

Dependency:

USB Host: integrate class API [4: aggregated] #99775

This change is used to update usb host connection/disconnection even when usb hub is used.

@AidenHu
Copy link
Contributor Author

AidenHu commented Nov 26, 2025

@josuah
This is created by API4 and I have tested based on the newest hub_class for multiple devices.
Considering the structure, the good way is locate the newly added function in usbh_device.c not in host_core.c . The related declarations are also added in usbh_device.h
These two functions can be called by connection/disconnection handler and hub class.
Hope you can view and hope this commit can be merged to API4

Comment on lines 503 to 505
k_mutex_lock(&ctx->mutex, K_FOREVER);
sys_dlist_remove(&udev->node);
k_mutex_unlock(&ctx->mutex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, usbh_device_free() takes care of calling sys_dlis_remove();, so not needed here (unless it is removed from usbh_device_free().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove this duplicated code.

Comment on lines 523 to 525
k_mutex_lock(&ctx->mutex, K_FOREVER);
sys_dlist_remove(&udev->node);
k_mutex_unlock(&ctx->mutex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: usbh_device_free() already calls calling sys_dlis_remove().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove it.

@josuah
Copy link
Contributor

josuah commented Nov 26, 2025

Once comments above adjusted, I can integrate it to API4, and if that makes sense to you, it is possible to put this PR on top of main directly, with just the last commit, then it can be reviewed+merged without waiting..

@AidenHu AidenHu force-pushed the pr_usb_host_connect_disconnect branch 2 times, most recently from 7583e8f to 7a5adf2 Compare November 27, 2025 03:00
@AidenHu
Copy link
Contributor Author

AidenHu commented Nov 27, 2025

Once comments above adjusted, I can integrate it to API4, and if that makes sense to you, it is possible to put this PR on top of main directly, with just the last commit, then it can be reviewed+merged without waiting..

@josuah
I have updated this commit based your comments, thank you much.
Meanwhile, I also rebase the top of main for the current PR update usb host connect disconnect#100072, which means that update usb host connect disconnect#100072 can be the last pull request for reviewing and merged to the main branch as what we have talked in Discord.
Please note that I updated the content of my two commits, but not affect the code, so my two commits in this PR are not same with the ones of API4. Anyway, this does not affect us because we have decided to use this update usb host connect disconnect#100072 to be the final PR for merging to main.
If something wrong I did, please correct me, thanks.

Josuah Demangeon and others added 18 commits November 28, 2025 10:43
Add a "struct usbh_status" that contains a bitmask of flags to keep
track of the global state of the host context, like done for the
device_next implementation.

Signed-off-by: Josuah Demangeon <[email protected]>
Add missing copyright notice for the linker script to help with
check_compliance.py.

Signed-off-by: Josuah Demangeon <[email protected]>
Add a "struct usbh_class_api" for the host implementation, and move all
the function poitners to it. Add more fields to "struct usbh_class_data".

Signed-off-by: Josuah Demangeon <[email protected]>
Add API wrappers around the function pointers in struct usbh_class_api,
while also documenting the USB host class internal API.

Signed-off-by: Josuah Demangeon <[email protected]>
Add functions to probe/remove all classes as part of a new usbh_class.c
and a matching usbh_class.h. These functions are called from the function
usbh_init_device_intl() in usbh_core.c to initialize every class upon
connection of a device. Every class driver provide filters to match the
interfaces of the device.

Co-authored-by: Aiden Hu <[email protected]>
Signed-off-by: Josuah Demangeon <[email protected]>
Move the UVC header with all the definitions from the UVC standard to
share it between USB host and device class implementation.

Signed-off-by: Josuah Demangeon <[email protected]>
Add tests making sure the USB Host class APIs introduced build
and run as expected.

Signed-off-by: Josuah Demangeon <[email protected]>
Add tests making sure the USB Host class APIs introduced build
and run as expected.

Signed-off-by: Josuah Demangeon <[email protected]>
Move the UVC header with all the definitions from the UVC standard to
share it between USB host and device class implementation.

Signed-off-by: Josuah Demangeon <[email protected]>
Move UVC helper functions to a file shared between UVC host and device.
The arrays are not visible anymore from either USB host or device, but
instead accessed through a front-end funciton.

Signed-off-by: Josuah Demangeon <[email protected]>
The USB control size field was wrong for UVC_PU_CONTRAST_CONTROL.
Correct it to the correct value from the standard.

Signed-off-by: Josuah Demangeon <[email protected]>
Loop through each of the VideoStreaming and VideoControl descriptor
to parse them. This is meant as a stub for the purpose of testing the
class API.

Signed-off-by: Josuah Demangeon <[email protected]>
Add a test to run the USB Video Class host support by using
the existing Zephyr USB Video Class device support.
This allows running implementing the host side from the device side.
A draft implementation of UVC is added leveraging this test.

Signed-off-by: Josuah Demangeon <[email protected]>
The public API file <zephyr/usb/class/usbd_uvc.h> lacked an include
to <zephyr/drivers/video.h> making it fail depending on the order of
the includes.

Signed-off-by: Josuah Demangeon <[email protected]>
Modify the USB device int sequence to read the device
descriptor only after setting a valid device address.

Signed-off-by: Santhosh Charles <[email protected]>
When hub is used, need to consider about multiple
devices are attached.

Signed-off-by: Aiden Hu <[email protected]>
add usbh_device_get_root and usbh_device_is_root
function to check root device

Signed-off-by: Aiden Hu <[email protected]>
For usb xfer, set endpoint type and interval by the
selected endpoint desc.

Signed-off-by: Aiden Hu <[email protected]>
Convert xfer's interval to actual value because
mcux_ep->interval is already calculated.

Signed-off-by: Aiden Hu <[email protected]>
maxPacketSize and numberPerUframe of pipe should
be set considering additional transactions.

Signed-off-by: Aiden Hu <[email protected]>
Add two functions:
usbh_connect_device() for device connection
usbh_disconnect_device() for device disconnection

These functions centralize the logic for device attach/detach,
including class probe and remove handling. They can be invoked
by the hub class as well as dev_connected_handler and
dev_removed_handler, improving code clarity and reuse.

Signed-off-by: Aiden Hu <[email protected]>
@AidenHu AidenHu force-pushed the pr_usb_host_connect_disconnect branch from b4fb918 to d194419 Compare November 28, 2025 02:43
@sonarqubecloud
Copy link

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants