Skip to content

feat(tg5040): keep device awake while connected as a USB gadget#783

Open
Pobega wants to merge 2 commits into
LoveRetro:mainfrom
Pobega:tg5040-usb-keepawake
Open

feat(tg5040): keep device awake while connected as a USB gadget#783
Pobega wants to merge 2 commits into
LoveRetro:mainfrom
Pobega:tg5040-usb-keepawake

Conversation

@Pobega

@Pobega Pobega commented Jul 17, 2026

Copy link
Copy Markdown

Add an opt-in "Keep awake over USB" setting that prevents screen-off and deep sleep while the device is enumerated as a USB gadget by a host, as distinct from merely charging.

Detection reads /sys/class/udc/*/state and treats "configured" as connected (PLAT_isUSBConnected), so it reflects an active data connection rather than power presence. This matters when the battery is full: charging already blocks sleep, but a full battery on USB would otherwise let the device sleep and drop the connection.

The state is polled on the existing battery thread into a new pwr.is_usb_connected atomic and, gated by CFG_getKeepAwakeWhenUSB, is factored into both PWR_preventAutosleep() (no screen-off) and the PWR_waitForWake() deep-sleep deferral, mirroring how is_charging is handled.

Setting defaults to off and is exposed in Settings under the tg5040-only block. tg5050 and desktop get PLAT_isUSBConnected stubs returning 0.

Disclosure: LLMs were used to develop this code.

Add an opt-in "Keep awake over USB" setting that prevents screen-off and
deep sleep while the device is enumerated as a USB gadget by a host, as
distinct from merely charging.

Detection reads /sys/class/udc/*/state and treats "configured" as
connected (PLAT_isUSBConnected), so it reflects an active data connection
rather than power presence. This matters when the battery is full: charging
already blocks sleep, but a full battery on USB would otherwise let the
device sleep and drop the connection.

The state is polled on the existing battery thread into a new
pwr.is_usb_connected atomic and, gated by CFG_getKeepAwakeWhenUSB, is
factored into both PWR_preventAutosleep() (no screen-off) and the
PWR_waitForWake() deep-sleep deferral, mirroring how is_charging is handled.

Setting defaults to off and is exposed in Settings under the tg5040-only
block. tg5050 and desktop get PLAT_isUSBConnected stubs returning 0.

Disclosure: LLMs were used to develop this code.
@Pobega

Pobega commented Jul 17, 2026

Copy link
Copy Markdown
Author

I tested this on a TrimUI Brick. I do not own any other tg5040 devices to test on.

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.

1 participant