1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-14 16:42:02 +00:00

fixup! fix(core): fix stwlc38 deinitialization

This commit is contained in:
tychovrahe 2025-02-12 16:21:54 +01:00
parent f4039c12e5
commit 963bc0654b
2 changed files with 11 additions and 8 deletions

View File

@ -75,12 +75,13 @@ void stwlc38_deinit(void) {
stwlc38_driver_t *drv = &g_stwlc38_driver;
NVIC_DisableIRQ(STWLC38_EXTI_INTERRUPT_NUM);
HAL_EXTI_ClearConfigLine(&drv->EXTI_Handle);
systimer_delete(drv->timer);
i2c_bus_close(drv->i2c_bus);
HAL_GPIO_DeInit(STWLC38_INT_PORT, STWLC38_INT_PIN);
HAL_GPIO_DeInit(STWLC37_ENB_PORT, STWLC38_ENB_PIN);
HAL_GPIO_DeInit(STWLC38_ENB_PORT, STWLC38_ENB_PIN);
memset(drv, 0, sizeof(stwlc38_driver_t));
}
@ -126,17 +127,16 @@ bool stwlc38_init(void) {
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Pin = STWLC38_ENB_PIN;
HAL_GPIO_WritePin(STWLC37_ENB_PORT, STWLC38_ENB_PIN, GPIO_PIN_RESET);
HAL_GPIO_Init(STWLC37_ENB_PORT, &GPIO_InitStructure);
HAL_GPIO_WritePin(STWLC38_ENB_PORT, STWLC38_ENB_PIN, GPIO_PIN_RESET);
HAL_GPIO_Init(STWLC38_ENB_PORT, &GPIO_InitStructure);
// Setup interrupt line for the STWLC38
EXTI_HandleTypeDef EXTI_Handle = {0};
EXTI_ConfigTypeDef EXTI_Config = {0};
EXTI_Config.GPIOSel = STWLC38_EXTI_INTERRUPT_GPIOSEL;
EXTI_Config.Line = STWLC38_EXTI_INTERRUPT_LINE;
EXTI_Config.Mode = EXTI_MODE_INTERRUPT;
EXTI_Config.Trigger = EXTI_TRIGGER_FALLING;
HAL_EXTI_SetConfigLine(&EXTI_Handle, &EXTI_Config);
HAL_EXTI_SetConfigLine(&drv->EXTI_Handle, &EXTI_Config);
NVIC_SetPriority(STWLC38_EXTI_INTERRUPT_NUM, IRQ_PRI_NORMAL);
__HAL_GPIO_EXTI_CLEAR_FLAG(STWLC38_INT_PIN);
NVIC_EnableIRQ(STWLC38_EXTI_INTERRUPT_NUM);
@ -164,9 +164,9 @@ bool stwlc38_enable(bool enable) {
}
if (enable) {
HAL_GPIO_WritePin(STWLC37_ENB_PORT, STWLC38_ENB_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(STWLC38_ENB_PORT, STWLC38_ENB_PIN, GPIO_PIN_RESET);
} else {
HAL_GPIO_WritePin(STWLC37_ENB_PORT, STWLC38_ENB_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(STWLC38_ENB_PORT, STWLC38_ENB_PIN, GPIO_PIN_SET);
}
return true;

View File

@ -34,7 +34,7 @@
#define STWLC38_EXTI_INTERRUPT_NUM EXTI15_IRQn
#define STWLC38_EXTI_INTERRUPT_HANDLER EXTI15_IRQHandler
#define STWLC38_ENB_PIN GPIO_PIN_3
#define STWLC37_ENB_PORT GPIOD
#define STWLC38_ENB_PORT GPIOD
#define STWLC38_ENB_PIN_CLK_ENA __HAL_RCC_GPIOD_CLK_ENABLE
// Period of the report readout [ms]
@ -72,6 +72,9 @@ typedef struct {
// Set if the driver is initialized
bool initialized;
// EXTI handle
EXTI_HandleTypeDef EXTI_Handle;
// I2C bus where the STWLC38 is connected
i2c_bus_t *i2c_bus;
// Storage for the pending I2C packet