Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO-F469NI_BD_SD_Card_Control
stm32469i_discovery_lcd.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32469i_discovery_lcd.c 00004 * @author MCD Application Team 00005 * @brief This file includes the driver for Liquid Crystal Display (LCD) module 00006 * mounted on STM32469I-Discovery evaluation board. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 /* File Info: ------------------------------------------------------------------ 00038 User NOTES 00039 1. How To use this driver: 00040 -------------------------- 00041 - This driver is used to drive directly in video mode a LCD TFT using the DSI interface. 00042 The following IPs are implied : DSI Host IP block working 00043 in conjunction to the LTDC controller. 00044 - This driver is linked by construction to LCD KoD mounted on board MB1166. 00045 00046 2. Driver description: 00047 --------------------- 00048 + Initialization steps: 00049 o Initialize the LCD using the BSP_LCD_Init() function. 00050 o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function. 00051 o Enable the LCD display using the BSP_LCD_DisplayOn() function. 00052 00053 + Options 00054 o Configure and enable the color keying functionality using the 00055 BSP_LCD_SetColorKeying() function. 00056 o Modify in the fly the transparency and/or the frame buffer address 00057 using the following functions: 00058 - BSP_LCD_SetTransparency() 00059 - BSP_LCD_SetLayerAddress() 00060 00061 + Display on LCD 00062 o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string 00063 line using the BSP_LCD_ClearStringLine() function. 00064 o Display a character on the specified line and column using the BSP_LCD_DisplayChar() 00065 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function. 00066 o Display a string line on the specified position (x,y in pixel) and align mode 00067 using the BSP_LCD_DisplayStringAtLine() function. 00068 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap) 00069 on LCD using the available set of functions. 00070 00071 ------------------------------------------------------------------------------*/ 00072 00073 /* Includes ------------------------------------------------------------------*/ 00074 #include "stm32469i_discovery_lcd.h" 00075 #include "../Fonts/fonts.h" 00076 //#include "../../../Utilities/Fonts/font24.c" 00077 //#include "../../../Utilities/Fonts/font20.c" 00078 //#include "../../../Utilities/Fonts/font16.c" 00079 //#include "../../../Utilities/Fonts/font12.c" 00080 //#include "../../../Utilities/Fonts/font8.c" 00081 00082 /** @addtogroup BSP 00083 * @{ 00084 */ 00085 00086 /** @addtogroup STM32469I_Discovery 00087 * @{ 00088 */ 00089 00090 /** @defgroup STM32469I-Discovery_LCD STM32469I Discovery LCD 00091 * @{ 00092 */ 00093 00094 /** @defgroup STM32469I-Discovery_LCD_Private_TypesDefinitions STM32469I Discovery LCD Private TypesDefinitions 00095 * @{ 00096 */ 00097 static DSI_VidCfgTypeDef hdsivideo_handle; 00098 00099 /** 00100 * @} 00101 */ 00102 00103 /** @defgroup STM32469I-Discovery_LCD_Private_Defines STM32469I Discovery LCD Private Defines 00104 * @{ 00105 */ 00106 /** 00107 * @} 00108 */ 00109 00110 /** @defgroup STM32469I-Discovery_LCD_Private_Macros STM32469I Discovery LCD Private Macros 00111 * @{ 00112 */ 00113 #define ABS(X) ((X) > 0 ? (X) : -(X)) 00114 00115 #define POLY_X(Z) ((int32_t)((Points + (Z))->X)) 00116 #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y)) 00117 /** 00118 * @} 00119 */ 00120 00121 /** @defgroup STM32469I-Discovery_LCD_Exported_Variables STM32469I Discovery LCD Exported Variables 00122 * @{ 00123 */ 00124 00125 /** 00126 * @} 00127 */ 00128 00129 00130 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables 00131 * @{ 00132 */ 00133 00134 DMA2D_HandleTypeDef hdma2d_eval; 00135 LTDC_HandleTypeDef hltdc_eval; 00136 DSI_HandleTypeDef hdsi_eval; 00137 uint32_t lcd_x_size = OTM8009A_800X480_WIDTH; 00138 uint32_t lcd_y_size = OTM8009A_800X480_HEIGHT; 00139 00140 /** 00141 * @} 00142 */ 00143 00144 00145 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables 00146 * @{ 00147 */ 00148 00149 /** 00150 * @brief Default Active LTDC Layer in which drawing is made is LTDC Layer Background 00151 */ 00152 static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND; 00153 00154 /** 00155 * @brief Current Drawing Layer properties variable 00156 */ 00157 static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER]; 00158 /** 00159 * @} 00160 */ 00161 00162 /** @defgroup STM32469I-Discovery_LCD_Private_FunctionPrototypes STM32469I Discovery LCD Private FunctionPrototypes 00163 * @{ 00164 */ 00165 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c); 00166 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3); 00167 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex); 00168 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode); 00169 /** 00170 * @} 00171 */ 00172 00173 /** @defgroup STM32469I-Discovery_LCD_Exported_Functions STM32469I Discovery LCD Exported Functions 00174 * @{ 00175 */ 00176 00177 /** 00178 * @brief Initializes the DSI LCD. 00179 * @retval LCD state 00180 */ 00181 uint8_t BSP_LCD_Init(void) 00182 { 00183 return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE)); 00184 } 00185 00186 /** 00187 * @brief Initializes the DSI LCD. 00188 * The ititialization is done as below: 00189 * - DSI PLL ititialization 00190 * - DSI ititialization 00191 * - LTDC ititialization 00192 * - OTM8009A LCD Display IC Driver ititialization 00193 * @retval LCD state 00194 */ 00195 uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation) 00196 { 00197 DSI_PLLInitTypeDef dsiPllInit; 00198 DSI_PHY_TimerTypeDef PhyTimings; 00199 static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; 00200 uint32_t LcdClock = 27429; /*!< LcdClk = 27429 kHz */ 00201 00202 uint32_t laneByteClk_kHz = 0; 00203 uint32_t VSA; /*!< Vertical start active time in units of lines */ 00204 uint32_t VBP; /*!< Vertical Back Porch time in units of lines */ 00205 uint32_t VFP; /*!< Vertical Front Porch time in units of lines */ 00206 uint32_t VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */ 00207 uint32_t HSA; /*!< Horizontal start active time in units of lcdClk */ 00208 uint32_t HBP; /*!< Horizontal Back Porch time in units of lcdClk */ 00209 uint32_t HFP; /*!< Horizontal Front Porch time in units of lcdClk */ 00210 uint32_t HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */ 00211 00212 00213 /* Toggle Hardware Reset of the DSI LCD using 00214 * its XRES signal (active low) */ 00215 BSP_LCD_Reset(); 00216 00217 /* Call first MSP Initialize only in case of first initialization 00218 * This will set IP blocks LTDC, DSI and DMA2D 00219 * - out of reset 00220 * - clocked 00221 * - NVIC IRQ related to IP blocks enabled 00222 */ 00223 BSP_LCD_MspInit(); 00224 00225 /*************************DSI Initialization***********************************/ 00226 00227 /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */ 00228 hdsi_eval.Instance = DSI; 00229 00230 HAL_DSI_DeInit(&(hdsi_eval)); 00231 00232 #if !defined(USE_STM32469I_DISCO_REVA) 00233 dsiPllInit.PLLNDIV = 125; 00234 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV2; 00235 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; 00236 #else 00237 dsiPllInit.PLLNDIV = 100; 00238 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5; 00239 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1; 00240 #endif 00241 laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */ 00242 00243 /* Set number of Lanes */ 00244 hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES; 00245 00246 /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */ 00247 hdsi_eval.Init.TXEscapeCkdiv = laneByteClk_kHz/15620; 00248 00249 HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit)); 00250 00251 /* Timing parameters for all Video modes 00252 * Set Timing parameters of LTDC depending on its chosen orientation 00253 */ 00254 if(orientation == LCD_ORIENTATION_PORTRAIT) 00255 { 00256 lcd_x_size = OTM8009A_480X800_WIDTH; /* 480 */ 00257 lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */ 00258 } 00259 else 00260 { 00261 /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */ 00262 lcd_x_size = OTM8009A_800X480_WIDTH; /* 800 */ 00263 lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */ 00264 } 00265 00266 HACT = lcd_x_size; 00267 VACT = lcd_y_size; 00268 00269 /* The following values are same for portrait and landscape orientations */ 00270 VSA = OTM8009A_480X800_VSYNC; 00271 VBP = OTM8009A_480X800_VBP; 00272 VFP = OTM8009A_480X800_VFP; 00273 HSA = OTM8009A_480X800_HSYNC; 00274 HBP = OTM8009A_480X800_HBP; 00275 HFP = OTM8009A_480X800_HFP; 00276 00277 00278 hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID; 00279 hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888; 00280 hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH; 00281 hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH; 00282 hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH; 00283 hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */ 00284 hdsivideo_handle.NullPacketSize = 0xFFF; 00285 hdsivideo_handle.NumberOfChunks = 0; 00286 hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */ 00287 hdsivideo_handle.HorizontalSyncActive = (HSA * laneByteClk_kHz) / LcdClock; 00288 hdsivideo_handle.HorizontalBackPorch = (HBP * laneByteClk_kHz) / LcdClock; 00289 hdsivideo_handle.HorizontalLine = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz) / LcdClock; /* Value depending on display orientation choice portrait/landscape */ 00290 hdsivideo_handle.VerticalSyncActive = VSA; 00291 hdsivideo_handle.VerticalBackPorch = VBP; 00292 hdsivideo_handle.VerticalFrontPorch = VFP; 00293 hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */ 00294 00295 /* Enable or disable sending LP command while streaming is active in video mode */ 00296 hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */ 00297 00298 /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */ 00299 /* Only useful when sending LP packets is allowed while streaming is active in video mode */ 00300 hdsivideo_handle.LPLargestPacketSize = 16; 00301 00302 /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */ 00303 /* Only useful when sending LP packets is allowed while streaming is active in video mode */ 00304 hdsivideo_handle.LPVACTLargestPacketSize = 0; 00305 00306 00307 /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */ 00308 /* while streaming is active in video mode */ 00309 hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */ 00310 hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */ 00311 hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */ 00312 hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */ 00313 hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */ 00314 hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */ 00315 00316 /* Configure DSI Video mode timings with settings set above */ 00317 HAL_DSI_ConfigVideoMode(&(hdsi_eval), &(hdsivideo_handle)); 00318 00319 /* Configure DSI PHY HS2LP and LP2HS timings */ 00320 PhyTimings.ClockLaneHS2LPTime = 35; 00321 PhyTimings.ClockLaneLP2HSTime = 35; 00322 PhyTimings.DataLaneHS2LPTime = 35; 00323 PhyTimings.DataLaneLP2HSTime = 35; 00324 PhyTimings.DataLaneMaxReadTime = 0; 00325 PhyTimings.StopWaitTime = 10; 00326 HAL_DSI_ConfigPhyTimer(&hdsi_eval, &PhyTimings); 00327 00328 /*************************End DSI Initialization*******************************/ 00329 00330 00331 /************************LTDC Initialization***********************************/ 00332 00333 /* Timing Configuration */ 00334 hltdc_eval.Init.HorizontalSync = (HSA - 1); 00335 hltdc_eval.Init.AccumulatedHBP = (HSA + HBP - 1); 00336 hltdc_eval.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1); 00337 hltdc_eval.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1); 00338 00339 /* Initialize the LCD pixel width and pixel height */ 00340 hltdc_eval.LayerCfg->ImageWidth = lcd_x_size; 00341 hltdc_eval.LayerCfg->ImageHeight = lcd_y_size; 00342 00343 00344 /* LCD clock configuration */ 00345 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ 00346 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz */ 00347 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz */ 00348 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz */ 00349 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; 00350 PeriphClkInitStruct.PLLSAI.PLLSAIN = 384; 00351 PeriphClkInitStruct.PLLSAI.PLLSAIR = 7; 00352 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2; 00353 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); 00354 00355 /* Background value */ 00356 hltdc_eval.Init.Backcolor.Blue = 0; 00357 hltdc_eval.Init.Backcolor.Green = 0; 00358 hltdc_eval.Init.Backcolor.Red = 0; 00359 hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC; 00360 hltdc_eval.Instance = LTDC; 00361 00362 /* Get LTDC Configuration from DSI Configuration */ 00363 HAL_LTDCEx_StructInitFromVideoConfig(&(hltdc_eval), &(hdsivideo_handle)); 00364 00365 /* Initialize the LTDC */ 00366 HAL_LTDC_Init(&hltdc_eval); 00367 00368 /* Enable the DSI host and wrapper after the LTDC initialization 00369 To avoid any synchronization issue, the DSI shall be started after enabling the LTDC */ 00370 HAL_DSI_Start(&(hdsi_eval)); 00371 00372 #if !defined(DATA_IN_ExtSDRAM) 00373 /* Initialize the SDRAM */ 00374 BSP_SDRAM_Init(); 00375 #endif /* DATA_IN_ExtSDRAM */ 00376 00377 /* Initialize the font */ 00378 BSP_LCD_SetFont(&LCD_DEFAULT_FONT); 00379 00380 /************************End LTDC Initialization*******************************/ 00381 00382 00383 /***********************OTM8009A Initialization********************************/ 00384 00385 /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver) 00386 * depending on configuration set in 'hdsivideo_handle'. 00387 */ 00388 OTM8009A_Init(OTM8009A_FORMAT_RGB888, orientation); 00389 00390 /***********************End OTM8009A Initialization****************************/ 00391 00392 return LCD_OK; 00393 } 00394 00395 /** 00396 * @brief BSP LCD Reset 00397 * Hw reset the LCD DSI activating its XRES signal (active low for some time) 00398 * and desactivating it later. 00399 * This signal is only cabled on Discovery Rev B and beyond. 00400 */ 00401 void BSP_LCD_Reset(void) 00402 { 00403 #if !defined(USE_STM32469I_DISCO_REVA) 00404 /* EVAL Rev B and beyond : reset the LCD by activation of XRES (active low) connected to PH7 */ 00405 GPIO_InitTypeDef gpio_init_structure; 00406 00407 __HAL_RCC_GPIOH_CLK_ENABLE(); 00408 00409 /* Configure the GPIO on PH7 */ 00410 gpio_init_structure.Pin = GPIO_PIN_7; 00411 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_OD; 00412 gpio_init_structure.Pull = GPIO_NOPULL; 00413 gpio_init_structure.Speed = GPIO_SPEED_HIGH; 00414 00415 HAL_GPIO_Init(GPIOH, &gpio_init_structure); 00416 00417 /* Activate XRES active low */ 00418 HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_RESET); 00419 00420 //HAL_Delay(20); /* wait 20 ms */ 00421 //wait_ms(20); 00422 00423 thread_sleep_for(20); // Jan 12th, 2021 by K.Arai 00424 00425 /* Desactivate XRES */ 00426 HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_SET); 00427 00428 /* Wait for 10ms after releasing XRES before sending commands */ 00429 //HAL_Delay(10); 00430 //wait_ms(10); 00431 00432 thread_sleep_for(10); // Jan 12th, 2021 by K.Arai 00433 #else 00434 00435 #endif /* USE_STM32469I_DISCO_REVA == 0 */ 00436 } 00437 00438 /** 00439 * @brief Gets the LCD X size. 00440 * @retval Used LCD X size 00441 */ 00442 uint32_t BSP_LCD_GetXSize(void) 00443 { 00444 return (lcd_x_size); 00445 } 00446 00447 /** 00448 * @brief Gets the LCD Y size. 00449 * @retval Used LCD Y size 00450 */ 00451 uint32_t BSP_LCD_GetYSize(void) 00452 { 00453 return (lcd_y_size); 00454 } 00455 00456 /** 00457 * @brief Set the LCD X size. 00458 * @param imageWidthPixels : uint32_t image width in pixels unit 00459 */ 00460 void BSP_LCD_SetXSize(uint32_t imageWidthPixels) 00461 { 00462 hltdc_eval.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels; 00463 } 00464 00465 /** 00466 * @brief Set the LCD Y size. 00467 * @param imageHeightPixels : uint32_t image height in lines unit 00468 */ 00469 void BSP_LCD_SetYSize(uint32_t imageHeightPixels) 00470 { 00471 hltdc_eval.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels; 00472 } 00473 00474 00475 /** 00476 * @brief Initializes the LCD layers. 00477 * @param LayerIndex: Layer foreground or background 00478 * @param FB_Address: Layer frame buffer 00479 */ 00480 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address) 00481 { 00482 LCD_LayerCfgTypeDef Layercfg; 00483 00484 /* Layer Init */ 00485 Layercfg.WindowX0 = 0; 00486 Layercfg.WindowX1 = BSP_LCD_GetXSize(); 00487 Layercfg.WindowY0 = 0; 00488 Layercfg.WindowY1 = BSP_LCD_GetYSize(); 00489 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888; 00490 Layercfg.FBStartAdress = FB_Address; 00491 Layercfg.Alpha = 255; 00492 Layercfg.Alpha0 = 0; 00493 Layercfg.Backcolor.Blue = 0; 00494 Layercfg.Backcolor.Green = 0; 00495 Layercfg.Backcolor.Red = 0; 00496 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; 00497 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; 00498 Layercfg.ImageWidth = BSP_LCD_GetXSize(); 00499 Layercfg.ImageHeight = BSP_LCD_GetYSize(); 00500 00501 HAL_LTDC_ConfigLayer(&hltdc_eval, &Layercfg, LayerIndex); 00502 00503 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE; 00504 DrawProp[LayerIndex].pFont = &Font24; 00505 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK; 00506 } 00507 00508 00509 /** 00510 * @brief Selects the LCD Layer. 00511 * @param LayerIndex: Layer foreground or background 00512 */ 00513 void BSP_LCD_SelectLayer(uint32_t LayerIndex) 00514 { 00515 ActiveLayer = LayerIndex; 00516 } 00517 00518 /** 00519 * @brief Sets an LCD Layer visible 00520 * @param LayerIndex: Visible Layer 00521 * @param State: New state of the specified layer 00522 * This parameter can be one of the following values: 00523 * @arg ENABLE 00524 * @arg DISABLE 00525 */ 00526 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State) 00527 { 00528 if(State == ENABLE) 00529 { 00530 __HAL_LTDC_LAYER_ENABLE(&(hltdc_eval), LayerIndex); 00531 } 00532 else 00533 { 00534 __HAL_LTDC_LAYER_DISABLE(&(hltdc_eval), LayerIndex); 00535 } 00536 __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(&(hltdc_eval)); 00537 00538 } 00539 00540 /** 00541 * @brief Configures the transparency. 00542 * @param LayerIndex: Layer foreground or background. 00543 * @param Transparency: Transparency 00544 * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF 00545 */ 00546 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency) 00547 { 00548 00549 HAL_LTDC_SetAlpha(&(hltdc_eval), Transparency, LayerIndex); 00550 00551 } 00552 00553 /** 00554 * @brief Sets an LCD layer frame buffer address. 00555 * @param LayerIndex: Layer foreground or background 00556 * @param Address: New LCD frame buffer value 00557 */ 00558 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address) 00559 { 00560 00561 HAL_LTDC_SetAddress(&(hltdc_eval), Address, LayerIndex); 00562 00563 } 00564 00565 /** 00566 * @brief Sets display window. 00567 * @param LayerIndex: Layer index 00568 * @param Xpos: LCD X position 00569 * @param Ypos: LCD Y position 00570 * @param Width: LCD window width 00571 * @param Height: LCD window height 00572 */ 00573 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00574 { 00575 /* Reconfigure the layer size */ 00576 HAL_LTDC_SetWindowSize(&(hltdc_eval), Width, Height, LayerIndex); 00577 00578 /* Reconfigure the layer position */ 00579 HAL_LTDC_SetWindowPosition(&(hltdc_eval), Xpos, Ypos, LayerIndex); 00580 00581 } 00582 00583 /** 00584 * @brief Configures and sets the color keying. 00585 * @param LayerIndex: Layer foreground or background 00586 * @param RGBValue: Color reference 00587 */ 00588 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue) 00589 { 00590 /* Configure and Enable the color Keying for LCD Layer */ 00591 HAL_LTDC_ConfigColorKeying(&(hltdc_eval), RGBValue, LayerIndex); 00592 HAL_LTDC_EnableColorKeying(&(hltdc_eval), LayerIndex); 00593 } 00594 00595 /** 00596 * @brief Disables the color keying. 00597 * @param LayerIndex: Layer foreground or background 00598 */ 00599 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex) 00600 { 00601 /* Disable the color Keying for LCD Layer */ 00602 HAL_LTDC_DisableColorKeying(&(hltdc_eval), LayerIndex); 00603 } 00604 00605 /** 00606 * @brief Sets the LCD text color. 00607 * @param Color: Text color code ARGB(8-8-8-8) 00608 */ 00609 void BSP_LCD_SetTextColor(uint32_t Color) 00610 { 00611 DrawProp[ActiveLayer].TextColor = Color; 00612 } 00613 00614 /** 00615 * @brief Gets the LCD text color. 00616 * @retval Used text color. 00617 */ 00618 uint32_t BSP_LCD_GetTextColor(void) 00619 { 00620 return DrawProp[ActiveLayer].TextColor; 00621 } 00622 00623 /** 00624 * @brief Sets the LCD background color. 00625 * @param Color: Layer background color code ARGB(8-8-8-8) 00626 */ 00627 void BSP_LCD_SetBackColor(uint32_t Color) 00628 { 00629 DrawProp[ActiveLayer].BackColor = Color; 00630 } 00631 00632 /** 00633 * @brief Gets the LCD background color. 00634 * @retval Used background color 00635 */ 00636 uint32_t BSP_LCD_GetBackColor(void) 00637 { 00638 return DrawProp[ActiveLayer].BackColor; 00639 } 00640 00641 /** 00642 * @brief Sets the LCD text font. 00643 * @param fonts: Layer font to be used 00644 */ 00645 void BSP_LCD_SetFont(sFONT *fonts) 00646 { 00647 DrawProp[ActiveLayer].pFont = fonts; 00648 } 00649 00650 /** 00651 * @brief Gets the LCD text font. 00652 * @retval Used layer font 00653 */ 00654 sFONT *BSP_LCD_GetFont(void) 00655 { 00656 return DrawProp[ActiveLayer].pFont; 00657 } 00658 00659 /** 00660 * @brief Reads an LCD pixel. 00661 * @param Xpos: X position 00662 * @param Ypos: Y position 00663 * @retval RGB pixel color 00664 */ 00665 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos) 00666 { 00667 uint32_t ret = 0; 00668 00669 if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888) 00670 { 00671 /* Read data value from SDRAM memory */ 00672 ret = *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))); 00673 } 00674 else if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888) 00675 { 00676 /* Read data value from SDRAM memory */ 00677 ret = (*(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF); 00678 } 00679 else if((hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \ 00680 (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \ 00681 (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88)) 00682 { 00683 /* Read data value from SDRAM memory */ 00684 ret = *(__IO uint16_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); 00685 } 00686 else 00687 { 00688 /* Read data value from SDRAM memory */ 00689 ret = *(__IO uint8_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); 00690 } 00691 00692 return ret; 00693 } 00694 00695 /** 00696 * @brief Clears the whole currently active layer of LTDC. 00697 * @param Color: Color of the background 00698 */ 00699 void BSP_LCD_Clear(uint32_t Color) 00700 { 00701 /* Clear the LCD */ 00702 LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color); 00703 } 00704 00705 /** 00706 * @brief Clears the selected line in currently active layer. 00707 * @param Line: Line to be cleared 00708 */ 00709 void BSP_LCD_ClearStringLine(uint32_t Line) 00710 { 00711 uint32_t color_backup = DrawProp[ActiveLayer].TextColor; 00712 DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor; 00713 00714 /* Draw rectangle with background color */ 00715 BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height); 00716 00717 DrawProp[ActiveLayer].TextColor = color_backup; 00718 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 00719 } 00720 00721 /** 00722 * @brief Displays one character in currently active layer. 00723 * @param Xpos: Start column address 00724 * @param Ypos: Line where to display the character shape. 00725 * @param Ascii: Character ascii code 00726 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E 00727 */ 00728 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) 00729 { 00730 DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\ 00731 DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]); 00732 } 00733 00734 /** 00735 * @brief Displays characters in currently active layer. 00736 * @param Xpos: X position (in pixel) 00737 * @param Ypos: Y position (in pixel) 00738 * @param Text: Pointer to string to display on LCD 00739 * @param Mode: Display mode 00740 * This parameter can be one of the following values: 00741 * @arg CENTER_MODE 00742 * @arg RIGHT_MODE 00743 * @arg LEFT_MODE 00744 */ 00745 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode) 00746 { 00747 uint16_t refcolumn = 1, i = 0; 00748 uint32_t size = 0, xsize = 0; 00749 uint8_t *ptr = Text; 00750 00751 /* Get the text size */ 00752 while (*ptr++) size ++ ; 00753 00754 /* Characters number per line */ 00755 xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width); 00756 00757 switch (Mode) 00758 { 00759 case CENTER_MODE: 00760 { 00761 refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2; 00762 break; 00763 } 00764 case LEFT_MODE: 00765 { 00766 refcolumn = Xpos; 00767 break; 00768 } 00769 case RIGHT_MODE: 00770 { 00771 refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width); 00772 break; 00773 } 00774 default: 00775 { 00776 refcolumn = Xpos; 00777 break; 00778 } 00779 } 00780 00781 /* Check that the Start column is located in the screen */ 00782 if ((refcolumn < 1) || (refcolumn >= 0x8000)) 00783 { 00784 refcolumn = 1; 00785 } 00786 00787 /* Send the string character by character on LCD */ 00788 while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width)) 00789 { 00790 /* Display one character on LCD */ 00791 BSP_LCD_DisplayChar(refcolumn, Ypos, *Text); 00792 /* Decrement the column position by 16 */ 00793 refcolumn += DrawProp[ActiveLayer].pFont->Width; 00794 00795 /* Point on the next character */ 00796 Text++; 00797 i++; 00798 } 00799 00800 } 00801 00802 /** 00803 * @brief Displays a maximum of 60 characters on the LCD. 00804 * @param Line: Line where to display the character shape 00805 * @param ptr: Pointer to string to display on LCD 00806 */ 00807 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr) 00808 { 00809 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE); 00810 } 00811 00812 /** 00813 * @brief Draws an horizontal line in currently active layer. 00814 * @param Xpos: X position 00815 * @param Ypos: Y position 00816 * @param Length: Line length 00817 */ 00818 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00819 { 00820 uint32_t Xaddress = 0; 00821 00822 /* Get the line address */ 00823 Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); 00824 00825 /* Write line */ 00826 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor); 00827 } 00828 00829 /** 00830 * @brief Draws a vertical line in currently active layer. 00831 * @param Xpos: X position 00832 * @param Ypos: Y position 00833 * @param Length: Line length 00834 */ 00835 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00836 { 00837 uint32_t Xaddress = 0; 00838 00839 /* Get the line address */ 00840 Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); 00841 00842 /* Write line */ 00843 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor); 00844 } 00845 00846 /** 00847 * @brief Draws an uni-line (between two points) in currently active layer. 00848 * @param x1: Point 1 X position 00849 * @param y1: Point 1 Y position 00850 * @param x2: Point 2 X position 00851 * @param y2: Point 2 Y position 00852 */ 00853 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) 00854 { 00855 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 00856 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 00857 curpixel = 0; 00858 00859 deltax = ABS(x2 - x1); /* The difference between the x's */ 00860 deltay = ABS(y2 - y1); /* The difference between the y's */ 00861 x = x1; /* Start x off at the first pixel */ 00862 y = y1; /* Start y off at the first pixel */ 00863 00864 if (x2 >= x1) /* The x-values are increasing */ 00865 { 00866 xinc1 = 1; 00867 xinc2 = 1; 00868 } 00869 else /* The x-values are decreasing */ 00870 { 00871 xinc1 = -1; 00872 xinc2 = -1; 00873 } 00874 00875 if (y2 >= y1) /* The y-values are increasing */ 00876 { 00877 yinc1 = 1; 00878 yinc2 = 1; 00879 } 00880 else /* The y-values are decreasing */ 00881 { 00882 yinc1 = -1; 00883 yinc2 = -1; 00884 } 00885 00886 if (deltax >= deltay) /* There is at least one x-value for every y-value */ 00887 { 00888 xinc1 = 0; /* Don't change the x when numerator >= denominator */ 00889 yinc2 = 0; /* Don't change the y for every iteration */ 00890 den = deltax; 00891 num = deltax / 2; 00892 numadd = deltay; 00893 numpixels = deltax; /* There are more x-values than y-values */ 00894 } 00895 else /* There is at least one y-value for every x-value */ 00896 { 00897 xinc2 = 0; /* Don't change the x for every iteration */ 00898 yinc1 = 0; /* Don't change the y when numerator >= denominator */ 00899 den = deltay; 00900 num = deltay / 2; 00901 numadd = deltax; 00902 numpixels = deltay; /* There are more y-values than x-values */ 00903 } 00904 00905 for (curpixel = 0; curpixel <= numpixels; curpixel++) 00906 { 00907 BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */ 00908 num += numadd; /* Increase the numerator by the top of the fraction */ 00909 if (num >= den) /* Check if numerator >= denominator */ 00910 { 00911 num -= den; /* Calculate the new numerator value */ 00912 x += xinc1; /* Change the x as appropriate */ 00913 y += yinc1; /* Change the y as appropriate */ 00914 } 00915 x += xinc2; /* Change the x as appropriate */ 00916 y += yinc2; /* Change the y as appropriate */ 00917 } 00918 } 00919 00920 /** 00921 * @brief Draws a rectangle in currently active layer. 00922 * @param Xpos: X position 00923 * @param Ypos: Y position 00924 * @param Width: Rectangle width 00925 * @param Height: Rectangle height 00926 */ 00927 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00928 { 00929 /* Draw horizontal lines */ 00930 BSP_LCD_DrawHLine(Xpos, Ypos, Width); 00931 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width); 00932 00933 /* Draw vertical lines */ 00934 BSP_LCD_DrawVLine(Xpos, Ypos, Height); 00935 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height); 00936 } 00937 00938 /** 00939 * @brief Draws a circle in currently active layer. 00940 * @param Xpos: X position 00941 * @param Ypos: Y position 00942 * @param Radius: Circle radius 00943 */ 00944 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 00945 { 00946 int32_t D; /* Decision Variable */ 00947 uint32_t CurX; /* Current X Value */ 00948 uint32_t CurY; /* Current Y Value */ 00949 00950 D = 3 - (Radius << 1); 00951 CurX = 0; 00952 CurY = Radius; 00953 00954 while (CurX <= CurY) 00955 { 00956 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor); 00957 00958 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor); 00959 00960 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor); 00961 00962 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor); 00963 00964 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor); 00965 00966 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor); 00967 00968 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor); 00969 00970 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor); 00971 00972 if (D < 0) 00973 { 00974 D += (CurX << 2) + 6; 00975 } 00976 else 00977 { 00978 D += ((CurX - CurY) << 2) + 10; 00979 CurY--; 00980 } 00981 CurX++; 00982 } 00983 } 00984 00985 /** 00986 * @brief Draws an poly-line (between many points) in currently active layer. 00987 * @param Points: Pointer to the points array 00988 * @param PointCount: Number of points 00989 */ 00990 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount) 00991 { 00992 int16_t X = 0, Y = 0; 00993 00994 if(PointCount < 2) 00995 { 00996 return; 00997 } 00998 00999 BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); 01000 01001 while(--PointCount) 01002 { 01003 X = Points->X; 01004 Y = Points->Y; 01005 Points++; 01006 BSP_LCD_DrawLine(X, Y, Points->X, Points->Y); 01007 } 01008 } 01009 01010 /** 01011 * @brief Draws an ellipse on LCD in currently active layer. 01012 * @param Xpos: X position 01013 * @param Ypos: Y position 01014 * @param XRadius: Ellipse X radius 01015 * @param YRadius: Ellipse Y radius 01016 */ 01017 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 01018 { 01019 int x = 0, y = -YRadius, err = 2-2*XRadius, e2; 01020 float K = 0, rad1 = 0, rad2 = 0; 01021 01022 rad1 = XRadius; 01023 rad2 = YRadius; 01024 01025 K = (float)(rad2/rad1); 01026 01027 do { 01028 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor); 01029 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor); 01030 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor); 01031 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor); 01032 01033 e2 = err; 01034 if (e2 <= x) { 01035 err += ++x*2+1; 01036 if (-y == x && e2 <= y) e2 = 0; 01037 } 01038 if (e2 > y) err += ++y*2+1; 01039 } 01040 while (y <= 0); 01041 } 01042 01043 /** 01044 * @brief Draws a bitmap picture loaded in the internal Flash (32 bpp) in currently active layer. 01045 * @param Xpos: Bmp X position in the LCD 01046 * @param Ypos: Bmp Y position in the LCD 01047 * @param pbmp: Pointer to Bmp picture address in the internal Flash 01048 */ 01049 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp) 01050 { 01051 uint32_t index = 0, width = 0, height = 0, bit_pixel = 0; 01052 uint32_t Address; 01053 uint32_t InputColorMode = 0; 01054 01055 /* Get bitmap data address offset */ 01056 index = pbmp[10] + (pbmp[11] << 8) + (pbmp[12] << 16) + (pbmp[13] << 24); 01057 01058 /* Read bitmap width */ 01059 width = pbmp[18] + (pbmp[19] << 8) + (pbmp[20] << 16) + (pbmp[21] << 24); 01060 01061 /* Read bitmap height */ 01062 height = pbmp[22] + (pbmp[23] << 8) + (pbmp[24] << 16) + (pbmp[25] << 24); 01063 01064 /* Read bit/pixel */ 01065 bit_pixel = pbmp[28] + (pbmp[29] << 8); 01066 01067 /* Set the address */ 01068 Address = hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4)); 01069 01070 /* Get the layer pixel format */ 01071 if ((bit_pixel/8) == 4) 01072 { 01073 InputColorMode = CM_ARGB8888; 01074 } 01075 else if ((bit_pixel/8) == 2) 01076 { 01077 InputColorMode = CM_RGB565; 01078 } 01079 else 01080 { 01081 InputColorMode = CM_RGB888; 01082 } 01083 01084 /* Bypass the bitmap header */ 01085 pbmp += (index + (width * (height - 1) * (bit_pixel/8))); 01086 01087 /* Convert picture to ARGB8888 pixel format */ 01088 for(index=0; index < height; index++) 01089 { 01090 /* Pixel format conversion */ 01091 LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode); 01092 01093 /* Increment the source and destination buffers */ 01094 Address+= (BSP_LCD_GetXSize()*4); 01095 pbmp -= width*(bit_pixel/8); 01096 } 01097 } 01098 01099 /** 01100 * @brief Draws a full rectangle in currently active layer. 01101 * @param Xpos: X position 01102 * @param Ypos: Y position 01103 * @param Width: Rectangle width 01104 * @param Height: Rectangle height 01105 */ 01106 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 01107 { 01108 uint32_t Xaddress = 0; 01109 01110 /* Set the text color */ 01111 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 01112 01113 /* Get the rectangle start address */ 01114 Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); 01115 01116 /* Fill the rectangle */ 01117 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor); 01118 } 01119 01120 /** 01121 * @brief Draws a full circle in currently active layer. 01122 * @param Xpos: X position 01123 * @param Ypos: Y position 01124 * @param Radius: Circle radius 01125 */ 01126 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) 01127 { 01128 int32_t D; /* Decision Variable */ 01129 uint32_t CurX; /* Current X Value */ 01130 uint32_t CurY; /* Current Y Value */ 01131 01132 D = 3 - (Radius << 1); 01133 01134 CurX = 0; 01135 CurY = Radius; 01136 01137 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 01138 01139 while (CurX <= CurY) 01140 { 01141 if(CurY > 0) 01142 { 01143 BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY); 01144 BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY); 01145 } 01146 01147 if(CurX > 0) 01148 { 01149 BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX); 01150 BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX); 01151 } 01152 if (D < 0) 01153 { 01154 D += (CurX << 2) + 6; 01155 } 01156 else 01157 { 01158 D += ((CurX - CurY) << 2) + 10; 01159 CurY--; 01160 } 01161 CurX++; 01162 } 01163 01164 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); 01165 BSP_LCD_DrawCircle(Xpos, Ypos, Radius); 01166 } 01167 01168 /** 01169 * @brief Draws a full poly-line (between many points) in currently active layer. 01170 * @param Points: Pointer to the points array 01171 * @param PointCount: Number of points 01172 */ 01173 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) 01174 { 01175 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; 01176 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0; 01177 01178 IMAGE_LEFT = IMAGE_RIGHT = Points->X; 01179 IMAGE_TOP= IMAGE_BOTTOM = Points->Y; 01180 01181 for(counter = 1; counter < PointCount; counter++) 01182 { 01183 pixelX = POLY_X(counter); 01184 if(pixelX < IMAGE_LEFT) 01185 { 01186 IMAGE_LEFT = pixelX; 01187 } 01188 if(pixelX > IMAGE_RIGHT) 01189 { 01190 IMAGE_RIGHT = pixelX; 01191 } 01192 01193 pixelY = POLY_Y(counter); 01194 if(pixelY < IMAGE_TOP) 01195 { 01196 IMAGE_TOP = pixelY; 01197 } 01198 if(pixelY > IMAGE_BOTTOM) 01199 { 01200 IMAGE_BOTTOM = pixelY; 01201 } 01202 } 01203 01204 if(PointCount < 2) 01205 { 01206 return; 01207 } 01208 01209 X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2; 01210 Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2; 01211 01212 X_first = Points->X; 01213 Y_first = Points->Y; 01214 01215 while(--PointCount) 01216 { 01217 X = Points->X; 01218 Y = Points->Y; 01219 Points++; 01220 X2 = Points->X; 01221 Y2 = Points->Y; 01222 01223 FillTriangle(X, X2, X_center, Y, Y2, Y_center); 01224 FillTriangle(X, X_center, X2, Y, Y_center, Y2); 01225 FillTriangle(X_center, X2, X, Y_center, Y2, Y); 01226 } 01227 01228 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); 01229 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); 01230 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); 01231 } 01232 01233 /** 01234 * @brief Draws a full ellipse in currently active layer. 01235 * @param Xpos: X position 01236 * @param Ypos: Y position 01237 * @param XRadius: Ellipse X radius 01238 * @param YRadius: Ellipse Y radius 01239 */ 01240 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) 01241 { 01242 int x = 0, y = -YRadius, err = 2-2*XRadius, e2; 01243 float K = 0, rad1 = 0, rad2 = 0; 01244 01245 rad1 = XRadius; 01246 rad2 = YRadius; 01247 01248 K = (float)(rad2/rad1); 01249 01250 do 01251 { 01252 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1)); 01253 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1)); 01254 01255 e2 = err; 01256 if (e2 <= x) 01257 { 01258 err += ++x*2+1; 01259 if (-y == x && e2 <= y) e2 = 0; 01260 } 01261 if (e2 > y) err += ++y*2+1; 01262 } 01263 while (y <= 0); 01264 } 01265 01266 /** 01267 * @brief Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff(). 01268 * Exit DSI ULPM mode if was allowed and configured in Dsi Configuration. 01269 */ 01270 void BSP_LCD_DisplayOn(void) 01271 { 01272 /* Send Display on DCS command to display */ 01273 HAL_DSI_ShortWrite(&(hdsi_eval), 01274 hdsivideo_handle.VirtualChannelID, 01275 DSI_DCS_SHORT_PKT_WRITE_P1, 01276 OTM8009A_CMD_DISPON, 01277 0x00); 01278 01279 } 01280 01281 /** 01282 * @brief Switch Off the display. 01283 * Enter DSI ULPM mode if was allowed and configured in Dsi Configuration. 01284 */ 01285 void BSP_LCD_DisplayOff(void) 01286 { 01287 /* Send Display off DCS Command to display */ 01288 HAL_DSI_ShortWrite(&(hdsi_eval), 01289 hdsivideo_handle.VirtualChannelID, 01290 DSI_DCS_SHORT_PKT_WRITE_P1, 01291 OTM8009A_CMD_DISPOFF, 01292 0x00); 01293 01294 } 01295 01296 /** 01297 * @brief DCS or Generic short/long write command 01298 * @param NbrParams: Number of parameters. It indicates the write command mode: 01299 * If inferior to 2, a long write command is performed else short. 01300 * @param pParams: Pointer to parameter values table. 01301 * @retval HAL status 01302 */ 01303 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams) 01304 { 01305 if(NbrParams <= 1) 01306 { 01307 HAL_DSI_ShortWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]); 01308 } 01309 else 01310 { 01311 HAL_DSI_LongWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams); 01312 } 01313 } 01314 01315 /******************************************************************************* 01316 LTDC, DMA2D and DSI BSP Routines 01317 *******************************************************************************/ 01318 /** 01319 * @brief Handles DMA2D interrupt request. 01320 * @note : Can be surcharged by application code implementation of the function. 01321 */ 01322 __weak void BSP_LCD_DMA2D_IRQHandler(void) 01323 { 01324 HAL_DMA2D_IRQHandler(&hdma2d_eval); 01325 } 01326 01327 /** 01328 * @brief Handles DSI interrupt request. 01329 * @note : Can be surcharged by application code implementation of the function. 01330 */ 01331 __weak void BSP_LCD_DSI_IRQHandler(void) 01332 { 01333 HAL_DSI_IRQHandler(&(hdsi_eval)); 01334 } 01335 01336 01337 /** 01338 * @brief Handles LTDC interrupt request. 01339 * @note : Can be surcharged by application code implementation of the function. 01340 */ 01341 __weak void BSP_LCD_LTDC_IRQHandler(void) 01342 { 01343 HAL_LTDC_IRQHandler(&(hltdc_eval)); 01344 } 01345 01346 /** 01347 * @brief De-Initializes the BSP LCD Msp 01348 * Application can surcharge if needed this function implementation. 01349 */ 01350 __weak void BSP_LCD_MspDeInit(void) 01351 { 01352 /** @brief Disable IRQ of LTDC IP */ 01353 HAL_NVIC_DisableIRQ(LTDC_IRQn); 01354 01355 /** @brief Disable IRQ of DMA2D IP */ 01356 HAL_NVIC_DisableIRQ(DMA2D_IRQn); 01357 01358 /** @brief Disable IRQ of DSI IP */ 01359 HAL_NVIC_DisableIRQ(DSI_IRQn); 01360 01361 /** @brief Force and let in reset state LTDC, DMA2D and DSI Host + Wrapper IPs */ 01362 __HAL_RCC_LTDC_FORCE_RESET(); 01363 __HAL_RCC_DMA2D_FORCE_RESET(); 01364 __HAL_RCC_DSI_FORCE_RESET(); 01365 01366 /** @brief Disable the LTDC, DMA2D and DSI Host and Wrapper clocks */ 01367 __HAL_RCC_LTDC_CLK_DISABLE(); 01368 __HAL_RCC_DMA2D_CLK_DISABLE(); 01369 __HAL_RCC_DSI_CLK_DISABLE(); 01370 } 01371 01372 /** 01373 * @brief Initialize the BSP LCD Msp. 01374 * Application can surcharge if needed this function implementation 01375 */ 01376 __weak void BSP_LCD_MspInit(void) 01377 { 01378 /** @brief Enable the LTDC clock */ 01379 __HAL_RCC_LTDC_CLK_ENABLE(); 01380 01381 /** @brief Toggle Sw reset of LTDC IP */ 01382 __HAL_RCC_LTDC_FORCE_RESET(); 01383 __HAL_RCC_LTDC_RELEASE_RESET(); 01384 01385 /** @brief Enable the DMA2D clock */ 01386 __HAL_RCC_DMA2D_CLK_ENABLE(); 01387 01388 /** @brief Toggle Sw reset of DMA2D IP */ 01389 __HAL_RCC_DMA2D_FORCE_RESET(); 01390 __HAL_RCC_DMA2D_RELEASE_RESET(); 01391 01392 /** @brief Enable DSI Host and wrapper clocks */ 01393 __HAL_RCC_DSI_CLK_ENABLE(); 01394 01395 /** @brief Soft Reset the DSI Host and wrapper */ 01396 __HAL_RCC_DSI_FORCE_RESET(); 01397 __HAL_RCC_DSI_RELEASE_RESET(); 01398 01399 /** @brief NVIC configuration for LTDC interrupt that is now enabled */ 01400 HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0); 01401 HAL_NVIC_EnableIRQ(LTDC_IRQn); 01402 01403 /** @brief NVIC configuration for DMA2D interrupt that is now enabled */ 01404 HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0); 01405 HAL_NVIC_EnableIRQ(DMA2D_IRQn); 01406 01407 /** @brief NVIC configuration for DSI interrupt that is now enabled */ 01408 HAL_NVIC_SetPriority(DSI_IRQn, 3, 0); 01409 HAL_NVIC_EnableIRQ(DSI_IRQn); 01410 } 01411 01412 /** 01413 * @brief This function handles LTDC Error interrupt Handler. 01414 * @note : Can be surcharged by application code implementation of the function. 01415 */ 01416 01417 __weak void BSP_LCD_LTDC_ER_IRQHandler(void) 01418 { 01419 HAL_LTDC_IRQHandler(&(hltdc_eval)); 01420 } 01421 01422 01423 /** 01424 * @brief Draws a pixel on LCD. 01425 * @param Xpos: X position 01426 * @param Ypos: Y position 01427 * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8) 01428 */ 01429 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code) 01430 { 01431 /* Write data value to all SDRAM memory */ 01432 *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code; 01433 } 01434 01435 01436 /** 01437 * @brief Draws a character on LCD. 01438 * @param Xpos: Line where to display the character shape 01439 * @param Ypos: Start column address 01440 * @param c: Pointer to the character data 01441 */ 01442 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c) 01443 { 01444 uint32_t i = 0, j = 0; 01445 uint16_t height, width; 01446 uint8_t offset; 01447 uint8_t *pchar; 01448 uint32_t line; 01449 01450 height = DrawProp[ActiveLayer].pFont->Height; 01451 width = DrawProp[ActiveLayer].pFont->Width; 01452 01453 offset = 8 *((width + 7)/8) - width ; 01454 01455 for(i = 0; i < height; i++) 01456 { 01457 pchar = ((uint8_t *)c + (width + 7)/8 * i); 01458 01459 switch(((width + 7)/8)) 01460 { 01461 01462 case 1: 01463 line = pchar[0]; 01464 break; 01465 01466 case 2: 01467 line = (pchar[0]<< 8) | pchar[1]; 01468 break; 01469 01470 case 3: 01471 default: 01472 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; 01473 break; 01474 } 01475 01476 for (j = 0; j < width; j++) 01477 { 01478 if(line & (1 << (width- j + offset- 1))) 01479 { 01480 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor); 01481 } 01482 else 01483 { 01484 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor); 01485 } 01486 } 01487 Ypos++; 01488 } 01489 } 01490 01491 /** 01492 * @brief Fills a triangle (between 3 points). 01493 * @param x1: Point 1 X position 01494 * @param y1: Point 1 Y position 01495 * @param x2: Point 2 X position 01496 * @param y2: Point 2 Y position 01497 * @param x3: Point 3 X position 01498 * @param y3: Point 3 Y position 01499 */ 01500 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3) 01501 { 01502 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, 01503 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, 01504 curpixel = 0; 01505 01506 deltax = ABS(x2 - x1); /* The difference between the x's */ 01507 deltay = ABS(y2 - y1); /* The difference between the y's */ 01508 x = x1; /* Start x off at the first pixel */ 01509 y = y1; /* Start y off at the first pixel */ 01510 01511 if (x2 >= x1) /* The x-values are increasing */ 01512 { 01513 xinc1 = 1; 01514 xinc2 = 1; 01515 } 01516 else /* The x-values are decreasing */ 01517 { 01518 xinc1 = -1; 01519 xinc2 = -1; 01520 } 01521 01522 if (y2 >= y1) /* The y-values are increasing */ 01523 { 01524 yinc1 = 1; 01525 yinc2 = 1; 01526 } 01527 else /* The y-values are decreasing */ 01528 { 01529 yinc1 = -1; 01530 yinc2 = -1; 01531 } 01532 01533 if (deltax >= deltay) /* There is at least one x-value for every y-value */ 01534 { 01535 xinc1 = 0; /* Don't change the x when numerator >= denominator */ 01536 yinc2 = 0; /* Don't change the y for every iteration */ 01537 den = deltax; 01538 num = deltax / 2; 01539 numadd = deltay; 01540 numpixels = deltax; /* There are more x-values than y-values */ 01541 } 01542 else /* There is at least one y-value for every x-value */ 01543 { 01544 xinc2 = 0; /* Don't change the x for every iteration */ 01545 yinc1 = 0; /* Don't change the y when numerator >= denominator */ 01546 den = deltay; 01547 num = deltay / 2; 01548 numadd = deltax; 01549 numpixels = deltay; /* There are more y-values than x-values */ 01550 } 01551 01552 for (curpixel = 0; curpixel <= numpixels; curpixel++) 01553 { 01554 BSP_LCD_DrawLine(x, y, x3, y3); 01555 01556 num += numadd; /* Increase the numerator by the top of the fraction */ 01557 if (num >= den) /* Check if numerator >= denominator */ 01558 { 01559 num -= den; /* Calculate the new numerator value */ 01560 x += xinc1; /* Change the x as appropriate */ 01561 y += yinc1; /* Change the y as appropriate */ 01562 } 01563 x += xinc2; /* Change the x as appropriate */ 01564 y += yinc2; /* Change the y as appropriate */ 01565 } 01566 } 01567 01568 /** 01569 * @brief Fills a buffer. 01570 * @param LayerIndex: Layer index 01571 * @param pDst: Pointer to destination buffer 01572 * @param xSize: Buffer width 01573 * @param ySize: Buffer height 01574 * @param OffLine: Offset 01575 * @param ColorIndex: Color index 01576 */ 01577 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex) 01578 { 01579 /* Register to memory mode with ARGB8888 as color Mode */ 01580 hdma2d_eval.Init.Mode = DMA2D_R2M; 01581 hdma2d_eval.Init.ColorMode = DMA2D_ARGB8888; 01582 hdma2d_eval.Init.OutputOffset = OffLine; 01583 01584 hdma2d_eval.Instance = DMA2D; 01585 01586 /* DMA2D Initialization */ 01587 if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK) 01588 { 01589 if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, LayerIndex) == HAL_OK) 01590 { 01591 if (HAL_DMA2D_Start(&hdma2d_eval, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK) 01592 { 01593 /* Polling For DMA transfer */ 01594 HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10); 01595 } 01596 } 01597 } 01598 } 01599 01600 /** 01601 * @brief Converts a line to an ARGB8888 pixel format. 01602 * @param pSrc: Pointer to source buffer 01603 * @param pDst: Output color 01604 * @param xSize: Buffer width 01605 * @param ColorMode: Input color mode 01606 */ 01607 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode) 01608 { 01609 /* Configure the DMA2D Mode, Color Mode and output offset */ 01610 hdma2d_eval.Init.Mode = DMA2D_M2M_PFC; 01611 hdma2d_eval.Init.ColorMode = DMA2D_ARGB8888; 01612 hdma2d_eval.Init.OutputOffset = 0; 01613 01614 /* Foreground Configuration */ 01615 hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; 01616 hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF; 01617 hdma2d_eval.LayerCfg[1].InputColorMode = ColorMode; 01618 hdma2d_eval.LayerCfg[1].InputOffset = 0; 01619 01620 hdma2d_eval.Instance = DMA2D; 01621 01622 /* DMA2D Initialization */ 01623 if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK) 01624 { 01625 if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK) 01626 { 01627 if (HAL_DMA2D_Start(&hdma2d_eval, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK) 01628 { 01629 /* Polling For DMA transfer */ 01630 HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10); 01631 } 01632 } 01633 } 01634 } 01635 01636 /** 01637 * @} 01638 */ 01639 01640 /** 01641 * @} 01642 */ 01643 01644 /** 01645 * @} 01646 */ 01647 01648 /** 01649 * @} 01650 */ 01651 01652 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Jul 14 2022 09:38:30 by
1.7.2