mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
fix(core): fix usb disconnected warning in new homescreen
[no changelog]
This commit is contained in:
parent
02e2b50d3f
commit
12f87aa01e
@ -329,7 +329,9 @@ fn generate_trezorhal_bindings() {
|
||||
.allowlist_function("buffers_get_line_buffer_4bpp")
|
||||
.allowlist_function("buffers_get_text_buffer")
|
||||
.allowlist_var("text_buffer_height")
|
||||
.allowlist_var("buffer_width");
|
||||
.allowlist_var("buffer_width")
|
||||
//usb
|
||||
.allowlist_function("usb_configured");
|
||||
// Write the bindings to a file in the OUR_DIR.
|
||||
bindings
|
||||
.generate()
|
||||
|
@ -13,6 +13,7 @@ pub mod random;
|
||||
pub mod rgb_led;
|
||||
pub mod slip39;
|
||||
pub mod storage;
|
||||
pub mod usb;
|
||||
pub mod uzlib;
|
||||
|
||||
pub mod buffers;
|
||||
|
5
core/embed/rust/src/trezorhal/usb.rs
Normal file
5
core/embed/rust/src/trezorhal/usb.rs
Normal file
@ -0,0 +1,5 @@
|
||||
use super::ffi;
|
||||
|
||||
pub fn usb_configured() -> bool {
|
||||
unsafe { ffi::usb_configured() == ffi::sectrue }
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
time::{Duration, Instant},
|
||||
trezorhal::usb::usb_configured,
|
||||
ui::{
|
||||
component::{Component, Empty, Event, EventCtx, Pad, TimerToken},
|
||||
display::{self, Color, Font},
|
||||
@ -45,7 +46,6 @@ where
|
||||
label,
|
||||
notification,
|
||||
hold_to_lock,
|
||||
usb_connected: true,
|
||||
loader: Loader::new().with_durations(LOADER_DURATION, LOADER_DURATION / 3),
|
||||
pad: Pad::with_background(theme::BG),
|
||||
delay: None,
|
||||
@ -61,7 +61,7 @@ where
|
||||
}
|
||||
|
||||
fn paint_notification(&self) {
|
||||
if !self.usb_connected {
|
||||
if !usb_configured() {
|
||||
let (color, icon) = Self::level_to_style(0);
|
||||
NotificationFrame::<Empty, T>::paint_notification(
|
||||
AREA,
|
||||
@ -91,12 +91,13 @@ where
|
||||
self.loader.paint()
|
||||
}
|
||||
|
||||
pub fn set_paint_notification(&mut self) {
|
||||
self.paint_notification_only = true;
|
||||
}
|
||||
|
||||
fn event_usb(&mut self, ctx: &mut EventCtx, event: Event) {
|
||||
if let Event::USB(USBEvent::Connected(is_connected)) = event {
|
||||
if self.usb_connected != is_connected {
|
||||
self.usb_connected = is_connected;
|
||||
ctx.request_paint();
|
||||
}
|
||||
if let Event::USB(USBEvent::Connected(_)) = event {
|
||||
ctx.request_paint();
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,6 +123,7 @@ where
|
||||
Event::Timer(token) if Some(token) == self.delay => {
|
||||
self.delay = None;
|
||||
self.pad.clear();
|
||||
self.paint_notification_only = false;
|
||||
self.loader.start_growing(ctx, Instant::now());
|
||||
}
|
||||
_ => {}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "rgb_led.h"
|
||||
#include "secbool.h"
|
||||
#include "storage.h"
|
||||
#include "usb.h"
|
||||
|
||||
#include "bip39.h"
|
||||
#include "rand.h"
|
||||
|
@ -17,33 +17,16 @@ class HomescreenBase(RustLayout):
|
||||
|
||||
def __init__(self, layout: Any) -> None:
|
||||
super().__init__(layout=layout)
|
||||
self.is_connected = True
|
||||
|
||||
async def __iter__(self) -> Any:
|
||||
# We need to catch the ui.Cancelled exception that kills us, because that means
|
||||
# that we will need to draw on screen again after restart.
|
||||
try:
|
||||
return await super().__iter__()
|
||||
except ui.Cancelled:
|
||||
storage_cache.homescreen_shown = None
|
||||
raise
|
||||
def _paint(self) -> None:
|
||||
self.layout.paint()
|
||||
|
||||
def _first_paint(self) -> None:
|
||||
from trezor import utils
|
||||
|
||||
if storage_cache.homescreen_shown is not self.RENDER_INDICATOR:
|
||||
super()._first_paint()
|
||||
storage_cache.homescreen_shown = self.RENDER_INDICATOR
|
||||
|
||||
# - RENDER_INDICATOR is set -> USB warning is not displayed
|
||||
# - RENDER_INDICATOR is not set -> initially homescreen does not display warning
|
||||
# - usb_checker_task only handles state changes
|
||||
# Here we need to handle the case when homescreen is started with USB disconnected.
|
||||
if not utils.usb_data_connected():
|
||||
msg = self.layout.usb_event(False)
|
||||
else:
|
||||
self._paint()
|
||||
if msg is not None:
|
||||
raise ui.Result(msg)
|
||||
|
||||
# In __debug__ mode, ignore {confirm,swipe,input}_signal.
|
||||
def create_tasks(self) -> tuple[loop.AwaitableTask, ...]:
|
||||
@ -85,11 +68,8 @@ class Homescreen(HomescreenBase):
|
||||
usbcheck = loop.wait(io.USB_CHECK)
|
||||
while True:
|
||||
is_connected = await usbcheck
|
||||
if is_connected != self.is_connected:
|
||||
self.is_connected = is_connected
|
||||
self.layout.usb_event(is_connected)
|
||||
self.layout.paint()
|
||||
storage_cache.homescreen_shown = None
|
||||
self.layout.usb_event(is_connected)
|
||||
self.layout.paint()
|
||||
|
||||
def create_tasks(self) -> Tuple[loop.AwaitableTask, ...]:
|
||||
return super().create_tasks() + (self.usb_checker_task(),)
|
||||
|
Loading…
Reference in New Issue
Block a user