comparison BootLoader/Src/gfx_engine_mini.c @ 1048:493a5903ec20 GasConsumption

Merge with 9d9d506a82d3162b6b2323819cc08652887d7dd4 (Bootloader)
author Ideenmodellierer
date Sat, 15 Nov 2025 19:29:44 +0100
parents 0dd92e9b70a2
children
comparison
equal deleted inserted replaced
1047:6fb16ca39125 1048:493a5903ec20
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 #define RING_BUF_SIZE (5u)
40 #define MAX_COLOR_STRING_LENGTH (100u)
41
42 typedef struct
43 {
44 uint32_t Xdelta;
45 uint32_t Ydelta;
46 uint8_t invert;
47 uint8_t color;
48 uint8_t dualFont;
49 uint8_t resize;
50 uint32_t font;
51 uint8_t spaceMode;
52 uint8_t singleSpaceWithSizeOfNextChar;
53 uint8_t useTinyFont;
54 uint32_t TinyFont;
55 int8_t TinyFontExtraYdelta;
56 tFont *actualFont;
57 uint8_t doubleSize;
58 } GFX_CfgWriteString;
59
60 typedef struct
61 {
62 uint32_t pBuffer;
63 uint32_t height;
64 uint32_t width;
65 uint32_t leftStart;
66 uint32_t bottomStart;
67 } GFX_layerSingle;
68 /*
69 typedef struct
70 {
71 GFX_layerSingle top;
72 GFX_layerSingle bottom;
73 } GFX_layersTopBottom;
74 */
75 typedef struct
76 {
77 uint32_t pActualTopBuffer;
78 uint32_t pNextTopBuffer[RING_BUF_SIZE];
79 GFX_layerSingle actualBottom;
80 GFX_layerSingle nextBottom[RING_BUF_SIZE];
81 uint8_t NextTopWrite;
82 uint8_t NextBottomWrite;
83 uint8_t NextTopRead;
84 uint8_t NextBottomRead;
85 } GFX_layerControl;
86
87 typedef struct
88 {
89 uint32_t StartAddress;
90 int8_t status;
91 uint8_t caller;
92 } SFrameList;
93
94 enum FRAMESTATE
95 {
96 CLEAR = 0,
97 BLOCKED,
98 RELEASED
99 };
100
101 enum LOGOSTATE
102 {
103 LOGOOFF = 0,
104 LOGOSTART = 1,
105 LOGOSTOP = 255
106 };
107
108 // should be 43
109 #define MAXFRAMES 39
110
111 #define SDRAM_BANK_ADDR ((uint32_t)0xD0000000)
112 #define FBGlobalStart SDRAM_BANK_ADDR
113 #define FBOffsetEachIndex (800*480*2)
114
115 #define SDRAM_DOUBLE_BUFFER_ONE ((uint32_t)(FBGlobalStart + (MAXFRAMES * FBOffsetEachIndex)))
116 #define SDRAM_DOUBLE_BUFFER_TWO ((uint32_t)(SDRAM_DOUBLE_BUFFER_ONE + (2 * FBOffsetEachIndex)))
117 #define SDRAM_DOUBLE_BUFFER_END ((uint32_t)(SDRAM_DOUBLE_BUFFER_TWO + (2 * FBOffsetEachIndex)))
118
119 /* Semi Private variables ---------------------------------------------------------*/
120
121 DMA2D_HandleTypeDef Dma2dHandle;
122 static LTDC_HandleTypeDef LtdcHandle;
123
124 /* Private variables ---------------------------------------------------------*/
125
126 static uint8_t DMA2D_at_work = 0;
127
128 static GFX_layerControl FrameHandler = { 0 };
129
130 static uint32_t pInvisibleFrame = 0;
131 static uint32_t pLogoFrame = 0;
132 static uint8_t logoStatus;
133 static uint32_t pBackgroundHwFrame = 0;
134 static uint8_t backgroundHwStatus;
135
136 static SFrameList frame[MAXFRAMES];
137
138 static void GFX_clear_frame_immediately(uint32_t pDestination);
139 static void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image);
140 /* ITM Trace-----------------------------------------------------------------*/
141
142 #include "stdio.h"
143
144 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
145 #define ITM_Port16(n) (*((volatile unsigned short*)(0xE0000000+4*n)))
146 #define ITM_Port32(n) (*((volatile unsigned long *)(0xE0000000+4*n)))
147
148 #define DEMCR (*((volatile unsigned long *)(0xE000EDFC)))
149 #define TRCENA 0x01000000
150
151 struct __FILE { int handle; /* Add whatever needed */ };
152 FILE __stdout;
153 FILE __stdin;
154
155 int fputc(int ch, FILE *f) {
156 if (DEMCR & TRCENA) {
157 while (ITM_Port32(0) == 0);
158 ITM_Port8(0) = ch;
159 }
160 return(ch);
161 }
162
163 uint32_t MinU32GFX(uint32_t a, uint32_t b)
164 {
165 return ((a<b)?a:b);
166 }
167
168
169 uint32_t MaxU32GFX(uint32_t a, uint32_t b)
170 {
171 return((a>b)?a:b);
172 }
173
174 /* Private function prototypes -----------------------------------------------*/
175
176 static uint32_t GFX_write_char(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font);
177 static uint32_t GFX_write_substring(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, uint8_t textId, int8_t nextCharFor2Byte);
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 static void GFX_clear_frame_dma2d(uint8_t frameId);
182
183 static uint32_t GFX_doubleBufferOne(void);
184 static uint32_t GFX_doubleBufferTwo(void);
185
186 static void GFX_LTDC_Init_display1(void);
187
188
189 /* Exported functions --------------------------------------------------------*/
190
191 uint8_t GFX_logoStatus(void)
192 {
193 return logoStatus;
194 }
195
196 void GFX_SetWindowLayer0(uint32_t pDestination, int16_t XleftGimpStyle, int16_t XrightGimpStyle, int16_t YtopGimpStyle, int16_t YbottomGimpStyle)
197 {
198 int16_t XSize, YSize, X0, Y0;
199
200 if(XleftGimpStyle < 0) XleftGimpStyle = 0;
201 if(XrightGimpStyle < 0) XrightGimpStyle = 0;
202 if(XleftGimpStyle > 799) XleftGimpStyle = 800;
203 if(XrightGimpStyle > 799) XrightGimpStyle = 800;
204
205 if(YtopGimpStyle < 0) YtopGimpStyle = 0;
206 if(YbottomGimpStyle < 0) YbottomGimpStyle = 0;
207 if(YtopGimpStyle > 479) YtopGimpStyle = 480;
208 if(YbottomGimpStyle > 479) YbottomGimpStyle = 480;
209
210 /*
211 XSize = YbottomGimpStyle - YtopGimpStyle;
212 YSize = XrightGimpStyle - XleftGimpStyle;
213 if((XSize <= 0) || (YSize <= 0))
214 return;
215 X0 = 479 - YbottomGimpStyle;
216 Y0 = XleftGimpStyle;
217 while((LTDC->CPSR & LTDC_CPSR_CYPOS) <= (uint32_t)800);
218 HAL_LTDC_SetWindowSize(&LtdcHandle, XSize, YSize, LayerIdx);
219 HAL_LTDC_SetWindowPosition(&LtdcHandle, X0, Y0,LayerIdx);
220 HAL_LTDC_SetAddress(&LtdcHandle, pDestination, LayerIdx);
221 */
222
223 XSize = XrightGimpStyle - XleftGimpStyle;
224 YSize = YbottomGimpStyle - YtopGimpStyle;
225 if((XSize <= 0) || (YSize <= 0))
226 return;
227 Y0 = 479 - YbottomGimpStyle;
228 X0 = XleftGimpStyle;
229
230 GFX_SetFrameBottom(pDestination, X0, Y0, XSize, YSize);
231 }
232
233
234 void GFX_logoAutoOff(void)
235 {
236 if(logoStatus == LOGOOFF)
237 logoStatus = LOGOSTART;
238 }
239
240
241 void GFX_hwBackgroundOn(void)
242 {
243 backgroundHwStatus = LOGOSTART;
244 }
245
246
247 void GFX_hwBackgroundOff(void)
248 {
249 backgroundHwStatus = LOGOSTOP;
250 }
251
252 void GFX_build_hw_background_frame(void)
253 {
254 GFX_DrawCfgScreen tLogoTemp;
255 SWindowGimpStyle windowGimp;
256
257 pBackgroundHwFrame = getFrame(1);
258 backgroundHwStatus = 0;
259
260 tLogoTemp.FBStartAdress = pBackgroundHwFrame;
261 tLogoTemp.ImageHeight = 480;
262 tLogoTemp.ImageWidth = 800;
263 tLogoTemp.LayerIndex = 1;
264
265 windowGimp.left = (800 - 400) / 2;
266 windowGimp.top = 0;//(480 - 46) / 2;
267
268 GFX_draw_image_color(&tLogoTemp, windowGimp, &ImgHWcolor);
269 /*
270 char localtext[256];
271 uint8_t ptr = 0;
272
273 localtext[ptr++] = ' ';
274 localtext[ptr++] = ' ';
275 localtext[ptr++] = 'O';
276 localtext[ptr++] = 'S';
277 localtext[ptr++] = ' ';
278 ptr += GFX_printf_firmware(&localtext[ptr]);
279 localtext[ptr] = 0;
280
281 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020);
282 */
283 }
284
285 void decompressFont(const tFont* pFont, const tImageComp** pFontComp)
286 {
287 uint16_t indexFont = 0;
288 uint16_t indexData = 0;
289 uint8_t data = 0;
290 uint8_t count = 0;
291 uint8_t targetIndex = 0;
292 uint8_t* pPixel;
293
294 for (indexFont = 0; indexFont < pFont->length; indexFont++)
295 {
296 pPixel = (uint8_t*)pFont->chars[indexFont].image->data;
297 for(indexData = 0; indexData < pFontComp[indexFont]->sizeComp; indexData += 2)
298 {
299 data = pFontComp[indexFont]->dataComp[indexData];
300 count = pFontComp[indexFont]->dataComp[indexData + 1];
301 for (targetIndex = 0; targetIndex < count; targetIndex++)
302 {
303 *pPixel++ = data;
304 }
305 }
306 }
307 }
308
309 void GFX_build_logo_frame(void)
310 {
311 GFX_DrawCfgScreen tLogoTemp;
312 SWindowGimpStyle windowGimp;
313
314 pLogoFrame = getFrame(1);
315 logoStatus = LOGOOFF;
316
317 tLogoTemp.FBStartAdress = pLogoFrame;
318 tLogoTemp.ImageHeight = 480;
319 tLogoTemp.ImageWidth = 800;
320 tLogoTemp.LayerIndex = 1;
321
322 windowGimp.left = (800 - 400) / 2;
323 windowGimp.top = (480 - 46) / 2;
324
325 GFX_draw_image_color(&tLogoTemp, windowGimp, &ImgHWcolor);
326 /*
327 char localtext[256];
328 uint8_t ptr = 0;
329
330 localtext[ptr++] = ' ';
331 localtext[ptr++] = ' ';
332 localtext[ptr++] = 'O';
333 localtext[ptr++] = 'S';
334 localtext[ptr++] = ' ';
335 ptr += GFX_printf_firmware(&localtext[ptr]);
336 localtext[ptr] = 0;
337
338 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020);
339 */
340 }
341
342 void GFX_init(uint32_t * pDestinationOut)
343 {
344 frame[0].StartAddress = FBGlobalStart;
345 GFX_clear_frame_immediately(frame[0].StartAddress);
346 frame[0].status = CLEAR;
347 frame[0].caller = 0;
348
349 for(int i=1;i<MAXFRAMES;i++)
350 {
351 frame[i].StartAddress = frame[i-1].StartAddress + FBOffsetEachIndex;
352 GFX_clear_frame_immediately(frame[i].StartAddress);
353 frame[i].status = CLEAR;
354 frame[i].caller = 0;
355 }
356
357 pInvisibleFrame = getFrame(2);
358 *pDestinationOut = pInvisibleFrame;
359
360 GFX_build_logo_frame();
361 GFX_build_hw_background_frame();
362
363 /* Register to memory mode with ARGB8888 as color Mode */
364 Dma2dHandle.Init.Mode = DMA2D_R2M;
365 Dma2dHandle.Init.ColorMode = DMA2D_ARGB4444;//to fake AL88, before: DMA2D_ARGB8888;
366 Dma2dHandle.Init.OutputOffset = 0;
367
368 /* DMA2D Callbacks Configuration */
369 Dma2dHandle.XferCpltCallback = GFX_Dma2d_TransferComplete;
370 Dma2dHandle.XferErrorCallback = GFX_Dma2d_TransferError;
371
372 Dma2dHandle.Instance = DMA2D;
373
374 /* DMA2D Initialisation */
375 if(HAL_DMA2D_Init(&Dma2dHandle) != HAL_OK)
376 GFX_Error_Handler();
377
378 if(HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1) != HAL_OK)
379 GFX_Error_Handler();
380
381 DMA2D_at_work = 255;
382 }
383 void GFX_init1_no_DMA(uint32_t * pDestinationOut, uint8_t blockFrames)
384 {
385 frame[0].StartAddress = FBGlobalStart;
386 GFX_clear_frame_immediately(frame[0].StartAddress);
387 frame[0].status = CLEAR;
388 frame[0].caller = 0;
389
390 for(int i=1;i<MAXFRAMES;i++)
391 {
392 frame[i].StartAddress = frame[i-1].StartAddress + FBOffsetEachIndex;
393 GFX_clear_frame_immediately(frame[i].StartAddress);
394 frame[i].status = CLEAR;
395 frame[i].caller = 0;
396 }
397
398 for(int i=0;i<blockFrames;i++)
399 {
400 frame[i].status = BLOCKED;
401 frame[i].caller = 1;
402 }
403
404 pInvisibleFrame = getFrame(2);
405 *pDestinationOut = pInvisibleFrame;
406
407 GFX_build_logo_frame();
408 GFX_build_hw_background_frame();
409 }
410
411
412 void GFX_init2_DMA(void)
413 {
414 /* Register to memory mode with ARGB8888 as color Mode */
415 Dma2dHandle.Init.Mode = DMA2D_R2M;
416 Dma2dHandle.Init.ColorMode = DMA2D_ARGB4444;//to fake AL88, before: DMA2D_ARGB8888;
417 Dma2dHandle.Init.OutputOffset = 0;
418
419 /* DMA2D Callbacks Configuration */
420 Dma2dHandle.XferCpltCallback = GFX_Dma2d_TransferComplete;
421 Dma2dHandle.XferErrorCallback = GFX_Dma2d_TransferError;
422
423 Dma2dHandle.Instance = DMA2D;
424
425 /* DMA2D Initialisation */
426 if(HAL_DMA2D_Init(&Dma2dHandle) != HAL_OK)
427 GFX_Error_Handler();
428
429 if(HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1) != HAL_OK)
430 GFX_Error_Handler();
431
432 DMA2D_at_work = 255;
433 }
434
435
436 void GFX_SetFrameTop(uint32_t pDestination)
437 {
438 uint8_t NextTopWork = FrameHandler.NextTopWrite + 1;
439
440 if(NextTopWork == RING_BUF_SIZE)
441 {
442 NextTopWork = 0;
443 }
444
445 if(pDestination == 0)
446 pDestination = pInvisibleFrame;
447
448 FrameHandler.pNextTopBuffer[NextTopWork] = pDestination;
449 FrameHandler.NextTopWrite = NextTopWork;
450 }
451
452
453 void GFX_SetFrameBottom(uint32_t pDestination, uint32_t x0, uint32_t y0, uint32_t width, uint32_t height)
454 {
455 uint8_t NextBottomWork = FrameHandler.NextBottomWrite + 1;
456
457 if(NextBottomWork == RING_BUF_SIZE)
458 {
459 NextBottomWork = 0;
460 }
461
462 if(pDestination == 0)
463 pDestination = pInvisibleFrame;
464
465 FrameHandler.nextBottom[NextBottomWork].pBuffer = pDestination;
466 FrameHandler.nextBottom[NextBottomWork].height = height;
467 FrameHandler.nextBottom[NextBottomWork].width = width;
468 FrameHandler.nextBottom[NextBottomWork].leftStart = x0;
469 FrameHandler.nextBottom[NextBottomWork].bottomStart = y0;
470 FrameHandler.NextBottomWrite = NextBottomWork;
471 }
472
473
474 void GFX_SetFramesTopBottom(uint32_t pTop, uint32_t pBottom, uint32_t heightBottom)
475 {
476 GFX_SetFrameTop(pTop);
477 GFX_SetFrameBottom(pBottom, 0, 0, 800, heightBottom);
478 }
479
480
481 static uint32_t GFX_get_pActualFrameTop(void)
482 {
483 return FrameHandler.pActualTopBuffer;
484 }
485
486
487 static uint32_t GFX_get_pActualFrameBottom(void)
488 {
489 return FrameHandler.actualBottom.pBuffer;
490 }
491
492
493 void GFX_start_VSYNC_IRQ(void)
494 {
495 GPIO_InitTypeDef GPIO_InitStructure;
496
497 GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
498 GPIO_InitStructure.Pull = GPIO_NOPULL;
499 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
500 GPIO_InitStructure.Pin = VSYNC_IRQ_PIN;
501 HAL_GPIO_Init(VSYNC_IRQ_GPIO_PORT, &GPIO_InitStructure);
502
503 HAL_NVIC_SetPriority(VSYNC_IRQ_EXTI_IRQn, 1, 0);
504 HAL_NVIC_EnableIRQ(VSYNC_IRQ_EXTI_IRQn);
505 }
506
507
508 void GFX_change_LTDC(void)
509 {
510 uint32_t pTop = 0;
511 uint32_t pBot = 0;
512 uint32_t heightBot = 0;
513 uint32_t widthBot = 0;
514 uint32_t leftStartBot = 0;
515 uint32_t bottomStartBot = 0;
516 uint8_t change_position = 0;
517 uint8_t change_size = 0;
518 uint8_t nextBottomBackup = FrameHandler.NextBottomRead; /* Restore entry value in case off logo handling */
519
520 // Top Frame
521 if(FrameHandler.NextTopRead != FrameHandler.NextTopWrite)
522 {
523 FrameHandler.NextTopRead++;
524 if(FrameHandler.NextTopRead == RING_BUF_SIZE)
525 {
526 FrameHandler.NextTopRead = 0;
527 }
528 }
529 pTop = FrameHandler.pNextTopBuffer[FrameHandler.NextTopRead];
530
531 if(FrameHandler.pActualTopBuffer != pTop)
532 {
533 HAL_LTDC_SetAddress(&LtdcHandle, pTop, 1);
534 FrameHandler.pActualTopBuffer = pTop;
535 }
536
537 // Bottom Frame
538 if(FrameHandler.NextBottomRead != FrameHandler.NextBottomWrite)
539 {
540 FrameHandler.NextBottomRead++;
541 if(FrameHandler.NextBottomRead == RING_BUF_SIZE)
542 {
543 FrameHandler.NextBottomRead = 0;
544 }
545 }
546 if(logoStatus != LOGOOFF)
547 {
548 switch(logoStatus)
549 {
550 case LOGOSTART:
551 HAL_LTDC_SetAlpha(&LtdcHandle, 0, 1);
552 HAL_LTDC_SetAlpha(&LtdcHandle, 34, 0);
553 HAL_LTDC_ConfigCLUT(&LtdcHandle, (uint32_t *)indexHWcolor, indexHWcolorSIZE, 0);
554 HAL_LTDC_SetAddress(&LtdcHandle, pLogoFrame, 0);
555 HAL_LTDC_SetWindowSize(&LtdcHandle, 480, 800, 0);
556 HAL_LTDC_SetWindowPosition(&LtdcHandle, 0, 0, 0);
557 logoStatus = 2;
558 FrameHandler.NextBottomRead = nextBottomBackup;
559 break;
560
561 case LOGOSTOP:
562 HAL_LTDC_SetAlpha(&LtdcHandle, 255, 1);
563 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 0);
564
565 pBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].pBuffer;
566 heightBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].height;
567 widthBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].width;
568 leftStartBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].leftStart;
569 bottomStartBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].bottomStart;
570 HAL_LTDC_SetWindowSize(&LtdcHandle, heightBot, widthBot, 0);
571 HAL_LTDC_SetWindowPosition(&LtdcHandle, bottomStartBot, leftStartBot, 0);
572 HAL_LTDC_SetAddress(&LtdcHandle, pBot, 0);
573 HAL_LTDC_SetAlpha(&LtdcHandle, 255, 0);
574 FrameHandler.actualBottom.height = heightBot;
575 FrameHandler.actualBottom.width = widthBot;
576 FrameHandler.actualBottom.leftStart = leftStartBot;
577 FrameHandler.actualBottom.bottomStart = bottomStartBot;
578 FrameHandler.actualBottom.pBuffer = pBot;
579
580 logoStatus = LOGOOFF;
581 if(backgroundHwStatus == 2)
582 {
583 backgroundHwStatus = LOGOSTART;
584 }
585 break;
586 default:
587 if(logoStatus < 35)
588 {
589 logoStatus++;
590 if(logoStatus <= 15)
591 HAL_LTDC_SetAlpha(&LtdcHandle, 17*logoStatus, 0);
592 }
593 else
594 {
595 logoStatus +=20;
596 HAL_LTDC_SetAlpha(&LtdcHandle, logoStatus-55, 1);
597 HAL_LTDC_SetAlpha(&LtdcHandle, 255+55-logoStatus, 0);
598 }
599 FrameHandler.NextBottomRead = nextBottomBackup;
600 break;
601 }
602 return;
603 }
604 else if (backgroundHwStatus != LOGOOFF)
605 {
606
607 switch(backgroundHwStatus)
608 {
609 case LOGOSTART:
610 HAL_LTDC_ConfigCLUT(&LtdcHandle, (uint32_t *)indexHWcolor, indexHWcolorSIZE, 0);
611 HAL_LTDC_SetAddress(&LtdcHandle, pBackgroundHwFrame, 0);
612 HAL_LTDC_SetWindowSize(&LtdcHandle, 480, 800, 0);
613 HAL_LTDC_SetWindowPosition(&LtdcHandle, 0, 0, 0);
614 backgroundHwStatus = 2;
615 FrameHandler.NextBottomRead = nextBottomBackup;
616 break;
617
618 case LOGOSTOP:
619 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 0);
620 pBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].pBuffer;
621 heightBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].height;
622 widthBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].width;
623 leftStartBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].leftStart;
624 bottomStartBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].bottomStart;
625 HAL_LTDC_SetWindowSize(&LtdcHandle, heightBot, widthBot, 0);
626 HAL_LTDC_SetWindowPosition(&LtdcHandle, bottomStartBot, leftStartBot, 0);
627 HAL_LTDC_SetAddress(&LtdcHandle, pBot, 0);
628 HAL_LTDC_SetAlpha(&LtdcHandle, 255, 0);
629 FrameHandler.actualBottom.height = heightBot;
630 FrameHandler.actualBottom.width = widthBot;
631 FrameHandler.actualBottom.leftStart = leftStartBot;
632 FrameHandler.actualBottom.bottomStart = bottomStartBot;
633 FrameHandler.actualBottom.pBuffer = pBot;
634 backgroundHwStatus = LOGOOFF;
635 break;
636
637 default:
638 FrameHandler.NextBottomRead = nextBottomBackup;
639 break;
640 }
641
642 return;
643 }
644 else
645 {
646 pBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].pBuffer;
647 heightBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].height;
648 widthBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].width;
649 leftStartBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].leftStart;
650 bottomStartBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].bottomStart;
651
652 if(FrameHandler.actualBottom.pBuffer == pBot)
653 pBot = 0;
654
655 if((FrameHandler.actualBottom.height != heightBot) || (FrameHandler.actualBottom.width != widthBot))
656 change_size = 1;
657
658 if((FrameHandler.actualBottom.leftStart != leftStartBot) || (FrameHandler.actualBottom.bottomStart != bottomStartBot))
659 change_position = 1;
660
661 if(pBot || change_size || change_position)
662 {
663 if(heightBot && widthBot)
664 HAL_LTDC_SetWindowSize(&LtdcHandle, heightBot, widthBot, 0);
665
666 if(change_position || leftStartBot || bottomStartBot)
667 HAL_LTDC_SetWindowPosition(&LtdcHandle, bottomStartBot, leftStartBot, 0);
668
669 if(pBot)
670 HAL_LTDC_SetAddress(&LtdcHandle, pBot, 0);
671
672 if(change_size)
673 {
674 FrameHandler.actualBottom.height = heightBot;
675 FrameHandler.actualBottom.width = widthBot;
676 }
677 if(change_position)
678 {
679 FrameHandler.actualBottom.leftStart = leftStartBot;
680 FrameHandler.actualBottom.bottomStart = bottomStartBot;
681 }
682 if(pBot)
683 FrameHandler.actualBottom.pBuffer = pBot;
684 }
685 }
686 }
687
688 uint8_t GFX_is_colorschemeDiveStandard(void)
689 {
690 return (ColorLUT[CLUT_Font027] == 0x00FFFFFF);
691 }
692
693
694 void change_CLUT_entry(uint8_t entryToChange, uint8_t entryUsedForChange)
695 {
696 /* bug fix
697 static uint8_t counter = 0;
698
699 if(entryToChange == 0x1C)
700 counter++;
701 */
702 ColorLUT[entryToChange] = ColorLUT[entryUsedForChange];
703 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 1);
704 if(logoStatus == LOGOOFF)
705 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, 0);
706 }
707
708
709 void GFX_use_colorscheme(uint8_t colorscheme)
710 {
711 uint8_t ColorSchemeStart;
712
713 if(colorscheme > 3)
714 colorscheme = 0;
715
716 ColorSchemeStart = CLUT_Colorscheme0 + (8 * colorscheme);
717 for(int i=1; i<8; i++)
718 {
719 ColorLUT[CLUT_Font027 + i] = ColorLUT[ColorSchemeStart + i];
720 }
721 change_CLUT_entry(CLUT_Font027, ColorSchemeStart);
722 }
723
724
725 void GFX_VGA_transform(uint32_t pSource, uint32_t pDestination)
726 {
727 int h, v;
728 uint32_t offsetSource, offsetSourceStartOfLine;
729
730 offsetSourceStartOfLine = 480 + 480 - 2;
731 for(v=0;v<480;v++)
732 {
733 offsetSource = offsetSourceStartOfLine;
734 for(h=0;h<640;h++)
735 {
736 *(__IO uint8_t*)pDestination = *(uint8_t*)(pSource + offsetSource);
737 pDestination++;
738 offsetSource += 1;
739 *(__IO uint8_t*)pDestination = *(uint8_t*)(pSource + offsetSource);
740 pDestination++;
741 offsetSource += 480 + 479;
742 }
743 offsetSourceStartOfLine -= 2;
744 }
745 }
746
747
748 static void GFX_clear_frame_immediately(uint32_t pDestination)
749 {
750 uint32_t i;
751 uint32_t* pfill = (uint32_t*) pDestination;
752
753
754 for(i = 200*480; i > 0; i--)
755 {
756 *pfill++ = 0;
757 *pfill++ = 0;
758 }
759 }
760
761
762 void GFX_clear_window_immediately(GFX_DrawCfgWindow* hgfx)
763 {
764 uint32_t pDestination, i, j;
765 uint16_t left, width, bottom, height, nextlineStep;
766
767 pDestination = (uint32_t)hgfx->Image->FBStartAdress;
768
769 left = hgfx->WindowX0;
770 width = 1 + hgfx->WindowX1 - left;
771 bottom = hgfx->WindowY0;
772 height = 1 + hgfx->WindowY1 - bottom;
773 nextlineStep = hgfx->Image->ImageHeight - height;
774 nextlineStep *= 2;
775
776 pDestination += 2 * bottom;
777 pDestination += 2 * hgfx->Image->ImageHeight * left;
778
779 for(j = width; j > 0; j--)
780 {
781 for(i = height; i > 0; i--)
782 {
783 *(__IO uint16_t*)pDestination = 0;
784 pDestination += 2;
785 }
786 pDestination += nextlineStep;
787 }
788 }
789
790
791 static void GFX_clear_frame_dma2d(uint8_t frameId)
792 {
793 if(frameId >= MAXFRAMES)
794 return;
795
796 DMA2D_at_work = frameId;
797
798 if (HAL_DMA2D_Start_IT(&Dma2dHandle, 0x0000000000, frame[frameId].StartAddress, 480, 800) != HAL_OK)
799 GFX_Error_Handler();
800 }
801
802
803 void GFX_fill_buffer(uint32_t pDestination, uint8_t alpha, uint8_t color)
804 {
805
806 union al88_u
807 {
808 uint8_t al8[2];
809 uint16_t al88;
810 };
811 union al88_u colorcombination;
812 uint32_t i;
813 uint32_t* pfill = (uint32_t*) pDestination;
814 uint32_t fillpattern;
815
816 colorcombination.al8[0] = color;
817 colorcombination.al8[1] = alpha;
818
819 fillpattern = (colorcombination.al88 << 16) | colorcombination.al88;
820 for(i = 800*480/2; i > 0; i--)
821 {
822 *pfill++ = fillpattern;
823 }
824 }
825
826 static void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
827 {
828 uint16_t* pDestination;
829
830 uint32_t j;
831 point_t start, stop;
832
833 start.x = window.left;
834 start.y = (hgfx->ImageHeight - image->height - window.top);
835 stop.y = start.y + image->height;
836 stop.x = start.x + image->width;
837 j = 0;
838
839 for(int xx = start.x; xx < stop.x; xx++)
840 {
841 pDestination = (uint16_t*)hgfx->FBStartAdress;
842 pDestination += xx * hgfx->ImageHeight;
843 pDestination += start.y;
844 for(int yy = start.y; yy < stop.y; yy++)
845 {
846 *(__IO uint16_t*)pDestination++ = 0xFF << 8 | image->data[j++];
847 }
848 }
849 }
850
851
852 /* this is NOT fast nor optimized */
853 void GFX_draw_pixel(GFX_DrawCfgScreen *hgfx, int16_t x, int16_t y, uint8_t color)
854 {
855 uint16_t* pDestination;
856
857 pDestination = (uint16_t*)hgfx->FBStartAdress;
858 pDestination += x * hgfx->ImageHeight;
859 pDestination += y;
860
861 *(__IO uint16_t*)pDestination = 0xFF << 8 | color;
862 }
863
864 /* this is NOT fast nor optimized */
865 void GFX_draw_circle(GFX_DrawCfgScreen *hgfx, point_t center, uint8_t radius, int8_t color)
866 {
867 int x, y;
868 int l;
869 int r2, y2;
870 int y2_new;
871 int ty;
872
873 /* cos pi/4 = 185363 / 2^18 (approx) */
874 l = (radius * 185363) >> 18;
875
876 /* hw */
877 l += 1;
878
879 /* At x=0, y=radius */
880 y = radius;
881
882 r2 = y2 = y * y;
883 ty = (2 * y) - 1;
884 y2_new = r2 + 3;
885
886 for (x = 0; x <= l; x++) {
887 y2_new -= (2 * x) - 3;
888
889 if ((y2 - y2_new) >= ty) {
890 y2 -= ty;
891 y -= 1;
892 ty -= 2;
893 }
894
895 GFX_draw_pixel (hgfx, x + center.x, y + center.y, color);
896 GFX_draw_pixel (hgfx, x + center.x, -y + center.y, color);
897 GFX_draw_pixel (hgfx, -x + center.x, y + center.y, color);
898 GFX_draw_pixel (hgfx, -x + center.x, -y + center.y, color);
899
900 GFX_draw_pixel (hgfx, y + center.x, x + center.y, color);
901 GFX_draw_pixel (hgfx, y + center.x, -x + center.y, color);
902 GFX_draw_pixel (hgfx, -y + center.x, x + center.y, color);
903 GFX_draw_pixel (hgfx, -y + center.x, -x + center.y, color);
904 }
905 }
906
907
908 void GFX_draw_colorline(GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color)
909 {
910 uint32_t pDestination;
911 uint32_t j;
912 uint32_t temp;
913
914 if(start.x == stop.x)
915 {
916 if(stop.y < start.y)
917 {
918 temp = stop.y;
919 stop.y = start.y;
920 start.y = temp;
921 }
922 pDestination = (uint32_t)hgfx->FBStartAdress;
923 pDestination += start.x * hgfx->ImageHeight * 2;
924 pDestination += start.y * 2;
925 for (j = stop.y - start.y; j > 0; j--)
926 {
927 *(__IO uint8_t*)pDestination = color;
928 pDestination += 1;
929 *(__IO uint8_t*)pDestination = 0xFF;
930 pDestination += 1;
931 }
932 }
933 else
934 if(start.y == stop.y)
935 {
936 if(stop.x < start.x)
937 {
938 temp = stop.x;
939 stop.x = start.x;
940 start.x = temp;
941 }
942 pDestination = (uint32_t)hgfx->FBStartAdress;
943 pDestination += start.x * hgfx->ImageHeight * 2;
944 pDestination += start.y * 2;
945 for (j = stop.x - start.x; j > 0; j--)
946 {
947 *(__IO uint8_t*)pDestination = color;
948 pDestination += 1;
949 *(__IO uint8_t*)pDestination = 0xFF;
950 pDestination -= 1;
951 pDestination += hgfx->ImageHeight * 2;
952 }
953 }
954 else // diagonal Bresenham's_line_algorithm
955 {
956 int x0 = start.x;
957 int y0 = start.y;
958 int x1 = stop.x;
959 int y1 = stop.y;
960 int dx = abs(x1-x0), sx = x0<x1 ? 1 : -1;
961 int dy = abs(y1-y0), sy = y0<y1 ? 1 : -1;
962 int err = (dx>dy ? dx : -dy)/2, e2;
963
964 for(;;)
965 {
966 pDestination = (uint32_t)hgfx->FBStartAdress;
967 pDestination += ((x0 * hgfx->ImageHeight) + y0) * 2;
968 *(__IO uint8_t*)pDestination = color;
969 pDestination += 1;
970 *(__IO uint8_t*)pDestination = 0xFF;
971 if (x0==x1 && y0==y1) break;
972 e2 = err;
973 if (e2 >-dx) { err -= dy; x0 += sx; }
974 if (e2 < dy) { err += dx; y0 += sy; }
975 }
976 }
977 }
978
979 // ===============================================================================
980 // GFX_graph_print
981 /// @brief Print all those nice curves, especially in logbook und miniLiveLogGraph
982 /// @version 0.0.2 hw 160519
983 ///
984 /// 151022 hw -bug fix
985 /// - die aktuelle Version macht keine Linien mehr �ber die gesamte Bildschirmh�he.
986 /// - daf�r sind L�cher in der Kurve (z.B. Temperaturgraph Tauchgang Matthias 17.10.15 15:19)
987 ///
988 /// more details about range can be found in show_logbook_logbook_show_log_page2() - temperature graph
989 ///
990 /// @param window: top and bottom is only the range used by the data of the graph, not the entire screen / scale
991 /// @param drawVeilUntil: ist auff�llen des Bereichs unter der Kurve mit etwas hellerer Farbe
992 /// @param Xdivide: wird bisher nichr benutzt.
993 // ===============================================================================
994
995
996 void GFX_graph_print(GFX_DrawCfgScreen *hgfx, const SWindowGimpStyle *window, const 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)
997 {
998 uint16_t* pDestination_tmp;
999 uint16_t* pDestination_start;
1000 uint16_t* pDestination_end;
1001 uint16_t* pDestination_zero_veil;
1002
1003 uint32_t max = 0;
1004 int windowheight = -1;
1005 int windowwidth = -1;
1006 int i = -1;
1007 int w1 = -1;
1008 int w2 = -1;
1009
1010 uint32_t h_ulong = 0;
1011 uint32_t h_ulong_old = 0;
1012 _Bool invert = 0;
1013
1014 uint16_t dataDelta = 0;
1015 uint16_t dataDeltaHalve = 0;
1016 uint16_t dataTemp = 0;
1017
1018 uint8_t colorDataTemp;
1019 uint8_t colormask = 0;
1020
1021 pDestination_zero_veil = 0;
1022
1023 if(dataMin > dataMax)
1024 {
1025 uint16_t dataFlip;
1026 dataFlip = dataMin;
1027 dataMin = dataMax;
1028 dataMax = dataFlip;
1029 invert = 1;
1030 }
1031 else
1032 invert = 0;
1033
1034 colormask = color;
1035
1036 if(window->bottom > 479)
1037 return;
1038 if(window->top > 479)
1039 return;
1040 if(window->right > 799)
1041 return;
1042 if(window->left > 799)
1043 return;
1044 if(window->bottom < 0)
1045 return;
1046 if(window->top < 0)
1047 return;
1048 if(window->right < 0)
1049 return;
1050 if(window->left < 0)
1051 return;
1052 if(window->bottom <= window->top)
1053 return;
1054 if(window->right <= window->left)
1055 return;
1056
1057 windowheight = window->bottom - window->top ;
1058 windowwidth = window->right - window->left;
1059 w1 = 0;
1060 w2 = 0;
1061 if(dataMax == dataMin)
1062 dataMax++;
1063 dataDelta = (unsigned long)(dataMax - dataMin);
1064 dataDeltaHalve = dataDelta / 2;
1065 while((w1 <= windowwidth) && (w2 < datalength))
1066 {
1067 int tmp = (10 * w1 * (long)datalength)/windowwidth;
1068 w2 = tmp/10;
1069 int rest = tmp - w2*10;
1070 if(rest >= 5)
1071 w2++;
1072
1073 if((datalength - 1) < w2)
1074 w2 = datalength-1;
1075
1076 if(colour_data != NULL)
1077 {
1078 colorDataTemp = colour_data[w2];
1079 colormask = color + colorDataTemp;
1080 }
1081
1082 dataTemp = data[w2];
1083 if(Xdivide > 1)
1084 {
1085 w2++;
1086 for(i=1;i<Xdivide;i++)
1087 {
1088 if(data[w2]>dataTemp)
1089 dataTemp = data[w2];
1090 w2++;
1091 }
1092 }
1093
1094 if(dataTemp > dataMin)
1095 dataTemp -= dataMin;
1096 else
1097 dataTemp = 0;
1098
1099 if(invert)
1100 {
1101 if(dataTemp < dataDelta)
1102 dataTemp = dataDelta - dataTemp;
1103 else
1104 dataTemp = 0;
1105 }
1106
1107 h_ulong = (unsigned long)dataTemp;
1108 h_ulong *= windowheight;
1109 h_ulong += dataDeltaHalve;
1110 h_ulong /= dataDelta;
1111
1112 if(h_ulong > (window->bottom - window->top))
1113 h_ulong = (window->bottom - window->top);
1114
1115 if(drawVeilUntil > 0)
1116 {
1117 pDestination_zero_veil = (uint16_t*)hgfx->FBStartAdress;
1118 pDestination_zero_veil += ((479 - (drawVeilUntil - 2) ) + ((w1 + window->left) * hgfx->ImageHeight) );
1119 }
1120 else if(drawVeilUntil < 0 )
1121 {
1122 pDestination_zero_veil = (uint16_t*)hgfx->FBStartAdress;
1123 pDestination_zero_veil += ((479 + (drawVeilUntil)) + ((w1 + window->left) * hgfx->ImageHeight) );
1124 }
1125
1126 if(h_ulong + window->top > max)
1127 {
1128 max = h_ulong + window->top;
1129 }
1130
1131 // hw 160519 wof�r ist das? Damit funktioniert Temperatur 25,5�C nicht!
1132 // if((dataMax == 255) || (data[w2] != 255))
1133 // {
1134 //output_content[pointer] = colormask;
1135 //output_mask[pointer] = true;
1136 if(dataTemp != 0xFFFF) /* do not draw invalid data pixels */
1137 {
1138 if(w1 > 0)
1139 {
1140 pDestination_start = (uint16_t*)hgfx->FBStartAdress;
1141 pDestination_start += (((479 - (window->top)) + ((w1 + window->left) * hgfx->ImageHeight)));
1142 pDestination_end = pDestination_start;
1143
1144 if(h_ulong >= h_ulong_old)
1145 {
1146 pDestination_start -= h_ulong_old;
1147 pDestination_end -= h_ulong;
1148
1149 }
1150 else
1151 {
1152 if(h_ulong < h_ulong_old)
1153 {
1154 pDestination_start += h_ulong_old;
1155 pDestination_end += h_ulong;
1156 }
1157 else
1158 {
1159 pDestination_start += h_ulong;
1160 pDestination_end += h_ulong_old;
1161 }
1162 }
1163
1164
1165 // deco stops
1166 if(drawVeilUntil < 0)
1167 {
1168 pDestination_tmp = pDestination_end;
1169 while(pDestination_tmp <= pDestination_zero_veil)
1170 {
1171 *(__IO uint16_t*)pDestination_tmp = (0x80 << 8) | colormask;
1172 pDestination_tmp++;
1173 }
1174 }
1175 else
1176 {
1177 // regular graph with veil underneath if requested
1178 // von oben nach unten
1179 // von grossen pDestination Werten zu kleinen pDestination Werten
1180 {
1181 pDestination_tmp = pDestination_start;
1182 while(pDestination_tmp >= pDestination_end)
1183 {
1184 *(__IO uint16_t*)pDestination_tmp = (0xFF << 8) | colormask ;
1185 pDestination_tmp--;
1186 }
1187 }
1188
1189 while((drawVeilUntil > 0) && (pDestination_tmp >= pDestination_zero_veil))
1190 {
1191 *(__IO uint16_t*)pDestination_tmp = (0x20 << 8) | colormask ;
1192 pDestination_tmp--;
1193 }
1194 }
1195 }
1196 h_ulong_old = h_ulong;
1197 }
1198 w1++;
1199 w2++;
1200 }
1201 }
1202
1203
1204 void GFX_draw_header(GFX_DrawCfgScreen *hgfx, uint8_t colorId)
1205 {
1206 uint32_t pDestination;
1207 point_t start, stop, now;
1208 uint8_t alpha;
1209
1210 /* display coordinate system */
1211 start.y = 400;
1212 stop.y = 479;
1213
1214 start.x = 0;
1215 stop.x = 799;
1216
1217 now.y = start.y;
1218 now.x = start.x;
1219
1220 while (now.x <= stop.x)
1221 {
1222 now.y = start.y;
1223 pDestination = (uint32_t)hgfx->FBStartAdress;
1224 pDestination += now.x * hgfx->ImageHeight * 2;
1225 pDestination += now.y * 2;
1226 now.x += 1;
1227
1228 alpha = 27;
1229 while(alpha < 246)
1230 {
1231 alpha += 9;
1232 *(__IO uint8_t*)pDestination = colorId;
1233 pDestination += 1;
1234 *(__IO uint8_t*)pDestination = alpha;
1235 pDestination += 1;
1236 now.y += 1;
1237 }
1238
1239 while(now.y <= stop.y)
1240 {
1241 *(__IO uint8_t*)pDestination = colorId;
1242 pDestination += 1;
1243 *(__IO uint8_t*)pDestination = 0xFF;
1244 pDestination += 1;
1245 now.y += 1;
1246 }
1247 }
1248 }
1249
1250 void GFX_draw_box2(GFX_DrawCfgScreen *hgfx, point_t start, point_t stop, uint8_t color, uint8_t roundCorners)
1251 {
1252 point_t point2, point4;
1253
1254 if(roundCorners)
1255 {
1256 point2.x = stop.x - start.x;
1257 point2.y = stop.y - start.y;
1258 GFX_draw_box(hgfx,start,point2,1,color);
1259 }
1260 else
1261 {
1262 point2.x = stop.x;
1263 point2.y = start.y;
1264
1265 point4.x = start.x;
1266 point4.y = stop.y;
1267
1268 GFX_draw_line(hgfx,start,point2,color);
1269 GFX_draw_line(hgfx,point2,stop,color);
1270 GFX_draw_line(hgfx,stop,point4,color);
1271 GFX_draw_line(hgfx,point4,start,color);
1272 }
1273 }
1274
1275 void GFX_draw_box(GFX_DrawCfgScreen *hgfx, point_t LeftLow, point_t WidthHeight, uint8_t Style, uint8_t color)
1276 {
1277 uint16_t* pDestination;
1278 uint16_t* pStart;
1279 uint32_t j;
1280 uint32_t lineWidth, lineHeight;
1281 int x, y;
1282 uint8_t intensity;
1283 int stepdir;
1284
1285 typedef struct {
1286 int x;
1287 int y;
1288 uint8_t intensity;
1289 } corner_t;
1290 const corner_t corner[16] = {
1291 {3,3,255}, // nur einmal
1292 {9,0,242},
1293 {8,0,194},
1294 {7,0,115},
1295 {6,0,36},
1296 {9,1,33},
1297 {8,1,84},
1298 {7,1,161},
1299 {6,1,255},
1300 {5,1,242},
1301 {4,1,36},
1302 {6,2,33},
1303 {5,2,84},
1304 {4,2,255},
1305 {3,2,84},
1306 {4,3,110}
1307 };
1308
1309 lineWidth = WidthHeight.x;
1310 lineHeight = WidthHeight.y;
1311 pStart = (uint16_t*)hgfx->FBStartAdress;
1312
1313 pStart += LeftLow.x * hgfx->ImageHeight;
1314 pStart += LeftLow.y;
1315 stepdir = 1;
1316
1317 // Untere Linie
1318 pDestination = pStart;
1319 if(Style)
1320 {
1321 pDestination += stepdir * 10 * hgfx->ImageHeight;
1322 lineWidth -= 18;
1323 }
1324 for (j = lineWidth; j > 0; j--)
1325 {
1326
1327 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1328 pDestination += stepdir * hgfx->ImageHeight;
1329 }
1330
1331 // Obere Linie
1332
1333 pDestination = pStart + stepdir * WidthHeight.y;
1334 if(Style)
1335 {
1336 pDestination += stepdir * 10 * hgfx->ImageHeight;
1337 }
1338
1339 for (j = lineWidth; j > 0; j--)
1340 {
1341 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1342 pDestination += stepdir * hgfx->ImageHeight;
1343 }
1344
1345 // Linke Linie
1346 pDestination = pStart;
1347
1348 if(Style)
1349 {
1350 pDestination += stepdir * 10;
1351 lineHeight -= 18;
1352 }
1353
1354 for (j = lineHeight; j > 0; j--)
1355 {
1356 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1357 pDestination += stepdir;
1358 }
1359
1360
1361 // Rechte Linie
1362
1363 pDestination = pStart + stepdir * WidthHeight.x * hgfx->ImageHeight;
1364 if(Style)
1365 {
1366 pDestination += stepdir * 10;
1367 }
1368
1369 for (j = lineHeight; j > 0; j--)
1370 {
1371 *(__IO uint16_t*)pDestination = 0xFF00 + color;
1372 pDestination += stepdir;
1373 }
1374
1375
1376 // Ecken wenn notwendig == Style
1377 if(Style)
1378 {
1379 // links unten
1380 pDestination = pStart;
1381 x = corner[0].x;
1382 y = corner[0].y;
1383 intensity = corner[0].intensity;
1384
1385 *(__IO uint16_t*)(pDestination + stepdir * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1386
1387 for(j = 15; j > 0; j--)
1388 {
1389 x = corner[j].x;
1390 y = corner[j].y;
1391 intensity = corner[j].intensity;
1392 *(__IO uint16_t*)(pDestination + stepdir * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1393 *(__IO uint16_t*)(pDestination + stepdir * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1394 }
1395 // links oben
1396 pDestination = pStart + stepdir * WidthHeight.y;
1397 x = corner[0].x;
1398 y = corner[0].y;
1399 intensity = corner[0].intensity;
1400 *(__IO uint16_t*)(pDestination + stepdir * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1401
1402 for(j = 15; j > 0; j--)
1403 {
1404 x = corner[j].x;
1405 y = corner[j].y;
1406 intensity = corner[j].intensity;
1407 *(__IO uint16_t*)(pDestination + stepdir * (-y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1408 *(__IO uint16_t*)(pDestination + stepdir * (-x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1409 }
1410 // rechts unten
1411 pDestination = pStart + stepdir * WidthHeight.x * hgfx->ImageHeight;
1412 x = corner[0].x;
1413 y = corner[0].y;
1414 intensity = corner[0].intensity;
1415 *(__IO uint16_t*)(pDestination + stepdir * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1416
1417 for(j = 15; j > 0; j--)
1418 {
1419 x = corner[j].x;
1420 y = corner[j].y;
1421 intensity = corner[j].intensity;
1422 *(__IO uint16_t*)(pDestination + stepdir * (y - (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1423 *(__IO uint16_t*)(pDestination + stepdir * (x - (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1424 }
1425 // rechts oben
1426 pDestination = pStart + stepdir * WidthHeight.y + stepdir * WidthHeight.x * hgfx->ImageHeight;
1427 x = corner[0].x;
1428 y = corner[0].y;
1429 intensity = corner[0].intensity;
1430 *(__IO uint16_t*)(pDestination + stepdir * -1 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1431
1432 for(j = 15; j > 0; j--)
1433 {
1434 x = corner[j].x;
1435 y = corner[j].y;
1436 intensity = corner[j].intensity;
1437 *(__IO uint16_t*)(pDestination + stepdir * -1 * (y + (x * hgfx->ImageHeight))) = (intensity << 8) + color;
1438 *(__IO uint16_t*)(pDestination + stepdir * -1 * (x + (y * hgfx->ImageHeight))) = (intensity << 8) + color;
1439 }
1440 }
1441 }
1442
1443
1444 /**
1445 ******************************************************************************
1446 * @brief GFX write label. / Write string with defined color
1447 * @author heinrichs weikamp gmbh
1448 * @version V0.0.1
1449 * @date 07-July-2014
1450 ******************************************************************************
1451 *
1452 * @param hgfx: check gfx_engine.h.
1453 * @param color: 16bit Alpha+CLUT.
1454 * @retval None
1455 */
1456
1457 uint32_t GFX_write_label(const tFont *Font, GFX_DrawCfgWindow* hgfx, const char *pText, uint8_t color)
1458 {
1459 return GFX_write_string_color(Font, hgfx, pText, 0, color);
1460 }
1461
1462
1463 /**
1464 ******************************************************************************
1465 * @brief GFX writeGfx_write_label_varstring. / Write string with all parameters and font color options
1466 heinrichs weikamp gmbh
1467 * @version V0.0.1
1468 * @date 22-April-2014
1469 ******************************************************************************
1470 *
1471 * @param XleftGimpStyle:
1472 * @param XrightGimpStyle:
1473 * @param YtopGimpStyle:
1474 * @param color:
1475 * @param tFont:
1476 * @param text: text to be printed
1477 * @retval None
1478 */
1479
1480 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)
1481 {
1482
1483 GFX_DrawCfgWindow hgfx;
1484
1485 if(XrightGimpStyle > 799)
1486 XrightGimpStyle = 799;
1487 if(XleftGimpStyle >= XrightGimpStyle)
1488 XleftGimpStyle = 0;
1489 if(YtopGimpStyle > 479)
1490 YtopGimpStyle = 479;
1491 hgfx.Image = screenInput;
1492 hgfx.WindowNumberOfTextLines = 1;
1493 hgfx.WindowLineSpacing = 0;
1494 hgfx.WindowTab = 0;
1495
1496 hgfx.WindowX0 = XleftGimpStyle;
1497 hgfx.WindowX1 = XrightGimpStyle;
1498 hgfx.WindowY1 = 479 - YtopGimpStyle;
1499 if(hgfx.WindowY1 < Font->height)
1500 hgfx.WindowY0 = 0;
1501 else
1502 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
1503 GFX_write_label(Font, &hgfx, text, color);
1504 }
1505
1506 /**
1507 ******************************************************************************
1508 * @brief GFX write string. / Write string with all parameters and font options
1509 * @author heinrichs weikamp gmbh
1510 * @version V0.0.1
1511 * @date 22-April-2014
1512 ******************************************************************************
1513 *
1514 * @param hgfx: check gfx_engine.h.
1515 * @param color: 32bit ARGB8888.
1516 * @retval None
1517 */
1518
1519 uint16_t GFX_return_offset(const tFont *Font, char *pText, uint8_t position)
1520 {
1521 char character;
1522 uint16_t digit, i;
1523 uint8_t found;
1524 uint16_t distance;
1525
1526 if(position == 0)
1527 return 0;
1528
1529 distance = 0;
1530 for(digit = 0; digit < position; digit++)
1531 {
1532 character = pText[digit];
1533 if(character == 0)
1534 return 0;
1535
1536 found = 0;
1537 for(i=0;i<Font->length;i++)
1538 {
1539 if(Font->chars[i].code == character)
1540 {
1541 found = 1;
1542 break;
1543 }
1544 }
1545 if(found)
1546 {
1547 distance += (uint16_t)(Font->chars[i].image->width);
1548 }
1549 }
1550 return distance;
1551
1552 /* FEHLT:
1553 if(*pText < ' ')
1554 if((*pText) & 0x80)
1555
1556 */
1557 }
1558
1559 void GFX_clean_line(GFX_DrawCfgWindow* hgfx, uint32_t line_number)
1560 {
1561 uint16_t height;
1562 uint32_t pDestination, i, j;
1563 uint16_t left, width, bottom, nextlineStep;
1564
1565 bottom = hgfx->WindowY0;
1566
1567 if(hgfx->WindowNumberOfTextLines && line_number && (line_number <= hgfx->WindowNumberOfTextLines))
1568 {
1569 bottom += hgfx->WindowLineSpacing * (hgfx->WindowNumberOfTextLines - line_number);
1570 height = hgfx->WindowLineSpacing;
1571 }
1572 else
1573 {
1574 height = 1 + hgfx->WindowY1 - bottom;
1575 }
1576
1577 pDestination = (uint32_t)hgfx->Image->FBStartAdress;
1578
1579 left = hgfx->WindowX0;
1580 width = 1 + hgfx->WindowX1 - left;
1581 nextlineStep = hgfx->Image->ImageHeight - height;
1582 nextlineStep *= 2;
1583 pDestination += 2 * bottom;
1584 pDestination += 2 * hgfx->Image->ImageHeight * left;
1585
1586 for(j = width; j > 0; j--)
1587 {
1588 for(i = height; i > 0; i--)
1589 {
1590 *(__IO uint16_t*)pDestination = 0;
1591 pDestination += 2;
1592 }
1593 pDestination += nextlineStep;
1594 }
1595 }
1596
1597
1598 void GFX_clean_area(GFX_DrawCfgScreen *tMscreen, uint16_t XleftGimpStyle, uint16_t XrightGimpStyle, uint16_t YtopGimpStyle, uint16_t YBottomGimpStyle)
1599 {
1600 uint16_t height;
1601 uint32_t pDestination, i, j;
1602 int32_t left, width, bottom, nextlineStep;
1603
1604 bottom = tMscreen->ImageHeight - YBottomGimpStyle;
1605 height = 1 + YBottomGimpStyle - YtopGimpStyle;
1606
1607 if(bottom < 0)
1608 bottom = 0;
1609 if(height > tMscreen->ImageHeight)
1610 height = tMscreen->ImageHeight;
1611
1612 pDestination = tMscreen->FBStartAdress;
1613
1614 left = XleftGimpStyle;
1615 width = 1 + XrightGimpStyle - left;
1616 if(width < 1)
1617 width = 1;
1618
1619 if(width > tMscreen->ImageWidth)
1620 width = tMscreen->ImageWidth;
1621
1622 nextlineStep = tMscreen->ImageHeight - height;
1623 nextlineStep *= 2;
1624 pDestination += 2 * bottom;
1625 pDestination += 2 * tMscreen->ImageHeight * left;
1626
1627 for(j = width; j > 0; j--)
1628 {
1629 for(i = height; i > 0; i--)
1630 {
1631 *(__IO uint16_t*)pDestination = 0;
1632 pDestination += 2;
1633 }
1634 pDestination += nextlineStep;
1635 }
1636 }
1637
1638
1639 uint32_t GFX_write_string(const tFont *Font, GFX_DrawCfgWindow* hgfx, const char *pText, uint32_t line_number)
1640 {
1641 return GFX_write_string_color(Font, hgfx, pText, line_number, 0);
1642 }
1643
1644 uint32_t GFX_write_string_color(const tFont *Font, GFX_DrawCfgWindow* hgfx, const char *pText, uint32_t line_number, uint8_t color)
1645 {
1646 if(hgfx->Image->FBStartAdress < FBGlobalStart)
1647 return 0;
1648
1649 GFX_CfgWriteString settings;
1650 uint32_t newXdelta;
1651 uint8_t minimal = 0;
1652 // uint32_t try_again;
1653
1654 if(hgfx->WindowNumberOfTextLines && line_number && (line_number <= hgfx->WindowNumberOfTextLines))
1655 {
1656 settings.Ydelta = hgfx->WindowLineSpacing * (hgfx->WindowNumberOfTextLines - line_number);
1657 }
1658 else
1659 {
1660 settings.Ydelta = 0;
1661 }
1662 settings.font = (uint32_t)Font;
1663 settings.Xdelta = 0;
1664 settings.color = color;
1665 settings.invert = 0;
1666 settings.resize = 0;
1667 settings.dualFont = 0;
1668 settings.spaceMode = 0;
1669 settings.singleSpaceWithSizeOfNextChar = 0;
1670 settings.useTinyFont = 0;
1671 settings.TinyFontExtraYdelta = 0;
1672 settings.TinyFont = (uint32_t)Font;
1673 settings.doubleSize = 0;
1674
1675 if((*pText) == TXT_MINIMAL) // for customtext and anything with Sonderzeichen
1676 minimal = 1;
1677 else
1678 minimal = 0;
1679
1680 if(Font == &FontT48min)
1681 {
1682 settings.TinyFont = (uint32_t)&FontT24min;
1683 settings.TinyFontExtraYdelta = 6;
1684 }
1685
1686 settings.actualFont = (tFont *)settings.font;
1687
1688 while ((*pText != 0) && (settings.Xdelta != 0x0000FFFF))// und fehlend: Abfrage window / image size
1689 {
1690 // try_again = 0;
1691
1692 if((*pText == '\177') && !minimal)
1693 {
1694 if(settings.singleSpaceWithSizeOfNextChar)
1695 {
1696 settings.singleSpaceWithSizeOfNextChar = 0;
1697 pText++;
1698 settings.Xdelta += *pText;
1699 }
1700 else
1701 settings.singleSpaceWithSizeOfNextChar = 1;
1702 }
1703 else
1704 if(*pText < ' ')
1705 {
1706 /* Xdelta -inline- changes */
1707 if((*pText == '\t') && !minimal)
1708 settings.Xdelta = hgfx->WindowTab - hgfx->WindowX0;
1709 else
1710 if(*pText == '\r') // carriage return, no newline
1711 settings.Xdelta = 0;
1712 else
1713 if((*pText == '\003') && !minimal) // doubleSize
1714 settings.doubleSize = 1;
1715 else
1716 /* Xdelta -up/down changes */
1717 if((*pText == '\f') && !minimal) // form feed = top align
1718 {
1719 if((hgfx->WindowY1 - hgfx->WindowY0) >= ((tFont *)settings.font)->height)
1720 {
1721 settings.Ydelta = hgfx->WindowY1 - hgfx->WindowY0;
1722 settings.Ydelta -= ((tFont *)settings.font)->height;
1723 }
1724 }
1725 else
1726 if(*pText == '\n') // newline, no carriage return
1727 {
1728 if(hgfx->WindowNumberOfTextLines && (line_number < hgfx->WindowNumberOfTextLines))
1729 {
1730 line_number++;
1731 settings.Ydelta = hgfx->WindowLineSpacing * (hgfx->WindowNumberOfTextLines - line_number);
1732 }
1733 }
1734 else
1735 /* Font style changes */
1736 if(*pText == '\a')
1737 settings.invert = settings.invert ? 0 : 1;
1738 else
1739 if((*pText == '\016') && !minimal)
1740 {
1741 if(settings.dualFont == 0)
1742 settings.dualFont = 1;
1743 else
1744 settings.actualFont = (tFont *)settings.TinyFont;
1745 }
1746 else
1747 if((*pText == '\017') && !minimal)
1748 {
1749 settings.dualFont = 0;
1750 settings.actualFont = (tFont *)settings.font;
1751 }
1752 else
1753 if((*pText >= '\020') && (*pText <= '\032') && !minimal)
1754 settings.color = *pText - '\020';
1755 else
1756 if((*pText == '\034') && !minimal)
1757 settings.spaceMode = 1;
1758 else
1759 if((*pText == '\035') && !minimal)
1760 settings.spaceMode = 0;
1761 }
1762 else
1763 if(((*pText) == TXT_2BYTE) && !minimal)
1764 {
1765 pText++;
1766 settings.Xdelta = GFX_write_substring(&settings, hgfx, (uint8_t)TXT_2BYTE, (int8_t)*pText);
1767 }
1768 else
1769 if(((*pText) & 0x80) && !minimal)
1770 settings.Xdelta = GFX_write_substring(&settings, hgfx, (uint8_t)*pText, 0);
1771 else
1772 if(!settings.invert && (*pText == ' '))
1773 {
1774 if(settings.spaceMode == 0)
1775 settings.Xdelta += ((tFont *)settings.font)->spacesize;
1776 else
1777 settings.Xdelta += ((tFont *)settings.font)->spacesize2Monospaced;
1778 }
1779 else
1780 if((settings.spaceMode == 1) && (*pText == ' '))
1781 settings.Xdelta += ((tFont *)settings.font)->spacesize2Monospaced;
1782 else
1783 {
1784 if(settings.actualFont == (tFont *)settings.TinyFont)
1785 settings.Ydelta += settings.TinyFontExtraYdelta;
1786
1787 newXdelta = GFX_write_char(hgfx, &settings, *(uint8_t *)pText, settings.actualFont);
1788 settings.Xdelta = newXdelta;
1789
1790 if(settings.actualFont == (tFont *)settings.TinyFont)
1791 settings.Ydelta -= settings.TinyFontExtraYdelta;
1792 }
1793 if(pText != 0) /* for TXT_2BYTE */
1794 pText++;
1795 }
1796 return settings.Ydelta;
1797 }
1798
1799 /* Private functions ---------------------------------------------------------*/
1800 /******************************************************************************
1801 Static Function
1802 *******************************************************************************/
1803
1804 /**
1805 ******************************************************************************
1806 * @brief GFX write substring. / Write string without parameters
1807 * @author heinrichs weikamp gmbh
1808 * @version V0.0.1
1809 * @date 22-April-2014
1810 ******************************************************************************
1811 *
1812 * @param hgfx: check gfx_engine.h.
1813 * @param color: 32bit ARGB8888.
1814 * @retval None
1815 */
1816
1817 static uint32_t GFX_write_substring(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, uint8_t textId, int8_t nextCharFor2Byte)
1818 {
1819 uint8_t i, j;
1820 uint32_t found;
1821 uint32_t pText;
1822 uint16_t decodeUTF8;
1823
1824 // -----------------------------
1825 if(textId != (uint8_t)TXT_2BYTE)
1826 {
1827 found = 0;
1828 j = 0;
1829 for(i=(uint8_t)TXT_Language;i<(uint8_t)TXT_END;i++)
1830 {
1831 j++;
1832 }
1833 if(!found)
1834 return cfg->Xdelta;
1835
1836 }
1837 // -----------------------------
1838 else
1839 {
1840 if(!nextCharFor2Byte)
1841 return cfg->Xdelta;
1842
1843 found = 0;
1844
1845 if(!found)
1846 return cfg->Xdelta;
1847 }
1848 // -----------------------------
1849
1850 if(cfg->actualFont == (tFont *)cfg->TinyFont)
1851 cfg->Ydelta += cfg->TinyFontExtraYdelta;
1852
1853 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
1854 {
1855 if(*(char*)pText == '\t')
1856 cfg->Xdelta = hgfx->WindowTab - hgfx->WindowX0;
1857 else
1858 if((*(char*)pText == ' ') && (cfg->invert == 0)) /* bypass drawing of white space only for not inverted mode */
1859 {
1860 cfg->Xdelta += ((tFont *)cfg->actualFont)->spacesize;
1861 }
1862 else
1863 if((*(char*)pText) & 0x80) /* Identify a UNICODE character other than standard ASCII using the highest bit */
1864 {
1865 decodeUTF8 = ((*(char*)pText) & 0x1F) << 6; /* use 5bits of first byte for upper part of unicode */
1866 pText++;
1867 decodeUTF8 |= (*(char*)pText) & 0x3F; /* add lower 6bits as second part of the unicode */
1868 if (decodeUTF8 <= 0xff) /* The following function has a uint8 input parameter ==> no UNICODEs > 0xff supported */
1869 {
1870 cfg->Xdelta = GFX_write_char(hgfx, cfg, (uint8_t)decodeUTF8, (tFont *)cfg->actualFont);
1871 }
1872 }
1873 else
1874 cfg->Xdelta = GFX_write_char(hgfx, cfg, *(uint8_t *)pText, (tFont *)cfg->actualFont);
1875
1876 pText++;
1877 }
1878
1879 if(cfg->actualFont == (tFont *)cfg->TinyFont)
1880 cfg->Ydelta -= cfg->TinyFontExtraYdelta;
1881
1882 return cfg->Xdelta;
1883 }
1884
1885
1886 /**
1887 ******************************************************************************
1888 * @brief GFX write char. / Write non-inverted, non-colored with entire 8 bit range
1889 * @author heinrichs weikamp gmbh
1890 * @version V0.0.1
1891 * @date 22-April-2014
1892 ******************************************************************************
1893 *
1894 * @param hgfx: check gfx_engine.h.
1895 * @param Ydelta: input
1896 * @param character: character
1897 * @param *Font: pointer to font to be used for this char
1898 * @retval Ydelta: 0x0000FFFF if not successful or char_truncated
1899 */
1900
1901 static uint32_t GFX_write_char_doubleSize(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font)
1902 {
1903 uint32_t i, j;
1904 uint32_t width, height;
1905 uint32_t found;
1906 uint16_t* pDestination;
1907 uint32_t pSource;
1908 uint32_t OffsetDestination;
1909 uint32_t width_left;
1910 uint32_t height_left;
1911 uint32_t char_truncated_WidthFlag;
1912 uint32_t char_truncated_Height;
1913 uint8_t fill;
1914 uint32_t widthFont, heightFont;
1915 uint32_t nextLine;
1916 int32_t stepdir;
1917
1918 stepdir = 1;
1919
1920 if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
1921 return 0x0000FFFF;
1922
1923 // -----------------------------
1924 found = 0;
1925 for(i=0;i<Font->length;i++)
1926 {
1927 if(Font->chars[i].code == character)
1928 {
1929 found = 1;
1930 break;
1931 }
1932 }
1933 if(!found)
1934 return cfg->Xdelta;
1935
1936 pSource = ((uint32_t)Font->chars[i].image->data);
1937 pDestination = (uint16_t*)(hgfx->Image->FBStartAdress);
1938
1939 heightFont = Font->chars[i].image->height;
1940 widthFont = Font->chars[i].image->width;
1941
1942 height = heightFont*2;
1943 width = widthFont*2;
1944
1945
1946 pDestination += (uint32_t)(hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
1947 pDestination += (hgfx->WindowY0 + cfg->Ydelta); /* set pointer to delta colum */
1948
1949 OffsetDestination = (hgfx->Image->ImageHeight - height);
1950 nextLine = hgfx->Image->ImageHeight;
1951
1952 // -----------------------------
1953 char_truncated_WidthFlag = 0;
1954 width_left = hgfx->Image->ImageWidth - (hgfx->WindowX0 + cfg->Xdelta);
1955 if(width_left < width)
1956 {
1957 char_truncated_WidthFlag = 1;
1958 width = width_left;
1959 widthFont = width/2;
1960 }
1961 // -----------------------------
1962
1963 char_truncated_Height = 0;
1964 height_left = hgfx->Image->ImageHeight - (hgfx->WindowY0 + cfg->Ydelta);
1965 if(height_left < height)
1966 {
1967 char_truncated_Height = height - height_left;
1968 if((char_truncated_Height & 1) != 0)
1969 {
1970 height_left -= 1;
1971 char_truncated_Height += 1;
1972 }
1973 height = height_left;
1974 heightFont = height/2;
1975 }
1976
1977 OffsetDestination += char_truncated_Height;
1978 // -----------------------------
1979 if(height == 0)
1980 return 0x0000FFFF;
1981 // -----------------------------
1982
1983 if(cfg->singleSpaceWithSizeOfNextChar)
1984 {
1985 cfg->singleSpaceWithSizeOfNextChar = 0;
1986
1987 if(cfg->invert)
1988 fill = 0xFF;
1989 else
1990 fill = 0;
1991
1992 height /= 2;
1993 for(i = width; i > 0; i--)
1994 {
1995 for (j = height; j > 0; j--)
1996 {
1997 *(__IO uint16_t*)pDestination = fill << 8 | cfg->color;
1998 pDestination += stepdir;
1999 *(__IO uint16_t*)pDestination = fill << 8 | cfg->color;
2000 pDestination += stepdir;
2001 }
2002 pDestination += stepdir * OffsetDestination;
2003 }
2004 }
2005 else
2006 if(cfg->invert)
2007 {
2008 if((heightFont & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2009 {
2010 heightFont /= 4;
2011 for(i = widthFont; i > 0; i--)
2012 {
2013 if(*(uint8_t*)pSource != 0x01)
2014 {
2015 for (j = heightFont; j > 0; j--)
2016 {
2017 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2018 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2019 pDestination += stepdir;
2020 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2021 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2022 pDestination += stepdir;
2023 pSource++;
2024
2025 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2026 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2027 pDestination += stepdir;
2028 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2029 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2030 pDestination += stepdir;
2031 pSource++;
2032
2033 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2034 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2035 pDestination += stepdir;
2036 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2037 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2038 pDestination += stepdir;
2039 pSource++;
2040
2041 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2042 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2043 pDestination += stepdir;
2044 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2045 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2046 pDestination += stepdir;
2047 pSource++;
2048 }
2049 pSource += char_truncated_Height;
2050 }
2051 else
2052 {
2053 pSource++;
2054 for (j = heightFont; j > 0; j--)
2055 {
2056 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2057 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2058 pDestination += stepdir;
2059 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2060 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2061 pDestination += stepdir;
2062 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2063 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2064 pDestination += stepdir;
2065 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2066 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2067 pDestination += stepdir;
2068 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2069 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2070 pDestination += stepdir;
2071 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2072 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2073 pDestination += stepdir;
2074 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2075 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2076 pDestination += stepdir;
2077 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2078 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2079 pDestination += stepdir;
2080 }
2081 }
2082 pDestination += (OffsetDestination + nextLine) * stepdir;
2083 }
2084 }
2085 else
2086 {
2087 heightFont /= 2;
2088 for(i = widthFont; i > 0; i--)
2089 {
2090 if(*(uint8_t*)pSource != 0x01)
2091 {
2092 for (j = heightFont; j > 0; j--)
2093 {
2094 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2095 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2096 pDestination += stepdir;
2097 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2098 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2099 pDestination += stepdir;
2100 pSource++;
2101
2102 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2103 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2104 pDestination += stepdir;
2105 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2106 *(__IO uint16_t*)(pDestination + nextLine) = (0xFF - *(uint8_t*)pSource) << 8 | cfg->color;
2107 pDestination += stepdir;
2108 pSource++;
2109 }
2110 pSource += char_truncated_Height;
2111 }
2112 else
2113 {
2114 pSource++;
2115 for (j = heightFont; j > 0; j--)
2116 {
2117 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2118 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2119 pDestination += stepdir;
2120 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2121 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2122 pDestination += stepdir;
2123 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2124 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2125 pDestination += stepdir;
2126 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2127 *(__IO uint16_t*)(pDestination + nextLine) = 0xFF << 8 | cfg->color;
2128 pDestination += stepdir;
2129 }
2130 }
2131 pDestination += (OffsetDestination + nextLine) * stepdir;
2132 }
2133 }
2134 } /* inverted */
2135 else
2136 {
2137 if((heightFont & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2138 {
2139 heightFont /= 4;
2140 for(i = widthFont; i > 0; i--)
2141 {
2142 if(*(uint8_t*)pSource != 0x01)
2143 {
2144 for (j = heightFont; j > 0; j--)
2145 {
2146 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2147 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2148 pDestination += stepdir;
2149 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2150 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2151 pDestination += stepdir;
2152 pSource++;
2153
2154 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2155 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2156 pDestination += stepdir;
2157 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2158 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2159 pDestination += stepdir;
2160 pSource++;
2161
2162 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2163 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2164 pDestination += stepdir;
2165 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2166 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2167 pDestination += stepdir;
2168 pSource++;
2169
2170 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2171 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2172 pDestination += stepdir;
2173 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2174 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2175 pDestination += stepdir;
2176 pSource++;
2177 }
2178 pSource += char_truncated_Height;
2179 }
2180 else
2181 {
2182 pSource++;
2183 pDestination += stepdir * height;
2184 }
2185 pDestination += stepdir * (OffsetDestination + nextLine);
2186 }
2187 }
2188 else
2189 {
2190 heightFont /= 2;
2191 for(i = widthFont; i > 0; i--)
2192 {
2193 if(*(uint8_t*)pSource != 0x01)
2194 {
2195 for (j = heightFont; j > 0; j--)
2196 {
2197 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2198 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2199 pDestination += stepdir;
2200 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2201 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2202 pDestination += stepdir;
2203 pSource++;
2204
2205 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2206 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2207 pDestination += stepdir;
2208 *(__IO uint16_t*)pDestination = *(uint8_t*)pSource << 8 | cfg->color;
2209 *(__IO uint16_t*)(pDestination + (stepdir * nextLine)) = *(uint8_t*)pSource << 8 | cfg->color;
2210 pDestination += stepdir;
2211 pSource++;
2212 }
2213 pSource += char_truncated_Height;
2214 }
2215 else
2216 {
2217 pSource++;
2218 pDestination += stepdir * height;
2219 }
2220 pDestination += stepdir * (OffsetDestination + nextLine);
2221 }
2222 }
2223 }
2224
2225
2226 // -----------------------------
2227
2228 if(char_truncated_WidthFlag)
2229 return 0x0000FFFF;
2230 else
2231 return cfg->Xdelta + width;
2232
2233 }
2234
2235
2236 /**
2237 ******************************************************************************
2238 * @brief GFX write char. / Write non-inverted, non-colored with entire 8 bit range
2239 * @author heinrichs weikamp gmbh
2240 * @version V0.0.1
2241 * @date 22-April-2014
2242 ******************************************************************************
2243 *
2244 * @param hgfx: check gfx_engine.h.
2245 * @param Ydelta: input
2246 * @param character: character
2247 * @param *Font: pointer to font to be used for this char
2248 * @retval Ydelta: 0x0000FFFF if not successful or char_truncated
2249 */
2250
2251 static uint32_t GFX_write_char(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font)
2252 {
2253 if(cfg->doubleSize)
2254 {
2255 return GFX_write_char_doubleSize(hgfx, cfg, character, Font);
2256 }
2257
2258 uint32_t i, j;
2259 uint32_t width, height;
2260 uint32_t found;
2261 uint16_t* pDestination;
2262 uint32_t pSource;
2263 uint32_t OffsetDestination;
2264 uint32_t width_left;
2265 uint32_t height_left;
2266 uint32_t char_truncated_WidthFlag;
2267 uint32_t char_truncated_Height;
2268 uint8_t fill;
2269 uint32_t fillpattern;
2270 int16_t stepdir;
2271
2272 stepdir = 1;
2273
2274 if(hgfx->Image->ImageWidth <= (hgfx->WindowX0 + cfg->Xdelta))
2275 return 0x0000FFFF;
2276
2277 // -----------------------------
2278 found = 0;
2279 for(i=0;i<Font->length;i++)
2280 {
2281 if(Font->chars[i].code == character)
2282 {
2283 found = 1;
2284 break;
2285 }
2286 }
2287 if(!found)
2288 return cfg->Xdelta;
2289 // -----------------------------
2290 /*
2291 if(Font == &Font144)
2292 cfg->Xdelta += 3;
2293 else
2294 if(Font == &Font84)
2295 cfg->Xdelta += 2;
2296 */
2297 // -----------------------------
2298
2299
2300 pSource = ((uint32_t)Font->chars[i].image->data);
2301 pDestination = (uint16_t*)(hgfx->Image->FBStartAdress);
2302
2303
2304 height = Font->chars[i].image->height;
2305 width = Font->chars[i].image->width;
2306
2307 OffsetDestination = hgfx->Image->ImageHeight - height;
2308
2309
2310 /* Xyyyyy y= height */
2311 /* Xyyyyy x= width */
2312 /* Xyyyyy */
2313
2314 pDestination += (hgfx->WindowX0 + cfg->Xdelta) * hgfx->Image->ImageHeight; /* set pointer to delta row */
2315 pDestination += (hgfx->WindowY0 + cfg->Ydelta); /* set pointer to delta colum */
2316
2317 // -----------------------------
2318 char_truncated_WidthFlag = 0;
2319 width_left = hgfx->Image->ImageWidth - (hgfx->WindowX0 + cfg->Xdelta);
2320 if(width_left < width)
2321 {
2322 char_truncated_WidthFlag = 1;
2323 width = width_left;
2324 }
2325 // -----------------------------
2326 char_truncated_Height = 0;
2327 height_left = hgfx->Image->ImageHeight - (hgfx->WindowY0 + cfg->Ydelta);
2328 if(height_left < height)
2329 {
2330 char_truncated_Height = height - height_left;
2331 if((char_truncated_Height & 1) != 0)
2332 {
2333 height_left -= 1;
2334 char_truncated_Height += 1;
2335 }
2336 height = height_left;
2337 }
2338 OffsetDestination += char_truncated_Height;
2339 // -----------------------------
2340 if(height == 0)
2341 return 0x0000FFFF;
2342 // -----------------------------
2343
2344 if(cfg->singleSpaceWithSizeOfNextChar)
2345 {
2346 cfg->singleSpaceWithSizeOfNextChar = 0;
2347
2348 if(cfg->invert)
2349 fill = 0xFF;
2350 else
2351 fill = 0;
2352
2353 height /= 2;
2354 for(i = width; i > 0; i--)
2355 {
2356 for (j = height; j > 0; j--)
2357 {
2358 *(__IO uint16_t*)pDestination = fill << 8 | cfg->color;
2359 pDestination += stepdir;
2360 *(__IO uint16_t*)pDestination = fill << 8 | cfg->color;
2361 pDestination += stepdir;
2362 }
2363 pDestination += stepdir * OffsetDestination;
2364 }
2365 }
2366 else
2367 if(cfg->invert)
2368 {
2369 if((height & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2370 {
2371 height /= 4;
2372 for(i = width; i > 0; i--)
2373 {
2374 if(*(uint8_t*)pSource != 0x01)
2375 {
2376
2377 for (j = height; j > 0; j--)
2378 {
2379 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource++) << 8 | cfg->color;
2380 pDestination += stepdir;
2381 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource++) << 8 | cfg->color;
2382 pDestination += stepdir;
2383 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource++) << 8 | cfg->color;
2384 pDestination += stepdir;
2385 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource++) << 8 | cfg->color;
2386 pDestination += stepdir;
2387 }
2388 pSource += char_truncated_Height;
2389 }
2390 else /* empty line => fast fill */
2391 {
2392 pSource++;
2393 fillpattern = (( 0xFF << 8 | cfg->color) << 16) | ( 0xFF << 8 | cfg->color);
2394 for (j = height; j > 0; j--)
2395 {
2396 *(__IO uint32_t*)pDestination = fillpattern;
2397 pDestination += stepdir;
2398 pDestination += stepdir;
2399 *(__IO uint32_t*)pDestination = fillpattern;
2400 pDestination += stepdir;
2401 pDestination += stepdir;
2402 }
2403 }
2404 pDestination += stepdir * OffsetDestination;
2405 }
2406 }
2407 else
2408 {
2409 height /= 2;
2410 for(i = width; i > 0; i--)
2411 {
2412 if(*(uint8_t*)pSource != 0x01)
2413 {
2414 for (j = height; j > 0; j--)
2415 {
2416 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource++) << 8 | cfg->color;
2417 pDestination += stepdir;
2418 *(__IO uint16_t*)pDestination = (0xFF - *(uint8_t*)pSource++) << 8 | cfg->color;
2419 pDestination += stepdir;
2420 }
2421 pSource += char_truncated_Height;
2422 }
2423 else
2424 {
2425 pSource++;
2426 for (j = height; j > 0; j--)
2427 {
2428 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2429 pDestination += stepdir;
2430 *(__IO uint16_t*)pDestination = 0xFF << 8 | cfg->color;
2431 pDestination += stepdir;
2432 }
2433 }
2434 pDestination += stepdir * OffsetDestination;
2435 }
2436 }
2437 }
2438 else /* not inverted */
2439 {
2440 if((height & 3) == 0) /* unroll for perfomance, by 4 if possible, by 2 (16bit) otherwise */
2441 {
2442
2443 height /= 4;
2444
2445 for(i = width; i > 0; i--)
2446 {
2447 if(*(uint8_t*)pSource != 0x01)
2448 {
2449 for (j = height; j > 0; j--)
2450 {
2451 *(__IO uint16_t*)pDestination = ( *(uint8_t*)pSource++ << 8) | (cfg->color);
2452 pDestination += stepdir;
2453 *(__IO uint16_t*)pDestination = ( *(uint8_t*)pSource++ << 8) | (cfg->color);
2454 pDestination += stepdir;
2455 *(__IO uint16_t*)pDestination = ( *(uint8_t*)pSource++ << 8) | (cfg->color);
2456 pDestination += stepdir;
2457 *(__IO uint16_t*)pDestination = ( *(uint8_t*)pSource++ << 8) | (cfg->color);
2458 pDestination += stepdir;
2459 }
2460
2461 pSource += char_truncated_Height;
2462 }
2463 else /* clear line */
2464 {
2465 pSource++;
2466 fillpattern = (cfg->color << 16) | cfg->color;
2467
2468 for (j = height; j > 0; j--)
2469 {
2470 *(__IO uint32_t*)pDestination = fillpattern;
2471 pDestination += stepdir;
2472 pDestination += stepdir;
2473 *(__IO uint32_t*)pDestination = fillpattern;
2474 pDestination += stepdir;
2475 pDestination += stepdir;
2476 }
2477 }
2478 pDestination += stepdir * OffsetDestination;
2479 }
2480 }
2481 else
2482 {
2483 height /= 2;
2484 for(i = width; i > 0; i--)
2485 {
2486 if(*(uint8_t*)pSource != 0x01)
2487 {
2488 for (j = height; j > 0; j--)
2489 {
2490 *(__IO uint16_t*)pDestination = ( *(uint8_t*)pSource++ << 8) | (cfg->color);
2491 pDestination += stepdir;
2492 *(__IO uint16_t*)pDestination = ( *(uint8_t*)pSource++ << 8) | (cfg->color);
2493 pDestination += stepdir;
2494 }
2495 pSource += char_truncated_Height;
2496 }
2497 else /* clear line */
2498 {
2499 pSource++;
2500 for (j = height; j > 0; j--)
2501 {
2502 *(__IO uint16_t*)pDestination = cfg->color;
2503 pDestination += stepdir;
2504 *(__IO uint16_t*)pDestination = cfg->color;
2505 pDestination += stepdir;
2506 }
2507 }
2508 pDestination += stepdir * OffsetDestination;
2509 }
2510 }
2511 }
2512
2513
2514 /*
2515 else
2516 if(Font == &Font144)
2517 width += 3;
2518 else
2519 if(Font == &Font84)
2520 width += 1;
2521 */
2522 // -----------------------------
2523
2524 if(char_truncated_WidthFlag)
2525 return 0x0000FFFF;
2526 else
2527 return cfg->Xdelta + width;
2528 }
2529
2530 void GFX_LTDC_Init(void)
2531 {
2532 GFX_LTDC_Init_display1();
2533 }
2534
2535 void GFX_LTDC_Init_display1(void)
2536 {
2537 /* Timing configuration */
2538 #define ActiveH_d1 800
2539 #define ActiveW_d1 480
2540
2541 #define Hsync_d1 2
2542 #define HFP_d1 8
2543 #define HBP_d1 8
2544
2545 #define Vsync_d1 2
2546 #define VFP_d1 4 // make sure this value * VSYNC is also set in display.c for OLED_VFP_SET
2547 #define VBP_d1 6 // make sure this value * VSYNC is also set in display.c for OLED_VBP_SET
2548
2549 /* Horizontal synchronization width = Hsync - 1 */
2550 LtdcHandle.Init.HorizontalSync = Hsync_d1 - 1;
2551 /* Vertical synchronization height = Vsync - 1 */
2552 LtdcHandle.Init.VerticalSync = Vsync_d1 -1;
2553 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
2554 LtdcHandle.Init.AccumulatedHBP = Hsync_d1 + HBP_d1 - 1;
2555 /* Accumulated vertical back porch = Vsync + VBP - 1 */
2556 LtdcHandle.Init.AccumulatedVBP = Vsync_d1 + VBP_d1 - 1;
2557 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
2558 LtdcHandle.Init.AccumulatedActiveW = Hsync_d1 + HBP_d1 + ActiveW_d1 - 1;
2559 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
2560 LtdcHandle.Init.AccumulatedActiveH = Vsync_d1 + VBP_d1 + ActiveH_d1 - 1;
2561 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
2562 LtdcHandle.Init.TotalWidth = Hsync_d1 + HBP_d1 + ActiveW_d1 + HFP_d1 - 1;
2563 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
2564 LtdcHandle.Init.TotalHeigh = Vsync_d1 + VBP_d1 + ActiveH_d1 + VFP_d1 - 1;
2565
2566 /* Configure R,G,B component values for LCD background color */
2567 LtdcHandle.Init.Backcolor.Red= 0;
2568 LtdcHandle.Init.Backcolor.Blue= 0;
2569 LtdcHandle.Init.Backcolor.Green= 0;
2570
2571 /* LCD clock configuration */
2572 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
2573 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
2574 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
2575 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
2576
2577 /* done in base.c SystemClockConfig
2578
2579 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
2580 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
2581 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
2582 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
2583 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
2584 */
2585 /* Polarity */
2586 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
2587 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL;
2588 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
2589 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IIPC;//LTDC_PCPOLARITY_IPC;
2590
2591 LtdcHandle.Instance = LTDC;
2592
2593 /* Configure the LTDC */
2594 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // initialize GPIO Pins, too
2595 {
2596 /* Initialization Error */
2597 GFX_Error_Handler();
2598 }
2599 }
2600
2601 void GFX_LTDC_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
2602 {
2603 LTDC_LayerCfgTypeDef Layercfg;
2604
2605 /* Layer Init */
2606 Layercfg.WindowX0 = 0;
2607 Layercfg.WindowX1 = 480;
2608 Layercfg.WindowY0 = 0;
2609 Layercfg.WindowY1 = 800;
2610 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_AL88;//LTDC_PIXEL_FORMAT_ARGB8888;
2611 Layercfg.FBStartAdress = FB_Address;
2612 Layercfg.Alpha = 255;
2613 Layercfg.Alpha0 = 0;
2614 Layercfg.Backcolor.Blue = 0;
2615 Layercfg.Backcolor.Green = 0;
2616 Layercfg.Backcolor.Red = 0;
2617 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
2618 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
2619 Layercfg.ImageWidth = 480;
2620 Layercfg.ImageHeight = 800;
2621
2622 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex);
2623 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex);
2624 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex);
2625 }
2626
2627 static uint32_t GFX_doubleBufferOne(void)
2628 {
2629 return SDRAM_DOUBLE_BUFFER_ONE;
2630 }
2631
2632
2633 static uint32_t GFX_doubleBufferTwo(void)
2634 {
2635 return SDRAM_DOUBLE_BUFFER_TWO;
2636 }
2637
2638 uint32_t getFrame(uint8_t callerId)
2639 {
2640 static uint8_t lastFrameProvided = 0;
2641 uint8_t i;
2642
2643 /* first iteration: look for a clear frame */
2644 i = lastFrameProvided;
2645 do
2646 {
2647 i++;
2648 if(i == MAXFRAMES)
2649 {
2650 i = 0;
2651 }
2652 } while((i != lastFrameProvided) && (frame[i].status != CLEAR));
2653
2654 if((i < MAXFRAMES) && (frame[i].status == CLEAR))
2655 {
2656 frame[i].status = BLOCKED;
2657 frame[i].caller = callerId;
2658 lastFrameProvided = i;
2659 return frame[i].StartAddress;
2660 }
2661
2662 /* second iteration: look for a frame which may be reused after clearing */
2663 i = lastFrameProvided;
2664 do
2665 {
2666 i++;
2667 if(i == MAXFRAMES)
2668 {
2669 i = 0;
2670 }
2671 }while((i != lastFrameProvided) && (frame[i].status != RELEASED));
2672
2673
2674 if((i < MAXFRAMES) && (frame[i].status == RELEASED))
2675 {
2676 GFX_clear_frame_immediately(frame[i].StartAddress);
2677 frame[i].status = BLOCKED;
2678 lastFrameProvided = i;
2679 return frame[i].StartAddress;
2680 }
2681 return 0;
2682 }
2683
2684
2685 void GFX_forceReleaseFramesWithId(uint8_t callerId)
2686 {
2687 for(int i=0; i<MAXFRAMES; i++)
2688 if((frame[i].caller == callerId) && (frame[i].status == BLOCKED))
2689 frame[i].status = RELEASED;
2690 }
2691
2692
2693 void releaseAllFramesExcept(uint8_t callerId, uint32_t frameStartAddress)
2694 {
2695 for(int i=0; i<MAXFRAMES; i++)
2696 if((frame[i].caller == callerId) && (frame[i].status == BLOCKED) && (frame[i].StartAddress != frameStartAddress))
2697 frame[i].status = RELEASED;
2698 }
2699
2700
2701 uint8_t releaseFrame(uint8_t callerId, uint32_t frameStartAddress)
2702 {
2703 static uint8_t countErrorCalls = 0;
2704
2705 if(frameStartAddress < FBGlobalStart)
2706 return 2;
2707
2708
2709 uint8_t i;
2710
2711 i = 0;
2712 while((i < MAXFRAMES) && (frame[i].StartAddress != frameStartAddress))
2713 i++;
2714
2715 if((i < MAXFRAMES) && (frame[i].StartAddress == frameStartAddress))
2716 {
2717 if(frame[i].caller == callerId)
2718 {
2719 frame[i].status = RELEASED;
2720 return 1;
2721 }
2722 else
2723 countErrorCalls++;
2724 }
2725 return 0;
2726 }
2727
2728
2729 uint16_t blockedFramesCount(void)
2730 {
2731 uint16_t count = MAXFRAMES;
2732
2733 for(int i = 0;i<MAXFRAMES;i++)
2734 if(frame[i].status == BLOCKED)
2735 count--;
2736
2737 return count;
2738 }
2739
2740
2741 uint8_t housekeepingFrame(void)
2742 {
2743 static uint8_t countLogClear = 0;
2744 uint8_t i;
2745 uint8_t retVal = 1;
2746
2747 if(DMA2D_at_work == 255)
2748 {
2749 i = 0;
2750 /* skip frame cleaning for actual frames which have not yet been replaced by new top/bottom frames */
2751 while((i < MAXFRAMES) && ((frame[i].status != RELEASED) || (frame[i].StartAddress == GFX_get_pActualFrameTop()) || (frame[i].StartAddress == GFX_get_pActualFrameBottom())))
2752 i++;
2753
2754 if((i < MAXFRAMES) && (frame[i].status == RELEASED))
2755 {
2756 if(frame[i].caller == 15)
2757 countLogClear++;
2758 GFX_clear_frame_dma2d(i);
2759 }
2760 else
2761 {
2762 retVal = 0; /* no more frame to be cleaned found */
2763 }
2764 }
2765 return retVal;
2766 }
2767
2768
2769 static void GFX_Dma2d_TransferComplete(DMA2D_HandleTypeDef* Dma2dHandle)
2770 {
2771 if(DMA2D_at_work < MAXFRAMES)
2772 frame[DMA2D_at_work].status = CLEAR;
2773
2774 DMA2D_at_work = 255;
2775 }
2776
2777
2778 static void GFX_Dma2d_TransferError(DMA2D_HandleTypeDef* Dma2dHandle)
2779 {
2780
2781 }
2782
2783 static void GFX_Error_Handler(void)
2784 {
2785 /* Turn LED3 on */
2786 // BSP_LED_On(LED3);
2787 while(1)
2788 {
2789 }
2790 }
2791
2792 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)
2793 {
2794 GFX_DrawCfgWindow hgfx;
2795
2796
2797 if(XrightGimpStyle > 799)
2798 XrightGimpStyle = 799;
2799 if(XleftGimpStyle >= XrightGimpStyle)
2800 XleftGimpStyle = 0;
2801 if(YtopGimpStyle > 479)
2802 YtopGimpStyle = 479;
2803
2804 hgfx.Image = tMscreen;
2805 hgfx.WindowNumberOfTextLines = 1;
2806 hgfx.WindowLineSpacing = 0;
2807 hgfx.WindowTab = 0;
2808
2809 hgfx.WindowX0 = XleftGimpStyle;
2810 hgfx.WindowX1 = XrightGimpStyle;
2811 hgfx.WindowY1 = 479 - YtopGimpStyle;
2812 if(hgfx.WindowY1 < Font->height)
2813 hgfx.WindowY0 = 0;
2814 else
2815 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
2816 GFX_write_string_color(Font, &hgfx, text, 0, color);
2817 }
2818
2819
2820 void gfx_write_topline_simple(GFX_DrawCfgScreen *tMscreen, const char *text, uint8_t color)
2821 {
2822 GFX_DrawCfgWindow hgfx;
2823 const tFont *Font = &FontT48min;
2824
2825 hgfx.Image = tMscreen;
2826 hgfx.WindowNumberOfTextLines = 1;
2827 hgfx.WindowLineSpacing = 0;
2828
2829 hgfx.WindowTab = 0;
2830 hgfx.WindowX0 = 20;
2831 hgfx.WindowX1 = 779;
2832
2833 hgfx.WindowY1 = 479;
2834 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
2835 GFX_write_label(Font, &hgfx, text, color);
2836 }
2837
2838
2839 void gfx_write_page_number(GFX_DrawCfgScreen *tMscreen, uint8_t page, uint8_t total, uint8_t color)
2840 {
2841 GFX_DrawCfgWindow hgfx;
2842 const tFont *Font = &FontT48min;
2843 char text[7];
2844 uint8_t i, secondDigitPage, secondDigitTotal;
2845
2846 if(total > 8)
2847 {
2848 Font = &FontT24min;
2849 }
2850
2851 hgfx.Image = tMscreen;
2852 hgfx.WindowNumberOfTextLines = 1;
2853 hgfx.WindowLineSpacing = 0;
2854 hgfx.WindowTab = 0;
2855
2856 hgfx.WindowX1 = 779;
2857 if(Font == &FontT24min)
2858 {
2859 hgfx.WindowX0 = hgfx.WindowX1 - (Font->spacesize*3);
2860 }
2861 else
2862 {
2863 hgfx.WindowX0 = hgfx.WindowX1 - (Font->spacesize2Monospaced*3);
2864 }
2865 hgfx.WindowY1 = 479;
2866 hgfx.WindowY0 = hgfx.WindowY1 - Font->height;
2867 if(page > 99)
2868 page = 99;
2869 if(total > 99)
2870 total = 99;
2871
2872 i = 0;
2873 text[i++] = '\002';
2874
2875 secondDigitPage = page / 10;
2876 page -= secondDigitPage * 10;
2877
2878 secondDigitTotal = total / 10;
2879 total -= secondDigitTotal * 10;
2880
2881 if(secondDigitPage)
2882 text[i++] = '0' + secondDigitPage;
2883 text[i++] = '0' + page;
2884
2885 text[i++] = '/';
2886
2887 if(secondDigitTotal)
2888 text[i++] = '0' + secondDigitTotal;
2889 text[i++] = '0' + total;
2890
2891 text[i] = 0;
2892
2893 GFX_clear_window_immediately(&hgfx);
2894 GFX_write_label(Font, &hgfx, text, color);
2895 }
2896
2897
2898 uint8_t gfx_number_to_string(uint8_t max_digits, _Bool fill, char *pText, uint32_t input)
2899 {
2900 uint8_t digits[10];
2901 uint32_t number, divider;
2902 int first;
2903 uint8_t out;
2904
2905 number = input;
2906 first = 0;
2907 divider = 1000000000;
2908 for(int i=9;i>=0;i--)
2909 {
2910 digits[i] = (uint8_t)(number / divider);
2911 number -= digits[i] * divider;
2912 divider /= 10;
2913 if((first == 0) && (digits[i] != 0))
2914 first = i;
2915 }
2916
2917 if((first + 1) > max_digits)
2918 {
2919 for(int i = 0; i<max_digits; i++)
2920 pText[i] = '9';
2921 out = max_digits;
2922 }
2923 else if(fill)
2924 {
2925 int i = 0;
2926 for(int k = max_digits; k>0; k--)
2927 pText[i++] = digits[k -1] + '0';
2928 out = max_digits;
2929 }
2930 else
2931 {
2932 int i = 0;
2933 for(int k = first; k>=0; k--)
2934 pText[i++] = digits[k] + '0';
2935 out = i;
2936 }
2937
2938 return out;
2939 }
2940
2941
2942 /* output is
2943 * 0->
2944 * |
2945 * v
2946 *
2947 * input is
2948 *
2949 * ->
2950 * A
2951 * |
2952 * 0
2953 */
2954 void GFX_screenshot(void)
2955 {
2956 uint32_t pSource = GFX_get_pActualFrameTop();
2957 uint32_t pSourceBottom =GFX_get_pActualFrameBottom();
2958 uint32_t pBottomNew = getFrame(99);
2959 uint32_t pDestination = GFX_doubleBufferOne();
2960 uint32_t sourceNow;
2961
2962
2963 uint32_t bot_leftStart = FrameHandler.actualBottom.leftStart; // x0 z.B. 0
2964 uint32_t bot_bottomStart = FrameHandler.actualBottom.bottomStart; // y0 z.B. 25
2965 uint32_t bot_width = FrameHandler.actualBottom.width; // 800
2966 uint32_t bot_height = FrameHandler.actualBottom.height; // 390
2967
2968 struct split
2969 {
2970 uint8_t blue;
2971 uint8_t green;
2972 uint8_t red;
2973 uint8_t alpha;
2974 };
2975
2976 union inout_u
2977 {
2978 uint32_t in;
2979 struct split out;
2980 };
2981
2982 union inout_u value;
2983
2984 /* test
2985 uint32_t pSourceTemp = pSource + (2*479);
2986 for (int j = 0xFFFF; j > 0x00FF; j -= 0x0100)
2987 {
2988 *(__IO uint16_t*)pSourceTemp = j;
2989 pSourceTemp += 480*2;
2990 }
2991 */
2992 // Top Layer
2993 const unsigned width = 800, height = 480;
2994 const uint32_t heightX2 = height*2;
2995
2996 for(unsigned y = 0; y < height; y++)
2997 {
2998 sourceNow = pSource + 2 * ((height - 1) - y);
2999 for(unsigned x = 0; x < width; x++)
3000 {
3001 // sourceNow += 2 * height * x + 2 * (height - 1 - y);
3002 value.in = ColorLUT[*(__IO uint8_t*)(sourceNow)];
3003 value.out.alpha = *(__IO uint8_t*)(sourceNow + 1);
3004
3005 *(__IO uint8_t*)(pDestination++) = value.out.red;
3006 *(__IO uint8_t*)(pDestination++) = value.out.green;
3007 *(__IO uint8_t*)(pDestination++) = value.out.blue;
3008 *(__IO uint8_t*)(pDestination++) = value.out.alpha;
3009 sourceNow += heightX2;
3010 }
3011 }
3012
3013 // Bottom Layer
3014 // build newBottom
3015 pSource = pSourceBottom;
3016 for(unsigned x = bot_leftStart; x < bot_leftStart+bot_width; x++)
3017 {
3018 for(unsigned y = bot_bottomStart; y < bot_bottomStart+bot_height; y++)
3019 {
3020 pDestination = pBottomNew + (2 * y);
3021 pDestination += heightX2 * x;
3022 *(__IO uint16_t*)(pDestination) = *(__IO uint16_t*)(pSource);
3023 pSource += 2;
3024 }
3025 }
3026
3027 // output Bottom Layer
3028 pSource = pBottomNew;
3029 pDestination = GFX_doubleBufferTwo();
3030
3031 for(unsigned y = 0; y < height; y++)
3032 {
3033 sourceNow = pSource + 2 * ((height - 1) - y);
3034 for(unsigned x = 0; x < width; x++)
3035 {
3036 // sourceNow = pSource + 2 * height * x + 2 * (height - 1 - y);
3037 value.in = ColorLUT[*(__IO uint8_t*)(sourceNow)];
3038 value.out.alpha = *(__IO uint8_t*)(sourceNow + 1);
3039
3040 *(__IO uint8_t*)(pDestination++) = value.out.red;
3041 *(__IO uint8_t*)(pDestination++) = value.out.green;
3042 *(__IO uint8_t*)(pDestination++) = value.out.blue;
3043 *(__IO uint8_t*)(pDestination++) = value.out.alpha;
3044 sourceNow += heightX2;
3045 }
3046 }
3047 releaseFrame(99,pBottomNew);
3048 /*
3049 // das kommt dazu!
3050 unsigned yEnd = 480 - FrameHandler.actualBottom.bottomStart;
3051 unsigned yStart = yEnd - FrameHandler.actualBottom.height;
3052
3053 if(yStart > 0)
3054 {
3055 for(unsigned y = 0; y < yStart; y++)
3056 for(unsigned x = 0; x < width; x++)
3057 {
3058 *(__IO uint8_t*)(pDestination++) = 0;
3059 *(__IO uint8_t*)(pDestination++) = 0;
3060 *(__IO uint8_t*)(pDestination++) = 0;
3061 *(__IO uint8_t*)(pDestination++) = 0;
3062 }
3063 }
3064 for(unsigned y = yStart; y < yEnd; y++)
3065 for(unsigned x = 0; x < width; x++)
3066 {
3067 sourceNow = pSource + 2 * height * x + 2 * (height - 1 - y);
3068 value.in = ColorLUT[*(__IO uint8_t*)(sourceNow)];
3069 value.out.alpha = *(__IO uint8_t*)(sourceNow + 1);
3070
3071 *(__IO uint8_t*)(pDestination++) = value.out.red;
3072 *(__IO uint8_t*)(pDestination++) = value.out.green;
3073 *(__IO uint8_t*)(pDestination++) = value.out.blue;
3074 *(__IO uint8_t*)(pDestination++) = value.out.alpha;
3075 }
3076 if(yEnd < 480)
3077 {
3078 for(unsigned y = yEnd; y < 480; y++)
3079 for(unsigned x = 0; x < width; x++)
3080 {
3081 *(__IO uint8_t*)(pDestination++) = 0;
3082 *(__IO uint8_t*)(pDestination++) = 0;
3083 *(__IO uint8_t*)(pDestination++) = 0;
3084 *(__IO uint8_t*)(pDestination++) = 0;
3085 }
3086 }
3087 */
3088 }
3089
3090 uint32_t GFX_Character_Width(uint8_t character, tFont *Font)
3091 {
3092 uint32_t i;
3093 for(i=0;i<Font->length;i++)
3094 {
3095 if(Font->chars[i].code == character)
3096 {
3097 return Font->chars[i].image->width;
3098 }
3099 }
3100
3101 return 0;
3102 }
3103
3104 void Gfx_colorsscheme_mod(char *text, uint8_t alternativeColor)
3105 {
3106 char *p = text;
3107 uint8_t index = 0;
3108
3109 while ((*p) && (index < MAX_COLOR_STRING_LENGTH))
3110 {
3111 if (*p == '\020')
3112 {
3113 if(!GFX_is_colorschemeDiveStandard())
3114 {
3115 *p = '\027';
3116 }
3117 else if(alternativeColor != 0)
3118 {
3119 *p += alternativeColor;
3120 }
3121 }
3122 p++;
3123 index++;
3124 }
3125 }
3126