mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-20 11:32:04 +00:00
fix(core): fix stwlc38 deinitialization
[no changelog]
This commit is contained in:
parent
612d20b535
commit
e47b604c48
@ -22,7 +22,6 @@
|
||||
|
||||
#include <io/i2c_bus.h>
|
||||
#include <sys/irq.h>
|
||||
#include <sys/systick.h>
|
||||
#include <sys/systimer.h>
|
||||
|
||||
#include "stwlc38.h"
|
||||
@ -75,8 +74,14 @@ static void stwlc38_fsm_continue(stwlc38_driver_t *drv);
|
||||
void stwlc38_deinit(void) {
|
||||
stwlc38_driver_t *drv = &g_stwlc38_driver;
|
||||
|
||||
i2c_bus_close(drv->i2c_bus);
|
||||
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(STWLC38_ENB_PORT, STWLC38_ENB_PIN);
|
||||
memset(drv, 0, sizeof(stwlc38_driver_t));
|
||||
}
|
||||
|
||||
@ -122,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);
|
||||
@ -160,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;
|
||||
@ -320,6 +324,10 @@ void STWLC38_EXTI_INTERRUPT_HANDLER(void) {
|
||||
// Clear the EXTI line pending bit
|
||||
__HAL_GPIO_EXTI_CLEAR_FLAG(STWLC38_INT_PIN);
|
||||
|
||||
if (!drv->initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (drv->state == STWLC38_STATE_POWER_DOWN) {
|
||||
// Inform the powerctl module about the WPC
|
||||
// wakeup_flags_set(WAKEUP_FLAGS_WPC);
|
||||
|
@ -17,8 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TREZORHAL_STWLC38_H
|
||||
#define TREZORHAL_STWLC38_H
|
||||
#pragma once
|
||||
|
||||
#include <trezor_types.h>
|
||||
|
||||
@ -89,7 +88,7 @@ void stwlc38_deinit(void);
|
||||
// wireless charging functionality.
|
||||
//
|
||||
// If the STWLC38 is disabled, it's not self-powered and is unable to
|
||||
// communicate over I2C. STWLC38 is disabled by default after initialization.
|
||||
// communicate over I2C. STWLC38 is enabled by default after initialization.
|
||||
//
|
||||
// Returns true if the STWLC38 was successfully enabled or disabled.
|
||||
bool stwlc38_enable(bool enable);
|
||||
@ -120,5 +119,3 @@ bool stwlc38_patch_and_config();
|
||||
|
||||
// Gets the current report from the STWLC38
|
||||
bool stwlc38_get_report(stwlc38_report_t* status);
|
||||
|
||||
#endif // TREZORHAL_STWLC38_H
|
||||
|
@ -17,8 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TREZORHAL_STWLC38_DEFS_H
|
||||
#define TREZORHAL_STWLC38_DEFS_H
|
||||
#pragma once
|
||||
|
||||
// I2C address of the STWLC38 on the I2C bus.
|
||||
#define STWLC38_I2C_ADDRESS 0x61
|
||||
@ -95,5 +94,3 @@
|
||||
#define STWLC38_ERR_INVALID_CHIP_ID 0x80000006U
|
||||
#define STWLC38_ERR_NVM_ID_MISMATCH 0x80000007U
|
||||
#define STWLC38_ERR_NVM_DATA_CORRUPTED 0x80000008U
|
||||
|
||||
#endif // TREZORHAL_STWLC38_DEFS_H
|
||||
|
@ -18,8 +18,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TREZORHAL_STWLC38_INTERNAL_H
|
||||
#define TREZORHAL_STWLC38_INTERNAL_H
|
||||
#pragma once
|
||||
|
||||
#include <io/i2c_bus.h>
|
||||
#include <trezor_types.h>
|
||||
@ -35,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]
|
||||
@ -73,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
|
||||
@ -99,5 +101,3 @@ typedef struct {
|
||||
extern stwlc38_driver_t g_stwlc38_driver;
|
||||
|
||||
#endif // KERNEL_MODE
|
||||
|
||||
#endif // TREZORHAL_STWLC38_INTERNAL_H
|
||||
|
Loading…
Reference in New Issue
Block a user