diff --git a/core/embed/io/haptic/drv2625/drv2625.c b/core/embed/io/haptic/drv2625/drv2625.c index 772849cdbf..2b9aac961c 100644 --- a/core/embed/io/haptic/drv2625/drv2625.c +++ b/core/embed/io/haptic/drv2625/drv2625.c @@ -147,17 +147,29 @@ bool haptic_init(void) { } GPIO_InitTypeDef GPIO_InitStructure = {0}; + +#ifdef DRV2625_RESET_PIN + DRV2625_RESET_CLK_ENA(); + GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; + GPIO_InitStructure.Pull = GPIO_PULLDOWN; + GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStructure.Pin = DRV2625_RESET_PIN; + HAL_GPIO_Init(DRV2625_RESET_PORT, &GPIO_InitStructure); + HAL_GPIO_WritePin(DRV2625_RESET_PORT, DRV2625_RESET_PIN, GPIO_PIN_SET); +#endif + + DRV2625_TRIG_CLK_ENA(); GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; GPIO_InitStructure.Pull = GPIO_PULLDOWN; GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW; - GPIO_InitStructure.Pin = GPIO_PIN_8; - GPIO_InitStructure.Alternate = GPIO_AF14_TIM16; - HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.Pin = DRV2625_TRIG_PIN; + GPIO_InitStructure.Alternate = DRV2625_TRIG_AF; + HAL_GPIO_Init(DRV2625_TRIG_PORT, &GPIO_InitStructure); + DRV2625_TRIG_TIM_CLK_ENA(); TIM_HandleTypeDef TIM_Handle = {0}; - __HAL_RCC_TIM16_CLK_ENABLE(); TIM_Handle.State = HAL_TIM_STATE_RESET; - TIM_Handle.Instance = TIM16; + TIM_Handle.Instance = DRV2625_TRIG_TIM; TIM_Handle.Init.Period = 0; TIM_Handle.Init.Prescaler = SystemCoreClock / 10000; TIM_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; @@ -175,7 +187,7 @@ bool haptic_init(void) { HAL_TIM_OC_Start(&TIM_Handle, TIM_CHANNEL_1); - TIM16->BDTR |= TIM_BDTR_MOE; + DRV2625_TRIG_TIM->BDTR |= TIM_BDTR_MOE; driver->initialized = true; driver->enabled = true; @@ -246,10 +258,10 @@ static bool haptic_play_rtp(int8_t amplitude, uint16_t duration_ms) { return true; } - TIM16->CNT = 1; - TIM16->CCR1 = 1; - TIM16->ARR = duration_ms * 10; - TIM16->CR1 |= TIM_CR1_CEN; + DRV2625_TRIG_TIM->CNT = 1; + DRV2625_TRIG_TIM->CCR1 = 1; + DRV2625_TRIG_TIM->ARR = duration_ms * 10; + DRV2625_TRIG_TIM->CR1 |= TIM_CR1_CEN; return true; } diff --git a/core/embed/models/T3T1/boards/trezor_t3t1_revE.h b/core/embed/models/T3T1/boards/trezor_t3t1_revE.h index 1cacc78778..051ffb71f4 100644 --- a/core/embed/models/T3T1/boards/trezor_t3t1_revE.h +++ b/core/embed/models/T3T1/boards/trezor_t3t1_revE.h @@ -92,6 +92,13 @@ #define TOUCH_ON_PIN GPIO_PIN_0 #define DRV2625_I2C_INSTANCE 1 +#define DRV2625_TRIG_PIN GPIO_PIN_8 +#define DRV2625_TRIG_PORT GPIOB +#define DRV2625_TRIG_CLK_ENA __HAL_RCC_GPIOB_CLK_ENABLE +#define DRV2625_TRIG_AF GPIO_AF14_TIM16 +#define DRV2625_TRIG_TIM TIM16 +#define DRV2625_TRIG_TIM_CLK_ENA __HAL_RCC_TIM16_CLK_ENABLE + #define HAPTIC_ACTUATOR "actuators/vg1040003d.h" #define OPTIGA_I2C_INSTANCE 2 diff --git a/core/embed/models/T3W1/boards/trezor_t3w1_revA.h b/core/embed/models/T3W1/boards/trezor_t3w1_revA.h index d43f26fa4b..87e5edcc57 100644 --- a/core/embed/models/T3W1/boards/trezor_t3w1_revA.h +++ b/core/embed/models/T3W1/boards/trezor_t3w1_revA.h @@ -101,6 +101,18 @@ #define TOUCH_INT_PORT GPIOC #define TOUCH_INT_PIN GPIO_PIN_3 +#define DRV2625_I2C_INSTANCE 2 +#define HAPTIC_ACTUATOR "actuators/vg1040003d.h" +#define DRV2625_TRIG_PIN GPIO_PIN_2 +#define DRV2625_TRIG_PORT GPIOA +#define DRV2625_TRIG_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE +#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_RESET_PIN GPIO_PIN_3 +#define DRV2625_RESET_PORT GPIOA +#define DRV2625_RESET_CLK_ENA __HAL_RCC_GPIOA_CLK_ENABLE + #define OPTIGA_I2C_INSTANCE 3 #define OPTIGA_RST_PORT GPIOD #define OPTIGA_RST_PIN GPIO_PIN_10 diff --git a/core/site_scons/models/T3W1/trezor_t3w1_revA.py b/core/site_scons/models/T3W1/trezor_t3w1_revA.py index d3d2f0d499..de0b92986a 100644 --- a/core/site_scons/models/T3W1/trezor_t3w1_revA.py +++ b/core/site_scons/models/T3W1/trezor_t3w1_revA.py @@ -58,6 +58,14 @@ def configure( defines += ["USE_I2C=1"] defines += ["USE_BUTTON=1"] + if "haptic" in features_wanted: + sources += [ + "embed/io/haptic/drv2625/drv2625.c", + ] + paths += ["embed/io/haptic/inc"] + features_available.append("haptic") + defines += ["USE_HAPTIC=1"] + # if "ble" in features_wanted: # sources += ["embed/trezorhal/stm32f4/ble/ble_hal.c"] # sources += ["embed/trezorhal/stm32f4/ble/dfu.c"]