mirror of
https://github.com/marcriera/ddgo-pnp-controller.git
synced 2025-04-18 09:39:28 +02:00
FunctionFS gadget test
This commit is contained in:
parent
c500940f26
commit
6c8783bd93
1 changed files with 32 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
use std::thread;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::{Read, Write};
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::state::ControllerState;
|
use crate::state::ControllerState;
|
||||||
mod dgoc44u;
|
mod dgoc44u;
|
||||||
mod tcpp20009;
|
mod tcpp20009;
|
||||||
|
@ -14,6 +19,7 @@ pub enum ControllerModel {
|
||||||
pub fn set_model(state: &ControllerState) -> ControllerModel {
|
pub fn set_model(state: &ControllerState) -> ControllerModel {
|
||||||
if state.button_right {
|
if state.button_right {
|
||||||
println!("Selected controller DGOC44-U.");
|
println!("Selected controller DGOC44-U.");
|
||||||
|
init_gadget();
|
||||||
return ControllerModel::DGOC44U;
|
return ControllerModel::DGOC44U;
|
||||||
}
|
}
|
||||||
else if state.button_up {
|
else if state.button_up {
|
||||||
|
@ -44,3 +50,29 @@ pub fn set_state(state: &mut ControllerState, model: &ControllerModel) {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init_gadget() {
|
||||||
|
Command::new("modprobe").args(["g_ffs"]).output();
|
||||||
|
Command::new("mkdir").args(["-p","/tmp/ffs-mascon"]).output();
|
||||||
|
Command::new("mount").args(["-t","functionfs","mascon","/tmp/ffs-mascon"]).output();
|
||||||
|
|
||||||
|
let descriptors = [0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||||
|
0x09, 0x04, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00,
|
||||||
|
0x07, 0x05, 0x81, 0x03, 0x08, 0x00, 0x00];
|
||||||
|
let strings = [0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
||||||
|
|
||||||
|
thread::spawn(move || {
|
||||||
|
if let Ok(mut ep0) = File::open("/tmp/ffs-mascon/ep0") {
|
||||||
|
let mut buffer = [0; 100];
|
||||||
|
loop {
|
||||||
|
ep0.read(&mut buffer).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if let Ok(mut ep0) = File::create("/tmp/ffs-mascon/ep0") {
|
||||||
|
ep0.write(&descriptors).ok();
|
||||||
|
println!("USB Gadget: Descriptors written to EP0");
|
||||||
|
ep0.write(&strings).ok();
|
||||||
|
println!("USB Gadget: Strings written to EP0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue