comparison Discovery/Src/gfx_engine.c @ 299:b70c26be71a0

Merged in janlmulder/ostc4/cleanup-3 (pull request #24) 1 bug fix, 1 possible bug fix and some cleanup.
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Fri, 17 May 2019 06:38:56 +0000
parents 87d54b4fd946
children e141b571a03d
comparison
equal deleted inserted replaced
295:718e5feded62 299:b70c26be71a0
112 #define SDRAM_DOUBLE_BUFFER_END ((uint32_t)(SDRAM_DOUBLE_BUFFER_TWO + (2 * FBOffsetEachIndex))) 112 #define SDRAM_DOUBLE_BUFFER_END ((uint32_t)(SDRAM_DOUBLE_BUFFER_TWO + (2 * FBOffsetEachIndex)))
113 113
114 /* Semi Private variables ---------------------------------------------------------*/ 114 /* Semi Private variables ---------------------------------------------------------*/
115 115
116 DMA2D_HandleTypeDef Dma2dHandle; 116 DMA2D_HandleTypeDef Dma2dHandle;
117 LTDC_HandleTypeDef LtdcHandle; 117 static LTDC_HandleTypeDef LtdcHandle;
118 118
119 /* Private variables ---------------------------------------------------------*/ 119 /* Private variables ---------------------------------------------------------*/
120 120
121 uint8_t DMA2D_at_work = 0; 121 static uint8_t DMA2D_at_work = 0;
122 122
123 GFX_layerControl FrameHandler = { 0 }; 123 static GFX_layerControl FrameHandler = { 0 };
124 124
125 uint32_t pInvisibleFrame = 0; 125 static uint32_t pInvisibleFrame = 0;
126 uint32_t pLogoFrame = 0; 126 static uint32_t pLogoFrame = 0;
127 uint8_t logoStatus; 127 static uint8_t logoStatus;
128 uint32_t pBackgroundHwFrame = 0; 128 static uint32_t pBackgroundHwFrame = 0;
129 uint8_t backgroundHwStatus; 129 static uint8_t backgroundHwStatus;
130 130
131 SFrameList frame[MAXFRAMES]; 131 static SFrameList frame[MAXFRAMES];
132 132
133 #define MAXFRAMECOUNTER (28) 133 #define MAXFRAMECOUNTER (28)
134 uint8_t frameCounter[MAXFRAMECOUNTER] = { 0 }; 134 static uint8_t frameCounter[MAXFRAMECOUNTER] = { 0 };
135 135
136 _Bool lock_changeLTDC = 0; 136 static _Bool lock_changeLTDC = 0;
137 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);
138 /* ITM Trace-----------------------------------------------------------------*/ 140 /* ITM Trace-----------------------------------------------------------------*/
139 141
140 #include "stdio.h" 142 #include "stdio.h"
141 143
142 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n))) 144 #define ITM_Port8(n) (*((volatile unsigned char *)(0xE0000000+4*n)))
171 173
172 /* Private function prototypes -----------------------------------------------*/ 174 /* Private function prototypes -----------------------------------------------*/
173 175
174 static uint32_t GFX_write_char(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font); 176 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); 177 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); 178 static 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); 179 static uint32_t GFX_write__Modify_Xdelta__RightAlign(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput);
178 static void GFX_Error_Handler(void); 180 static void GFX_Error_Handler(void);
179 static void GFX_Dma2d_TransferComplete(DMA2D_HandleTypeDef* Dma2dHandle); 181 static void GFX_Dma2d_TransferComplete(DMA2D_HandleTypeDef* Dma2dHandle);
180 static void GFX_Dma2d_TransferError(DMA2D_HandleTypeDef* Dma2dHandle); 182 static void GFX_Dma2d_TransferError(DMA2D_HandleTypeDef* Dma2dHandle);
181 void GFX_clear_frame_dma2d(uint8_t frameId); 183 static void GFX_clear_frame_dma2d(uint8_t frameId);
182 184
183 uint32_t GFX_doubleBufferOne(void); 185 static uint32_t GFX_doubleBufferOne(void);
184 uint32_t GFX_doubleBufferTwo(void); 186 static uint32_t GFX_doubleBufferTwo(void);
185 187
186 188
187 /* Exported functions --------------------------------------------------------*/ 189 /* Exported functions --------------------------------------------------------*/
188 190
189 uint8_t GFX_logoStatus(void) 191 uint8_t GFX_logoStatus(void)
190 { 192 {
191 return logoStatus; 193 return logoStatus;
192 } 194 }
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 195
217 void GFX_SetWindowLayer0(uint32_t pDestination, int16_t XleftGimpStyle, int16_t XrightGimpStyle, int16_t YtopGimpStyle, int16_t YbottomGimpStyle) 196 void GFX_SetWindowLayer0(uint32_t pDestination, int16_t XleftGimpStyle, int16_t XrightGimpStyle, int16_t YtopGimpStyle, int16_t YbottomGimpStyle)
218 { 197 {
219 int16_t XSize, YSize, X0, Y0; 198 int16_t XSize, YSize, X0, Y0;
220 199
256 { 235 {
257 if(logoStatus == LOGOOFF) 236 if(logoStatus == LOGOOFF)
258 logoStatus = LOGOSTART; 237 logoStatus = LOGOSTART;
259 } 238 }
260 239
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 240
307 void GFX_hwBackgroundOn(void) 241 void GFX_hwBackgroundOn(void)
308 { 242 {
309 backgroundHwStatus = LOGOSTART; 243 backgroundHwStatus = LOGOSTART;
310 } 244 }
314 { 248 {
315 backgroundHwStatus = LOGOSTOP; 249 backgroundHwStatus = LOGOSTOP;
316 } 250 }
317 251
318 252
319 void GFX_build_hw_background_frame(void) 253 static void GFX_build_hw_background_frame(void)
320 { 254 {
321 GFX_DrawCfgScreen tLogoTemp; 255 GFX_DrawCfgScreen tLogoTemp;
322 SWindowGimpStyle windowGimp; 256 SWindowGimpStyle windowGimp;
323 257
324 pBackgroundHwFrame = getFrame(1); 258 pBackgroundHwFrame = getFrame(1);
348 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020); 282 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020);
349 */ 283 */
350 } 284 }
351 285
352 286
353 287 static void GFX_build_logo_frame(void)
354
355 void GFX_build_logo_frame(void)
356 { 288 {
357 GFX_DrawCfgScreen tLogoTemp; 289 GFX_DrawCfgScreen tLogoTemp;
358 SWindowGimpStyle windowGimp; 290 SWindowGimpStyle windowGimp;
359 291
360 pLogoFrame = getFrame(1); 292 pLogoFrame = getFrame(1);
432 364
433 DMA2D_at_work = 255; 365 DMA2D_at_work = 255;
434 } 366 }
435 367
436 368
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) 369 void GFX_SetFrameTop(uint32_t pDestination)
492 { 370 {
493 lock_changeLTDC = 1; 371 lock_changeLTDC = 1;
494 uint8_t boolNextTop = !FrameHandler.boolNextTop; 372 uint8_t boolNextTop = !FrameHandler.boolNextTop;
495 373
525 GFX_SetFrameTop(pTop); 403 GFX_SetFrameTop(pTop);
526 GFX_SetFrameBottom(pBottom, 0, 0, 800, heightBottom); 404 GFX_SetFrameBottom(pBottom, 0, 0, 800, heightBottom);
527 } 405 }
528 406
529 407
530 uint32_t GFX_get_pActualFrameTop(void) 408 static uint32_t GFX_get_pActualFrameTop(void)
531 { 409 {
532 return FrameHandler.pActualTopBuffer; 410 return FrameHandler.pActualTopBuffer;
533 } 411 }
534 412
535 413
536 uint32_t GFX_get_pActualFrameBottom(void) 414 static uint32_t GFX_get_pActualFrameBottom(void)
537 { 415 {
538 return FrameHandler.actualBottom.pBuffer; 416 return FrameHandler.actualBottom.pBuffer;
539 } 417 }
540 418
541 419
770 } 648 }
771 offsetSourceStartOfLine -= 2; 649 offsetSourceStartOfLine -= 2;
772 } 650 }
773 } 651 }
774 652
775 HAL_StatusTypeDef GFX_SetBackgroundColor(uint32_t LayerIdx, uint8_t red, uint8_t green, uint8_t blue) 653
776 { 654 static void GFX_clear_frame_immediately(uint32_t pDestination)
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 { 655 {
815 uint32_t i; 656 uint32_t i;
816 uint32_t* pfill = (uint32_t*) pDestination; 657 uint32_t* pfill = (uint32_t*) pDestination;
817 658
818 659
851 pDestination += nextlineStep; 692 pDestination += nextlineStep;
852 } 693 }
853 } 694 }
854 695
855 696
856 void GFX_clear_frame_dma2d(uint8_t frameId) 697 static void GFX_clear_frame_dma2d(uint8_t frameId)
857 { 698 {
858 if(frameId >= MAXFRAMES) 699 if(frameId >= MAXFRAMES)
859 return; 700 return;
860 701
861 DMA2D_at_work = frameId; 702 DMA2D_at_work = frameId;
887 *pfill++ = fillpattern; 728 *pfill++ = fillpattern;
888 } 729 }
889 } 730 }
890 731
891 732
892 void gfx_flip(point_t *p1, point_t *p2) 733 static void gfx_flip(point_t *p1, point_t *p2)
893 { 734 {
894 point_t temp; 735 point_t temp;
895 736
896 temp = *p1; 737 temp = *p1;
897 *p1 = *p2; 738 *p1 = *p2;
1112 } 953 }
1113 } 954 }
1114 } 955 }
1115 956
1116 957
1117 void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image) 958 static void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
1118 { 959 {
1119 uint16_t* pDestination; 960 uint16_t* pDestination;
1120 961
1121 uint32_t j; 962 uint32_t j;
1122 point_t start, stop; 963 point_t start, stop;
1158 } 999 }
1159 } 1000 }
1160 } 1001 }
1161 1002
1162 1003
1163 int16_Point_t switchToOctantZeroFrom(uint8_t octant, int16_t x, int16_t y)
1164 {
1165 int16_Point_t answer;
1166 switch(octant)
1167 {
1168 case 0:// return (x,y);
1169 answer.x = x;
1170 answer.y = y;
1171 break;
1172 case 1:// return (y,x);
1173 answer.x = y;
1174 answer.y = x;
1175 break;
1176 case 2:// return (y, -x);
1177 answer.x = y;
1178 answer.y = -x;
1179 break;
1180 case 3:// return (-x, y);
1181 answer.x = -x;
1182 answer.y = y;
1183 break;
1184 case 4:// return (-x, -y);
1185 answer.x = -x;
1186 answer.y = -y;
1187 break;
1188 case 5:// return (-y, -x);
1189 answer.x = -y;
1190 answer.y = -x;
1191 break;
1192 case 6:// return (-y, x);
1193 answer.x = -y;
1194 answer.y = x;
1195 break;
1196 case 7:// return (x, -y);
1197 answer.x = x;
1198 answer.y = -y;
1199 break;
1200 }
1201 return answer;
1202 }
1203
1204 /* this is NOT fast nor optimized */ 1004 /* this is NOT fast nor optimized */
1205 void GFX_draw_pixel(GFX_DrawCfgScreen *hgfx, int16_t x, int16_t y, uint8_t color) 1005 static void GFX_draw_pixel(GFX_DrawCfgScreen *hgfx, int16_t x, int16_t y, uint8_t color)
1206 { 1006 {
1207 uint16_t* pDestination; 1007 uint16_t* pDestination;
1208 1008
1209 SSettings* pSettings; 1009 SSettings* pSettings;
1210 pSettings = settingsGetPointer(); 1010 pSettings = settingsGetPointer();
1219 { 1019 {
1220 pDestination += x * hgfx->ImageHeight; 1020 pDestination += x * hgfx->ImageHeight;
1221 pDestination += y; 1021 pDestination += y;
1222 } 1022 }
1223 *(__IO uint16_t*)pDestination = 0xFF << 8 | color; 1023 *(__IO uint16_t*)pDestination = 0xFF << 8 | color;
1224 }
1225
1226
1227 /* store the quarter circle for given radius */
1228 void GFX_draw_circle_with_MEMORY(uint8_t use_memory, GFX_DrawCfgScreen *hgfx, point_t center, uint8_t radius, int8_t color)
1229 {
1230 } 1024 }
1231 1025
1232 /* this is NOT fast nor optimized */ 1026 /* this is NOT fast nor optimized */
1233 void GFX_draw_circle(GFX_DrawCfgScreen *hgfx, point_t center, uint8_t radius, int8_t color) 1027 void GFX_draw_circle(GFX_DrawCfgScreen *hgfx, point_t center, uint8_t radius, int8_t color)
1234 { 1028 {
1391 // GFX_draw_colorline(hgfx, p1,p2, color ); 1185 // GFX_draw_colorline(hgfx, p1,p2, color );
1392 GFX_draw_line(hgfx, p1,p2, color ); 1186 GFX_draw_line(hgfx, p1,p2, color );
1393 } 1187 }
1394 } 1188 }
1395 } 1189 }
1396
1397 /* drawVeilUntil ist auff�llen des Bereichs unter der Kurve mit etwas hellerer Farbe
1398 * Xdivide ist nichr benutzt, wird weggelassen in dieser Version
1399 */
1400 /*
1401 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)
1402 {
1403 if(window->bottom > 479)
1404 return;
1405 if(window->top > 479)
1406 return;
1407 if(window->right > 799)
1408 return;
1409 if(window->left > 799)
1410 return;
1411 if(window->bottom < 0)
1412 return;
1413 if(window->top < 0)
1414 return;
1415 if(window->right < 0)
1416 return;
1417 if(window->left < 0)
1418 return;
1419 if(window->bottom <= window->top)
1420 return;
1421 if(window->right <= window->left)
1422 return;
1423
1424 uint16_t windowwidth = (uint16_t)window->right - (uint16_t)window->left;
1425
1426 if(dataMax == dataMin)
1427 dataMax++;
1428
1429 uint8_t invert = 0;
1430 if(dataMin > dataMax)
1431 {
1432 uint16_t dataFlip;
1433 dataFlip = dataMin;
1434 dataMin = dataMax;
1435 dataMax = dataFlip;
1436 invert = 1;
1437 }
1438 else
1439 invert = 0;
1440
1441 uint16_t dataDelta = 0;
1442 dataDelta = dataMax - dataMin;
1443
1444 uint8_t colormask = color;
1445
1446 uint16_t loopX, loopData;
1447 loopX = 0;
1448 loopData = 0;
1449 while((loopX <= windowwidth) & (loopData < datalength))
1450 {
1451
1452 }
1453
1454
1455 uint32_t pDestination_zero_veil = 0;
1456 uint32_t pDestination = 0;
1457 uint32_t pDestinationOld = 0;
1458 int windowwidth = -1;
1459 int windowheight = -1;
1460 int w1 = -1;
1461 int w2 = -1;
1462 int value = -1;
1463 uint8_t colormask = 0;
1464
1465 // preparation
1466 windowheight = window->bottom - window->top;
1467 windowwidth = window->right - window->left;
1468 pDestination_zero_veil = hgfx->FBStartAdress + 2 * ( (479 - (drawVeilUntil - 2) ) + ( (window->left) * hgfx->ImageHeight) );
1469
1470 while((w1 <= windowwidth) & (w2 < datalength))
1471 {
1472 // before
1473 if(colour_data != NULL)
1474 {
1475 colormask = color + colour_data[w2];
1476 }
1477 pDestination = hgfx->FBStartAdress + 2 * ( (479 - (window->top + value) ) + ( (w1 + window->left) * hgfx->ImageHeight) );
1478
1479 // after
1480 pDestination_zero_veil += (window->left) * hgfx->ImageHeight;
1481 }
1482 }
1483 */
1484
1485
1486 1190
1487 // =============================================================================== 1191 // ===============================================================================
1488 // GFX_graph_print 1192 // GFX_graph_print
1489 /// @brief Print all those nice curves, especially in logbook und miniLiveLogGraph 1193 /// @brief Print all those nice curves, especially in logbook und miniLiveLogGraph
1490 /// @version 0.0.2 hw 160519 1194 /// @version 0.0.2 hw 160519
1573 w2 = 0; 1277 w2 = 0;
1574 if(dataMax == dataMin) 1278 if(dataMax == dataMin)
1575 dataMax++; 1279 dataMax++;
1576 dataDelta = (unsigned long)(dataMax - dataMin); 1280 dataDelta = (unsigned long)(dataMax - dataMin);
1577 dataDeltaHalve = dataDelta / 2; 1281 dataDeltaHalve = dataDelta / 2;
1578 while((w1 <= windowwidth) & (w2 < datalength)) 1282 while((w1 <= windowwidth) && (w2 < datalength))
1579 { 1283 {
1580 int tmp = (10 * w1 * (long)datalength)/windowwidth; 1284 int tmp = (10 * w1 * (long)datalength)/windowwidth;
1581 w2 = tmp/10; 1285 w2 = tmp/10;
1582 int rest = tmp - w2*10; 1286 int rest = tmp - w2*10;
1583 if(rest >= 5) 1287 if(rest >= 5)
2015 } 1719 }
2016 } 1720 }
2017 } 1721 }
2018 1722
2019 1723
2020
2021
2022 /** 1724 /**
2023 ****************************************************************************** 1725 ******************************************************************************
2024 * @brief GFX write label. / Write string with defined color 1726 * @brief GFX write label. / Write string with defined color
2025 * @author heinrichs weikamp gmbh 1727 * @author heinrichs weikamp gmbh
2026 * @version V0.0.1 1728 * @version V0.0.1
3272 * @param *cText: output 2974 * @param *cText: output
3273 * @param *pTextInput: input 2975 * @param *pTextInput: input
3274 * @param gfx_selected_language: gfx_selected_language 2976 * @param gfx_selected_language: gfx_selected_language
3275 * @retval counter and *cText content 2977 * @retval counter and *cText content
3276 */ 2978 */
3277 int8_t GFX_write__Modify_helper(char *cText, const char *pTextInput, uint8_t gfx_selected_language) 2979 static int8_t GFX_write__Modify_helper(char *cText, const char *pTextInput, uint8_t gfx_selected_language)
3278 { 2980 {
3279 uint32_t pText, backup; 2981 uint32_t pText, backup;
3280 uint8_t textId; 2982 uint8_t textId;
3281 int8_t counter; 2983 int8_t counter;
3282 uint32_t found; 2984 uint32_t found;
3372 * @param *cfg: Ydelta, Font 3074 * @param *cfg: Ydelta, Font
3373 * @param *pText: character 3075 * @param *pText: character
3374 * @retval Ydelta: 0 if text has to start left ( and probably does not fit) 3076 * @retval Ydelta: 0 if text has to start left ( and probably does not fit)
3375 */ 3077 */
3376 3078
3377 uint32_t GFX_write__Modify_Xdelta__Centered(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput) 3079 static uint32_t GFX_write__Modify_Xdelta__Centered(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput)
3378 { 3080 {
3379 char cText[101]; 3081 char cText[101];
3380 uint32_t result; 3082 uint32_t result;
3381 uint32_t Xsum; 3083 uint32_t Xsum;
3382 uint32_t i, j; 3084 uint32_t i, j;
3442 result = 0; 3144 result = 0;
3443 return result; 3145 return result;
3444 } 3146 }
3445 3147
3446 3148
3447 uint32_t GFX_write__Modify_Xdelta__RightAlign(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput) 3149 static uint32_t GFX_write__Modify_Xdelta__RightAlign(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput)
3448 { 3150 {
3449 char cText[101]; 3151 char cText[101];
3450 uint32_t result; 3152 uint32_t result;
3451 uint32_t Xsum; 3153 uint32_t Xsum;
3452 uint32_t i, j; 3154 uint32_t i, j;
3539 else 3241 else
3540 result = 0; 3242 result = 0;
3541 3243
3542 return result; 3244 return result;
3543 } 3245 }
3544
3545
3546 3246
3547 void GFX_LTDC_Init(void) 3247 void GFX_LTDC_Init(void)
3548 { 3248 {
3549 /* 3249 /*
3550 HSYNC=10 (9+1) 3250 HSYNC=10 (9+1)
3609 /* Initialization Error */ 3309 /* Initialization Error */
3610 GFX_Error_Handler(); 3310 GFX_Error_Handler();
3611 } 3311 }
3612 } 3312 }
3613 3313
3614 void GFX_VGA_LTDC_Init_test(void)
3615 {
3616
3617 LtdcHandle.Init.HorizontalSync = 48;
3618 /* Vertical synchronization height = Vsync - 1 */
3619 LtdcHandle.Init.VerticalSync = 3;
3620 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
3621 LtdcHandle.Init.AccumulatedHBP = 48 + 40 - 1;
3622 /* Accumulated vertical back porch = Vsync + VBP - 1 */
3623 LtdcHandle.Init.AccumulatedVBP = 3 + 29 - 1;
3624 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
3625 LtdcHandle.Init.AccumulatedActiveW = 800 + 48 + 40 - 1;//499;//500;//499;
3626 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
3627 LtdcHandle.Init.AccumulatedActiveH = 480 + 3 + 29 - 1;
3628 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
3629 LtdcHandle.Init.TotalWidth = 800 + 48 + 40 - 1 + 40;//508;//507;
3630 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
3631 LtdcHandle.Init.TotalHeigh = 480 + 3 + 29 - 1 + 13;
3632
3633 /* Configure R,G,B component values for LCD background color */
3634 LtdcHandle.Init.Backcolor.Red= 0;
3635 LtdcHandle.Init.Backcolor.Blue= 0;
3636 LtdcHandle.Init.Backcolor.Green= 0;
3637
3638 /* LCD clock configuration */
3639 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
3640 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
3641 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
3642 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
3643
3644 /* done in main.c SystemClockConfig
3645
3646 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
3647 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
3648 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
3649 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
3650 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
3651 */
3652 /* Polarity */
3653 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
3654 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL;
3655 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
3656 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;//LTDC_PCPOLARITY_IPC;
3657
3658 LtdcHandle.Instance = LTDC;
3659
3660 /* Configure the LTDC */
3661 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // auch init der GPIO Pins
3662 {
3663 /* Initialization Error */
3664 GFX_Error_Handler();
3665 }
3666 }
3667
3668
3669 void GFX_VGA_LTDC_Init_org(void)
3670 {
3671
3672 LtdcHandle.Init.HorizontalSync = 96;
3673 /* Vertical synchronization height = Vsync - 1 */
3674 LtdcHandle.Init.VerticalSync = 2;
3675 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
3676 LtdcHandle.Init.AccumulatedHBP = 96 + 48;
3677 /* Accumulated vertical back porch = Vsync + VBP - 1 */
3678 LtdcHandle.Init.AccumulatedVBP = 2 + 35;
3679 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
3680 LtdcHandle.Init.AccumulatedActiveW = 96 + 48 + 800;//499;//500;//499;
3681 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
3682 LtdcHandle.Init.AccumulatedActiveH = 2 + 35 + 480;
3683 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
3684 LtdcHandle.Init.TotalWidth = 96 + 48 + 800 + 12;//508;//507;
3685 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
3686 LtdcHandle.Init.TotalHeigh = 2 + 35 + 480 + 12;
3687
3688 /* Configure R,G,B component values for LCD background color */
3689 LtdcHandle.Init.Backcolor.Red= 0;
3690 LtdcHandle.Init.Backcolor.Blue= 0;
3691 LtdcHandle.Init.Backcolor.Green= 0;
3692
3693 /* LCD clock configuration */
3694 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
3695 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
3696 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
3697 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
3698
3699 /* done in main.c SystemClockConfig
3700
3701 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
3702 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
3703 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
3704 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
3705 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
3706 */
3707 /* Polarity */
3708 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
3709 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AH;
3710 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
3711 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;//LTDC_PCPOLARITY_IPC;
3712
3713 LtdcHandle.Instance = LTDC;
3714
3715 /* Configure the LTDC */
3716 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // auch init der GPIO Pins
3717 {
3718 /* Initialization Error */
3719 GFX_Error_Handler();
3720 }
3721 }
3722
3723 void GFX_VGA_LTDC_Init(void)
3724 //void GFX_VGA_LTDC_Init_640x480(void)
3725 {
3726
3727 LtdcHandle.Init.HorizontalSync = 96;
3728 /* Vertical synchronization height = Vsync - 1 */
3729 LtdcHandle.Init.VerticalSync = 2;
3730 /* Accumulated horizontal back porch = Hsync + HBP - 1 */
3731 LtdcHandle.Init.AccumulatedHBP = 96 + 48;
3732 /* Accumulated vertical back porch = Vsync + VBP - 1 */
3733 LtdcHandle.Init.AccumulatedVBP = 2 + 35;
3734 /* Accumulated active width = Hsync + HBP + Active Width - 1 */
3735 LtdcHandle.Init.AccumulatedActiveW = 96 + 48 + 640;//499;//500;//499;
3736 /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */
3737 LtdcHandle.Init.AccumulatedActiveH = 2 + 35 + 480;
3738 /* Total width = Hsync + HBP + Active Width + HFP - 1 */
3739 LtdcHandle.Init.TotalWidth = 96 + 48 + 640 + 12;//508;//507;
3740 /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */
3741 LtdcHandle.Init.TotalHeigh = 2 + 35 + 480 + 12;
3742
3743 /* Configure R,G,B component values for LCD background color */
3744 LtdcHandle.Init.Backcolor.Red= 0;
3745 LtdcHandle.Init.Backcolor.Blue= 0;
3746 LtdcHandle.Init.Backcolor.Green= 0;
3747
3748 /* LCD clock configuration */
3749 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
3750 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
3751 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */
3752 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */
3753
3754 /* done in main.c SystemClockConfig
3755
3756 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
3757 PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
3758 PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
3759 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
3760 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
3761 */
3762 /* Polarity */
3763 LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL;
3764 LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AH;
3765 LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL;
3766 LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC;//LTDC_PCPOLARITY_IPC;
3767
3768 LtdcHandle.Instance = LTDC;
3769
3770 /* Configure the LTDC */
3771 if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK) // auch init der GPIO Pins
3772 {
3773 /* Initialization Error */
3774 GFX_Error_Handler();
3775 }
3776 }
3777
3778
3779 void GFX_LTDC_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address) 3314 void GFX_LTDC_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
3780 { 3315 {
3781 LTDC_LayerCfgTypeDef Layercfg; 3316 LTDC_LayerCfgTypeDef Layercfg;
3782 3317
3783 /* Layer Init */ 3318 /* Layer Init */
3800 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex); 3335 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex);
3801 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex); 3336 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex);
3802 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex); 3337 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex);
3803 } 3338 }
3804 3339
3805 void GFX_VGA_LTDC_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address) 3340 static uint32_t GFX_doubleBufferOne(void)
3806 {
3807 LTDC_LayerCfgTypeDef Layercfg;
3808
3809 /* Layer Init */
3810 Layercfg.WindowX0 = 0;
3811 Layercfg.WindowX1 = 640;
3812 Layercfg.WindowY0 = 0;
3813 Layercfg.WindowY1 = 480;
3814 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_AL88;//LTDC_PIXEL_FORMAT_ARGB8888;
3815 Layercfg.FBStartAdress = FB_Address;
3816 Layercfg.Alpha = 255;
3817 Layercfg.Alpha0 = 0;
3818 Layercfg.Backcolor.Blue = 0;
3819 Layercfg.Backcolor.Green = 0;
3820 Layercfg.Backcolor.Red = 0;
3821 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
3822 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
3823 Layercfg.ImageWidth = 640;
3824 Layercfg.ImageHeight = 480;
3825
3826 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex);
3827 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex);
3828 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex);
3829 }
3830
3831 void GFX_LTDC_LayerTESTInit(uint16_t LayerIndex, uint32_t FB_Address)
3832 {
3833 LTDC_LayerCfgTypeDef Layercfg;
3834
3835 /* Layer Init */
3836 Layercfg.WindowX0 = 0;
3837 Layercfg.WindowX1 = 390;
3838 Layercfg.WindowY0 = 0;
3839 Layercfg.WindowY1 = 800;
3840 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_AL88;//LTDC_PIXEL_FORMAT_ARGB8888;
3841 Layercfg.FBStartAdress = FB_Address;
3842 Layercfg.Alpha = 255;
3843 Layercfg.Alpha0 = 255;
3844 Layercfg.Backcolor.Blue = 0;
3845 Layercfg.Backcolor.Green = 0;
3846 Layercfg.Backcolor.Red = 200;
3847 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
3848 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
3849 Layercfg.ImageWidth = 480;
3850 Layercfg.ImageHeight = 800;
3851
3852 HAL_LTDC_ConfigCLUT(&LtdcHandle, ColorLUT, CLUT_END, LayerIndex);
3853 HAL_LTDC_ConfigLayer(&LtdcHandle, &Layercfg, LayerIndex);
3854 HAL_LTDC_EnableCLUT(&LtdcHandle, LayerIndex);
3855 }
3856
3857
3858 uint32_t GFX_doubleBufferOne(void)
3859 { 3341 {
3860 return SDRAM_DOUBLE_BUFFER_ONE; 3342 return SDRAM_DOUBLE_BUFFER_ONE;
3861 } 3343 }
3862 3344
3863 3345
3864 uint32_t GFX_doubleBufferTwo(void) 3346 static uint32_t GFX_doubleBufferTwo(void)
3865 { 3347 {
3866 return SDRAM_DOUBLE_BUFFER_TWO; 3348 return SDRAM_DOUBLE_BUFFER_TWO;
3867 }
3868
3869 /*
3870 void doubleBufferClear(uint32_t pDestination)
3871 {
3872 for(uint32_t i = 2*200*480; i > 0; i--)
3873 {
3874 *(__IO uint16_t*)pDestination = 0;
3875 pDestination += 2;
3876 *(__IO uint16_t*)pDestination = 0;
3877 pDestination += 2;
3878 *(__IO uint16_t*)pDestination = 0;
3879 pDestination += 2;
3880 *(__IO uint16_t*)pDestination = 0;
3881 pDestination += 2;
3882 }
3883 }
3884
3885
3886 void GFX_doubleBufferClearOne(void)
3887 {
3888 doubleBufferClear(SDRAM_DOUBLE_BUFFER_ONE);
3889 }
3890
3891
3892 void GFX_doubleBufferClearTwo(void)
3893 {
3894 doubleBufferClear(SDRAM_DOUBLE_BUFFER_TWO);
3895 }
3896 */
3897
3898 uint32_t getFrameByNumber(uint8_t ZeroToMaxFrames)
3899 {
3900 if(ZeroToMaxFrames >= MAXFRAMES)
3901 return 0;
3902 else
3903 return frame[ZeroToMaxFrames].StartAddress;
3904 } 3349 }
3905 3350
3906 uint32_t getFrame(uint8_t callerId) 3351 uint32_t getFrame(uint8_t callerId)
3907 { 3352 {
3908 uint8_t i; 3353 uint8_t i;
3983 for(int i = 0;i<MAXFRAMES;i++) 3428 for(int i = 0;i<MAXFRAMES;i++)
3984 if(frame[i].status == BLOCKED) 3429 if(frame[i].status == BLOCKED)
3985 count--; 3430 count--;
3986 3431
3987 return count; 3432 return count;
3988 }
3989
3990
3991 uint8_t getFrameCount(uint8_t frameId)
3992 {
3993 if(frameId < (MAXFRAMECOUNTER - 3))
3994 return frameCounter[frameId];
3995 else
3996 return frameCounter[MAXFRAMECOUNTER - 2];
3997 } 3433 }
3998 3434
3999 3435
4000 void housekeepingFrame(void) 3436 void housekeepingFrame(void)
4001 { 3437 {