1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-27 13:35:44 +00:00

menu: turn off

This commit is contained in:
tychovrahe 2025-03-11 03:40:38 +01:00
parent 0ef7d0634c
commit 48aa377929
3 changed files with 52 additions and 19 deletions

View File

@ -34,6 +34,7 @@ typedef enum {
MENU_EXIT = 0xAABBCCDD, MENU_EXIT = 0xAABBCCDD,
MENU_REBOOT = 0x11223344, MENU_REBOOT = 0x11223344,
MENU_WIPE = 0x55667788, MENU_WIPE = 0x55667788,
MENU_TURN_OFF = 0x99AABBCC,
} menu_result_t; } menu_result_t;
// todo: use bindgen to tie this to rust // todo: use bindgen to tie this to rust

View File

@ -23,6 +23,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <util/image.h> #include <util/image.h>
#ifdef USE_POWERCTL
#include <sys/powerctl.h>
#endif
#include "antiglitch.h" #include "antiglitch.h"
#include "bootui.h" #include "bootui.h"
#include "workflow.h" #include "workflow.h"
@ -79,6 +83,11 @@ workflow_result_t workflow_bootloader(const vendor_header *const vhdr,
} }
return WF_ERROR_FATAL; return WF_ERROR_FATAL;
} }
#ifdef USE_POWERCTL
if (menu_result == MENU_TURN_OFF) {
powerctl_hibernate();
}
#endif
break; break;
case SCREEN_WAIT_FOR_HOST: case SCREEN_WAIT_FOR_HOST:
workflow_result_t res = workflow_result_t res =

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
trezorhal::secbool::{secbool, sectrue}, trezorhal::secbool::{secbool, sectrue},
ui::{ ui::{
component::{Child, Component, Event, EventCtx, Label, Pad}, component::{Component, Event, EventCtx, Label, Pad},
constant::{screen, WIDTH}, constant::{screen, WIDTH},
display::Icon, display::Icon,
geometry::{Insets, Point, Rect}, geometry::{Insets, Point, Rect},
@ -26,14 +26,16 @@ pub enum MenuMsg {
Close = 0xAABBCCDD, Close = 0xAABBCCDD,
Reboot = 0x11223344, Reboot = 0x11223344,
FactoryReset = 0x55667788, FactoryReset = 0x55667788,
TurnOff = 0x99AABBCC,
} }
pub struct Menu { pub struct Menu {
bg: Pad, bg: Pad,
title: Child<Label<'static>>, title: Label<'static>,
close: Child<Button>, close: Button,
reboot: Child<Button>, reboot: Button,
reset: Child<Button>, reset: Button,
turn_off: Option<Button>,
} }
impl Menu { impl Menu {
@ -41,22 +43,29 @@ impl Menu {
let content_reboot = IconText::new("REBOOT TREZOR", Icon::new(REFRESH24)); let content_reboot = IconText::new("REBOOT TREZOR", Icon::new(REFRESH24));
let content_reset = IconText::new("FACTORY RESET", Icon::new(FIRE24)); let content_reset = IconText::new("FACTORY RESET", Icon::new(FIRE24));
let turn_off = IconText::new("TURN OFF", Icon::new(FIRE24));
#[cfg(not(feature = "powerctl"))]
let turn_off_menu_item = false;
#[cfg(feature = "powerctl")]
let turn_off_menu_item = true;
let mut instance = Self { let mut instance = Self {
bg: Pad::with_background(BLD_BG), bg: Pad::with_background(BLD_BG),
title: Child::new( title: Label::left_aligned("BOOTLOADER".into(), text_title(BLD_BG))
Label::left_aligned("BOOTLOADER".into(), text_title(BLD_BG)).vertically_centered(), .vertically_centered(),
), close: Button::with_icon(Icon::new(X32))
close: Child::new( .styled(button_bld_menu())
Button::with_icon(Icon::new(X32)) .with_expanded_touch_area(Insets::uniform(CORNER_BUTTON_TOUCH_EXPANSION)),
.styled(button_bld_menu()) reboot: Button::with_icon_and_text(content_reboot)
.with_expanded_touch_area(Insets::uniform(CORNER_BUTTON_TOUCH_EXPANSION)), .styled(button_bld())
), .initially_enabled(sectrue == firmware_present),
reboot: Child::new( reset: Button::with_icon_and_text(content_reset).styled(button_bld()),
Button::with_icon_and_text(content_reboot) turn_off: if turn_off_menu_item {
.styled(button_bld()) Some(Button::with_icon_and_text(turn_off).styled(button_bld()))
.initially_enabled(sectrue == firmware_present), } else {
), None
reset: Child::new(Button::with_icon_and_text(content_reset).styled(button_bld())), },
}; };
instance.bg.clear(); instance.bg.clear();
instance instance
@ -84,6 +93,16 @@ impl Component for Menu {
BUTTON_AREA_START + 2 * BUTTON_HEIGHT + BUTTON_SPACING, BUTTON_AREA_START + 2 * BUTTON_HEIGHT + BUTTON_SPACING,
), ),
)); ));
self.turn_off.place(Rect::new(
Point::new(
CONTENT_PADDING,
BUTTON_AREA_START + 2 * BUTTON_HEIGHT + 2 * BUTTON_SPACING,
),
Point::new(
WIDTH - CONTENT_PADDING,
BUTTON_AREA_START + 3 * BUTTON_HEIGHT + 2 * BUTTON_SPACING,
),
));
bounds bounds
} }
@ -97,6 +116,9 @@ impl Component for Menu {
if let Some(Clicked) = self.reset.event(ctx, event) { if let Some(Clicked) = self.reset.event(ctx, event) {
return Some(Self::Msg::FactoryReset); return Some(Self::Msg::FactoryReset);
} }
if let Some(Clicked) = self.turn_off.event(ctx, event) {
return Some(Self::Msg::TurnOff);
}
None None
} }
@ -107,5 +129,6 @@ impl Component for Menu {
self.close.render(target); self.close.render(target);
self.reboot.render(target); self.reboot.render(target);
self.reset.render(target); self.reset.render(target);
self.turn_off.render(target);
} }
} }