mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-10 06:32:42 +00:00
refactor(core): introduce separate backlight pin driver
[no changelog]
This commit is contained in:
parent
368d41902d
commit
e2035e1c06
103
core/embed/io/backlight/stm32/backlight_pin.c
Normal file
103
core/embed/io/backlight/stm32/backlight_pin.c
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Trezor project, https://trezor.io/
|
||||||
|
*
|
||||||
|
* Copyright (c) SatoshiLabs
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <io/backlight.h>
|
||||||
|
|
||||||
|
#include <trezor_bsp.h>
|
||||||
|
#include <trezor_rtl.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
// Set if driver is initialized
|
||||||
|
bool initialized;
|
||||||
|
// Current backlight level in range 0-255
|
||||||
|
int current_level;
|
||||||
|
|
||||||
|
} backlight_driver_t;
|
||||||
|
|
||||||
|
static backlight_driver_t g_backlight_driver = {
|
||||||
|
.initialized = false,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void backlight_on(void) {
|
||||||
|
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||||
|
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStructure.Pull = GPIO_PULLUP;
|
||||||
|
GPIO_InitStructure.Pin = BACKLIGHT_PIN_PIN;
|
||||||
|
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(BACKLIGHT_PIN_PORT, &GPIO_InitStructure);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void backlight_off(void) {
|
||||||
|
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||||
|
GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
|
||||||
|
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStructure.Pin = BACKLIGHT_PIN_PIN;
|
||||||
|
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(BACKLIGHT_PIN_PORT, &GPIO_InitStructure);
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_init(backlight_action_t action) {
|
||||||
|
backlight_driver_t *drv = &g_backlight_driver;
|
||||||
|
|
||||||
|
if (drv->initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BACKLIGHT_PIN_CLK_ENABLE();
|
||||||
|
|
||||||
|
if (action == BACKLIGHT_RESET) {
|
||||||
|
backlight_off();
|
||||||
|
};
|
||||||
|
|
||||||
|
drv->initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void backlight_deinit(backlight_action_t action) {
|
||||||
|
backlight_driver_t *drv = &g_backlight_driver;
|
||||||
|
if (!drv->initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == BACKLIGHT_RESET) {
|
||||||
|
backlight_off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int backlight_set(int val) {
|
||||||
|
backlight_driver_t *drv = &g_backlight_driver;
|
||||||
|
if (!drv->initialized) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val > 0) {
|
||||||
|
backlight_on();
|
||||||
|
} else {
|
||||||
|
backlight_off();
|
||||||
|
}
|
||||||
|
drv->current_level = val;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int backlight_get(void) {
|
||||||
|
backlight_driver_t *drv = &g_backlight_driver;
|
||||||
|
if (!drv->initialized) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return drv->current_level;
|
||||||
|
}
|
@ -356,16 +356,6 @@ bool display_init(display_content_mode_t mode) {
|
|||||||
systick_delay_ms(120);
|
systick_delay_ms(120);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DISPLAY_BACKLIGHT_PIN
|
|
||||||
DISPLAY_BACKLIGHT_CLK_ENABLE();
|
|
||||||
/* Configure LCD Backlight Pin */
|
|
||||||
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
|
||||||
GPIO_InitStructure.Pull = GPIO_PULLUP;
|
|
||||||
GPIO_InitStructure.Pin = DISPLAY_BACKLIGHT_PIN;
|
|
||||||
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(DISPLAY_BACKLIGHT_PORT, &GPIO_InitStructure);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_BACKLIGHT
|
#ifdef USE_BACKLIGHT
|
||||||
backlight_init(BACKLIGHT_RESET);
|
backlight_init(BACKLIGHT_RESET);
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,9 +9,10 @@
|
|||||||
#define DISPLAY_RESET_PIN GPIO_PIN_5
|
#define DISPLAY_RESET_PIN GPIO_PIN_5
|
||||||
#define DISPLAY_RESET_PORT GPIOD
|
#define DISPLAY_RESET_PORT GPIOD
|
||||||
#define DISPLAY_RESET_CLK_ENA __HAL_RCC_GPIOD_CLK_ENABLE
|
#define DISPLAY_RESET_CLK_ENA __HAL_RCC_GPIOD_CLK_ENABLE
|
||||||
#define DISPLAY_BACKLIGHT_PIN GPIO_PIN_6
|
|
||||||
#define DISPLAY_BACKLIGHT_PORT GPIOI
|
#define BACKLIGHT_PIN_PIN GPIO_PIN_6
|
||||||
#define DISPLAY_BACKLIGHT_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
#define BACKLIGHT_PIN_PORT GPIOI
|
||||||
|
#define BACKLIGHT_PIN_CLK_ENABLE() __HAL_RCC_GPIOI_CLK_ENABLE()
|
||||||
|
|
||||||
#define I2C_COUNT 1
|
#define I2C_COUNT 1
|
||||||
#define I2C_INSTANCE_0 I2C5
|
#define I2C_INSTANCE_0 I2C5
|
||||||
|
@ -48,6 +48,11 @@ def configure(
|
|||||||
]
|
]
|
||||||
paths += ["embed/io/display/inc"]
|
paths += ["embed/io/display/inc"]
|
||||||
|
|
||||||
|
features_available.append("backlight")
|
||||||
|
defines += [("USE_BACKLIGHT", "1")]
|
||||||
|
sources += ["embed/io/backlight/stm32/backlight_pin.c"]
|
||||||
|
paths += ["embed/io/backlight/inc"]
|
||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ["embed/io/i2c_bus/stm32u5/i2c_bus.c"]
|
sources += ["embed/io/i2c_bus/stm32u5/i2c_bus.c"]
|
||||||
sources += ["embed/io/touch/sitronix/sitronix.c"]
|
sources += ["embed/io/touch/sitronix/sitronix.c"]
|
||||||
|
Loading…
Reference in New Issue
Block a user