13 #include "freertos/task.h" |
13 #include "freertos/task.h" |
14 #include "esp_system.h" |
14 #include "esp_system.h" |
15 #include "tft.h" |
15 #include "tft.h" |
16 #include "time.h" |
16 #include "time.h" |
17 #include <math.h> |
17 #include <math.h> |
18 #include "rom/tjpgd.h" |
18 #include "esp32/rom/tjpgd.h" |
19 #include "esp_heap_caps.h" |
19 #include "esp_heap_caps.h" |
20 #include "tftspi.h" |
20 #include "tftspi.h" |
21 |
|
22 #include "vnc-server.h" |
|
23 |
21 |
24 #define DEG_TO_RAD 0.01745329252 |
22 #define DEG_TO_RAD 0.01745329252 |
25 #define RAD_TO_DEG 57.295779513 |
23 #define RAD_TO_DEG 57.295779513 |
26 #define deg_to_rad 0.01745329252 + 3.14159265359 |
24 #define deg_to_rad 0.01745329252 + 3.14159265359 |
27 #define swap(a, b) { int16_t t = a; a = b; b = t; } |
25 #define swap(a, b) { int16_t t = a; a = b; b = t; } |
137 //------------------------------------------------------------------------ |
135 //------------------------------------------------------------------------ |
138 static void _drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel) { |
136 static void _drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel) { |
139 |
137 |
140 if ((x < dispWin.x1) || (y < dispWin.y1) || (x > dispWin.x2) || (y > dispWin.y2)) return; |
138 if ((x < dispWin.x1) || (y < dispWin.y1) || (x > dispWin.x2) || (y > dispWin.y2)) return; |
141 drawPixel(x, y, color, sel); |
139 drawPixel(x, y, color, sel); |
142 VncDrawPixel(x, y, VNC_RGB2COL(color.r, color.g, color.b)); |
|
143 } |
140 } |
144 |
141 |
145 //==================================================================== |
142 //==================================================================== |
146 void TFT_drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel) { |
143 void TFT_drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel) { |
147 |
144 |
166 } |
163 } |
167 if (h < 0) h = 0; |
164 if (h < 0) h = 0; |
168 if ((y + h) > (dispWin.y2+1)) h = dispWin.y2 - y + 1; |
165 if ((y + h) > (dispWin.y2+1)) h = dispWin.y2 - y + 1; |
169 if (h == 0) h = 1; |
166 if (h == 0) h = 1; |
170 TFT_pushColorRep(x, y, x, y+h-1, color, (uint32_t)h); |
167 TFT_pushColorRep(x, y, x, y+h-1, color, (uint32_t)h); |
171 VncDrawVertLine(x, y, y+h-1, VNC_RGB2COL(color.r, color.g, color.b)); |
|
172 } |
168 } |
173 |
169 |
174 //-------------------------------------------------------------------------- |
170 //-------------------------------------------------------------------------- |
175 static void _drawFastHLine(int16_t x, int16_t y, int16_t w, color_t color) { |
171 static void _drawFastHLine(int16_t x, int16_t y, int16_t w, color_t color) { |
176 // clipping |
172 // clipping |
182 if (w < 0) w = 0; |
178 if (w < 0) w = 0; |
183 if ((x + w) > (dispWin.x2+1)) w = dispWin.x2 - x + 1; |
179 if ((x + w) > (dispWin.x2+1)) w = dispWin.x2 - x + 1; |
184 if (w == 0) w = 1; |
180 if (w == 0) w = 1; |
185 |
181 |
186 TFT_pushColorRep(x, y, x+w-1, y, color, (uint32_t)w); |
182 TFT_pushColorRep(x, y, x+w-1, y, color, (uint32_t)w); |
187 VncDrawHorzLine(x, x+w-1, y, VNC_RGB2COL(color.r, color.g, color.b)); |
|
188 } |
183 } |
189 |
184 |
190 //====================================================================== |
185 //====================================================================== |
191 void TFT_drawFastVLine(int16_t x, int16_t y, int16_t h, color_t color) { |
186 void TFT_drawFastVLine(int16_t x, int16_t y, int16_t h, color_t color) { |
192 _drawFastVLine(x+dispWin.x1, y+dispWin.y1, h, color); |
187 _drawFastVLine(x+dispWin.x1, y+dispWin.y1, h, color); |
285 if ((x + w) > (dispWin.x2+1)) w = dispWin.x2 - x + 1; |
280 if ((x + w) > (dispWin.x2+1)) w = dispWin.x2 - x + 1; |
286 if ((y + h) > (dispWin.y2+1)) h = dispWin.y2 - y + 1; |
281 if ((y + h) > (dispWin.y2+1)) h = dispWin.y2 - y + 1; |
287 if (w == 0) w = 1; |
282 if (w == 0) w = 1; |
288 if (h == 0) h = 1; |
283 if (h == 0) h = 1; |
289 TFT_pushColorRep(x, y, x+w-1, y+h-1, color, (uint32_t)(h*w)); |
284 TFT_pushColorRep(x, y, x+w-1, y+h-1, color, (uint32_t)(h*w)); |
290 VncFillRect(x, y, x+w-1, y+h-1, VNC_RGB2COL(color.r, color.g, color.b)); |
|
291 } |
285 } |
292 |
286 |
293 //============================================================================ |
287 //============================================================================ |
294 void TFT_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, color_t color) { |
288 void TFT_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, color_t color) { |
295 _fillRect(x+dispWin.x1, y+dispWin.y1, w, h, color); |
289 _fillRect(x+dispWin.x1, y+dispWin.y1, w, h, color); |
296 } |
290 } |
297 |
291 |
298 //================================== |
292 //================================== |
299 void TFT_fillScreen(color_t color) { |
293 void TFT_fillScreen(color_t color) { |
300 TFT_pushColorRep(0, 0, _width-1, _height-1, color, (uint32_t)(_height*_width)); |
294 TFT_pushColorRep(0, 0, _width-1, _height-1, color, (uint32_t)(_height*_width)); |
301 VncCls(VNC_RGB2COL(color.r, color.g, color.b)); |
|
302 } |
295 } |
303 |
296 |
304 //================================== |
297 //================================== |
305 void TFT_fillWindow(color_t color) { |
298 void TFT_fillWindow(color_t color) { |
306 TFT_pushColorRep(dispWin.x1, dispWin.y1, dispWin.x2, dispWin.y2, |
299 TFT_pushColorRep(dispWin.x1, dispWin.y1, dispWin.x2, dispWin.y2, |
307 color, (uint32_t)((dispWin.x2-dispWin.x1+1) * (dispWin.y2-dispWin.y1+1))); |
300 color, (uint32_t)((dispWin.x2-dispWin.x1+1) * (dispWin.y2-dispWin.y1+1))); |
308 VncFillRect(dispWin.x1, dispWin.y1, dispWin.x2, dispWin.y2, VNC_RGB2COL(color.r, color.g, color.b)); |
|
309 } |
301 } |
310 |
302 |
311 // ^^^============= Basics drawing functions ================================^^^ |
303 // ^^^============= Basics drawing functions ================================^^^ |
312 |
304 |
313 |
305 |
891 } |
883 } |
892 if ((ch & mask) != 0) { |
884 if ((ch & mask) != 0) { |
893 // visible pixel |
885 // visible pixel |
894 bufPos = ((j + fontChar.adjYOffset) * char_width) + (fontChar.xOffset + i); // bufY + bufX |
886 bufPos = ((j + fontChar.adjYOffset) * char_width) + (fontChar.xOffset + i); // bufY + bufX |
895 color_line[bufPos] = _fg; |
887 color_line[bufPos] = _fg; |
896 VncDrawPixel(x + (fontChar.xOffset + i), y + (j + fontChar.adjYOffset), VNC_RGB2COL(_fg.r, _fg.g, _fg.b)); |
|
897 } else { |
|
898 VncDrawPixel(x + (fontChar.xOffset + i), y + (j + fontChar.adjYOffset), VNC_RGB2COL(_bg.r, _bg.g, _bg.b)); |
|
899 } |
888 } |
900 mask >>= 1; |
889 mask >>= 1; |
901 } |
890 } |
902 } |
891 } |
903 // send to display in one transaction |
892 // send to display in one transaction |
969 ch = cfont.font[temp + k]; |
958 ch = cfont.font[temp + k]; |
970 mask = 0x80; |
959 mask = 0x80; |
971 for (i = 0; i < 8; i++) { |
960 for (i = 0; i < 8; i++) { |
972 if ((ch & mask) !=0) { |
961 if ((ch & mask) !=0) { |
973 color_line[(j*cfont.x_size) + (i+(k*8))] = _fg; |
962 color_line[(j*cfont.x_size) + (i+(k*8))] = _fg; |
974 VncDrawPixel(x+i+(k*8), y+j, VNC_RGB2COL(_fg.r, _fg.g, _fg.b)); |
|
975 } else { |
|
976 VncDrawPixel(x+i+(k*8), y+j, VNC_RGB2COL(_bg.r, _bg.g, _bg.b)); |
|
977 } |
963 } |
978 mask >>= 1; |
964 mask >>= 1; |
979 } |
965 } |
980 } |
966 } |
981 temp += (fz); |
967 temp += (fz); |