App_display.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. ******************************************************************************
  3. * @file App_display.c
  4. * @brief LVGL 显示任务 (App 应用层)
  5. *
  6. * 初始化 LVGL 内核/显示驱动/触摸, 创建主界面, 并周期驱动渲染。
  7. ******************************************************************************
  8. */
  9. #include <stdio.h>
  10. #include "App_display.h"
  11. #include "FreeRTOS.h"
  12. #include "task.h"
  13. #include "lvgl.h"
  14. #include "lv_port_disp.h"
  15. #include "lv_port_indev.h"
  16. #include "Int_gt1151.h"
  17. #include "Ui.h"
  18. /* 任务参数 (数字越大优先级越高); LVGL 渲染/动画/触摸处理较重, 栈需较大 */
  19. #define TASK_LVGL_PRIORITY 3
  20. #define TASK_LVGL_STACK_SIZE 2048
  21. TaskHandle_t xLVGLDisplayTaskHandle = NULL;
  22. /**
  23. * @brief LVGL 显示任务体: 初始化渲染链并周期驱动 LVGL
  24. * @note 初始化顺序有依赖: lv_init → 显示驱动 → 触摸 → indev → 主界面;
  25. * 循环内 5ms 步进配合 LV_DISP_DEF_REFR_PERIOD(30ms) 完成刷新/动画/输入。
  26. * @param argument : 任务入参 (未使用)
  27. * @return 无 (任务不可返回)
  28. */
  29. static void Task_LVGL_Display(void *argument)
  30. {
  31. (void)argument;
  32. printf("LVGL display task running...\r\n");
  33. /* LVGL 内核初始化 */
  34. lv_init();
  35. /* 注册显示驱动:LTDC + SDRAM 静态显存 + 双全屏缓冲 */
  36. lv_port_disp_init();
  37. /* 初始化 GT1151Q 电容触摸芯片 */
  38. if (Int_gt1151_init() == 0)
  39. {
  40. printf("GT1151 Init OK\r\n");
  41. /* 注册触摸输入设备 (注意: 需在 lv_init 之后、主循环 lv_timer_handler 之前) */
  42. lv_port_indev_init();
  43. }
  44. else
  45. {
  46. printf("[ERR] GT1151 Init failed\r\n");
  47. }
  48. /* 创建工业设备主页 (UI 页面层) */
  49. Ui_init();
  50. while (1)
  51. {
  52. /* 周期驱动 LVGL(渲染/动画/输入),配合 LV_DISP_DEF_REFR_PERIOD 30ms */
  53. lv_timer_handler();
  54. vTaskDelay(pdMS_TO_TICKS(5));
  55. }
  56. }
  57. /**
  58. * @brief 创建 LVGL 显示任务
  59. * @note 在 vTaskStartScheduler() 之前调用一次; 句柄存于 xLVGLDisplayTaskHandle。
  60. * @param 无
  61. * @return 无
  62. */
  63. void App_display_task_create(void)
  64. {
  65. BaseType_t ret;
  66. ret = xTaskCreate(Task_LVGL_Display, "lvglDisplayTask", TASK_LVGL_STACK_SIZE,
  67. NULL, TASK_LVGL_PRIORITY, &xLVGLDisplayTaskHandle);
  68. if (ret != pdPASS)
  69. {
  70. printf("[ERR] LVGL display task create failed\r\n");
  71. }
  72. }