rust-embedded-community / usb-device

Experimental device-side USB framework for microcontrollers in Rust.
MIT License
437 stars 75 forks source link

Resume (remote wakeup) hooks #65

Closed haata closed 2 years ago

haata commented 3 years ago

I see a bunch of places in the code to enable "remote_wakeup". However, I can seem to find where to trigger the remote wakeup sequence from the perspective of the UsbBus trait.

I'm currently implementing this hal for atsam4 (which is very different from atsamd) and should hopefully get some code pushed in the next week or so (I have ep0 up and running now!).

In the context of a keyboard, when a key is pressed and the computer is asleep you need to check if the USB module is in a suspend state.

In Suspend state it is possible to wake up the host sending an external resume.

  • The device must wait at least 5 ms after being entered in suspend before sending an external resume.
  • The device has 10 ms from the moment it starts to drain current and it forces a K state to resume the host.
  • The device must force a K state from 1 to 15 ms to resume the host

In my case for atsam4s I need to set a bit in the USB (UDP) register block, then clear it immediately after. I know from other MCUs (mk20dx256vlh7 iirc), you actually need to wait for an interrupt on when to clear this bit in order to handle the 1 to 15 ms timing. Other MCUs you have to keep track of this yourself.

Have these cases been considered in this crate yet?

haata commented 2 years ago

(Implemented a different way at the interrupt/hal level rather than using usb-device)