My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tft_queue.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../../inc/MarlinConfig.h"
  24. #include "tft_string.h"
  25. #include "tft_image.h"
  26. #ifndef TFT_QUEUE_SIZE
  27. #define TFT_QUEUE_SIZE 8192
  28. #endif
  29. enum QueueTaskType : uint8_t {
  30. TASK_END_OF_QUEUE = 0x00,
  31. TASK_FILL,
  32. TASK_CANVAS,
  33. };
  34. enum QueueTaskState : uint8_t {
  35. TASK_STATE_READY = 0x00,
  36. TASK_STATE_IN_PROGRESS,
  37. TASK_STATE_COMPLETED,
  38. TASK_STATE_SKETCH = 0xFF,
  39. };
  40. enum CanvasSubtype : uint8_t {
  41. CANVAS_SET_BACKGROUND = 0x00,
  42. CANVAS_ADD_TEXT,
  43. CANVAS_ADD_IMAGE,
  44. CANVAS_ADD_BAR,
  45. CANVAS_ADD_RECTANGLE,
  46. };
  47. typedef struct __attribute__((__packed__)) {
  48. QueueTaskType type;
  49. QueueTaskState state;
  50. uint8_t *nextTask;
  51. } queueTask_t;
  52. typedef struct __attribute__((__packed__)) {
  53. uint16_t x;
  54. uint16_t y;
  55. uint16_t width;
  56. uint16_t height;
  57. uint16_t color;
  58. uint32_t count;
  59. } parametersFill_t;
  60. typedef struct __attribute__((__packed__)) {
  61. uint16_t x;
  62. uint16_t y;
  63. uint16_t width;
  64. uint16_t height;
  65. uint32_t count;
  66. } parametersCanvas_t;
  67. typedef struct __attribute__((__packed__)) {
  68. CanvasSubtype type;
  69. uint8_t *nextParameter;
  70. uint16_t color;
  71. } parametersCanvasBackground_t;
  72. typedef struct __attribute__((__packed__)) {
  73. CanvasSubtype type;
  74. uint8_t *nextParameter;
  75. uint16_t x;
  76. uint16_t y;
  77. uint16_t color;
  78. uint32_t count;
  79. uint16_t maxWidth;
  80. uint16_t stringLength;
  81. } parametersCanvasText_t;
  82. typedef struct __attribute__((__packed__)) {
  83. CanvasSubtype type;
  84. uint8_t *nextParameter;
  85. int16_t x;
  86. int16_t y;
  87. MarlinImage image;
  88. } parametersCanvasImage_t;
  89. typedef struct __attribute__((__packed__)) {
  90. CanvasSubtype type;
  91. uint8_t *nextParameter;
  92. uint16_t x;
  93. uint16_t y;
  94. uint16_t width;
  95. uint16_t height;
  96. uint16_t color;
  97. } parametersCanvasBar_t;
  98. typedef struct __attribute__((__packed__)) {
  99. CanvasSubtype type;
  100. uint8_t *nextParameter;
  101. uint16_t x;
  102. uint16_t y;
  103. uint16_t width;
  104. uint16_t height;
  105. uint16_t color;
  106. } parametersCanvasRectangle_t;
  107. class TFT_Queue {
  108. private:
  109. static uint8_t queue[TFT_QUEUE_SIZE];
  110. static uint8_t *end_of_queue;
  111. static uint8_t *current_task;
  112. static uint8_t *last_task;
  113. static uint8_t *last_parameter;
  114. static void finish_sketch();
  115. static void fill(queueTask_t *task);
  116. static void canvas(queueTask_t *task);
  117. static void handle_queue_overflow(uint16_t sizeNeeded);
  118. public:
  119. static void reset();
  120. static void async();
  121. static void sync() { while (current_task != nullptr) async(); }
  122. static void fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
  123. static void canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
  124. static void set_background(uint16_t color);
  125. static void add_text(uint16_t x, uint16_t y, uint16_t color, const uint8_t *string, uint16_t maxWidth);
  126. static void add_text(uint16_t x, uint16_t y, uint16_t color, const char *string, uint16_t maxWidth) {
  127. add_text(x, y, color, (uint8_t *)string, maxWidth);
  128. }
  129. static void add_image(int16_t x, int16_t y, MarlinImage image, uint16_t *colors);
  130. static void add_image(int16_t x, int16_t y, MarlinImage image, uint16_t color_main, uint16_t color_background, uint16_t color_shadow);
  131. static void add_bar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
  132. static void add_rectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
  133. };