I am using an ATmega32u4 that is connected semi-permanently to a mobile Android device (specifically, a keyboard connected to a phone).
While the device is connected and USB is enabled on the ATmega32u4, the USB driver on the phone stays permanently active, keeping the phone from going into sleep mode.
I plugged in an off-the-shelf regular keyboard and here the driver stays active for maybe a few seconds when the keyboard is used, but quickly sleeps afterward.
Since documentation and examples for the ATmega32u4 are scarce, I wanted to ask on a protocol level: What does a USB device need to do to tell the host "I am idle, no need for the host to stay awake"?
So far I know this:
- Disabling the port from the device side lets the host sleep, but it takes a few seconds to reconnect, which is not ok for the use case.
- I believe the USB autosuspend mechanism is relevant for this
- I do receive SUSPI and WAKEUPI interrupts
- According to the documentation, I need to freeze the USB clock on SUSPI and resume it on WAKEUPI. This does not let the host sleep, though.
So how, on a protocol level, does the process of letting the host sleep work?
(If someone has specific hints for the ATmega32u4 too, I'd be grateful as well, but it's not required for a helpful answer.)