1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-16 07:15:47 +00:00

feat(core/prodtest): add hibernation on power button long-press

[no changelog]
This commit is contained in:
tychovrahe 2025-03-20 14:47:25 +01:00 committed by TychoVrahe
parent f579d31684
commit 8ea957b8e1
4 changed files with 73 additions and 0 deletions

View File

@ -32,6 +32,11 @@ void rgb_led_deinit(void);
#endif
#define RGBLED_GREEN 0x00FF00
#define RGBLED_RED 0xFF0000
#define RGBLED_BLUE 0x0000FF
#define RGBLED_YELLOW 0xFFFF00
// Set RGB LED color
// color: 24-bit RGB color, 0x00RRGGBB
void rgb_led_set_color(uint32_t color);

View File

@ -24,6 +24,8 @@
#include <io/rgb_led.h>
#include <rtl/cli.h>
#include "../prodtest.h"
static void prodtest_rgbled_set(cli_t* cli) {
uint32_t r = 0;
uint32_t g = 0;
@ -51,6 +53,9 @@ static void prodtest_rgbled_set(cli_t* cli) {
cli_trace(cli, "Setting the RGB LED color to [%d, %d, %d]...", r, g, b);
// Disable automatic control of RGB LED in prodtest main loop
prodtest_disable_rgbled_control();
uint32_t rgb = (r << 16) | (g << 8) | b;
rgb_led_set_color(rgb);

View File

@ -24,6 +24,7 @@
#include <io/usb.h>
#include <rtl/cli.h>
#include <sys/system.h>
#include <sys/systick.h>
#include <util/flash_otp.h>
#include <util/rsod.h>
#include <util/unit_properties.h>
@ -176,6 +177,11 @@ static void show_welcome_screen(void) {
}
}
// Set if the RGB LED must not be controlled by the main loop
static bool g_rgbled_control_disabled = false;
void prodtest_disable_rgbled_control(void) { g_rgbled_control_disabled = true; }
static void drivers_init(void) {
#ifdef USE_POWERCTL
powerctl_init();
@ -248,10 +254,44 @@ int main(void) {
pair_optiga(&g_cli);
#endif
#if defined USE_BUTTON && defined USE_POWERCTL
uint32_t btn_deadline = 0;
#endif
#ifdef USE_RGB_LED
uint32_t led_start_deadline = ticks_timeout(1000);
rgb_led_set_color(RGBLED_GREEN);
#endif
while (true) {
if (usb_vcp_can_read(VCP_IFACE)) {
cli_process_io(&g_cli);
}
#if defined USE_BUTTON && defined USE_POWERCTL
button_event_t btn_event = {0};
if (button_get_event(&btn_event) && btn_event.button == BTN_POWER) {
if (btn_event.event_type == BTN_EVENT_DOWN) {
btn_deadline = ticks_timeout(1000);
} else if (btn_event.event_type == BTN_EVENT_UP) {
if (ticks_expired(btn_deadline)) {
powerctl_hibernate();
rgb_led_set_color(RGBLED_YELLOW);
systick_delay_ms(1000);
rgb_led_set_color(0);
}
}
}
if (button_is_down(BTN_POWER) && ticks_expired(btn_deadline)) {
rgb_led_set_color(RGBLED_RED);
}
#endif
#ifdef USE_RGB_LED
if (ticks_expired(led_start_deadline) && !g_rgbled_control_disabled) {
rgb_led_set_color(0);
}
#endif
}
return 0;

View File

@ -0,0 +1,23 @@
/*
* This file is part of the Trezor project, https://trezor.io/
*
* Copyright (c) SatoshiLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
// Disable automatic control of RGB LED in prodtest main loop
void prodtest_disable_rgbled_control(void);