Skip to content

USB Wake Feature (port from DS5Dongle) - #93

Open
515orestis wants to merge 7 commits into
SundayMoments:mainfrom
515orestis:feature/enable-wake
Open

USB Wake Feature (port from DS5Dongle)#93
515orestis wants to merge 7 commits into
SundayMoments:mainfrom
515orestis:feature/enable-wake

Conversation

@515orestis

Copy link
Copy Markdown

No description provided.

515orestis and others added 7 commits July 6, 2026 01:16
…tons

Ports the wake feature from awalol/DS5Dongle into the DS5 Bridge companion
firmware. When built with ENABLE_WAKE_HID (default ON), the config descriptor
advertises USB REMOTE_WAKEUP (bmAttributes 0xE0) and a controller button press
during host suspend taps F15 on the existing HID keyboard interface to wake the PC.

- src/wake.{h,cpp}: wake FSM (button/reconnect detection -> tud_remote_wakeup ->
  F15 keystroke via HID instance 1), stripped of awalol's config/ps_shortcut and
  controller power-off (DS5 Bridge already power-manages in usb_pm_poll()).
- usb_descriptors.c: 0xE0 REMOTE_WAKEUP when ENABLE_WAKE_HID.
- usb.cpp: wake_note_suspend/resume() in the suspend/resume/mount callbacks.
- bt.cpp: wake_on_bt_connect() on HID interrupt channel open (pad reconnect).
- main.cpp: wake_on_bt_input() per BT report; wake_init()/wake_task() in main loop.
- CMakeLists.txt: build src/wake.cpp, add ENABLE_WAKE_HID option (default ON).
Firmware: add a runtime wake enable/disable flag gated in the wake FSM, exposed
via a new companion command CommandSetWakeEnabled (0x34). Default enabled.
- wake.{h,cpp}: wake_set_enabled()/wake_is_enabled(); request_host_wake() no-ops
  when disabled (still advertises remote-wakeup, just never wakes the host).
- companion.cpp: CommandSetWakeEnabled handler (mirrors SetSleepKeybindEnabled).

Companion app: 'Wake PC on PS Button' toggle in the device settings
'Power & Controller' section, wired end-to-end and re-applied on connect.
- protocol.ts: SET_WAKE_ENABLED (0x34) + wakeEnabled setting.
- types.ts / settings-store.ts: wakeEnabled setting (default true) + persistence.
- preload.ts / main.ts: setWakeEnabled IPC.
- bridge-service.ts: setWakeEnabled() + apply on connect.
- App.tsx: the toggle row + settings mapping.

Typecheck passes (tsc main+renderer); firmware builds clean (Pico SDK 2.2.0).
…umerate)

Previously the toggle only gated the firmware's wake action while the descriptor
statically advertised remote-wakeup, so Windows always saw the device as a wake
source. Now mirror awalol/DS5Dongle:

- usb_descriptors.c: bmAttributes REMOTE_WAKEUP bit (0xE0/0xC0) is set at runtime
  in tud_descriptor_configuration_cb from the wake flag (via C-linkage
  wake_remote_wakeup_enabled()); static image carries 0xC0. Keyboard interface
  stays present regardless (shared with shortcuts), unlike awalol which drops it.
- companion.cpp: CommandSetWakeEnabled calls usb_request_reconnect() so Windows
  re-reads the descriptor and adds/removes the device from its wake sources --
  but only when the value actually changes, else the app's connect-time settings
  re-apply would loop the reconnect.
- wake.cpp: wake_remote_wakeup_enabled() C accessor for the C-compiled descriptor.

Not persisted to flash (DS5 Bridge has no on-dongle config store; the companion
app re-applies on connect, like its other settings).
The reapply routine now sends SET_WAKE_ENABLED (0x34) during a full
settings re-apply, but the test's expected command-order constant was
not updated, failing the two reapply-order assertions. Insert the
command at the same position as in bridge-service.ts (after
SET_SLEEP_KEYBIND_ENABLED).
# Conflicts:
#	CMakeLists.txt
#	src/bt.cpp
#	src/main.cpp
The merge from up/main brought upstream's flash-nuke hash constant, but
our bundled pico-universal-flash-nuke.uf2 is built locally and differs
byte-for-byte. Rebuilt the flash-nuke and regenerated the constant so the
bundled binary matches the hash the companion verifies at runtime.
@SundayMoments

Copy link
Copy Markdown
Owner

Thanks for updating the PR. I'll be testing it later today.

@515orestis

Copy link
Copy Markdown
Author

it was based on 1.6.3 .i have updated from 1.6.4 but not tested , it has multiple changes from 1.6.3 ->1.6.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants