9
\$\begingroup\$

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.)

\$\endgroup\$
1
  • 1
    \$\begingroup\$ very useful question ... my wild guess is that the current draw drops in the regular keyboard when not being used ... does a mouse behave the same way? \$\endgroup\$
    – jsotola
    Sep 15, 2023 at 15:19

1 Answer 1

1
\$\begingroup\$

For low-powered devices as phones and tablets with keyboards/mice, there is a special host driver modification for keyboard power policy, something like if no activity occurs for 70-200 ms, the link (and USB host controller) goes to sleep. Any keypress would wake the link up, with a noticeable and annoying lag.

If the off-shelf keyboard works that way but your device does not, you need to implement all default HID descriptors in your device; the simplest way is to copy entire standard keyboard set of descriptors, so the phone can load its default class driver. If you want to know which particular descriptor makes the phone to behave that way, you need to study details of USB HID Class Specification.

But obviously your device must implement the SUSPEND/RESUME/Wake-up functions if you want to save power.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.