Skip to content

Commit 2ec4e26

Browse files
committed
usb: device_next: new USB Video Class implementation
Introduce a new USB Video Class (UVC) implementation from scratch. It exposes a native Zephyr Video driver interface, allowing to call the video_enqueue()/video_dequeue() interface. It will query the attached video device to learn about the pipeline capabilities, and use this to configure the USB descriptors. At runtime, this UVC implementation will send this device all the control requests, which it can then dispatch to the rest of the pipeline. The application can poll the format currently selected by the host, but will not be alerted when the host configures a new format, as there is no video.h API for it yet. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent cacfb79 commit 2ec4e26

File tree

7 files changed

+2654
-0
lines changed

7 files changed

+2654
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 tinyVision.ai Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
Declare an USB Video Class (UVC) device instance.
6+
7+
Each UVC instance added to the USB Device Controller (UDC) node will be visible
8+
as a new camera from the host point of view.
9+
10+
compatible: "zephyr,uvc-device"
11+
12+
include: base.yaml

include/zephyr/usb/class/usbd_uvc.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2025 tinyVision.ai Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief USB Device Firmware Upgrade (DFU) public header
10+
*
11+
* Header exposes API for registering DFU images.
12+
*/
13+
14+
#ifndef ZEPHYR_INCLUDE_USB_CLASS_USBD_UVC_H
15+
#define ZEPHYR_INCLUDE_USB_CLASS_USBD_UVC_H
16+
17+
#include <zephyr/kernel.h>
18+
19+
void uvc_set_video_dev(const struct device *const dev, const struct device *const video_dev);
20+
21+
#endif /* ZEPHYR_INCLUDE_USB_CLASS_USBD_UVC_H */

subsys/usb/device_next/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ zephyr_library_sources_ifdef(
7878
class/usbd_midi2.c
7979
)
8080

81+
zephyr_library_sources_ifdef(
82+
CONFIG_USBD_VIDEO_CLASS
83+
class/usbd_uvc.c
84+
)
85+
8186
zephyr_library_sources_ifdef(
8287
CONFIG_USBD_HID_SUPPORT
8388
class/usbd_hid.c

subsys/usb/device_next/class/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ rsource "Kconfig.uac2"
1212
rsource "Kconfig.hid"
1313
rsource "Kconfig.midi2"
1414
rsource "Kconfig.dfu"
15+
rsource "Kconfig.uvc"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2025 tinyVision.ai Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config USBD_VIDEO_CLASS
6+
bool "USB Video Class implementation [EXPERIMENTAL]"
7+
depends on DT_HAS_ZEPHYR_UVC_DEVICE_ENABLED
8+
select EXPERIMENTAL
9+
help
10+
USB Device Video Class (UVC) implementation.
11+
12+
if USBD_VIDEO_CLASS
13+
14+
config USBD_VIDEO_HEADER_SIZE
15+
int "USB Video payload header size"
16+
range 2 255
17+
default 8
18+
help
19+
Sets the size of the video payload header to allow custom data to be
20+
added after the mandatory fields.
21+
The default value is arbitrary, made to fit situations, preserving a
22+
64-bit alignment of the payload data for ease of debugging.
23+
24+
config USBD_VIDEO_MAX_FORMATS
25+
int "Max number of format descriptors"
26+
range 1 254
27+
default 32
28+
help
29+
The table of format descriptors are generated at runtime. This options plans the
30+
storage at build time to allow enough descriptors to be generated. The default value
31+
aims a compromise between enough descriptors for most devices, but not too much memory
32+
being used.
33+
34+
config USBD_VIDEO_MAX_FRMIVAL
35+
int "Max number of video output stream per USB Video interface"
36+
range 1 255
37+
default 8
38+
help
39+
Max number of Frame Interval listed on a frame descriptor. The
40+
default value is selected arbitrarily to fit most situations without
41+
requiring too much RAM.
42+
43+
module = USBD_VIDEO
44+
module-str = usbd uvc
45+
default-count = 1
46+
source "subsys/logging/Kconfig.template.log_config"
47+
48+
endif # USBD_VIDEO_CLASS

0 commit comments

Comments
 (0)