server udc fix
This commit is contained in:
parent
7ba368bf22
commit
9ce834264e
@ -85,7 +85,7 @@ impl UsbGadget {
|
|||||||
|
|
||||||
/* 1 – detach gadget */
|
/* 1 – detach gadget */
|
||||||
info!("🔌 detaching gadget from {ctrl}");
|
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)?;
|
Self::wait_state(&ctrl, "not attached", 3_000)?;
|
||||||
|
|
||||||
/* 2 – reset driver */
|
/* 2 – reset driver */
|
||||||
@ -97,13 +97,27 @@ impl UsbGadget {
|
|||||||
/* 4 – re‑attach + pull‑up */
|
/* 4 – re‑attach + pull‑up */
|
||||||
info!("🔌 re‑attaching gadget to {ctrl}");
|
info!("🔌 re‑attaching gadget to {ctrl}");
|
||||||
Self::write_attr(self.udc_file, &ctrl)?;
|
Self::write_attr(self.udc_file, &ctrl)?;
|
||||||
info!("Wrote udc file");
|
|
||||||
let sc = format!("/sys/class/udc/{ctrl}/soft_connect");
|
let sc = format!("/sys/class/udc/{ctrl}/soft_connect");
|
||||||
Self::write_attr(&sc, "0")?;
|
if Path::new(&sc).exists() {
|
||||||
info!("Wrote soft connect file 0");
|
// try to set the pull-up; ignore if the kernel rejects it
|
||||||
thread::sleep(Duration::from_millis(50));
|
match Self::write_attr(&sc, "1") {
|
||||||
Self::write_attr(&sc, "1")?;
|
Err(err) => {
|
||||||
info!("Wrote soft connect file 1");
|
// 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) */
|
/* 5 – wait for host (but tolerate sleep) */
|
||||||
Self::wait_state(&ctrl, "configured", 6_000)
|
Self::wait_state(&ctrl, "configured", 6_000)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user