mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-21 03:52:04 +00:00
refactor(core): make backlight/fading optional
[no changelog]
This commit is contained in:
parent
1f1680243f
commit
539420cac8
@ -695,7 +695,12 @@ if FROZEN:
|
|||||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
|
||||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Zcash*.py'))
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Zcash*.py'))
|
||||||
|
|
||||||
source_mpy = env.FrozenModule(source=SOURCE_PY, source_dir=SOURCE_PY_DIR, bitcoin_only=BITCOIN_ONLY)
|
source_mpy = env.FrozenModule(
|
||||||
|
source=SOURCE_PY,
|
||||||
|
source_dir=SOURCE_PY_DIR,
|
||||||
|
bitcoin_only=BITCOIN_ONLY,
|
||||||
|
backlight='backlight' in FEATURES_AVAILABLE
|
||||||
|
)
|
||||||
|
|
||||||
source_mpyc = env.FrozenCFile(
|
source_mpyc = env.FrozenCFile(
|
||||||
target='frozen_mpy.c', source=source_mpy, qstr_header=qstr_preprocessed)
|
target='frozen_mpy.c', source=source_mpy, qstr_header=qstr_preprocessed)
|
||||||
|
@ -690,7 +690,12 @@ if FROZEN:
|
|||||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'apps/bitcoin/sign_tx/zcash_v4.py'))
|
||||||
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Zcash*.py'))
|
SOURCE_PY.extend(Glob(SOURCE_PY_DIR + 'trezor/enums/Zcash*.py'))
|
||||||
|
|
||||||
source_mpy = env.FrozenModule(source=SOURCE_PY, source_dir=SOURCE_PY_DIR, bitcoin_only=BITCOIN_ONLY)
|
source_mpy = env.FrozenModule(
|
||||||
|
source=SOURCE_PY,
|
||||||
|
source_dir=SOURCE_PY_DIR,
|
||||||
|
bitcoin_only=BITCOIN_ONLY,
|
||||||
|
backlight='backlight' in TREZOR_MODEL in ('T',)
|
||||||
|
)
|
||||||
|
|
||||||
source_mpyc = env.FrozenCFile(
|
source_mpyc = env.FrozenCFile(
|
||||||
target='frozen_mpy.c', source=source_mpy, qstr_header=qstr_preprocessed)
|
target='frozen_mpy.c', source=source_mpy, qstr_header=qstr_preprocessed)
|
||||||
|
@ -259,6 +259,7 @@ STATIC mp_obj_str_t mod_trezorutils_revision_obj = {
|
|||||||
/// VERSION_MINOR: int
|
/// VERSION_MINOR: int
|
||||||
/// VERSION_PATCH: int
|
/// VERSION_PATCH: int
|
||||||
/// USE_SD_CARD: bool
|
/// USE_SD_CARD: bool
|
||||||
|
/// USE_BACKLIGHT: bool
|
||||||
/// MODEL: str
|
/// MODEL: str
|
||||||
/// INTERNAL_MODEL: str
|
/// INTERNAL_MODEL: str
|
||||||
/// EMULATOR: bool
|
/// EMULATOR: bool
|
||||||
@ -289,6 +290,11 @@ STATIC const mp_rom_map_elem_t mp_module_trezorutils_globals_table[] = {
|
|||||||
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_true},
|
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_true},
|
||||||
#else
|
#else
|
||||||
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_false},
|
{MP_ROM_QSTR(MP_QSTR_USE_SD_CARD), mp_const_false},
|
||||||
|
#endif
|
||||||
|
#ifdef USE_SD_CARD
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_USE_BACKLIGHT), mp_const_true},
|
||||||
|
#else
|
||||||
|
{MP_ROM_QSTR(MP_QSTR_USE_BACKLIGHT), mp_const_false},
|
||||||
#endif
|
#endif
|
||||||
{MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_QSTR(MODEL_NAME_QSTR)},
|
{MP_ROM_QSTR(MP_QSTR_MODEL), MP_ROM_QSTR(MODEL_NAME_QSTR)},
|
||||||
{MP_ROM_QSTR(MP_QSTR_INTERNAL_MODEL),
|
{MP_ROM_QSTR(MP_QSTR_INTERNAL_MODEL),
|
||||||
|
@ -567,11 +567,13 @@ void display_offset(int set_xy[2], int *get_x, int *get_y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void display_fade(int start, int end, int delay) {
|
void display_fade(int start, int end, int delay) {
|
||||||
|
#ifdef USE_BACKLIGHT
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
display_backlight(start + i * (end - start) / 100);
|
display_backlight(start + i * (end - start) / 100);
|
||||||
hal_delay(delay / 100);
|
hal_delay(delay / 100);
|
||||||
}
|
}
|
||||||
display_backlight(end);
|
display_backlight(end);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UTF8_IS_CONT(ch) (((ch)&0xC0) == 0x80)
|
#define UTF8_IS_CONT(ch) (((ch)&0xC0) == 0x80)
|
||||||
|
@ -27,6 +27,7 @@ debug = ["ui_debug"]
|
|||||||
sbu = []
|
sbu = []
|
||||||
sd_card = []
|
sd_card = []
|
||||||
rgb_led = []
|
rgb_led = []
|
||||||
|
backlight = []
|
||||||
test = [
|
test = [
|
||||||
"button",
|
"button",
|
||||||
"cc",
|
"cc",
|
||||||
@ -37,6 +38,7 @@ test = [
|
|||||||
"ui",
|
"ui",
|
||||||
"dma2d",
|
"dma2d",
|
||||||
"touch",
|
"touch",
|
||||||
|
"backlight"
|
||||||
]
|
]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
@ -39,15 +39,18 @@ pub fn backlight() -> u16 {
|
|||||||
display::backlight(-1) as u16
|
display::backlight(-1) as u16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "backlight")]
|
||||||
pub fn set_backlight(val: u16) {
|
pub fn set_backlight(val: u16) {
|
||||||
display::backlight(val as i32);
|
display::backlight(val as i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "backlight")]
|
||||||
pub fn fade_backlight(target: u16) {
|
pub fn fade_backlight(target: u16) {
|
||||||
const FADE_DURATION_MS: u32 = 50;
|
const FADE_DURATION_MS: u32 = 50;
|
||||||
fade_backlight_duration(target, FADE_DURATION_MS);
|
fade_backlight_duration(target, FADE_DURATION_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "backlight")]
|
||||||
pub fn fade_backlight_duration(target: u16, duration_ms: u32) {
|
pub fn fade_backlight_duration(target: u16, duration_ms: u32) {
|
||||||
let target = target as i32;
|
let target = target as i32;
|
||||||
let duration_ms = duration_ms as i32;
|
let duration_ms = duration_ms as i32;
|
||||||
@ -62,6 +65,15 @@ pub fn fade_backlight_duration(target: u16, duration_ms: u32) {
|
|||||||
set_backlight(target as u16);
|
set_backlight(target as u16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "backlight"))]
|
||||||
|
pub fn set_backlight(_: u16) {}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "backlight"))]
|
||||||
|
pub fn fade_backlight(_: u16) {}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "backlight"))]
|
||||||
|
pub fn fade_backlight_duration(_: u16, _: u32) {}
|
||||||
|
|
||||||
/// Fill a whole rectangle with a specific color.
|
/// Fill a whole rectangle with a specific color.
|
||||||
pub fn rect_fill(r: Rect, fg_color: Color) {
|
pub fn rect_fill(r: Rect, fg_color: Color) {
|
||||||
display::bar(r.x0, r.y0, r.width(), r.height(), fg_color.into());
|
display::bar(r.x0, r.y0, r.width(), r.height(), fg_color.into());
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#define USE_TOUCH 1
|
#define USE_TOUCH 1
|
||||||
#define USE_SBU 1
|
#define USE_SBU 1
|
||||||
#define USE_RGB_COLORS 1
|
#define USE_RGB_COLORS 1
|
||||||
|
#define USE_BACKLIGHT 1
|
||||||
#define USE_DISP_I8080_8BIT_DW 1
|
#define USE_DISP_I8080_8BIT_DW 1
|
||||||
|
|
||||||
#define I2C_COUNT 1
|
#define I2C_COUNT 1
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#define USE_SD_CARD 1
|
#define USE_SD_CARD 1
|
||||||
#define USE_SBU 1
|
#define USE_SBU 1
|
||||||
#define USE_RGB_COLORS 1
|
#define USE_RGB_COLORS 1
|
||||||
|
#define USE_BACKLIGHT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TREZOR_MODEL_1
|
#ifdef TREZOR_MODEL_1
|
||||||
|
@ -84,6 +84,7 @@ VERSION_MAJOR: int
|
|||||||
VERSION_MINOR: int
|
VERSION_MINOR: int
|
||||||
VERSION_PATCH: int
|
VERSION_PATCH: int
|
||||||
USE_SD_CARD: bool
|
USE_SD_CARD: bool
|
||||||
|
USE_BACKLIGHT: bool
|
||||||
MODEL: str
|
MODEL: str
|
||||||
INTERNAL_MODEL: str
|
INTERNAL_MODEL: str
|
||||||
EMULATOR: bool
|
EMULATOR: bool
|
||||||
|
@ -26,6 +26,8 @@ def configure(
|
|||||||
sources += [f'embed/trezorhal/displays/panels/lx154a2411.c', ]
|
sources += [f'embed/trezorhal/displays/panels/lx154a2411.c', ]
|
||||||
sources += [f'embed/trezorhal/displays/panels/lx154a2422.c', ]
|
sources += [f'embed/trezorhal/displays/panels/lx154a2422.c', ]
|
||||||
|
|
||||||
|
features_available.append("backlight")
|
||||||
|
|
||||||
if "input" in features_wanted:
|
if "input" in features_wanted:
|
||||||
sources += ["embed/trezorhal/i2c.c"]
|
sources += ["embed/trezorhal/i2c.c"]
|
||||||
sources += ["embed/trezorhal/touch/touch.c"]
|
sources += ["embed/trezorhal/touch/touch.c"]
|
||||||
|
@ -31,9 +31,11 @@ def generate(env):
|
|||||||
# replace "utils.BITCOIN_ONLY" with literal constant (True/False)
|
# replace "utils.BITCOIN_ONLY" with literal constant (True/False)
|
||||||
# so the compiler can optimize out the things we don't want
|
# so the compiler can optimize out the things we don't want
|
||||||
btc_only = env['bitcoin_only'] == '1'
|
btc_only = env['bitcoin_only'] == '1'
|
||||||
|
backlight = env['backlight']
|
||||||
interim = f"{target[:-4]}.i" # replace .mpy with .i
|
interim = f"{target[:-4]}.i" # replace .mpy with .i
|
||||||
sed_scripts = " ".join([
|
sed_scripts = " ".join([
|
||||||
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
|
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
|
||||||
|
rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'",
|
||||||
r"-e 's/if TYPE_CHECKING/if False/'",
|
r"-e 's/if TYPE_CHECKING/if False/'",
|
||||||
r"-e 's/import typing/# \0/'",
|
r"-e 's/import typing/# \0/'",
|
||||||
r"-e '/from typing import (/,/^\s*)/ {s/^/# /}'",
|
r"-e '/from typing import (/,/^\s*)/ {s/^/# /}'",
|
||||||
|
@ -66,29 +66,31 @@ async def _alert(count: int) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def alert(count: int = 3) -> None:
|
def alert(count: int = 3) -> None:
|
||||||
global _alert_in_progress
|
if utils.USE_BACKLIGHT:
|
||||||
if _alert_in_progress:
|
global _alert_in_progress
|
||||||
return
|
if _alert_in_progress:
|
||||||
|
return
|
||||||
|
|
||||||
_alert_in_progress = True
|
_alert_in_progress = True
|
||||||
loop.schedule(_alert(count))
|
loop.schedule(_alert(count))
|
||||||
|
|
||||||
|
|
||||||
def backlight_fade(val: int, delay: int = 14000, step: int = 15) -> None:
|
def backlight_fade(val: int, delay: int = 14000, step: int = 15) -> None:
|
||||||
if __debug__:
|
if utils.USE_BACKLIGHT:
|
||||||
if utils.DISABLE_ANIMATION:
|
if __debug__:
|
||||||
|
if utils.DISABLE_ANIMATION:
|
||||||
|
display.backlight(val)
|
||||||
|
return
|
||||||
|
current = display.backlight()
|
||||||
|
if current < 0:
|
||||||
display.backlight(val)
|
display.backlight(val)
|
||||||
return
|
return
|
||||||
current = display.backlight()
|
elif current > val:
|
||||||
if current < 0:
|
step = -step
|
||||||
|
for i in range(current, val, step):
|
||||||
|
display.backlight(i)
|
||||||
|
utime.sleep_us(delay)
|
||||||
display.backlight(val)
|
display.backlight(val)
|
||||||
return
|
|
||||||
elif current > val:
|
|
||||||
step = -step
|
|
||||||
for i in range(current, val, step):
|
|
||||||
display.backlight(i)
|
|
||||||
utime.sleep_us(delay)
|
|
||||||
display.backlight(val)
|
|
||||||
|
|
||||||
|
|
||||||
# Component events. Should be different from `io.TOUCH_*` events.
|
# Component events. Should be different from `io.TOUCH_*` events.
|
||||||
|
@ -6,6 +6,7 @@ from trezorutils import ( # noqa: F401
|
|||||||
INTERNAL_MODEL,
|
INTERNAL_MODEL,
|
||||||
MODEL,
|
MODEL,
|
||||||
SCM_REVISION,
|
SCM_REVISION,
|
||||||
|
USE_BACKLIGHT,
|
||||||
USE_SD_CARD,
|
USE_SD_CARD,
|
||||||
VERSION_MAJOR,
|
VERSION_MAJOR,
|
||||||
VERSION_MINOR,
|
VERSION_MINOR,
|
||||||
|
Loading…
Reference in New Issue
Block a user