-
Notifications
You must be signed in to change notification settings - Fork 1.5k
drivers/usbdev: add UVC gadget class driver #18609
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
Open
JianyuWang0623
wants to merge
4
commits into
apache:master
Choose a base branch
from
JianyuWang0623:uvc_camera
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,395
−58
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cc5e917
arch/xtensa/esp32s3: fix CAM DMA race and heap-allocate descriptors
JianyuWang0623 2c64005
drivers/video/gc0308: add YUYV output format support
JianyuWang0623 a87cc33
drivers/usbdev: add UVC gadget class driver
JianyuWang0623 2498ab0
boards/lckfb-szpi-esp32s3: add UVC camera standalone defconfig
JianyuWang0623 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ following section. | |
| syslog.rst | ||
| sdio.rst | ||
| usbdev.rst | ||
| uvc.rst | ||
| usbhost.rst | ||
| usbmisc.rst | ||
| usbmonitor.rst | ||
|
|
||
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,127 @@ | ||
| ====================================== | ||
| USB Video Class (UVC) Gadget Driver | ||
| ====================================== | ||
|
|
||
| Overview | ||
| ======== | ||
|
|
||
| The UVC gadget driver (``drivers/usbdev/uvc.c``) implements a USB Video Class | ||
| 1.1 device that makes NuttX appear as a USB webcam to the host. The driver | ||
| exposes a character device (``/dev/uvc0``) that applications write video frames | ||
| to. It handles all UVC class-specific control requests (PROBE / COMMIT) | ||
| internally and uses bulk transfers for video data. | ||
|
|
||
| The driver supports two modes: | ||
|
|
||
| - **Standalone** – the UVC function is the only USB class on the bus. | ||
| - **Composite** – the UVC function is combined with other USB class drivers | ||
| (e.g. CDC/ACM) via the NuttX composite device framework. | ||
|
|
||
| Features | ||
| ======== | ||
|
|
||
| - UVC 1.1 compliant (uncompressed YUY2 format) | ||
| - Bulk transfer mode for video data | ||
| - Automatic PROBE / COMMIT negotiation with the host | ||
| - ``poll()`` support – applications can wait for the host to start streaming | ||
| (``POLLOUT``) and detect disconnection (``POLLHUP``) | ||
| - Runtime video parameters – resolution and frame rate are passed at | ||
| initialization time, so USB descriptors always match the actual sensor | ||
| - ``boardctl()`` integration for easy application-level bring-up | ||
|
|
||
| Configuration | ||
| ============= | ||
|
|
||
| The driver is enabled through the following Kconfig options: | ||
|
|
||
| .. code-block:: kconfig | ||
|
|
||
| CONFIG_USBUVC=y # Enable UVC gadget support | ||
| CONFIG_USBUVC_COMPOSITE=n # Set y for composite device mode | ||
| CONFIG_USBUVC_EPBULKIN=1 # Bulk IN endpoint number (standalone) | ||
| CONFIG_USBUVC_EP0MAXPACKET=64 # EP0 max packet size (standalone) | ||
| CONFIG_USBUVC_EPBULKIN_FSSIZE=64 # Bulk IN full-speed max packet size | ||
| CONFIG_USBUVC_NWRREQS=4 # Number of pre-allocated write requests | ||
| CONFIG_USBUVC_NPOLLWAITERS=2 # Number of poll waiters | ||
|
|
||
| Header Files | ||
| ============ | ||
|
|
||
| - ``include/nuttx/usb/uvc.h`` – Public API, UVC descriptor constants, and | ||
| data structures. | ||
|
|
||
| Data Structures | ||
| =============== | ||
|
|
||
| ``struct uvc_params_s`` | ||
| ----------------------- | ||
|
|
||
| Passed to the initialization function so that USB descriptors reflect the | ||
| actual sensor capabilities:: | ||
|
|
||
| struct uvc_params_s | ||
| { | ||
| uint16_t width; /* Frame width in pixels */ | ||
| uint16_t height; /* Frame height in pixels */ | ||
| uint8_t fps; /* Frames per second */ | ||
| }; | ||
|
|
||
| Public Interfaces | ||
| ================= | ||
|
|
||
| Standalone Mode | ||
| --------------- | ||
|
|
||
| ``usbdev_uvc_initialize()`` | ||
| Initialize the UVC gadget and register ``/dev/uvc0``. *params* may be | ||
| ``NULL`` to use defaults (320 × 240 @ 5 fps). Returns a handle for later | ||
| ``usbdev_uvc_uninitialize()``. | ||
|
|
||
| ``usbdev_uvc_uninitialize()`` | ||
| Tear down the UVC gadget and unregister the character device. | ||
|
|
||
| Composite Mode | ||
| -------------- | ||
|
|
||
| ``usbdev_uvc_classobject()`` | ||
| Create a UVC class driver instance for use inside a composite device. | ||
|
|
||
| ``usbdev_uvc_classuninitialize()`` | ||
| Destroy a class driver instance created by ``usbdev_uvc_classobject()``. | ||
|
|
||
| ``usbdev_uvc_get_composite_devdesc()`` | ||
| Fill a ``composite_devdesc_s`` for the composite framework. | ||
|
|
||
| boardctl Integration | ||
| -------------------- | ||
|
|
||
| Applications can manage the UVC gadget through ``boardctl()``:: | ||
|
|
||
| struct boardioc_usbdev_ctrl_s ctrl; | ||
| struct uvc_params_s params = { .width = 320, .height = 240, .fps = 15 }; | ||
| FAR void *handle = (FAR void *)¶ms; | ||
|
|
||
| ctrl.usbdev = BOARDIOC_USBDEV_UVC; | ||
| ctrl.action = BOARDIOC_USBDEV_CONNECT; | ||
| ctrl.instance = 0; | ||
| ctrl.config = 0; | ||
| ctrl.handle = &handle; | ||
|
|
||
| boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); | ||
|
|
||
| /* ... use /dev/uvc0 ... */ | ||
|
|
||
| ctrl.action = BOARDIOC_USBDEV_DISCONNECT; | ||
| boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl); | ||
|
|
||
| Device Operation | ||
| ================ | ||
|
|
||
| 1. The application opens ``/dev/uvc0`` for writing. | ||
| 2. Use ``poll()`` with ``POLLOUT`` to wait for the USB host to start streaming | ||
| (i.e. the host sends a VS_COMMIT_CONTROL SET_CUR request). | ||
| 3. Write complete video frames via ``write()``. The driver prepends a 2-byte | ||
| UVC payload header (with FID / EOF bits) automatically. | ||
| 4. When the host stops streaming, ``write()`` returns ``-EAGAIN``. The | ||
| application can ``poll()`` again to wait for the host to restart. | ||
| 5. ``POLLHUP`` is reported when the host explicitly stops streaming. |
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
Oops, something went wrong.
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.
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.