App_freertosTask.c 2.8 KB

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