Fri, 26 Oct 2018 22:19:48 +0200
Version 0.2.6. Removed dead code in the tft component.
0 | 1 | /** |
2 | * @file tft.h | |
3 | * @brief High level TFT functions | |
4 | * @author LoBo 04/2017 | |
5 | * @see https://github.com/loboris | |
20
3fd5e0fc075f
Version 0.2.6. Removed dead code in the tft component.
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
6 | * @author M. Broek - removed unused code for this app. |
0 | 7 | */ |
8 | ||
9 | #ifndef _TFT_H_ | |
10 | #define _TFT_H_ | |
11 | ||
12 | #include <stdlib.h> | |
13 | #include "tftspi.h" | |
14 | ||
15 | typedef struct { | |
16 | uint16_t x1; | |
17 | uint16_t y1; | |
18 | uint16_t x2; | |
19 | uint16_t y2; | |
20 | } dispWin_t; | |
21 | ||
22 | typedef struct { | |
23 | uint8_t *font; | |
24 | uint8_t x_size; | |
25 | uint8_t y_size; | |
26 | uint8_t offset; | |
27 | uint16_t numchars; | |
28 | uint16_t size; | |
29 | uint8_t max_x_size; | |
30 | uint8_t bitmap; | |
31 | color_t color; | |
32 | } Font; | |
33 | ||
34 | ||
35 | //========================================================================================== | |
36 | // ==== Global variables =================================================================== | |
37 | //========================================================================================== | |
38 | extern uint8_t orientation; ///< current screen orientation | |
39 | extern uint16_t font_rotate; ///< current font font_rotate angle (0~395) | |
40 | extern uint8_t font_transparent; ///< if not 0 draw fonts transparent | |
41 | extern uint8_t font_forceFixed; ///< if not zero force drawing proportional fonts with fixed width | |
42 | extern uint8_t font_buffered_char; | |
43 | extern uint8_t font_line_space; ///< additional spacing between text lines; added to font height | |
44 | extern uint8_t text_wrap; ///< if not 0 wrap long text to the new line, else clip | |
45 | extern color_t _fg; ///< current foreground color for fonts | |
46 | extern color_t _bg; ///< current background for non transparent fonts | |
47 | extern dispWin_t dispWin; ///< display clip window | |
48 | extern float _angleOffset; ///< angle offset for arc, polygon and line by angle functions | |
49 | extern uint8_t image_debug; ///< print debug messages during image decode if set to 1 | |
50 | ||
51 | extern Font cfont; ///< Current font structure | |
52 | ||
53 | extern int TFT_X; ///< X position of the next character after TFT_print() function | |
54 | extern int TFT_Y; ///< Y position of the next character after TFT_print() function | |
55 | ||
56 | // ========================================================================================= | |
57 | ||
58 | ||
59 | // Buffer is created during jpeg decode for sending data | |
60 | // Total size of the buffer is 2 * (JPG_IMAGE_LINE_BUF_SIZE * 3) | |
61 | // The size must be multiple of 256 bytes !! | |
62 | #define JPG_IMAGE_LINE_BUF_SIZE 512 | |
63 | ||
64 | // --- Constants for ellipse function --- | |
65 | #define TFT_ELLIPSE_UPPER_RIGHT 0x01 | |
66 | #define TFT_ELLIPSE_UPPER_LEFT 0x02 | |
67 | #define TFT_ELLIPSE_LOWER_LEFT 0x04 | |
68 | #define TFT_ELLIPSE_LOWER_RIGHT 0x08 | |
69 | ||
70 | // Constants for Arc function | |
71 | // number representing the maximum angle (e.g. if 100, then if you pass in start=0 and end=50, you get a half circle) | |
72 | // this can be changed with setArcParams function at runtime | |
73 | #define DEFAULT_ARC_ANGLE_MAX 360 | |
74 | // rotational offset in degrees defining position of value 0 (-90 will put it at the top of circle) | |
75 | // this can be changed with setAngleOffset function at runtime | |
76 | #define DEFAULT_ANGLE_OFFSET -90 | |
77 | ||
78 | #define PI 3.14159265359 | |
79 | ||
80 | #define MIN_POLIGON_SIDES 3 | |
81 | #define MAX_POLIGON_SIDES 60 | |
82 | ||
83 | // === Color names constants === | |
84 | extern const color_t TFT_BLACK; | |
85 | extern const color_t TFT_NAVY; | |
86 | extern const color_t TFT_DARKGREEN; | |
87 | extern const color_t TFT_DARKCYAN; | |
88 | extern const color_t TFT_MAROON; | |
89 | extern const color_t TFT_PURPLE; | |
90 | extern const color_t TFT_OLIVE; | |
91 | extern const color_t TFT_LIGHTGREY; | |
92 | extern const color_t TFT_DARKGREY; | |
93 | extern const color_t TFT_BLUE; | |
94 | extern const color_t TFT_GREEN; | |
95 | extern const color_t TFT_CYAN; | |
96 | extern const color_t TFT_RED; | |
97 | extern const color_t TFT_MAGENTA; | |
98 | extern const color_t TFT_YELLOW; | |
99 | extern const color_t TFT_WHITE; | |
100 | extern const color_t TFT_ORANGE; | |
101 | extern const color_t TFT_GREENYELLOW; | |
102 | extern const color_t TFT_PINK; | |
103 | ||
104 | // === Color invert constants === | |
105 | #define INVERT_ON 1 | |
106 | #define INVERT_OFF 0 | |
107 | ||
108 | // === Special coordinates constants === | |
109 | #define CENTER -9003 | |
110 | #define RIGHT -9004 | |
111 | #define BOTTOM -9004 | |
112 | ||
113 | #define LASTX 7000 | |
114 | #define LASTY 8000 | |
115 | ||
116 | // === Embedded fonts constants === | |
117 | #define DEFAULT_FONT 0 ///< 12 points 95 characters DejaVu font. | |
118 | #define DEJAVU18_FONT 1 ///< 18 points 95 characters DejaVuSans font. | |
119 | #define DEJAVU24_FONT 2 ///< 24 points 95 characters DejaVu font. | |
120 | #define UBUNTU16_FONT 3 ///< 16 points 95 characters Ubuntu font. | |
121 | #define COMIC24_FONT 4 ///< 24 points 95 characters Comic font. | |
122 | #define MINYA24_FONT 5 ///< 24 points 95 characters Minya font. | |
123 | #define TOONEY32_FONT 6 ///< 32 points 95 characters Tooney font. | |
124 | #define SMALL_FONT 7 ///< 8x12 pixels 95 characters fixed font. | |
125 | #define DEF_SMALL_FONT 8 ///< 9 points 95 characters font. | |
126 | #define FONT_7SEG 9 ///< Variable size 14 characters 7 segment font. | |
127 | #define USER_FONT 10 ///< font will be read from file | |
128 | ||
129 | ||
130 | ||
131 | // ===== PUBLIC FUNCTIONS ========================================================================= | |
132 | ||
133 | ||
134 | /** | |
135 | * @brief Draw pixel at given x,y coordinates | |
136 | * @param x horizontal position | |
137 | * @param y vertical position | |
138 | * @param color pixel color | |
139 | * @param sel if not 0 activate CS before and deactivat after sending pixel data to display | |
140 | * when sending multiple pixels it is faster to activate the CS first, | |
141 | * send all pixels an deactivate CS after all pixela was sent | |
142 | */ | |
143 | void TFT_drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel); | |
144 | ||
145 | /** | |
146 | * @brief Read pixel color value from display GRAM at given x,y coordinates | |
147 | * @param[in] x horizontal position | |
148 | * @param[in] y vertical position | |
149 | */ | |
150 | color_t TFT_readPixel(int16_t x, int16_t y); | |
151 | ||
152 | /** | |
153 | * @brief Draw vertical line at given x,y coordinates | |
154 | * | |
155 | * @param x horizontal start position | |
156 | * @param y vertical start position | |
157 | * @param h line height in pixels | |
158 | * @param color line color | |
159 | */ | |
160 | void TFT_drawFastVLine(int16_t x, int16_t y, int16_t h, color_t color); | |
161 | ||
162 | /** | |
163 | * @brief Draw horizontal line at given x,y coordinates | |
164 | * | |
165 | * @param x horizontal start position | |
166 | * @param y vertical start position | |
167 | * @param w line width in pixels | |
168 | * @param color line color | |
169 | */ | |
170 | void TFT_drawFastHLine(int16_t x, int16_t y, int16_t w, color_t color); | |
171 | ||
172 | /** | |
173 | * @brief Draw line on screen | |
174 | * | |
175 | * @param x0 horizontal start position | |
176 | * @param y0 vertical start position | |
177 | * @param x1 horizontal end position | |
178 | * @param y1 vertical end position | |
179 | * @param color line color | |
180 | */ | |
181 | void TFT_drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color); | |
182 | ||
183 | /** | |
184 | * @brief Fill given rectangular screen region with color | |
185 | * | |
186 | * @param x horizontal rect start position | |
187 | * @param y vertical rect start position | |
188 | * @param w rectangle width | |
189 | * @param h rectangle height | |
190 | * @param color fill color | |
191 | */ | |
192 | void TFT_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, color_t color); | |
193 | ||
194 | /** | |
195 | * @brief Draw rectangle on screen | |
196 | * | |
197 | * @param x horizontal rect start position | |
198 | * @param y vertical rect start position | |
199 | * @param w rectangle width | |
200 | * @param h rectangle height | |
201 | * @param color rect line color | |
202 | */ | |
203 | void TFT_drawRect(uint16_t x1,uint16_t y1,uint16_t w,uint16_t h, color_t color); | |
204 | ||
205 | /** | |
206 | * @brief Draw rectangle with rounded corners on screen | |
207 | * | |
208 | * @param x horizontal rect start position | |
209 | * @param y vertical rect start position | |
210 | * @param w rectangle width | |
211 | * @param h rectangle height | |
212 | * @param r corner radius | |
213 | * @param color rectangle color | |
214 | */ | |
215 | void TFT_drawRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color); | |
216 | ||
217 | /** | |
218 | * @brief Fill given rectangular screen region with rounded corners with color | |
219 | * | |
220 | * @param x horizontal rect start position | |
221 | * @param y vertical rect start position | |
222 | * @param w rectangle width | |
223 | * @param h rectangle height | |
224 | * @param r corner radius | |
225 | * @param color fill color | |
226 | */ | |
227 | void TFT_fillRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color); | |
228 | ||
229 | /** | |
230 | * @brief Fill the whole screen with color | |
231 | * | |
232 | * @param color fill color | |
233 | */ | |
234 | void TFT_fillScreen(color_t color); | |
235 | ||
236 | /** | |
237 | * @brief Fill the current clip window with color | |
238 | * | |
239 | * @param color fill color | |
240 | */ | |
241 | void TFT_fillWindow(color_t color); | |
242 | ||
243 | /** | |
244 | * @brief Draw circle on screen | |
245 | * | |
246 | * @param x circle center x position | |
247 | * @param y circle center x position | |
248 | * @param r circle radius | |
249 | * @param color circle color | |
250 | */ | |
251 | void TFT_drawCircle(int16_t x, int16_t y, int radius, color_t color); | |
252 | ||
253 | /** | |
254 | * @brief Fill circle on screen with color | |
255 | * | |
256 | * @param x circle center x position | |
257 | * @param y circle center x position | |
258 | * @param r circle radius | |
259 | * @param color circle fill color | |
260 | */ | |
261 | void TFT_fillCircle(int16_t x, int16_t y, int radius, color_t color); | |
262 | ||
263 | /** | |
264 | * @brief Set the font used for writing the text to display. | |
265 | * | |
266 | * ------------------------------------------------------------------------------------ | |
267 | * For 7 segment font only characters 0,1,2,3,4,5,6,7,8,9, . , - , : , / are available. | |
268 | * Character ‘/‘ draws the degree sign. | |
269 | * ------------------------------------------------------------------------------------ | |
270 | * | |
271 | * @param font font number; use defined font names | |
272 | * @param font_file pointer to font file name; NULL for embeded fonts | |
273 | */ | |
274 | void TFT_setFont(uint8_t font, const char *font_file); | |
275 | ||
276 | /** | |
277 | * @brief Returns current font height & width in pixels. | |
278 | * | |
279 | * @param[in] width pointer to returned font width | |
280 | * @param[in] height pointer to returned font height | |
281 | */ | |
282 | int TFT_getfontsize(int *width, int* height); | |
283 | ||
284 | /** | |
285 | * @brief Returns current font height in pixels. | |
286 | * @return The font height in pixels. | |
287 | */ | |
288 | int TFT_getfontheight(); | |
289 | ||
290 | /** | |
291 | * @brief Write text to display. | |
292 | * | |
293 | * Rotation of the displayed text depends on 'font_rotate' variable (0~360) | |
294 | * if 'font_transparent' variable is set to 1, no background pixels will be printed | |
295 | * | |
296 | * If the text does not fit the screen width it will be clipped (if text_wrap=0), | |
297 | * or continued on next line (if text_wrap=1) | |
298 | * | |
299 | * Two special characters are allowed in strings: | |
300 | * | |
301 | * ‘\r’ CR (0x0D), clears the display to EOL | |
302 | * ‘\n’ LF (ox0A), continues to the new line, x=0 | |
303 | * | |
304 | * @param st pointer to null terminated string to be printed | |
305 | * @param x horizontal position of the upper left point in pixels. Special values can be entered: | |
306 | * | |
307 | * CENTER, centers the text | |
308 | * RIGHT, right justifies the text | |
309 | * LASTX, continues from last X position; offset can be used: LASTX+n | |
310 | * | |
311 | * @param y vertical position of the upper left point in pixels. Special values can be entered: | |
312 | * | |
313 | * CENTER, centers the text | |
314 | * BOTTOM, bottom justifies the text | |
315 | * LASTY, continues from last Y position; offset can be used: LASTY+n | |
316 | * | |
317 | */ | |
318 | void TFT_print(char *st, int x, int y); | |
319 | ||
320 | /** | |
321 | * @brief Set atributes for 7 segment vector font | |
322 | * @note 7 segment font must be the current font to this function to have effect | |
323 | * | |
324 | * @param l 6~40; distance between bars in pixels | |
325 | * @param w 1~12, max l/2; bar width in pixels | |
326 | * @param outline draw font outline if set to 1 | |
327 | * @param color font outline color, only used if outline=1 | |
328 | */ | |
329 | void set_7seg_font_atrib(uint8_t l, uint8_t w, int outline, color_t color); | |
330 | ||
331 | /** | |
332 | * @brief Sets the clipping area coordinates. | |
333 | * All writing to screen is clipped to that area. | |
334 | * Starting x & y in all functions will be adjusted to the clipping area. | |
335 | * | |
336 | * @param x1,y1 upper left point of the clipping area | |
337 | * @param x2,y2 bottom right point of the clipping area | |
338 | */ | |
339 | void TFT_setclipwin(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2); | |
340 | ||
341 | /** | |
342 | * @brief Resets the clipping area to full screen (0,0),(_wodth,_height) | |
343 | */ | |
344 | void TFT_resetclipwin(); | |
345 | ||
346 | /** | |
347 | * @brief Save current clipping area to temporary variable | |
348 | */ | |
349 | void TFT_saveClipWin(); | |
350 | ||
351 | /** | |
352 | * @brief Restore current clipping area from temporary variable | |
353 | */ | |
354 | void TFT_restoreClipWin(); | |
355 | ||
356 | /** | |
357 | * @brief Set the screen rotation | |
358 | * Also resets the clip window and clears the screen with current background color | |
359 | * | |
360 | * @param rot 0~3; screen rotation; use defined rotation constants: | |
361 | * PORTRAIT, LANDSCAPE, PORTRAIT_FLIP, LANDSCAPE_FLIP | |
362 | */ | |
363 | void TFT_setRotation(uint8_t rot); | |
364 | ||
365 | /** | |
366 | * @brief Select gamma curve | |
367 | * @param gm gama curve, values 0~3 | |
368 | */ | |
369 | void TFT_setGammaCurve(uint8_t gm); | |
370 | ||
371 | /** | |
372 | * @brief returns the string width in pixels. Useful for positions strings on the screen. | |
373 | * @return The string width. | |
374 | */ | |
375 | int TFT_getStringWidth(char* str); | |
376 | ||
377 | ||
378 | /** | |
379 | * @brief Fills the rectangle occupied by string with current background color | |
380 | * @param x X position | |
381 | * @param Y Y position | |
382 | * @param str The string | |
383 | */ | |
384 | void TFT_clearStringRect(int x, int y, char *str); | |
385 | ||
386 | /** | |
387 | * @brief Get the touch panel coordinates. | |
388 | * The coordinates are adjusted to screen orientation if raw=0 | |
389 | * | |
390 | * @param[in] x pointer to X coordinate | |
391 | * @param[in] y pointer to Y coordinate | |
392 | * @param raw if 0 returns calibrated screen coordinates; if 1 returns raw touch controller coordinates | |
393 | * @return 0 if touch panel is not touched; x=y=0 | |
394 | * 1 if touch panel is touched; x&y are the valid coordinates | |
395 | */ | |
396 | int TFT_read_touch(int *x, int* y, uint8_t raw); | |
397 | ||
398 | #endif |