mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
replace wait with msg.select
This commit is contained in:
parent
fa52ecfb79
commit
1664a4fc29
@ -47,10 +47,15 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_send(mp_obj_t self, mp_obj_t message) {
|
|||||||
}
|
}
|
||||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send);
|
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_send);
|
||||||
|
|
||||||
// def Msg.select(self, timeout_ms: int) -> None/tuple/bytes
|
#define TICK_RESOLUTION 1000
|
||||||
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_ms) {
|
|
||||||
int to = mp_obj_get_int(timeout_ms);
|
// def Msg.select(self, timeout_us: int) -> None/tuple/bytes
|
||||||
while (--to >= 0) {
|
STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
|
||||||
|
int to = mp_obj_get_int(timeout_us);
|
||||||
|
if (to < 0) {
|
||||||
|
to = 0;
|
||||||
|
}
|
||||||
|
while (to >= 0) {
|
||||||
uint32_t e = msg_poll_ui_event();
|
uint32_t e = msg_poll_ui_event();
|
||||||
if (e) {
|
if (e) {
|
||||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||||
@ -66,7 +71,8 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_ms) {
|
|||||||
memcpy(vstr.buf, m, 64);
|
memcpy(vstr.buf, m, 64);
|
||||||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
|
||||||
}
|
}
|
||||||
mp_hal_delay_ms(1);
|
mp_hal_delay_us_fast(TICK_RESOLUTION);
|
||||||
|
to -= TICK_RESOLUTION;
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
9
send_udp.py
Executable file
9
send_udp.py
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import socket
|
||||||
|
|
||||||
|
UDP_IP = '127.0.0.1'
|
||||||
|
UDP_PORT = 21324
|
||||||
|
MESSAGE = b'Hello, World!'
|
||||||
|
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
|
@ -2,6 +2,7 @@ import utime
|
|||||||
import uheapq
|
import uheapq
|
||||||
|
|
||||||
from .utils import type_gen
|
from .utils import type_gen
|
||||||
|
from . import msg
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
import logging
|
import logging
|
||||||
@ -34,7 +35,10 @@ def wait(delay):
|
|||||||
log.debug("Sleeping for: %s", delay)
|
log.debug("Sleeping for: %s", delay)
|
||||||
|
|
||||||
last_sleep = delay
|
last_sleep = delay
|
||||||
utime.sleep_us(delay)
|
m = msg.select(delay)
|
||||||
|
if m:
|
||||||
|
print('msg:', m)
|
||||||
|
return m
|
||||||
|
|
||||||
def run_forever():
|
def run_forever():
|
||||||
global q, cnt
|
global q, cnt
|
||||||
@ -47,11 +51,12 @@ def run_forever():
|
|||||||
tnow = utime.ticks_us()
|
tnow = utime.ticks_us()
|
||||||
delay = t - tnow
|
delay = t - tnow
|
||||||
if delay > 0:
|
if delay > 0:
|
||||||
wait(delay)
|
m = wait(delay)
|
||||||
else:
|
else:
|
||||||
wait(-1)
|
m = wait(0)
|
||||||
# Assuming IO completion scheduled some tasks
|
# Assuming IO completion scheduled some tasks
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if callable(cb):
|
if callable(cb):
|
||||||
ret = cb(*args)
|
ret = cb(*args)
|
||||||
if __debug__ and isinstance(ret, type_gen):
|
if __debug__ and isinstance(ret, type_gen):
|
||||||
|
@ -2,8 +2,8 @@ from TrezorMsg import Msg
|
|||||||
|
|
||||||
_msg = Msg()
|
_msg = Msg()
|
||||||
|
|
||||||
def select(timeout_ms):
|
def select(timeout_us):
|
||||||
return _msg.select(timeout_ms)
|
return _msg.select(timeout_us)
|
||||||
|
|
||||||
def send(msg):
|
def send(msg):
|
||||||
return _msg.send(msg)
|
return _msg.send(msg)
|
||||||
|
2
vendor/micropython
vendored
2
vendor/micropython
vendored
@ -1 +1 @@
|
|||||||
Subproject commit da3fe60b7dc12ce393e9a63c9d6ac366b9c81045
|
Subproject commit c4e00834d394bf07e3c347494648c7fe73fee50b
|
Loading…
Reference in New Issue
Block a user