From 09664638f87949db7c8f9f2deb1c7ca2879132ae Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 20 Dec 2023 15:52:06 +0900 Subject: [PATCH] usb_usb: power saving during suspend without remote wakeup https://github.com/tmk/tmk_keyboard/issues/769#issuecomment-1864054914 --- converter/usb_usb/config.h | 3 +++ converter/usb_usb/usb_usb.cpp | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/converter/usb_usb/config.h b/converter/usb_usb/config.h index 54573160..a6252371 100644 --- a/converter/usb_usb/config.h +++ b/converter/usb_usb/config.h @@ -53,4 +53,7 @@ along with this program. If not, see . #define LOCKING_SUPPORT_ENABLE #define LOCKING_RESYNC_ENABLE +// power saving during suspended without remote wakeup disabled +#define UHS2_POWER_SAVING + #endif diff --git a/converter/usb_usb/usb_usb.cpp b/converter/usb_usb/usb_usb.cpp index 7dcf9636..2f102a50 100644 --- a/converter/usb_usb/usb_usb.cpp +++ b/converter/usb_usb/usb_usb.cpp @@ -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(); }