mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-18 10:32:02 +00:00
display.orientation() and display.backlight() now return current value
This commit is contained in:
parent
c0313cc868
commit
171a7b3795
@ -93,31 +93,38 @@ static void display_unsleep(void) {
|
|||||||
|
|
||||||
static uint8_t WINDOW_OFFSET_X = 0, WINDOW_OFFSET_Y = 0;
|
static uint8_t WINDOW_OFFSET_X = 0, WINDOW_OFFSET_Y = 0;
|
||||||
|
|
||||||
void display_orientation(int degrees)
|
int display_orientation(int degrees)
|
||||||
{
|
{
|
||||||
// memory access control
|
if (degrees != ORIENTATION) {
|
||||||
switch (degrees) {
|
// memory access control
|
||||||
case 0:
|
switch (degrees) {
|
||||||
CMD(0x36); DATA(0x08 | (1<<6) | (1<<7));
|
case 0:
|
||||||
WINDOW_OFFSET_X = 0;
|
CMD(0x36); DATA(0x08 | (1<<6) | (1<<7));
|
||||||
WINDOW_OFFSET_Y = 80;
|
WINDOW_OFFSET_X = 0;
|
||||||
break;
|
WINDOW_OFFSET_Y = 80;
|
||||||
case 90:
|
ORIENTATION = 0;
|
||||||
CMD(0x36); DATA(0x08 | (1<<5) | (1<<6));
|
break;
|
||||||
WINDOW_OFFSET_X = 0;
|
case 90:
|
||||||
WINDOW_OFFSET_Y = 0;
|
CMD(0x36); DATA(0x08 | (1<<5) | (1<<6));
|
||||||
break;
|
WINDOW_OFFSET_X = 0;
|
||||||
case 180:
|
WINDOW_OFFSET_Y = 0;
|
||||||
CMD(0x36); DATA(0x08);
|
ORIENTATION = 90;
|
||||||
WINDOW_OFFSET_X = 0;
|
break;
|
||||||
WINDOW_OFFSET_Y = 0;
|
case 180:
|
||||||
break;
|
CMD(0x36); DATA(0x08);
|
||||||
case 270:
|
WINDOW_OFFSET_X = 0;
|
||||||
CMD(0x36); DATA(0x08 | (1<<5) | (1<<7));
|
WINDOW_OFFSET_Y = 0;
|
||||||
WINDOW_OFFSET_X = 80;
|
ORIENTATION = 180;
|
||||||
WINDOW_OFFSET_Y = 0;
|
break;
|
||||||
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) {
|
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_update(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_backlight(uint8_t val)
|
int display_backlight(int val)
|
||||||
{
|
{
|
||||||
|
if (val >= 0 && val <= 255) {
|
||||||
|
BACKLIGHT = val;
|
||||||
|
}
|
||||||
|
return BACKLIGHT;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ static SDL_Surface *SCREEN = 0;
|
|||||||
static SDL_Texture *TEXTURE = 0;
|
static SDL_Texture *TEXTURE = 0;
|
||||||
static int DATAODD = 0;
|
static int DATAODD = 0;
|
||||||
static int POSX, POSY, SX, SY, EX, EY = 0;
|
static int POSX, POSY, SX, SY, EX, EY = 0;
|
||||||
static int ROTATION = 0;
|
|
||||||
|
|
||||||
#define CMD(X) (void)(X);
|
#define CMD(X) (void)(X);
|
||||||
|
|
||||||
@ -112,16 +111,25 @@ void display_update(void)
|
|||||||
SDL_RenderClear(RENDERER);
|
SDL_RenderClear(RENDERER);
|
||||||
SDL_UpdateTexture(TEXTURE, NULL, SCREEN->pixels, SCREEN->pitch);
|
SDL_UpdateTexture(TEXTURE, NULL, SCREEN->pixels, SCREEN->pitch);
|
||||||
const SDL_Rect r = {DISPLAY_BORDER, DISPLAY_BORDER, RESX, RESY};
|
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);
|
SDL_RenderPresent(RENDERER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void display_orientation(int degrees)
|
int display_orientation(int degrees)
|
||||||
{
|
{
|
||||||
ROTATION = degrees;
|
if (degrees != ORIENTATION) {
|
||||||
display_update();
|
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;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static int BACKLIGHT = 255;
|
||||||
|
static int ORIENTATION = 0;
|
||||||
|
|
||||||
#if defined STM32_HAL_H
|
#if defined STM32_HAL_H
|
||||||
#include "display-stmhal.h"
|
#include "display-stmhal.h"
|
||||||
#else
|
#else
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
void display_init(void);
|
void display_init(void);
|
||||||
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
void display_set_window(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||||
void display_update(void);
|
void display_update(void);
|
||||||
void display_orientation(int degrees);
|
int display_orientation(int degrees);
|
||||||
void display_backlight(uint8_t val);
|
int display_backlight(int val);
|
||||||
|
|
||||||
void set_color_table(uint16_t colortable[16], uint16_t fgcolor, uint16_t bgcolor);
|
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);
|
void display_bar(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint16_t c);
|
||||||
|
@ -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);
|
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.
|
/// Sets display orientation to 0, 90, 180 or 270 degrees.
|
||||||
/// Everything needs to be redrawn again when this function is used.
|
/// 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) {
|
STATIC mp_obj_t mod_TrezorUi_Display_orientation(size_t n_args, const mp_obj_t *args) {
|
||||||
mp_int_t deg = mp_obj_get_int(degrees);
|
mp_int_t deg;
|
||||||
if (deg != 0 && deg != 90 && deg != 180 && deg != 270) {
|
if (n_args > 1) {
|
||||||
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "Value must be 0, 90, 180 or 270"));
|
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"));
|
||||||
|
}
|
||||||
|
deg = display_orientation(deg);
|
||||||
|
} else {
|
||||||
|
deg = display_orientation(-1);
|
||||||
}
|
}
|
||||||
display_orientation(deg);
|
return MP_OBJ_NEW_SMALL_INT(deg);
|
||||||
return mp_const_none;
|
|
||||||
}
|
}
|
||||||
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.
|
/// 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) {
|
STATIC mp_obj_t mod_TrezorUi_Display_backlight(size_t n_args, const mp_obj_t *args) {
|
||||||
display_backlight(mp_obj_get_int(reg));
|
mp_int_t val;
|
||||||
return mp_const_none;
|
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
|
/// def trezor.ui.display.raw(reg: int, data: bytes) -> None
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user