mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-22 20:42:03 +00:00
remove trezor.main, simplify trezor.workflow
This commit is contained in:
parent
bdc9496ff0
commit
3db1bf89fa
12
src/main.py
12
src/main.py
@ -1,8 +1,15 @@
|
|||||||
from micropython import const
|
from micropython import const
|
||||||
|
|
||||||
|
from trezor import config
|
||||||
from trezor import io
|
from trezor import io
|
||||||
|
from trezor import log
|
||||||
|
from trezor import loop
|
||||||
from trezor import wire
|
from trezor import wire
|
||||||
from trezor import main
|
from trezor import workflow
|
||||||
|
|
||||||
|
config.init()
|
||||||
|
|
||||||
|
log.level = log.DEBUG
|
||||||
|
|
||||||
# initialize the USB stack
|
# initialize the USB stack
|
||||||
usb_wire = io.HID(
|
usb_wire = io.HID(
|
||||||
@ -97,4 +104,5 @@ wire.setup(usb_wire)
|
|||||||
from apps.homescreen.homescreen import layout_homescreen
|
from apps.homescreen.homescreen import layout_homescreen
|
||||||
|
|
||||||
# run main even loop and specify which screen is default
|
# run main even loop and specify which screen is default
|
||||||
main.run(default_workflow=layout_homescreen)
|
workflow.startdefault(layout_homescreen)
|
||||||
|
loop.run()
|
@ -4,7 +4,7 @@ the form of python coroutines (either plain generators or `async` functions) are
|
|||||||
stepped through until completion, and can get asynchronously blocked by
|
stepped through until completion, and can get asynchronously blocked by
|
||||||
`yield`ing or `await`ing a syscall.
|
`yield`ing or `await`ing a syscall.
|
||||||
|
|
||||||
See `schedule_task`, `run_forever`, and syscalls `Sleep`, `Select`, `Signal`
|
See `schedule_task`, `run`, and syscalls `Sleep`, `Select`, `Signal`
|
||||||
and `Wait`.
|
and `Wait`.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ if __debug__:
|
|||||||
def schedule_task(task, value=None, deadline=None):
|
def schedule_task(task, value=None, deadline=None):
|
||||||
'''
|
'''
|
||||||
Schedule task to be executed with `value` on given `deadline` (in
|
Schedule task to be executed with `value` on given `deadline` (in
|
||||||
microseconds). Does not start the event loop itself, see `run_forever`.
|
microseconds). Does not start the event loop itself, see `run`.
|
||||||
'''
|
'''
|
||||||
if deadline is None:
|
if deadline is None:
|
||||||
deadline = utime.ticks_us()
|
deadline = utime.ticks_us()
|
||||||
@ -75,7 +75,7 @@ def _unpause_task(task):
|
|||||||
_paused_tasks[iface].remove(task)
|
_paused_tasks[iface].remove(task)
|
||||||
|
|
||||||
|
|
||||||
def run_forever():
|
def run():
|
||||||
'''
|
'''
|
||||||
Loop forever, stepping through scheduled tasks and awaiting I/O events
|
Loop forever, stepping through scheduled tasks and awaiting I/O events
|
||||||
inbetween. Use `schedule_task` first to add a coroutine to the task queue.
|
inbetween. Use `schedule_task` first to add a coroutine to the task queue.
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
from trezor import config
|
|
||||||
from trezor import loop
|
|
||||||
from trezor import workflow
|
|
||||||
from trezor import log
|
|
||||||
|
|
||||||
config.init()
|
|
||||||
|
|
||||||
log.level = log.DEBUG
|
|
||||||
|
|
||||||
|
|
||||||
def run(default_workflow):
|
|
||||||
workflow.start_default(default_workflow)
|
|
||||||
loop.run_forever()
|
|
@ -112,7 +112,12 @@ async def session_handler(iface, sid):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
handler, args = unexpected_msg, ()
|
handler, args = unexpected_msg, ()
|
||||||
|
|
||||||
await handler(ctx, reader, *args)
|
w = handler(ctx, reader, *args)
|
||||||
|
try:
|
||||||
|
workflow.onstart(w)
|
||||||
|
await w
|
||||||
|
finally:
|
||||||
|
workflow.onclose(w)
|
||||||
|
|
||||||
except UnexpectedMessageError as exc:
|
except UnexpectedMessageError as exc:
|
||||||
# retry with opened reader from the exception
|
# retry with opened reader from the exception
|
||||||
|
@ -1,40 +1,43 @@
|
|||||||
from trezor import log, loop, ui
|
from trezor import log
|
||||||
|
from trezor import loop
|
||||||
|
from trezor import ui
|
||||||
|
|
||||||
_started = []
|
started = []
|
||||||
_default = None
|
default = None
|
||||||
_default_genfunc = None
|
default_handler = None
|
||||||
|
|
||||||
|
|
||||||
def start_default(genfunc):
|
def onstart(w):
|
||||||
global _default
|
closedefault()
|
||||||
global _default_genfunc
|
started.append(w)
|
||||||
_default_genfunc = genfunc
|
|
||||||
_default = _default_genfunc()
|
|
||||||
log.info(__name__, 'start default %s', _default)
|
|
||||||
loop.schedule_task(_default)
|
|
||||||
ui.display.backlight(ui.BACKLIGHT_NORMAL)
|
ui.display.backlight(ui.BACKLIGHT_NORMAL)
|
||||||
|
log.debug(__name__, 'onstart: %s', w)
|
||||||
|
|
||||||
|
|
||||||
def close_default():
|
def onclose(w):
|
||||||
global _default
|
started.remove(w)
|
||||||
if _default is not None:
|
log.debug(__name__, 'onclose: %s', w)
|
||||||
log.info(__name__, 'close default %s', _default)
|
|
||||||
_default.close()
|
if not started and default_handler:
|
||||||
_default = None
|
startdefault(default_handler)
|
||||||
|
|
||||||
|
|
||||||
def start(workflow):
|
def closedefault():
|
||||||
close_default()
|
global default
|
||||||
_started.append(workflow)
|
|
||||||
log.info(__name__, 'start %s', workflow)
|
if default:
|
||||||
loop.schedule_task(_watch(workflow))
|
default.close()
|
||||||
ui.display.backlight(ui.BACKLIGHT_NORMAL)
|
default = None
|
||||||
|
log.debug(__name__, 'closedefault')
|
||||||
|
|
||||||
|
|
||||||
async def _watch(workflow):
|
def startdefault(handler):
|
||||||
try:
|
global default
|
||||||
return await workflow
|
global default_handler
|
||||||
finally:
|
|
||||||
_started.remove(workflow)
|
if not default:
|
||||||
if not _started and _default_genfunc is not None:
|
default_handler = handler
|
||||||
start_default(_default_genfunc)
|
default = handler()
|
||||||
|
loop.schedule_task(default)
|
||||||
|
ui.display.backlight(ui.BACKLIGHT_NORMAL)
|
||||||
|
log.debug(__name__, 'startdefault')
|
Loading…
Reference in New Issue
Block a user