aboutsummaryrefslogtreecommitdiff
path: root/Marlin/src/lcd/tft/tft_queue.h
blob: 7eaa0c01c1a2e579ce4b9d48aa484eb3f2771e70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
 * Marlin 3D Printer Firmware
 * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
 *
 * Based on Sprinter and grbl.
 * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */
#pragma once

#include "../../inc/MarlinConfig.h"
#include "tft_string.h"
#include "tft_image.h"

#ifndef TFT_QUEUE_SIZE
  #define TFT_QUEUE_SIZE              8192
#endif

enum QueueTaskType : uint8_t {
  TASK_END_OF_QUEUE = 0x00,
  TASK_FILL,
  TASK_CANVAS,
};

enum QueueTaskState : uint8_t {
  TASK_STATE_READY = 0x00,
  TASK_STATE_IN_PROGRESS,
  TASK_STATE_COMPLETED,
  TASK_STATE_SKETCH = 0xFF,
};

enum CanvasSubtype : uint8_t {
  CANVAS_SET_BACKGROUND = 0x00,
  CANVAS_ADD_TEXT,
  CANVAS_ADD_IMAGE,
  CANVAS_ADD_BAR,
  CANVAS_ADD_RECTANGLE,
};

typedef struct __attribute__((__packed__)) {
  QueueTaskType type;
  QueueTaskState state;
  uint8_t *nextTask;
} queueTask_t;

typedef struct __attribute__((__packed__)) {
  uint16_t x;
  uint16_t y;
  uint16_t width;
  uint16_t height;
  uint16_t color;
  uint32_t count;
} parametersFill_t;

typedef struct __attribute__((__packed__)) {
  uint16_t x;
  uint16_t y;
  uint16_t width;
  uint16_t height;
  uint32_t count;
} parametersCanvas_t;

typedef struct __attribute__((__packed__)) {
  CanvasSubtype type;
  uint8_t *nextParameter;
  uint16_t color;
} parametersCanvasBackground_t;

typedef struct __attribute__((__packed__)) {
  CanvasSubtype type;
  uint8_t *nextParameter;
  uint16_t x;
  uint16_t y;
  uint16_t color;
  uint32_t count;
  uint16_t maxWidth;
  uint16_t stringLength;
} parametersCanvasText_t;

typedef struct __attribute__((__packed__)) {
  CanvasSubtype type;
  uint8_t *nextParameter;
  int16_t x;
  int16_t y;
  MarlinImage image;
} parametersCanvasImage_t;

typedef struct __attribute__((__packed__)) {
  CanvasSubtype type;
  uint8_t *nextParameter;
  uint16_t x;
  uint16_t y;
  uint16_t width;
  uint16_t height;
  uint16_t color;
} parametersCanvasBar_t;

typedef struct __attribute__((__packed__)) {
  CanvasSubtype type;
  uint8_t *nextParameter;
  uint16_t x;
  uint16_t y;
  uint16_t width;
  uint16_t height;
  uint16_t color;
} parametersCanvasRectangle_t;

class TFT_Queue {
  private:
    static uint8_t queue[TFT_QUEUE_SIZE];
    static uint8_t *end_of_queue;
    static uint8_t *current_task;
    static uint8_t *last_task;
    static uint8_t *last_parameter;

    static void finish_sketch();
    static void fill(queueTask_t *task);
    static void canvas(queueTask_t *task);
    static void handle_queue_overflow(uint16_t sizeNeeded);

  public:
    static void reset();
    static void async();
    static void sync() { while (current_task != NULL) async(); }

    static void fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
    static void canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
    static void set_background(uint16_t color);
    static void add_text(uint16_t x, uint16_t y, uint16_t color, uint8_t *string, uint16_t maxWidth);

    static void add_image(int16_t x, int16_t y, MarlinImage image, uint16_t *colors);
    static void add_image(int16_t x, int16_t y, MarlinImage image, uint16_t color_main, uint16_t color_background, uint16_t color_shadow);

    static void add_bar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
    static void add_rectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
};