JianyuWang0623 opened a new pull request, #18609: URL: https://github.com/apache/nuttx/pull/18609
*Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## 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: 1. **arch/xtensa/esp32s3: fix CAM DMA race and heap-allocate descriptors** - Stops DMA *before* invoking the frame-complete callback in the ISR, preventing a race where `set_buf()` rewrites DMA descriptors while GDMA is still draining the CAM AFIFO. - Checks `priv->capturing` after the callback to avoid restarting DMA when the V4L2 layer has already called `stop_capture` inside the callback (single-buffer FIFO case). - Moves DMA descriptors from the driver struct to heap (`kmm_memalign`) so that a stale/corrupted descriptor scribbles on heap instead of overwriting `g_cam_priv` fields. - Removes leftover debug polling loop from `start_capture`. 2. **drivers/video/gc0308: add YUYV output format support** - Adds `V4L2_PIX_FMT_YUYV` to the GC0308 sensor's format descriptor list. - Dynamically configures the output format register (0x24) in `start_capture()` based on the requested pixel format (RGB565 or YCbCr422). - Tracks the active pixel format in `priv->pixelformat`. 3. **drivers/usbdev: add UVC gadget class driver** - Implements a USB Video Class 1.1 Bulk-transport gadget (`drivers/usbdev/uvc.c`, `include/nuttx/usb/uvc.h`). - Exposes `/dev/uvc0` character device; userspace writes raw YUY2 frames, the driver prepends UVC Payload Headers and splits into USB transfers. - Supports PROBE/COMMIT negotiation with dynamic resolution and frame interval from the camera sensor. - Handles host disconnect gracefully: 30-second `nxsem_tickwait` timeout, double `EP_CANCEL` guard, `wrsem` drain on re-COMMIT. - Adds `BOARDIOC_USBDEV_UVC` to `boardctl.h` for standalone initialization. - Includes Kconfig (`CONFIG_USBUVC`) and build system integration. - Composite device support is compile-gated (`CONFIG_USBUVC_COMPOSITE`) but not exercised in this PR. ## Impact - **New feature**: NuttX devices with a camera sensor can now enumerate as a standard UVC webcam. Works out-of-the-box with Linux V4L2 applications (ffmpeg, Guvcview, Cheese, etc.). - **Existing code**: The CAM DMA fix (commit 1) changes ISR behavior for `esp32s3_cam.c` — DMA is now stopped before the callback and only restarted if `priv->capturing` is still true. This is a bugfix with no impact on existing users who don't use the CAM driver. - **Build**: No impact on existing configurations. The UVC driver is only built when `CONFIG_USBUVC=y`. - **Hardware**: Tested on ESP32-S3 with GC0308 sensor. The UVC driver is hardware-agnostic and should work with any NuttX USB device controller and V4L2 camera sensor. ## 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:0102` and is recognized by V4L2: ``` $ v4l2-ctl --list-devices NuttX UVC Camera (usb-0000:00:14.0-1): /dev/video1 ``` **Streaming (ffmpeg)**: 10-round open/close stress test at 320x240 YUY2 @ 5fps, all passed: ``` $ for i in $(seq 1 10); do ffmpeg -f v4l2 -video_size 320x240 -i /dev/video1 -frames:v 10 -y /dev/null 2>&1 done Round 1: PASS Round 2: PASS ... Round 10: PASS === RESULT: 10/10 passed, 0 failed === ``` **Photo capture (Guvcview)**: JPEG 320×240 captured successfully. **Video recording (Guvcview)**: MKV 320×240 @ 5fps, 5.02s, MPEG4 + MP2 audio recorded successfully. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
