Commit 7538b7bd authored by Josuah Demangeon's avatar Josuah Demangeon Committed by Benjamin Cabé
Browse files

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: default avatarJosuah Demangeon <me@josuah.net>
parent fd6e60dd
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
# Copyright (c) 2025 tinyVision.ai Inc.
# SPDX-License-Identifier: Apache-2.0

description: |
  USB Video Class (UVC) device instance.

  Each UVC instance added to the USB Device Controller (UDC) node will be visible
  as a new camera from the host point of view.

compatible: "zephyr,uvc-device"

include: base.yaml
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2025 tinyVision.ai Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/**
 * @file
 * @brief USB Video Class (UVC) public header
 */

#ifndef ZEPHYR_INCLUDE_USB_CLASS_USBD_UVC_H
#define ZEPHYR_INCLUDE_USB_CLASS_USBD_UVC_H

#include <zephyr/device.h>

/**
 * @brief USB Video Class (UVC) device API
 * @defgroup usbd_uvc USB Video Class (UVC) device API
 * @ingroup usb
 * @since 4.2
 * @version 0.1.0
 * @see uvc: "Universal Serial Bus Device Class Definition for Video Devices"
 *      Document Release 1.5 (August 9, 2012)
 * @{
 */

/**
 * @brief Set the video device that a UVC instance will use.
 *
 * It will query its supported controls, formats and frame rates, and use this information to
 * generate USB descriptors sent to the host.
 *
 * At runtime, it will forward all USB controls from the host to this device.
 *
 * @note This function must be called before @ref usbd_enable.
 *
 * @param uvc_dev The UVC device
 * @param video_dev The video device that this UVC instance controls
 */
void uvc_set_video_dev(const struct device *uvc_dev, const struct device *video_dev);

/**
 * @}
 */

#endif /* ZEPHYR_INCLUDE_USB_CLASS_USBD_UVC_H */
+5 −0
Original line number Diff line number Diff line
@@ -78,6 +78,11 @@ zephyr_library_sources_ifdef(
  class/usbd_midi2.c
)

zephyr_library_sources_ifdef(
	CONFIG_USBD_VIDEO_CLASS
	class/usbd_uvc.c
)

zephyr_library_sources_ifdef(
	CONFIG_USBD_HID_SUPPORT
	class/usbd_hid.c
+1 −0
Original line number Diff line number Diff line
@@ -12,3 +12,4 @@ rsource "Kconfig.uac2"
rsource "Kconfig.hid"
rsource "Kconfig.midi2"
rsource "Kconfig.dfu"
rsource "Kconfig.uvc"
+46 −0
Original line number Diff line number Diff line
# Copyright (c) 2025 tinyVision.ai Inc.
#
# SPDX-License-Identifier: Apache-2.0

config USBD_VIDEO_CLASS
	bool "USB Video Class implementation [EXPERIMENTAL]"
	depends on DT_HAS_ZEPHYR_UVC_DEVICE_ENABLED
	select EXPERIMENTAL
	help
	  USB Device Video Class (UVC) implementation.

if USBD_VIDEO_CLASS

config USBD_VIDEO_MAX_FORMATS
	int "Max number of format descriptors"
	range 1 254
	default 32
	help
	  The table of format descriptors are generated at runtime. This options plans the
	  storage at build time to allow enough descriptors to be generated. The default value
	  aims a compromise between enough descriptors for most devices, but not too much memory
	  being used.

config USBD_VIDEO_MAX_FRMIVAL
	int "Max number of video output stream per USB Video interface"
	range 1 255
	default 8
	help
	  Max number of Frame Interval listed on a frame descriptor. The
	  default value is selected arbitrarily to fit most situations without
	  requiring too much RAM.

config USBD_VIDEO_NUM_BUFS
	int "Max number of buffers the UVC class can allocate"
	default 16
	help
	  Control the number of buffer UVC can allocate in parallel.
	  The default is a compromise to allow enough concurrent buffers but not too much
	  memory usage.

module = USBD_VIDEO
module-str = usbd uvc
default-count = 1
source "subsys/logging/Kconfig.template.log_config"

endif # USBD_VIDEO_CLASS
Loading