mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-02 11:58:32 +00:00
feat(core/prodtest): add hibernation on power button long-press
[no changelog]
This commit is contained in:
parent
f579d31684
commit
8ea957b8e1
@ -32,6 +32,11 @@ void rgb_led_deinit(void);
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RGBLED_GREEN 0x00FF00
|
||||||
|
#define RGBLED_RED 0xFF0000
|
||||||
|
#define RGBLED_BLUE 0x0000FF
|
||||||
|
#define RGBLED_YELLOW 0xFFFF00
|
||||||
|
|
||||||
// Set RGB LED color
|
// Set RGB LED color
|
||||||
// color: 24-bit RGB color, 0x00RRGGBB
|
// color: 24-bit RGB color, 0x00RRGGBB
|
||||||
void rgb_led_set_color(uint32_t color);
|
void rgb_led_set_color(uint32_t color);
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include <io/rgb_led.h>
|
#include <io/rgb_led.h>
|
||||||
#include <rtl/cli.h>
|
#include <rtl/cli.h>
|
||||||
|
|
||||||
|
#include "../prodtest.h"
|
||||||
|
|
||||||
static void prodtest_rgbled_set(cli_t* cli) {
|
static void prodtest_rgbled_set(cli_t* cli) {
|
||||||
uint32_t r = 0;
|
uint32_t r = 0;
|
||||||
uint32_t g = 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);
|
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;
|
uint32_t rgb = (r << 16) | (g << 8) | b;
|
||||||
|
|
||||||
rgb_led_set_color(rgb);
|
rgb_led_set_color(rgb);
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <io/usb.h>
|
#include <io/usb.h>
|
||||||
#include <rtl/cli.h>
|
#include <rtl/cli.h>
|
||||||
#include <sys/system.h>
|
#include <sys/system.h>
|
||||||
|
#include <sys/systick.h>
|
||||||
#include <util/flash_otp.h>
|
#include <util/flash_otp.h>
|
||||||
#include <util/rsod.h>
|
#include <util/rsod.h>
|
||||||
#include <util/unit_properties.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) {
|
static void drivers_init(void) {
|
||||||
#ifdef USE_POWERCTL
|
#ifdef USE_POWERCTL
|
||||||
powerctl_init();
|
powerctl_init();
|
||||||
@ -248,10 +254,44 @@ int main(void) {
|
|||||||
pair_optiga(&g_cli);
|
pair_optiga(&g_cli);
|
||||||
#endif
|
#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) {
|
while (true) {
|
||||||
if (usb_vcp_can_read(VCP_IFACE)) {
|
if (usb_vcp_can_read(VCP_IFACE)) {
|
||||||
cli_process_io(&g_cli);
|
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;
|
return 0;
|
||||||
|
23
core/embed/projects/prodtest/prodtest.h
Normal file
23
core/embed/projects/prodtest/prodtest.h
Normal 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);
|
Loading…
Reference in New Issue
Block a user