Skip to content

Commit

Permalink
perf(core): optimize boot time by removing unnecessary touch initiali…
Browse files Browse the repository at this point in the history
…zation delays
  • Loading branch information
TychoVrahe committed Feb 5, 2024
1 parent 017622f commit b4723ac
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions core/embed/bootloader/.changelog.d/3429.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speed-up device boot
32 changes: 16 additions & 16 deletions core/embed/bootloader/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ int bootloader_main(void) {

random_delays_init();

#if defined TREZOR_MODEL_T
set_core_clock(CLOCK_180_MHZ);
#endif

#ifdef STM32U5
if (sectrue != flash_configure_sec_area_ob()) {
#ifdef STM32U5
Expand All @@ -425,6 +429,15 @@ int bootloader_main(void) {
hash_processor_init();
#endif

#ifdef USE_I2C
i2c_init();
#endif

#ifdef USE_TOUCH
touch_power_on();
touch_init();
#endif

#ifdef USE_DMA2D
dma2d_init();
#endif
Expand Down Expand Up @@ -489,24 +502,10 @@ int bootloader_main(void) {
firmware_present_backup = firmware_present;
}

#if defined TREZOR_MODEL_T
set_core_clock(CLOCK_180_MHZ);
display_set_little_endian();
#endif

#ifdef USE_I2C
i2c_init();
#endif

#ifdef USE_OPTIGA
optiga_hal_init();
#endif

#ifdef USE_TOUCH
touch_power_on();
touch_init();
#endif

#ifdef USE_BUTTON
button_init();
#endif
Expand Down Expand Up @@ -549,15 +548,16 @@ int bootloader_main(void) {
uint32_t touched = 0;
#ifdef USE_TOUCH
if (firmware_present == sectrue && stay_in_bootloader != sectrue) {
for (int i = 0; i < 100; i++) {
touch_wait_until_ready();
for (int i = 0; i < 10; i++) {
touched = touch_is_detected() | touch_read();
if (touched) {
break;
}
#ifdef TREZOR_EMULATOR
hal_delay(25);
#else
hal_delay(1);
hal_delay_us(1000);
#endif
}
}
Expand Down
25 changes: 20 additions & 5 deletions core/embed/trezorhal/stm32f4/touch/ft6x36.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
#define EVENT_OLD_TIMEOUT_MS 50
#define EVENT_MISSING_TIMEOUT_MS 50

static uint32_t touch_init_ticks = 0;

static void touch_default_pin_state(void) {
GPIO_PinState state = HAL_GPIO_ReadPin(TOUCH_ON_PORT, TOUCH_ON_PIN);

// set power off and other pins as per section 3.5 of FT6236 datasheet
HAL_GPIO_WritePin(TOUCH_ON_PORT, TOUCH_ON_PIN,
GPIO_PIN_SET); // CTP_ON (active low) i.e.- CTPM power
Expand Down Expand Up @@ -74,7 +78,11 @@ static void touch_default_pin_state(void) {
// for these changes to take effect. a reset needs to be low for
// a minimum of 5ms. also wait for power circuitry to stabilize (if it
// changed).
HAL_Delay(100); // 100ms (being conservative)
HAL_Delay(10);

if (state == GPIO_PIN_SET) {
HAL_Delay(90); // add 90 ms for circuitry to stabilize (being conservative)
}
}

static void touch_active_pin_state(void) {
Expand All @@ -93,8 +101,10 @@ static void touch_active_pin_state(void) {

HAL_GPIO_WritePin(TOUCH_RST_PORT, TOUCH_RST_PIN,
GPIO_PIN_SET); // release CTPM reset
HAL_Delay(310); // "Time of starting to report point after resetting" min is
// 300ms, giving an extra 10ms

touch_init_ticks = hal_ticks_ms();

HAL_Delay(5);
}

void touch_set_mode(void) {
Expand All @@ -118,8 +128,6 @@ void touch_power_on(void) {

// turn on CTP circuitry
touch_active_pin_state();

HAL_Delay(50);
}

void touch_power_off(void) {
Expand All @@ -143,6 +151,13 @@ void touch_init(void) {
touch_sensitivity(TOUCH_SENSITIVITY);
}

void touch_wait_until_ready(void) {
// wait for the touch controller to be ready
while (hal_ticks_ms() - touch_init_ticks < 310) {
HAL_Delay(1);
}
}

void touch_sensitivity(uint8_t value) {
// set panel threshold (TH_GROUP) - default value is 0x12
uint8_t touch_panel_threshold[] = {0x80, value};
Expand Down
2 changes: 2 additions & 0 deletions core/embed/trezorhal/stm32f4/touch/stmpe811.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,5 @@ uint32_t touch_read(void) {

return 0;
}

void touch_wait_until_ready(void) {}
2 changes: 2 additions & 0 deletions core/embed/trezorhal/stm32u5/touch/sitronix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,3 +1212,5 @@ uint32_t touch_read(void) {

return 0;
}

void touch_wait_until_ready(void) {}
2 changes: 2 additions & 0 deletions core/embed/trezorhal/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
void 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);
uint32_t touch_read(void);
uint32_t touch_click(void);
Expand Down
1 change: 1 addition & 0 deletions core/embed/trezorhal/unix/touch/touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ uint32_t touch_read(void) {

void touch_init(void) {}
void touch_power_on(void) {}
void touch_wait_until_ready(void) {}

uint32_t touch_is_detected(void) { return _touch_detected; }

Expand Down

0 comments on commit b4723ac

Please sign in to comment.