From 7a603b871724e01c308e793dd9d3b3fe16aa63ef Mon Sep 17 00:00:00 2001 From: cepetr Date: Mon, 13 Jan 2025 19:08:16 +0100 Subject: [PATCH] feat(core): improve haptic driver peripherals init/deinit [no changelog] --- core/embed/io/haptic/drv2625/drv2625.c | 37 +++++++++++++------ .../models/T3T1/boards/trezor_t3t1_revE.h | 3 ++ .../models/T3W1/boards/trezor_t3w1_revA.h | 3 ++ .../models/T3W1/boards/trezor_t3w1_revA0.h | 4 ++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/core/embed/io/haptic/drv2625/drv2625.c b/core/embed/io/haptic/drv2625/drv2625.c index 8ee33d9eb3..9da82675d4 100644 --- a/core/embed/io/haptic/drv2625/drv2625.c +++ b/core/embed/io/haptic/drv2625/drv2625.c @@ -115,7 +115,7 @@ bool haptic_init(void) { #ifdef DRV2625_RESET_PIN DRV2625_RESET_CLK_ENA(); GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStructure.Pull = GPIO_PULLDOWN; + GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStructure.Pin = DRV2625_RESET_PIN; HAL_GPIO_WritePin(DRV2625_RESET_PORT, DRV2625_RESET_PIN, GPIO_PIN_RESET); @@ -170,7 +170,10 @@ bool haptic_init(void) { goto cleanup; } + DRV2625_TRIG_TIM_FORCE_RESET(); + DRV2625_TRIG_TIM_RELEASE_RESET(); DRV2625_TRIG_TIM_CLK_ENA(); + TIM_HandleTypeDef TIM_Handle = {0}; TIM_Handle.State = HAL_TIM_STATE_RESET; TIM_Handle.Instance = DRV2625_TRIG_TIM; @@ -199,24 +202,36 @@ bool haptic_init(void) { return true; cleanup: - i2c_bus_close(driver->i2c_bus); - memset(driver, 0, sizeof(haptic_driver_t)); -#ifdef DRV2625_RESET_PIN - HAL_GPIO_WritePin(DRV2625_RESET_PORT, DRV2625_RESET_PIN, GPIO_PIN_RESET); -#endif + haptic_deinit(); return false; } void haptic_deinit(void) { haptic_driver_t *driver = &g_haptic_driver; - if (!driver->initialized) { - return; - } - i2c_bus_close(driver->i2c_bus); - // TODO: deinitialize GPIOs and the TIMER + GPIO_InitTypeDef GPIO_InitStructure = {0}; + +#ifdef DRV2625_RESET_PIN + // External pull-down on NRST pin ensures that the DRV2625 goes into + // shutdown mode when the reset GPIO is deinitialized. + GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.Pull = GPIO_NOPULL; + GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStructure.Pin = DRV2625_RESET_PIN; + HAL_GPIO_Init(DRV2625_RESET_PORT, &GPIO_InitStructure); +#endif + + GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; + GPIO_InitStructure.Pull = GPIO_NOPULL; + GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStructure.Pin = DRV2625_TRIG_PIN; + HAL_GPIO_Init(DRV2625_TRIG_PORT, &GPIO_InitStructure); + + DRV2625_TRIG_TIM_FORCE_RESET(); + DRV2625_TRIG_TIM_RELEASE_RESET(); + DRV2625_TRIG_TIM_CLK_DIS(); memset(driver, 0, sizeof(haptic_driver_t)); } diff --git a/core/embed/models/T3T1/boards/trezor_t3t1_revE.h b/core/embed/models/T3T1/boards/trezor_t3t1_revE.h index ee8ce34674..fe191e079d 100644 --- a/core/embed/models/T3T1/boards/trezor_t3t1_revE.h +++ b/core/embed/models/T3T1/boards/trezor_t3t1_revE.h @@ -101,6 +101,9 @@ #define DRV2625_TRIG_AF GPIO_AF14_TIM16 #define DRV2625_TRIG_TIM TIM16 #define DRV2625_TRIG_TIM_CLK_ENA __HAL_RCC_TIM16_CLK_ENABLE +#define DRV2625_TRIG_TIM_CLK_DIS __HAL_RCC_TIM16_CLK_DISABLE +#define DRV2625_TRIG_TIM_FORCE_RESET __HAL_RCC_TIM16_FORCE_RESET +#define DRV2625_TRIG_TIM_RELEASE_RESET __HAL_RCC_TIM16_RELEASE_RESET #define HAPTIC_ACTUATOR "actuators/vg1040003d.h" diff --git a/core/embed/models/T3W1/boards/trezor_t3w1_revA.h b/core/embed/models/T3W1/boards/trezor_t3w1_revA.h index e88d2f3a99..fe9cbb0bdc 100644 --- a/core/embed/models/T3W1/boards/trezor_t3w1_revA.h +++ b/core/embed/models/T3W1/boards/trezor_t3w1_revA.h @@ -128,6 +128,9 @@ #define DRV2625_TRIG_AF GPIO_AF14_TIM15 #define DRV2625_TRIG_TIM TIM15 #define DRV2625_TRIG_TIM_CLK_ENA __HAL_RCC_TIM15_CLK_ENABLE +#define DRV2625_TRIG_TIM_CLK_DIS __HAL_RCC_TIM15_CLK_DISABLE +#define DRV2625_TRIG_TIM_FORCE_RESET __HAL_RCC_TIM15_FORCE_RESET +#define DRV2625_TRIG_TIM_RELEASE_RESET __HAL_RCC_TIM15_RELEASE_RESET #define DRV2625_RESET_PIN GPIO_PIN_3 #define DRV2625_RESET_PORT GPIOA #define DRV2625_RESET_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE diff --git a/core/embed/models/T3W1/boards/trezor_t3w1_revA0.h b/core/embed/models/T3W1/boards/trezor_t3w1_revA0.h index f87cc28273..6f6ae4ea6c 100644 --- a/core/embed/models/T3W1/boards/trezor_t3w1_revA0.h +++ b/core/embed/models/T3W1/boards/trezor_t3w1_revA0.h @@ -127,6 +127,10 @@ #define DRV2625_TRIG_AF GPIO_AF14_TIM15 #define DRV2625_TRIG_TIM TIM15 #define DRV2625_TRIG_TIM_CLK_ENA __HAL_RCC_TIM15_CLK_ENABLE +#define DRV2625_TRIG_TIM_CLK_DIS __HAL_RCC_TIM15_CLK_DISABLE +#define DRV2625_TRIG_TIM_FORCE_RESET __HAL_RCC_TIM15_FORCE_RESET +#define DRV2625_TRIG_TIM_RELEASE_RESET __HAL_RCC_TIM15_RELEASE_RESET + #define DRV2625_RESET_PIN GPIO_PIN_3 #define DRV2625_RESET_PORT GPIOA #define DRV2625_RESET_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE