App_freertosTask.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include "App_freertosTask.h"
  2. #include <stdio.h>
  3. #include "lvgl.h"
  4. #include "lv_port_disp.h"
  5. #include "lv_port_indev.h"
  6. #include "Int_gt1151.h"
  7. #include "Ui.h"
  8. #define TASK_CPLD_PRIORITY 4
  9. #define TASK_CPLD_STACK_SIZE 512
  10. #define TASK_LVGL_PRIORITY 3
  11. #define TASK_LVGL_STACK_SIZE 2048
  12. #define TASK_TEST_PRIORITY 1
  13. #define TASK_TEST_STACK_SIZE 512
  14. TaskHandle_t xCPLDProcessTaskHandle = NULL;
  15. TaskHandle_t xLVGLDisplayTaskHandle = NULL;
  16. TaskHandle_t xTestTaskHandle = NULL;
  17. /**
  18. * @brief 创建各个任务
  19. *
  20. */
  21. void App_Task_Create(void)
  22. {
  23. BaseType_t ret;
  24. ret = xTaskCreate(Task_CPLD_Process, "cpldProcessTask", TASK_CPLD_STACK_SIZE, NULL, TASK_CPLD_PRIORITY, &xCPLDProcessTaskHandle);
  25. if (ret != pdPASS)
  26. {
  27. printf("[ERR] CPLD process task create failed\r\n");
  28. }
  29. ret = xTaskCreate(Task_LVGL_Display, "lvglDisplayTask", TASK_LVGL_STACK_SIZE, NULL, TASK_LVGL_PRIORITY, &xLVGLDisplayTaskHandle);
  30. if (ret != pdPASS)
  31. {
  32. printf("[ERR] LVGL display task create failed\r\n");
  33. }
  34. ret = xTaskCreate(Task_Test, "testTask", TASK_TEST_STACK_SIZE, NULL, TASK_TEST_PRIORITY, &xTestTaskHandle);
  35. if (ret != pdPASS)
  36. {
  37. printf("[ERR] Test task create failed\r\n");
  38. }
  39. }
  40. /**
  41. * @brief 处理 CPLD 通信的任务
  42. *
  43. * @param argument
  44. */
  45. void Task_CPLD_Process(void *argument)
  46. {
  47. (void)argument;
  48. printf("CPLD process task running...\r\n");
  49. while (1)
  50. {
  51. /* TODO: CPLD 通信处理 */
  52. vTaskDelay(pdMS_TO_TICKS(1000));
  53. }
  54. }
  55. /**
  56. * @brief 处理 LVGL 显示的任务
  57. *
  58. * @param argument
  59. */
  60. void Task_LVGL_Display(void *argument)
  61. {
  62. (void)argument;
  63. printf("LVGL display task running...\r\n");
  64. /* LVGL 内核初始化 */
  65. lv_init();
  66. /* 注册显示驱动:LTDC + SDRAM 静态显存 + 双全屏缓冲 */
  67. lv_port_disp_init();
  68. /* 初始化 GT1151Q 电容触摸芯片 */
  69. if (Int_gt1151_init() == 0)
  70. {
  71. printf("GT1151 Init OK\r\n");
  72. /* 注册触摸输入设备 (注意: 需在 lv_init 之后、主循环 lv_timer_handler 之前) */
  73. lv_port_indev_init();
  74. }
  75. else
  76. {
  77. printf("[ERR] GT1151 Init failed\r\n");
  78. }
  79. /* 创建工业设备主页 (UI 页面层) */
  80. Ui_init();
  81. /* 假数据: 设备就绪 */
  82. Ui_set_ready(true);
  83. while (1)
  84. {
  85. /* 周期驱动 LVGL(渲染/动画/输入),配合 LV_DISP_DEF_REFR_PERIOD 30ms */
  86. lv_timer_handler();
  87. vTaskDelay(pdMS_TO_TICKS(5));
  88. }
  89. }
  90. /**
  91. * @brief 处理测试的任务
  92. *
  93. * @param argument
  94. */
  95. void Task_Test(void *argument)
  96. {
  97. (void)argument;
  98. printf("Test task running...\r\n");
  99. while (1)
  100. {
  101. /* TODO: 测试 */
  102. vTaskDelay(pdMS_TO_TICKS(5000));
  103. }
  104. }