Skip to content

Commit

Permalink
performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ChisBread committed Sep 4, 2022
1 parent 3e4bce6 commit 88548f8
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 81 deletions.
29 changes: 13 additions & 16 deletions Firmware/ESP32/RX5808/main/gui/lvgl_app/page_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ bool lock_flag = false; //lock
static void page_main_exit(void);
static void page_main_group_create(void);
static void fre_label_update(uint8_t a, uint8_t b);

static void event_callback(lv_event_t* event)
{
lv_event_code_t code = lv_event_get_code(event);
if (code == LV_EVENT_KEY)
{
if (lock_flag == true)
{
if (code == LV_EVENT_KEY) {
if (lock_flag == true) {
lv_key_t key_status = lv_indev_get_key(lv_indev_get_act());
if (key_status >= LV_KEY_UP && key_status <= LV_KEY_LEFT) {
beep_on_off(1);
lv_fun_param_delayed(beep_on_off, 100, 0);
}
video_composite_sync_release(40);// 临时取消帧同步,让画面看起来流畅点
if (key_status == LV_KEY_LEFT) {
channel_count--;
if (channel_count < 0)
Expand All @@ -65,8 +63,7 @@ static void event_callback(lv_event_t* event)
rx5808_div_setup_upload();
fre_label_update(Chx_count, channel_count);
lv_label_set_text_fmt(lv_channel_label, "%c%d", Rx5808_ChxMap[Chx_count], channel_count + 1);
}
else if (key_status == LV_KEY_RIGHT) {
} else if (key_status == LV_KEY_RIGHT) {
channel_count++;
if (channel_count > 7)
channel_count = 0;
Expand All @@ -75,9 +72,7 @@ static void event_callback(lv_event_t* event)
rx5808_div_setup_upload();
fre_label_update(Chx_count, channel_count);
lv_label_set_text_fmt(lv_channel_label, "%c%d", Rx5808_ChxMap[Chx_count], channel_count + 1);

}
else if (key_status == LV_KEY_UP) {
} else if (key_status == LV_KEY_UP) {
Chx_count--;
if (Chx_count < 0)
Chx_count = 5;
Expand All @@ -86,8 +81,7 @@ static void event_callback(lv_event_t* event)
rx5808_div_setup_upload();
fre_label_update(Chx_count, channel_count);
lv_label_set_text_fmt(lv_channel_label, "%c%d", Rx5808_ChxMap[Chx_count], channel_count + 1);
}
else if (key_status == LV_KEY_DOWN) {
} else if (key_status == LV_KEY_DOWN) {
Chx_count++;
if (Chx_count > 5)
Chx_count = 0;
Expand All @@ -99,8 +93,10 @@ static void event_callback(lv_event_t* event)
}
}
}
else if (code == LV_EVENT_SHORT_CLICKED)
{
else if (code == LV_EVENT_SHORT_CLICKED) {
if(get_video_switch()) {
video_composite_sync_release(90);// 临时取消帧同步,让画面看起来流畅点
}
beep_on_off(1);
lv_fun_param_delayed(beep_on_off, 100, 0);
page_main_exit();
Expand All @@ -120,8 +116,9 @@ static void event_callback(lv_event_t* event)
lv_obj_set_style_bg_color(lock_btn, lv_color_make(255, 0, 0), LV_STATE_DEFAULT);
lock_flag = false;
}
// 开启或关闭OSD
composite_switch(lock_flag);
// 开启或关闭OSD与帧同步
video_composite_switch(lock_flag);
video_composite_sync_switch(lock_flag);
}
}

Expand Down
11 changes: 8 additions & 3 deletions Firmware/ESP32/RX5808/main/gui/lvgl_app/page_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "page_scan.h"
#include "page_main.h"
#include "lvgl_stl.h"
#include "lv_port_disp.h"
#include "rx5808.h"
#include "lcd.h"
#include "beep.h"
Expand Down Expand Up @@ -49,11 +50,12 @@ void Menu_event_callback(lv_event_t* event)
lv_event_code_t code = lv_event_get_code(event);
lv_obj_t* obj = lv_event_get_target(event);
lv_key_t key_status = lv_indev_get_key(lv_indev_get_act());
if (code == LV_EVENT_KEY)
{
if (code == LV_EVENT_KEY) {
beep_on_off(1);
lv_fun_param_delayed(beep_on_off, 100, 0);

if(get_video_switch()) {
video_composite_sync_release(30);// 临时取消帧同步,让画面看起来流畅点
}
if (key_status == LV_KEY_ENTER) {
if (obj == rx5808_div_menu[item_setup].item_contain) {
page_menu_exit();
Expand All @@ -69,6 +71,9 @@ void Menu_event_callback(lv_event_t* event)
}
}
else if (key_status == LV_KEY_LEFT) {
if(get_video_switch()) {
video_composite_sync_release(160);// 临时取消帧同步,让画面看起来流畅点
}
page_menu_exit();
page_main_create();
}
Expand Down
57 changes: 26 additions & 31 deletions Firmware/ESP32/RX5808/main/gui/lvgl_driver/lv_port_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "lv_port_disp.h"
#include "../../lvgl.h"
#include "lcd.h"
//#include "lvgl_driver_video.h"
#include "capi_video.h"
#include "driver/gpio.h"
/*********************
Expand All @@ -26,34 +25,21 @@ lv_color_t lv_disp_buf2[DISP_BUF_SIZE];
lv_disp_drv_t *disp_drv_spi;
lv_disp_t *default_disp = NULL;
bool g_dac_video_render = false;
bool g_dac_video_sync = false;
uint16_t sync_release_times = 0;
uint8_t refresh_times = 0;
/**********************
* TYPEDEFS
**********************/

/**********************
* STATIC PROTOTYPES
**********************/
static void disp_init(void);

static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
// const lv_area_t * fill_area, lv_color_t color);

/**********************
* STATIC VARIABLES
**********************/

/**********************
* MACROS
**********************/

/**********************
* GLOBAL FUNCTIONS
**********************/
static void composite_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area);
void composite_monitor_cb(lv_disp_drv_t *disp_drv, uint32_t time_ms, uint32_t px_num);
void composite_switch(bool flag) {
static void IRAM_ATTR composite_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area);
void IRAM_ATTR composite_monitor_cb(lv_disp_drv_t *disp_drv, uint32_t time_ms, uint32_t px_num);
bool get_video_switch(void) {
return g_dac_video_render;
}
void IRAM_ATTR video_composite_switch(bool flag) {
g_dac_video_render = flag;
if(g_dac_video_render) {
// 注册A/V信号输出
Expand All @@ -65,6 +51,12 @@ void composite_switch(bool flag) {
gpio_set_level(DAC_VIDEO_SWITCH, 0);
graph_video_stop();
}
void video_composite_sync_switch(bool flag) {
g_dac_video_sync = flag;
}
void video_composite_sync_release(uint16_t times) {
sync_release_times = times;
}
void lv_port_disp_init(void)
{
/*-------------------------
Expand Down Expand Up @@ -109,7 +101,7 @@ void lv_port_disp_init(void)
/*Finally register the driver*/
disp_drv_spi = &disp_drv;
default_disp = lv_disp_drv_register(disp_drv_spi);
//composite_switch(true);
//video_composite_switch(true);
}

/**********************
Expand All @@ -126,15 +118,22 @@ static void disp_init(void)
*You can use DMA or any hardware acceleration to do this operation in the background but
*'lv_disp_flush_ready()' has to be called when finished.*/
uint16_t videoframe_cnt = 0;
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
static void IRAM_ATTR disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
/*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/
//DAC flush
if(g_dac_video_render) {
//加了以后画面更稳定, 但影响UI流畅度
if(g_dac_video_sync && !sync_release_times) {
graph_video_sync();
}
if(sync_release_times) {
--sync_release_times;
}
lv_color_t *color_p_dac = color_p;
for(int y = area->y1; y <= area->y2; ++y) {
for(int x = area->x1; x <= area->x2; ++x) {
graph_video_set_color_8bit(x+50, y+70,
graph_video_set_color_8bit(x+50, y+80,
lv_color_to8(*color_p_dac));
++color_p_dac;
}
Expand All @@ -158,21 +157,17 @@ static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_colo
/*IMPORTANT!!!
*Inform the graphics library that you are ready with the flushing*/
lv_disp_flush_ready(disp_drv);
if(g_dac_video_render) {
//加了以后画面更稳定, 但影响UI流畅度
graph_video_sync();
}
}

void composite_monitor_cb(lv_disp_drv_t * disp_drv, uint32_t time_ms, uint32_t px_num) {
void IRAM_ATTR composite_monitor_cb(lv_disp_drv_t * disp_drv, uint32_t time_ms, uint32_t px_num) {
// 每次切换OSD显示时, 都需要强制绘制屏幕
if(refresh_times) {
lv_obj_invalidate(lv_scr_act());
--refresh_times;
}

}
void composite_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area) {
void IRAM_ATTR composite_rounder_cb(lv_disp_drv_t * disp_drv, lv_area_t * area) {
// // RBG16bit的情况下,保证每次刷新的范围都32bit对齐
// area->x1 &= ~1;
// area->x2 |= 1;
Expand Down
5 changes: 4 additions & 1 deletion Firmware/ESP32/RX5808/main/gui/lvgl_driver/lv_port_disp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/
void lv_port_disp_init(void);
void composite_switch(bool flag);
bool get_video_switch(void);
void video_composite_switch(bool flag);
void video_composite_sync_switch(bool flag);
void video_composite_sync_release(uint16_t times);
/**********************
* MACROS
**********************/
Expand Down
24 changes: 12 additions & 12 deletions Firmware/ESP32/RX5808/main/video/capi_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,34 @@ enum
};
const uint32_t* pal_palette();
const uint32_t* ntsc_palette();
void graph_video_sync() {
video_wait_frame();
}
void graph_video_start(bool ntsc) {
graph = bmp_create(XRES, YRES, 8);
bmp_clear(graph, 0);
_lines = graph->line;
if(ntsc) {
ntsc_palette();
video_init(4, EMU_SMS, palette_ram, 1);
video_init(4, EMU_RGB_8BIT, palette_ram, 1);
} else {
pal_palette();
video_init(4, EMU_SMS, palette_ram, 0);
video_init(4, EMU_RGB_8BIT, palette_ram, 0);
}
}
void graph_video_set_color(int x_pos, int y_pos, uint8_t r,uint8_t g,uint8_t b) {
graph->line[y_pos][x_pos] = (((r >> 5) & 0x4) | ((g >> 6) & 0x2) | (b >> 7)) +1;
}

void graph_video_set_color_8bit(int x_pos, int y_pos, uint8_t c) {
graph->line[y_pos][x_pos] = c;
}
void graph_video_stop() {
video_destroy();
bmp_destroy(&graph);
delete []palette_ram;
palette_ram = 0;
}
void IRAM_ATTR graph_video_sync() {
video_wait_frame();
}
void IRAM_ATTR graph_video_set_color(int x_pos, int y_pos, uint8_t r,uint8_t g,uint8_t b) {
graph->line[y_pos][x_pos] = (((r >> 5) & 0x4) | ((g >> 6) & 0x2) | (b >> 7)) +1;
}

void IRAM_ATTR graph_video_set_color_8bit(int x_pos, int y_pos, uint8_t c) {
graph->line[y_pos][x_pos] = c;
}

const uint32_t* ntsc_palette() {
if (!palette_ram) {
Expand Down
9 changes: 5 additions & 4 deletions Firmware/ESP32/RX5808/main/video/capi_video.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
void graph_video_set_color(int x, int y, uint8_t r,uint8_t g,uint8_t b);
void graph_video_set_color_8bit(int x_pos, int y_pos, uint8_t c);
#include <stdint.h>
#include "esp_attr.h"
void IRAM_ATTR graph_video_set_color(int x, int y, uint8_t r,uint8_t g,uint8_t b);
void IRAM_ATTR graph_video_set_color_8bit(int x_pos, int y_pos, uint8_t c);
void graph_video_start(bool ntsc);
void graph_video_stop();
void graph_video_sync();
void IRAM_ATTR graph_video_sync();
#ifdef __cplusplus
}
#endif
Loading

0 comments on commit 88548f8

Please sign in to comment.