Skip to content

Commit

Permalink
Add UVC video gadget support (#12)
Browse files Browse the repository at this point in the history
Tested with https://gitlab.freedesktop.org/camera/uvc-gadget. Creating the gadget, then running uvc-gadget uvc.usb-gadget0-0 (where 'uvc.usb-gadget0-0' is the function dir) will enumerate with my macOS host. One can open a camera application and open the device. The default just shows a test pattern.
  • Loading branch information
tuna-f1sh authored Dec 5, 2024
1 parent 01041d2 commit 2557284
Show file tree
Hide file tree
Showing 5 changed files with 489 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The following pre-defined USB functions, implemented by kernel drivers, are avai
* mass-storage device (MSD)
* musical instrument digital interface (MIDI)
* audio device (UAC2)
* video device (UVC)

In addition fully custom USB functions can be implemented in user-mode Rust code.

Expand Down Expand Up @@ -62,6 +63,7 @@ The following Linux kernel configuration options should be enabled for full func
* `CONFIG_USB_CONFIGFS_F_HID`
* `CONFIG_USB_CONFIGFS_F_MIDI`
* `CONFIG_USB_CONFIGFS_F_UAC2`
* `CONFIG_USB_CONFIGFS_F_UVC`

root permissions are required to configure USB gadgets on Linux and
the `configfs` filesystem needs to be mounted.
Expand Down
2 changes: 2 additions & 0 deletions src/function/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod net;
pub mod other;
pub mod serial;
pub mod util;
pub mod video;

use std::{cmp, hash, hash::Hash, sync::Arc};

Expand Down Expand Up @@ -63,4 +64,5 @@ impl Hash for Handle {
fn register_remove_handlers() {
register_remove_handler(custom::driver(), custom::remove_handler);
register_remove_handler(msd::driver(), msd::remove_handler);
register_remove_handler(video::driver(), video::remove_handler);
}
15 changes: 15 additions & 0 deletions src/function/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ impl FunctionDir {
fs::create_dir(path)
}

/// Create a subdirectory and its parent directories.
pub fn create_dir_all(&self, name: impl AsRef<Path>) -> Result<()> {
let path = self.property_path(name)?;
log::debug!("creating directorys {}", path.display());
fs::create_dir_all(path)
}

/// Remove a subdirectory.
pub fn remove_dir(&self, name: impl AsRef<Path>) -> Result<()> {
let path = self.property_path(name)?;
Expand Down Expand Up @@ -249,6 +256,14 @@ impl FunctionDir {
log::debug!("setting property {} to {}", path.display(), String::from_utf8_lossy(value));
fs::write(path, value)
}

/// Create a symbolic link.
pub fn symlink(&self, target: impl AsRef<Path>, link: impl AsRef<Path>) -> Result<()> {
let target = self.property_path(target)?;
let link = self.property_path(link)?;
log::debug!("creating symlink {} -> {}", link.display(), target.display());
std::os::unix::fs::symlink(target, link)
}
}

/// Split configfs function directory path into driver name and instance name.
Expand Down
Loading

0 comments on commit 2557284

Please sign in to comment.