1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

feat(core): allow T3T1 to start without touch during testing

[no changelog]
This commit is contained in:
tychovrahe 2024-03-04 15:46:58 +01:00 committed by TychoVrahe
parent 5e827e09c4
commit a80959e50f
7 changed files with 43 additions and 23 deletions

View File

@ -419,16 +419,28 @@ int bootloader_main(void) {
i2c_init();
#endif
#ifdef USE_TOUCH
touch_power_on();
touch_init();
#endif
display_reinit();
#ifdef USE_DMA2D
dma2d_init();
#endif
display_reinit();
unit_variant_init();
#ifdef USE_TOUCH
touch_power_on();
#ifdef TREZOR_MODEL_T3T1
// on T3T1, tester needs to run without touch, so making an exception
// until unit variant is written in OTP
if (unit_variant_present()) {
ensure(touch_init(), "Touch screen panel was not loaded properly.");
} else {
touch_init();
}
#else
ensure(touch_init(), "Touch screen panel was not loaded properly.");
#endif
#endif
#ifdef STM32U5
ensure(secret_ensure_initialized(), "secret reinitialized");
@ -508,8 +520,6 @@ int bootloader_main(void) {
rgb_led_init();
#endif
unit_variant_init();
#if PRODUCTION && !defined STM32U5
// for STM32U5, this check is moved to boardloader
check_bootloader_version();

View File

@ -107,7 +107,7 @@ static void touch_active_pin_state(void) {
HAL_Delay(5);
}
void touch_set_mode(void) {
secbool touch_set_mode(void) {
// set register 0xA4 G_MODE to interrupt trigger mode (0x01). basically, CTPM
// generates a pulse when new data is available
uint8_t touch_panel_config[] = {0xA4, 0x01};
@ -115,12 +115,12 @@ void touch_set_mode(void) {
if (HAL_OK == i2c_transmit(TOUCH_I2C_INSTANCE, TOUCH_ADDRESS,
touch_panel_config, sizeof(touch_panel_config),
10)) {
return;
return sectrue;
}
i2c_cycle(TOUCH_I2C_INSTANCE);
}
ensure(secfalse, "Touch screen panel was not loaded properly.");
return secfalse;
}
void touch_power_on(void) {
@ -136,7 +136,7 @@ void touch_power_off(void) {
touch_default_pin_state();
}
void touch_init(void) {
secbool touch_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
// PC4 capacitive touch panel module (CTPM) interrupt (INT) input
@ -147,8 +147,10 @@ void touch_init(void) {
HAL_GPIO_Init(TOUCH_INT_PORT, &GPIO_InitStructure);
__HAL_GPIO_EXTI_CLEAR_FLAG(TOUCH_INT_PIN);
touch_set_mode();
touch_sensitivity(TOUCH_SENSITIVITY);
if (sectrue != touch_set_mode()) {
return secfalse;
}
return touch_sensitivity(TOUCH_SENSITIVITY);
}
void touch_wait_until_ready(void) {
@ -158,19 +160,19 @@ void touch_wait_until_ready(void) {
}
}
void touch_sensitivity(uint8_t value) {
secbool touch_sensitivity(uint8_t value) {
// set panel threshold (TH_GROUP) - default value is 0x12
uint8_t touch_panel_threshold[] = {0x80, value};
for (int i = 0; i < 3; i++) {
if (HAL_OK == i2c_transmit(TOUCH_I2C_INSTANCE, TOUCH_ADDRESS,
touch_panel_threshold,
sizeof(touch_panel_threshold), 10)) {
return;
return sectrue;
}
i2c_cycle(TOUCH_I2C_INSTANCE);
}
ensure(secfalse, "Touch screen panel was not loaded properly.");
return secfalse;
}
uint32_t touch_is_detected(void) {

View File

@ -470,7 +470,7 @@ void stmpe811_Reset() {
IOE_Delay(2);
}
void touch_init(void) {
secbool touch_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
__HAL_RCC_GPIOA_CLK_ENABLE();
@ -486,9 +486,11 @@ void touch_init(void) {
stmpe811_Reset();
touch_set_mode();
touch_sensitivity(0x06);
return sectrue;
}
void touch_sensitivity(uint8_t value) {
secbool touch_sensitivity(uint8_t value) {
// set panel threshold (TH_GROUP) - default value is 0x12
// uint8_t touch_panel_threshold[] = {0x80, value};
// ensure(sectrue *
@ -496,6 +498,7 @@ void touch_sensitivity(uint8_t value) {
// &I2c_handle, TOUCH_ADDRESS, touch_panel_threshold,
// sizeof(touch_panel_threshold), 10)),
// NULL);
return sectrue;
}
uint32_t touch_is_detected(void) {

View File

@ -49,6 +49,8 @@ uint32_t systick_val_copy = 0;
extern void shutdown_privileged(void);
void __attribute__((noreturn)) trezor_shutdown(void) {
display_finish_actions();
__HAL_RCC_SAES_CLK_DISABLE();
// Erase all secrets
TAMP->CR2 |= TAMP_CR2_BKERASE;

View File

@ -1135,7 +1135,7 @@ static int32_t SITRONIX_Probe(uint32_t Instance) {
#include <string.h>
#include "touch.h"
void touch_init(void) {
secbool touch_init(void) {
TS_Init_t TsInit;
/* Initialize the TouchScreen */
@ -1145,10 +1145,12 @@ void touch_init(void) {
TsInit.Accuracy = 10;
BSP_TS_Init(0, &TsInit);
return sectrue;
}
void touch_power_on(void) {}
void touch_power_off(void) {}
void touch_sensitivity(uint8_t value) {}
secbool touch_sensitivity(uint8_t value) { return sectrue; }
uint32_t touch_is_detected(void) { return sitronix_touching != 0; }

View File

@ -2,17 +2,18 @@
#define _TOUCH_H
#include <stdint.h>
#include "secbool.h"
#define TOUCH_START (1U << 24)
#define TOUCH_MOVE (1U << 25)
#define TOUCH_END (1U << 26)
void touch_init(void);
secbool touch_init(void);
void touch_power_on(void);
void touch_power_off(void);
void touch_wait_until_ready(void);
void touch_sensitivity(uint8_t value);
secbool touch_sensitivity(uint8_t value);
uint32_t touch_read(void);
uint32_t touch_click(void);
uint32_t touch_is_detected(void);

View File

@ -217,7 +217,7 @@ uint32_t touch_read(void) {
return ev_type | touch_pack_xy(ev_x, ev_y);
}
void touch_init(void) {}
secbool touch_init(void) { return sectrue; }
void touch_power_on(void) {}
void touch_wait_until_ready(void) {}