1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 20:19:23 +00:00

add Display.orientation and Display.rawcmd

This commit is contained in:
Pavol Rusnak 2016-03-29 16:57:46 +02:00
parent 05d00668e0
commit be3cd79bc8
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 42 additions and 9 deletions

View File

@ -95,21 +95,31 @@ static void display_unsleep(void) {
CMD(0x29); // display
}
static uint8_t WINDOW_OFFSET_X = 0, WINDOW_OFFSET_Y = 0;
static void display_orientation(uint16_t degrees)
{
// memory access control
switch (degrees) {
case 0:
CMD(0x36); DATA(0x08);
CMD(0x36); DATA(0x08 | (1<<6) | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
break;
case 90:
CMD(0x36); DATA(0x08);
CMD(0x36); DATA(0x08 | (1<<5) | (1<<6));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
break;
case 180:
CMD(0x36); DATA(0x08);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
break;
case 270:
CMD(0x36); DATA(0x08);
CMD(0x36); DATA(0x08 | (1<<5) | (1<<7));
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
break;
}
}
@ -142,11 +152,21 @@ static void display_init(void) {
display_unsleep();
}
static void display_set_window(uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
CMD(0x2A); DATA(0); DATA(x); DATA(0); DATA(x + w - 1); // column addr set
CMD(0x2B); DATA(0); DATA(y); DATA(0); DATA(y + h - 1); // row addr set
static void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
x += WINDOW_OFFSET_X;
y += WINDOW_OFFSET_Y;
uint16_t x1 = x + w - 1;
uint16_t y1 = y + h - 1;
CMD(0x2A); DATA(x >> 8); DATA(x & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
CMD(0x2B); DATA(y >> 8); DATA(y & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
CMD(0x2C);
}
static void display_update(void) {
}
static void display_rawcmd(uint8_t reg, uint8_t *data, int datalen)
{
CMD(reg);
DATAS(data, datalen);
}

View File

@ -55,7 +55,7 @@ static void display_init(void)
SDL_inited = 1;
}
static void display_set_window(uint8_t x, uint8_t y, uint8_t w, uint8_t h) {
static void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
if (!SDL_inited) return;
SX = x; SY = y;
EX = x + w - 1; EY = y + h - 1;
@ -77,3 +77,7 @@ static void display_orientation(int degrees)
ROTATION = degrees;
display_update();
}
static void display_rawcmd(uint8_t reg, uint8_t *data, int datalen)
{
}

View File

@ -26,8 +26,6 @@
#error Unsupported port. Only STMHAL and UNIX ports are supported.
#endif
#define SINF_WRITE DATA
#include "modTrezorUi-inflate.h"
#include "modTrezorUi-font_Roboto.h"
#include "modTrezorUi-font_RobotoMono.h"
@ -257,6 +255,16 @@ 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) {
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);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUi_Display_rawcmd_obj, mod_TrezorUi_Display_rawcmd);
STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&mod_TrezorUi_Display_bar_obj) },
{ MP_ROM_QSTR(MP_QSTR_blit), MP_ROM_PTR(&mod_TrezorUi_Display_blit_obj) },
@ -264,6 +272,7 @@ STATIC const mp_rom_map_elem_t mod_TrezorUi_Display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_icon), MP_ROM_PTR(&mod_TrezorUi_Display_icon_obj) },
{ MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&mod_TrezorUi_Display_text_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) },
};
STATIC MP_DEFINE_CONST_DICT(mod_TrezorUi_Display_locals_dict, mod_TrezorUi_Display_locals_dict_table);