comparison Discovery/Src/gfx_engine.c @ 870:bc6c90e20d9e Evo_2_23

Instrument code for Bootloader: the Bootloader was reactivated. Because some functions have changed in the past years an instrumentation had to be done to avoid compile issues (e.g. no multilanguage in Bootloader, no special fonts)
author Ideenmodellierer
date Mon, 12 Aug 2024 22:25:46 +0200
parents b7e43b28bee1
children e373e90a48db
comparison
equal deleted inserted replaced
869:4e10a3e087a1 870:bc6c90e20d9e
34 34
35 /* Exported variables --------------------------------------------------------*/ 35 /* Exported variables --------------------------------------------------------*/
36 36
37 /* Private types -------------------------------------------------------------*/ 37 /* Private types -------------------------------------------------------------*/
38 38
39 #define RING_BUF_SIZE (5u) 39 #define RING_BUF_SIZE (5u)
40 #define MAX_COLOR_STRING_LENGTH (100u)
40 41
41 typedef struct 42 typedef struct
42 { 43 {
43 uint32_t Xdelta; 44 uint32_t Xdelta;
44 uint32_t Ydelta; 45 uint32_t Ydelta;
246 void GFX_hwBackgroundOff(void) 247 void GFX_hwBackgroundOff(void)
247 { 248 {
248 backgroundHwStatus = LOGOSTOP; 249 backgroundHwStatus = LOGOSTOP;
249 } 250 }
250 251
251
252 void GFX_build_hw_background_frame(void) 252 void GFX_build_hw_background_frame(void)
253 { 253 {
254 GFX_DrawCfgScreen tLogoTemp; 254 GFX_DrawCfgScreen tLogoTemp;
255 SWindowGimpStyle windowGimp; 255 SWindowGimpStyle windowGimp;
256 256
314 314
315 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020); 315 write_content_simple(&tLogoTemp, 0, 800, 240-24, &FontT24,localtext,CLUT_Font020);
316 */ 316 */
317 } 317 }
318 318
319
320 void GFX_init(uint32_t * pDestinationOut) 319 void GFX_init(uint32_t * pDestinationOut)
321 { 320 {
322 frame[0].StartAddress = FBGlobalStart; 321 frame[0].StartAddress = FBGlobalStart;
323 GFX_clear_frame_immediately(frame[0].StartAddress); 322 GFX_clear_frame_immediately(frame[0].StartAddress);
324 frame[0].status = CLEAR; 323 frame[0].status = CLEAR;
336 *pDestinationOut = pInvisibleFrame; 335 *pDestinationOut = pInvisibleFrame;
337 336
338 GFX_build_logo_frame(); 337 GFX_build_logo_frame();
339 GFX_build_hw_background_frame(); 338 GFX_build_hw_background_frame();
340 339
340 /* Register to memory mode with ARGB8888 as color Mode */
341 Dma2dHandle.Init.Mode = DMA2D_R2M;
342 Dma2dHandle.Init.ColorMode = DMA2D_ARGB4444;//to fake AL88, before: DMA2D_ARGB8888;
343 Dma2dHandle.Init.OutputOffset = 0;
344
345 /* DMA2D Callbacks Configuration */
346 Dma2dHandle.XferCpltCallback = GFX_Dma2d_TransferComplete;
347 Dma2dHandle.XferErrorCallback = GFX_Dma2d_TransferError;
348
349 Dma2dHandle.Instance = DMA2D;
350
351 /* DMA2D Initialisation */
352 if(HAL_DMA2D_Init(&Dma2dHandle) != HAL_OK)
353 GFX_Error_Handler();
354
355 if(HAL_DMA2D_ConfigLayer(&Dma2dHandle, 1) != HAL_OK)
356 GFX_Error_Handler();
357
358 DMA2D_at_work = 255;
359 }
360 void GFX_init1_no_DMA(uint32_t * pDestinationOut, uint8_t blockFrames)
361 {
362 frame[0].StartAddress = FBGlobalStart;
363 GFX_clear_frame_immediately(frame[0].StartAddress);
364 frame[0].status = CLEAR;
365 frame[0].caller = 0;
366
367 for(int i=1;i<MAXFRAMES;i++)
368 {
369 frame[i].StartAddress = frame[i-1].StartAddress + FBOffsetEachIndex;
370 GFX_clear_frame_immediately(frame[i].StartAddress);
371 frame[i].status = CLEAR;
372 frame[i].caller = 0;
373 }
374
375 for(int i=0;i<blockFrames;i++)
376 {
377 frame[i].status = BLOCKED;
378 frame[i].caller = 1;
379 }
380
381 pInvisibleFrame = getFrame(2);
382 *pDestinationOut = pInvisibleFrame;
383
384 GFX_build_logo_frame();
385 GFX_build_hw_background_frame();
386 }
387
388
389 void GFX_init2_DMA(void)
390 {
341 /* Register to memory mode with ARGB8888 as color Mode */ 391 /* Register to memory mode with ARGB8888 as color Mode */
342 Dma2dHandle.Init.Mode = DMA2D_R2M; 392 Dma2dHandle.Init.Mode = DMA2D_R2M;
343 Dma2dHandle.Init.ColorMode = DMA2D_ARGB4444;//to fake AL88, before: DMA2D_ARGB8888; 393 Dma2dHandle.Init.ColorMode = DMA2D_ARGB4444;//to fake AL88, before: DMA2D_ARGB8888;
344 Dma2dHandle.Init.OutputOffset = 0; 394 Dma2dHandle.Init.OutputOffset = 0;
345 395
528 } 578 }
529 return; 579 return;
530 } 580 }
531 else if (backgroundHwStatus != LOGOOFF) 581 else if (backgroundHwStatus != LOGOOFF)
532 { 582 {
583
533 switch(backgroundHwStatus) 584 switch(backgroundHwStatus)
534 { 585 {
535 case LOGOSTART: 586 case LOGOSTART:
536 HAL_LTDC_ConfigCLUT(&LtdcHandle, (uint32_t *)indexHWcolor, indexHWcolorSIZE, 0); 587 HAL_LTDC_ConfigCLUT(&LtdcHandle, (uint32_t *)indexHWcolor, indexHWcolorSIZE, 0);
537 HAL_LTDC_SetAddress(&LtdcHandle, pBackgroundHwFrame, 0); 588 HAL_LTDC_SetAddress(&LtdcHandle, pBackgroundHwFrame, 0);
562 613
563 default: 614 default:
564 FrameHandler.NextBottomRead = nextBottomBackup; 615 FrameHandler.NextBottomRead = nextBottomBackup;
565 break; 616 break;
566 } 617 }
618
567 return; 619 return;
568 } 620 }
569 else 621 else
570 { 622 {
571 pBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].pBuffer; 623 pBot = FrameHandler.nextBottom[FrameHandler.NextBottomRead].pBuffer;
971 } 1023 }
972 } 1024 }
973 } 1025 }
974 } 1026 }
975 1027
976
977 static void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image) 1028 static void GFX_draw_image_color(GFX_DrawCfgScreen *hgfx, SWindowGimpStyle window, const tImage *image)
978 { 1029 {
979 uint16_t* pDestination; 1030 uint16_t* pDestination;
980 1031
981 uint32_t j; 1032 uint32_t j;
2098 { 2149 {
2099 settings.dualFont = 0; 2150 settings.dualFont = 0;
2100 settings.actualFont = (tFont *)settings.font; 2151 settings.actualFont = (tFont *)settings.font;
2101 } 2152 }
2102 else 2153 else
2154 #ifndef BOOTLOADER_STANDALONE
2103 if((*pText == '\005') && !minimal) 2155 if((*pText == '\005') && !minimal)
2104 { 2156 {
2105 newXdelta = GFX_write_char(hgfx, &settings, 'a', (tFont *)&Awe48); 2157 newXdelta = GFX_write_char(hgfx, &settings, 'a', (tFont *)&Awe48);
2106 settings.Xdelta = newXdelta; 2158 settings.Xdelta = newXdelta;
2107 } 2159 }
2110 { 2162 {
2111 newXdelta = GFX_write_char(hgfx, &settings, 'b', (tFont *)&Awe48); 2163 newXdelta = GFX_write_char(hgfx, &settings, 'b', (tFont *)&Awe48);
2112 settings.Xdelta = newXdelta; 2164 settings.Xdelta = newXdelta;
2113 } 2165 }
2114 else 2166 else
2167 #endif
2115 if((*pText >= '\020') && (*pText <= '\032') && !minimal) 2168 if((*pText >= '\020') && (*pText <= '\032') && !minimal)
2116 settings.color = *pText - '\020'; 2169 settings.color = *pText - '\020';
2117 else 2170 else
2118 if((*pText == '\034') && !minimal) 2171 if((*pText == '\034') && !minimal)
2119 settings.spaceMode = 1; 2172 settings.spaceMode = 1;
2186 { 2239 {
2187 uint8_t i, j; 2240 uint8_t i, j;
2188 uint32_t found; 2241 uint32_t found;
2189 uint32_t pText; 2242 uint32_t pText;
2190 uint16_t decodeUTF8; 2243 uint16_t decodeUTF8;
2191 uint8_t gfx_selected_language;
2192 #ifndef BOOTLOADER_STANDALONE 2244 #ifndef BOOTLOADER_STANDALONE
2245 uint8_t gfx_selected_language = 0;
2193 SSettings *pSettings; 2246 SSettings *pSettings;
2194 pSettings = settingsGetPointer(); 2247 pSettings = settingsGetPointer();
2195 gfx_selected_language = pSettings->selected_language; 2248 gfx_selected_language = pSettings->selected_language;
2196 if(gfx_selected_language >= LANGUAGE_END) 2249 if(gfx_selected_language >= LANGUAGE_END) gfx_selected_language = 0;
2197 #endif 2250 #endif
2198 gfx_selected_language = 0;
2199
2200 2251
2201 // ----------------------------- 2252 // -----------------------------
2202 if(textId != (uint8_t)TXT_2BYTE) 2253 if(textId != (uint8_t)TXT_2BYTE)
2203 { 2254 {
2204 found = 0; 2255 found = 0;
2205 j = 0; 2256 j = 0;
2206 for(i=(uint8_t)TXT_Language;i<(uint8_t)TXT_END;i++) 2257 for(i=(uint8_t)TXT_Language;i<(uint8_t)TXT_END;i++)
2207 { 2258 {
2259 #ifndef BOOTLOADER_STANDALONE
2208 if(text_array[j].code == textId) 2260 if(text_array[j].code == textId)
2209 { 2261 {
2210 found = 1; 2262 found = 1;
2211 break; 2263 break;
2212 } 2264 }
2265 #endif
2213 j++; 2266 j++;
2214 } 2267 }
2215 if(!found) 2268 if(!found)
2216 return cfg->Xdelta; 2269 return cfg->Xdelta;
2217 2270
2218 // ----------------------------- 2271 // -----------------------------
2272 #ifndef BOOTLOADER_STANDALONE
2219 pText = (uint32_t)text_array[j].text[gfx_selected_language]; 2273 pText = (uint32_t)text_array[j].text[gfx_selected_language];
2220 if(!pText) 2274 if(!pText)
2221 pText = (uint32_t)text_array[j].text[0]; 2275 pText = (uint32_t)text_array[j].text[0];
2222 else 2276 else
2223 if(*(char*)pText == 0) 2277 if(*(char*)pText == 0)
2224 pText = (uint32_t)text_array[j].text[0]; 2278 pText = (uint32_t)text_array[j].text[0];
2279 #endif
2225 } 2280 }
2226 // ----------------------------- 2281 // -----------------------------
2227 else 2282 else
2228 { 2283 {
2229 if(!nextCharFor2Byte) 2284 if(!nextCharFor2Byte)
2230 return cfg->Xdelta; 2285 return cfg->Xdelta;
2231 2286
2232 found = 0; 2287 found = 0;
2233 for(j=0;j<(uint8_t)TXT2BYTE_END-(uint8_t)TXT2BYTE_START;j++) 2288 for(j=0;j<(uint8_t)TXT2BYTE_END-(uint8_t)TXT2BYTE_START;j++)
2234 { 2289 {
2290 #ifndef BOOTLOADER_STANDALONE
2235 if((uint8_t)text_array2[j].code == (uint8_t)nextCharFor2Byte) 2291 if((uint8_t)text_array2[j].code == (uint8_t)nextCharFor2Byte)
2236 { 2292 {
2237 found = 1; 2293 found = 1;
2238 break; 2294 break;
2239 } 2295 }
2296 #endif
2240 } 2297 }
2241 if(!found) 2298 if(!found)
2242 return cfg->Xdelta; 2299 return cfg->Xdelta;
2300 #ifndef BOOTLOADER_STANDALONE
2243 // ----------------------------- 2301 // -----------------------------
2244 pText = (uint32_t)text_array2[j].text[gfx_selected_language]; 2302 pText = (uint32_t)text_array2[j].text[gfx_selected_language];
2245 if(!pText) 2303 if(!pText)
2246 pText = (uint32_t)text_array2[j].text[0]; 2304 pText = (uint32_t)text_array2[j].text[0];
2247 else 2305 else
2248 if(*(char*)pText == 0) 2306 if(*(char*)pText == 0)
2249 pText = (uint32_t)text_array2[j].text[0]; 2307 pText = (uint32_t)text_array2[j].text[0];
2308 #endif
2250 } 2309 }
2251 // ----------------------------- 2310 // -----------------------------
2252 2311
2253 if(cfg->actualFont == (tFont *)cfg->TinyFont) 2312 if(cfg->actualFont == (tFont *)cfg->TinyFont)
2254 cfg->Ydelta += cfg->TinyFontExtraYdelta; 2313 cfg->Ydelta += cfg->TinyFontExtraYdelta;
2683 * @retval Ydelta: 0x0000FFFF if not successful or char_truncated 2742 * @retval Ydelta: 0x0000FFFF if not successful or char_truncated
2684 */ 2743 */
2685 2744
2686 static uint32_t GFX_write_char(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font) 2745 static uint32_t GFX_write_char(GFX_DrawCfgWindow* hgfx, GFX_CfgWriteString* cfg, uint8_t character, tFont *Font)
2687 { 2746 {
2747
2748 #ifndef BOOTLOADER_STANDALONE
2688 Font = GFX_Check_Extra_Font(character, Font); 2749 Font = GFX_Check_Extra_Font(character, Font);
2750 #endif
2689 if(cfg->doubleSize) 2751 if(cfg->doubleSize)
2690 { 2752 {
2691 return GFX_write_char_doubleSize(hgfx, cfg, character, Font); 2753 return GFX_write_char_doubleSize(hgfx, cfg, character, Font);
2692 } 2754 }
2693 2755
3004 return 0x0000FFFF; 3066 return 0x0000FFFF;
3005 else 3067 else
3006 return cfg->Xdelta + width; 3068 return cfg->Xdelta + width;
3007 } 3069 }
3008 3070
3071 #ifndef BOOTLOADER_STANDALONE
3009 3072
3010 /** 3073 /**
3011 ****************************************************************************** 3074 ******************************************************************************
3012 * @brief GFX write Modify helper for center and right align. 3075 * @brief GFX write Modify helper for center and right align.
3013 * @author heinrichs weikamp gmbh 3076 * @author heinrichs weikamp gmbh
3103 } 3166 }
3104 cText[counter] = 0; 3167 cText[counter] = 0;
3105 return counter; 3168 return counter;
3106 } 3169 }
3107 3170
3108 3171 #endif
3109 /** 3172 /**
3110 ****************************************************************************** 3173 ******************************************************************************
3111 * @brief GFX write Modify Ydelta for align. / calc Ydelta for start 3174 * @brief GFX write Modify Ydelta for align. / calc Ydelta for start
3112 * @author heinrichs weikamp gmbh 3175 * @author heinrichs weikamp gmbh
3113 * @version V0.0.1 3176 * @version V0.0.1
3124 { 3187 {
3125 char cText[101]; 3188 char cText[101];
3126 uint32_t result; 3189 uint32_t result;
3127 uint32_t Xsum; 3190 uint32_t Xsum;
3128 uint32_t j; 3191 uint32_t j;
3129 uint8_t gfx_selected_language;
3130 uint32_t pText; 3192 uint32_t pText;
3131 uint16_t decodeUTF8; 3193 uint16_t decodeUTF8;
3132 uint8_t tinyState = 0; /* used to identify the usage of tiny font */ 3194 uint8_t tinyState = 0; /* used to identify the usage of tiny font */
3133 tFont* ptargetFont; 3195 tFont* ptargetFont;
3134 3196
3135 #ifndef BOOTLOADER_STANDALONE 3197 #ifndef BOOTLOADER_STANDALONE
3198 uint8_t gfx_selected_language = 0;
3136 SSettings *pSettings; 3199 SSettings *pSettings;
3137 pSettings = settingsGetPointer(); 3200 pSettings = settingsGetPointer();
3138 gfx_selected_language = pSettings->selected_language; 3201 gfx_selected_language = pSettings->selected_language;
3139 if(gfx_selected_language >= LANGUAGE_END) 3202 if(gfx_selected_language >= LANGUAGE_END)
3140 #endif 3203 #endif
3141 gfx_selected_language = 0;
3142 // ----------------------------- 3204 // -----------------------------
3143 3205 #ifndef BOOTLOADER_STANDALONE
3144 GFX_write__Modify_helper(cText,pTextInput,gfx_selected_language); 3206 GFX_write__Modify_helper(cText,pTextInput,gfx_selected_language);
3145 3207 #endif
3146 pText = (uint32_t)&cText[0]; 3208 pText = (uint32_t)&cText[0];
3147 Xsum = 0; 3209 Xsum = 0;
3148 j = 0; 3210 j = 0;
3149 ptargetFont = (tFont *)cfg->font; 3211 ptargetFont = (tFont *)cfg->font;
3150 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size 3212 while (*(char*)pText != 0)// und fehlend: Abfrage window / image size
3217 } 3279 }
3218 3280
3219 3281
3220 static uint32_t GFX_write__Modify_Xdelta__RightAlign(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput) 3282 static uint32_t GFX_write__Modify_Xdelta__RightAlign(GFX_CfgWriteString* cfg, GFX_DrawCfgWindow* hgfx, const char *pTextInput)
3221 { 3283 {
3222 char cText[101];
3223 uint32_t result; 3284 uint32_t result;
3224 uint32_t Xsum; 3285 uint32_t Xsum;
3225 uint32_t j; 3286 uint32_t j;
3226 tFont *font; 3287 tFont *font;
3227 uint8_t gfx_selected_language; 3288 char cText[101];
3228 uint32_t pText; 3289 uint32_t pText;
3229 uint16_t decodeUTF8; 3290 uint16_t decodeUTF8;
3230 uint8_t tinyState = 0; /* used to identify the usage of tiny font */ 3291 uint8_t tinyState = 0; /* used to identify the usage of tiny font */
3231 3292
3232 #ifndef BOOTLOADER_STANDALONE 3293 #ifndef BOOTLOADER_STANDALONE
3294 uint8_t gfx_selected_language = 0;
3233 SSettings *pSettings; 3295 SSettings *pSettings;
3234 pSettings = settingsGetPointer(); 3296 pSettings = settingsGetPointer();
3235 gfx_selected_language = pSettings->selected_language; 3297 gfx_selected_language = pSettings->selected_language;
3236 if(gfx_selected_language >= LANGUAGE_END) 3298 if(gfx_selected_language >= LANGUAGE_END)
3299 #else
3300 cText[0] = 0;
3237 #endif 3301 #endif
3238 gfx_selected_language = 0;
3239 // ----------------------------- 3302 // -----------------------------
3240 3303 #ifndef BOOTLOADER_STANDALONE
3241 GFX_write__Modify_helper(cText,pTextInput,gfx_selected_language); 3304 GFX_write__Modify_helper(cText,pTextInput,gfx_selected_language);
3305 #endif
3242 pText = (uint32_t)&cText[0]; 3306 pText = (uint32_t)&cText[0];
3243
3244 // ----------------------------- 3307 // -----------------------------
3245 3308
3246 font = (tFont *)cfg->font; 3309 font = (tFont *)cfg->font;
3247 Xsum = 0; 3310 Xsum = 0;
3248 j = 0; 3311 j = 0;
3916 } 3979 }
3917 } 3980 }
3918 */ 3981 */
3919 } 3982 }
3920 3983
3984 #ifndef BOOTLOADER_STANDALONE
3921 tFont* GFX_Check_Extra_Font(uint8_t character, tFont *Font) 3985 tFont* GFX_Check_Extra_Font(uint8_t character, tFont *Font)
3922 { 3986 {
3923 uint32_t i; 3987 uint32_t i;
3924 uint32_t found; 3988 uint32_t found;
3925 3989
3945 Font = (tFont *)&FontT105Extra; 4009 Font = (tFont *)&FontT105Extra;
3946 } 4010 }
3947 4011
3948 return Font; 4012 return Font;
3949 } 4013 }
3950 4014 #endif
3951 uint32_t GFX_Character_Width(uint8_t character, tFont *Font) 4015 uint32_t GFX_Character_Width(uint8_t character, tFont *Font)
3952 { 4016 {
3953 uint32_t i; 4017 uint32_t i;
4018 #ifndef BOOTLOADER_STANDALONE
3954 uint32_t found; 4019 uint32_t found;
4020 #endif
3955 4021
3956 for(i=0;i<Font->length;i++) 4022 for(i=0;i<Font->length;i++)
3957 { 4023 {
3958 if(Font->chars[i].code == character) 4024 if(Font->chars[i].code == character)
3959 { 4025 {
3960 return Font->chars[i].image->width; 4026 return Font->chars[i].image->width;
3961 } 4027 }
3962 } 4028 }
3963 4029
4030 #ifndef BOOTLOADER_STANDALONE
3964 found = 0; 4031 found = 0;
3965 if (Font == &FontT54) 4032 if (Font == &FontT54)
3966 { 4033 {
3967 found = 1; 4034 found = 1;
3968 Font = (tFont *)&FontT54Extra; 4035 Font = (tFont *)&FontT54Extra;
3986 { 4053 {
3987 return Font->chars[i].image->width; 4054 return Font->chars[i].image->width;
3988 } 4055 }
3989 } 4056 }
3990 } 4057 }
3991 4058 #endif
3992 return 0; 4059 return 0;
3993 } 4060 }
4061
4062 void Gfx_colorsscheme_mod(char *text, uint8_t alternativeColor)
4063 {
4064 char *p = text;
4065 uint8_t index = 0;
4066
4067 while ((*p) && (index < MAX_COLOR_STRING_LENGTH))
4068 {
4069 if (*p == '\020')
4070 {
4071 if(!GFX_is_colorschemeDiveStandard())
4072 {
4073 *p = '\027';
4074 }
4075 else if(alternativeColor != 0)
4076 {
4077 *p += alternativeColor;
4078 }
4079 }
4080 p++;
4081 index++;
4082 }
4083 }
4084