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