Skip to content

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

Closed
josuah wants to merge 23 commits intozephyrproject-rtos:mainfrom
josuah:pr_usb_host_class_api4
Closed

USB Host: integrate class API [4: aggregated]#99775
josuah wants to merge 23 commits intozephyrproject-rtos:mainfrom
josuah:pr_usb_host_class_api4

Conversation

@josuah
Copy link
Copy Markdown
Contributor

@josuah josuah commented Nov 21, 2025

Dependencies:

This PR is only here to aggregate multiple other PRs together as a way to combine all "preview" features together.

It is not meant to be merged, and will stay a draft.
You might be interested in basing your PR on top of API2 or even better: directly on top of main

If you wish to add more commit to this PR, I would recommend to open a PR against the main branch, and add a message in this thread so I can pick the commit. This way, your change can be merged directly.

@josuah josuah force-pushed the pr_usb_host_class_api4 branch 2 times, most recently from 3f8f7bc to 2ce56b8 Compare November 21, 2025 12:18
@AidenHu
Copy link
Copy Markdown
Contributor

AidenHu commented Nov 21, 2025

@josuah
so how about the commit add two APIs for connect/disconnect from the PR Usb host hub class enablement #99735 ? In host core, we need to provide APIs or trigger to be used by hub class to connect/disconnect the device. This commit can not be created by main. Or do you have any idea about this topic?

@josuah josuah changed the title Pr usb host class api4 USB Host: integrate class API [4: aggregated] Nov 21, 2025
@josuah josuah mentioned this pull request Nov 21, 2025
18 tasks
@josuah
Copy link
Copy Markdown
Contributor Author

josuah commented Nov 24, 2025

@AidenHu

so how about the commit add two APIs for connect/disconnect

I was wondering about it: there is already two functions that seems like doing the same thing:

static void dev_connected_handler(struct usbh_context *const ctx);
static void dev_removed_handler(struct usbh_context *const ctx);

I will continue on the original issue.

@AidenHu
Copy link
Copy Markdown
Contributor

AidenHu commented Nov 26, 2025

@josuah
I have tested the current host core by this newest API4.
Now the detach/attach for hub1->hub2->device ecm can work based on the newest hub_class. This indicates the current host core is fine. Besides, there are still some transfers to be cancelled when handling detach, I am still checking it.

I have updated the usb host connection/disconnection by the commit #100072.
This PR is created based on this API4 and I have tested by my local environment. Need your help to view it. If the change is fine, hope you can merge this commit #100072 to API4.

Furthermore, I also need your help to merge the commit hub_class to your API4, which this will make me easier to use newest code. Here sorry about that previously I preferred hub_class as a standalone PR.

@josuah josuah force-pushed the pr_usb_host_class_api4 branch from 823b5db to 9506c40 Compare November 27, 2025 19:00
@josuah josuah force-pushed the pr_usb_host_class_api4 branch 7 times, most recently from 05415e1 to e4c6cda Compare December 10, 2025 14:56
@josuah josuah force-pushed the pr_usb_host_class_api4 branch from e4c6cda to cfde414 Compare December 10, 2025 17:49
@josuah josuah added the DNM This PR should not be merged (Do Not Merge) label Dec 11, 2025
@zephyrproject-rtos zephyrproject-rtos deleted a comment from sonarqubecloud Bot Dec 11, 2025
Josuah Demangeon and others added 5 commits December 18, 2025 16:05
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 <josuah.demangeon@nordicsemi.no>
Add missing copyright notice for the linker script to help with
check_compliance.py.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
Add helpers to parse USB descriptors.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
jfischer-no and others added 18 commits December 21, 2025 03:45
Add basic functions to initialize and probe class drivers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
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 <weiwei.hu@nxp.com>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
Make sure that there is at least enough room for the header before
dereferencing the fields such as bLength.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Allocate a larger size to keep room for a nil descriptor at the end of
the configuration descriptor. This is used to walk through the list of
descriptors until this empty descriptor happens.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Add tests making sure the USB Host class APIs introduced build
and run as expected.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Switch to the SPDX-FileCopyrightText prefix for all sources in USB Host
class.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Every USB host class and platform will have to select the appropriate
size for the configurtion descriptor, and the defaults will not be enough
for some classes that encode a lot of information in the configuration
descriptor. Add logging to debug this.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Add tests making sure the USB Host class APIs introduced build
and run as expected.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
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 <josuah.demangeon@nordicsemi.no>
Allow the MAX_FRMIVAL Kconfig to be used for both device and host
implementation as the header is in subsys/usb/common/.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
Modify the USB device int sequence to read the device
descriptor only after setting a valid device address.

Signed-off-by: Santhosh Charles <santhosh@linumiz.com>
When hub is used, need to consider about multiple
devices are attached.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
@josuah josuah force-pushed the pr_usb_host_class_api4 branch from cfde414 to f8b0c23 Compare December 21, 2025 04:13
@sonarqubecloud
Copy link
Copy Markdown

@josuah josuah closed this Dec 21, 2025
@josuah
Copy link
Copy Markdown
Contributor Author

josuah commented Dec 21, 2025

Closing to make it more obvious that it is not meant to be merged.

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

Labels

DNM This PR should not be merged (Do Not Merge)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants