From a447cb549281e1d09e2becd140db289b3df2aa1c Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 4 Apr 2016 12:02:49 +0200 Subject: [PATCH] refactor display_rawcmd into display_raw --- docs/api.md | 2 +- extmod/modTrezorUi/modTrezorUi-stmhal.h | 6 ------ extmod/modTrezorUi/modTrezorUi-unix.h | 5 +---- extmod/modTrezorUi/modTrezorUi.c | 18 +++++++++++++----- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/docs/api.md b/docs/api.md index 0369e28ce0..5e9f63f704 100644 --- a/docs/api.md +++ b/docs/api.md @@ -34,7 +34,7 @@ trezor.ui.display.qrcode(self, x: int, y: int, data: bytes, scale: int) -> None trezor.ui.display.orientation(self, degrees: int) -> None -trezor.ui.display.rawcmd(self, reg: int, data: bytes) -> None +trezor.ui.display.raw(self, reg: int, data: bytes) -> None trezor.ui.display.backlight(self, val: int) -> None ``` diff --git a/extmod/modTrezorUi/modTrezorUi-stmhal.h b/extmod/modTrezorUi/modTrezorUi-stmhal.h index d991c5eaa8..491527a6b7 100644 --- a/extmod/modTrezorUi/modTrezorUi-stmhal.h +++ b/extmod/modTrezorUi/modTrezorUi-stmhal.h @@ -165,12 +165,6 @@ static void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) { static void display_update(void) { } -static void display_rawcmd(uint8_t reg, uint8_t *data, int datalen) -{ - CMD(reg); - DATAS(data, datalen); -} - static void display_backlight(uint8_t val) { } diff --git a/extmod/modTrezorUi/modTrezorUi-unix.h b/extmod/modTrezorUi/modTrezorUi-unix.h index f0f6ee1c3e..ba813ab5af 100644 --- a/extmod/modTrezorUi/modTrezorUi-unix.h +++ b/extmod/modTrezorUi/modTrezorUi-unix.h @@ -15,6 +15,7 @@ static int DATAODD = 0; static int POSX, POSY, SX, SY, EX, EY = 0; static int ROTATION = 0; +#define CMD(X) (void)(X); #define DATA(X) DATAfunc((X)) #define DISPLAY_BORDER 8 @@ -108,10 +109,6 @@ static void display_orientation(int degrees) display_update(); } -static void display_rawcmd(uint8_t reg, uint8_t *data, int datalen) -{ -} - static void display_backlight(uint8_t val) { } diff --git a/extmod/modTrezorUi/modTrezorUi.c b/extmod/modTrezorUi/modTrezorUi.c index a5032a66e9..32f7d41ddd 100644 --- a/extmod/modTrezorUi/modTrezorUi.c +++ b/extmod/modTrezorUi/modTrezorUi.c @@ -190,6 +190,14 @@ static void display_qrcode(uint8_t x, uint8_t y, char *data, int datalen, int sc display_update(); } +static void display_raw(uint8_t reg, uint8_t *data, int datalen) +{ + if (reg) { + CMD(reg); + } + DATAS(data, datalen); +} + // uPy wrappers // class Display(object): @@ -318,15 +326,15 @@ STATIC mp_obj_t mod_TrezorUi_Display_orientation(mp_obj_t self, mp_obj_t degrees } MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_orientation_obj, mod_TrezorUi_Display_orientation); -// def Display.rawcmd(self, reg: int, data: bytes) -> None -STATIC mp_obj_t mod_TrezorUi_Display_rawcmd(mp_obj_t self, mp_obj_t reg, mp_obj_t data) { +// def Display.raw(self, reg: int, data: bytes) -> None +STATIC mp_obj_t mod_TrezorUi_Display_raw(mp_obj_t self, mp_obj_t reg, mp_obj_t data) { mp_int_t r = mp_obj_get_int(reg); mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); - display_rawcmd(r, bufinfo.buf, bufinfo.len); + display_raw(r, bufinfo.buf, bufinfo.len); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_rawcmd_obj, mod_TrezorUi_Display_rawcmd); +MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_raw_obj, mod_TrezorUi_Display_raw); // def Display.backlight(self, val: int) -> None STATIC mp_obj_t mod_TrezorUi_Display_backlight(mp_obj_t self, mp_obj_t reg) { @@ -345,7 +353,7 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_TrezorUi_Display_text_obj) }, { MP_ROM_QSTR(MP_QSTR_qrcode), MP_ROM_PTR(&mod_TrezorUi_Display_qrcode_obj) }, { MP_ROM_QSTR(MP_QSTR_orientation), MP_ROM_PTR(&mod_TrezorUi_Display_orientation_obj) }, - { MP_ROM_QSTR(MP_QSTR_rawcmd), MP_ROM_PTR(&mod_TrezorUi_Display_rawcmd_obj) }, + { MP_ROM_QSTR(MP_QSTR_raw), MP_ROM_PTR(&mod_TrezorUi_Display_raw_obj) }, { MP_ROM_QSTR(MP_QSTR_backlight), MP_ROM_PTR(&mod_TrezorUi_Display_backlight_obj) }, }; STATIC MP_DEFINE_CONST_DICT(mod_TrezorUi_Display_locals_dict, mod_TrezorUi_Display_locals_dict_table);