-
Notifications
You must be signed in to change notification settings - Fork 8.4k
usb: host: class: support for usb host video class #94085
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
base: main
Are you sure you want to change the base?
Changes from all commits
16b61db
010638b
9c27337
a071c98
4617ffc
474238e
c960560
5bd97c9
f5e898b
d814fbe
cfd72a3
e51fbbf
d334d1d
9bb8b64
f545687
ca1514b
4139fff
fd1abd7
16538fd
ef9d0cf
2f940be
399578c
357c154
0ec11fe
47fa1e9
7e1aaef
6d3a8c8
8e040d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ supported: | |
| - pwm | ||
| - spi | ||
| - usb_device | ||
| - usb_host | ||
| - watchdog | ||
| - netif:eth | ||
| - netif:openthread | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,8 @@ int video_init_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint | |
| int video_init_int_menu_ctrl(struct video_ctrl *ctrl, const struct device *dev, uint32_t id, | ||
| uint8_t def, const int64_t menu[], size_t menu_len); | ||
|
|
||
| int video_find_ctrl(const struct device *dev, uint32_t id, struct video_ctrl **ctrl); | ||
|
|
||
|
Comment on lines
+75
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think See comment below for |
||
| void video_cluster_ctrl(struct video_ctrl *ctrls, uint8_t sz); | ||
|
|
||
| void video_auto_cluster_ctrl(struct video_ctrl *ctrls, uint8_t sz, bool set_volatile); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| description: | | ||
| USB Video Class (UVC) host instance. | ||
|
|
||
| Each UVC instance added to the USB Host Controller (UHC) node will be visible | ||
| as a new camera from Zephyr point of view. | ||
|
|
||
| as soon as a camera is connected to USB this device will be usable by the application as a | ||
| video device, following the video API. | ||
|
|
||
| compatible: "zephyr,uvc-host" | ||
|
|
||
| include: base.yaml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /* | ||
| * Copyright (c) 2022 Nordic Semiconductor ASA | ||
| * | ||
| * SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| * SPDX-FileCopyrightText: Copyright 2025 NXP | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
|
|
@@ -17,6 +17,7 @@ | |
| #include <stdint.h> | ||
| #include <zephyr/device.h> | ||
| #include <zephyr/net_buf.h> | ||
| #include <zephyr/sys/util.h> | ||
| #include <zephyr/sys/dlist.h> | ||
| #include <zephyr/sys/bitarray.h> | ||
| #include <zephyr/drivers/usb/uhc.h> | ||
|
|
@@ -26,13 +27,29 @@ | |
| extern "C" { | ||
| #endif | ||
|
|
||
|
|
||
| /* device signal value definitions */ | ||
| #define USBH_DEVICE_CONNECTED 1 | ||
| #define USBH_DEVICE_DISCONNECTED 2 | ||
|
|
||
|
|
||
|
Comment on lines
+30
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like not used anywhere, possibly to remove from this commit. |
||
| /** | ||
| * @brief USB HOST Core Layer API | ||
| * @defgroup usb_host_core_api USB Host Core API | ||
| * @ingroup usb | ||
| * @{ | ||
| */ | ||
|
|
||
| /** | ||
| * USB host support status | ||
| */ | ||
| struct usbh_status { | ||
| /** USB host support is initialized */ | ||
| unsigned int initialized : 1; | ||
| /** USB host support is enabled */ | ||
| unsigned int enabled : 1; | ||
| }; | ||
|
|
||
| /** | ||
| * USB host support runtime context | ||
| */ | ||
|
|
@@ -43,10 +60,10 @@ struct usbh_context { | |
| struct k_mutex mutex; | ||
| /** Pointer to UHC device struct */ | ||
| const struct device *dev; | ||
| /** Status of the USB host support */ | ||
| struct usbh_status status; | ||
| /** USB device list */ | ||
| sys_dlist_t udevs; | ||
| /** USB root device */ | ||
| struct usb_device *root; | ||
| /** Allocated device addresses bit array */ | ||
| struct sys_bitarray *addr_ba; | ||
| }; | ||
|
|
@@ -60,47 +77,116 @@ struct usbh_context { | |
| .addr_ba = &ba_##device_name, \ | ||
| } | ||
|
|
||
| struct usbh_class_data; | ||
|
|
||
| /** | ||
| * @brief USB Class Code triple | ||
| * @brief Information about a device, which is relevant for matching a particular class. | ||
| */ | ||
| struct usbh_code_triple { | ||
| /** Device Class Code */ | ||
| uint8_t dclass; | ||
| /** Class Subclass Code */ | ||
| struct usbh_class_filter { | ||
| /** Vendor ID */ | ||
| uint16_t vid; | ||
| /** Product ID */ | ||
| uint16_t pid; | ||
| /** Class Code */ | ||
| uint8_t class; | ||
| /** Subclass Code */ | ||
| uint8_t sub; | ||
| /** Class Protocol Code */ | ||
| /** Protocol Code */ | ||
| uint8_t proto; | ||
| /** Flags that tell which field to match */ | ||
| uint8_t flags; | ||
| }; | ||
|
|
||
| /** | ||
| * @brief USB host class instance API | ||
| */ | ||
| struct usbh_class_api { | ||
| /** Host init handler, before any device is connected */ | ||
| int (*init)(struct usbh_class_data *const c_data, | ||
| struct usbh_context *const uhs_ctx); | ||
| /** Request completion event handler */ | ||
| int (*completion_cb)(struct usbh_class_data *const c_data, | ||
| struct uhc_transfer *const xfer); | ||
| /** Device connection handler */ | ||
| int (*probe)(struct usbh_class_data *const c_data, | ||
| struct usb_device *const udev, | ||
| const uint8_t iface); | ||
| /** Device removal handler */ | ||
| int (*removed)(struct usbh_class_data *const c_data); | ||
| }; | ||
|
|
||
| /** | ||
| * @brief USB host class data and class instance API | ||
| * @brief USB host class instance data | ||
| */ | ||
| struct usbh_class_data { | ||
| /** Class code supported by this instance */ | ||
| struct usbh_code_triple code; | ||
| /** Name of the USB host class instance */ | ||
| const char *name; | ||
| /** Pointer to USB host stack context structure */ | ||
| struct usbh_context *uhs_ctx; | ||
| /** Pointer to USB device this class is used for */ | ||
| struct usb_device *udev; | ||
| /** Interface number for which this class matched */ | ||
| uint8_t iface; | ||
| /** Pointer to host support class API */ | ||
| struct usbh_class_api *api; | ||
| /** Pointer to private data */ | ||
| void *priv; | ||
| }; | ||
|
|
||
| /** Initialization of the class implementation */ | ||
| /* int (*init)(struct usbh_context *const uhs_ctx); */ | ||
| /** Request completion event handler */ | ||
| int (*request)(struct usbh_context *const uhs_ctx, | ||
| struct uhc_transfer *const xfer, int err); | ||
| /** Device connected handler */ | ||
| int (*connected)(struct usbh_context *const uhs_ctx); | ||
| /** Device removed handler */ | ||
| int (*removed)(struct usbh_context *const uhs_ctx); | ||
| /** Bus remote wakeup handler */ | ||
| int (*rwup)(struct usbh_context *const uhs_ctx); | ||
| /** Bus suspended handler */ | ||
| int (*suspended)(struct usbh_context *const uhs_ctx); | ||
| /** Bus resumed handler */ | ||
| int (*resumed)(struct usbh_context *const uhs_ctx); | ||
| /** | ||
| * @cond INTERNAL_HIDDEN | ||
| * | ||
| * Internal state of an USB class. Not corresponding to an USB protocol state, | ||
| * but instead software life cycle. | ||
| */ | ||
| enum usbh_class_state { | ||
| /** The class is available to be associated to an USB device function. */ | ||
| USBH_CLASS_STATE_IDLE, | ||
| /** The class got bound to an USB function of a particular device on the bus. */ | ||
| USBH_CLASS_STATE_BOUND, | ||
| /** The class failed to initialize and cannot be used. */ | ||
| USBH_CLASS_STATE_ERROR, | ||
| }; | ||
| /* @endcond */ | ||
|
|
||
| /** | ||
| * @cond INTERNAL_HIDDEN | ||
| * | ||
| * Variables used by the USB host stack but not exposed to the class | ||
| * through the class API. | ||
| */ | ||
| #define USBH_DEFINE_CLASS(name) \ | ||
| static STRUCT_SECTION_ITERABLE(usbh_class_data, name) | ||
| struct usbh_class_node { | ||
| /** Class information exposed to host class implementations (drivers). */ | ||
| struct usbh_class_data *const c_data; | ||
| /** Filter rules to match this USB host class instance against a device class **/ | ||
| struct usbh_class_filter *filters; | ||
| /** State of the USB class instance */ | ||
| enum usbh_class_state state; | ||
| }; | ||
| /* @endcond */ | ||
|
|
||
| /** | ||
| * @brief Define USB host support class data | ||
| * | ||
| * Macro defines class (function) data, as well as corresponding node | ||
| * structures used internally by the stack. | ||
| * | ||
| * @param[in] class_name Class name | ||
| * @param[in] class_api Pointer to struct usbh_class_api | ||
| * @param[in] class_priv Class private data | ||
| * @param[in] filt Array of @ref usbh_class_filter to match this class or NULL to match everything. | ||
| * When non-NULL, the it has to be terminated by an entry with @c flags set to 0. | ||
| */ | ||
| #define USBH_DEFINE_CLASS(class_name, class_api, class_priv, filt) \ | ||
| static struct usbh_class_data UTIL_CAT(class_data_, class_name) = { \ | ||
| .name = STRINGIFY(class_name), \ | ||
| .api = class_api, \ | ||
| .priv = class_priv, \ | ||
| }; \ | ||
| static STRUCT_SECTION_ITERABLE(usbh_class_node, class_name) = { \ | ||
| .c_data = &UTIL_CAT(class_data_, class_name), \ | ||
| .filters = filt, \ | ||
| }; | ||
|
|
||
| /** | ||
| * @brief Initialize the USB host support; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(video_capture) | ||
|
|
||
| FILE(GLOB app_sources src/*.c) | ||
| target_sources(app PRIVATE ${app_sources}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need to remain private, see comments below.