1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

display.orientation() and display.backlight() now return current value

This commit is contained in:
Pavol Rusnak 2016-05-18 00:39:19 +02:00
parent c0313cc868
commit 171a7b3795
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 83 additions and 45 deletions

View File

@ -93,31 +93,38 @@ static void display_unsleep(void) {
static uint8_t WINDOW_OFFSET_X = 0, WINDOW_OFFSET_Y = 0;
void display_orientation(int degrees)
int display_orientation(int degrees)
{
if (degrees != ORIENTATION) {
// memory access control
switch (degrees) {
case 0:
CMD(0x36); DATA(0x08 | (1<<6) | (1<<7));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 80;
ORIENTATION = 0;
break;
case 90:
CMD(0x36); DATA(0x08 | (1<<5) | (1<<6));
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
ORIENTATION = 90;
break;
case 180:
CMD(0x36); DATA(0x08);
WINDOW_OFFSET_X = 0;
WINDOW_OFFSET_Y = 0;
ORIENTATION = 180;
break;
case 270:
CMD(0x36); DATA(0x08 | (1<<5) | (1<<7));
WINDOW_OFFSET_X = 80;
WINDOW_OFFSET_Y = 0;
ORIENTATION = 270;
break;
}
}
return ORIENTATION;
}
void display_init(void) {
@ -161,6 +168,10 @@ void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
void display_update(void) {
}
void display_backlight(uint8_t val)
int display_backlight(int val)
{
if (val >= 0 && val <= 255) {
BACKLIGHT = val;
}
return BACKLIGHT;
}

View File

@ -15,7 +15,6 @@ static SDL_Surface *SCREEN = 0;
static SDL_Texture *TEXTURE = 0;
static int DATAODD = 0;
static int POSX, POSY, SX, SY, EX, EY = 0;
static int ROTATION = 0;
#define CMD(X) (void)(X);
@ -112,16 +111,25 @@ void display_update(void)
SDL_RenderClear(RENDERER);
SDL_UpdateTexture(TEXTURE, NULL, SCREEN->pixels, SCREEN->pitch);
const SDL_Rect r = {DISPLAY_BORDER, DISPLAY_BORDER, RESX, RESY};
SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, ROTATION, NULL, 0);
SDL_RenderCopyEx(RENDERER, TEXTURE, NULL, &r, ORIENTATION, NULL, 0);
SDL_RenderPresent(RENDERER);
}
void display_orientation(int degrees)
int display_orientation(int degrees)
{
ROTATION = degrees;
if (degrees != ORIENTATION) {
if (degrees == 0 || degrees == 90 || degrees == 180 || degrees == 270) {
ORIENTATION = degrees;
display_update();
}
}
return ORIENTATION;
}
void display_backlight(uint8_t val)
int display_backlight(int val)
{
if (val >= 0 && val <= 255) {
BACKLIGHT = val;
}
return BACKLIGHT;
}

View File

@ -15,6 +15,9 @@
#include "display.h"
#include <string.h>
static int BACKLIGHT = 255;
static int ORIENTATION = 0;
#if defined STM32_HAL_H
#include "display-stmhal.h"
#else

View File

@ -14,8 +14,8 @@
void display_init(void);
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
void display_update(void);
void display_orientation(int degrees);
void display_backlight(uint8_t val);
int display_orientation(int degrees);
int display_backlight(int val);
void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor);
void display_bar(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c);

View File

@ -252,30 +252,46 @@ STATIC mp_obj_t mod_TrezorUi_Display_loader(size_t n_args, const mp_obj_t *args)
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_loader_obj, 4, 6, mod_TrezorUi_Display_loader);
/// def trezor.ui.display.orientation(degrees: int) -> None
/// def trezor.ui.display.orientation(degrees: int=None) -> int
///
/// Sets display orientation to 0, 90, 180 or 270 degrees.
/// Everything needs to be redrawn again when this function is used.
/// Call without the degrees parameter to just perform the read of the value.
///
STATIC mp_obj_t mod_TrezorUi_Display_orientation(mp_obj_t self, mp_obj_t degrees) {
mp_int_t deg = mp_obj_get_int(degrees);
STATIC mp_obj_t mod_TrezorUi_Display_orientation(size_t n_args, const mp_obj_t *args) {
mp_int_t deg;
if (n_args > 1) {
deg = mp_obj_get_int(args[1]);
if (deg != 0 && deg != 90 && deg != 180 && deg != 270) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Value must be 0, 90, 180 or 270"));
}
display_orientation(deg);
return mp_const_none;
deg = display_orientation(deg);
} else {
deg = display_orientation(-1);
}
return MP_OBJ_NEW_SMALL_INT(deg);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_orientation_obj, mod_TrezorUi_Display_orientation);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_orientation_obj, 1, 2, mod_TrezorUi_Display_orientation);
/// def trezor.ui.display.backlight(val: int) -> None
/// def trezor.ui.display.backlight(val: int=None) -> int
///
/// Sets backlight intensity to the value specified in val.
/// Call without the val parameter to just perform the read of the value.
///
STATIC mp_obj_t mod_TrezorUi_Display_backlight(mp_obj_t self, mp_obj_t reg) {
display_backlight(mp_obj_get_int(reg));
return mp_const_none;
STATIC mp_obj_t mod_TrezorUi_Display_backlight(size_t n_args, const mp_obj_t *args) {
mp_int_t val;
if (n_args > 1) {
val = mp_obj_get_int(args[1]);
if (val < 0 || val > 255) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Value must be between 0 and 255"));
}
val = display_backlight(val);
} else {
val = display_backlight(-1);
}
return MP_OBJ_NEW_SMALL_INT(val);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Display_backlight_obj, mod_TrezorUi_Display_backlight);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_TrezorUi_Display_backlight_obj, 1, 2, mod_TrezorUi_Display_backlight);
/// def trezor.ui.display.raw(reg: int, data: bytes) -> None
///