mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-24 05:12:02 +00:00
modtrezorui: add display.offset() function
This commit is contained in:
parent
57fbd4dfc2
commit
35beedfcbc
@ -17,6 +17,7 @@
|
||||
|
||||
static int BACKLIGHT = 0;
|
||||
static int ORIENTATION = 0;
|
||||
static int OFFSET[2] = {0, 0};
|
||||
|
||||
#if defined STM32_HAL_H
|
||||
#include "display-stmhal.h"
|
||||
@ -342,3 +343,12 @@ void display_raw(uint8_t reg, const uint8_t *data, int datalen)
|
||||
}
|
||||
DATAS(data, datalen);
|
||||
}
|
||||
|
||||
int *display_offset(int xy[2])
|
||||
{
|
||||
if (xy) {
|
||||
OFFSET[0] = xy[0];
|
||||
OFFSET[1] = xy[1];
|
||||
}
|
||||
return OFFSET;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ void display_init(void);
|
||||
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
int display_orientation(int degrees);
|
||||
int display_backlight(int val);
|
||||
int *display_offset(int xy[2]);
|
||||
|
||||
void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor);
|
||||
void display_clear(void);
|
||||
|
@ -339,6 +339,38 @@ STATIC mp_obj_t mod_TrezorUi_Display_backlight(size_t n_args, const mp_obj_t *ar
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_backlight_obj, 1, 2, mod_TrezorUi_Display_backlight);
|
||||
|
||||
/// def trezor.ui.display.offset(xy: tuple=None) -> tuple:
|
||||
/// '''
|
||||
/// Sets offset (x, y) for all subsequent drawing calls.
|
||||
/// Call without the xy parameter to just perform the read of the value.
|
||||
/// '''
|
||||
STATIC mp_obj_t mod_TrezorUi_Display_offset(size_t n_args, const mp_obj_t *args) {
|
||||
int xy[2], *ret;
|
||||
if (n_args > 1) {
|
||||
mp_uint_t xy_cnt;
|
||||
mp_obj_t *xy_obj;
|
||||
if (MP_OBJ_IS_TYPE(args[1], &mp_type_tuple)) {
|
||||
mp_obj_tuple_get(args[1], &xy_cnt, &xy_obj);
|
||||
} else {
|
||||
mp_raise_TypeError("Tuple expected");
|
||||
}
|
||||
if (xy_cnt != 2) {
|
||||
mp_raise_ValueError("Tuple of 2 values expected");
|
||||
}
|
||||
xy[0] = mp_obj_get_int(xy_obj[0]);
|
||||
xy[1] = mp_obj_get_int(xy_obj[1]);
|
||||
ret = display_offset(xy);
|
||||
} else {
|
||||
ret = display_offset(0);
|
||||
}
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
|
||||
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(ret[0]);
|
||||
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(ret[1]);
|
||||
return MP_OBJ_FROM_PTR(tuple);
|
||||
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_offset_obj, 1, 2, mod_TrezorUi_Display_offset);
|
||||
|
||||
/// def trezor.ui.display.raw(reg: int, data: bytes) -> None:
|
||||
/// '''
|
||||
/// Performs a raw command on the display. Read the datasheet to learn more.
|
||||
@ -382,6 +414,7 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_loader), MP_ROM_PTR(&mod_TrezorUi_Display_loader_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_TrezorUi_Display_orientation_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&mod_TrezorUi_Display_backlight_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_offset), MP_ROM_PTR(&mod_TrezorUi_Display_offset_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_raw), MP_ROM_PTR(&mod_TrezorUi_Display_raw_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_save), MP_ROM_PTR(&mod_TrezorUi_Display_save_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_FONT_MONO), MP_OBJ_NEW_SMALL_INT(FONT_MONO) },
|
||||
|
@ -1,12 +1,18 @@
|
||||
|
||||
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||
def setup(ifaces: list) -> None:
|
||||
def set_interfaces(ifaces: list/tuple) -> None:
|
||||
'''
|
||||
Configures USB interfaces with a list of tuples (interface_number, usage_page)
|
||||
Configures USB interfaces with a list/tuple of (usage_page, ...)
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||
def send(iface: int, message: bytes) -> int:
|
||||
def get_interfaces() -> tuple:
|
||||
'''
|
||||
Reads a tuple (of usage pages) of configured USB interfaces
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezormsg/modtrezormsg.c
|
||||
def send(usage_page: int, message: bytes) -> int:
|
||||
'''
|
||||
Sends message using USB HID (device) or UDP (emulator).
|
||||
'''
|
||||
|
@ -85,7 +85,7 @@ def loader(progress: int, fgcolor: int, bgcolor: int, icon: bytes=None, iconfgco
|
||||
Renders a rotating loader graphic.
|
||||
Progress determines its position (0-1000), fgcolor is used as foreground color, bgcolor as background.
|
||||
When icon and iconfgcolor are provided, an icon is drawn in the middle using the color specified in iconfgcolor.
|
||||
Icon needs to be of exaclty 96x96 pixels size.
|
||||
Icon needs to be of exactly LOADER_ICON_SIZE x LOADER_ICON_SIZE pixels size.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
@ -103,6 +103,13 @@ def backlight(val: int=None) -> int:
|
||||
Call without the val parameter to just perform the read of the value.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def offset(xy: tuple=None) -> tuple:
|
||||
'''
|
||||
Sets offset (x, y) for all subsequent drawing calls.
|
||||
Call without the xy parameter to just perform the read of the value.
|
||||
'''
|
||||
|
||||
# ../extmod/modtrezorui/modtrezorui-display.h
|
||||
def raw(reg: int, data: bytes) -> None:
|
||||
'''
|
||||
|
9
mocks/trezor/utils.py
Normal file
9
mocks/trezor/utils.py
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
# ../extmod/modtrezorutils/modtrezorutils.c
|
||||
def memcpy(dst: bytearray, dst_ofs: int,
|
||||
src: bytearray, src_ofs: int,
|
||||
'''
|
||||
Copies at most `n` bytes from `src` at offset `src_ofs` to
|
||||
`dst` at offset `dst_ofs`. Returns the number of actually
|
||||
copied bytes.
|
||||
'''
|
Loading…
Reference in New Issue
Block a user