comparison Discovery/Src/gfx_engine.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children e97deb6e2705
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 /**
2 ******************************************************************************
3 * @file gfx_engine.c
4 * @author heinrichs weikamp gmbh
5 * @version V0.0.2
6 * @date 30-April-2014
7 * @brief Main source file of GFX Graphic Engine
8 * This file provides firmware functions to manage the following
9 * functions to draw on the screen:
10 * + write string to display
11 *
12 ******************************************************************************
13 * @attention
14 *
15 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
16 *
17 ******************************************************************************
18 */
19
20 /* Includes ------------------------------------------------------------------*/
21
22 #include <stdlib.h>
23 #include <stdint.h>
24
25 #include "stm32f4xx_hal.h"
26
27 #include "gfx.h"
28 #include "gfx_engine.h"
29 #include "gfx_fonts.h"
30 #include "gfx_colors.h"
31 #include "ostc.h"
32 #include "settings.h"
33 #include "text_multilanguage.h"
34
35 /* Exported variables --------------------------------------------------------*/
36
37 /* Private types -------------------------------------------------------------*/
38
39 typedef struct
40 {
41 uint32_t Xdelta;
42 uint32_t Ydelta;
43 uint8_t invert;
44 uint8_t color;
45 uint8_t dualFont;
46 uint8_t resize;
47 uint32_t font;
48 uint8_t spaceMode;
49 uint8_t singleSpaceWithSizeOfNextChar;
50 uint8_t useTinyFont;
51 uint32_t TinyFont;
52 int8_t TinyFontExtraYdelta;
53 tFont *actualFont;
54 uint8_t doubleSize;
55 } GFX_CfgWriteString;
56
57 typedef struct
58 {
59 uint32_t pBuffer;
60 uint32_t height;
61 uint32_t width;
62 uint32_t leftStart;
63 uint32_t bottomStart;
64 } GFX_layerSingle;
65 /*
66 typedef struct
67 {
68 GFX_layerSingle top;
69 GFX_layerSingle bottom;
70 } GFX_layersTopBottom;
71 */
72 typedef struct
73 {
74 uint32_t pActualTopBuffer;
75 uint32_t pNextTopBuffer[2];
76 GFX_layerSingle actualBottom;
77 GFX_layerSingle nextBottom[2];
78 uint8_t boolNextTop;
79 uint8_t boolNextBottom;
80 } GFX_layerControl;
81
82 typedef struct
83 {
84 uint32_t StartAddress;
85 int8_t status;
86 uint8_t caller;
87 } SFrameList;
88
89 enum FRAMESTATE
90 {
91 CLEAR = 0,
92 BLOCKED,
93 RELEASED
94 };
95
96 enum LOGOSTATE
97 {
98 LOGOOFF = 0,
99 LOGOSTART = 1,
100 LOGOSTOP = 255
101 };
102
103 // should be 43
104 #define MAXFRAMES 39
105
106 #define SDRAM_BANK_ADDR ((uint32_t)0xD0000000)
107 #define FBGlobalStart SDRAM_BANK_ADDR
108 #define FBOffsetEachIndex (800*480*2)
109
110 #define SDRAM_DOUBLE_BUFFER_ONE ((uint32_t)(FBGlobalStart + (MAXFRAMES * FBOffsetEachIndex)))
111 #define SDRAM_DOUBLE_BUFFER_TWO ((uint32_t)(SDRAM_DOUBLE_BUFFER_ONE + (2 * FBOffsetEachIndex)))
112 #define SDRAM_DOUBLE_BUFFER_END ((uint32_t)(SDRAM_DOUBLE_BUFFER_TWO + (2 * FBOffsetEachIndex)))
113
114 /* Semi Private variables ---------------------------------------------------------*/
115
116 DMA2D_HandleTypeDef Dma2dHandle;
117 LTDC_HandleTypeDef LtdcHandle;
118
119 /* Private variables ---------------------------------------------------------*/
120
121 uint8_t DMA2D_at_work = 0;
122
123 GFX_layerControl FrameHandler = { 0 };
124
125 uint32_t pInvisibleFrame = 0;
126 uint32_t pLogoFrame = 0;
127 uint8_t logoStatus;
128 uint32_t pBackgroundHwFrame = 0;
129 uint8_t backgroundHwStatus;
130
131 SFrameList frame[MAXFRAMES];
132
133 #define MAXFRAMECOUNTER (28)
134 uint8_t frameCounter[MAXFRAMECOUNTER] = { 0 };
135
136 _Bool lock_changeLTDC = 0;
137
138 /* ITM Trace-----------------------------------------------------------------*/
139
140 #include "stdio.h"
141
142 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
143 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
144 #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
145
146 #define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
147 #define TRCENA 0x01000000
148
149 struct __FILE { int handle; /* Add whatever needed */ };
150 FILE __stdout;
151 FILE __stdin;
152
153 int fputc(int ch, FILE *f) {
154 if (DEMCR & TRCENA) {
155 while (ITM_Port32(0) == 0);
156 ITM_Port8(0) = ch;
157 }
158 return(ch);
159 }
160
161 uint32_t MinU32GFX(uint32_t a, uint32_t b)
162 {
163 return ((a<b)?a:b);
164 }
165
166
167 uint32_t MaxU32GFX(uint32_t a, uint32_t b)
168 {
169 return((a>b)?a:b);
170 }
171
172 /* Private function prototypes -----------------------------------------------*/
173
174 static uint32_t GFX_write_char(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font);
175 static uint32_t GFX_write_substring(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, uint8_t textId, int8_t nextCharFor2Byte);
176 uint32_t GFX_write__Modify_Xdelta__Centered(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pText);
177 uint32_t GFX_write__Modify_Xdelta__RightAlign(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput);
178 static void GFX_Error_Handler(void);
179 static void GFX_Dma2d_TransferComplete(DMA2D_HandleTypeDef* Dma2dHandle);
180 static void GFX_Dma2d_TransferError(DMA2D_HandleTypeDef* Dma2dHandle);
181 void GFX_clear_frame_dma2d(uint8_t frameId);
182
183 uint32_t GFX_doubleBufferOne(void);
184 uint32_t GFX_doubleBufferTwo(void);
185
186
187 /* Exported functions --------------------------------------------------------*/
188
189 uint8_t GFX_logoStatus(void)
190 {
191 return logoStatus;
192 }
193
194
195 void GFX_helper_font_memory_list(const tFont *Font)
196 {
197 int i;
198 uint8_t character;
199
200 // -----------------------------
201
202 for(character = 0x20; character < 0xFF; character++)
203 {
204 for(i=0;i<Font->length;i++)
205 {
206 if(Font->chars[i].code == character)
207 {
208 printf("%02x: 0x%0lx 0x%0lx\n\r",(uint8_t)character, (uint32_t)(Font->chars[i].image->data),((uint32_t)(Font->chars[i+1].image->data)-(uint32_t)(Font->chars[i].image->data)));
209 break;
210 }
211 }
212 }
213 }
214
215
216
217 void GFX_SetWindowLayer0(uint32_t pDestination, int16_t XleftGimpStyle, int16_t XrightGimpStyle, int16_t YtopGimpStyle, int16_t YbottomGimpStyle)
218 {
219 int16_t XSize, YSize, X0, Y0;
220
221 if(XleftGimpStyle < 0) XleftGimpStyle = 0;
222 if(XrightGimpStyle < 0) XrightGimpStyle = 0;
223 if(XleftGimpStyle > 799) XleftGimpStyle = 800;
224 if(XrightGimpStyle > 799) XrightGimpStyle = 800;
225
226 if(YtopGimpStyle < 0) YtopGimpStyle = 0;
227 if(YbottomGimpStyle < 0) YbottomGimpStyle = 0;
228 if(YtopGimpStyle > 479) YtopGimpStyle = 480;
229 if(YbottomGimpStyle > 479) YbottomGimpStyle = 480;
230
231 /*
232 XSize = YbottomGimpStyle - YtopGimpStyle;
233 YSize = XrightGimpStyle - XleftGimpStyle;
234 if((XSize <= 0) || (YSize <= 0))
235 return;
236 X0 = 479 - YbottomGimpStyle;
237 Y0 = XleftGimpStyle;
238 while((LTDC->CPSR & LTDC_CPSR_CYPOS) <= (uint32_t)800);
239 HAL_LTDC_SetWindowSize(&LtdcHandle, XSize, YSize, LayerIdx);
240 HAL_LTDC_SetWindowPosition(&LtdcHandle, X0, Y0,LayerIdx);
241 HAL_LTDC_SetAddress(&LtdcHandle, pDestination, LayerIdx);
242 */
243
244 XSize = XrightGimpStyle - XleftGimpStyle;
245 YSize = YbottomGimpStyle - YtopGimpStyle;
246 if((XSize <= 0) || (YSize <= 0))
247 return;
248 Y0 = 479 - YbottomGimpStyle;
249 X0 = XleftGimpStyle;
250
251 GFX_SetFrameBottom(pDestination, X0, Y0, XSize, YSize);
252 }
253
254
255 void GFX_logoAutoOff(void)
256 {
257 if(logoStatus == LOGOOFF)
258 logoStatus = LOGOSTART;
259 }
260
261 /*
262 uint8_t GFX_printf_firmware(char *text)
263 {
264 uint8_t zahl, ptr;
265
266 ptr = 0;
267 zahl = settingsGetPointer()->firmwareVersion16to32bit.ub.first;
268 if(zahl >= 10)
269 {
270 text[ptr++] = '0' + (zahl / 10);
271 zahl = zahl - ((zahl / 10 ) * 10);
272 }
273 text[ptr++] = '0' + zahl;
274 text[ptr++] = '.';
275
276 zahl = settingsGetPointer()->firmwareVersion16to32bit.ub.second;
277 if(zahl >= 10)
278 {
279 text[ptr++] = '0' + (zahl / 10);
280 zahl = zahl - ((zahl / 10 ) * 10);
281 }
282 text[ptr++] = '0' + zahl;
283 text[ptr++] = '.';
284
285 zahl = settingsGetPointer()->firmwareVersion16to32bit.ub.third;
286 if(zahl >= 10)
287 {
288 text[ptr++] = '0' + (zahl / 10);
289 zahl = zahl - ((zahl / 10 ) * 10);
290 }
291 text[ptr++] = '0' + zahl;
292
293 if(settingsGetPointer()->firmwareVersion16to32bit.ub.betaFlag)
294 {
295 text[ptr++] = ' ';
296 text[ptr++] = 'b';
297 text[ptr++] = 'e';
298 text[ptr++] = 't';
299 text[ptr++] = 'a';
300 }
301 text[ptr] = 0;
302
303 return ptr;
304 }
305 */
306
307 void GFX_hwBackgroundOn(void)
308 {
309 backgroundHwStatus = LOGOSTART;
310 }
311
312
313 void GFX_hwBackgroundOff(void)
314 {
315 backgroundHwStatus = LOGOSTOP;
316 }
317
318
319 void GFX_build_hw_background_frame(void)
320 {
321 GFX_DrawCfgScreen tLogoTemp;
322 SWindowGimpStyle windowGimp;
323
324 pBackgroundHwFrame = getFrame(1);
325 backgroundHwStatus = 0;
326
327 tLogoTemp.FBStartAdress = pBackgroundHwFrame;
328 tLogoTemp.ImageHeight = 480;
329 tLogoTemp.ImageWidth = 800;
330 tLogoTemp.LayerIndex = 1;
331
332 windowGimp.left = (800 - 400) / 2;
333 windowGimp.top = 0;//(480 - 46) / 2;
334
335 GFX_draw_image_color(&tLogoTemp, windowGimp, &ImgHWcolor);
336 /*
337 char localtext[256];
338 uint8_t ptr = 0;
339
340 localtext[ptr++] = ' ';
341 localtext[ptr++] = ' ';
342 localtext[ptr++] = 'O';
343 localtext[ptr++] = 'S';
344 localtext[ptr++] = ' ';
345 ptr += GFX_printf_firmware(&localtext[ptr]);
346 localtext[ptr] = 0;
347
348 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020);
349 */
350 }
351
352
353
354
355 void GFX_build_logo_frame(void)
356 {
357 GFX_DrawCfgScreen tLogoTemp;
358 SWindowGimpStyle windowGimp;
359
360 pLogoFrame = getFrame(1);
361 logoStatus = LOGOOFF;
362
363 tLogoTemp.FBStartAdress = pLogoFrame;
364 tLogoTemp.ImageHeight = 480;
365 tLogoTemp.ImageWidth = 800;
366 tLogoTemp.LayerIndex = 1;
367
368 windowGimp.left = (800 - 400) / 2;
369 windowGimp.top = (480 - 46) / 2;
370
371 GFX_draw_image_color(&tLogoTemp, windowGimp, &ImgHWcolor);
372 /*
373 char localtext[256];
374 uint8_t ptr = 0;
375
376 localtext[ptr++] = ' ';
377 localtext[ptr++] = ' ';
378 localtext[ptr++] = 'O';
379 localtext[ptr++] = 'S';
380 localtext[ptr++] = ' ';
381 ptr += GFX_printf_firmware(&localtext[ptr]);
382 localtext[ptr] = 0;
383
384 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020);
385 */
386 }
387
388
389 void GFX_init(uint32_t * pDestinationOut)
390 {
391 frame[0].StartAddress = FBGlobalStart;
392 GFX_clear_frame_immediately(frame[0].StartAddress);
393 frame[0].status = CLEAR;
394 frame[0].caller = 0;
395
396 for(int i=1;i<MAXFRAMES;i++)
397 {
398 frame[i].StartAddress = frame[i-1].StartAddress + FBOffsetEachIndex;
399 GFX_clear_frame_immediately(frame[i].StartAddress);
400 frame[i].status = CLEAR;
401 frame[i].caller = 0;
402 }
403
404 for(int i=1;i<MAXFRAMECOUNTER;i++)
405 {
406 frameCounter[i] = 0;
407 }
408
409 pInvisibleFrame = getFrame(2);
410 *pDestinationOut = pInvisibleFrame;
411
412 GFX_build_logo_frame();
413 GFX_build_hw_background_frame();
414
415 /* Register to memory mode with ARGB8888 as color Mode */
416 Dma2dHandle.Init.Mode = DMA2D_R2M;
417 Dma2dHandle.Init.ColorMode = DMA2D_ARGB4444;//to fake AL88, before: DMA2D_ARGB8888;
418 Dma2dHandle.Init.OutputOffset = 0;
419
420 /* DMA2D Callbacks Configuration */
421 Dma2dHandle.XferCpltCallback = GFX_Dma2d_TransferComplete;
422 Dma2dHandle.XferErrorCallback = GFX_Dma2d_TransferError;
423
424 Dma2dHandle.Instance = DMA2D;
425
426 /* DMA2D Initialisation */
427 if(HAL_DMA2D_Init(&Dma2dHandle) != HAL_OK)
428 GFX_Error_Handler();
429
430 if(HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1) != HAL_OK)
431 GFX_Error_Handler();
432
433 DMA2D_at_work = 255;
434 }
435
436
437 void GFX_init1_no_DMA(uint32_t * pDestinationOut, uint8_t blockFrames)
438 {
439 frame[0].StartAddress = FBGlobalStart;
440 GFX_clear_frame_immediately(frame[0].StartAddress);
441 frame[0].status = CLEAR;
442 frame[0].caller = 0;
443
444 for(int i=1;i<MAXFRAMES;i++)
445 {
446 frame[i].StartAddress = frame[i-1].StartAddress + FBOffsetEachIndex;
447 GFX_clear_frame_immediately(frame[i].StartAddress);
448 frame[i].status = CLEAR;
449 frame[i].caller = 0;
450 }
451
452 for(int i=0;i<blockFrames;i++)
453 {
454 frame[i].status = BLOCKED;
455 frame[i].caller = 1;
456 }
457
458 pInvisibleFrame = getFrame(2);
459 *pDestinationOut = pInvisibleFrame;
460
461 GFX_build_logo_frame();
462 GFX_build_hw_background_frame();
463 }
464
465
466 void GFX_init2_DMA(void)
467 {
468 /* Register to memory mode with ARGB8888 as color Mode */
469 Dma2dHandle.Init.Mode = DMA2D_R2M;
470 Dma2dHandle.Init.ColorMode = DMA2D_ARGB4444;//to fake AL88, before: DMA2D_ARGB8888;
471 Dma2dHandle.Init.OutputOffset = 0;
472
473 /* DMA2D Callbacks Configuration */
474 Dma2dHandle.XferCpltCallback = GFX_Dma2d_TransferComplete;
475 Dma2dHandle.XferErrorCallback = GFX_Dma2d_TransferError;
476
477 Dma2dHandle.Instance = DMA2D;
478
479 /* DMA2D Initialisation */
480 if(HAL_DMA2D_Init(&Dma2dHandle) != HAL_OK)
481 GFX_Error_Handler();
482
483 if(HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1) != HAL_OK)
484 GFX_Error_Handler();
485
486 DMA2D_at_work = 255;
487 }
488
489
490
491 void GFX_SetFrameTop(uint32_t pDestination)
492 {
493 lock_changeLTDC = 1;
494 uint8_t boolNextTop = !FrameHandler.boolNextTop;
495
496 if(pDestination == 0)
497 pDestination = pInvisibleFrame;
498
499 FrameHandler.pNextTopBuffer[boolNextTop] = pDestination;
500 FrameHandler.boolNextTop = boolNextTop;
501 lock_changeLTDC = 0;
502 }
503
504
505 void GFX_SetFrameBottom(uint32_t pDestination, uint32_t x0, uint32_t y0, uint32_t width, uint32_t height)
506 {
507 lock_changeLTDC = 1;
508 uint8_t boolNextBottom = !FrameHandler.boolNextBottom;
509
510 if(pDestination == 0)
511 pDestination = pInvisibleFrame;
512
513 FrameHandler.nextBottom[boolNextBottom].pBuffer = pDestination;
514 FrameHandler.nextBottom[boolNextBottom].height = height;
515 FrameHandler.nextBottom[boolNextBottom].width = width;
516 FrameHandler.nextBottom[boolNextBottom].leftStart = x0;
517 FrameHandler.nextBottom[boolNextBottom].bottomStart = y0;
518 FrameHandler.boolNextBottom = boolNextBottom;
519 lock_changeLTDC = 0;
520 }
521
522
523 void GFX_SetFramesTopBottom(uint32_t pTop, uint32_t pBottom, uint32_t heightBottom)
524 {
525 GFX_SetFrameTop(pTop);
526 GFX_SetFrameBottom(pBottom, 0, 0, 800, heightBottom);
527 }
528
529
530 uint32_t GFX_get_pActualFrameTop(void)
531 {
532 return FrameHandler.pActualTopBuffer;
533 }
534
535
536 uint32_t GFX_get_pActualFrameBottom(void)
537 {
538 return FrameHandler.actualBottom.pBuffer;
539 }
540
541
542 void GFX_start_VSYNC_IRQ(void)
543 {
544 GPIO_InitTypeDef GPIO_InitStructure;
545
546 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
547 GPIO_InitStructure.Pull = GPIO_NOPULL;
548 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
549 GPIO_InitStructure.Pin = VSYNC_IRQ_PIN;
550 HAL_GPIO_Init(VSYNC_IRQ_GPIO_PORT, &GPIO_InitStructure);
551
552 HAL_NVIC_SetPriority(VSYNC_IRQ_EXTI_IRQn, 1, 0);
553 HAL_NVIC_EnableIRQ(VSYNC_IRQ_EXTI_IRQn);
554 }
555
556
557 void GFX_change_LTDC(void)
558 {
559 if(lock_changeLTDC == 1)
560 return;
561
562 uint32_t pTop = 0;
563 uint32_t pBot = 0;
564 uint32_t heightBot = 0;
565 uint32_t widthBot = 0;
566 uint32_t leftStartBot = 0;
567 uint32_t bottomStartBot = 0;
568 uint8_t change_position = 0;
569 uint8_t change_size = 0;
570
571 // Top Frame
572 pTop = FrameHandler.pNextTopBuffer[FrameHandler.boolNextTop];
573 if(FrameHandler.pActualTopBuffer != pTop)
574 {
575 HAL_LTDC_SetAddress(&LtdcHandle, pTop, 1);
576 FrameHandler.pActualTopBuffer = pTop;
577 }
578
579 // Bottom Frame
580 if(logoStatus != LOGOOFF)
581 {
582 switch(logoStatus)
583 {
584 case LOGOSTART:
585 HAL_LTDC_SetAlpha(&LtdcHandle, 0, 1);
586 HAL_LTDC_SetAlpha(&LtdcHandle, 34, 0);
587 HAL_LTDC_ConfigCLUT(&LtdcHandle, (uint32_t *)indexHWcolor, indexHWcolorSIZE, 0);
588 HAL_LTDC_SetAddress(&LtdcHandle, pLogoFrame, 0);
589 HAL_LTDC_SetWindowSize(&LtdcHandle, 480, 800, 0);
590 HAL_LTDC_SetWindowPosition(&LtdcHandle, 0, 0, 0);
591 logoStatus = 2;
592 break;
593
594 case LOGOSTOP:
595 HAL_LTDC_SetAlpha(&LtdcHandle, 255, 1);
596 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 0);
597
598 pBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].pBuffer;
599 heightBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].height;
600 widthBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].width;
601 leftStartBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].leftStart;
602 bottomStartBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].bottomStart;
603 HAL_LTDC_SetWindowSize(&LtdcHandle, heightBot, widthBot, 0);
604 HAL_LTDC_SetWindowPosition(&LtdcHandle, bottomStartBot, leftStartBot, 0);
605 HAL_LTDC_SetAddress(&LtdcHandle, pBot, 0);
606 HAL_LTDC_SetAlpha(&LtdcHandle, 255, 0);
607 FrameHandler.actualBottom.height = heightBot;
608 FrameHandler.actualBottom.width = widthBot;
609 FrameHandler.actualBottom.leftStart = leftStartBot;
610 FrameHandler.actualBottom.bottomStart = bottomStartBot;
611 FrameHandler.actualBottom.pBuffer = pBot;
612
613 logoStatus = LOGOOFF;
614 if(backgroundHwStatus == 2)
615 {
616 backgroundHwStatus = LOGOSTART;
617 }
618 break;
619 default:
620 if(logoStatus < 35)
621 {
622 logoStatus++;
623 if(logoStatus <= 15)
624 HAL_LTDC_SetAlpha(&LtdcHandle, 17*logoStatus, 0);
625 }
626 else
627 {
628 logoStatus +=20;
629 HAL_LTDC_SetAlpha(&LtdcHandle, logoStatus-55, 1);
630 HAL_LTDC_SetAlpha(&LtdcHandle, 255+55-logoStatus, 0);
631 }
632 break;
633 }
634 return;
635 }
636 else if (backgroundHwStatus != LOGOOFF)
637 {
638 switch(backgroundHwStatus)
639 {
640 case LOGOSTART:
641 HAL_LTDC_ConfigCLUT(&LtdcHandle, (uint32_t *)indexHWcolor, indexHWcolorSIZE, 0);
642 HAL_LTDC_SetAddress(&LtdcHandle, pBackgroundHwFrame, 0);
643 HAL_LTDC_SetWindowSize(&LtdcHandle, 480, 800, 0);
644 HAL_LTDC_SetWindowPosition(&LtdcHandle, 0, 0, 0);
645 backgroundHwStatus = 2;
646 break;
647
648 case LOGOSTOP:
649 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 0);
650 pBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].pBuffer;
651 heightBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].height;
652 widthBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].width;
653 leftStartBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].leftStart;
654 bottomStartBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].bottomStart;
655 HAL_LTDC_SetWindowSize(&LtdcHandle, heightBot, widthBot, 0);
656 HAL_LTDC_SetWindowPosition(&LtdcHandle, bottomStartBot, leftStartBot, 0);
657 HAL_LTDC_SetAddress(&LtdcHandle, pBot, 0);
658 HAL_LTDC_SetAlpha(&LtdcHandle, 255, 0);
659 FrameHandler.actualBottom.height = heightBot;
660 FrameHandler.actualBottom.width = widthBot;
661 FrameHandler.actualBottom.leftStart = leftStartBot;
662 FrameHandler.actualBottom.bottomStart = bottomStartBot;
663 FrameHandler.actualBottom.pBuffer = pBot;
664 backgroundHwStatus = LOGOOFF;
665 break;
666
667 default:
668 break;
669 }
670 return;
671 }
672 else
673 {
674 pBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].pBuffer;
675 heightBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].height;
676 widthBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].width;
677 leftStartBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].leftStart;
678 bottomStartBot = FrameHandler.nextBottom[FrameHandler.boolNextBottom].bottomStart;
679
680 if(FrameHandler.actualBottom.pBuffer == pBot)
681 pBot = 0;
682
683 if((FrameHandler.actualBottom.height != heightBot) || (FrameHandler.actualBottom.width != widthBot))
684 change_size = 1;
685
686 if((FrameHandler.actualBottom.leftStart != leftStartBot) || (FrameHandler.actualBottom.bottomStart != bottomStartBot))
687 change_position = 1;
688
689 if(pBot || change_size || change_position)
690 {
691 if(heightBot && widthBot)
692 HAL_LTDC_SetWindowSize(&LtdcHandle, heightBot, widthBot, 0);
693
694 if(change_position || leftStartBot || bottomStartBot)
695 HAL_LTDC_SetWindowPosition(&LtdcHandle, bottomStartBot, leftStartBot, 0);
696
697 if(pBot)
698 HAL_LTDC_SetAddress(&LtdcHandle, pBot, 0);
699
700 if(change_size)
701 {
702 FrameHandler.actualBottom.height = heightBot;
703 FrameHandler.actualBottom.width = widthBot;
704 }
705 if(change_position)
706 {
707 FrameHandler.actualBottom.leftStart = leftStartBot;
708 FrameHandler.actualBottom.bottomStart = bottomStartBot;
709 }
710 if(pBot)
711 FrameHandler.actualBottom.pBuffer = pBot;
712 }
713 }
714 }
715
716 uint8_t GFX_is_colorschemeDiveStandard(void)
717 {
718 return (ColorLUT[CLUT_Font027] == 0x00FFFFFF);
719 }
720
721
722 void change_CLUT_entry(uint8_t entryToChange, uint8_t entryUsedForChange)
723 {
724 /* bug fix
725 static uint8_t counter = 0;
726
727 if(entryToChange == 0x1C)
728 counter++;
729 */
730 ColorLUT[entryToChange] = ColorLUT[entryUsedForChange];
731 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 1);
732 if(logoStatus == LOGOOFF)
733 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 0);
734 }
735
736
737 void GFX_use_colorscheme(uint8_t colorscheme)
738 {
739 uint8_t ColorSchemeStart;
740
741 if(colorscheme > 3)
742 colorscheme = 0;
743
744 ColorSchemeStart = CLUT_Colorscheme0 + (8 * colorscheme);
745 for(int i=1; i<8; i++)
746 {
747 ColorLUT[CLUT_Font027 + i] = ColorLUT[ColorSchemeStart + i];
748 }
749 change_CLUT_entry(CLUT_Font027, ColorSchemeStart);
750 }
751
752
753 void GFX_VGA_transform(uint32_t pSource, uint32_t pDestination)
754 {
755 int h, v;
756 uint32_t offsetSource, offsetSourceStartOfLine;
757
758 offsetSourceStartOfLine = 480 + 480 - 2;
759 for(v=0;v<480;v++)
760 {
761 offsetSource = offsetSourceStartOfLine;
762 for(h=0;h<640;h++)
763 {
764 *(__IO uint8_t*)pDestination = *(uint8_t*)(pSource + offsetSource);
765 pDestination++;
766 offsetSource += 1;
767 *(__IO uint8_t*)pDestination = *(uint8_t*)(pSource + offsetSource);
768 pDestination++;
769 offsetSource += 480 + 479;
770 }
771 offsetSourceStartOfLine -= 2;
772 }
773 }
774
775 HAL_StatusTypeDef GFX_SetBackgroundColor(uint32_t LayerIdx, uint8_t red, uint8_t green, uint8_t blue)
776 {
777 uint32_t tmp = 0;
778 uint32_t tmp1 = 0;
779
780 /* Process locked */
781 __HAL_LOCK(&LtdcHandle);
782
783 /* Change LTDC peripheral state */
784 LtdcHandle.State = HAL_LTDC_STATE_BUSY;
785
786 /* Check the parameters */
787 assert_param(IS_LTDC_LAYER(LayerIdx));
788
789 /* Copy new layer configuration into handle structure */
790 LtdcHandle.LayerCfg[LayerIdx].Backcolor.Red = red;
791 LtdcHandle.LayerCfg[LayerIdx].Backcolor.Green = green;
792 LtdcHandle.LayerCfg[LayerIdx].Backcolor.Blue = blue;
793
794 /* Configure the LTDC Layer */
795 tmp = ((uint32_t)(green) << 8);
796 tmp1 = ((uint32_t)(red) << 16);
797 __HAL_LTDC_LAYER(&LtdcHandle, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED | LTDC_LxDCCR_DCALPHA);
798 __HAL_LTDC_LAYER(&LtdcHandle, LayerIdx)->DCCR = (blue | tmp | tmp1 | 0xFF);
799
800 /* Sets the Reload type */
801 LtdcHandle.Instance->SRCR = LTDC_SRCR_IMR;
802
803 /* Initialize the LTDC state*/
804 LtdcHandle.State = HAL_LTDC_STATE_READY;
805
806 /* Process unlocked */
807 __HAL_UNLOCK(&LtdcHandle);
808
809 return HAL_OK;
810 }
811
812
813 void GFX_clear_frame_immediately(uint32_t pDestination)
814 {
815 uint32_t i;
816
817 for(i = 200*480; i > 0; i--)
818 {
819 *(__IO uint16_t*)pDestination = 0;
820 pDestination += 2;
821 *(__IO uint16_t*)pDestination = 0;
822 pDestination += 2;
823 *(__IO uint16_t*)pDestination = 0;
824 pDestination += 2;
825 *(__IO uint16_t*)pDestination = 0;
826 pDestination += 2;
827 }
828 }
829
830
831 void GFX_clear_window_immediately(GFX_DrawCfgWindow* hgfx)
832 {
833 uint32_t pDestination, i, j;
834 uint16_t left, width, bottom, height, nextlineStep;
835
836 pDestination = (uint32_t)hgfx->Image->FBStartAdress;
837
838 left = hgfx->WindowX0;
839 width = 1 + hgfx->WindowX1 - left;
840 bottom = hgfx->WindowY0;
841 height = 1 + hgfx->WindowY1 - bottom;
842 nextlineStep = hgfx->Image->ImageHeight - height;
843 nextlineStep *= 2;
844
845 pDestination += 2 * bottom;
846 pDestination += 2 * hgfx->Image->ImageHeight * left;
847
848 for(j = width; j > 0; j--)
849 {
850 for(i = height; i > 0; i--)
851 {
852 *(__IO uint16_t*)pDestination = 0;
853 pDestination += 2;
854 }
855 pDestination += nextlineStep;
856 }
857 }
858
859
860 void GFX_clear_frame_dma2d(uint8_t frameId)
861 {
862 if(frameId >= MAXFRAMES)
863 return;
864
865 DMA2D_at_work = frameId;
866
867 if (HAL_DMA2D_Start_IT(&Dma2dHandle, 0x0000000000, frame[frameId].StartAddress, 480, 800) != HAL_OK)
868 GFX_Error_Handler();
869 }
870
871
872 void GFX_fill_buffer(uint32_t pDestination, uint8_t alpha, uint8_t color)
873 {
874
875 union al88_u
876 {
877 uint8_t al8[2];
878 uint16_t al88;
879 };
880
881 union al88_u colorcombination;
882 uint32_t i;
883
884 colorcombination.al8[0] = color;
885 colorcombination.al8[1] = alpha;
886
887 for(i = 800*480; i > 0; i--)
888 {
889 *(__IO uint16_t*)pDestination = colorcombination.al88;
890 pDestination += 2;
891 }
892 }
893
894
895 void gfx_flip(point_t *p1, point_t *p2)
896 {
897 point_t temp;
898
899 temp = *p1;
900 *p1 = *p2;
901 *p2 = temp;
902 }
903
904
905 static inline void gfx_brush(uint8_t thickness, GFX_DrawCfgScreen *hgfx, uint16_t x0, uint16_t y0, uint8_t color)
906 {
907 uint32_t pDestination;
908 uint8_t offset = thickness/2;
909
910 pDestination = hgfx->FBStartAdress + 2*(x0 - offset)*hgfx->ImageHeight + 2*(y0-offset);
911 for(int x=thickness;x>0;x--)
912 {
913 for(int y=thickness;y>0;y--)
914 {
915 *(__IO uint16_t*)pDestination = 0xFF00 + color;
916 pDestination +=2;
917 }
918 pDestination += 2*(hgfx->ImageHeight - thickness);
919 }
920 }
921
922
923 void GFX_draw_thick_line(uint8_t thickness, GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color)
924 {
925 if(thickness < 2)
926 GFX_draw_line(hgfx, start, stop, color);
927
928 int x0 = start.x;
929 int y0 = start.y;
930 int x1 = stop.x;
931 int y1 = stop.y;
932 int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
933 int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
934 int err = (dx>dy ? dx : -dy)/2, e2;
935
936
937 if(start.x == stop.x)
938 {
939 if(start.y > stop.y) gfx_flip(&start,&stop);
940 for (int j = stop.y - start.y; j > 0; j--)
941 {
942 gfx_brush(thickness,hgfx,start.x,start.y++,color);
943 }
944 }
945 else
946 if(start.y == stop.y)
947 {
948 if(start.x > stop.x) gfx_flip(&start,&stop);
949
950 for (int j = stop.x - start.x; j > 0; j--)
951 {
952 gfx_brush(thickness,hgfx,start.x++,start.y,color);
953 }
954 }
955 else // diagonal
956 {
957 for(;;)
958 {
959 gfx_brush(thickness,hgfx,x0,y0,color);
960 if (x0==x1 && y0==y1) break;
961 e2 = err;
962 if (e2 >-dx) { err -= dy; x0 += sx; }
963 if (e2 < dy) { err += dx; y0 += sy; }
964 }
965 }
966 }
967
968
969 void GFX_draw_line(GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color)
970 {
971 uint32_t pDestination;
972 uint32_t j;
973
974 if(start.x == stop.x)
975 {
976 if(start.y > stop.y) gfx_flip(&start,&stop);
977 pDestination = (uint32_t)hgfx->FBStartAdress;
978 pDestination += start.x * hgfx->ImageHeight * 2;
979 pDestination += start.y * 2;
980 for (j = stop.y - start.y; j > 0; j--)
981 {
982 *(__IO uint16_t*)pDestination = 0xFF00 + color;
983 pDestination += 2;
984 }
985 }
986 else
987 if(start.y == stop.y)
988 {
989 if(start.x > stop.x) gfx_flip(&start,&stop);
990 pDestination = (uint32_t)hgfx->FBStartAdress;
991 pDestination += start.x * hgfx->ImageHeight * 2;
992 pDestination += start.y * 2;
993 for (j = stop.x - start.x; j > 0; j--)
994 {
995 *(__IO uint16_t*)pDestination = 0xFF00 + color;
996 pDestination += hgfx->ImageHeight * 2;
997 }
998 }
999 else // diagonal
1000 {
1001 int x0 = start.x;
1002 int y0 = start.y;
1003 int x1 = stop.x;
1004 int y1 = stop.y;
1005 int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
1006 int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
1007 int err = (dx>dy ? dx : -dy)/2, e2;
1008
1009 for(;;)
1010 {
1011 pDestination = (uint32_t)hgfx->FBStartAdress;
1012 pDestination += ((x0 * hgfx->ImageHeight) + y0) * 2;
1013 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1014 if (x0==x1 && y0==y1) break;
1015 e2 = err;
1016 if (e2 >-dx) { err -= dy; x0 += sx; }
1017 if (e2 < dy) { err += dx; y0 += sy; }
1018 }
1019 }
1020 }
1021
1022
1023 void GFX_draw_image_monochrome(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image, uint8_t color)
1024 {
1025 uint32_t pDestination;
1026 uint32_t j;
1027 point_t start, stop;
1028
1029 start.x = window.left;
1030 start.y = (hgfx->ImageHeight - image->height - window.top);
1031 stop.y = start.y + image->height;
1032 stop.x = start.x + image->width;
1033 j = 0;
1034
1035 for(int xx = start.x; xx < stop.x; xx++)
1036 {
1037 pDestination = (uint32_t)hgfx->FBStartAdress;
1038 pDestination += xx * hgfx->ImageHeight * 2;
1039 pDestination += start.y * 2;
1040 for(int yy = start.y; yy < stop.y; yy++)
1041 {
1042 *(__IO uint8_t*)pDestination = color;
1043 pDestination += 1;
1044 *(__IO uint8_t*)pDestination = image->data[j++];
1045 pDestination += 1;
1046 }
1047 }
1048 }
1049
1050
1051 void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
1052 {
1053 uint32_t pDestination;
1054 uint32_t j;
1055 point_t start, stop;
1056
1057 start.x = window.left;
1058 start.y = (hgfx->ImageHeight - image->height - window.top);
1059 stop.y = start.y + image->height;
1060 stop.x = start.x + image->width;
1061 j = 0;
1062
1063 for(int xx = start.x; xx < stop.x; xx++)
1064 {
1065 pDestination = (uint32_t)hgfx->FBStartAdress;
1066 pDestination += xx * hgfx->ImageHeight * 2;
1067 pDestination += start.y * 2;
1068 for(int yy = start.y; yy < stop.y; yy++)
1069 {
1070 *(__IO uint8_t*)pDestination = image->data[j++];
1071 pDestination += 1;
1072 *(__IO uint8_t*)pDestination = 0xFF;
1073 pDestination += 1;
1074 }
1075 }
1076 }
1077
1078
1079 int16_Point_t switchToOctantZeroFrom(uint8_t octant, int16_t x, int16_t y)
1080 {
1081 int16_Point_t answer;
1082 switch(octant)
1083 {
1084 case 0:// return (x,y);
1085 answer.x = x;
1086 answer.y = y;
1087 break;
1088 case 1:// return (y,x);
1089 answer.x = y;
1090 answer.y = x;
1091 break;
1092 case 2:// return (y, -x);
1093 answer.x = y;
1094 answer.y = -x;
1095 break;
1096 case 3:// return (-x, y);
1097 answer.x = -x;
1098 answer.y = y;
1099 break;
1100 case 4:// return (-x, -y);
1101 answer.x = -x;
1102 answer.y = -y;
1103 break;
1104 case 5:// return (-y, -x);
1105 answer.x = -y;
1106 answer.y = -x;
1107 break;
1108 case 6:// return (-y, x);
1109 answer.x = -y;
1110 answer.y = x;
1111 break;
1112 case 7:// return (x, -y);
1113 answer.x = x;
1114 answer.y = -y;
1115 break;
1116 }
1117 return answer;
1118 }
1119
1120 /* this is NOT fast nor optimized */
1121 void GFX_draw_pixel(GFX_DrawCfgScreen *hgfx, int16_t x, int16_t y, uint8_t color)
1122 {
1123 uint32_t pDestination;
1124
1125 pDestination = (uint32_t)hgfx->FBStartAdress;
1126 pDestination += x * hgfx->ImageHeight * 2;
1127 pDestination += y * 2;
1128
1129 *(__IO uint8_t*)pDestination = color;
1130 pDestination += 1;
1131 *(__IO uint8_t*)pDestination = 0xFF;
1132 }
1133
1134
1135 /* store the quarter circle for given radius */
1136 void GFX_draw_circle_with_MEMORY(uint8_t use_memory, GFX_DrawCfgScreen *hgfx, point_t center, uint8_t radius, int8_t color)
1137 {
1138 }
1139
1140 /* this is NOT fast nor optimized */
1141 void GFX_draw_circle(GFX_DrawCfgScreen *hgfx, point_t center, uint8_t radius, int8_t color)
1142 {
1143 int x, y;
1144 int l;
1145 int r2, y2;
1146 int y2_new;
1147 int ty;
1148
1149 /* cos pi/4 = 185363 / 2^18 (approx) */
1150 l = (radius * 185363) >> 18;
1151
1152 /* hw */
1153 l += 1;
1154
1155 /* At x=0, y=radius */
1156 y = radius;
1157
1158 r2 = y2 = y * y;
1159 ty = (2 * y) - 1;
1160 y2_new = r2 + 3;
1161
1162 for (x = 0; x <= l; x++) {
1163 y2_new -= (2 * x) - 3;
1164
1165 if ((y2 - y2_new) >= ty) {
1166 y2 -= ty;
1167 y -= 1;
1168 ty -= 2;
1169 }
1170
1171 GFX_draw_pixel (hgfx, x + center.x, y + center.y, color);
1172 GFX_draw_pixel (hgfx, x + center.x, -y + center.y, color);
1173 GFX_draw_pixel (hgfx, -x + center.x, y + center.y, color);
1174 GFX_draw_pixel (hgfx, -x + center.x, -y + center.y, color);
1175
1176 GFX_draw_pixel (hgfx, y + center.x, x + center.y, color);
1177 GFX_draw_pixel (hgfx, y + center.x, -x + center.y, color);
1178 GFX_draw_pixel (hgfx, -y + center.x, x + center.y, color);
1179 GFX_draw_pixel (hgfx, -y + center.x, -x + center.y, color);
1180 }
1181 }
1182
1183
1184 void GFX_draw_colorline(GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color)
1185 {
1186 uint32_t pDestination;
1187 uint32_t j;
1188 uint32_t temp;
1189
1190 if(start.x == stop.x)
1191 {
1192 if(stop.y < start.y)
1193 {
1194 temp = stop.y;
1195 stop.y = start.y;
1196 start.y = temp;
1197 }
1198 pDestination = (uint32_t)hgfx->FBStartAdress;
1199 pDestination += start.x * hgfx->ImageHeight * 2;
1200 pDestination += start.y * 2;
1201 for (j = stop.y - start.y; j > 0; j--)
1202 {
1203 *(__IO uint8_t*)pDestination = color;
1204 pDestination += 1;
1205 *(__IO uint8_t*)pDestination = 0xFF;
1206 pDestination += 1;
1207 }
1208 }
1209 else
1210 if(start.y == stop.y)
1211 {
1212 if(stop.x < start.x)
1213 {
1214 temp = stop.x;
1215 stop.x = start.x;
1216 start.x = temp;
1217 }
1218 pDestination = (uint32_t)hgfx->FBStartAdress;
1219 pDestination += start.x * hgfx->ImageHeight * 2;
1220 pDestination += start.y * 2;
1221 for (j = stop.x - start.x; j > 0; j--)
1222 {
1223 *(__IO uint8_t*)pDestination = color;
1224 pDestination += 1;
1225 *(__IO uint8_t*)pDestination = 0xFF;
1226 pDestination -= 1;
1227 pDestination += hgfx->ImageHeight * 2;
1228 }
1229 }
1230 else // diagonal Bresenham's_line_algorithm
1231 {
1232 int x0 = start.x;
1233 int y0 = start.y;
1234 int x1 = stop.x;
1235 int y1 = stop.y;
1236 int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
1237 int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
1238 int err = (dx>dy ? dx : -dy)/2, e2;
1239
1240 for(;;)
1241 {
1242 pDestination = (uint32_t)hgfx->FBStartAdress;
1243 pDestination += ((x0 * hgfx->ImageHeight) + y0) * 2;
1244 *(__IO uint8_t*)pDestination = color;
1245 pDestination += 1;
1246 *(__IO uint8_t*)pDestination = 0xFF;
1247 if (x0==x1 && y0==y1) break;
1248 e2 = err;
1249 if (e2 >-dx) { err -= dy; x0 += sx; }
1250 if (e2 < dy) { err += dx; y0 += sy; }
1251 }
1252 }
1253 }
1254
1255
1256 void GFX_draw_Grid(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, int vlines, float vdeltaline, int hlines, float hdeltalines, uint8_t color)
1257 {
1258 point_t p1;
1259 point_t p2;
1260 int winthight = window.bottom - window.top;
1261 int winwidth = window.right - window.left;
1262 float deltaline = 0;
1263
1264 if(vlines > 0)
1265 {
1266 deltaline = ((float)winwidth) /vlines;
1267
1268 p1.y = 479 - window.top;
1269 p2.y = 479 - window.bottom;
1270 for(int i = 0; i <= vlines; i++)
1271 {
1272 p1.x = window.left + (int)(i * deltaline + 0.5f);
1273 p2.x = p1.x ;
1274 GFX_draw_colorline(hgfx, p1,p2, color );
1275 }
1276 }
1277 if(vdeltaline > 0)
1278 {
1279 p1.y = 479 - window.top;
1280 p2.y = 479 - window.bottom;
1281 for(int i = 0; i < winwidth/vdeltaline; i++)
1282 {
1283 p1.x = window.left + (int)(i * vdeltaline + 0.5f);
1284 p2.x = p1.x ;
1285 GFX_draw_colorline(hgfx, p1,p2, color );
1286 }
1287 }
1288 if(hlines > 0)
1289 {
1290 deltaline = ((float)winthight)/hlines;
1291 p1.x = window.left;
1292 p2.x = window.right;
1293 for(int i = 0; i <= hlines; i++)
1294 {
1295 p1.y = 479 - window.top - (int)(i * deltaline + 0.5f);
1296 p2.y = p1.y;
1297 GFX_draw_colorline(hgfx, p1,p2, color );
1298 }
1299 }
1300 }
1301
1302 /* drawVeilUntil ist auff�llen des Bereichs unter der Kurve mit etwas hellerer Farbe
1303 * Xdivide ist nichr benutzt, wird weggelassen in dieser Version
1304 */
1305 /*
1306 void GFX_graph_print(GFX_DrawCfgScreen *hgfx, const SWindowGimpStyle *window, uint16_t drawVeilUntil, uint8_t Xdivide, uint16_t dataMin, uint16_t dataMax, uint16_t *data, uint16_t datalength, uint8_t color, uint8_t *colour_data)
1307 {
1308 if(window->bottom > 479)
1309 return;
1310 if(window->top > 479)
1311 return;
1312 if(window->right > 799)
1313 return;
1314 if(window->left > 799)
1315 return;
1316 if(window->bottom < 0)
1317 return;
1318 if(window->top < 0)
1319 return;
1320 if(window->right < 0)
1321 return;
1322 if(window->left < 0)
1323 return;
1324 if(window->bottom <= window->top)
1325 return;
1326 if(window->right <= window->left)
1327 return;
1328
1329 uint16_t windowwidth = (uint16_t)window->right - (uint16_t)window->left;
1330
1331 if(dataMax == dataMin)
1332 dataMax++;
1333
1334 uint8_t invert = 0;
1335 if(dataMin > dataMax)
1336 {
1337 uint16_t dataFlip;
1338 dataFlip = dataMin;
1339 dataMin = dataMax;
1340 dataMax = dataFlip;
1341 invert = 1;
1342 }
1343 else
1344 invert = 0;
1345
1346 uint16_t dataDelta = 0;
1347 dataDelta = dataMax - dataMin;
1348
1349 uint8_t colormask = color;
1350
1351 uint16_t loopX, loopData;
1352 loopX = 0;
1353 loopData = 0;
1354 while((loopX <= windowwidth) & (loopData < datalength))
1355 {
1356
1357 }
1358
1359
1360 uint32_t pDestination_zero_veil = 0;
1361 uint32_t pDestination = 0;
1362 uint32_t pDestinationOld = 0;
1363 int windowwidth = -1;
1364 int windowheight = -1;
1365 int w1 = -1;
1366 int w2 = -1;
1367 int value = -1;
1368 uint8_t colormask = 0;
1369
1370 // preparation
1371 windowheight = window->bottom - window->top;
1372 windowwidth = window->right - window->left;
1373 pDestination_zero_veil = hgfx->FBStartAdress + 2 * ( (479 - (drawVeilUntil - 2) ) + ( (window->left) * hgfx->ImageHeight) );
1374
1375 while((w1 <= windowwidth) & (w2 < datalength))
1376 {
1377 // before
1378 if(colour_data != NULL)
1379 {
1380 colormask = color + colour_data[w2];
1381 }
1382 pDestination = hgfx->FBStartAdress + 2 * ( (479 - (window->top + value) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
1383
1384 // after
1385 pDestination_zero_veil += (window->left) * hgfx->ImageHeight;
1386 }
1387 }
1388 */
1389
1390
1391
1392 // ===============================================================================
1393 // GFX_graph_print
1394 /// @brief Print all those nice curves, especially in logbook und miniLiveLogGraph
1395 /// @version 0.0.2 hw 160519
1396 ///
1397 /// 151022 hw -bug fix
1398 /// - die aktuelle Version macht keine Linien mehr �ber die gesamte Bildschirmh�he.
1399 /// - daf�r sind L�cher in der Kurve (z.B. Temperaturgraph Tauchgang Matthias 17.10.15 15:19)
1400 ///
1401 /// more details about range can be found in show_logbook_logbook_show_log_page2() - temperature graph
1402 ///
1403 /// @param window: top and bottom is only the range used by the data of the graph, not the entire screen / scale
1404 /// @param drawVeilUntil: ist auff�llen des Bereichs unter der Kurve mit etwas hellerer Farbe
1405 /// @param Xdivide: wird bisher nichr benutzt.
1406 // ===============================================================================
1407
1408
1409 void GFX_graph_print(GFX_DrawCfgScreen *hgfx, const SWindowGimpStyle *window, int16_t drawVeilUntil, uint8_t Xdivide, uint16_t dataMin, uint16_t dataMax, uint16_t *data, uint16_t datalength, uint8_t color, uint8_t *colour_data)
1410 {
1411 //uint32_t pDestination,pDestination_old,
1412 uint32_t pDestination_tmp,pDestination_end, pDestination_start, pDestination_zero_veil;
1413
1414 uint32_t max = 0;
1415 int windowheight = -1;
1416 int windowwidth = -1;
1417 int i = -1;
1418 int w1 = -1;
1419 int w2 = -1;
1420
1421 uint32_t h_ulong = 0;
1422 uint32_t h_ulong_old = 0;
1423 _Bool invert = 0;
1424
1425 uint16_t dataDelta = 0;
1426 uint16_t dataDeltaHalve = 0;
1427 uint16_t dataTemp = 0;
1428
1429 uint8_t colorDataTemp;
1430 uint8_t colormask = 0;
1431
1432 if(dataMin > dataMax)
1433 {
1434 uint16_t dataFlip;
1435 dataFlip = dataMin;
1436 dataMin = dataMax;
1437 dataMax = dataFlip;
1438 invert = 1;
1439 }
1440 else
1441 invert = 0;
1442
1443 colormask = color;
1444
1445
1446 if(window->bottom > 479)
1447 return;
1448 if(window->top > 479)
1449 return;
1450 if(window->right > 799)
1451 return;
1452 if(window->left > 799)
1453 return;
1454 if(window->bottom < 0)
1455 return;
1456 if(window->top < 0)
1457 return;
1458 if(window->right < 0)
1459 return;
1460 if(window->left < 0)
1461 return;
1462 if(window->bottom <= window->top)
1463 return;
1464 if(window->right <= window->left)
1465 return;
1466
1467 windowheight = window->bottom - window->top ;
1468 windowwidth = window->right - window->left;
1469 w1 = 0;
1470 w2 = 0;
1471 if(dataMax == dataMin)
1472 dataMax++;
1473 dataDelta = (unsigned long)(dataMax - dataMin);
1474 dataDeltaHalve = dataDelta / 2;
1475 while((w1 <= windowwidth) & (w2 < datalength))
1476 {
1477 int tmp = (10 * w1 * (long)datalength)/windowwidth;
1478 w2 = tmp/10;
1479 int rest = tmp - w2*10;
1480 if(rest >= 5)
1481 w2++;
1482
1483 if((datalength - 1) < w2)
1484 w2 = datalength-1;
1485
1486 if(colour_data != NULL)
1487 {
1488 colorDataTemp = colour_data[w2];
1489 colormask = color + colorDataTemp;
1490 }
1491
1492 dataTemp = data[w2];
1493 if(Xdivide > 1)
1494 {
1495 w2++;
1496 for(i=1;i<Xdivide;i++)
1497 {
1498 if(data[w2]>dataTemp)
1499 dataTemp = data[w2];
1500 w2++;
1501 }
1502 }
1503
1504 if(dataTemp > dataMin)
1505 dataTemp -= dataMin;
1506 else
1507 dataTemp = 0;
1508
1509 if(invert)
1510 {
1511 if(dataTemp < dataDelta)
1512 dataTemp = dataDelta - dataTemp;
1513 else
1514 dataTemp = 0;
1515 }
1516
1517 h_ulong = (unsigned long)dataTemp;
1518 h_ulong *= windowheight;
1519 h_ulong += dataDeltaHalve;
1520 h_ulong /= dataDelta;
1521
1522 if(h_ulong > (window->bottom - window->top))
1523 h_ulong = (window->bottom - window->top);
1524
1525 if(drawVeilUntil > 0)
1526 {
1527 pDestination_zero_veil = hgfx->FBStartAdress + 2 * ( (479 - (drawVeilUntil - 2) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
1528 }
1529 else if(drawVeilUntil < 0 )
1530 {
1531 pDestination_zero_veil = hgfx->FBStartAdress + 2 * ( (479 + (drawVeilUntil) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
1532 }
1533
1534 if(h_ulong + window->top > max)
1535 {
1536 max = h_ulong + window->top;
1537 }
1538
1539 // hw 160519 wof�r ist das? Damit funktioniert Temperatur 25,5�C nicht!
1540 // if((dataMax == 255) || (data[w2] != 255))
1541 // {
1542 //output_content[pointer] = colormask;
1543 //output_mask[pointer] = true;
1544 if(w1 > 0)
1545 {
1546 pDestination_start = hgfx->FBStartAdress + (2 * ((479 - (window->top)) + ((w1 + window->left) * hgfx->ImageHeight)));
1547 pDestination_end = pDestination_start;
1548 if(h_ulong >= h_ulong_old)
1549 {
1550 pDestination_start -= 2 * h_ulong_old;
1551 pDestination_end -= 2 * h_ulong;
1552 }
1553 else
1554 {
1555 pDestination_start -= 2 * h_ulong;
1556 pDestination_end -= 2 * h_ulong_old;
1557 }
1558
1559 // deco stops
1560 if(drawVeilUntil < 0)
1561 {
1562 pDestination_tmp = pDestination_end;
1563 while(pDestination_tmp <= pDestination_zero_veil)
1564 {
1565 *(__IO uint8_t*)pDestination_tmp = colormask;
1566 pDestination_tmp -= 1;
1567 *(__IO uint8_t*)pDestination_tmp = 0x80;
1568 pDestination_tmp += 3;
1569 }
1570 }
1571 else
1572 {
1573 // regular graph with veil underneath if requested
1574 // von oben nach unten
1575 // von grossen pDestination Werten zu kleinen pDestination Werten
1576 pDestination_tmp = pDestination_start;
1577 while(pDestination_tmp >= pDestination_end)
1578 {
1579 *(__IO uint8_t*)pDestination_tmp = colormask;
1580 pDestination_tmp += 1;
1581 *(__IO uint8_t*)pDestination_tmp = 0xFF;
1582 pDestination_tmp -= 3;
1583 }
1584 while((drawVeilUntil > 0) && (pDestination_tmp >= pDestination_zero_veil))
1585 {
1586 *(__IO uint8_t*)pDestination_tmp = colormask;
1587 pDestination_tmp += 1;
1588 *(__IO uint8_t*)pDestination_tmp = 0x20;
1589 pDestination_tmp -= 3;
1590 }
1591 }
1592 }
1593 h_ulong_old = h_ulong;
1594 // }
1595 w1++;
1596 w2++;
1597 }
1598 }
1599
1600
1601 void GFX_draw_header(GFX_DrawCfgScreen *hgfx, uint8_t colorId)
1602 {
1603 uint32_t pDestination;
1604 point_t start, stop, now;
1605 uint8_t alpha;
1606
1607 /* display coordinate system */
1608 start.y = 400;
1609 stop.y = 479;
1610
1611 start.x = 0;
1612 stop.x = 799;
1613
1614 now.y = start.y;
1615 now.x = start.x;
1616
1617 while (now.x <= stop.x)
1618 {
1619 now.y = start.y;
1620 pDestination = (uint32_t)hgfx->FBStartAdress;
1621 pDestination += now.x * hgfx->ImageHeight * 2;
1622 pDestination += now.y * 2;
1623 now.x += 1;
1624
1625 alpha = 27;
1626 while(alpha < 246)
1627 {
1628 alpha += 9;
1629 *(__IO uint8_t*)pDestination = colorId;
1630 pDestination += 1;
1631 *(__IO uint8_t*)pDestination = alpha;
1632 pDestination += 1;
1633 now.y += 1;
1634 }
1635
1636 while(now.y <= stop.y)
1637 {
1638 *(__IO uint8_t*)pDestination = colorId;
1639 pDestination += 1;
1640 *(__IO uint8_t*)pDestination = 0xFF;
1641 pDestination += 1;
1642 now.y += 1;
1643 }
1644 }
1645 }
1646
1647 void GFX_draw_box2(GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color, uint8_t roundCorners)
1648 {
1649 point_t point2, point4;
1650
1651 if(roundCorners)
1652 {
1653 point2.x = stop.x - start.x;
1654 point2.y = stop.y - start.y;
1655 GFX_draw_box(hgfx,start,point2,1,color);
1656 }
1657 else
1658 {
1659 point2.x = stop.x;
1660 point2.y = start.y;
1661
1662 point4.x = start.x;
1663 point4.y = stop.y;
1664
1665 GFX_draw_line(hgfx,start,point2,color);
1666 GFX_draw_line(hgfx,point2,stop,color);
1667 GFX_draw_line(hgfx,stop,point4,color);
1668 GFX_draw_line(hgfx,point4,start,color);
1669 }
1670 }
1671
1672 void GFX_draw_box(GFX_DrawCfgScreen *hgfx, point_t LeftLow, point_t WidthHeight, uint8_t Style, uint8_t color)
1673 {
1674 uint32_t pDestination, pStart;
1675 uint32_t j;
1676 uint32_t lineWidth, lineHeight;
1677 int x, y;
1678 uint8_t intensity;
1679
1680 typedef struct {
1681 int x;
1682 int y;
1683 uint8_t intensity;
1684 } corner_t;
1685 const corner_t corner[16] = {
1686 {3,3,255}, // nur einmal
1687 {9,0,242},
1688 {8,0,194},
1689 {7,0,115},
1690 {6,0,36},
1691 {9,1,33},
1692 {8,1,84},
1693 {7,1,161},
1694 {6,1,255},
1695 {5,1,242},
1696 {4,1,36},
1697 {6,2,33},
1698 {5,2,84},
1699 {4,2,255},
1700 {3,2,84},
1701 {4,3,110}
1702 };
1703
1704 lineWidth = WidthHeight.x;
1705 lineHeight = WidthHeight.y;
1706
1707 pStart = (uint32_t)hgfx->FBStartAdress;
1708 pStart += LeftLow.x * hgfx->ImageHeight * 2;
1709 pStart += LeftLow.y * 2;
1710
1711 // Untere Linie
1712 pDestination = pStart;
1713 if(Style)
1714 {
1715 pDestination += 2 * 10 * hgfx->ImageHeight;
1716 lineWidth -= 18;
1717 }
1718 for (j = lineWidth; j > 0; j--)
1719 {
1720 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1721 pDestination += hgfx->ImageHeight * 2;
1722 }
1723
1724 // Obere Linie
1725 pDestination = pStart + 2 * WidthHeight.y;
1726 if(Style)
1727 {
1728 pDestination += 2 * 10 * hgfx->ImageHeight;
1729 }
1730
1731 for (j = lineWidth; j > 0; j--)
1732 {
1733 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1734 pDestination += hgfx->ImageHeight * 2;
1735 }
1736
1737 // Linke Linie
1738 pDestination = pStart;
1739 if(Style)
1740 {
1741 pDestination += 2 * 10;
1742 lineHeight -= 18;
1743 }
1744
1745 for (j = lineHeight; j > 0; j--)
1746 {
1747 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1748 pDestination += 2;
1749 }
1750
1751 // Rechte Linie
1752 pDestination = pStart + 2 * WidthHeight.x * hgfx->ImageHeight;
1753 if(Style)
1754 {
1755 pDestination += 2 * 10;
1756 }
1757
1758 for (j = lineHeight; j > 0; j--)
1759 {
1760 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1761 pDestination += 2;
1762 }
1763
1764 // Ecken wenn notwendig == Style
1765 if(Style)
1766 {
1767 // links unten
1768 pDestination = pStart;
1769 x = corner[0].x;
1770 y = corner[0].y;
1771 intensity = corner[0].intensity;
1772 *(__IO uint16_t*)(pDestination + 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1773
1774 for(j = 15; j > 0; j--)
1775 {
1776 x = corner[j].x;
1777 y = corner[j].y;
1778 intensity = corner[j].intensity;
1779 *(__IO uint16_t*)(pDestination + 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1780 *(__IO uint16_t*)(pDestination + 2 * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1781 }
1782 // links oben
1783 pDestination = pStart + 2 * WidthHeight.y;
1784 x = corner[0].x;
1785 y = corner[0].y;
1786 intensity = corner[0].intensity;
1787 *(__IO uint16_t*)(pDestination + 2 * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1788
1789 for(j = 15; j > 0; j--)
1790 {
1791 x = corner[j].x;
1792 y = corner[j].y;
1793 intensity = corner[j].intensity;
1794 *(__IO uint16_t*)(pDestination + 2 * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1795 *(__IO uint16_t*)(pDestination + 2 * (-x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1796 }
1797 // rechts unten
1798 pDestination = pStart + 2 * WidthHeight.x * hgfx->ImageHeight;
1799 x = corner[0].x;
1800 y = corner[0].y;
1801 intensity = corner[0].intensity;
1802 *(__IO uint16_t*)(pDestination + 2 * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1803
1804 for(j = 15; j > 0; j--)
1805 {
1806 x = corner[j].x;
1807 y = corner[j].y;
1808 intensity = corner[j].intensity;
1809 *(__IO uint16_t*)(pDestination + 2 * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1810 *(__IO uint16_t*)(pDestination + 2 * (x - (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1811 }
1812 // rechts oben
1813 pDestination = pStart + 2 * WidthHeight.y + 2 * WidthHeight.x * hgfx->ImageHeight;
1814 x = corner[0].x;
1815 y = corner[0].y;
1816 intensity = corner[0].intensity;
1817 *(__IO uint16_t*)(pDestination - 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1818
1819 for(j = 15; j > 0; j--)
1820 {
1821 x = corner[j].x;
1822 y = corner[j].y;
1823 intensity = corner[j].intensity;
1824 *(__IO uint16_t*)(pDestination - 2 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1825 *(__IO uint16_t*)(pDestination - 2 * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1826 }
1827 }
1828 }
1829
1830
1831
1832
1833 /**
1834 ******************************************************************************
1835 * @brief GFX write label. / Write string with defined color
1836 * @author heinrichs weikamp gmbh
1837 * @version V0.0.1
1838 * @date 07-July-2014
1839 ******************************************************************************
1840 *
1841 * @param hgfx: check gfx_engine.h.
1842 * @param color: 16bit Alpha+CLUT.
1843 * @retval None
1844 */
1845
1846 uint32_t GFX_write_label(const tFont *Font, GFX_DrawCfgWindow* hgfx, const char *pText, uint8_t color)
1847 {
1848 return GFX_write_string_color(Font, hgfx, pText, 0, color);
1849 }
1850
1851
1852 /**
1853 ******************************************************************************
1854 * @brief GFX writeGfx_write_label_varstring. / Write string with all parameters and font color options
1855 * @author Peter Ryser
1856 * @version V0.0.1
1857 * @date 22-April-2014
1858 ******************************************************************************
1859 *
1860 * @param XleftGimpStyle:
1861 * @param XrightGimpStyle:
1862 * @param YtopGimpStyle:
1863 * @param color:
1864 * @param tFont:
1865 * @param text: text to be printed
1866 * @retval None
1867 */
1868
1869 void Gfx_write_label_var(GFX_DrawCfgScreen *screenInput, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const uint8_t color, const char *text)
1870 {
1871
1872 GFX_DrawCfgWindow hgfx;
1873
1874 if(XrightGimpStyle > 799)
1875 XrightGimpStyle = 799;
1876 if(XleftGimpStyle >= XrightGimpStyle)
1877 XleftGimpStyle = 0;
1878 if(YtopGimpStyle > 479)
1879 YtopGimpStyle = 479;
1880 hgfx.Image = screenInput;
1881 hgfx.WindowNumberOfTextLines = 1;
1882 hgfx.WindowLineSpacing = 0;
1883 hgfx.WindowTab = 0;
1884 hgfx.WindowX0 = XleftGimpStyle;
1885 hgfx.WindowX1 = XrightGimpStyle;
1886 hgfx.WindowY1 = 479 - YtopGimpStyle;
1887 if(hgfx.WindowY1 < Font->height)
1888 hgfx.WindowY0 = 0;
1889 else
1890 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
1891
1892 GFX_write_label(Font, &hgfx, text, color);
1893 }
1894
1895 /**
1896 ******************************************************************************
1897 * @brief GFX write string. / Write string with all parameters and font options
1898 * @author heinrichs weikamp gmbh
1899 * @version V0.0.1
1900 * @date 22-April-2014
1901 ******************************************************************************
1902 *
1903 * @param hgfx: check gfx_engine.h.
1904 * @param color: 32bit ARGB8888.
1905 * @retval None
1906 */
1907
1908 uint16_t GFX_return_offset(const tFont *Font, char *pText, uint8_t position)
1909 {
1910 char character;
1911 uint16_t digit, i;
1912 uint8_t found;
1913 uint16_t distance;
1914
1915 if(position == 0)
1916 return 0;
1917
1918 distance = 0;
1919 for(digit = 0; digit < position; digit++)
1920 {
1921 character = pText[digit];
1922 if(character == 0)
1923 return 0;
1924
1925 found = 0;
1926 for(i=0;i<Font->length;i++)
1927 {
1928 if(Font->chars[i].code == character)
1929 {
1930 found = 1;
1931 break;
1932 }
1933 }
1934 if(found)
1935 {
1936 distance += (uint16_t)(Font->chars[i].image->width);
1937 if(Font == &FontT144)
1938 distance += 3;
1939 else
1940 if(Font == &FontT105)
1941 distance += 2;
1942 }
1943 }
1944 return distance;
1945
1946 /* FEHLT:
1947 if(*pText < ' ')
1948 if((*pText) & 0x80)
1949
1950 if(((tFont *)settings.font == &FontT105) && settings.dualFont && ((*pText == '.') || (*pText == ':')))
1951 settings.font = (uint32_t)&FontT54;
1952 */
1953 }
1954
1955 void GFX_clean_line(GFX_DrawCfgWindow* hgfx, uint32_t line_number)
1956 {
1957 uint16_t height;
1958 uint32_t pDestination, i, j;
1959 uint16_t left, width, bottom, nextlineStep;
1960
1961 bottom = hgfx->WindowY0;
1962
1963 if(hgfx->WindowNumberOfTextLines && line_number && (line_number <= hgfx->WindowNumberOfTextLines))
1964 {
1965 bottom += hgfx->WindowLineSpacing * (hgfx->WindowNumberOfTextLines - line_number);
1966 height = hgfx->WindowLineSpacing;
1967 }
1968 else
1969 {
1970 height = 1 + hgfx->WindowY1 - bottom;
1971 }
1972
1973 pDestination = (uint32_t)hgfx->Image->FBStartAdress;
1974
1975 left = hgfx->WindowX0;
1976 width = 1 + hgfx->WindowX1 - left;
1977 nextlineStep = hgfx->Image->ImageHeight - height;
1978 nextlineStep *= 2;
1979 pDestination += 2 * bottom;
1980 pDestination += 2 * hgfx->Image->ImageHeight * left;
1981
1982 for(j = width; j > 0; j--)
1983 {
1984 for(i = height; i > 0; i--)
1985 {
1986 *(__IO uint16_t*)pDestination = 0;
1987 pDestination += 2;
1988 }
1989 pDestination += nextlineStep;
1990 }
1991 }
1992
1993
1994 void GFX_clean_area(GFX_DrawCfgScreen *tMscreen, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, uint16_t YBottomGimpStyle)
1995 {
1996 uint16_t height;
1997 uint32_t pDestination, i, j;
1998 int32_t left, width, bottom, nextlineStep;
1999
2000 bottom = tMscreen->ImageHeight - YBottomGimpStyle;
2001 height = 1 + YBottomGimpStyle - YtopGimpStyle;
2002
2003 if(bottom < 0)
2004 bottom = 0;
2005 if(height > tMscreen->ImageHeight)
2006 height = tMscreen->ImageHeight;
2007
2008 pDestination = tMscreen->FBStartAdress;
2009
2010 left = XleftGimpStyle;
2011 width = 1 + XrightGimpStyle - left;
2012 if(width < 1)
2013 width = 1;
2014
2015 if(width > tMscreen->ImageWidth)
2016 width = tMscreen->ImageWidth;
2017
2018 nextlineStep = tMscreen->ImageHeight - height;
2019 nextlineStep *= 2;
2020 pDestination += 2 * bottom;
2021 pDestination += 2 * tMscreen->ImageHeight * left;
2022
2023 for(j = width; j > 0; j--)
2024 {
2025 for(i = height; i > 0; i--)
2026 {
2027 *(__IO uint16_t*)pDestination = 0;
2028 pDestination += 2;
2029 }
2030 pDestination += nextlineStep;
2031 }
2032 }
2033
2034
2035 uint32_t GFX_write_string(const tFont *Font, GFX_DrawCfgWindow* hgfx, const char *pText, uint32_t line_number)
2036 {
2037 return GFX_write_string_color(Font, hgfx, pText, line_number, 0);
2038 }
2039
2040 uint32_t GFX_write_string_color(const tFont *Font, GFX_DrawCfgWindow* hgfx, const char *pText, uint32_t line_number, uint8_t color)
2041 {
2042 if(hgfx->Image->FBStartAdress < FBGlobalStart)
2043 return 0;
2044
2045 GFX_CfgWriteString settings;
2046 uint32_t newXdelta;
2047 uint8_t minimal = 0;
2048 // uint32_t try_again;
2049
2050 if(hgfx->WindowNumberOfTextLines && line_number && (line_number <= hgfx->WindowNumberOfTextLines))
2051 {
2052 settings.Ydelta = hgfx->WindowLineSpacing * (hgfx->WindowNumberOfTextLines - line_number);
2053 }
2054 else
2055 {
2056 settings.Ydelta = 0;
2057 }
2058 settings.font = (uint32_t)Font;
2059 settings.Xdelta = 0;
2060 settings.color = color;
2061 settings.invert = 0;
2062 settings.resize = 0;
2063 settings.dualFont = 0;
2064 settings.spaceMode = 0;
2065 settings.singleSpaceWithSizeOfNextChar = 0;
2066 settings.useTinyFont = 0;
2067 settings.TinyFontExtraYdelta = 0;
2068 settings.TinyFont = (uint32_t)Font;
2069 settings.doubleSize = 0;
2070
2071 if((*pText) == TXT_MINIMAL) // for customtext and anything with Sonderzeichen
2072 minimal = 1;
2073 else
2074 minimal = 0;
2075
2076 if(Font == &FontT144)
2077 settings.TinyFont = (uint32_t)&FontT84;
2078 else
2079 if(Font == &FontT105)
2080 settings.TinyFont = (uint32_t)&FontT54;
2081 else
2082 if(Font == &FontT54)
2083 {
2084 settings.TinyFont = (uint32_t)&FontT48;
2085 settings.TinyFontExtraYdelta = -9;
2086 }
2087 else
2088 if(Font == &FontT48)
2089 {
2090 settings.TinyFont = (uint32_t)&FontT24;
2091 settings.TinyFontExtraYdelta = 6;
2092 }
2093 else
2094 if(Font == &FontT42)
2095 {
2096 settings.TinyFont = (uint32_t)&FontT24;
2097 settings.TinyFontExtraYdelta = 2;
2098 }
2099
2100 settings.actualFont = (tFont *)settings.font;
2101
2102 while ((*pText != 0) && (settings.Xdelta != 0x0000FFFF))// und fehlend: Abfrage window / image size
2103 {
2104 // try_again = 0;
2105
2106 if((*pText == '\177') && !minimal)
2107 {
2108 if(settings.singleSpaceWithSizeOfNextChar)
2109 {
2110 settings.singleSpaceWithSizeOfNextChar = 0;
2111 pText++;
2112 settings.Xdelta += *pText;
2113 }
2114 else
2115 settings.singleSpaceWithSizeOfNextChar = 1;
2116 }
2117 else
2118 if(*pText < ' ')
2119 {
2120 /* Xdelta -inline- changes */
2121 if((*pText == '\t') && !minimal)
2122 settings.Xdelta = hgfx->WindowTab - hgfx->WindowX0;
2123 else
2124 if(*pText == '\r') // carriage return, no newline
2125 settings.Xdelta = 0;
2126 else
2127 if((*pText == '\001') && !minimal) // center
2128 settings.Xdelta = GFX_write__Modify_Xdelta__Centered(&settings, hgfx, pText+1);
2129 else
2130 if((*pText == '\002') && !minimal) // right
2131 settings.Xdelta = GFX_write__Modify_Xdelta__RightAlign(&settings, hgfx, pText+1);
2132 else
2133 if((*pText == '\003') && !minimal) // doubleSize
2134 settings.doubleSize = 1;
2135 else
2136 /* Xdelta -up/down changes */
2137 if((*pText == '\f') && !minimal) // form feed = top align
2138 {
2139 if((hgfx->WindowY1 - hgfx->WindowY0) >= ((tFont *)settings.font)->height)
2140 {
2141 settings.Ydelta = hgfx->WindowY1 - hgfx->WindowY0;
2142 settings.Ydelta -= ((tFont *)settings.font)->height;
2143 }
2144 }
2145 else
2146 if(*pText == '\n') // newline, no carriage return
2147 {
2148 if(hgfx->WindowNumberOfTextLines && (line_number < hgfx->WindowNumberOfTextLines))
2149 {
2150 line_number++;
2151 settings.Ydelta = hgfx->WindowLineSpacing * (hgfx->WindowNumberOfTextLines - line_number);
2152 }
2153 }
2154 else
2155 /* Font style changes */
2156 if(*pText == '\a')
2157 settings.invert = 1;
2158 else
2159 if((*pText == '\016') && !minimal)
2160 {
2161 if(settings.dualFont == 0)
2162 settings.dualFont = 1;
2163 else
2164 settings.actualFont = (tFont *)settings.TinyFont;
2165 }
2166 else
2167 if((*pText == '\017') && !minimal)
2168 {
2169 settings.dualFont = 0;
2170 settings.actualFont = (tFont *)settings.font;
2171 }
2172 else
2173 if((*pText == '\005') && !minimal)
2174 {
2175 newXdelta = GFX_write_char(hgfx, &settings, 'a', (tFont *)&Awe48);
2176 settings.Xdelta = newXdelta;
2177 }
2178 else
2179 if((*pText == '\006') && !minimal)
2180 {
2181 newXdelta = GFX_write_char(hgfx, &settings, 'b', (tFont *)&Awe48);
2182 settings.Xdelta = newXdelta;
2183 }
2184 else
2185 if((*pText >= '\020') && (*pText <= '\032') && !minimal)
2186 settings.color = *pText - '\020';
2187 else
2188 if((*pText == '\034') && !minimal)
2189 settings.spaceMode = 1;
2190 else
2191 if((*pText == '\035') && !minimal)
2192 settings.spaceMode = 0;
2193 }
2194 else
2195 if(((*pText) == TXT_2BYTE) && !minimal)
2196 {
2197 pText++;
2198 settings.Xdelta = GFX_write_substring(&settings, hgfx, (uint8_t)TXT_2BYTE, (int8_t)*pText);
2199 }
2200 else
2201 if(((*pText) & 0x80) && !minimal)
2202 settings.Xdelta = GFX_write_substring(&settings, hgfx, (uint8_t)*pText, 0);
2203 else
2204 if(!settings.invert && (*pText == ' '))
2205 {
2206 if(settings.spaceMode == 0)
2207 settings.Xdelta += ((tFont *)settings.font)->spacesize;
2208 else
2209 settings.Xdelta += ((tFont *)settings.font)->spacesize2Monospaced;
2210 }
2211 else
2212 if((settings.spaceMode == 1) && (*pText == ' '))
2213 settings.Xdelta += ((tFont *)settings.font)->spacesize2Monospaced;
2214 else
2215 {
2216 if(((tFont *)settings.font == &FontT144) && ((*pText == '.') || (*pText == ':')))
2217 settings.actualFont = (tFont *)settings.TinyFont;
2218 else
2219 if(((tFont *)settings.font == &FontT105) && settings.dualFont && ((*pText == '.') || (*pText == ':')))
2220 settings.actualFont = (tFont *)settings.TinyFont;
2221
2222 if(settings.actualFont == (tFont *)settings.TinyFont)
2223 settings.Ydelta += settings.TinyFontExtraYdelta;
2224
2225 newXdelta = GFX_write_char(hgfx, &settings, *(uint8_t *)pText, settings.actualFont);
2226 settings.Xdelta = newXdelta;
2227
2228 if(settings.actualFont == (tFont *)settings.TinyFont)
2229 settings.Ydelta -= settings.TinyFontExtraYdelta;
2230 }
2231 if(pText != 0) /* for TXT_2BYTE */
2232 pText++;
2233 }
2234 return settings.Ydelta;
2235 }
2236
2237 /* Private functions ---------------------------------------------------------*/
2238 /******************************************************************************
2239 Static Function
2240 *******************************************************************************/
2241
2242 /**
2243 ******************************************************************************
2244 * @brief GFX write substring. / Write string without parameters
2245 * @author heinrichs weikamp gmbh
2246 * @version V0.0.1
2247 * @date 22-April-2014
2248 ******************************************************************************
2249 *
2250 * @param hgfx: check gfx_engine.h.
2251 * @param color: 32bit ARGB8888.
2252 * @retval None
2253 */
2254
2255 static uint32_t GFX_write_substring(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, uint8_t textId, int8_t nextCharFor2Byte)
2256 {
2257 uint8_t i, j;
2258 uint32_t found;
2259 uint32_t pText;
2260 uint8_t gfx_selected_language;
2261 #ifndef BOOTLOADER_STANDALONE
2262 SSettings *pSettings;
2263 pSettings = settingsGetPointer();
2264 gfx_selected_language = pSettings->selected_language;
2265 if(gfx_selected_language >= LANGUAGE_END)
2266 #endif
2267 gfx_selected_language = 0;
2268 // -----------------------------
2269 if(textId != (uint8_t)TXT_2BYTE)
2270 {
2271 found = 0;
2272 j = 0;
2273 for(i=(uint8_t)TXT_Language;i<(uint8_t)TXT_END;i++)
2274 {
2275 if(text_array[j].code == textId)
2276 {
2277 found = 1;
2278 break;
2279 }
2280 j++;
2281 }
2282 if(!found)
2283 return cfg->Xdelta;
2284 // -----------------------------
2285 pText = (uint32_t)text_array[j].text[gfx_selected_language];
2286 if(!pText)
2287 pText = (uint32_t)text_array[j].text[0];
2288 else
2289 if(*(char*)pText == 0)
2290 pText = (uint32_t)text_array[j].text[0];
2291 }
2292 // -----------------------------
2293 else
2294 {
2295 if(!nextCharFor2Byte)
2296 return cfg->Xdelta;
2297
2298 found = 0;
2299 for(j=0;j<(uint8_t)TXT2BYTE_END-(uint8_t)TXT2BYTE_START;j++)
2300 {
2301 if((uint8_t)text_array2[j].code == (uint8_t)nextCharFor2Byte)
2302 {
2303 found = 1;
2304 break;
2305 }
2306 }
2307 if(!found)
2308 return cfg->Xdelta;
2309 // -----------------------------
2310 pText = (uint32_t)text_array2[j].text[gfx_selected_language];
2311 if(!pText)
2312 pText = (uint32_t)text_array2[j].text[0];
2313 else
2314 if(*(char*)pText == 0)
2315 pText = (uint32_t)text_array2[j].text[0];
2316 }
2317 // -----------------------------
2318
2319 if(cfg->actualFont == (tFont *)cfg->TinyFont)
2320 cfg->Ydelta += cfg->TinyFontExtraYdelta;
2321
2322 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
2323 {
2324 if(*(char*)pText == '\t')
2325 cfg->Xdelta = hgfx->WindowTab - hgfx->WindowX0;
2326 else
2327 if(*(char*)pText == ' ')
2328 cfg->Xdelta += ((tFont *)cfg->actualFont)->spacesize;
2329 else
2330 cfg->Xdelta = GFX_write_char(hgfx, cfg, *(uint8_t *)pText, (tFont *)cfg->actualFont);
2331
2332 pText++;
2333 }
2334
2335 if(cfg->actualFont == (tFont *)cfg->TinyFont)
2336 cfg->Ydelta -= cfg->TinyFontExtraYdelta;
2337
2338 return cfg->Xdelta;
2339 }
2340
2341
2342 /**
2343 ******************************************************************************
2344 * @brief GFX write char. / Write non-inverted, non-colored with entire 8 bit range
2345 * @author heinrichs weikamp gmbh
2346 * @version V0.0.1
2347 * @date 22-April-2014
2348 ******************************************************************************
2349 *
2350 * @param hgfx: check gfx_engine.h.
2351 * @param Ydelta: input
2352 * @param character: character
2353 * @param *Font: pointer to font to be used for this char
2354 * @retval Ydelta: 0x0000FFFF if not successful or char_truncated
2355 */
2356
2357 static uint32_t GFX_write_char_doubleSize(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font)
2358 {
2359 uint32_t i, j;
2360 uint32_t width, height;
2361 uint32_t found;
2362 uint32_t pDestination;
2363 uint32_t pDestinationColor;
2364 uint32_t pSource;
2365 uint32_t OffsetDestination;
2366 uint32_t width_left;
2367 uint32_t height_left;
2368 uint32_t char_truncated_WidthFlag;
2369 uint32_t char_truncated_Height;
2370 uint8_t fill;
2371 uint32_t widthFont, heightFont;
2372 uint32_t nextLine;
2373
2374
2375 if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
2376 return 0x0000FFFF;
2377
2378 // -----------------------------
2379 found = 0;
2380 for(i=0;i<Font->length;i++)
2381 {
2382 if(Font->chars[i].code == character)
2383 {
2384 found = 1;
2385 break;
2386 }
2387 }
2388 if(!found)
2389 return cfg->Xdelta;
2390
2391 pSource = ((uint32_t)Font->chars[i].image->data);
2392 pDestination = 1 + (uint32_t)hgfx->Image->FBStartAdress;
2393
2394 heightFont = Font->chars[i].image->height;
2395 widthFont = Font->chars[i].image->width;
2396
2397 height = heightFont*2;
2398 width = widthFont*2;
2399
2400 OffsetDestination = 2 * (hgfx->Image->ImageHeight - height);
2401
2402 pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight * 2;
2403 pDestination += (hgfx->WindowY0 + cfg->Ydelta) * 2;
2404 nextLine = hgfx->Image->ImageHeight * 2;
2405
2406 // -----------------------------
2407 char_truncated_WidthFlag = 0;
2408 width_left = hgfx->Image->ImageWidth - (hgfx->WindowX0 + cfg->Xdelta);
2409 if(width_left < width)
2410 {
2411 char_truncated_WidthFlag = 1;
2412 width = width_left;
2413 widthFont = width/2;
2414 }
2415 // -----------------------------
2416 char_truncated_Height = 0;
2417 height_left = hgfx->Image->ImageHeight - (hgfx->WindowY0 + cfg->Ydelta);
2418 if(height_left < height)
2419 {
2420 char_truncated_Height = height - height_left;
2421 if((char_truncated_Height & 1) != 0)
2422 {
2423 height_left -= 1;
2424 char_truncated_Height += 1;
2425 }
2426 height = height_left;
2427 heightFont = height/2;
2428 }
2429 OffsetDestination += 2 * char_truncated_Height;
2430 // -----------------------------
2431 if(height == 0)
2432 return 0x0000FFFF;
2433 // -----------------------------
2434
2435 if((cfg->color > 0) )
2436 {
2437 pDestinationColor = pDestination - 1;
2438
2439 for(i = width; i > 0; i--)
2440 {
2441 for (j = height; j > 0; j--)
2442 {
2443 *(__IO uint32_t*)pDestinationColor = cfg->color;
2444 pDestinationColor += 2;
2445 }
2446 pDestinationColor += OffsetDestination;
2447 }
2448 }
2449
2450 if(cfg->singleSpaceWithSizeOfNextChar)
2451 {
2452 cfg->singleSpaceWithSizeOfNextChar = 0;
2453
2454 if(cfg->invert)
2455 fill = 0xFF;
2456 else
2457 fill = 0;
2458
2459 height /= 2;
2460 for(i = width; i > 0; i--)
2461 {
2462 for (j = height; j > 0; j--)
2463 {
2464 *(__IO uint8_t*)pDestination = fill;
2465 pDestination += 2;
2466 *(__IO uint8_t*)pDestination = fill;
2467 pDestination += 2;
2468 }
2469 pDestination += OffsetDestination;
2470 }
2471 }
2472 else
2473 if(cfg->invert)
2474 {
2475 if((heightFont & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2476 {
2477 heightFont /= 4;
2478 for(i = widthFont; i > 0; i--)
2479 {
2480 if(*(uint8_t*)pSource != 0x01)
2481 {
2482 for (j = heightFont; j > 0; j--)
2483 {
2484 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2485 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2486 pDestination += 2;
2487 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2488 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2489 pSource++;
2490 pDestination += 2;
2491
2492 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2493 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2494 pDestination += 2;
2495 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2496 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2497 pSource++;
2498 pDestination += 2;
2499
2500 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2501 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2502 pDestination += 2;
2503 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2504 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2505 pSource++;
2506 pDestination += 2;
2507
2508 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2509 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2510 pDestination += 2;
2511 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2512 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2513 pSource++;
2514 pDestination += 2;
2515 }
2516 pSource += char_truncated_Height;
2517 }
2518 else
2519 {
2520 pSource++;
2521 for (j = height; j > 0; j--)
2522 {
2523 *(__IO uint8_t*)pDestination = 0xFF;
2524 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2525 pDestination += 2;
2526 *(__IO uint8_t*)pDestination = 0xFF;
2527 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2528 pDestination += 2;
2529 *(__IO uint8_t*)pDestination = 0xFF;
2530 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2531 pDestination += 2;
2532 *(__IO uint8_t*)pDestination = 0xFF;
2533 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2534 pDestination += 2;
2535 *(__IO uint8_t*)pDestination = 0xFF;
2536 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2537 pDestination += 2;
2538 *(__IO uint8_t*)pDestination = 0xFF;
2539 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2540 pDestination += 2;
2541 *(__IO uint8_t*)pDestination = 0xFF;
2542 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2543 pDestination += 2;
2544 *(__IO uint8_t*)pDestination = 0xFF;
2545 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2546 pDestination += 2;
2547 }
2548 }
2549 pDestination += OffsetDestination + nextLine;
2550 }
2551 }
2552 else
2553 {
2554 heightFont /= 2;
2555 for(i = widthFont; i > 0; i--)
2556 {
2557 if(*(uint8_t*)pSource != 0x01)
2558 {
2559 for (j = heightFont; j > 0; j--)
2560 {
2561 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2562 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2563 pDestination += 2;
2564 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2565 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2566 pSource++;
2567 pDestination += 2;
2568
2569 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2570 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2571 pDestination += 2;
2572 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2573 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF - *(uint8_t*)pSource;
2574 pSource++;
2575 pDestination += 2;
2576 }
2577 pSource += char_truncated_Height;
2578 }
2579 else
2580 {
2581 pSource++;
2582 for (j = heightFont; j > 0; j--)
2583 {
2584 *(__IO uint8_t*)pDestination = 0xFF;
2585 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2586 pDestination += 2;
2587 *(__IO uint8_t*)pDestination = 0xFF;
2588 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2589 pDestination += 2;
2590 *(__IO uint8_t*)pDestination = 0xFF;
2591 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2592 pDestination += 2;
2593 *(__IO uint8_t*)pDestination = 0xFF;
2594 *(__IO uint8_t*)(pDestination + nextLine) = 0xFF;
2595 pDestination += 2;
2596 }
2597 }
2598 pDestination += OffsetDestination + nextLine;
2599 }
2600 }
2601 }
2602 else
2603 {
2604 if((heightFont & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2605 {
2606 heightFont /= 4;
2607 for(i = widthFont; i > 0; i--)
2608 {
2609 if(*(uint8_t*)pSource != 0x01)
2610 {
2611 for (j = heightFont; j > 0; j--)
2612 {
2613 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2614 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2615 pDestination += 2;
2616 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2617 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2618 pSource++;
2619 pDestination += 2;
2620
2621 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2622 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2623 pDestination += 2;
2624 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2625 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2626 pSource++;
2627 pDestination += 2;
2628
2629 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2630 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2631 pDestination += 2;
2632 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2633 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2634 pSource++;
2635 pDestination += 2;
2636
2637 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2638 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2639 pDestination += 2;
2640 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2641 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2642 pSource++;
2643 pDestination += 2;
2644 }
2645 pSource += char_truncated_Height;
2646 }
2647 else
2648 {
2649 pSource++;
2650 pDestination += 2 * height;
2651 }
2652 pDestination += OffsetDestination + nextLine;
2653 }
2654 }
2655 else
2656 {
2657 heightFont /= 2;
2658 for(i = widthFont; i > 0; i--)
2659 {
2660 if(*(uint8_t*)pSource != 0x01)
2661 {
2662 for (j = heightFont; j > 0; j--)
2663 {
2664 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2665 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2666 pDestination += 2;
2667 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2668 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2669 pSource++;
2670 pDestination += 2;
2671
2672 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2673 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2674 pDestination += 2;
2675 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2676 *(__IO uint8_t*)(pDestination + nextLine) = *(uint8_t*)pSource;
2677 pSource++;
2678 pDestination += 2;
2679 }
2680 pSource += char_truncated_Height;
2681 }
2682 else
2683 {
2684 pSource++;
2685 pDestination += 2 * height;
2686 }
2687 pDestination += OffsetDestination + nextLine;
2688 }
2689 }
2690 }
2691
2692 // -----------------------------
2693
2694 if(Font == &FontT144)
2695 width += 6;
2696 else
2697 if(Font == &FontT105)
2698 width += 4;
2699
2700 // -----------------------------
2701
2702 if(char_truncated_WidthFlag)
2703 return 0x0000FFFF;
2704 else
2705 return cfg->Xdelta + width;
2706
2707 }
2708
2709
2710 /**
2711 ******************************************************************************
2712 * @brief GFX write char. / Write non-inverted, non-colored with entire 8 bit range
2713 * @author heinrichs weikamp gmbh
2714 * @version V0.0.1
2715 * @date 22-April-2014
2716 ******************************************************************************
2717 *
2718 * @param hgfx: check gfx_engine.h.
2719 * @param Ydelta: input
2720 * @param character: character
2721 * @param *Font: pointer to font to be used for this char
2722 * @retval Ydelta: 0x0000FFFF if not successful or char_truncated
2723 */
2724
2725 static uint32_t GFX_write_char(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font)
2726 {
2727 if(cfg->doubleSize)
2728 {
2729 return GFX_write_char_doubleSize(hgfx, cfg, character, Font);
2730 }
2731
2732 uint32_t i, j;
2733 uint32_t width, height;
2734 uint32_t found;
2735 uint32_t pDestination;
2736 uint32_t pDestinationColor;
2737 uint32_t pSource;
2738 uint32_t OffsetDestination;
2739 uint32_t width_left;
2740 uint32_t height_left;
2741 uint32_t char_truncated_WidthFlag;
2742 uint32_t char_truncated_Height;
2743 uint8_t fill;
2744
2745 if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
2746 return 0x0000FFFF;
2747
2748 // -----------------------------
2749 found = 0;
2750 for(i=0;i<Font->length;i++)
2751 {
2752 if(Font->chars[i].code == character)
2753 {
2754 found = 1;
2755 break;
2756 }
2757 }
2758 if(!found)
2759 return cfg->Xdelta;
2760 // -----------------------------
2761 /*
2762 if(Font == &Font144)
2763 cfg->Xdelta += 3;
2764 else
2765 if(Font == &Font84)
2766 cfg->Xdelta += 2;
2767 */
2768 // -----------------------------
2769
2770
2771 pSource = ((uint32_t)Font->chars[i].image->data);
2772 pDestination = 1 + (uint32_t)hgfx->Image->FBStartAdress;
2773
2774 height = Font->chars[i].image->height;
2775 width = Font->chars[i].image->width;
2776
2777 OffsetDestination = 2 * (hgfx->Image->ImageHeight - height);
2778
2779 pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight * 2;
2780 pDestination += (hgfx->WindowY0 + cfg->Ydelta) * 2;
2781
2782
2783
2784 // -----------------------------
2785 char_truncated_WidthFlag = 0;
2786 width_left = hgfx->Image->ImageWidth - (hgfx->WindowX0 + cfg->Xdelta);
2787 if(width_left < width)
2788 {
2789 char_truncated_WidthFlag = 1;
2790 width = width_left;
2791 }
2792 // -----------------------------
2793 char_truncated_Height = 0;
2794 height_left = hgfx->Image->ImageHeight - (hgfx->WindowY0 + cfg->Ydelta);
2795 if(height_left < height)
2796 {
2797 char_truncated_Height = height - height_left;
2798 if((char_truncated_Height & 1) != 0)
2799 {
2800 height_left -= 1;
2801 char_truncated_Height += 1;
2802 }
2803 height = height_left;
2804 }
2805 OffsetDestination += 2 * char_truncated_Height;
2806 // -----------------------------
2807 if(height == 0)
2808 return 0x0000FFFF;
2809 // -----------------------------
2810
2811 if((cfg->color > 0) )//&& (cfg->color < 6))
2812 {
2813 pDestinationColor = pDestination - 1;
2814
2815 for(i = width; i > 0; i--)
2816 {
2817 for (j = height; j > 0; j--)
2818 {
2819 *(__IO uint32_t*)pDestinationColor = cfg->color;//ColorLUT[cfg->color - 1];
2820 pDestinationColor += 2;
2821 }
2822 pDestinationColor += OffsetDestination;
2823 }
2824 }
2825
2826 if(cfg->singleSpaceWithSizeOfNextChar)
2827 {
2828 cfg->singleSpaceWithSizeOfNextChar = 0;
2829
2830 if(cfg->invert)
2831 fill = 0xFF;
2832 else
2833 fill = 0;
2834
2835 height /= 2;
2836 for(i = width; i > 0; i--)
2837 {
2838 for (j = height; j > 0; j--)
2839 {
2840 *(__IO uint8_t*)pDestination = fill;
2841 pDestination += 2;
2842 *(__IO uint8_t*)pDestination = fill;
2843 pDestination += 2;
2844 }
2845 pDestination += OffsetDestination;
2846 }
2847 }
2848 else
2849 if(cfg->invert)
2850 {
2851 if((height & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2852 {
2853 height /= 4;
2854 for(i = width; i > 0; i--)
2855 {
2856 if(*(uint8_t*)pSource != 0x01)
2857 {
2858 for (j = height; j > 0; j--)
2859 {
2860 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2861 pSource++;
2862 pDestination += 2;
2863 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2864 pSource++;
2865 pDestination += 2;
2866 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2867 pSource++;
2868 pDestination += 2;
2869 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2870 pSource++;
2871 pDestination += 2;
2872 }
2873 pSource += char_truncated_Height;
2874 }
2875 else
2876 {
2877 pSource++;
2878 for (j = height; j > 0; j--)
2879 {
2880 *(__IO uint8_t*)pDestination = 0xFF;
2881 pDestination += 2;
2882 *(__IO uint8_t*)pDestination = 0xFF;
2883 pDestination += 2;
2884 *(__IO uint8_t*)pDestination = 0xFF;
2885 pDestination += 2;
2886 *(__IO uint8_t*)pDestination = 0xFF;
2887 pDestination += 2;
2888 }
2889 }
2890 pDestination += OffsetDestination;
2891 }
2892 }
2893 else
2894 {
2895 height /= 2;
2896 for(i = width; i > 0; i--)
2897 {
2898 if(*(uint8_t*)pSource != 0x01)
2899 {
2900 for (j = height; j > 0; j--)
2901 {
2902 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2903 pSource++;
2904 pDestination += 2;
2905 *(__IO uint8_t*)pDestination = 0xFF - *(uint8_t*)pSource;
2906 pSource++;
2907 pDestination += 2;
2908 }
2909 pSource += char_truncated_Height;
2910 }
2911 else
2912 {
2913 pSource++;
2914 for (j = height; j > 0; j--)
2915 {
2916 *(__IO uint8_t*)pDestination = 0xFF;
2917 pDestination += 2;
2918 *(__IO uint8_t*)pDestination = 0xFF;
2919 pDestination += 2;
2920 }
2921 }
2922 pDestination += OffsetDestination;
2923 }
2924 }
2925 }
2926 else
2927 {
2928 if((height & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2929 {
2930 height /= 4;
2931 for(i = width; i > 0; i--)
2932 {
2933 if(*(uint8_t*)pSource != 0x01)
2934 {
2935 for (j = height; j > 0; j--)
2936 {
2937 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2938 pSource++;
2939 pDestination += 2;
2940 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2941 pSource++;
2942 pDestination += 2;
2943 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2944 pSource++;
2945 pDestination += 2;
2946 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2947 pSource++;
2948 pDestination += 2;
2949 }
2950 pSource += char_truncated_Height;
2951 }
2952 else
2953 {
2954 pSource++;
2955 pDestination += 2 * height * 4;
2956 }
2957 pDestination += OffsetDestination;
2958 }
2959 }
2960 else
2961 {
2962 height /= 2;
2963 for(i = width; i > 0; i--)
2964 {
2965 if(*(uint8_t*)pSource != 0x01)
2966 {
2967 for (j = height; j > 0; j--)
2968 {
2969 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2970 pSource++;
2971 pDestination += 2;
2972 *(__IO uint8_t*)pDestination = *(uint8_t*)pSource;
2973 pSource++;
2974 pDestination += 2;
2975 }
2976 pSource += char_truncated_Height;
2977 }
2978 else
2979 {
2980 pSource++;
2981 pDestination += 2 * height * 2;
2982 }
2983 pDestination += OffsetDestination;
2984 }
2985 }
2986 }
2987
2988 // -----------------------------
2989
2990 if(Font == &FontT144)
2991 width += 3;
2992 else
2993 if(Font == &FontT105)
2994 width += 2;
2995 /*
2996 else
2997 if(Font == &Font144)
2998 width += 3;
2999 else
3000 if(Font == &Font84)
3001 width += 1;
3002 */
3003 // -----------------------------
3004
3005 if(char_truncated_WidthFlag)
3006 return 0x0000FFFF;
3007 else
3008 return cfg->Xdelta + width;
3009 }
3010
3011
3012 /**
3013 ******************************************************************************
3014 * @brief GFX write Modify helper for center and right align.
3015 * @author heinrichs weikamp gmbh
3016 * @version V0.0.1
3017 * @date 17-March-2015
3018 ******************************************************************************
3019 *
3020 * @param *cText: output
3021 * @param *pTextInput: input
3022 * @param gfx_selected_language: gfx_selected_language
3023 * @retval counter and *cText content
3024 */
3025 int8_t GFX_write__Modify_helper(char *cText, const char *pTextInput, uint8_t gfx_selected_language)
3026 {
3027 uint32_t pText, backup;
3028 uint8_t textId;
3029 int8_t counter;
3030 uint32_t found;
3031 uint32_t j;
3032
3033 pText = (uint32_t)pTextInput;
3034 counter = 0;
3035 while((counter < 100) && (*(char*)pText != 0) && (*(char*)pText != '\r'))
3036 {
3037 if((*(char*)pText) == TXT_2BYTE)
3038 {
3039 backup = pText;
3040
3041 found = 0;
3042 j = 0;
3043 textId = (int8_t)*(char*)(pText + 1);
3044 if(textId != 0)
3045 {
3046 for(j=0;j<(uint8_t)TXT2BYTE_END-(uint8_t)TXT2BYTE_START;j++)
3047 {
3048 if((uint8_t)text_array2[j].code == (uint8_t)textId)
3049 {
3050 found = 1;
3051 break;
3052 }
3053 }
3054 if(found)
3055 {
3056 pText = (uint32_t)text_array2[j].text[gfx_selected_language];
3057 if(!pText)
3058 pText = (uint32_t)text_array2[j].text[0];
3059 else
3060 if(*(char*)pText == 0)
3061 pText = (uint32_t)text_array2[j].text[0];
3062
3063 while((counter < 100) && (*(char*)pText != 0))
3064 cText[counter++] = *(char*)pText++;
3065 }
3066 pText = backup + 2;
3067 }
3068 else
3069 pText = 0;
3070 }
3071 if((*(char*)pText) & 0x80)
3072 {
3073 backup = pText;
3074
3075 found = 0;
3076 j = 0;
3077 textId = (uint8_t)*(char*)pText;
3078 for(uint8_t ii=(uint8_t)TXT_Language;ii<(uint8_t)TXT_END;ii++)
3079 {
3080 if(text_array[j].code == textId)
3081 {
3082 found = 1;
3083 break;
3084 }
3085 j++;
3086 }
3087 if(found)
3088 {
3089 pText = (uint32_t)text_array[j].text[gfx_selected_language];
3090 if(!pText)
3091 pText = (uint32_t)text_array[j].text[0];
3092 else
3093 if(*(char*)pText == 0)
3094 pText = (uint32_t)text_array[j].text[0];
3095
3096 while((counter < 100) && (*(char*)pText != 0))
3097 cText[counter++] = *(char*)pText++;
3098 }
3099 pText = backup + 1;
3100 }
3101 else
3102 {
3103 cText[counter++] = *(char*)pText++;
3104 }
3105 }
3106 cText[counter] = 0;
3107 return counter;
3108 }
3109
3110
3111 /**
3112 ******************************************************************************
3113 * @brief GFX write Modify Ydelta for align. / calc Ydelta for start
3114 * @author heinrichs weikamp gmbh
3115 * @version V0.0.1
3116 * @date 22-April-2014
3117 ******************************************************************************
3118 *
3119 * @param *hgfx: check gfx_engine.h.
3120 * @param *cfg: Ydelta, Font
3121 * @param *pText: character
3122 * @retval Ydelta: 0 if text has to start left ( and probably does not fit)
3123 */
3124
3125 uint32_t GFX_write__Modify_Xdelta__Centered(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput)
3126 {
3127 char cText[101];
3128 uint32_t result;
3129 uint32_t Xsum;
3130 uint32_t i, j;
3131 uint8_t gfx_selected_language;
3132 uint32_t pText;
3133
3134 #ifndef BOOTLOADER_STANDALONE
3135 SSettings *pSettings;
3136 pSettings = settingsGetPointer();
3137 gfx_selected_language = pSettings->selected_language;
3138 if(gfx_selected_language >= LANGUAGE_END)
3139 #endif
3140 gfx_selected_language = 0;
3141 // -----------------------------
3142
3143 GFX_write__Modify_helper(cText,pTextInput,gfx_selected_language);
3144
3145 pText = (uint32_t)&cText[0];
3146 Xsum = 0;
3147 j = 0;
3148 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
3149 {
3150 for(i=0;i<((tFont *)cfg->font)->length;i++)
3151 {
3152 if(((tFont *)cfg->font)->chars[i].code == *(char*)pText)
3153 {
3154 Xsum += ((tFont *)cfg->font)->chars[i].image->width;
3155 break;
3156 }
3157 }
3158 pText++;
3159 j++;
3160 if(((tFont *)cfg->font == &FontT144) && (*(char*)pText != 0))
3161 Xsum += 3;
3162 else
3163 if(((tFont *)cfg->font == &FontT105) && (*(char*)pText != 0))
3164 Xsum += 2;
3165 }
3166 pText -= j;
3167
3168 if(cfg->doubleSize)
3169 Xsum *= 2;
3170
3171 result = hgfx->WindowX1 - hgfx->WindowX0;
3172 if(Xsum < result)
3173 {
3174 result -= Xsum;
3175 result /= 2;
3176 }
3177 else
3178 result = 0;
3179 return result;
3180 }
3181
3182
3183 uint32_t GFX_write__Modify_Xdelta__RightAlign(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput)
3184 {
3185 char cText[101];
3186 uint32_t result;
3187 uint32_t Xsum;
3188 uint32_t i, j;
3189 tFont *font;
3190 uint8_t gfx_selected_language;
3191 uint32_t pText;
3192 uint8_t setToTinyFont = 0;
3193
3194 #ifndef BOOTLOADER_STANDALONE
3195 SSettings *pSettings;
3196 pSettings = settingsGetPointer();
3197 gfx_selected_language = pSettings->selected_language;
3198 if(gfx_selected_language >= LANGUAGE_END)
3199 #endif
3200 gfx_selected_language = 0;
3201 // -----------------------------
3202
3203 GFX_write__Modify_helper(cText,pTextInput,gfx_selected_language);
3204 pText = (uint32_t)&cText[0];
3205
3206 // -----------------------------
3207
3208 setToTinyFont = 0;
3209 font = (tFont *)cfg->font;
3210 Xsum = 0;
3211 j = 0;
3212
3213 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
3214 {
3215 if((font == &FontT144) && (*(char*)pText == '.'))
3216 {
3217 font = (tFont *)&FontT84;
3218 }
3219 else
3220 if((font == &FontT105) && (*(char*)pText == '\16')) // two times to start tiny font
3221 {
3222 if(!setToTinyFont)
3223 setToTinyFont = 1;
3224 else
3225 font = (tFont *)&FontT54;
3226 }
3227 else
3228 if((font == &FontT105) && cfg->dualFont && ((*(char*)pText == '.') || (*(char*)pText == ':')))
3229 {
3230 font = (tFont *)&FontT54;
3231 }
3232
3233 if(*(char*)pText == ' ')
3234 {
3235 Xsum += font->spacesize;
3236 }
3237 else
3238 {
3239 for(i=0;i<font->length;i++)
3240 {
3241 if(font->chars[i].code == *(char*)pText)
3242 {
3243 Xsum += font->chars[i].image->width;
3244 break;
3245 }
3246 }
3247 }
3248 pText++;
3249 j++;
3250 if((font == &FontT144) && (*(char*)pText != 0))
3251 Xsum += 3;
3252 else
3253 if((font == &FontT105) && (*(char*)pText != 0))
3254 Xsum += 2;
3255 }
3256 pText -= j;
3257
3258 if(cfg->doubleSize)
3259 Xsum *= 2;
3260
3261 result = hgfx->WindowX1 - hgfx->WindowX0 - 1;
3262 if(Xsum < result)
3263 result -= Xsum;
3264 else
3265 result = 0;
3266
3267 return result;
3268 }
3269
3270
3271
3272 void GFX_LTDC_Init(void)
3273 {
3274 /*
3275 HSYNC=10 (9+1)
3276 HBP=10 (19-10+1)
3277 ActiveW=480 (499-10-10+1)
3278 HFP=8 (507-480-10-10+1)
3279
3280 VSYNC=2 (1+1)
3281 VBP=2 (3-2+1)
3282 ActiveH=800 (803-2-2+1)
3283 VFP=2 (805-800-2-2+1)
3284 */
3285
3286 /* Timing configuration */
3287 /* Horizontal synchronization width = Hsync - 1 */
3288 LtdcHandle.Init.HorizontalSync = 9;
3289 /* Vertical synchronization height = Vsync - 1 */
3290 LtdcHandle.Init.VerticalSync = 1;
3291 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
3292 LtdcHandle.Init.AccumulatedHBP = 19;
3293 /* Accumulated vertical back porch = Vsync + VBP - 1 */
3294 LtdcHandle.Init.AccumulatedVBP = 3;
3295 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
3296 LtdcHandle.Init.AccumulatedActiveW = 499;//500;//499;
3297 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
3298 LtdcHandle.Init.AccumulatedActiveH = 803;
3299 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
3300 LtdcHandle.Init.TotalWidth = 507;//508;//507;
3301 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
3302 LtdcHandle.Init.TotalHeigh = 805;
3303
3304 /* Configure R,G,B component values for LCD background color */
3305 LtdcHandle.Init.Backcolor.Red= 0;
3306 LtdcHandle.Init.Backcolor.Blue= 0;
3307 LtdcHandle.Init.Backcolor.Green= 0;
3308
3309 /* LCD clock configuration */
3310 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
3311 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
3312 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
3313 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
3314
3315 /* done in main.c SystemClockConfig
3316
3317 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
3318 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
3319 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
3320 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
3321 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
3322 */
3323 /* Polarity */
3324 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
3325 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL;
3326 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
3327 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IIPC;//LTDC_PCPOLARITY_IPC;
3328
3329 LtdcHandle.Instance = LTDC;
3330
3331 /* Configure the LTDC */
3332 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // auch init der GPIO Pins
3333 {
3334 /* Initialization Error */
3335 GFX_Error_Handler();
3336 }
3337 }
3338
3339 void GFX_VGA_LTDC_Init_test(void)
3340 {
3341
3342 LtdcHandle.Init.HorizontalSync = 48;
3343 /* Vertical synchronization height = Vsync - 1 */
3344 LtdcHandle.Init.VerticalSync = 3;
3345 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
3346 LtdcHandle.Init.AccumulatedHBP = 48 + 40 - 1;
3347 /* Accumulated vertical back porch = Vsync + VBP - 1 */
3348 LtdcHandle.Init.AccumulatedVBP = 3 + 29 - 1;
3349 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
3350 LtdcHandle.Init.AccumulatedActiveW = 800 + 48 + 40 - 1;//499;//500;//499;
3351 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
3352 LtdcHandle.Init.AccumulatedActiveH = 480 + 3 + 29 - 1;
3353 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
3354 LtdcHandle.Init.TotalWidth = 800 + 48 + 40 - 1 + 40;//508;//507;
3355 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
3356 LtdcHandle.Init.TotalHeigh = 480 + 3 + 29 - 1 + 13;
3357
3358 /* Configure R,G,B component values for LCD background color */
3359 LtdcHandle.Init.Backcolor.Red= 0;
3360 LtdcHandle.Init.Backcolor.Blue= 0;
3361 LtdcHandle.Init.Backcolor.Green= 0;
3362
3363 /* LCD clock configuration */
3364 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
3365 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
3366 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
3367 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
3368
3369 /* done in main.c SystemClockConfig
3370
3371 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
3372 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
3373 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
3374 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
3375 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
3376 */
3377 /* Polarity */
3378 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
3379 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL;
3380 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
3381 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;//LTDC_PCPOLARITY_IPC;
3382
3383 LtdcHandle.Instance = LTDC;
3384
3385 /* Configure the LTDC */
3386 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // auch init der GPIO Pins
3387 {
3388 /* Initialization Error */
3389 GFX_Error_Handler();
3390 }
3391 }
3392
3393
3394 void GFX_VGA_LTDC_Init_org(void)
3395 {
3396
3397 LtdcHandle.Init.HorizontalSync = 96;
3398 /* Vertical synchronization height = Vsync - 1 */
3399 LtdcHandle.Init.VerticalSync = 2;
3400 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
3401 LtdcHandle.Init.AccumulatedHBP = 96 + 48;
3402 /* Accumulated vertical back porch = Vsync + VBP - 1 */
3403 LtdcHandle.Init.AccumulatedVBP = 2 + 35;
3404 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
3405 LtdcHandle.Init.AccumulatedActiveW = 96 + 48 + 800;//499;//500;//499;
3406 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
3407 LtdcHandle.Init.AccumulatedActiveH = 2 + 35 + 480;
3408 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
3409 LtdcHandle.Init.TotalWidth = 96 + 48 + 800 + 12;//508;//507;
3410 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
3411 LtdcHandle.Init.TotalHeigh = 2 + 35 + 480 + 12;
3412
3413 /* Configure R,G,B component values for LCD background color */
3414 LtdcHandle.Init.Backcolor.Red= 0;
3415 LtdcHandle.Init.Backcolor.Blue= 0;
3416 LtdcHandle.Init.Backcolor.Green= 0;
3417
3418 /* LCD clock configuration */
3419 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
3420 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
3421 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
3422 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
3423
3424 /* done in main.c SystemClockConfig
3425
3426 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
3427 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
3428 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
3429 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
3430 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
3431 */
3432 /* Polarity */
3433 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
3434 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AH;
3435 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
3436 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;//LTDC_PCPOLARITY_IPC;
3437
3438 LtdcHandle.Instance = LTDC;
3439
3440 /* Configure the LTDC */
3441 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // auch init der GPIO Pins
3442 {
3443 /* Initialization Error */
3444 GFX_Error_Handler();
3445 }
3446 }
3447
3448 void GFX_VGA_LTDC_Init(void)
3449 //void GFX_VGA_LTDC_Init_640x480(void)
3450 {
3451
3452 LtdcHandle.Init.HorizontalSync = 96;
3453 /* Vertical synchronization height = Vsync - 1 */
3454 LtdcHandle.Init.VerticalSync = 2;
3455 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
3456 LtdcHandle.Init.AccumulatedHBP = 96 + 48;
3457 /* Accumulated vertical back porch = Vsync + VBP - 1 */
3458 LtdcHandle.Init.AccumulatedVBP = 2 + 35;
3459 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
3460 LtdcHandle.Init.AccumulatedActiveW = 96 + 48 + 640;//499;//500;//499;
3461 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
3462 LtdcHandle.Init.AccumulatedActiveH = 2 + 35 + 480;
3463 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
3464 LtdcHandle.Init.TotalWidth = 96 + 48 + 640 + 12;//508;//507;
3465 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
3466 LtdcHandle.Init.TotalHeigh = 2 + 35 + 480 + 12;
3467
3468 /* Configure R,G,B component values for LCD background color */
3469 LtdcHandle.Init.Backcolor.Red= 0;
3470 LtdcHandle.Init.Backcolor.Blue= 0;
3471 LtdcHandle.Init.Backcolor.Green= 0;
3472
3473 /* LCD clock configuration */
3474 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
3475 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
3476 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
3477 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
3478
3479 /* done in main.c SystemClockConfig
3480
3481 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
3482 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
3483 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
3484 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
3485 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
3486 */
3487 /* Polarity */
3488 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
3489 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AH;
3490 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
3491 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;//LTDC_PCPOLARITY_IPC;
3492
3493 LtdcHandle.Instance = LTDC;
3494
3495 /* Configure the LTDC */
3496 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // auch init der GPIO Pins
3497 {
3498 /* Initialization Error */
3499 GFX_Error_Handler();
3500 }
3501 }
3502
3503
3504 void GFX_LTDC_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
3505 {
3506 LTDC_LayerCfgTypeDef Layercfg;
3507
3508 /* Layer Init */
3509 Layercfg.WindowX0 = 0;
3510 Layercfg.WindowX1 = 480;
3511 Layercfg.WindowY0 = 0;
3512 Layercfg.WindowY1 = 800;
3513 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_AL88;//LTDC_PIXEL_FORMAT_ARGB8888;
3514 Layercfg.FBStartAdress = FB_Address;
3515 Layercfg.Alpha = 255;
3516 Layercfg.Alpha0 = 0;
3517 Layercfg.Backcolor.Blue = 0;
3518 Layercfg.Backcolor.Green = 0;
3519 Layercfg.Backcolor.Red = 0;
3520 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
3521 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
3522 Layercfg.ImageWidth = 480;
3523 Layercfg.ImageHeight = 800;
3524
3525 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex);
3526 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex);
3527 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex);
3528 }
3529
3530 void GFX_VGA_LTDC_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
3531 {
3532 LTDC_LayerCfgTypeDef Layercfg;
3533
3534 /* Layer Init */
3535 Layercfg.WindowX0 = 0;
3536 Layercfg.WindowX1 = 640;
3537 Layercfg.WindowY0 = 0;
3538 Layercfg.WindowY1 = 480;
3539 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_AL88;//LTDC_PIXEL_FORMAT_ARGB8888;
3540 Layercfg.FBStartAdress = FB_Address;
3541 Layercfg.Alpha = 255;
3542 Layercfg.Alpha0 = 0;
3543 Layercfg.Backcolor.Blue = 0;
3544 Layercfg.Backcolor.Green = 0;
3545 Layercfg.Backcolor.Red = 0;
3546 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
3547 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
3548 Layercfg.ImageWidth = 640;
3549 Layercfg.ImageHeight = 480;
3550
3551 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex);
3552 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex);
3553 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex);
3554 }
3555
3556 void GFX_LTDC_LayerTESTInit(uint16_t LayerIndex, uint32_t FB_Address)
3557 {
3558 LTDC_LayerCfgTypeDef Layercfg;
3559
3560 /* Layer Init */
3561 Layercfg.WindowX0 = 0;
3562 Layercfg.WindowX1 = 390;
3563 Layercfg.WindowY0 = 0;
3564 Layercfg.WindowY1 = 800;
3565 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_AL88;//LTDC_PIXEL_FORMAT_ARGB8888;
3566 Layercfg.FBStartAdress = FB_Address;
3567 Layercfg.Alpha = 255;
3568 Layercfg.Alpha0 = 255;
3569 Layercfg.Backcolor.Blue = 0;
3570 Layercfg.Backcolor.Green = 0;
3571 Layercfg.Backcolor.Red = 200;
3572 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
3573 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
3574 Layercfg.ImageWidth = 480;
3575 Layercfg.ImageHeight = 800;
3576
3577 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex);
3578 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex);
3579 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex);
3580 }
3581
3582
3583 uint32_t GFX_doubleBufferOne(void)
3584 {
3585 return SDRAM_DOUBLE_BUFFER_ONE;
3586 }
3587
3588
3589 uint32_t GFX_doubleBufferTwo(void)
3590 {
3591 return SDRAM_DOUBLE_BUFFER_TWO;
3592 }
3593
3594 /*
3595 void doubleBufferClear(uint32_t pDestination)
3596 {
3597 for(uint32_t i = 2*200*480; i > 0; i--)
3598 {
3599 *(__IO uint16_t*)pDestination = 0;
3600 pDestination += 2;
3601 *(__IO uint16_t*)pDestination = 0;
3602 pDestination += 2;
3603 *(__IO uint16_t*)pDestination = 0;
3604 pDestination += 2;
3605 *(__IO uint16_t*)pDestination = 0;
3606 pDestination += 2;
3607 }
3608 }
3609
3610
3611 void GFX_doubleBufferClearOne(void)
3612 {
3613 doubleBufferClear(SDRAM_DOUBLE_BUFFER_ONE);
3614 }
3615
3616
3617 void GFX_doubleBufferClearTwo(void)
3618 {
3619 doubleBufferClear(SDRAM_DOUBLE_BUFFER_TWO);
3620 }
3621 */
3622
3623 uint32_t getFrameByNumber(uint8_t ZeroToMaxFrames)
3624 {
3625 if(ZeroToMaxFrames >= MAXFRAMES)
3626 return 0;
3627 else
3628 return frame[ZeroToMaxFrames].StartAddress;
3629 }
3630
3631 uint32_t getFrame(uint8_t callerId)
3632 {
3633 uint8_t i;
3634
3635 i = 0;
3636 while((i < MAXFRAMES) && (frame[i].status != CLEAR))
3637 i++;
3638
3639 if((i < MAXFRAMES) && (frame[i].status == CLEAR))
3640 {
3641 frame[i].status = BLOCKED;
3642 frame[i].caller = callerId;
3643 return frame[i].StartAddress;
3644 }
3645
3646 i = 0;
3647 while((i < MAXFRAMES) && (frame[i].status != RELEASED))
3648 i++;
3649
3650 if((i < MAXFRAMES) && (frame[i].status == RELEASED))
3651 {
3652 GFX_clear_frame_immediately(frame[i].StartAddress);
3653 frame[i].status = BLOCKED;
3654 return frame[i].StartAddress;
3655 }
3656 return 0;
3657 }
3658
3659
3660 void GFX_forceReleaseFramesWithId(uint8_t callerId)
3661 {
3662 for(int i=0; i<MAXFRAMES; i++)
3663 if((frame[i].caller == callerId) && (frame[i].status == BLOCKED))
3664 frame[i].status = RELEASED;
3665 }
3666
3667
3668 void releaseAllFramesExcept(uint8_t callerId, uint32_t frameStartAddress)
3669 {
3670 for(int i=0; i<MAXFRAMES; i++)
3671 if((frame[i].caller == callerId) && (frame[i].status == BLOCKED) && (frame[i].StartAddress != frameStartAddress))
3672 frame[i].status = RELEASED;
3673 }
3674
3675
3676 uint8_t releaseFrame(uint8_t callerId, uint32_t frameStartAddress)
3677 {
3678 static uint8_t countErrorCalls = 0;
3679
3680 if(frameStartAddress < FBGlobalStart)
3681 return 2;
3682
3683
3684 uint8_t i;
3685
3686 i = 0;
3687 while((i < MAXFRAMES) && (frame[i].StartAddress != frameStartAddress))
3688 i++;
3689
3690 if((i < MAXFRAMES) && (frame[i].StartAddress == frameStartAddress))
3691 {
3692 if(frame[i].caller == callerId)
3693 {
3694 frame[i].status = RELEASED;
3695 return 1;
3696 }
3697 else
3698 countErrorCalls++;
3699 }
3700 return 0;
3701 }
3702
3703
3704 uint16_t blockedFramesCount(void)
3705 {
3706 uint16_t count = MAXFRAMES;
3707
3708 for(int i = 0;i<MAXFRAMES;i++)
3709 if(frame[i].status == BLOCKED)
3710 count--;
3711
3712 return count;
3713 }
3714
3715
3716 uint8_t getFrameCount(uint8_t frameId)
3717 {
3718 if(frameId < (MAXFRAMECOUNTER - 3))
3719 return frameCounter[frameId];
3720 else
3721 return frameCounter[MAXFRAMECOUNTER - 2];
3722 }
3723
3724
3725 void housekeepingFrame(void)
3726 {
3727 static uint8_t countLogClear = 0;
3728
3729 if(DMA2D_at_work != 255)
3730 return;
3731
3732 /* new for debug hw 151202 */
3733 for(int i=1;i<MAXFRAMECOUNTER;i++)
3734 {
3735 frameCounter[i] = 0;
3736 }
3737 for(int i=1;i<MAXFRAMES;i++)
3738 {
3739 if(frame[i].status == BLOCKED)
3740 {
3741 if(frame[i].caller < (MAXFRAMECOUNTER - 2))
3742 frameCounter[frame[i].caller]++;
3743 else
3744 frameCounter[MAXFRAMECOUNTER-3]++;
3745 }
3746 else
3747 if(frame[i].status == RELEASED)
3748 frameCounter[MAXFRAMECOUNTER-2]++;
3749 else
3750 frameCounter[MAXFRAMECOUNTER-1]++;
3751 }
3752
3753
3754 uint8_t i;
3755
3756 i = 0;
3757 while((i < MAXFRAMES) && ((frame[i].status != RELEASED) || (frame[i].StartAddress == GFX_get_pActualFrameTop()) || (frame[i].StartAddress == GFX_get_pActualFrameBottom())))
3758 i++;
3759
3760 if((i < MAXFRAMES) && (frame[i].status == RELEASED))
3761 {
3762 if(frame[i].caller == 15)
3763 countLogClear++;
3764 GFX_clear_frame_dma2d(i);
3765 }
3766 }
3767
3768
3769 static void GFX_Dma2d_TransferComplete(DMA2D_HandleTypeDef* Dma2dHandle)
3770 {
3771 if(DMA2D_at_work < MAXFRAMES)
3772 frame[DMA2D_at_work].status = CLEAR;
3773
3774 DMA2D_at_work = 255;
3775 }
3776
3777
3778 static void GFX_Dma2d_TransferError(DMA2D_HandleTypeDef* Dma2dHandle)
3779 {
3780
3781 }
3782
3783 static void GFX_Error_Handler(void)
3784 {
3785 /* Turn LED3 on */
3786 // BSP_LED_On(LED3);
3787 while(1)
3788 {
3789 }
3790 }
3791
3792 void write_content_simple(GFX_DrawCfgScreen *tMscreen, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, const tFont *Font, const char *text, uint8_t color)
3793 {
3794 GFX_DrawCfgWindow hgfx;
3795
3796 if(XrightGimpStyle > 799)
3797 XrightGimpStyle = 799;
3798 if(XleftGimpStyle >= XrightGimpStyle)
3799 XleftGimpStyle = 0;
3800 if(YtopGimpStyle > 479)
3801 YtopGimpStyle = 479;
3802 hgfx.Image = tMscreen;
3803 hgfx.WindowNumberOfTextLines = 1;
3804 hgfx.WindowLineSpacing = 0;
3805 hgfx.WindowTab = 0;
3806 hgfx.WindowX0 = XleftGimpStyle;
3807 hgfx.WindowX1 = XrightGimpStyle;
3808 hgfx.WindowY1 = 479 - YtopGimpStyle;
3809 if(hgfx.WindowY1 < Font->height)
3810 hgfx.WindowY0 = 0;
3811 else
3812 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
3813
3814 GFX_write_string_color(Font, &hgfx, text, 0, color);
3815 }
3816
3817
3818 void gfx_write_topline_simple(GFX_DrawCfgScreen *tMscreen, const char *text, uint8_t color)
3819 {
3820 GFX_DrawCfgWindow hgfx;
3821 const tFont *Font = &FontT48;
3822
3823 hgfx.Image = tMscreen;
3824 hgfx.WindowNumberOfTextLines = 1;
3825 hgfx.WindowLineSpacing = 0;
3826 hgfx.WindowTab = 0;
3827 hgfx.WindowX0 = 20;
3828 hgfx.WindowX1 = 779;
3829 hgfx.WindowY1 = 479;
3830 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
3831
3832 GFX_write_label(Font, &hgfx, text, color);
3833
3834 }
3835
3836
3837 void gfx_write_page_number(GFX_DrawCfgScreen *tMscreen, uint8_t page, uint8_t total, uint8_t color)
3838 {
3839 GFX_DrawCfgWindow hgfx;
3840 const tFont *Font = &FontT48;
3841 char text[7];
3842 uint8_t i, secondDigitPage, secondDigitTotal;
3843
3844 hgfx.Image = tMscreen;
3845 hgfx.WindowNumberOfTextLines = 1;
3846 hgfx.WindowLineSpacing = 0;
3847 hgfx.WindowTab = 0;
3848 hgfx.WindowX1 = 779;
3849 hgfx.WindowX0 = hgfx.WindowX1 - (25*5);
3850 hgfx.WindowY1 = 479;
3851 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
3852
3853 if(page > 99)
3854 page = 99;
3855 if(total > 99)
3856 total = 99;
3857
3858 i = 0;
3859 text[i++] = '\002';
3860
3861 secondDigitPage = page / 10;
3862 page -= secondDigitPage * 10;
3863
3864 secondDigitTotal = total / 10;
3865 total -= secondDigitTotal * 10;
3866
3867 if(secondDigitPage)
3868 text[i++] = '0' + secondDigitPage;
3869 text[i++] = '0' + page;
3870
3871 text[i++] = '/';
3872
3873 if(secondDigitTotal)
3874 text[i++] = '0' + secondDigitTotal;
3875 text[i++] = '0' + total;
3876
3877 text[i] = 0;
3878
3879 GFX_clear_window_immediately(&hgfx);
3880 GFX_write_label(Font, &hgfx, text, color);
3881 }
3882
3883
3884 uint8_t gfx_number_to_string(uint8_t max_digits, _Bool fill, char *pText, uint32_t input)
3885 {
3886 uint8_t digits[10];
3887 uint32_t number, divider;
3888 int first;
3889 uint8_t out;
3890
3891 number = input;
3892 first = 0;
3893 divider = 1000000000;
3894 for(int i=9;i>=0;i--)
3895 {
3896 digits[i] = (uint8_t)(number / divider);
3897 number -= digits[i] * divider;
3898 divider /= 10;
3899 if((first == 0) && (digits[i] != 0))
3900 first = i;
3901 }
3902
3903 if((first + 1) > max_digits)
3904 {
3905 for(int i = 0; i<max_digits; i++)
3906 pText[i] = '9';
3907 out = max_digits;
3908 }
3909 else if(fill)
3910 {
3911 int i = 0;
3912 for(int k = max_digits; k>0; k--)
3913 pText[i++] = digits[k -1] + '0';
3914 out = max_digits;
3915 }
3916 else
3917 {
3918 int i = 0;
3919 for(int k = first; k>=0; k--)
3920 pText[i++] = digits[k] + '0';
3921 out = i;
3922 }
3923
3924 return out;
3925 }
3926
3927
3928 /* output is
3929 * 0->
3930 * |
3931 * v
3932 *
3933 * input is
3934 *
3935 * ->
3936 * A
3937 * |
3938 * 0
3939 */
3940 void GFX_screenshot(void)
3941 {
3942 uint32_t pSource = GFX_get_pActualFrameTop();
3943 uint32_t pSourceBottom =GFX_get_pActualFrameBottom();
3944 uint32_t pBottomNew = getFrame(99);
3945 uint32_t pDestination = GFX_doubleBufferOne();
3946 uint32_t sourceNow;
3947
3948
3949 uint32_t bot_leftStart = FrameHandler.actualBottom.leftStart; // x0 z.B. 0
3950 uint32_t bot_bottomStart = FrameHandler.actualBottom.bottomStart; // y0 z.B. 25
3951 uint32_t bot_width = FrameHandler.actualBottom.width; // 800
3952 uint32_t bot_height = FrameHandler.actualBottom.height; // 390
3953
3954 struct split
3955 {
3956 uint8_t blue;
3957 uint8_t green;
3958 uint8_t red;
3959 uint8_t alpha;
3960 };
3961
3962 union inout_u
3963 {
3964 uint32_t in;
3965 struct split out;
3966 };
3967
3968 union inout_u value;
3969
3970 /* test
3971 uint32_t pSourceTemp = pSource + (2*479);
3972 for (int j = 0xFFFF; j > 0x00FF; j -= 0x0100)
3973 {
3974 *(__IO uint16_t*)pSourceTemp = j;
3975 pSourceTemp += 480*2;
3976 }
3977 */
3978 // Top Layer
3979 const unsigned width = 800, height = 480;
3980 const uint32_t heightX2 = height*2;
3981
3982 for(unsigned y = 0; y < height; y++)
3983 {
3984 sourceNow = pSource + 2 * ((height - 1) - y);
3985 for(unsigned x = 0; x < width; x++)
3986 {
3987 // sourceNow += 2 * height * x + 2 * (height - 1 - y);
3988 value.in = ColorLUT[*(__IO uint8_t*)(sourceNow)];
3989 value.out.alpha = *(__IO uint8_t*)(sourceNow + 1);
3990
3991 *(__IO uint8_t*)(pDestination++) = value.out.red;
3992 *(__IO uint8_t*)(pDestination++) = value.out.green;
3993 *(__IO uint8_t*)(pDestination++) = value.out.blue;
3994 *(__IO uint8_t*)(pDestination++) = value.out.alpha;
3995 sourceNow += heightX2;
3996 }
3997 }
3998
3999 // Bottom Layer
4000 // build newBottom
4001 pSource = pSourceBottom;
4002 for(unsigned x = bot_leftStart; x < bot_leftStart+bot_width; x++)
4003 {
4004 for(unsigned y = bot_bottomStart; y < bot_bottomStart+bot_height; y++)
4005 {
4006 pDestination = pBottomNew + (2 * y);
4007 pDestination += heightX2 * x;
4008 *(__IO uint16_t*)(pDestination) = *(__IO uint16_t*)(pSource);
4009 pSource += 2;
4010 }
4011 }
4012
4013 // output Bottom Layer
4014 pSource = pBottomNew;
4015 pDestination = GFX_doubleBufferTwo();
4016
4017 for(unsigned y = 0; y < height; y++)
4018 {
4019 sourceNow = pSource + 2 * ((height - 1) - y);
4020 for(unsigned x = 0; x < width; x++)
4021 {
4022 // sourceNow = pSource + 2 * height * x + 2 * (height - 1 - y);
4023 value.in = ColorLUT[*(__IO uint8_t*)(sourceNow)];
4024 value.out.alpha = *(__IO uint8_t*)(sourceNow + 1);
4025
4026 *(__IO uint8_t*)(pDestination++) = value.out.red;
4027 *(__IO uint8_t*)(pDestination++) = value.out.green;
4028 *(__IO uint8_t*)(pDestination++) = value.out.blue;
4029 *(__IO uint8_t*)(pDestination++) = value.out.alpha;
4030 sourceNow += heightX2;
4031 }
4032 }
4033 releaseFrame(99,pBottomNew);
4034 /*
4035 // das kommt dazu!
4036 unsigned yEnd = 480 - FrameHandler.actualBottom.bottomStart;
4037 unsigned yStart = yEnd - FrameHandler.actualBottom.height;
4038
4039 if(yStart > 0)
4040 {
4041 for(unsigned y = 0; y < yStart; y++)
4042 for(unsigned x = 0; x < width; x++)
4043 {
4044 *(__IO uint8_t*)(pDestination++) = 0;
4045 *(__IO uint8_t*)(pDestination++) = 0;
4046 *(__IO uint8_t*)(pDestination++) = 0;
4047 *(__IO uint8_t*)(pDestination++) = 0;
4048 }
4049 }
4050 for(unsigned y = yStart; y < yEnd; y++)
4051 for(unsigned x = 0; x < width; x++)
4052 {
4053 sourceNow = pSource + 2 * height * x + 2 * (height - 1 - y);
4054 value.in = ColorLUT[*(__IO uint8_t*)(sourceNow)];
4055 value.out.alpha = *(__IO uint8_t*)(sourceNow + 1);
4056
4057 *(__IO uint8_t*)(pDestination++) = value.out.red;
4058 *(__IO uint8_t*)(pDestination++) = value.out.green;
4059 *(__IO uint8_t*)(pDestination++) = value.out.blue;
4060 *(__IO uint8_t*)(pDestination++) = value.out.alpha;
4061 }
4062 if(yEnd < 480)
4063 {
4064 for(unsigned y = yEnd; y < 480; y++)
4065 for(unsigned x = 0; x < width; x++)
4066 {
4067 *(__IO uint8_t*)(pDestination++) = 0;
4068 *(__IO uint8_t*)(pDestination++) = 0;
4069 *(__IO uint8_t*)(pDestination++) = 0;
4070 *(__IO uint8_t*)(pDestination++) = 0;
4071 }
4072 }
4073 */
4074 }