From daa1df9f0fcc93dcdf64a47e38b8b7d779fddc05 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 6 Jun 2016 17:42:50 +0200 Subject: [PATCH] make backlight code cleaner --- extmod/modtrezorui/display-stmhal.h | 4 ++-- extmod/modtrezorui/display-unix.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extmod/modtrezorui/display-stmhal.h b/extmod/modtrezorui/display-stmhal.h index 32c77a41a9..7b288eed2c 100644 --- a/extmod/modtrezorui/display-stmhal.h +++ b/extmod/modtrezorui/display-stmhal.h @@ -203,9 +203,9 @@ void display_update(void) { int display_backlight(int val) { - if (val >= 0 && val <= 255) { + if (BACKLIGHT != val && val >= 0 && val <= 255) { BACKLIGHT = val; + __HAL_TIM_SetCompare(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * BACKLIGHT / 255); } - __HAL_TIM_SetCompare(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * BACKLIGHT / 255); return BACKLIGHT; } diff --git a/extmod/modtrezorui/display-unix.h b/extmod/modtrezorui/display-unix.h index 46f3bdabfb..1b5dcc4231 100644 --- a/extmod/modtrezorui/display-unix.h +++ b/extmod/modtrezorui/display-unix.h @@ -128,9 +128,9 @@ int display_orientation(int degrees) int display_backlight(int val) { - if (val >= 0 && val <= 255) { + if (BACKLIGHT != val && val >= 0 && val <= 255) { BACKLIGHT = val; + SDL_SetRenderDrawColor(RENDERER, BACKLIGHT, BACKLIGHT, BACKLIGHT, 255); } - SDL_SetRenderDrawColor(RENDERER, BACKLIGHT, BACKLIGHT, BACKLIGHT, 255); return BACKLIGHT; }