lvgl移植完毕,加入dma及双缓冲刷新

This commit is contained in:
shentou 2025-12-20 16:09:44 +08:00
parent a708f48a59
commit 2ebe359343
6 changed files with 56 additions and 33 deletions

View File

@ -18,12 +18,12 @@
*********************/
#ifndef MY_DISP_HOR_RES
#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen width, default value 320 is used for now.
#define MY_DISP_HOR_RES 320
#define MY_DISP_HOR_RES 240
#endif
#ifndef MY_DISP_VER_RES
#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen height, default value 240 is used for now.
#define MY_DISP_VER_RES 240
#define MY_DISP_VER_RES 320
#endif
@ -117,7 +117,7 @@ void lv_port_disp_init(void)
static lv_disp_draw_buf_t draw_buf_dsc_2;
static lv_color_t buf_2_1[MY_DISP_HOR_RES * 20]; /*A buffer for 10 rows*/
static lv_color_t buf_2_2[MY_DISP_HOR_RES * 20]; /*An other buffer for 10 rows*/
lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 40); /*Initialize the display buffer*/
lv_disp_draw_buf_init(&draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 20); /*Initialize the display buffer*/
// /* Example for 3) also set disp_drv.full_refresh = 1 below*/
// static lv_disp_draw_buf_t draw_buf_dsc_3;

View File

@ -1,6 +1,7 @@
- delay: 0
description: ''
freq_control: false
function: Task_lvgl
name: lvgl
freq_control: true
frequency: 1000.0
function: Task_display
name: display
stack: 1024

View File

@ -1,5 +1,5 @@
/*
lvgl Task
display Task
*/
@ -17,33 +17,55 @@
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* USER STRUCT BEGIN */
void lv_ex_label(void)
{
char* github_addr = "hahahahahahahahah";
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_label_set_recolor(label, true);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); /*Circular scroll*/
lv_obj_set_width(label, 120);
lv_label_set_text_fmt(label, "#ff0000 hahahahahahahahaha %s#", github_addr);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 10);
lv_obj_t * label2 = lv_label_create(lv_scr_act());
lv_label_set_recolor(label2, true);
lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); /*Circular scroll*/
lv_obj_set_width(label2, 120);
lv_label_set_text_fmt(label2, "#ff0000 hahahahahahaha# #0000ff hahahahahahaha#");
lv_obj_align(label2, LV_ALIGN_CENTER, 0, -10);
}
/* USER STRUCT END */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */
void Task_lvgl(void *argument) {
void Task_display(void *argument) {
(void)argument; /* 未使用argument消除警告 */
/* 计算任务运行到指定频率需要等待的tick数 */
const uint32_t delay_tick = osKernelGetTickFreq() / DISPLAY_FREQ;
osDelay(DISPLAY_INIT_DELAY); /* 延时一段时间再开启任务 */
uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */
/* USER CODE INIT BEGIN */
lcd_init();
lv_init();
lv_port_disp_init();
lv_demo_stress();
// osDelay(LVGL_INIT_DELAY); /* 延时一段时间再开启任务 */
/* USER CODE INIT BEGIN */
lv_ex_label();
// lv_demo_stress();
/* USER CODE INIT END */
while (1) {
tick += delay_tick; /* 计算下一个唤醒时刻 */
/* USER CODE BEGIN */
// lcd_fill(100, 100,200,200,RED);
lv_task_handler();
// lv_timer_handler();
/* USER CODE BEGIN */
lv_tick_inc(1);
/* USER CODE END */
osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */
}
}

View File

@ -30,7 +30,7 @@ void Task_Init(void *argument) {
osKernelLock(); /* 锁定内核,防止任务切换 */
/* 创建任务线程 */
task_runtime.thread.lvgl = osThreadNew(Task_lvgl, NULL, &attr_lvgl);
task_runtime.thread.display = osThreadNew(Task_display, NULL, &attr_display);
// 创建消息队列
/* USER MESSAGE BEGIN */

View File

@ -9,8 +9,8 @@ const osThreadAttr_t attr_init = {
};
/* User_task */
const osThreadAttr_t attr_lvgl = {
.name = "lvgl",
const osThreadAttr_t attr_display = {
.name = "display",
.priority = osPriorityNormal,
.stack_size = 1024 * 8,
.stack_size = 1024 * 4,
};

View File

@ -13,11 +13,11 @@ extern "C" {
/* USER INCLUDE END */
/* Exported constants ------------------------------------------------------- */
/* 任务运行频率 */
#define DISPLAY_FREQ (1000.0)
/* 任务初始化延时ms */
#define TASK_INIT_DELAY (100u)
#define LVGL_INIT_DELAY (0)
#define DISPLAY_INIT_DELAY (0)
/* Exported defines --------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
@ -27,7 +27,7 @@ extern "C" {
typedef struct {
/* 各任务,也可以叫做线程 */
struct {
osThreadId_t lvgl;
osThreadId_t display;
} thread;
/* USER MESSAGE BEGIN */
@ -49,17 +49,17 @@ typedef struct {
/* 各任务的stack使用 */
struct {
UBaseType_t lvgl;
UBaseType_t display;
} stack_water_mark;
/* 各任务运行频率 */
struct {
float display;
} freq;
/* 任务最近运行时间 */
struct {
float display;
} last_up_time;
} Task_Runtime_t;
@ -69,11 +69,11 @@ extern Task_Runtime_t task_runtime;
/* 初始化任务句柄 */
extern const osThreadAttr_t attr_init;
extern const osThreadAttr_t attr_lvgl;
extern const osThreadAttr_t attr_display;
/* 任务函数声明 */
void Task_Init(void *argument);
void Task_lvgl(void *argument);
void Task_display(void *argument);
#ifdef __cplusplus
}