mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-09 15:00:58 +00:00
feat(core): improve haptic driver peripherals init/deinit
[no changelog]
This commit is contained in:
parent
a5aee9f124
commit
6944eb1874
@ -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));
|
||||
}
|
||||
|
@ -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"
|
||||
|
||||
|
@ -127,6 +127,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
|
||||
|
Loading…
Reference in New Issue
Block a user