server udc fix
This commit is contained in:
parent
f4a9b4eb6f
commit
140eef5513
@ -51,7 +51,7 @@ fn init_tracing() -> anyhow::Result<WorkerGuard> {
|
||||
}
|
||||
|
||||
async fn open_with_retry(path: &str) -> anyhow::Result<tokio::fs::File> {
|
||||
const MAX_ATTEMPTS: usize = 40; // ≈ 2 s (@50 ms)
|
||||
const MAX_ATTEMPTS: usize = 200; // ≈ 10 s (@50 ms)
|
||||
for attempt in 1..=MAX_ATTEMPTS {
|
||||
match OpenOptions::new()
|
||||
.write(true)
|
||||
|
||||
@ -84,7 +84,30 @@ impl UsbGadget {
|
||||
/* 3 – re‑attach gadget */
|
||||
info!("🔌 re‑attaching gadget to {ctrl}");
|
||||
Self::write_attr(self.udc_file, &ctrl)?;
|
||||
Self::wait_state(&ctrl, "configured", 6_000)?;
|
||||
|
||||
/* 4 – toggle gadget */
|
||||
let sc = format!("/sys/class/udc/{ctrl}/soft_connect");
|
||||
// toggle 0 → 1 to force the controller to assert pull‑ups
|
||||
Self::write_attr(&sc, "0")?; // guarantee clean edge
|
||||
thread::sleep(Duration::from_millis(50));
|
||||
Self::write_attr(&sc, "1")?;
|
||||
|
||||
/* 4 – wait for gadget */
|
||||
Self::wait_state(&ctrl, "configured", 6_000)
|
||||
.or_else(|e| {
|
||||
// If the host is physically absent (sleep / KVM paused)
|
||||
// we allow 'not attached' and continue – we can still
|
||||
// accept keyboard/mouse data and the host will enumerate
|
||||
// later without another reset.
|
||||
let last = fs::read_to_string(format!("/sys/class/udc/{ctrl}/state"))
|
||||
.unwrap_or_default();
|
||||
if last.trim() == "not attached" {
|
||||
warn!("⚠️ host did not enumerate within 6 s – continuing (state = {last:?})");
|
||||
Ok(())
|
||||
} else {
|
||||
Err(e)
|
||||
}
|
||||
})?;
|
||||
|
||||
info!("✅ USB‑gadget cycle complete");
|
||||
Ok(())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user