Skip to content
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

Add UVC for video gadget #12

Merged
merged 10 commits into from
Dec 5, 2024
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());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
log::debug!("creating directorys {}", path.display());
log::debug!("creating directories {}", 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
Loading