From a762e75fee5177b99906367674038941633b0a8e Mon Sep 17 00:00:00 2001 From: TychoVrahe <37884576+TychoVrahe@users.noreply.github.com> Date: Tue, 26 Jul 2022 15:09:43 +0200 Subject: [PATCH] fix(core): reintroduce touch controller initialization without power down/up in firmware, fix model R firmware initialization --- core/.changelog.d/2130.changed | 1 + core/.changelog.d/2130.removed | 1 - core/embed/bootloader/main.c | 2 +- core/embed/firmware/main.c | 12 ++++++------ core/embed/trezorhal/touch.c | 35 +++++++++++++++++++--------------- 5 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 core/.changelog.d/2130.changed delete mode 100644 core/.changelog.d/2130.removed diff --git a/core/.changelog.d/2130.changed b/core/.changelog.d/2130.changed new file mode 100644 index 000000000..16dd999c3 --- /dev/null +++ b/core/.changelog.d/2130.changed @@ -0,0 +1 @@ +Remove power-down power-up cycle from touch controller initialization in firmware diff --git a/core/.changelog.d/2130.removed b/core/.changelog.d/2130.removed deleted file mode 100644 index b63ef51b3..000000000 --- a/core/.changelog.d/2130.removed +++ /dev/null @@ -1 +0,0 @@ -Don't initialize touch controller in firmware diff --git a/core/embed/bootloader/main.c b/core/embed/bootloader/main.c index 3d1c5a61d..1c9156959 100644 --- a/core/embed/bootloader/main.c +++ b/core/embed/bootloader/main.c @@ -250,8 +250,8 @@ int main(void) { random_delays_init(); // display_init_seq(); #if defined TREZOR_MODEL_T - touch_init(); touch_power_on(); + touch_init(); #endif #if defined TREZOR_MODEL_R diff --git a/core/embed/firmware/main.c b/core/embed/firmware/main.c index 210e90fb1..d3069837f 100644 --- a/core/embed/firmware/main.c +++ b/core/embed/firmware/main.c @@ -73,7 +73,7 @@ int main(void) { #endif // reinitialize HAL for Trezor One -#if defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R +#if defined TREZOR_MODEL_1 HAL_Init(); #endif @@ -85,9 +85,7 @@ int main(void) { #if !defined TREZOR_MODEL_1 parse_boardloader_capabilities(); -#endif -#if defined TREZOR_MODEL_T #if PRODUCTION check_and_replace_bootloader(); #endif @@ -98,7 +96,7 @@ int main(void) { // Init peripherals pendsv_init(); -#if defined TREZOR_MODEL_1 || defined TREZOR_MODEL_R +#if defined TREZOR_MODEL_1 display_init(); button_init(); #endif @@ -110,15 +108,17 @@ int main(void) { #endif #if defined TREZOR_MODEL_T + touch_init(); // display_init_seq(); sdcard_init(); + display_clear(); +#endif +#if !defined TREZOR_MODEL_1 // jump to unprivileged mode // http://infocenter.arm.com/help/topic/com.arm.doc.dui0552a/CHDBIBGJ.html __asm__ volatile("msr control, %0" ::"r"(0x1)); __asm__ volatile("isb"); - - display_clear(); #endif #ifdef USE_SECP256K1_ZKP diff --git a/core/embed/trezorhal/touch.c b/core/embed/trezorhal/touch.c index 8da532944..4c5d915a0 100644 --- a/core/embed/trezorhal/touch.c +++ b/core/embed/trezorhal/touch.c @@ -102,8 +102,6 @@ static void touch_active_pin_state(void) { // 300ms, giving an extra 10ms } -void touch_init(void) { touch_default_pin_state(); } - void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) { // enable I2C clock __HAL_RCC_I2C1_CLK_ENABLE(); @@ -200,18 +198,7 @@ static void _i2c_cycle(void) { HAL_Delay(10); } -void touch_power_on(void) { - if (i2c_handle.Instance) { - return; - } - - // turn on CTP circuitry - touch_active_pin_state(); - HAL_Delay(50); - - // I2C device interface configuration - _i2c_init(); - +void touch_set_mode(void) { // set register 0xA4 G_MODE to interrupt polling mode (0x00). basically, CTPM // keeps this input line (to PC4) low while a finger is on the screen. uint8_t touch_panel_config[] = {0xA4, 0x00}; @@ -220,8 +207,18 @@ void touch_power_on(void) { &i2c_handle, TOUCH_ADDRESS, touch_panel_config, sizeof(touch_panel_config), 10)), NULL); +} - touch_sensitivity(0x06); +void touch_power_on(void) { + if (i2c_handle.Instance) { + return; + } + + touch_default_pin_state(); + + // turn on CTP circuitry + touch_active_pin_state(); + HAL_Delay(50); } void touch_power_off(void) { @@ -231,6 +228,14 @@ void touch_power_off(void) { touch_default_pin_state(); } +void touch_init(void) { + // I2C device interface configuration + _i2c_init(); + + touch_set_mode(); + touch_sensitivity(0x06); +} + void touch_sensitivity(uint8_t value) { // set panel threshold (TH_GROUP) - default value is 0x12 uint8_t touch_panel_threshold[] = {0x80, value};