-
Notifications
You must be signed in to change notification settings - Fork 9.1k
USB Host: integrate class API [3: UVC] #94591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MaureenHelm
merged 4 commits into
zephyrproject-rtos:main
from
josuah:pr_usb_host_class_api3
Feb 9, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| # SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| if(CONFIG_USBD_VIDEO_CLASS) | ||
| if(CONFIG_USBD_VIDEO_CLASS OR CONFIG_USBH_VIDEO_CLASS) | ||
| zephyr_include_directories(.) | ||
| zephyr_sources(uvc.c) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| rsource "Kconfig.uvc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config USBH_VIDEO_CLASS | ||
| bool "USB host Video Class support [EXPERIMENTAL]" | ||
| select EXPERIMENTAL | ||
| help | ||
| USB Host Video Class (UVC) implementation. | ||
|
|
||
| if USBH_VIDEO_CLASS | ||
|
|
||
| config USBH_VIDEO_MAX_FRMIVAL | ||
| int "Max number of video frame interval per descriptor supported" | ||
| range 1 255 | ||
| default 16 | ||
| help | ||
| Max number of Frame Interval listed on a frame descriptor. The | ||
| default value is selected arbitrarily to fit most situations. | ||
|
|
||
| module = USBH_UVC | ||
| module-str = usbh uvc | ||
| default-count = 1 | ||
| source "subsys/logging/Kconfig.template.log_config" | ||
| source "subsys/usb/device_next/class/Kconfig.template.instances_count" | ||
|
|
||
| endif # USBH_VIDEO_CLASS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <stdlib.h> | ||
|
|
||
| #include <zephyr/init.h> | ||
| #include <zephyr/device.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/sys/byteorder.h> | ||
| #include <zephyr/sys/atomic.h> | ||
| #include <zephyr/usb/usbh.h> | ||
| #include <zephyr/usb/usb_ch9.h> | ||
| #include <zephyr/drivers/usb/udc.h> | ||
| #include <zephyr/drivers/video.h> | ||
| #include <zephyr/drivers/video-controls.h> | ||
| #include <zephyr/logging/log.h> | ||
|
|
||
| #include <zephyr/sys/util.h> | ||
| #include <zephyr/usb/usb_ch9.h> | ||
|
|
||
| #include "usbh_ch9.h" | ||
| #include "usbh_class.h" | ||
| #include "usbh_desc.h" | ||
| #include "usbh_device.h" | ||
|
|
||
| #include "uvc.h" | ||
| #include "../../../drivers/video/video_ctrls.h" | ||
| #include "../../../drivers/video/video_device.h" | ||
|
|
||
| LOG_MODULE_REGISTER(usbh_uvc, CONFIG_USBH_UVC_LOG_LEVEL); | ||
|
|
||
| struct usbh_uvc_data { | ||
| const char *name; | ||
| }; | ||
|
|
||
| /* | ||
| * Descriptor parsing utilities | ||
| * Validate and parse the video streaming and video control descriptors. | ||
| */ | ||
|
|
||
| static int usbh_uvc_probe(struct usbh_class_data *const c_data, | ||
| struct usb_device *const udev, const uint8_t iface) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_removed(struct usbh_class_data *const c_data) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_init(struct usbh_class_data *const c_data, | ||
| struct usbh_context *const uhs_ctx) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_completion_cb(struct usbh_class_data *const c_data, | ||
| struct uhc_transfer *const xfer) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_preinit(const struct device *dev) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static struct usbh_class_api uvc_class_api = { | ||
| .init = usbh_uvc_init, | ||
| .completion_cb = usbh_uvc_completion_cb, | ||
| .probe = usbh_uvc_probe, | ||
| .removed = usbh_uvc_removed, | ||
| }; | ||
|
|
||
| static int usbh_uvc_get_caps(const struct device *const dev, struct video_caps *const caps) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_get_format(const struct device *const dev, struct video_format *const fmt) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_set_stream(const struct device *const dev, const bool enable, | ||
| const enum video_buf_type type) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_enqueue(const struct device *const dev, struct video_buffer *const vbuf) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static int usbh_uvc_dequeue(const struct device *const dev, struct video_buffer **const vbuf, | ||
| k_timeout_t timeout) | ||
| { | ||
| return 0; | ||
| } | ||
|
|
||
| static DEVICE_API(video, uvc_video_api) = { | ||
| .get_caps = usbh_uvc_get_caps, | ||
| .get_format = usbh_uvc_get_format, | ||
| .set_stream = usbh_uvc_set_stream, | ||
| .enqueue = usbh_uvc_enqueue, | ||
| .dequeue = usbh_uvc_dequeue, | ||
| }; | ||
|
|
||
| static struct usbh_class_filter usbh_uvc_filters[] = { | ||
| { | ||
| .flags = USBH_CLASS_MATCH_CODE_TRIPLE, | ||
| .class = USB_BCC_VIDEO, | ||
| .sub = UVC_SC_VIDEO_INTERFACE_COLLECTION, | ||
| .proto = 0, | ||
| }, | ||
| {0}, | ||
| }; | ||
|
|
||
|
|
||
| #define USBH_VIDEO_DEVICE_DEFINE(n, _) \ | ||
| \ | ||
| static struct usbh_uvc_data uvc_data_##n = { \ | ||
| .name = "uvc_"#n, \ | ||
| }; \ | ||
| \ | ||
| DEVICE_DEFINE(usbh_uvc_##n, "usbh_uvc_"#n, \ | ||
| usbh_uvc_preinit, NULL, \ | ||
| &uvc_data_##n, NULL, \ | ||
| POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, \ | ||
| &uvc_video_api); \ | ||
| \ | ||
| USBH_DEFINE_CLASS(uvc_c_data_##n, &uvc_class_api, \ | ||
| (void *)DEVICE_GET(usbh_uvc_##n), \ | ||
| usbh_uvc_filters); \ | ||
| \ | ||
| VIDEO_DEVICE_DEFINE(uvc_host_##n, DEVICE_GET(usbh_uvc_##n), NULL); | ||
|
|
||
| LISTIFY(CONFIG_USBH_UVC_INSTANCES_COUNT, USBH_VIDEO_DEVICE_DEFINE, ()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(uvc_uvb) | ||
|
|
||
| include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake) | ||
|
|
||
| FILE(GLOB app_sources src/*.c) | ||
| target_sources(app PRIVATE ${app_sources}) | ||
| zephyr_include_directories(${ZEPHYR_BASE}/subsys/usb/host) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config SYS_CLOCK_TICKS_PER_SEC | ||
| default 1000000 if BOARD_NATIVE_SIM | ||
|
|
||
| # Source common USB sample options used to initialize new experimental USB | ||
| # device stack. The scope of these options is limited to USB samples in project | ||
| # tree, you cannot use them in your own application. | ||
| source "samples/subsys/usb/common/Kconfig.sample_usbd" | ||
|
|
||
| source "Kconfig.zephyr" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /delete-node/ &zephyr_udc0; | ||
|
|
||
| / { | ||
| zephyr_uhc0: uhc_vrt0 { | ||
| compatible = "zephyr,uhc-virtual"; | ||
|
|
||
| zephyr_udc0: udc_vrt0 { | ||
| compatible = "zephyr,udc-virtual"; | ||
| num-bidir-endpoints = <8>; | ||
| maximum-speed = "high-speed"; | ||
| }; | ||
| }; | ||
|
|
||
| uvc_device: uvcd { | ||
| compatible = "zephyr,uvc-device"; | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include "native_sim.overlay" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.