Skip to content

Commit

Permalink
usb_usb: power saving during suspend without remote wakeup
Browse files Browse the repository at this point in the history
  • Loading branch information
tmk committed Dec 20, 2023
1 parent ea27f71 commit 0966463
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions converter/usb_usb/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define LOCKING_SUPPORT_ENABLE
#define LOCKING_RESYNC_ENABLE

// power saving during suspended without remote wakeup disabled
#define UHS2_POWER_SAVING

#endif
23 changes: 23 additions & 0 deletions converter/usb_usb/usb_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,38 @@ void hook_usb_suspend_loop(void)
static uint8_t _led_stats = 0;
void hook_usb_suspend_entry(void)
{
dprintf("[S]");
matrix_clear();
clear_keyboard();

usb_host.suspend();

#ifdef UHS2_POWER_SAVING
// power down when remote wake is not enabled
if (!USB_Device_RemoteWakeupEnabled) {
dprintf("[p]");
usb_host.powerDown();
}
#endif
}

void hook_usb_wakeup(void)
{
dprintf("[W]");
suspend_wakeup_init();

#ifdef UHS2_POWER_SAVING
// power down when remote wake is not enabled
if (!USB_Device_RemoteWakeupEnabled) {
dprintf("[P]");
usb_host.powerUp();

// USB state cannot be retained through power down/up cycle
// device should be enumerated and initialize from the beginning
usb_host.ReleaseAllDevices();
usb_host.setUsbTaskState(USB_STATE_DETACHED);
}
#endif

usb_host.resume();
}

0 comments on commit 0966463

Please sign in to comment.