Skip to content

Commit

Permalink
Start USB only after detecting a connection. (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihuanhuan authored Jun 11, 2024
1 parent 2825a90 commit 8d7fece
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions core/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@

# === Prepare the USB interfaces first. Do not connect to the host yet.
# usb imports trezor.utils and trezor.io which is a C module
import usb
import usb # noqa: F401

# start the USB
# import storage.device
# if not storage.device.is_airgap_mode():
# usb.bus.open(storage.device.get_device_id())

import storage.device
if not storage.device.is_airgap_mode():
usb.bus.open(storage.device.get_device_id())
storage.device.get_device_id()

# initialize the status bar
StatusBar.get_instance()
Expand Down
8 changes: 8 additions & 0 deletions core/src/trezor/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ async def _deal_charging_state(value: bytes) -> None:
if utils.CHARGE_WIRELESS_STATUS != utils.CHARGE_WIRELESS_STOP:
utils.CHARGE_WIRELESS_STATUS = utils.CHARGE_WIRELESS_STOP
ctrl_charge_switch(True)
if not device.is_airgap_mode() and usb.bus.state() == 0:
usb.bus = usb.init()
for iface in usb.active_iface:
usb.bus.add(iface)
usb.bus.open(device.get_device_id())

elif res in (_USB_STATUS_PLUG_OUT, _POWER_STATUS_CHARGING_FINISHED):
if utils.CHARGE_WIRELESS_STATUS != utils.CHARGE_WIRELESS_STOP:
Expand All @@ -392,6 +397,9 @@ async def _deal_charging_state(value: bytes) -> None:
StatusBar.get_instance().show_usb(False)
if utils.BATTERY_CAP:
StatusBar.get_instance().set_battery_img(utils.BATTERY_CAP, utils.CHARGING)
if res == _USB_STATUS_PLUG_OUT:
if usb.bus.state() == 1:
usb.bus.close()

utils.turn_on_lcd_if_possible()

Expand Down

0 comments on commit 8d7fece

Please sign in to comment.