STM32746G-Discovery board drivers V1.0.0
Dependents: F746_SD_GraphicEqualizer_ren0620
Fork of BSP_DISCO_F746NG by
stm32746g_discovery_lcd.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32746g_discovery_lcd.c 00004 * @author MCD Application Team 00005 * @version V1.0.0 00006 * @date 25-June-2015 00007 * @brief This file includes the driver for Liquid Crystal Display (LCD) module 00008 * mounted on STM32746G-Discovery board. 00009 @verbatim 00010 1. How To use this driver: 00011 -------------------------- 00012 - This driver is used to drive directly an LCD TFT using the LTDC controller. 00013 - This driver uses timing and setting for RK043FN48H LCD. 00014 00015 2. Driver description: 00016 --------------------- 00017 + Initialization steps: 00018 o Initialize the LCD using the BSP_LCD_Init() function. 00019 o Apply the Layer configuration using the BSP_LCD_LayerDefaultInit() function. 00020 o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function. 00021 o Enable the LCD display using the BSP_LCD_DisplayOn() function. 00022 00023 + Options 00024 o Configure and enable the color keying functionality using the 00025 BSP_LCD_SetColorKeying() function. 00026 o Modify in the fly the transparency and/or the frame buffer address 00027 using the following functions: 00028 - BSP_LCD_SetTransparency() 00029 - BSP_LCD_SetLayerAddress() 00030 00031 + Display on LCD 00032 o Clear the hole LCD using BSP_LCD_Clear() function or only one specified string 00033 line using the BSP_LCD_ClearStringLine() function. 00034 o Display a character on the specified line and column using the BSP_LCD_DisplayChar() 00035 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function. 00036 o Display a string line on the specified position (x,y in pixel) and align mode 00037 using the BSP_LCD_DisplayStringAtLine() function. 00038 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap) 00039 on LCD using the available set of functions. 00040 @endverbatim 00041 ****************************************************************************** 00042 * @attention 00043 * 00044 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00045 * 00046 * Redistribution and use in source and binary forms, with or without modification, 00047 * are permitted provided that the following conditions are met: 00048 * 1. Redistributions of source code must retain the above copyright notice, 00049 * this list of conditions and the following disclaimer. 00050 * 2. Redistributions in binary form must reproduce the above copyright notice, 00051 * this list of conditions and the following disclaimer in the documentation 00052 * and/or other materials provided with the distribution. 00053 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00054 * may be used to endorse or promote products derived from this software 00055 * without specific prior written permission. 00056 * 00057 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00058 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00059 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00060 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00061 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00062 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00063 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00064 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00065 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00066 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00067 * 00068 ****************************************************************************** 00069 */ 00070 00071 /* Includes ------------------------------------------------------------------*/ 00072 #include "stm32746g_discovery_lcd.h" 00073 #include "fonts.h" 00074 /* 00075 #include "font24.c" 00076 #include "font20.c" 00077 #include "font16.c" 00078 #include "font12.c" 00079 #include "font8.c" 00080 */ 00081 00082 /** @addtogroup BSP 00083 * @{ 00084 */ 00085 00086 /** @addtogroup STM32746G_DISCOVERY 00087 * @{ 00088 */ 00089 00090 /** @addtogroup STM32746G_DISCOVERY_LCD 00091 * @{ 00092 */ 00093 00094 /** @defgroup STM32746G_DISCOVERY_LCD_Private_TypesDefinitions STM32746G_DISCOVERY_LCD Private Types Definitions 00095 * @{ 00096 */ 00097 /** 00098 * @} 00099 */ 00100 00101 /** @defgroup STM32746G_DISCOVERY_LCD_Private_Defines STM32746G_DISCOVERY LCD Private Defines 00102 * @{ 00103 */ 00104 #define POLY_X(Z) ((int32_t)((Points + Z)->X)) 00105 #define POLY_Y(Z) ((int32_t)((Points + Z)->Y)) 00106 /** 00107 * @} 00108 */ 00109 00110 /** @defgroup STM32746G_DISCOVERY_LCD_Private_Macros STM32746G_DISCOVERY_LCD Private Macros 00111 * @{ 00112 */ 00113 #define ABS(X) ((X) > 0 ? (X) : -(X)) 00114 /** 00115 * @} 00116 */ 00117 00118 /** @defgroup STM32746G_DISCOVERY_LCD_Private_Variables STM32746G_DISCOVERY_LCD Private Variables 00119 * @{ 00120 */ 00121 static LTDC_HandleTypeDef hLtdcHandler; 00122 static DMA2D_HandleTypeDef hDma2dHandler; 00123 00124 /* Default LCD configuration with LCD Layer 1 */ 00125 static uint32_t ActiveLayer = 0; 00126 static LCD_DrawPropTypeDef DrawProp[MAX_LAYER_NUMBER]; 00127 /** 00128 * @} 00129 */ 00130 00131 /** @defgroup STM32746G_DISCOVERY_LCD_Private_FunctionPrototypes STM32746G_DISCOVERY_LCD Private Function Prototypes 00132 * @{ 00133 */ 00134 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c); 00135 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3); 00136 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex); 00137 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode); 00138 /** 00139 * @} 00140 */ 00141 00142 /** @defgroup STM32746G_DISCOVERY_LCD_Exported_Functions STM32746G_DISCOVERY_LCD Exported Functions 00143 * @{ 00144 */ 00145 00146 /** 00147 * @brief Initializes the LCD. 00148 * @retval LCD state 00149 */ 00150 uint8_t BSP_LCD_Init(void) 00151 { 00152 /* Select the used LCD */ 00153 00154 /* The RK043FN48H LCD 480x272 is selected */ 00155 /* Timing Configuration */ 00156 hLtdcHandler.Init.HorizontalSync = (RK043FN48H_HSYNC - 1); 00157 hLtdcHandler.Init.VerticalSync = (RK043FN48H_VSYNC - 1); 00158 hLtdcHandler.Init.AccumulatedHBP = (RK043FN48H_HSYNC + RK043FN48H_HBP - 1); 00159 hLtdcHandler.Init.AccumulatedVBP = (RK043FN48H_VSYNC + RK043FN48H_VBP - 1); 00160 hLtdcHandler.Init.AccumulatedActiveH = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP - 1); 00161 hLtdcHandler.Init.AccumulatedActiveW = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP - 1); 00162 hLtdcHandler.Init.TotalHeigh = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP + RK043FN48H_VFP - 1); 00163 hLtdcHandler.Init.TotalWidth = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP + RK043FN48H_HFP - 1); 00164 00165 /* LCD clock configuration */ 00166 BSP_LCD_ClockConfig(&hLtdcHandler, NULL); 00167 00168 /* Initialize the LCD pixel width and pixel height */ 00169 hLtdcHandler.LayerCfg->ImageWidth = RK043FN48H_WIDTH; 00170 hLtdcHandler.LayerCfg->ImageHeight = RK043FN48H_HEIGHT; 00171 00172 /* Background value */ 00173 hLtdcHandler.Init.Backcolor.Blue = 0; 00174 hLtdcHandler.Init.Backcolor.Green = 0; 00175 hLtdcHandler.Init.Backcolor.Red = 0; 00176 00177 /* Polarity */ 00178 hLtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL; 00179 hLtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL; 00180 hLtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL; 00181 hLtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC; 00182 hLtdcHandler.Instance = LTDC; 00183 00184 if(HAL_LTDC_GetState(&hLtdcHandler) == HAL_LTDC_STATE_RESET) 00185 { 00186 /* Initialize the LCD Msp: this __weak function can be rewritten by the application */ 00187 BSP_LCD_MspInit(&hLtdcHandler, NULL); 00188 } 00189 HAL_LTDC_Init(&hLtdcHandler); 00190 00191 /* Assert display enable LCD_DISP pin */ 00192 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_SET); 00193 00194 /* Assert backlight LCD_BL_CTRL pin */ 00195 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET); 00196 00197 #if !defined(DATA_IN_ExtSDRAM) 00198 /* Initialize the SDRAM */ 00199 BSP_SDRAM_Init(); 00200 #endif 00201 00202 /* Initialize the font */ 00203 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); 00204 00205 return LCD_OK; 00206 } 00207 00208 /** 00209 * @brief DeInitializes the LCD. 00210 * @retval LCD state 00211 */ 00212 uint8_t BSP_LCD_DeInit(void) 00213 { 00214 /* Initialize the hLtdcHandler Instance parameter */ 00215 hLtdcHandler.Instance = LTDC; 00216 00217 /* Disable LTDC block */ 00218 __HAL_LTDC_DISABLE(&hLtdcHandler); 00219 00220 /* DeInit the LTDC */ 00221 HAL_LTDC_DeInit(&hLtdcHandler); 00222 00223 /* DeInit the LTDC MSP : this __weak function can be rewritten by the application */ 00224 BSP_LCD_MspDeInit(&hLtdcHandler, NULL); 00225 00226 return LCD_OK; 00227 } 00228 00229 /** 00230 * @brief Gets the LCD X size. 00231 * @retval Used LCD X size 00232 */ 00233 uint32_t BSP_LCD_GetXSize(void) 00234 { 00235 return hLtdcHandler.LayerCfg[ActiveLayer].ImageWidth; 00236 } 00237 00238 /** 00239 * @brief Gets the LCD Y size. 00240 * @retval Used LCD Y size 00241 */ 00242 uint32_t BSP_LCD_GetYSize(void) 00243 { 00244 return hLtdcHandler.LayerCfg[ActiveLayer].ImageHeight; 00245 } 00246 00247 /** 00248 * @brief Set the LCD X size. 00249 * @param imageWidthPixels : image width in pixels unit 00250 * @retval None 00251 */ 00252 void BSP_LCD_SetXSize(uint32_t imageWidthPixels) 00253 { 00254 hLtdcHandler.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels; 00255 } 00256 00257 /** 00258 * @brief Set the LCD Y size. 00259 * @param imageHeightPixels : image height in lines unit 00260 * @retval None 00261 */ 00262 void BSP_LCD_SetYSize(uint32_t imageHeightPixels) 00263 { 00264 hLtdcHandler.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels; 00265 } 00266 00267 /** 00268 * @brief Initializes the LCD layer in ARGB8888 format (32 bits per pixel). 00269 * @param LayerIndex: Layer foreground or background 00270 * @param FB_Address: Layer frame buffer 00271 * @retval None 00272 */ 00273 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address) 00274 { 00275 LCD_LayerCfgTypeDef layer_cfg; 00276 00277 /* Layer Init */ 00278 layer_cfg.WindowX0 = 0; 00279 layer_cfg.WindowX1 = BSP_LCD_GetXSize(); 00280 layer_cfg.WindowY0 = 0; 00281 layer_cfg.WindowY1 = BSP_LCD_GetYSize(); 00282 layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888; 00283 layer_cfg.FBStartAdress = FB_Address; 00284 layer_cfg.Alpha = 255; 00285 layer_cfg.Alpha0 = 0; 00286 layer_cfg.Backcolor.Blue = 0; 00287 layer_cfg.Backcolor.Green = 0; 00288 layer_cfg.Backcolor.Red = 0; 00289 layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; 00290 layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; 00291 layer_cfg.ImageWidth = BSP_LCD_GetXSize(); 00292 layer_cfg.ImageHeight = BSP_LCD_GetYSize(); 00293 00294 HAL_LTDC_ConfigLayer(&hLtdcHandler, &layer_cfg, LayerIndex); 00295 00296 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE; 00297 DrawProp[LayerIndex].pFont = &Font24; 00298 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK; 00299 } 00300 00301 /** 00302 * @brief Initializes the LCD layer in RGB565 format (16 bits per pixel). 00303 * @param LayerIndex: Layer foreground or background 00304 * @param FB_Address: Layer frame buffer 00305 * @retval None 00306 */ 00307 void BSP_LCD_LayerRgb565Init(uint16_t LayerIndex, uint32_t FB_Address) 00308 { 00309 LCD_LayerCfgTypeDef layer_cfg; 00310 00311 /* Layer Init */ 00312 layer_cfg.WindowX0 = 0; 00313 layer_cfg.WindowX1 = BSP_LCD_GetXSize(); 00314 layer_cfg.WindowY0 = 0; 00315 layer_cfg.WindowY1 = BSP_LCD_GetYSize(); 00316 layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; 00317 layer_cfg.FBStartAdress = FB_Address; 00318 layer_cfg.Alpha = 255; 00319 layer_cfg.Alpha0 = 0; 00320 layer_cfg.Backcolor.Blue = 0; 00321 layer_cfg.Backcolor.Green = 0; 00322 layer_cfg.Backcolor.Red = 0; 00323 layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; 00324 layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; 00325 layer_cfg.ImageWidth = BSP_LCD_GetXSize(); 00326 layer_cfg.ImageHeight = BSP_LCD_GetYSize(); 00327 00328 HAL_LTDC_ConfigLayer(&hLtdcHandler, &layer_cfg, LayerIndex); 00329 00330 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE; 00331 DrawProp[LayerIndex].pFont = &Font24; 00332 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK; 00333 } 00334 00335 /** 00336 * @brief Selects the LCD Layer. 00337 * @param LayerIndex: Layer foreground or background 00338 * @retval None 00339 */ 00340 void BSP_LCD_SelectLayer(uint32_t LayerIndex) 00341 { 00342 ActiveLayer = LayerIndex; 00343 } 00344 00345 /** 00346 * @brief Sets an LCD Layer visible 00347 * @param LayerIndex: Visible Layer 00348 * @param State: New state of the specified layer 00349 * This parameter can be one of the following values: 00350 * @arg ENABLE 00351 * @arg DISABLE 00352 * @retval None 00353 */ 00354 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State) 00355 { 00356 if(State == ENABLE) 00357 { 00358 __HAL_LTDC_LAYER_ENABLE(&hLtdcHandler, LayerIndex); 00359 } 00360 else 00361 { 00362 __HAL_LTDC_LAYER_DISABLE(&hLtdcHandler, LayerIndex); 00363 } 00364 __HAL_LTDC_RELOAD_CONFIG(&hLtdcHandler); 00365 } 00366 00367 /** 00368 * @brief Configures the transparency. 00369 * @param LayerIndex: Layer foreground or background. 00370 * @param Transparency: Transparency 00371 * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF 00372 * @retval None 00373 */ 00374 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency) 00375 { 00376 HAL_LTDC_SetAlpha(&hLtdcHandler, Transparency, LayerIndex); 00377 } 00378 00379 /** 00380 * @brief Sets an LCD layer frame buffer address. 00381 * @param LayerIndex: Layer foreground or background 00382 * @param Address: New LCD frame buffer value 00383 * @retval None 00384 */ 00385 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address) 00386 { 00387 HAL_LTDC_SetAddress(&hLtdcHandler, Address, LayerIndex); 00388 } 00389 00390 /** 00391 * @brief Sets display window. 00392 * @param LayerIndex: Layer index 00393 * @param Xpos: LCD X position 00394 * @param Ypos: LCD Y position 00395 * @param Width: LCD window width 00396 * @param Height: LCD window height 00397 * @retval None 00398 */ 00399 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00400 { 00401 /* Reconfigure the layer size */ 00402 HAL_LTDC_SetWindowSize(&hLtdcHandler, Width, Height, LayerIndex); 00403 00404 /* Reconfigure the layer position */ 00405 HAL_LTDC_SetWindowPosition(&hLtdcHandler, Xpos, Ypos, LayerIndex); 00406 } 00407 00408 /** 00409 * @brief Configures and sets the color keying. 00410 * @param LayerIndex: Layer foreground or background 00411 * @param RGBValue: Color reference 00412 * @retval None 00413 */ 00414 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue) 00415 { 00416 /* Configure and Enable the color Keying for LCD Layer */ 00417 HAL_LTDC_ConfigColorKeying(&hLtdcHandler, RGBValue, LayerIndex); 00418 HAL_LTDC_EnableColorKeying(&hLtdcHandler, LayerIndex); 00419 } 00420 00421 /** 00422 * @brief Disables the color keying. 00423 * @param LayerIndex: Layer foreground or background 00424 * @retval None 00425 */ 00426 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex) 00427 { 00428 /* Disable the color Keying for LCD Layer */ 00429 HAL_LTDC_DisableColorKeying(&hLtdcHandler, LayerIndex); 00430 } 00431 00432 /** 00433 * @brief Sets the LCD text color. 00434 * @param Color: Text color code ARGB(8-8-8-8) 00435 * @retval None 00436 */ 00437 void BSP_LCD_SetTextColor(uint32_t Color) 00438 { 00439 DrawProp[ActiveLayer].TextColor = Color; 00440 } 00441 00442 /** 00443 * @brief Gets the LCD text color. 00444 * @retval Used text color. 00445 */ 00446 uint32_t BSP_LCD_GetTextColor(void) 00447 { 00448 return DrawProp[ActiveLayer].TextColor; 00449 } 00450 00451 /** 00452 * @brief Sets the LCD background color. 00453 * @param Color: Layer background color code ARGB(8-8-8-8) 00454 * @retval None 00455 */ 00456 void BSP_LCD_SetBackColor(uint32_t Color) 00457 { 00458 DrawProp[ActiveLayer].BackColor = Color; 00459 } 00460 00461 /** 00462 * @brief Gets the LCD background color. 00463 * @retval Used background colour 00464 */ 00465 uint32_t BSP_LCD_GetBackColor(void) 00466 { 00467 return DrawProp[ActiveLayer].BackColor; 00468 } 00469 00470 /** 00471 * @brief Sets the LCD text font. 00472 * @param fonts: Layer font to be used 00473 * @retval None 00474 */ 00475 void BSP_LCD_SetFont(sFONT *fonts) 00476 { 00477 DrawProp[ActiveLayer].pFont = fonts; 00478 } 00479 00480 /** 00481 * @brief Gets the LCD text font. 00482 * @retval Used layer font 00483 */ 00484 sFONT *BSP_LCD_GetFont(void) 00485 { 00486 return DrawProp[ActiveLayer].pFont; 00487 } 00488 00489 /** 00490 * @brief Reads an LCD pixel. 00491 * @param Xpos: X position 00492 * @param Ypos: Y position 00493 * @retval RGB pixel color 00494 */ 00495 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos) 00496 { 00497 uint32_t ret = 0; 00498 00499 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888) 00500 { 00501 /* Read data value from SDRAM memory */ 00502 ret = *(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); 00503 } 00504 else if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888) 00505 { 00506 /* Read data value from SDRAM memory */ 00507 ret = (*(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF); 00508 } 00509 else if((hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \ 00510 (hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \ 00511 (hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88)) 00512 { 00513 /* Read data value from SDRAM memory */ 00514 ret = *(__IO uint16_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); 00515 } 00516 else 00517 { 00518 /* Read data value from SDRAM memory */ 00519 ret = *(__IO uint8_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); 00520 } 00521 00522 return ret; 00523 } 00524 00525 /** 00526 * @brief Clears the hole LCD. 00527 * @param Color: Color of the background 00528 * @retval None 00529 */ 00530 void BSP_LCD_Clear(uint32_t Color) 00531 { 00532 /* Clear the LCD */ 00533 LL_FillBuffer(ActiveLayer, (uint32_t *)(hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color); 00534 } 00535 00536 /** 00537 * @brief Clears the selected line. 00538 * @param Line: Line to be cleared 00539 * @retval None 00540 */ 00541 void BSP_LCD_ClearStringLine(uint32_t Line) 00542 { 00543 uint32_t color_backup = DrawProp[ActiveLayer].TextColor; 00544 DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor; 00545 00546 /* Draw rectangle with background color */ 00547 BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height); 00548 00549 DrawProp[ActiveLayer].TextColor = color_backup; 00550 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 00551 } 00552 00553 /** 00554 * @brief Displays one character. 00555 * @param Xpos: Start column address 00556 * @param Ypos: Line where to display the character shape. 00557 * @param Ascii: Character ascii code 00558 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E 00559 * @retval None 00560 */ 00561 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) 00562 { 00563 DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\ 00564 DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]); 00565 } 00566 00567 /** 00568 * @brief Displays characters on the LCD. 00569 * @param Xpos: X position (in pixel) 00570 * @param Ypos: Y position (in pixel) 00571 * @param Text: Pointer to string to display on LCD 00572 * @param Mode: Display mode 00573 * This parameter can be one of the following values: 00574 * @arg CENTER_MODE 00575 * @arg RIGHT_MODE 00576 * @arg LEFT_MODE 00577 * @retval None 00578 */ 00579 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode) 00580 { 00581 uint16_t ref_column = 1, i = 0; 00582 uint32_t size = 0, xsize = 0; 00583 uint8_t *ptr = Text; 00584 00585 /* Get the text size */ 00586 while (*ptr++) size ++ ; 00587 00588 /* Characters number per line */ 00589 xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width); 00590 00591 switch (Mode) 00592 { 00593 case CENTER_MODE: 00594 { 00595 ref_column = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2; 00596 break; 00597 } 00598 case LEFT_MODE: 00599 { 00600 ref_column = Xpos; 00601 break; 00602 } 00603 case RIGHT_MODE: 00604 { 00605 ref_column = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width); 00606 break; 00607 } 00608 default: 00609 { 00610 ref_column = Xpos; 00611 break; 00612 } 00613 } 00614 00615 /* Check that the Start column is located in the screen */ 00616 if ((ref_column < 1) || (ref_column >= 0x8000)) 00617 { 00618 ref_column = 1; 00619 } 00620 00621 /* Send the string character by character on LCD */ 00622 while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width)) 00623 { 00624 /* Display one character on LCD */ 00625 BSP_LCD_DisplayChar(ref_column, Ypos, *Text); 00626 /* Decrement the column position by 16 */ 00627 ref_column += DrawProp[ActiveLayer].pFont->Width; 00628 /* Point on the next character */ 00629 Text++; 00630 i++; 00631 } 00632 } 00633 00634 /** 00635 * @brief Displays a maximum of 60 characters on the LCD. 00636 * @param Line: Line where to display the character shape 00637 * @param ptr: Pointer to string to display on LCD 00638 * @retval None 00639 */ 00640 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr) 00641 { 00642 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE); 00643 } 00644 00645 /** 00646 * @brief Draws an horizontal line. 00647 * @param Xpos: X position 00648 * @param Ypos: Y position 00649 * @param Length: Line length 00650 * @retval None 00651 */ 00652 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00653 { 00654 uint32_t Xaddress = 0; 00655 00656 /* Get the line address */ 00657 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) 00658 { /* RGB565 format */ 00659 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos); 00660 } 00661 else 00662 { /* ARGB8888 format */ 00663 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); 00664 } 00665 00666 /* Write line */ 00667 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor); 00668 } 00669 00670 /** 00671 * @brief Draws a vertical line. 00672 * @param Xpos: X position 00673 * @param Ypos: Y position 00674 * @param Length: Line length 00675 * @retval None 00676 */ 00677 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00678 { 00679 uint32_t Xaddress = 0; 00680 00681 /* Get the line address */ 00682 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) 00683 { /* RGB565 format */ 00684 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos); 00685 } 00686 else 00687 { /* ARGB8888 format */ 00688 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); 00689 } 00690 00691 /* Write line */ 00692 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor); 00693 } 00694 00695 /** 00696 * @brief Draws an uni-line (between two points). 00697 * @param x1: Point 1 X position 00698 * @param y1: Point 1 Y position 00699 * @param x2: Point 2 X position 00700 * @param y2: Point 2 Y position 00701 * @retval None 00702 */ 00703 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) 00704 { 00705 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 00706 yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0, 00707 curpixel = 0; 00708 00709 deltax = ABS(x2 - x1); /* The difference between the x's */ 00710 deltay = ABS(y2 - y1); /* The difference between the y's */ 00711 x = x1; /* Start x off at the first pixel */ 00712 y = y1; /* Start y off at the first pixel */ 00713 00714 if (x2 >= x1) /* The x-values are increasing */ 00715 { 00716 xinc1 = 1; 00717 xinc2 = 1; 00718 } 00719 else /* The x-values are decreasing */ 00720 { 00721 xinc1 = -1; 00722 xinc2 = -1; 00723 } 00724 00725 if (y2 >= y1) /* The y-values are increasing */ 00726 { 00727 yinc1 = 1; 00728 yinc2 = 1; 00729 } 00730 else /* The y-values are decreasing */ 00731 { 00732 yinc1 = -1; 00733 yinc2 = -1; 00734 } 00735 00736 if (deltax >= deltay) /* There is at least one x-value for every y-value */ 00737 { 00738 xinc1 = 0; /* Don't change the x when numerator >= denominator */ 00739 yinc2 = 0; /* Don't change the y for every iteration */ 00740 den = deltax; 00741 num = deltax / 2; 00742 num_add = deltay; 00743 num_pixels = deltax; /* There are more x-values than y-values */ 00744 } 00745 else /* There is at least one y-value for every x-value */ 00746 { 00747 xinc2 = 0; /* Don't change the x for every iteration */ 00748 yinc1 = 0; /* Don't change the y when numerator >= denominator */ 00749 den = deltay; 00750 num = deltay / 2; 00751 num_add = deltax; 00752 num_pixels = deltay; /* There are more y-values than x-values */ 00753 } 00754 00755 for (curpixel = 0; curpixel <= num_pixels; curpixel++) 00756 { 00757 BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */ 00758 num += num_add; /* Increase the numerator by the top of the fraction */ 00759 if (num >= den) /* Check if numerator >= denominator */ 00760 { 00761 num -= den; /* Calculate the new numerator value */ 00762 x += xinc1; /* Change the x as appropriate */ 00763 y += yinc1; /* Change the y as appropriate */ 00764 } 00765 x += xinc2; /* Change the x as appropriate */ 00766 y += yinc2; /* Change the y as appropriate */ 00767 } 00768 } 00769 00770 /** 00771 * @brief Draws a rectangle. 00772 * @param Xpos: X position 00773 * @param Ypos: Y position 00774 * @param Width: Rectangle width 00775 * @param Height: Rectangle height 00776 * @retval None 00777 */ 00778 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00779 { 00780 /* Draw horizontal lines */ 00781 BSP_LCD_DrawHLine(Xpos, Ypos, Width); 00782 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width); 00783 00784 /* Draw vertical lines */ 00785 BSP_LCD_DrawVLine(Xpos, Ypos, Height); 00786 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height); 00787 } 00788 00789 /** 00790 * @brief Draws a circle. 00791 * @param Xpos: X position 00792 * @param Ypos: Y position 00793 * @param Radius: Circle radius 00794 * @retval None 00795 */ 00796 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 00797 { 00798 int32_t decision; /* Decision Variable */ 00799 uint32_t current_x; /* Current X Value */ 00800 uint32_t current_y; /* Current Y Value */ 00801 00802 decision = 3 - (Radius << 1); 00803 current_x = 0; 00804 current_y = Radius; 00805 00806 while (current_x <= current_y) 00807 { 00808 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos - current_y), DrawProp[ActiveLayer].TextColor); 00809 00810 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos - current_y), DrawProp[ActiveLayer].TextColor); 00811 00812 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos - current_x), DrawProp[ActiveLayer].TextColor); 00813 00814 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos - current_x), DrawProp[ActiveLayer].TextColor); 00815 00816 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos + current_y), DrawProp[ActiveLayer].TextColor); 00817 00818 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos + current_y), DrawProp[ActiveLayer].TextColor); 00819 00820 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos + current_x), DrawProp[ActiveLayer].TextColor); 00821 00822 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos + current_x), DrawProp[ActiveLayer].TextColor); 00823 00824 if (decision < 0) 00825 { 00826 decision += (current_x << 2) + 6; 00827 } 00828 else 00829 { 00830 decision += ((current_x - current_y) << 2) + 10; 00831 current_y--; 00832 } 00833 current_x++; 00834 } 00835 } 00836 00837 /** 00838 * @brief Draws an poly-line (between many points). 00839 * @param Points: Pointer to the points array 00840 * @param PointCount: Number of points 00841 * @retval None 00842 */ 00843 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount) 00844 { 00845 int16_t x = 0, y = 0; 00846 00847 if(PointCount < 2) 00848 { 00849 return; 00850 } 00851 00852 BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); 00853 00854 while(--PointCount) 00855 { 00856 x = Points->X; 00857 y = Points->Y; 00858 Points++; 00859 BSP_LCD_DrawLine(x, y, Points->X, Points->Y); 00860 } 00861 } 00862 00863 /** 00864 * @brief Draws an ellipse on LCD. 00865 * @param Xpos: X position 00866 * @param Ypos: Y position 00867 * @param XRadius: Ellipse X radius 00868 * @param YRadius: Ellipse Y radius 00869 * @retval None 00870 */ 00871 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 00872 { 00873 int x = 0, y = -YRadius, err = 2-2*XRadius, e2; 00874 float k = 0, rad1 = 0, rad2 = 0; 00875 00876 rad1 = XRadius; 00877 rad2 = YRadius; 00878 00879 k = (float)(rad2/rad1); 00880 00881 do { 00882 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor); 00883 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor); 00884 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor); 00885 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor); 00886 00887 e2 = err; 00888 if (e2 <= x) { 00889 err += ++x*2+1; 00890 if (-y == x && e2 <= y) e2 = 0; 00891 } 00892 if (e2 > y) err += ++y*2+1; 00893 } 00894 while (y <= 0); 00895 } 00896 00897 /** 00898 * @brief Draws a pixel on LCD. 00899 * @param Xpos: X position 00900 * @param Ypos: Y position 00901 * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8) 00902 * @retval None 00903 */ 00904 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code) 00905 { 00906 /* Write data value to all SDRAM memory */ 00907 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) 00908 { /* RGB565 format */ 00909 *(__IO uint16_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) = (uint16_t)RGB_Code; 00910 } 00911 else 00912 { /* ARGB8888 format */ 00913 *(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code; 00914 } 00915 } 00916 00917 /** 00918 * @brief Draws a bitmap picture loaded in the internal Flash in ARGB888 format (32 bits per pixel). 00919 * @param Xpos: Bmp X position in the LCD 00920 * @param Ypos: Bmp Y position in the LCD 00921 * @param pbmp: Pointer to Bmp picture address in the internal Flash 00922 * @retval None 00923 */ 00924 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp) 00925 { 00926 uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; 00927 uint32_t address; 00928 uint32_t input_color_mode = 0; 00929 00930 /* Get bitmap data address offset */ 00931 index = *(__IO uint16_t *) (pbmp + 10); 00932 index |= (*(__IO uint16_t *) (pbmp + 12)) << 16; 00933 00934 /* Read bitmap width */ 00935 width = *(uint16_t *) (pbmp + 18); 00936 width |= (*(uint16_t *) (pbmp + 20)) << 16; 00937 00938 /* Read bitmap height */ 00939 height = *(uint16_t *) (pbmp + 22); 00940 height |= (*(uint16_t *) (pbmp + 24)) << 16; 00941 00942 /* Read bit/pixel */ 00943 bit_pixel = *(uint16_t *) (pbmp + 28); 00944 00945 /* Set the address */ 00946 address = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); 00947 00948 /* Get the layer pixel format */ 00949 if ((bit_pixel/8) == 4) 00950 { 00951 input_color_mode = CM_ARGB8888; 00952 } 00953 else if ((bit_pixel/8) == 2) 00954 { 00955 input_color_mode = CM_RGB565; 00956 } 00957 else 00958 { 00959 input_color_mode = CM_RGB888; 00960 } 00961 00962 /* Bypass the bitmap header */ 00963 pbmp += (index + (width * (height - 1) * (bit_pixel/8))); 00964 00965 /* Convert picture to ARGB8888 pixel format */ 00966 for(index=0; index < height; index++) 00967 { 00968 /* Pixel format conversion */ 00969 LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)address, width, input_color_mode); 00970 00971 /* Increment the source and destination buffers */ 00972 address+= (BSP_LCD_GetXSize()*4); 00973 pbmp -= width*(bit_pixel/8); 00974 } 00975 } 00976 00977 /** 00978 * @brief Draws a full rectangle. 00979 * @param Xpos: X position 00980 * @param Ypos: Y position 00981 * @param Width: Rectangle width 00982 * @param Height: Rectangle height 00983 * @retval None 00984 */ 00985 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00986 { 00987 uint32_t x_address = 0; 00988 00989 /* Set the text color */ 00990 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 00991 00992 /* Get the rectangle start address */ 00993 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) 00994 { /* RGB565 format */ 00995 x_address = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos); 00996 } 00997 else 00998 { /* ARGB8888 format */ 00999 x_address = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); 01000 } 01001 /* Fill the rectangle */ 01002 LL_FillBuffer(ActiveLayer, (uint32_t *)x_address, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor); 01003 } 01004 01005 /** 01006 * @brief Draws a full circle. 01007 * @param Xpos: X position 01008 * @param Ypos: Y position 01009 * @param Radius: Circle radius 01010 * @retval None 01011 */ 01012 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 01013 { 01014 int32_t decision; /* Decision Variable */ 01015 uint32_t current_x; /* Current X Value */ 01016 uint32_t current_y; /* Current Y Value */ 01017 01018 decision = 3 - (Radius << 1); 01019 01020 current_x = 0; 01021 current_y = Radius; 01022 01023 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 01024 01025 while (current_x <= current_y) 01026 { 01027 if(current_y > 0) 01028 { 01029 BSP_LCD_DrawHLine(Xpos - current_y, Ypos + current_x, 2*current_y); 01030 BSP_LCD_DrawHLine(Xpos - current_y, Ypos - current_x, 2*current_y); 01031 } 01032 01033 if(current_x > 0) 01034 { 01035 BSP_LCD_DrawHLine(Xpos - current_x, Ypos - current_y, 2*current_x); 01036 BSP_LCD_DrawHLine(Xpos - current_x, Ypos + current_y, 2*current_x); 01037 } 01038 if (decision < 0) 01039 { 01040 decision += (current_x << 2) + 6; 01041 } 01042 else 01043 { 01044 decision += ((current_x - current_y) << 2) + 10; 01045 current_y--; 01046 } 01047 current_x++; 01048 } 01049 01050 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 01051 BSP_LCD_DrawCircle(Xpos, Ypos, Radius); 01052 } 01053 01054 /** 01055 * @brief Draws a full poly-line (between many points). 01056 * @param Points: Pointer to the points array 01057 * @param PointCount: Number of points 01058 * @retval None 01059 */ 01060 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) 01061 { 01062 int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0; 01063 uint16_t image_left = 0, image_right = 0, image_top = 0, image_bottom = 0; 01064 01065 image_left = image_right = Points->X; 01066 image_top= image_bottom = Points->Y; 01067 01068 for(counter = 1; counter < PointCount; counter++) 01069 { 01070 pixelX = POLY_X(counter); 01071 if(pixelX < image_left) 01072 { 01073 image_left = pixelX; 01074 } 01075 if(pixelX > image_right) 01076 { 01077 image_right = pixelX; 01078 } 01079 01080 pixelY = POLY_Y(counter); 01081 if(pixelY < image_top) 01082 { 01083 image_top = pixelY; 01084 } 01085 if(pixelY > image_bottom) 01086 { 01087 image_bottom = pixelY; 01088 } 01089 } 01090 01091 if(PointCount < 2) 01092 { 01093 return; 01094 } 01095 01096 X_center = (image_left + image_right)/2; 01097 Y_center = (image_bottom + image_top)/2; 01098 01099 X_first = Points->X; 01100 Y_first = Points->Y; 01101 01102 while(--PointCount) 01103 { 01104 X = Points->X; 01105 Y = Points->Y; 01106 Points++; 01107 X2 = Points->X; 01108 Y2 = Points->Y; 01109 01110 FillTriangle(X, X2, X_center, Y, Y2, Y_center); 01111 FillTriangle(X, X_center, X2, Y, Y_center, Y2); 01112 FillTriangle(X_center, X2, X, Y_center, Y2, Y); 01113 } 01114 01115 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); 01116 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); 01117 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); 01118 } 01119 01120 /** 01121 * @brief Draws a full ellipse. 01122 * @param Xpos: X position 01123 * @param Ypos: Y position 01124 * @param XRadius: Ellipse X radius 01125 * @param YRadius: Ellipse Y radius 01126 * @retval None 01127 */ 01128 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 01129 { 01130 int x = 0, y = -YRadius, err = 2-2*XRadius, e2; 01131 float k = 0, rad1 = 0, rad2 = 0; 01132 01133 rad1 = XRadius; 01134 rad2 = YRadius; 01135 01136 k = (float)(rad2/rad1); 01137 01138 do 01139 { 01140 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos+y), (2*(uint16_t)(x/k) + 1)); 01141 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos-y), (2*(uint16_t)(x/k) + 1)); 01142 01143 e2 = err; 01144 if (e2 <= x) 01145 { 01146 err += ++x*2+1; 01147 if (-y == x && e2 <= y) e2 = 0; 01148 } 01149 if (e2 > y) err += ++y*2+1; 01150 } 01151 while (y <= 0); 01152 } 01153 01154 /** 01155 * @brief Enables the display. 01156 * @retval None 01157 */ 01158 void BSP_LCD_DisplayOn(void) 01159 { 01160 /* Display On */ 01161 __HAL_LTDC_ENABLE(&hLtdcHandler); 01162 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_SET); /* Assert LCD_DISP pin */ 01163 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET); /* Assert LCD_BL_CTRL pin */ 01164 } 01165 01166 /** 01167 * @brief Disables the display. 01168 * @retval None 01169 */ 01170 void BSP_LCD_DisplayOff(void) 01171 { 01172 /* Display Off */ 01173 __HAL_LTDC_DISABLE(&hLtdcHandler); 01174 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_RESET); /* De-assert LCD_DISP pin */ 01175 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_RESET);/* De-assert LCD_BL_CTRL pin */ 01176 } 01177 01178 /** 01179 * @brief Initializes the LTDC MSP. 01180 * @param hltdc: LTDC handle 01181 * @param Params 01182 * @retval None 01183 */ 01184 __weak void BSP_LCD_MspInit(LTDC_HandleTypeDef *hltdc, void *Params) 01185 { 01186 GPIO_InitTypeDef gpio_init_structure; 01187 01188 /* Enable the LTDC and DMA2D clocks */ 01189 __HAL_RCC_LTDC_CLK_ENABLE(); 01190 __HAL_RCC_DMA2D_CLK_ENABLE(); 01191 01192 /* Enable GPIOs clock */ 01193 __HAL_RCC_GPIOE_CLK_ENABLE(); 01194 __HAL_RCC_GPIOG_CLK_ENABLE(); 01195 __HAL_RCC_GPIOI_CLK_ENABLE(); 01196 __HAL_RCC_GPIOJ_CLK_ENABLE(); 01197 __HAL_RCC_GPIOK_CLK_ENABLE(); 01198 LCD_DISP_GPIO_CLK_ENABLE(); 01199 LCD_BL_CTRL_GPIO_CLK_ENABLE(); 01200 01201 /*** LTDC Pins configuration ***/ 01202 /* GPIOE configuration */ 01203 gpio_init_structure.Pin = GPIO_PIN_4; 01204 gpio_init_structure.Mode = GPIO_MODE_AF_PP; 01205 gpio_init_structure.Pull = GPIO_NOPULL; 01206 gpio_init_structure.Speed = GPIO_SPEED_FAST; 01207 gpio_init_structure.Alternate = GPIO_AF14_LTDC; 01208 HAL_GPIO_Init(GPIOE, &gpio_init_structure); 01209 01210 /* GPIOG configuration */ 01211 gpio_init_structure.Pin = GPIO_PIN_12; 01212 gpio_init_structure.Mode = GPIO_MODE_AF_PP; 01213 gpio_init_structure.Alternate = GPIO_AF9_LTDC; 01214 HAL_GPIO_Init(GPIOG, &gpio_init_structure); 01215 01216 /* GPIOI LTDC alternate configuration */ 01217 gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | \ 01218 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; 01219 gpio_init_structure.Mode = GPIO_MODE_AF_PP; 01220 gpio_init_structure.Alternate = GPIO_AF14_LTDC; 01221 HAL_GPIO_Init(GPIOI, &gpio_init_structure); 01222 01223 /* GPIOJ configuration */ 01224 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | \ 01225 GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | \ 01226 GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \ 01227 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; 01228 gpio_init_structure.Mode = GPIO_MODE_AF_PP; 01229 gpio_init_structure.Alternate = GPIO_AF14_LTDC; 01230 HAL_GPIO_Init(GPIOJ, &gpio_init_structure); 01231 01232 /* GPIOK configuration */ 01233 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4 | \ 01234 GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; 01235 gpio_init_structure.Mode = GPIO_MODE_AF_PP; 01236 gpio_init_structure.Alternate = GPIO_AF14_LTDC; 01237 HAL_GPIO_Init(GPIOK, &gpio_init_structure); 01238 01239 /* LCD_DISP GPIO configuration */ 01240 gpio_init_structure.Pin = LCD_DISP_PIN; /* LCD_DISP pin has to be manually controlled */ 01241 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; 01242 HAL_GPIO_Init(LCD_DISP_GPIO_PORT, &gpio_init_structure); 01243 01244 /* LCD_BL_CTRL GPIO configuration */ 01245 gpio_init_structure.Pin = LCD_BL_CTRL_PIN; /* LCD_BL_CTRL pin has to be manually controlled */ 01246 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; 01247 HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &gpio_init_structure); 01248 } 01249 01250 /** 01251 * @brief DeInitializes BSP_LCD MSP. 01252 * @param hltdc: LTDC handle 01253 * @param Params 01254 * @retval None 01255 */ 01256 __weak void BSP_LCD_MspDeInit(LTDC_HandleTypeDef *hltdc, void *Params) 01257 { 01258 GPIO_InitTypeDef gpio_init_structure; 01259 01260 /* Disable LTDC block */ 01261 __HAL_LTDC_DISABLE(hltdc); 01262 01263 /* LTDC Pins deactivation */ 01264 01265 /* GPIOE deactivation */ 01266 gpio_init_structure.Pin = GPIO_PIN_4; 01267 HAL_GPIO_DeInit(GPIOE, gpio_init_structure.Pin); 01268 01269 /* GPIOG deactivation */ 01270 gpio_init_structure.Pin = GPIO_PIN_12; 01271 HAL_GPIO_DeInit(GPIOG, gpio_init_structure.Pin); 01272 01273 /* GPIOI deactivation */ 01274 gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_12 | \ 01275 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; 01276 HAL_GPIO_DeInit(GPIOI, gpio_init_structure.Pin); 01277 01278 /* GPIOJ deactivation */ 01279 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | \ 01280 GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | \ 01281 GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \ 01282 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15; 01283 HAL_GPIO_DeInit(GPIOJ, gpio_init_structure.Pin); 01284 01285 /* GPIOK deactivation */ 01286 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4 | \ 01287 GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; 01288 HAL_GPIO_DeInit(GPIOK, gpio_init_structure.Pin); 01289 01290 /* Disable LTDC clock */ 01291 __HAL_RCC_LTDC_CLK_DISABLE(); 01292 01293 /* GPIO pins clock can be shut down in the application 01294 by surcharging this __weak function */ 01295 } 01296 01297 /** 01298 * @brief Clock Config. 01299 * @param hltdc: LTDC handle 01300 * @param Params 01301 * @note This API is called by BSP_LCD_Init() 01302 * Being __weak it can be overwritten by the application 01303 * @retval None 01304 */ 01305 __weak void BSP_LCD_ClockConfig(LTDC_HandleTypeDef *hltdc, void *Params) 01306 { 01307 static RCC_PeriphCLKInitTypeDef periph_clk_init_struct; 01308 01309 /* RK043FN48H LCD clock configuration */ 01310 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ 01311 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ 01312 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/5 = 38.4 Mhz */ 01313 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_4 = 38.4/4 = 9.6Mhz */ 01314 periph_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; 01315 periph_clk_init_struct.PLLSAI.PLLSAIN = 192; 01316 periph_clk_init_struct.PLLSAI.PLLSAIR = RK043FN48H_FREQUENCY_DIVIDER; 01317 periph_clk_init_struct.PLLSAIDivR = RCC_PLLSAIDIVR_4; 01318 HAL_RCCEx_PeriphCLKConfig(&periph_clk_init_struct); 01319 } 01320 01321 01322 /******************************************************************************* 01323 Static Functions 01324 *******************************************************************************/ 01325 01326 /** 01327 * @brief Draws a character on LCD. 01328 * @param Xpos: Line where to display the character shape 01329 * @param Ypos: Start column address 01330 * @param c: Pointer to the character data 01331 * @retval None 01332 */ 01333 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c) 01334 { 01335 uint32_t i = 0, j = 0; 01336 uint16_t height, width; 01337 uint8_t offset; 01338 uint8_t *pchar; 01339 uint32_t line; 01340 01341 height = DrawProp[ActiveLayer].pFont->Height; 01342 width = DrawProp[ActiveLayer].pFont->Width; 01343 01344 offset = 8 *((width + 7)/8) - width ; 01345 01346 for(i = 0; i < height; i++) 01347 { 01348 pchar = ((uint8_t *)c + (width + 7)/8 * i); 01349 01350 switch(((width + 7)/8)) 01351 { 01352 01353 case 1: 01354 line = pchar[0]; 01355 break; 01356 01357 case 2: 01358 line = (pchar[0]<< 8) | pchar[1]; 01359 break; 01360 01361 case 3: 01362 default: 01363 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; 01364 break; 01365 } 01366 01367 for (j = 0; j < width; j++) 01368 { 01369 if(line & (1 << (width- j + offset- 1))) 01370 { 01371 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor); 01372 } 01373 else 01374 { 01375 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor); 01376 } 01377 } 01378 Ypos++; 01379 } 01380 } 01381 01382 /** 01383 * @brief Fills a triangle (between 3 points). 01384 * @param x1: Point 1 X position 01385 * @param y1: Point 1 Y position 01386 * @param x2: Point 2 X position 01387 * @param y2: Point 2 Y position 01388 * @param x3: Point 3 X position 01389 * @param y3: Point 3 Y position 01390 * @retval None 01391 */ 01392 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3) 01393 { 01394 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 01395 yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0, 01396 curpixel = 0; 01397 01398 deltax = ABS(x2 - x1); /* The difference between the x's */ 01399 deltay = ABS(y2 - y1); /* The difference between the y's */ 01400 x = x1; /* Start x off at the first pixel */ 01401 y = y1; /* Start y off at the first pixel */ 01402 01403 if (x2 >= x1) /* The x-values are increasing */ 01404 { 01405 xinc1 = 1; 01406 xinc2 = 1; 01407 } 01408 else /* The x-values are decreasing */ 01409 { 01410 xinc1 = -1; 01411 xinc2 = -1; 01412 } 01413 01414 if (y2 >= y1) /* The y-values are increasing */ 01415 { 01416 yinc1 = 1; 01417 yinc2 = 1; 01418 } 01419 else /* The y-values are decreasing */ 01420 { 01421 yinc1 = -1; 01422 yinc2 = -1; 01423 } 01424 01425 if (deltax >= deltay) /* There is at least one x-value for every y-value */ 01426 { 01427 xinc1 = 0; /* Don't change the x when numerator >= denominator */ 01428 yinc2 = 0; /* Don't change the y for every iteration */ 01429 den = deltax; 01430 num = deltax / 2; 01431 num_add = deltay; 01432 num_pixels = deltax; /* There are more x-values than y-values */ 01433 } 01434 else /* There is at least one y-value for every x-value */ 01435 { 01436 xinc2 = 0; /* Don't change the x for every iteration */ 01437 yinc1 = 0; /* Don't change the y when numerator >= denominator */ 01438 den = deltay; 01439 num = deltay / 2; 01440 num_add = deltax; 01441 num_pixels = deltay; /* There are more y-values than x-values */ 01442 } 01443 01444 for (curpixel = 0; curpixel <= num_pixels; curpixel++) 01445 { 01446 BSP_LCD_DrawLine(x, y, x3, y3); 01447 01448 num += num_add; /* Increase the numerator by the top of the fraction */ 01449 if (num >= den) /* Check if numerator >= denominator */ 01450 { 01451 num -= den; /* Calculate the new numerator value */ 01452 x += xinc1; /* Change the x as appropriate */ 01453 y += yinc1; /* Change the y as appropriate */ 01454 } 01455 x += xinc2; /* Change the x as appropriate */ 01456 y += yinc2; /* Change the y as appropriate */ 01457 } 01458 } 01459 01460 /** 01461 * @brief Fills a buffer. 01462 * @param LayerIndex: Layer index 01463 * @param pDst: Pointer to destination buffer 01464 * @param xSize: Buffer width 01465 * @param ySize: Buffer height 01466 * @param OffLine: Offset 01467 * @param ColorIndex: Color index 01468 * @retval None 01469 */ 01470 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex) 01471 { 01472 /* Register to memory mode with ARGB8888 as color Mode */ 01473 hDma2dHandler.Init.Mode = DMA2D_R2M; 01474 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) 01475 { /* RGB565 format */ 01476 hDma2dHandler.Init.ColorMode = DMA2D_RGB565; 01477 } 01478 else 01479 { /* ARGB8888 format */ 01480 hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888; 01481 } 01482 hDma2dHandler.Init.OutputOffset = OffLine; 01483 01484 hDma2dHandler.Instance = DMA2D; 01485 01486 /* DMA2D Initialization */ 01487 if(HAL_DMA2D_Init(&hDma2dHandler) == HAL_OK) 01488 { 01489 if(HAL_DMA2D_ConfigLayer(&hDma2dHandler, LayerIndex) == HAL_OK) 01490 { 01491 if (HAL_DMA2D_Start(&hDma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK) 01492 { 01493 /* Polling For DMA transfer */ 01494 HAL_DMA2D_PollForTransfer(&hDma2dHandler, 10); 01495 } 01496 } 01497 } 01498 } 01499 01500 /** 01501 * @brief Converts a line to an ARGB8888 pixel format. 01502 * @param pSrc: Pointer to source buffer 01503 * @param pDst: Output color 01504 * @param xSize: Buffer width 01505 * @param ColorMode: Input color mode 01506 * @retval None 01507 */ 01508 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode) 01509 { 01510 /* Configure the DMA2D Mode, Color Mode and output offset */ 01511 hDma2dHandler.Init.Mode = DMA2D_M2M_PFC; 01512 hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888; 01513 hDma2dHandler.Init.OutputOffset = 0; 01514 01515 /* Foreground Configuration */ 01516 hDma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; 01517 hDma2dHandler.LayerCfg[1].InputAlpha = 0xFF; 01518 hDma2dHandler.LayerCfg[1].InputColorMode = ColorMode; 01519 hDma2dHandler.LayerCfg[1].InputOffset = 0; 01520 01521 hDma2dHandler.Instance = DMA2D; 01522 01523 /* DMA2D Initialization */ 01524 if(HAL_DMA2D_Init(&hDma2dHandler) == HAL_OK) 01525 { 01526 if(HAL_DMA2D_ConfigLayer(&hDma2dHandler, 1) == HAL_OK) 01527 { 01528 if (HAL_DMA2D_Start(&hDma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK) 01529 { 01530 /* Polling For DMA transfer */ 01531 HAL_DMA2D_PollForTransfer(&hDma2dHandler, 10); 01532 } 01533 } 01534 } 01535 } 01536 01537 /** 01538 * @} 01539 */ 01540 01541 /** 01542 * @} 01543 */ 01544 01545 /** 01546 * @} 01547 */ 01548 01549 /** 01550 * @} 01551 */ 01552 01553 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 18:43:04 by 1.7.2