Skip to content

Commit 00399b8

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 video capabilities, and use this to configure the USB descriptors. At runtime, this UVC implementation will send this device all the control requests, which it will send to the attached video device. 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 6099239 commit 00399b8

File tree

7 files changed

+2925
-0
lines changed

7 files changed

+2925
-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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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_MAX_FORMATS
15+
int "Max number of format descriptors"
16+
range 1 254
17+
default 32
18+
help
19+
The table of format descriptors are generated at runtime. This options plans the
20+
storage at build time to allow enough descriptors to be generated. The default value
21+
aims a compromise between enough descriptors for most devices, but not too much memory
22+
being used.
23+
24+
config USBD_VIDEO_MAX_FRMIVAL
25+
int "Max number of video output stream per USB Video interface"
26+
range 1 255
27+
default 8
28+
help
29+
Max number of Frame Interval listed on a frame descriptor. The
30+
default value is selected arbitrarily to fit most situations without
31+
requiring too much RAM.
32+
33+
config USBD_VIDEO_NUM_BUFS
34+
int "Max number of buffers the UVC class can allocate"
35+
default 16
36+
help
37+
Control the number of buffer UVC can allocate in parallel.
38+
The default is a compromise to allow enough concurrent buffers but not too much
39+
memory usage.
40+
41+
module = USBD_VIDEO
42+
module-str = usbd uvc
43+
default-count = 1
44+
source "subsys/logging/Kconfig.template.log_config"
45+
46+
endif # USBD_VIDEO_CLASS

0 commit comments

Comments
 (0)