server udc fix

This commit is contained in:
Brad Stein 2025-06-26 00:45:52 -05:00
parent 7ba368bf22
commit 9ce834264e

View File

@ -85,7 +85,7 @@ impl UsbGadget {
/* 1 detach gadget */
info!("🔌 detaching gadget from {ctrl}");
Self::write_attr(self.udc_file, "")?;
Self::write_attr(self.udc_file, "none")?;
Self::wait_state(&ctrl, "not attached", 3_000)?;
/* 2 reset driver */
@ -97,13 +97,27 @@ impl UsbGadget {
/* 4 reattach + pullup */
info!("🔌 reattaching gadget to {ctrl}");
Self::write_attr(self.udc_file, &ctrl)?;
info!("Wrote udc file");
let sc = format!("/sys/class/udc/{ctrl}/soft_connect");
Self::write_attr(&sc, "0")?;
info!("Wrote soft connect file 0");
thread::sleep(Duration::from_millis(50));
Self::write_attr(&sc, "1")?;
info!("Wrote soft connect file 1");
if Path::new(&sc).exists() {
// try to set the pull-up; ignore if the kernel rejects it
match Self::write_attr(&sc, "1") {
Err(err) => {
// only swallow specific errno values
if let Some(io) = err.downcast_ref::<std::io::Error>() {
match io.raw_os_error() {
// EINVAL | EPERM | ENOENT
Some(libc::EINVAL) | Some(libc::EPERM) | Some(libc::ENOENT) => {
warn!("soft_connect unsupported ({io}); continuing");
}
_ => return Err(err), // propagate all other errors
}
} else {
return Err(err); // non-IO errors: propagate
}
}
Ok(_) => { /* success */ }
}
}
/* 5 wait for host (but tolerate sleep) */
Self::wait_state(&ctrl, "configured", 6_000)