App_freertosTask.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. #include "Com_usart3.h"
  10. #define TASK_CPLD_PRIORITY 4
  11. #define TASK_CPLD_STACK_SIZE 512
  12. #define TASK_LVGL_PRIORITY 3
  13. #define TASK_LVGL_STACK_SIZE 2048
  14. #define TASK_TEST_PRIORITY 1
  15. #define TASK_TEST_STACK_SIZE 512
  16. TaskHandle_t xCPLDProcessTaskHandle = NULL;
  17. TaskHandle_t xLVGLDisplayTaskHandle = NULL;
  18. TaskHandle_t xTestTaskHandle = NULL;
  19. /**
  20. * @brief 创建各个任务
  21. *
  22. */
  23. void App_Task_Create(void)
  24. {
  25. BaseType_t ret;
  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. static const uint8_t tx_frame[] = "USART3 Test Frame ABC 123\r\n";
  102. while (1)
  103. {
  104. uint32_t sent = Com_usart3_send(tx_frame, sizeof(tx_frame) - 1);
  105. printf("[USART3 TX] sent=%lu\r\n", (unsigned long)sent);
  106. while (Com_usart3_available() > 0)
  107. {
  108. uint8_t b;
  109. Com_usart3_read(&b, 1);
  110. printf("%c", b);
  111. }
  112. vTaskDelay(pdMS_TO_TICKS(5000));
  113. }
  114. }