drivers/usbdev: add UVC gadget class driver #18609
drivers/usbdev: add UVC gadget class driver #18609JianyuWang0623 wants to merge 4 commits intoapache:masterfrom
Conversation
- Remove debug polling loop from esp32s3_cam_start_capture() that busy-waited on DMA status register. - Fix DMA ISR race: stop DMA before invoking capture callback to prevent ISR re-triggering while callback processes the buffer. Check priv->capturing before restarting DMA in ISR. - Move DMA descriptors from struct to heap allocation, avoiding stack/BSS alignment issues with cache-line-aligned descriptors. Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
GC0308 sensor supports multiple output formats via register 0x24. Add YUYV (YCbCr422) alongside existing RGB565 in fmtdescs and configure the output format register dynamically in start_capture() based on the requested pixel format. Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
| ifeq ($(CONFIG_USBUVC),y) | ||
| CSRCS += uvc.c | ||
| endif | ||
|
|
There was a problem hiding this comment.
Hi @JianyuWang0623, CMake needs to be aligned with Make
There was a problem hiding this comment.
done, thank you
5f15f25 to
54fb44b
Compare
acassis
left a comment
There was a problem hiding this comment.
@JianyuWang0623 WOW!!! That is really cool! Two things: 1) please include a Documentation about this feature; 2) please include the board profile that use created to test it.
54fb44b to
3fba730
Compare
@acassis done |
Add USB Video Class 1.1 gadget driver supporting Bulk transport with uncompressed YUY2 video streaming. Resolution and frame interval are negotiated dynamically via PROBE/COMMIT control. - uvc.h: protocol constants, streaming control struct, public API - uvc.c: class driver with PROBE/COMMIT, bulk EP, /dev/uvc0 chardev - Kconfig/Make.defs: USBUVC config and build rules - boardctl.c: BOARDIOC_USBDEV_UVC standalone init path Hardened against host disconnect: - Removed nxmutex_lock from USB interrupt context paths - Added 30s semaphore timeout in uvc_write with EP_CANCEL fallback - Drain stale wrsem counts in VS_COMMIT before new stream - Guard uvc_streaming_stop() against double EP_CANCEL race - Handle EP_SUBMIT returning -ESHUTDOWN gracefully Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Add UVC configuration for lckfb-szpi-esp32s3 board based on gc0308 camera config, with USB OTG and UVC gadget driver enabled in standalone (non-composite) mode. - defconfig: enable ESP32S3_OTG, USBUVC, UVC example app - board doc: add uvc section with usage and host verification Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
|
@JianyuWang0623 please fix this Documentation issue: |
3774bb2 to
2498ab0
Compare
@acassis done |
| /* Configure CAM controller */ | ||
|
|
||
| return esp32s3_cam_config(priv); | ||
| int ret = esp32s3_cam_config(priv); |
There was a problem hiding this comment.
| int ret = esp32s3_cam_config(priv); | |
| return esp32s3_cam_config(priv); |
|
@JianyuWang0623 I have not idea why the CI is failing now, even spending time scrolling it I only saw some warnings: @simbit18 any idea? |
@acassis I've restarted the workflow; let's see if it freezes again. |
Note: Please adhere to Contributing Guidelines.
Summary
This PR adds USB Video Class (UVC) gadget support for NuttX, enabling an ESP32-S3 board to appear as a standard USB webcam on a Linux host — no custom host driver required.
The change consists of three commits:
arch/xtensa/esp32s3: fix CAM DMA race and heap-allocate descriptors
set_buf()rewrites DMA descriptors while GDMA is still draining the CAM AFIFO.priv->capturingafter the callback to avoid restarting DMA when the V4L2 layer has already calledstop_captureinside the callback (single-buffer FIFO case).kmm_memalign) so that a stale/corrupted descriptor scribbles on heap instead of overwritingg_cam_privfields.start_capture.drivers/video/gc0308: add YUYV output format support
V4L2_PIX_FMT_YUYVto the GC0308 sensor's format descriptor list.start_capture()based on the requested pixel format (RGB565 or YCbCr422).priv->pixelformat.drivers/usbdev: add UVC gadget class driver
drivers/usbdev/uvc.c,include/nuttx/usb/uvc.h)./dev/uvc0character device; userspace writes raw YUY2 frames, the driver prepends UVC Payload Headers and splits into USB transfers.nxsem_tickwaittimeout, doubleEP_CANCELguard,wrsemdrain on re-COMMIT.BOARDIOC_USBDEV_UVCtoboardctl.hfor standalone initialization.CONFIG_USBUVC) and build system integration.CONFIG_USBUVC_COMPOSITE) but not exercised in this PR.Impact
esp32s3_cam.c— DMA is now stopped before the callback and only restarted ifpriv->capturingis still true. This is a bugfix with no impact on existing users who don't use the CAM driver.CONFIG_USBUVC=y.Testing
Host: Ubuntu 24.04 x86_64, kernel 6.8
Board: LCKFB-SZPI-ESP32S3 (ESP32-S3 + GC0308 camera)
Config:
lckfb-szpi-esp32s3:uvc(standalone UVC, no composite)Build:
make distclean && ./tools/configure.sh lckfb-szpi-esp32s3:uvc && make -j$(nproc)Enumeration: Device enumerates as
1d6b:0102and is recognized by V4L2:Streaming (ffmpeg): 10-round open/close stress test at 320x240 YUY2 @ 5fps, all passed:
Photo capture (Guvcview): JPEG 320×240 captured successfully.
Video recording (Guvcview): MKV 320×240 @ 5fps, 5.02s, MPEG4 + MP2 audio recorded successfully.