1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-30 01:01:00 +00:00

display updates

This commit is contained in:
mcudev 2017-09-07 21:04:23 -04:00 committed by Pavol Rusnak
parent 58bad110e2
commit 43e8b85700
8 changed files with 54 additions and 46 deletions

View File

@ -146,9 +146,6 @@ int main(void)
__fatal_error("sdcard_init", __FILE__, __LINE__, __FUNCTION__); __fatal_error("sdcard_init", __FILE__, __LINE__, __FUNCTION__);
} }
display_clear();
display_backlight(255);
display_printf("TREZOR Boardloader %d.%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD); display_printf("TREZOR Boardloader %d.%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD);
display_printf("==================\n"); display_printf("==================\n");
display_printf("starting boardloader\n"); display_printf("starting boardloader\n");

View File

@ -83,7 +83,6 @@ void check_and_jump(void)
display_vendor(vhdr.vimg, (const char *)vhdr.vstr, vhdr.vstr_len, hdr.version); display_vendor(vhdr.vimg, (const char *)vhdr.vstr, vhdr.vstr_len, hdr.version);
HAL_Delay(1000); // TODO: remove? HAL_Delay(1000); // TODO: remove?
display_printf("JUMP!\n");
jump_to(FIRMWARE_START + vhdr.hdrlen + HEADER_SIZE); jump_to(FIRMWARE_START + vhdr.hdrlen + HEADER_SIZE);
} else { } else {
@ -195,17 +194,14 @@ int main(void)
{ {
periph_init(); periph_init();
if (0 != display_init()) { display_pwm_init();
__fatal_error("display_init", __FILE__, __LINE__, __FUNCTION__); display_orientation(0);
} display_backlight(255);
if (0 != touch_init()) { if (0 != touch_init()) {
__fatal_error("touch_init", __FILE__, __LINE__, __FUNCTION__); __fatal_error("touch_init", __FILE__, __LINE__, __FUNCTION__);
} }
display_clear();
display_backlight(255);
display_printf("TREZOR Bootloader %d.%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD); display_printf("TREZOR Bootloader %d.%d.%d.%d\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_BUILD);
display_printf("=================\n"); display_printf("=================\n");
display_printf("starting bootloader\n"); display_printf("starting bootloader\n");

View File

@ -119,6 +119,30 @@ void display_set_backlight(int val)
__HAL_TIM_SET_COMPARE(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * val / 255); __HAL_TIM_SET_COMPARE(&TIM1_Handle, TIM_CHANNEL_1, LED_PWM_TIM_PERIOD * val / 255);
} }
void display_pwm_init(void)
{
// enable PWM timer
TIM1_Handle.Instance = TIM1;
TIM1_Handle.Init.Period = LED_PWM_TIM_PERIOD - 1;
TIM1_Handle.Init.Prescaler = timer1_get_source_freq() / 1000000 - 1; // TIM runs at 1MHz
TIM1_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
TIM1_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
TIM1_Handle.Init.RepetitionCounter = 0;
HAL_TIM_PWM_Init(&TIM1_Handle);
TIM_OC_InitTypeDef TIM_OC_InitStructure;
TIM_OC_InitStructure.Pulse = 0;
TIM_OC_InitStructure.OCMode = TIM_OCMODE_PWM2;
TIM_OC_InitStructure.OCPolarity = TIM_OCPOLARITY_HIGH;
TIM_OC_InitStructure.OCFastMode = TIM_OCFAST_DISABLE;
TIM_OC_InitStructure.OCNPolarity = TIM_OCNPOLARITY_HIGH;
TIM_OC_InitStructure.OCIdleState = TIM_OCIDLESTATE_SET;
TIM_OC_InitStructure.OCNIdleState = TIM_OCNIDLESTATE_SET;
HAL_TIM_PWM_ConfigChannel(&TIM1_Handle, &TIM_OC_InitStructure, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&TIM1_Handle, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start(&TIM1_Handle, TIM_CHANNEL_1);
}
int display_init(void) { int display_init(void) {
// init peripherials // init peripherials
__HAL_RCC_GPIOE_CLK_ENABLE(); __HAL_RCC_GPIOE_CLK_ENABLE();
@ -161,26 +185,7 @@ int display_init(void) {
GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10; GPIO_InitStructure.Pin = GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10;
HAL_GPIO_Init(GPIOE, &GPIO_InitStructure); HAL_GPIO_Init(GPIOE, &GPIO_InitStructure);
// enable PWM timer display_pwm_init();
TIM1_Handle.Instance = TIM1;
TIM1_Handle.Init.Period = LED_PWM_TIM_PERIOD - 1;
TIM1_Handle.Init.Prescaler = timer1_get_source_freq() / 1000000 - 1; // TIM runs at 1MHz
TIM1_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
TIM1_Handle.Init.CounterMode = TIM_COUNTERMODE_UP;
TIM1_Handle.Init.RepetitionCounter = 0;
HAL_TIM_PWM_Init(&TIM1_Handle);
TIM_OC_InitTypeDef TIM_OC_InitStructure;
TIM_OC_InitStructure.Pulse = 0;
TIM_OC_InitStructure.OCMode = TIM_OCMODE_PWM2;
TIM_OC_InitStructure.OCPolarity = TIM_OCPOLARITY_HIGH;
TIM_OC_InitStructure.OCFastMode = TIM_OCFAST_DISABLE;
TIM_OC_InitStructure.OCNPolarity = TIM_OCNPOLARITY_HIGH;
TIM_OC_InitStructure.OCIdleState = TIM_OCIDLESTATE_SET;
TIM_OC_InitStructure.OCNIdleState = TIM_OCNIDLESTATE_SET;
HAL_TIM_PWM_ConfigChannel(&TIM1_Handle, &TIM_OC_InitStructure, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&TIM1_Handle, TIM_CHANNEL_1);
HAL_TIMEx_PWMN_Start(&TIM1_Handle, TIM_CHANNEL_1);
// timing values from: // timing values from:
// http://ele-tech.com/html/it-is-developed-that-embedded-stm32-fsmc-interface-drives-tft-lcd-to-be-designed.html // http://ele-tech.com/html/it-is-developed-that-embedded-stm32-fsmc-interface-drives-tft-lcd-to-be-designed.html
@ -269,18 +274,16 @@ int display_init(void) {
CMD(0x26); DATA(0x01); // gamma func (gc3) enable CMD(0x26); DATA(0x01); // gamma func (gc3) enable
CMD(0x20); // don't invert colors CMD(0x20); // don't invert colors
#endif #endif
display_set_orientation(0); display_backlight(0);
display_set_backlight(0);
// clear buffer
display_clear(); display_clear();
display_orientation(0);
display_unsleep(); display_unsleep();
display_backlight(255);
return 0; return 0;
} }
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { static void display_set_window_raw(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
x0 += BUFFER_OFFSET_X; y0 += BUFFER_OFFSET_Y; {
x1 += BUFFER_OFFSET_X; y1 += BUFFER_OFFSET_Y;
#if DISPLAY_ILI9341V || DISPLAY_ST7789V #if DISPLAY_ILI9341V || DISPLAY_ST7789V
CMD(0x2A); DATA(x0 >> 8); DATA(x0 & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set CMD(0x2A); DATA(x0 >> 8); DATA(x0 & 0xFF); DATA(x1 >> 8); DATA(x1 & 0xFF); // column addr set
CMD(0x2B); DATA(y0 >> 8); DATA(y0 & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set CMD(0x2B); DATA(y0 >> 8); DATA(y0 & 0xFF); DATA(y1 >> 8); DATA(y1 & 0xFF); // row addr set
@ -288,6 +291,13 @@ static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y
#endif #endif
} }
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
x0 += BUFFER_OFFSET_X; y0 += BUFFER_OFFSET_Y;
x1 += BUFFER_OFFSET_X; y1 += BUFFER_OFFSET_Y;
display_set_window_raw(x0, y0, x1, y1);
}
void display_refresh(void) { void display_refresh(void) {
#if DISPLAY_VSYNC #if DISPLAY_VSYNC
// synchronize with the panel synchronization signal in order to avoid visual tearing effects // synchronize with the panel synchronization signal in order to avoid visual tearing effects

View File

@ -62,7 +62,7 @@ int display_init(void)
return 0; return 0;
} }
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) static void display_set_window_raw(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{ {
#ifndef TREZOR_NOUI #ifndef TREZOR_NOUI
SX = x0; SY = y0; SX = x0; SY = y0;
@ -72,6 +72,11 @@ static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y
#endif #endif
} }
static void display_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
display_set_window_raw(x0, y0, x1, y1);
}
void display_refresh(void) void display_refresh(void)
{ {
#ifndef TREZOR_NOUI #ifndef TREZOR_NOUI

View File

@ -24,8 +24,8 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
static int DISPLAY_BACKLIGHT = 0; static int DISPLAY_BACKLIGHT = -1;
static int DISPLAY_ORIENTATION = 0; static int DISPLAY_ORIENTATION = -1;
static int DISPLAY_OFFSET[2] = {0, 0}; static int DISPLAY_OFFSET[2] = {0, 0};
#if defined TREZOR_STM32 #if defined TREZOR_STM32
@ -67,8 +67,8 @@ static inline void clamp_coords(int x, int y, int w, int h, int *x0, int *y0, in
void display_clear(void) void display_clear(void)
{ {
display_set_window(0, 0, DISPLAY_RESX - 1, DISPLAY_RESY - 1); display_set_window_raw(0, 0, MAX_DISPLAY_RESX - 1, MAX_DISPLAY_RESY - 1);
for (int i = 0; i < DISPLAY_RESX * DISPLAY_RESY * 2; i++) { for (int i = 0; i < MAX_DISPLAY_RESX * MAX_DISPLAY_RESY * 2; i++) {
DATA(0x00); DATA(0x00);
} }
} }

View File

@ -42,6 +42,7 @@
// provided by port // provided by port
void display_pwm_init(void);
int display_init(void); int display_init(void);
void display_refresh(void); void display_refresh(void);
void display_save(const char *filename); void display_save(const char *filename);

View File

@ -23,7 +23,6 @@ typedef struct _mp_obj_Display_t {
/// ''' /// '''
STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { STATIC mp_obj_t mod_trezorui_Display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_arg_check_num(n_args, n_kw, 0, 0, false);
display_init();
mp_obj_Display_t *o = m_new_obj(mp_obj_Display_t); mp_obj_Display_t *o = m_new_obj(mp_obj_Display_t);
o->base.type = type; o->base.type = type;
return MP_OBJ_FROM_PTR(o); return MP_OBJ_FROM_PTR(o);

View File

@ -27,9 +27,9 @@ int main(void) {
pendsv_init(); pendsv_init();
if (0 != display_init()) { display_pwm_init();
__fatal_error("display_init", __FILE__, __LINE__, __FUNCTION__); display_orientation(0);
} display_backlight(255);
if (0 != flash_init()) { if (0 != flash_init()) {
__fatal_error("flash_init", __FILE__, __LINE__, __FUNCTION__); __fatal_error("flash_init", __FILE__, __LINE__, __FUNCTION__);