Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suspend to low power mode on T3W1 #4454

Merged
merged 14 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ build_reflash: ## build reflash firmware + reflash image
dd if=build/bootloader/bootloader.bin of=$(REFLASH_BUILD_DIR)/sdimage.bin bs=1 seek=49152

build_kernel: ## build kernel image
$(SCONS) PYOPT=1 $(KERNEL_BUILD_DIR)/kernel.bin
$(SCONS) $(KERNEL_BUILD_DIR)/kernel.bin

build_firmware: templates build_cross build_kernel ## build firmware with frozen modules
$(SCONS) $(FIRMWARE_BUILD_DIR)/firmware.bin
Expand Down
3 changes: 3 additions & 0 deletions core/embed/gfx/bitblt/dma2d_bitblt.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
// Initializes DMA2D peripheral
void dma2d_init(void);

// Deinitializes DMA2D peripheral
void dma2d_deinit(void);

// Waits until any pending DMA2D operation is finished
void dma2d_wait(void);

Expand Down
6 changes: 6 additions & 0 deletions core/embed/gfx/bitblt/gfx_bitblt.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ void gfx_bitblt_init(void) {
#endif
}

void gfx_bitblt_deinit(void) {
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
dma2d_deinit();
#endif
}

void gfx_bitblt_wait(void) {
#if defined(USE_DMA2D) && !defined(TREZOR_EMULATOR)
dma2d_wait();
Expand Down
14 changes: 13 additions & 1 deletion core/embed/gfx/bitblt/stm32/dma2d_bitblt.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ static inline bool dma2d_accessible(const void* ptr) {
#endif
}

void dma2d_init(void) { __HAL_RCC_DMA2D_CLK_ENABLE(); }
void dma2d_init(void) {
__HAL_RCC_DMA2D_FORCE_RESET();
__HAL_RCC_DMA2D_RELEASE_RESET();

__HAL_RCC_DMA2D_CLK_ENABLE();
}

void dma2d_deinit(void) {
__HAL_RCC_DMA2D_CLK_DISABLE();

__HAL_RCC_DMA2D_FORCE_RESET();
__HAL_RCC_DMA2D_RELEASE_RESET();
}

void dma2d_wait(void) {
while (HAL_DMA2D_PollForTransfer(&dma2d_handle, 10) != HAL_OK)
Expand Down
3 changes: 3 additions & 0 deletions core/embed/gfx/inc/gfx/gfx_bitblt.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ typedef struct {
// Initializes bitblt operations
void gfx_bitblt_init(void);

// Deinitializes bitblt operations
void gfx_bitblt_deinit(void);

// If the bitblt operation is asynchronous, waits until it's finished
void gfx_bitblt_wait(void);

Expand Down
3 changes: 3 additions & 0 deletions core/embed/io/button/inc/io/button.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ typedef enum {
// Returns true in case of success, false otherwise
bool button_init(void);

// Deinitializes button driver
void button_deinit(void);

#endif // KERNEL_MODE

// Get the last button event
Expand Down
13 changes: 13 additions & 0 deletions core/embed/io/button/stm32/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <io/button.h>
#include <sys/irq.h>
#include <sys/mpu.h>

#ifdef USE_POWERCTL
#include <sys/wakeup_flags.h>
Expand Down Expand Up @@ -103,6 +104,12 @@ bool button_init(void) {
return true;
}

void button_deinit(void) {
#ifdef BTN_EXIT_INTERRUPT_HANDLER
NVIC_DisableIRQ(BTN_EXTI_INTERRUPT_NUM);
#endif
}

uint32_t button_get_event(void) {
button_driver_t *drv = &g_button_driver;

Expand Down Expand Up @@ -182,6 +189,9 @@ bool button_is_down(button_t button) {

#ifdef BTN_EXTI_INTERRUPT_HANDLER
void BTN_EXTI_INTERRUPT_HANDLER(void) {
IRQ_LOG_ENTER();
mpu_mode_t mpu_mode = mpu_reconfig(MPU_MODE_DEFAULT);

// button_driver_t *drv = &g_button_driver;

// Clear the EXTI line pending bit
Expand All @@ -191,6 +201,9 @@ void BTN_EXTI_INTERRUPT_HANDLER(void) {
// Inform the powerctl module about button press
wakeup_flags_set(WAKEUP_FLAG_BUTTON);
#endif

mpu_restore(mpu_mode);
IRQ_LOG_EXIT();
}
#endif

Expand Down
22 changes: 17 additions & 5 deletions core/embed/io/display/backlight/stm32/backlight_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ void backlight_pwm_init(backlight_action_t action) {
}
}

// Enable peripheral clocks
// Initialize PWM GPIO
BACKLIGHT_PWM_PORT_CLK_EN();
BACKLIGHT_PWM_TIM_CLK_EN();

// Initialize PWM GPIO
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
Expand All @@ -82,6 +80,9 @@ void backlight_pwm_init(backlight_action_t action) {
HAL_GPIO_Init(BACKLIGHT_PWM_PORT, &GPIO_InitStructure);

// Initialize PWM timer
BACKLIGHT_PWM_TIM_FORCE_RESET();
BACKLIGHT_PWM_TIM_RELEASE_RESET();
BACKLIGHT_PWM_TIM_CLK_EN();

uint32_t tmpcr1 = 0;

Expand Down Expand Up @@ -220,8 +221,19 @@ void backlight_pwm_deinit(backlight_action_t action) {

#else
if (action == BACKLIGHT_RESET) {
// TODO: reset TIMER and GPIO
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR = 0;
// Deinitialize PWM GPIO
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Pin = BACKLIGHT_PWM_PIN;
HAL_GPIO_Init(BACKLIGHT_PWM_PORT, &GPIO_InitStructure);

// Deinitialize PWM timer
BACKLIGHT_PWM_TIM_FORCE_RESET();
BACKLIGHT_PWM_TIM_RELEASE_RESET();
BACKLIGHT_PWM_TIM_CLK_DIS();

} else { // action == BACKLIGHT_RETAIN
BACKLIGHT_PWM_TIM->BACKLIGHT_PWM_TIM_CCR =
(LED_PWM_TIM_PERIOD * drv->current_level) / 255;
Expand Down
4 changes: 3 additions & 1 deletion core/embed/io/display/inc/io/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ typedef enum {
//
// If `mode` is `DISPLAY_RETAIN_CONTENT`, ensure the driver was previously
// initialized and `display_deinit(DISPLAY_RETAIN_CONTENT)` was called.
void display_init(display_content_mode_t mode);
//
// Returns `true` if the initialization was successful.
bool display_init(display_content_mode_t mode);

// Deinitializes the display controller.
//
Expand Down
Loading
Loading