STM32F469NI Discovery board drivers

Dependents:   DISCO-F469NI_LCDTS_GUI_demo Configurable_Robots DISCO-F469NI_LCD_demo DISCO-F469NI_SD_demo ... more

Committer:
Jerome Coutant
Date:
Tue May 16 10:50:26 2017 +0200
Revision:
2:123b894b49dd
Child:
3:3cdfcc4f7c9d
STM32Cube_FW_BSP_DISCO_F469NI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jerome Coutant 2:123b894b49dd 1 /**
Jerome Coutant 2:123b894b49dd 2 ******************************************************************************
Jerome Coutant 2:123b894b49dd 3 * @file stm32469i_discovery_lcd.c
Jerome Coutant 2:123b894b49dd 4 * @author MCD Application Team
Jerome Coutant 2:123b894b49dd 5 * @version V2.0.0
Jerome Coutant 2:123b894b49dd 6 * @date 27-January-2017
Jerome Coutant 2:123b894b49dd 7 * @brief This file includes the driver for Liquid Crystal Display (LCD) module
Jerome Coutant 2:123b894b49dd 8 * mounted on STM32469I-Discovery evaluation board.
Jerome Coutant 2:123b894b49dd 9 ******************************************************************************
Jerome Coutant 2:123b894b49dd 10 * @attention
Jerome Coutant 2:123b894b49dd 11 *
Jerome Coutant 2:123b894b49dd 12 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
Jerome Coutant 2:123b894b49dd 13 *
Jerome Coutant 2:123b894b49dd 14 * Redistribution and use in source and binary forms, with or without modification,
Jerome Coutant 2:123b894b49dd 15 * are permitted provided that the following conditions are met:
Jerome Coutant 2:123b894b49dd 16 * 1. Redistributions of source code must retain the above copyright notice,
Jerome Coutant 2:123b894b49dd 17 * this list of conditions and the following disclaimer.
Jerome Coutant 2:123b894b49dd 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Jerome Coutant 2:123b894b49dd 19 * this list of conditions and the following disclaimer in the documentation
Jerome Coutant 2:123b894b49dd 20 * and/or other materials provided with the distribution.
Jerome Coutant 2:123b894b49dd 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Jerome Coutant 2:123b894b49dd 22 * may be used to endorse or promote products derived from this software
Jerome Coutant 2:123b894b49dd 23 * without specific prior written permission.
Jerome Coutant 2:123b894b49dd 24 *
Jerome Coutant 2:123b894b49dd 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Jerome Coutant 2:123b894b49dd 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Jerome Coutant 2:123b894b49dd 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jerome Coutant 2:123b894b49dd 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Jerome Coutant 2:123b894b49dd 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Jerome Coutant 2:123b894b49dd 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Jerome Coutant 2:123b894b49dd 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Jerome Coutant 2:123b894b49dd 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Jerome Coutant 2:123b894b49dd 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Jerome Coutant 2:123b894b49dd 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jerome Coutant 2:123b894b49dd 35 *
Jerome Coutant 2:123b894b49dd 36 ******************************************************************************
Jerome Coutant 2:123b894b49dd 37 */
Jerome Coutant 2:123b894b49dd 38
Jerome Coutant 2:123b894b49dd 39 /* File Info: ------------------------------------------------------------------
Jerome Coutant 2:123b894b49dd 40 User NOTES
Jerome Coutant 2:123b894b49dd 41 1. How To use this driver:
Jerome Coutant 2:123b894b49dd 42 --------------------------
Jerome Coutant 2:123b894b49dd 43 - This driver is used to drive directly in video mode a LCD TFT using the DSI interface.
Jerome Coutant 2:123b894b49dd 44 The following IPs are implied : DSI Host IP block working
Jerome Coutant 2:123b894b49dd 45 in conjunction to the LTDC controller.
Jerome Coutant 2:123b894b49dd 46 - This driver is linked by construction to LCD KoD mounted on board MB1166.
Jerome Coutant 2:123b894b49dd 47
Jerome Coutant 2:123b894b49dd 48 2. Driver description:
Jerome Coutant 2:123b894b49dd 49 ---------------------
Jerome Coutant 2:123b894b49dd 50 + Initialization steps:
Jerome Coutant 2:123b894b49dd 51 o Initialize the LCD using the BSP_LCD_Init() function.
Jerome Coutant 2:123b894b49dd 52 o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
Jerome Coutant 2:123b894b49dd 53 o Enable the LCD display using the BSP_LCD_DisplayOn() function.
Jerome Coutant 2:123b894b49dd 54
Jerome Coutant 2:123b894b49dd 55 + Options
Jerome Coutant 2:123b894b49dd 56 o Configure and enable the color keying functionality using the
Jerome Coutant 2:123b894b49dd 57 BSP_LCD_SetColorKeying() function.
Jerome Coutant 2:123b894b49dd 58 o Modify in the fly the transparency and/or the frame buffer address
Jerome Coutant 2:123b894b49dd 59 using the following functions:
Jerome Coutant 2:123b894b49dd 60 - BSP_LCD_SetTransparency()
Jerome Coutant 2:123b894b49dd 61 - BSP_LCD_SetLayerAddress()
Jerome Coutant 2:123b894b49dd 62
Jerome Coutant 2:123b894b49dd 63 + Display on LCD
Jerome Coutant 2:123b894b49dd 64 o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string
Jerome Coutant 2:123b894b49dd 65 line using the BSP_LCD_ClearStringLine() function.
Jerome Coutant 2:123b894b49dd 66 o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
Jerome Coutant 2:123b894b49dd 67 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 2:123b894b49dd 68 o Display a string line on the specified position (x,y in pixel) and align mode
Jerome Coutant 2:123b894b49dd 69 using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 2:123b894b49dd 70 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
Jerome Coutant 2:123b894b49dd 71 on LCD using the available set of functions.
Jerome Coutant 2:123b894b49dd 72
Jerome Coutant 2:123b894b49dd 73 ------------------------------------------------------------------------------*/
Jerome Coutant 2:123b894b49dd 74
Jerome Coutant 2:123b894b49dd 75 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 2:123b894b49dd 76 #include "stm32469i_discovery_lcd.h"
Jerome Coutant 2:123b894b49dd 77 #include "../Fonts/fonts.h"
Jerome Coutant 2:123b894b49dd 78 //#include "../../../Utilities/Fonts/font24.c"
Jerome Coutant 2:123b894b49dd 79 //#include "../../../Utilities/Fonts/font20.c"
Jerome Coutant 2:123b894b49dd 80 //#include "../../../Utilities/Fonts/font16.c"
Jerome Coutant 2:123b894b49dd 81 //#include "../../../Utilities/Fonts/font12.c"
Jerome Coutant 2:123b894b49dd 82 //#include "../../../Utilities/Fonts/font8.c"
Jerome Coutant 2:123b894b49dd 83
Jerome Coutant 2:123b894b49dd 84 /** @addtogroup BSP
Jerome Coutant 2:123b894b49dd 85 * @{
Jerome Coutant 2:123b894b49dd 86 */
Jerome Coutant 2:123b894b49dd 87
Jerome Coutant 2:123b894b49dd 88 /** @addtogroup STM32469I_Discovery
Jerome Coutant 2:123b894b49dd 89 * @{
Jerome Coutant 2:123b894b49dd 90 */
Jerome Coutant 2:123b894b49dd 91
Jerome Coutant 2:123b894b49dd 92 /** @defgroup STM32469I-Discovery_LCD STM32469I Discovery LCD
Jerome Coutant 2:123b894b49dd 93 * @{
Jerome Coutant 2:123b894b49dd 94 */
Jerome Coutant 2:123b894b49dd 95
Jerome Coutant 2:123b894b49dd 96 /** @defgroup STM32469I-Discovery_LCD_Private_TypesDefinitions STM32469I Discovery LCD Private TypesDefinitions
Jerome Coutant 2:123b894b49dd 97 * @{
Jerome Coutant 2:123b894b49dd 98 */
Jerome Coutant 2:123b894b49dd 99 static DSI_VidCfgTypeDef hdsivideo_handle;
Jerome Coutant 2:123b894b49dd 100
Jerome Coutant 2:123b894b49dd 101 /**
Jerome Coutant 2:123b894b49dd 102 * @}
Jerome Coutant 2:123b894b49dd 103 */
Jerome Coutant 2:123b894b49dd 104
Jerome Coutant 2:123b894b49dd 105 /** @defgroup STM32469I-Discovery_LCD_Private_Defines STM32469I Discovery LCD Private Defines
Jerome Coutant 2:123b894b49dd 106 * @{
Jerome Coutant 2:123b894b49dd 107 */
Jerome Coutant 2:123b894b49dd 108 /**
Jerome Coutant 2:123b894b49dd 109 * @}
Jerome Coutant 2:123b894b49dd 110 */
Jerome Coutant 2:123b894b49dd 111
Jerome Coutant 2:123b894b49dd 112 /** @defgroup STM32469I-Discovery_LCD_Private_Macros STM32469I Discovery LCD Private Macros
Jerome Coutant 2:123b894b49dd 113 * @{
Jerome Coutant 2:123b894b49dd 114 */
Jerome Coutant 2:123b894b49dd 115 #define ABS(X) ((X) > 0 ? (X) : -(X))
Jerome Coutant 2:123b894b49dd 116
Jerome Coutant 2:123b894b49dd 117 #define POLY_X(Z) ((int32_t)((Points + (Z))->X))
Jerome Coutant 2:123b894b49dd 118 #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y))
Jerome Coutant 2:123b894b49dd 119 /**
Jerome Coutant 2:123b894b49dd 120 * @}
Jerome Coutant 2:123b894b49dd 121 */
Jerome Coutant 2:123b894b49dd 122
Jerome Coutant 2:123b894b49dd 123 /** @defgroup STM32469I-Discovery_LCD_Exported_Variables STM32469I Discovery LCD Exported Variables
Jerome Coutant 2:123b894b49dd 124 * @{
Jerome Coutant 2:123b894b49dd 125 */
Jerome Coutant 2:123b894b49dd 126
Jerome Coutant 2:123b894b49dd 127 /**
Jerome Coutant 2:123b894b49dd 128 * @}
Jerome Coutant 2:123b894b49dd 129 */
Jerome Coutant 2:123b894b49dd 130
Jerome Coutant 2:123b894b49dd 131
Jerome Coutant 2:123b894b49dd 132 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables
Jerome Coutant 2:123b894b49dd 133 * @{
Jerome Coutant 2:123b894b49dd 134 */
Jerome Coutant 2:123b894b49dd 135
Jerome Coutant 2:123b894b49dd 136 DMA2D_HandleTypeDef hdma2d_eval;
Jerome Coutant 2:123b894b49dd 137 LTDC_HandleTypeDef hltdc_eval;
Jerome Coutant 2:123b894b49dd 138 DSI_HandleTypeDef hdsi_eval;
Jerome Coutant 2:123b894b49dd 139 uint32_t lcd_x_size = OTM8009A_800X480_WIDTH;
Jerome Coutant 2:123b894b49dd 140 uint32_t lcd_y_size = OTM8009A_800X480_HEIGHT;
Jerome Coutant 2:123b894b49dd 141
Jerome Coutant 2:123b894b49dd 142 /**
Jerome Coutant 2:123b894b49dd 143 * @}
Jerome Coutant 2:123b894b49dd 144 */
Jerome Coutant 2:123b894b49dd 145
Jerome Coutant 2:123b894b49dd 146
Jerome Coutant 2:123b894b49dd 147 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables
Jerome Coutant 2:123b894b49dd 148 * @{
Jerome Coutant 2:123b894b49dd 149 */
Jerome Coutant 2:123b894b49dd 150
Jerome Coutant 2:123b894b49dd 151 /**
Jerome Coutant 2:123b894b49dd 152 * @brief Default Active LTDC Layer in which drawing is made is LTDC Layer Background
Jerome Coutant 2:123b894b49dd 153 */
Jerome Coutant 2:123b894b49dd 154 static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
Jerome Coutant 2:123b894b49dd 155
Jerome Coutant 2:123b894b49dd 156 /**
Jerome Coutant 2:123b894b49dd 157 * @brief Current Drawing Layer properties variable
Jerome Coutant 2:123b894b49dd 158 */
Jerome Coutant 2:123b894b49dd 159 static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER];
Jerome Coutant 2:123b894b49dd 160 /**
Jerome Coutant 2:123b894b49dd 161 * @}
Jerome Coutant 2:123b894b49dd 162 */
Jerome Coutant 2:123b894b49dd 163
Jerome Coutant 2:123b894b49dd 164 /** @defgroup STM32469I-Discovery_LCD_Private_FunctionPrototypes STM32469I Discovery LCD Private FunctionPrototypes
Jerome Coutant 2:123b894b49dd 165 * @{
Jerome Coutant 2:123b894b49dd 166 */
Jerome Coutant 2:123b894b49dd 167 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
Jerome Coutant 2:123b894b49dd 168 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
Jerome Coutant 2:123b894b49dd 169 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
Jerome Coutant 2:123b894b49dd 170 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
Jerome Coutant 2:123b894b49dd 171 /**
Jerome Coutant 2:123b894b49dd 172 * @}
Jerome Coutant 2:123b894b49dd 173 */
Jerome Coutant 2:123b894b49dd 174
Jerome Coutant 2:123b894b49dd 175 /** @defgroup STM32469I-Discovery_LCD_Exported_Functions STM32469I Discovery LCD Exported Functions
Jerome Coutant 2:123b894b49dd 176 * @{
Jerome Coutant 2:123b894b49dd 177 */
Jerome Coutant 2:123b894b49dd 178
Jerome Coutant 2:123b894b49dd 179 /**
Jerome Coutant 2:123b894b49dd 180 * @brief Initializes the DSI LCD.
Jerome Coutant 2:123b894b49dd 181 * @retval LCD state
Jerome Coutant 2:123b894b49dd 182 */
Jerome Coutant 2:123b894b49dd 183 uint8_t BSP_LCD_Init(void)
Jerome Coutant 2:123b894b49dd 184 {
Jerome Coutant 2:123b894b49dd 185 return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE));
Jerome Coutant 2:123b894b49dd 186 }
Jerome Coutant 2:123b894b49dd 187
Jerome Coutant 2:123b894b49dd 188 /**
Jerome Coutant 2:123b894b49dd 189 * @brief Initializes the DSI LCD.
Jerome Coutant 2:123b894b49dd 190 * The ititialization is done as below:
Jerome Coutant 2:123b894b49dd 191 * - DSI PLL ititialization
Jerome Coutant 2:123b894b49dd 192 * - DSI ititialization
Jerome Coutant 2:123b894b49dd 193 * - LTDC ititialization
Jerome Coutant 2:123b894b49dd 194 * - OTM8009A LCD Display IC Driver ititialization
Jerome Coutant 2:123b894b49dd 195 * @retval LCD state
Jerome Coutant 2:123b894b49dd 196 */
Jerome Coutant 2:123b894b49dd 197 uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation)
Jerome Coutant 2:123b894b49dd 198 {
Jerome Coutant 2:123b894b49dd 199 DSI_PLLInitTypeDef dsiPllInit;
Jerome Coutant 2:123b894b49dd 200 DSI_PHY_TimerTypeDef PhyTimings;
Jerome Coutant 2:123b894b49dd 201 static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
Jerome Coutant 2:123b894b49dd 202 uint32_t LcdClock = 27429; /*!< LcdClk = 27429 kHz */
Jerome Coutant 2:123b894b49dd 203
Jerome Coutant 2:123b894b49dd 204 uint32_t laneByteClk_kHz = 0;
Jerome Coutant 2:123b894b49dd 205 uint32_t VSA; /*!< Vertical start active time in units of lines */
Jerome Coutant 2:123b894b49dd 206 uint32_t VBP; /*!< Vertical Back Porch time in units of lines */
Jerome Coutant 2:123b894b49dd 207 uint32_t VFP; /*!< Vertical Front Porch time in units of lines */
Jerome Coutant 2:123b894b49dd 208 uint32_t VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */
Jerome Coutant 2:123b894b49dd 209 uint32_t HSA; /*!< Horizontal start active time in units of lcdClk */
Jerome Coutant 2:123b894b49dd 210 uint32_t HBP; /*!< Horizontal Back Porch time in units of lcdClk */
Jerome Coutant 2:123b894b49dd 211 uint32_t HFP; /*!< Horizontal Front Porch time in units of lcdClk */
Jerome Coutant 2:123b894b49dd 212 uint32_t HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */
Jerome Coutant 2:123b894b49dd 213
Jerome Coutant 2:123b894b49dd 214
Jerome Coutant 2:123b894b49dd 215 /* Toggle Hardware Reset of the DSI LCD using
Jerome Coutant 2:123b894b49dd 216 * its XRES signal (active low) */
Jerome Coutant 2:123b894b49dd 217 BSP_LCD_Reset();
Jerome Coutant 2:123b894b49dd 218
Jerome Coutant 2:123b894b49dd 219 /* Call first MSP Initialize only in case of first initialization
Jerome Coutant 2:123b894b49dd 220 * This will set IP blocks LTDC, DSI and DMA2D
Jerome Coutant 2:123b894b49dd 221 * - out of reset
Jerome Coutant 2:123b894b49dd 222 * - clocked
Jerome Coutant 2:123b894b49dd 223 * - NVIC IRQ related to IP blocks enabled
Jerome Coutant 2:123b894b49dd 224 */
Jerome Coutant 2:123b894b49dd 225 BSP_LCD_MspInit();
Jerome Coutant 2:123b894b49dd 226
Jerome Coutant 2:123b894b49dd 227 /*************************DSI Initialization***********************************/
Jerome Coutant 2:123b894b49dd 228
Jerome Coutant 2:123b894b49dd 229 /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
Jerome Coutant 2:123b894b49dd 230 hdsi_eval.Instance = DSI;
Jerome Coutant 2:123b894b49dd 231
Jerome Coutant 2:123b894b49dd 232 HAL_DSI_DeInit(&(hdsi_eval));
Jerome Coutant 2:123b894b49dd 233
Jerome Coutant 2:123b894b49dd 234 #if !defined(USE_STM32469I_DISCO_REVA)
Jerome Coutant 2:123b894b49dd 235 dsiPllInit.PLLNDIV = 125;
Jerome Coutant 2:123b894b49dd 236 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV2;
Jerome Coutant 2:123b894b49dd 237 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
Jerome Coutant 2:123b894b49dd 238 #else
Jerome Coutant 2:123b894b49dd 239 dsiPllInit.PLLNDIV = 100;
Jerome Coutant 2:123b894b49dd 240 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
Jerome Coutant 2:123b894b49dd 241 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
Jerome Coutant 2:123b894b49dd 242 #endif
Jerome Coutant 2:123b894b49dd 243 laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
Jerome Coutant 2:123b894b49dd 244
Jerome Coutant 2:123b894b49dd 245 /* Set number of Lanes */
Jerome Coutant 2:123b894b49dd 246 hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
Jerome Coutant 2:123b894b49dd 247
Jerome Coutant 2:123b894b49dd 248 /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
Jerome Coutant 2:123b894b49dd 249 hdsi_eval.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
Jerome Coutant 2:123b894b49dd 250
Jerome Coutant 2:123b894b49dd 251 HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit));
Jerome Coutant 2:123b894b49dd 252
Jerome Coutant 2:123b894b49dd 253 /* Timing parameters for all Video modes
Jerome Coutant 2:123b894b49dd 254 * Set Timing parameters of LTDC depending on its chosen orientation
Jerome Coutant 2:123b894b49dd 255 */
Jerome Coutant 2:123b894b49dd 256 if(orientation == LCD_ORIENTATION_PORTRAIT)
Jerome Coutant 2:123b894b49dd 257 {
Jerome Coutant 2:123b894b49dd 258 lcd_x_size = OTM8009A_480X800_WIDTH; /* 480 */
Jerome Coutant 2:123b894b49dd 259 lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */
Jerome Coutant 2:123b894b49dd 260 }
Jerome Coutant 2:123b894b49dd 261 else
Jerome Coutant 2:123b894b49dd 262 {
Jerome Coutant 2:123b894b49dd 263 /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
Jerome Coutant 2:123b894b49dd 264 lcd_x_size = OTM8009A_800X480_WIDTH; /* 800 */
Jerome Coutant 2:123b894b49dd 265 lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */
Jerome Coutant 2:123b894b49dd 266 }
Jerome Coutant 2:123b894b49dd 267
Jerome Coutant 2:123b894b49dd 268 HACT = lcd_x_size;
Jerome Coutant 2:123b894b49dd 269 VACT = lcd_y_size;
Jerome Coutant 2:123b894b49dd 270
Jerome Coutant 2:123b894b49dd 271 /* The following values are same for portrait and landscape orientations */
Jerome Coutant 2:123b894b49dd 272 VSA = OTM8009A_480X800_VSYNC;
Jerome Coutant 2:123b894b49dd 273 VBP = OTM8009A_480X800_VBP;
Jerome Coutant 2:123b894b49dd 274 VFP = OTM8009A_480X800_VFP;
Jerome Coutant 2:123b894b49dd 275 HSA = OTM8009A_480X800_HSYNC;
Jerome Coutant 2:123b894b49dd 276 HBP = OTM8009A_480X800_HBP;
Jerome Coutant 2:123b894b49dd 277 HFP = OTM8009A_480X800_HFP;
Jerome Coutant 2:123b894b49dd 278
Jerome Coutant 2:123b894b49dd 279
Jerome Coutant 2:123b894b49dd 280 hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID;
Jerome Coutant 2:123b894b49dd 281 hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888;
Jerome Coutant 2:123b894b49dd 282 hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
Jerome Coutant 2:123b894b49dd 283 hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
Jerome Coutant 2:123b894b49dd 284 hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
Jerome Coutant 2:123b894b49dd 285 hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
Jerome Coutant 2:123b894b49dd 286 hdsivideo_handle.NullPacketSize = 0xFFF;
Jerome Coutant 2:123b894b49dd 287 hdsivideo_handle.NumberOfChunks = 0;
Jerome Coutant 2:123b894b49dd 288 hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 2:123b894b49dd 289 hdsivideo_handle.HorizontalSyncActive = (HSA * laneByteClk_kHz) / LcdClock;
Jerome Coutant 2:123b894b49dd 290 hdsivideo_handle.HorizontalBackPorch = (HBP * laneByteClk_kHz) / LcdClock;
Jerome Coutant 2:123b894b49dd 291 hdsivideo_handle.HorizontalLine = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz) / LcdClock; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 2:123b894b49dd 292 hdsivideo_handle.VerticalSyncActive = VSA;
Jerome Coutant 2:123b894b49dd 293 hdsivideo_handle.VerticalBackPorch = VBP;
Jerome Coutant 2:123b894b49dd 294 hdsivideo_handle.VerticalFrontPorch = VFP;
Jerome Coutant 2:123b894b49dd 295 hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 2:123b894b49dd 296
Jerome Coutant 2:123b894b49dd 297 /* Enable or disable sending LP command while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 298 hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
Jerome Coutant 2:123b894b49dd 299
Jerome Coutant 2:123b894b49dd 300 /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
Jerome Coutant 2:123b894b49dd 301 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 302 hdsivideo_handle.LPLargestPacketSize = 16;
Jerome Coutant 2:123b894b49dd 303
Jerome Coutant 2:123b894b49dd 304 /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
Jerome Coutant 2:123b894b49dd 305 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 306 hdsivideo_handle.LPVACTLargestPacketSize = 0;
Jerome Coutant 2:123b894b49dd 307
Jerome Coutant 2:123b894b49dd 308
Jerome Coutant 2:123b894b49dd 309 /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */
Jerome Coutant 2:123b894b49dd 310 /* while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 311 hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */
Jerome Coutant 2:123b894b49dd 312 hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */
Jerome Coutant 2:123b894b49dd 313 hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */
Jerome Coutant 2:123b894b49dd 314 hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */
Jerome Coutant 2:123b894b49dd 315 hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */
Jerome Coutant 2:123b894b49dd 316 hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
Jerome Coutant 2:123b894b49dd 317
Jerome Coutant 2:123b894b49dd 318 /* Configure DSI Video mode timings with settings set above */
Jerome Coutant 2:123b894b49dd 319 HAL_DSI_ConfigVideoMode(&(hdsi_eval), &(hdsivideo_handle));
Jerome Coutant 2:123b894b49dd 320
Jerome Coutant 2:123b894b49dd 321 /* Configure DSI PHY HS2LP and LP2HS timings */
Jerome Coutant 2:123b894b49dd 322 PhyTimings.ClockLaneHS2LPTime = 35;
Jerome Coutant 2:123b894b49dd 323 PhyTimings.ClockLaneLP2HSTime = 35;
Jerome Coutant 2:123b894b49dd 324 PhyTimings.DataLaneHS2LPTime = 35;
Jerome Coutant 2:123b894b49dd 325 PhyTimings.DataLaneLP2HSTime = 35;
Jerome Coutant 2:123b894b49dd 326 PhyTimings.DataLaneMaxReadTime = 0;
Jerome Coutant 2:123b894b49dd 327 PhyTimings.StopWaitTime = 10;
Jerome Coutant 2:123b894b49dd 328 HAL_DSI_ConfigPhyTimer(&hdsi_eval, &PhyTimings);
Jerome Coutant 2:123b894b49dd 329
Jerome Coutant 2:123b894b49dd 330 /*************************End DSI Initialization*******************************/
Jerome Coutant 2:123b894b49dd 331
Jerome Coutant 2:123b894b49dd 332
Jerome Coutant 2:123b894b49dd 333 /************************LTDC Initialization***********************************/
Jerome Coutant 2:123b894b49dd 334
Jerome Coutant 2:123b894b49dd 335 /* Timing Configuration */
Jerome Coutant 2:123b894b49dd 336 hltdc_eval.Init.HorizontalSync = (HSA - 1);
Jerome Coutant 2:123b894b49dd 337 hltdc_eval.Init.AccumulatedHBP = (HSA + HBP - 1);
Jerome Coutant 2:123b894b49dd 338 hltdc_eval.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
Jerome Coutant 2:123b894b49dd 339 hltdc_eval.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
Jerome Coutant 2:123b894b49dd 340
Jerome Coutant 2:123b894b49dd 341 /* Initialize the LCD pixel width and pixel height */
Jerome Coutant 2:123b894b49dd 342 hltdc_eval.LayerCfg->ImageWidth = lcd_x_size;
Jerome Coutant 2:123b894b49dd 343 hltdc_eval.LayerCfg->ImageHeight = lcd_y_size;
Jerome Coutant 2:123b894b49dd 344
Jerome Coutant 2:123b894b49dd 345
Jerome Coutant 2:123b894b49dd 346 /* LCD clock configuration */
Jerome Coutant 2:123b894b49dd 347 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
Jerome Coutant 2:123b894b49dd 348 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz */
Jerome Coutant 2:123b894b49dd 349 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz */
Jerome Coutant 2:123b894b49dd 350 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz */
Jerome Coutant 2:123b894b49dd 351 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
Jerome Coutant 2:123b894b49dd 352 PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
Jerome Coutant 2:123b894b49dd 353 PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;
Jerome Coutant 2:123b894b49dd 354 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
Jerome Coutant 2:123b894b49dd 355 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
Jerome Coutant 2:123b894b49dd 356
Jerome Coutant 2:123b894b49dd 357 /* Background value */
Jerome Coutant 2:123b894b49dd 358 hltdc_eval.Init.Backcolor.Blue = 0;
Jerome Coutant 2:123b894b49dd 359 hltdc_eval.Init.Backcolor.Green = 0;
Jerome Coutant 2:123b894b49dd 360 hltdc_eval.Init.Backcolor.Red = 0;
Jerome Coutant 2:123b894b49dd 361 hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
Jerome Coutant 2:123b894b49dd 362 hltdc_eval.Instance = LTDC;
Jerome Coutant 2:123b894b49dd 363
Jerome Coutant 2:123b894b49dd 364 /* Get LTDC Configuration from DSI Configuration */
Jerome Coutant 2:123b894b49dd 365 HAL_LTDCEx_StructInitFromVideoConfig(&(hltdc_eval), &(hdsivideo_handle));
Jerome Coutant 2:123b894b49dd 366
Jerome Coutant 2:123b894b49dd 367 /* Initialize the LTDC */
Jerome Coutant 2:123b894b49dd 368 HAL_LTDC_Init(&hltdc_eval);
Jerome Coutant 2:123b894b49dd 369
Jerome Coutant 2:123b894b49dd 370 /* Enable the DSI host and wrapper after the LTDC initialization
Jerome Coutant 2:123b894b49dd 371 To avoid any synchronization issue, the DSI shall be started after enabling the LTDC */
Jerome Coutant 2:123b894b49dd 372 HAL_DSI_Start(&(hdsi_eval));
Jerome Coutant 2:123b894b49dd 373
Jerome Coutant 2:123b894b49dd 374 #if !defined(DATA_IN_ExtSDRAM)
Jerome Coutant 2:123b894b49dd 375 /* Initialize the SDRAM */
Jerome Coutant 2:123b894b49dd 376 BSP_SDRAM_Init();
Jerome Coutant 2:123b894b49dd 377 #endif /* DATA_IN_ExtSDRAM */
Jerome Coutant 2:123b894b49dd 378
Jerome Coutant 2:123b894b49dd 379 /* Initialize the font */
Jerome Coutant 2:123b894b49dd 380 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
Jerome Coutant 2:123b894b49dd 381
Jerome Coutant 2:123b894b49dd 382 /************************End LTDC Initialization*******************************/
Jerome Coutant 2:123b894b49dd 383
Jerome Coutant 2:123b894b49dd 384
Jerome Coutant 2:123b894b49dd 385 /***********************OTM8009A Initialization********************************/
Jerome Coutant 2:123b894b49dd 386
Jerome Coutant 2:123b894b49dd 387 /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
Jerome Coutant 2:123b894b49dd 388 * depending on configuration set in 'hdsivideo_handle'.
Jerome Coutant 2:123b894b49dd 389 */
Jerome Coutant 2:123b894b49dd 390 OTM8009A_Init(OTM8009A_FORMAT_RGB888, orientation);
Jerome Coutant 2:123b894b49dd 391
Jerome Coutant 2:123b894b49dd 392 /***********************End OTM8009A Initialization****************************/
Jerome Coutant 2:123b894b49dd 393
Jerome Coutant 2:123b894b49dd 394 return LCD_OK;
Jerome Coutant 2:123b894b49dd 395 }
Jerome Coutant 2:123b894b49dd 396
Jerome Coutant 2:123b894b49dd 397 /**
Jerome Coutant 2:123b894b49dd 398 * @brief BSP LCD Reset
Jerome Coutant 2:123b894b49dd 399 * Hw reset the LCD DSI activating its XRES signal (active low for some time)
Jerome Coutant 2:123b894b49dd 400 * and desactivating it later.
Jerome Coutant 2:123b894b49dd 401 * This signal is only cabled on Discovery Rev B and beyond.
Jerome Coutant 2:123b894b49dd 402 */
Jerome Coutant 2:123b894b49dd 403 void BSP_LCD_Reset(void)
Jerome Coutant 2:123b894b49dd 404 {
Jerome Coutant 2:123b894b49dd 405 #if !defined(USE_STM32469I_DISCO_REVA)
Jerome Coutant 2:123b894b49dd 406 /* EVAL Rev B and beyond : reset the LCD by activation of XRES (active low) connected to PH7 */
Jerome Coutant 2:123b894b49dd 407 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 2:123b894b49dd 408
Jerome Coutant 2:123b894b49dd 409 __HAL_RCC_GPIOH_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 410
Jerome Coutant 2:123b894b49dd 411 /* Configure the GPIO on PH7 */
Jerome Coutant 2:123b894b49dd 412 gpio_init_structure.Pin = GPIO_PIN_7;
Jerome Coutant 2:123b894b49dd 413 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_OD;
Jerome Coutant 2:123b894b49dd 414 gpio_init_structure.Pull = GPIO_NOPULL;
Jerome Coutant 2:123b894b49dd 415 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
Jerome Coutant 2:123b894b49dd 416
Jerome Coutant 2:123b894b49dd 417 HAL_GPIO_Init(GPIOH, &gpio_init_structure);
Jerome Coutant 2:123b894b49dd 418
Jerome Coutant 2:123b894b49dd 419 /* Activate XRES active low */
Jerome Coutant 2:123b894b49dd 420 HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_RESET);
Jerome Coutant 2:123b894b49dd 421
Jerome Coutant 2:123b894b49dd 422 //HAL_Delay(20); /* wait 20 ms */
Jerome Coutant 2:123b894b49dd 423 wait_ms(20);
Jerome Coutant 2:123b894b49dd 424
Jerome Coutant 2:123b894b49dd 425 /* Desactivate XRES */
Jerome Coutant 2:123b894b49dd 426 HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_SET);
Jerome Coutant 2:123b894b49dd 427
Jerome Coutant 2:123b894b49dd 428 /* Wait for 10ms after releasing XRES before sending commands */
Jerome Coutant 2:123b894b49dd 429 //HAL_Delay(10);
Jerome Coutant 2:123b894b49dd 430 wait_ms(10);
Jerome Coutant 2:123b894b49dd 431 #else
Jerome Coutant 2:123b894b49dd 432
Jerome Coutant 2:123b894b49dd 433 #endif /* USE_STM32469I_DISCO_REVA == 0 */
Jerome Coutant 2:123b894b49dd 434 }
Jerome Coutant 2:123b894b49dd 435
Jerome Coutant 2:123b894b49dd 436 /**
Jerome Coutant 2:123b894b49dd 437 * @brief Gets the LCD X size.
Jerome Coutant 2:123b894b49dd 438 * @retval Used LCD X size
Jerome Coutant 2:123b894b49dd 439 */
Jerome Coutant 2:123b894b49dd 440 uint32_t BSP_LCD_GetXSize(void)
Jerome Coutant 2:123b894b49dd 441 {
Jerome Coutant 2:123b894b49dd 442 return (lcd_x_size);
Jerome Coutant 2:123b894b49dd 443 }
Jerome Coutant 2:123b894b49dd 444
Jerome Coutant 2:123b894b49dd 445 /**
Jerome Coutant 2:123b894b49dd 446 * @brief Gets the LCD Y size.
Jerome Coutant 2:123b894b49dd 447 * @retval Used LCD Y size
Jerome Coutant 2:123b894b49dd 448 */
Jerome Coutant 2:123b894b49dd 449 uint32_t BSP_LCD_GetYSize(void)
Jerome Coutant 2:123b894b49dd 450 {
Jerome Coutant 2:123b894b49dd 451 return (lcd_y_size);
Jerome Coutant 2:123b894b49dd 452 }
Jerome Coutant 2:123b894b49dd 453
Jerome Coutant 2:123b894b49dd 454 /**
Jerome Coutant 2:123b894b49dd 455 * @brief Set the LCD X size.
Jerome Coutant 2:123b894b49dd 456 * @param imageWidthPixels : uint32_t image width in pixels unit
Jerome Coutant 2:123b894b49dd 457 */
Jerome Coutant 2:123b894b49dd 458 void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
Jerome Coutant 2:123b894b49dd 459 {
Jerome Coutant 2:123b894b49dd 460 hltdc_eval.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
Jerome Coutant 2:123b894b49dd 461 }
Jerome Coutant 2:123b894b49dd 462
Jerome Coutant 2:123b894b49dd 463 /**
Jerome Coutant 2:123b894b49dd 464 * @brief Set the LCD Y size.
Jerome Coutant 2:123b894b49dd 465 * @param imageHeightPixels : uint32_t image height in lines unit
Jerome Coutant 2:123b894b49dd 466 */
Jerome Coutant 2:123b894b49dd 467 void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
Jerome Coutant 2:123b894b49dd 468 {
Jerome Coutant 2:123b894b49dd 469 hltdc_eval.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
Jerome Coutant 2:123b894b49dd 470 }
Jerome Coutant 2:123b894b49dd 471
Jerome Coutant 2:123b894b49dd 472
Jerome Coutant 2:123b894b49dd 473 /**
Jerome Coutant 2:123b894b49dd 474 * @brief Initializes the LCD layers.
Jerome Coutant 2:123b894b49dd 475 * @param LayerIndex: Layer foreground or background
Jerome Coutant 2:123b894b49dd 476 * @param FB_Address: Layer frame buffer
Jerome Coutant 2:123b894b49dd 477 */
Jerome Coutant 2:123b894b49dd 478 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
Jerome Coutant 2:123b894b49dd 479 {
Jerome Coutant 2:123b894b49dd 480 LCD_LayerCfgTypeDef Layercfg;
Jerome Coutant 2:123b894b49dd 481
Jerome Coutant 2:123b894b49dd 482 /* Layer Init */
Jerome Coutant 2:123b894b49dd 483 Layercfg.WindowX0 = 0;
Jerome Coutant 2:123b894b49dd 484 Layercfg.WindowX1 = BSP_LCD_GetXSize();
Jerome Coutant 2:123b894b49dd 485 Layercfg.WindowY0 = 0;
Jerome Coutant 2:123b894b49dd 486 Layercfg.WindowY1 = BSP_LCD_GetYSize();
Jerome Coutant 2:123b894b49dd 487 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
Jerome Coutant 2:123b894b49dd 488 Layercfg.FBStartAdress = FB_Address;
Jerome Coutant 2:123b894b49dd 489 Layercfg.Alpha = 255;
Jerome Coutant 2:123b894b49dd 490 Layercfg.Alpha0 = 0;
Jerome Coutant 2:123b894b49dd 491 Layercfg.Backcolor.Blue = 0;
Jerome Coutant 2:123b894b49dd 492 Layercfg.Backcolor.Green = 0;
Jerome Coutant 2:123b894b49dd 493 Layercfg.Backcolor.Red = 0;
Jerome Coutant 2:123b894b49dd 494 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
Jerome Coutant 2:123b894b49dd 495 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
Jerome Coutant 2:123b894b49dd 496 Layercfg.ImageWidth = BSP_LCD_GetXSize();
Jerome Coutant 2:123b894b49dd 497 Layercfg.ImageHeight = BSP_LCD_GetYSize();
Jerome Coutant 2:123b894b49dd 498
Jerome Coutant 2:123b894b49dd 499 HAL_LTDC_ConfigLayer(&hltdc_eval, &Layercfg, LayerIndex);
Jerome Coutant 2:123b894b49dd 500
Jerome Coutant 2:123b894b49dd 501 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
Jerome Coutant 2:123b894b49dd 502 DrawProp[LayerIndex].pFont = &Font24;
Jerome Coutant 2:123b894b49dd 503 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
Jerome Coutant 2:123b894b49dd 504 }
Jerome Coutant 2:123b894b49dd 505
Jerome Coutant 2:123b894b49dd 506
Jerome Coutant 2:123b894b49dd 507 /**
Jerome Coutant 2:123b894b49dd 508 * @brief Selects the LCD Layer.
Jerome Coutant 2:123b894b49dd 509 * @param LayerIndex: Layer foreground or background
Jerome Coutant 2:123b894b49dd 510 */
Jerome Coutant 2:123b894b49dd 511 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
Jerome Coutant 2:123b894b49dd 512 {
Jerome Coutant 2:123b894b49dd 513 ActiveLayer = LayerIndex;
Jerome Coutant 2:123b894b49dd 514 }
Jerome Coutant 2:123b894b49dd 515
Jerome Coutant 2:123b894b49dd 516 /**
Jerome Coutant 2:123b894b49dd 517 * @brief Sets an LCD Layer visible
Jerome Coutant 2:123b894b49dd 518 * @param LayerIndex: Visible Layer
Jerome Coutant 2:123b894b49dd 519 * @param State: New state of the specified layer
Jerome Coutant 2:123b894b49dd 520 * This parameter can be one of the following values:
Jerome Coutant 2:123b894b49dd 521 * @arg ENABLE
Jerome Coutant 2:123b894b49dd 522 * @arg DISABLE
Jerome Coutant 2:123b894b49dd 523 */
Jerome Coutant 2:123b894b49dd 524 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
Jerome Coutant 2:123b894b49dd 525 {
Jerome Coutant 2:123b894b49dd 526 if(State == ENABLE)
Jerome Coutant 2:123b894b49dd 527 {
Jerome Coutant 2:123b894b49dd 528 __HAL_LTDC_LAYER_ENABLE(&(hltdc_eval), LayerIndex);
Jerome Coutant 2:123b894b49dd 529 }
Jerome Coutant 2:123b894b49dd 530 else
Jerome Coutant 2:123b894b49dd 531 {
Jerome Coutant 2:123b894b49dd 532 __HAL_LTDC_LAYER_DISABLE(&(hltdc_eval), LayerIndex);
Jerome Coutant 2:123b894b49dd 533 }
Jerome Coutant 2:123b894b49dd 534 __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG(&(hltdc_eval));
Jerome Coutant 2:123b894b49dd 535
Jerome Coutant 2:123b894b49dd 536 }
Jerome Coutant 2:123b894b49dd 537
Jerome Coutant 2:123b894b49dd 538 /**
Jerome Coutant 2:123b894b49dd 539 * @brief Configures the transparency.
Jerome Coutant 2:123b894b49dd 540 * @param LayerIndex: Layer foreground or background.
Jerome Coutant 2:123b894b49dd 541 * @param Transparency: Transparency
Jerome Coutant 2:123b894b49dd 542 * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
Jerome Coutant 2:123b894b49dd 543 */
Jerome Coutant 2:123b894b49dd 544 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
Jerome Coutant 2:123b894b49dd 545 {
Jerome Coutant 2:123b894b49dd 546
Jerome Coutant 2:123b894b49dd 547 HAL_LTDC_SetAlpha(&(hltdc_eval), Transparency, LayerIndex);
Jerome Coutant 2:123b894b49dd 548
Jerome Coutant 2:123b894b49dd 549 }
Jerome Coutant 2:123b894b49dd 550
Jerome Coutant 2:123b894b49dd 551 /**
Jerome Coutant 2:123b894b49dd 552 * @brief Sets an LCD layer frame buffer address.
Jerome Coutant 2:123b894b49dd 553 * @param LayerIndex: Layer foreground or background
Jerome Coutant 2:123b894b49dd 554 * @param Address: New LCD frame buffer value
Jerome Coutant 2:123b894b49dd 555 */
Jerome Coutant 2:123b894b49dd 556 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
Jerome Coutant 2:123b894b49dd 557 {
Jerome Coutant 2:123b894b49dd 558
Jerome Coutant 2:123b894b49dd 559 HAL_LTDC_SetAddress(&(hltdc_eval), Address, LayerIndex);
Jerome Coutant 2:123b894b49dd 560
Jerome Coutant 2:123b894b49dd 561 }
Jerome Coutant 2:123b894b49dd 562
Jerome Coutant 2:123b894b49dd 563 /**
Jerome Coutant 2:123b894b49dd 564 * @brief Sets display window.
Jerome Coutant 2:123b894b49dd 565 * @param LayerIndex: Layer index
Jerome Coutant 2:123b894b49dd 566 * @param Xpos: LCD X position
Jerome Coutant 2:123b894b49dd 567 * @param Ypos: LCD Y position
Jerome Coutant 2:123b894b49dd 568 * @param Width: LCD window width
Jerome Coutant 2:123b894b49dd 569 * @param Height: LCD window height
Jerome Coutant 2:123b894b49dd 570 */
Jerome Coutant 2:123b894b49dd 571 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 2:123b894b49dd 572 {
Jerome Coutant 2:123b894b49dd 573 /* Reconfigure the layer size */
Jerome Coutant 2:123b894b49dd 574 HAL_LTDC_SetWindowSize(&(hltdc_eval), Width, Height, LayerIndex);
Jerome Coutant 2:123b894b49dd 575
Jerome Coutant 2:123b894b49dd 576 /* Reconfigure the layer position */
Jerome Coutant 2:123b894b49dd 577 HAL_LTDC_SetWindowPosition(&(hltdc_eval), Xpos, Ypos, LayerIndex);
Jerome Coutant 2:123b894b49dd 578
Jerome Coutant 2:123b894b49dd 579 }
Jerome Coutant 2:123b894b49dd 580
Jerome Coutant 2:123b894b49dd 581 /**
Jerome Coutant 2:123b894b49dd 582 * @brief Configures and sets the color keying.
Jerome Coutant 2:123b894b49dd 583 * @param LayerIndex: Layer foreground or background
Jerome Coutant 2:123b894b49dd 584 * @param RGBValue: Color reference
Jerome Coutant 2:123b894b49dd 585 */
Jerome Coutant 2:123b894b49dd 586 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
Jerome Coutant 2:123b894b49dd 587 {
Jerome Coutant 2:123b894b49dd 588 /* Configure and Enable the color Keying for LCD Layer */
Jerome Coutant 2:123b894b49dd 589 HAL_LTDC_ConfigColorKeying(&(hltdc_eval), RGBValue, LayerIndex);
Jerome Coutant 2:123b894b49dd 590 HAL_LTDC_EnableColorKeying(&(hltdc_eval), LayerIndex);
Jerome Coutant 2:123b894b49dd 591 }
Jerome Coutant 2:123b894b49dd 592
Jerome Coutant 2:123b894b49dd 593 /**
Jerome Coutant 2:123b894b49dd 594 * @brief Disables the color keying.
Jerome Coutant 2:123b894b49dd 595 * @param LayerIndex: Layer foreground or background
Jerome Coutant 2:123b894b49dd 596 */
Jerome Coutant 2:123b894b49dd 597 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
Jerome Coutant 2:123b894b49dd 598 {
Jerome Coutant 2:123b894b49dd 599 /* Disable the color Keying for LCD Layer */
Jerome Coutant 2:123b894b49dd 600 HAL_LTDC_DisableColorKeying(&(hltdc_eval), LayerIndex);
Jerome Coutant 2:123b894b49dd 601 }
Jerome Coutant 2:123b894b49dd 602
Jerome Coutant 2:123b894b49dd 603 /**
Jerome Coutant 2:123b894b49dd 604 * @brief Sets the LCD text color.
Jerome Coutant 2:123b894b49dd 605 * @param Color: Text color code ARGB(8-8-8-8)
Jerome Coutant 2:123b894b49dd 606 */
Jerome Coutant 2:123b894b49dd 607 void BSP_LCD_SetTextColor(uint32_t Color)
Jerome Coutant 2:123b894b49dd 608 {
Jerome Coutant 2:123b894b49dd 609 DrawProp[ActiveLayer].TextColor = Color;
Jerome Coutant 2:123b894b49dd 610 }
Jerome Coutant 2:123b894b49dd 611
Jerome Coutant 2:123b894b49dd 612 /**
Jerome Coutant 2:123b894b49dd 613 * @brief Gets the LCD text color.
Jerome Coutant 2:123b894b49dd 614 * @retval Used text color.
Jerome Coutant 2:123b894b49dd 615 */
Jerome Coutant 2:123b894b49dd 616 uint32_t BSP_LCD_GetTextColor(void)
Jerome Coutant 2:123b894b49dd 617 {
Jerome Coutant 2:123b894b49dd 618 return DrawProp[ActiveLayer].TextColor;
Jerome Coutant 2:123b894b49dd 619 }
Jerome Coutant 2:123b894b49dd 620
Jerome Coutant 2:123b894b49dd 621 /**
Jerome Coutant 2:123b894b49dd 622 * @brief Sets the LCD background color.
Jerome Coutant 2:123b894b49dd 623 * @param Color: Layer background color code ARGB(8-8-8-8)
Jerome Coutant 2:123b894b49dd 624 */
Jerome Coutant 2:123b894b49dd 625 void BSP_LCD_SetBackColor(uint32_t Color)
Jerome Coutant 2:123b894b49dd 626 {
Jerome Coutant 2:123b894b49dd 627 DrawProp[ActiveLayer].BackColor = Color;
Jerome Coutant 2:123b894b49dd 628 }
Jerome Coutant 2:123b894b49dd 629
Jerome Coutant 2:123b894b49dd 630 /**
Jerome Coutant 2:123b894b49dd 631 * @brief Gets the LCD background color.
Jerome Coutant 2:123b894b49dd 632 * @retval Used background color
Jerome Coutant 2:123b894b49dd 633 */
Jerome Coutant 2:123b894b49dd 634 uint32_t BSP_LCD_GetBackColor(void)
Jerome Coutant 2:123b894b49dd 635 {
Jerome Coutant 2:123b894b49dd 636 return DrawProp[ActiveLayer].BackColor;
Jerome Coutant 2:123b894b49dd 637 }
Jerome Coutant 2:123b894b49dd 638
Jerome Coutant 2:123b894b49dd 639 /**
Jerome Coutant 2:123b894b49dd 640 * @brief Sets the LCD text font.
Jerome Coutant 2:123b894b49dd 641 * @param fonts: Layer font to be used
Jerome Coutant 2:123b894b49dd 642 */
Jerome Coutant 2:123b894b49dd 643 void BSP_LCD_SetFont(sFONT *fonts)
Jerome Coutant 2:123b894b49dd 644 {
Jerome Coutant 2:123b894b49dd 645 DrawProp[ActiveLayer].pFont = fonts;
Jerome Coutant 2:123b894b49dd 646 }
Jerome Coutant 2:123b894b49dd 647
Jerome Coutant 2:123b894b49dd 648 /**
Jerome Coutant 2:123b894b49dd 649 * @brief Gets the LCD text font.
Jerome Coutant 2:123b894b49dd 650 * @retval Used layer font
Jerome Coutant 2:123b894b49dd 651 */
Jerome Coutant 2:123b894b49dd 652 sFONT *BSP_LCD_GetFont(void)
Jerome Coutant 2:123b894b49dd 653 {
Jerome Coutant 2:123b894b49dd 654 return DrawProp[ActiveLayer].pFont;
Jerome Coutant 2:123b894b49dd 655 }
Jerome Coutant 2:123b894b49dd 656
Jerome Coutant 2:123b894b49dd 657 /**
Jerome Coutant 2:123b894b49dd 658 * @brief Reads an LCD pixel.
Jerome Coutant 2:123b894b49dd 659 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 660 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 661 * @retval RGB pixel color
Jerome Coutant 2:123b894b49dd 662 */
Jerome Coutant 2:123b894b49dd 663 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
Jerome Coutant 2:123b894b49dd 664 {
Jerome Coutant 2:123b894b49dd 665 uint32_t ret = 0;
Jerome Coutant 2:123b894b49dd 666
Jerome Coutant 2:123b894b49dd 667 if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
Jerome Coutant 2:123b894b49dd 668 {
Jerome Coutant 2:123b894b49dd 669 /* Read data value from SDRAM memory */
Jerome Coutant 2:123b894b49dd 670 ret = *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 2:123b894b49dd 671 }
Jerome Coutant 2:123b894b49dd 672 else if(hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
Jerome Coutant 2:123b894b49dd 673 {
Jerome Coutant 2:123b894b49dd 674 /* Read data value from SDRAM memory */
Jerome Coutant 2:123b894b49dd 675 ret = (*(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
Jerome Coutant 2:123b894b49dd 676 }
Jerome Coutant 2:123b894b49dd 677 else if((hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
Jerome Coutant 2:123b894b49dd 678 (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
Jerome Coutant 2:123b894b49dd 679 (hltdc_eval.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
Jerome Coutant 2:123b894b49dd 680 {
Jerome Coutant 2:123b894b49dd 681 /* Read data value from SDRAM memory */
Jerome Coutant 2:123b894b49dd 682 ret = *(__IO uint16_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 2:123b894b49dd 683 }
Jerome Coutant 2:123b894b49dd 684 else
Jerome Coutant 2:123b894b49dd 685 {
Jerome Coutant 2:123b894b49dd 686 /* Read data value from SDRAM memory */
Jerome Coutant 2:123b894b49dd 687 ret = *(__IO uint8_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 2:123b894b49dd 688 }
Jerome Coutant 2:123b894b49dd 689
Jerome Coutant 2:123b894b49dd 690 return ret;
Jerome Coutant 2:123b894b49dd 691 }
Jerome Coutant 2:123b894b49dd 692
Jerome Coutant 2:123b894b49dd 693 /**
Jerome Coutant 2:123b894b49dd 694 * @brief Clears the whole currently active layer of LTDC.
Jerome Coutant 2:123b894b49dd 695 * @param Color: Color of the background
Jerome Coutant 2:123b894b49dd 696 */
Jerome Coutant 2:123b894b49dd 697 void BSP_LCD_Clear(uint32_t Color)
Jerome Coutant 2:123b894b49dd 698 {
Jerome Coutant 2:123b894b49dd 699 /* Clear the LCD */
Jerome Coutant 2:123b894b49dd 700 LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
Jerome Coutant 2:123b894b49dd 701 }
Jerome Coutant 2:123b894b49dd 702
Jerome Coutant 2:123b894b49dd 703 /**
Jerome Coutant 2:123b894b49dd 704 * @brief Clears the selected line in currently active layer.
Jerome Coutant 2:123b894b49dd 705 * @param Line: Line to be cleared
Jerome Coutant 2:123b894b49dd 706 */
Jerome Coutant 2:123b894b49dd 707 void BSP_LCD_ClearStringLine(uint32_t Line)
Jerome Coutant 2:123b894b49dd 708 {
Jerome Coutant 2:123b894b49dd 709 uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
Jerome Coutant 2:123b894b49dd 710 DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
Jerome Coutant 2:123b894b49dd 711
Jerome Coutant 2:123b894b49dd 712 /* Draw rectangle with background color */
Jerome Coutant 2:123b894b49dd 713 BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
Jerome Coutant 2:123b894b49dd 714
Jerome Coutant 2:123b894b49dd 715 DrawProp[ActiveLayer].TextColor = color_backup;
Jerome Coutant 2:123b894b49dd 716 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 717 }
Jerome Coutant 2:123b894b49dd 718
Jerome Coutant 2:123b894b49dd 719 /**
Jerome Coutant 2:123b894b49dd 720 * @brief Displays one character in currently active layer.
Jerome Coutant 2:123b894b49dd 721 * @param Xpos: Start column address
Jerome Coutant 2:123b894b49dd 722 * @param Ypos: Line where to display the character shape.
Jerome Coutant 2:123b894b49dd 723 * @param Ascii: Character ascii code
Jerome Coutant 2:123b894b49dd 724 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
Jerome Coutant 2:123b894b49dd 725 */
Jerome Coutant 2:123b894b49dd 726 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
Jerome Coutant 2:123b894b49dd 727 {
Jerome Coutant 2:123b894b49dd 728 DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
Jerome Coutant 2:123b894b49dd 729 DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
Jerome Coutant 2:123b894b49dd 730 }
Jerome Coutant 2:123b894b49dd 731
Jerome Coutant 2:123b894b49dd 732 /**
Jerome Coutant 2:123b894b49dd 733 * @brief Displays characters in currently active layer.
Jerome Coutant 2:123b894b49dd 734 * @param Xpos: X position (in pixel)
Jerome Coutant 2:123b894b49dd 735 * @param Ypos: Y position (in pixel)
Jerome Coutant 2:123b894b49dd 736 * @param Text: Pointer to string to display on LCD
Jerome Coutant 2:123b894b49dd 737 * @param Mode: Display mode
Jerome Coutant 2:123b894b49dd 738 * This parameter can be one of the following values:
Jerome Coutant 2:123b894b49dd 739 * @arg CENTER_MODE
Jerome Coutant 2:123b894b49dd 740 * @arg RIGHT_MODE
Jerome Coutant 2:123b894b49dd 741 * @arg LEFT_MODE
Jerome Coutant 2:123b894b49dd 742 */
Jerome Coutant 2:123b894b49dd 743 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
Jerome Coutant 2:123b894b49dd 744 {
Jerome Coutant 2:123b894b49dd 745 uint16_t refcolumn = 1, i = 0;
Jerome Coutant 2:123b894b49dd 746 uint32_t size = 0, xsize = 0;
Jerome Coutant 2:123b894b49dd 747 uint8_t *ptr = Text;
Jerome Coutant 2:123b894b49dd 748
Jerome Coutant 2:123b894b49dd 749 /* Get the text size */
Jerome Coutant 2:123b894b49dd 750 while (*ptr++) size ++ ;
Jerome Coutant 2:123b894b49dd 751
Jerome Coutant 2:123b894b49dd 752 /* Characters number per line */
Jerome Coutant 2:123b894b49dd 753 xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
Jerome Coutant 2:123b894b49dd 754
Jerome Coutant 2:123b894b49dd 755 switch (Mode)
Jerome Coutant 2:123b894b49dd 756 {
Jerome Coutant 2:123b894b49dd 757 case CENTER_MODE:
Jerome Coutant 2:123b894b49dd 758 {
Jerome Coutant 2:123b894b49dd 759 refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
Jerome Coutant 2:123b894b49dd 760 break;
Jerome Coutant 2:123b894b49dd 761 }
Jerome Coutant 2:123b894b49dd 762 case LEFT_MODE:
Jerome Coutant 2:123b894b49dd 763 {
Jerome Coutant 2:123b894b49dd 764 refcolumn = Xpos;
Jerome Coutant 2:123b894b49dd 765 break;
Jerome Coutant 2:123b894b49dd 766 }
Jerome Coutant 2:123b894b49dd 767 case RIGHT_MODE:
Jerome Coutant 2:123b894b49dd 768 {
Jerome Coutant 2:123b894b49dd 769 refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
Jerome Coutant 2:123b894b49dd 770 break;
Jerome Coutant 2:123b894b49dd 771 }
Jerome Coutant 2:123b894b49dd 772 default:
Jerome Coutant 2:123b894b49dd 773 {
Jerome Coutant 2:123b894b49dd 774 refcolumn = Xpos;
Jerome Coutant 2:123b894b49dd 775 break;
Jerome Coutant 2:123b894b49dd 776 }
Jerome Coutant 2:123b894b49dd 777 }
Jerome Coutant 2:123b894b49dd 778
Jerome Coutant 2:123b894b49dd 779 /* Check that the Start column is located in the screen */
Jerome Coutant 2:123b894b49dd 780 if ((refcolumn < 1) || (refcolumn >= 0x8000))
Jerome Coutant 2:123b894b49dd 781 {
Jerome Coutant 2:123b894b49dd 782 refcolumn = 1;
Jerome Coutant 2:123b894b49dd 783 }
Jerome Coutant 2:123b894b49dd 784
Jerome Coutant 2:123b894b49dd 785 /* Send the string character by character on LCD */
Jerome Coutant 2:123b894b49dd 786 while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
Jerome Coutant 2:123b894b49dd 787 {
Jerome Coutant 2:123b894b49dd 788 /* Display one character on LCD */
Jerome Coutant 2:123b894b49dd 789 BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
Jerome Coutant 2:123b894b49dd 790 /* Decrement the column position by 16 */
Jerome Coutant 2:123b894b49dd 791 refcolumn += DrawProp[ActiveLayer].pFont->Width;
Jerome Coutant 2:123b894b49dd 792
Jerome Coutant 2:123b894b49dd 793 /* Point on the next character */
Jerome Coutant 2:123b894b49dd 794 Text++;
Jerome Coutant 2:123b894b49dd 795 i++;
Jerome Coutant 2:123b894b49dd 796 }
Jerome Coutant 2:123b894b49dd 797
Jerome Coutant 2:123b894b49dd 798 }
Jerome Coutant 2:123b894b49dd 799
Jerome Coutant 2:123b894b49dd 800 /**
Jerome Coutant 2:123b894b49dd 801 * @brief Displays a maximum of 60 characters on the LCD.
Jerome Coutant 2:123b894b49dd 802 * @param Line: Line where to display the character shape
Jerome Coutant 2:123b894b49dd 803 * @param ptr: Pointer to string to display on LCD
Jerome Coutant 2:123b894b49dd 804 */
Jerome Coutant 2:123b894b49dd 805 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
Jerome Coutant 2:123b894b49dd 806 {
Jerome Coutant 2:123b894b49dd 807 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
Jerome Coutant 2:123b894b49dd 808 }
Jerome Coutant 2:123b894b49dd 809
Jerome Coutant 2:123b894b49dd 810 /**
Jerome Coutant 2:123b894b49dd 811 * @brief Draws an horizontal line in currently active layer.
Jerome Coutant 2:123b894b49dd 812 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 813 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 814 * @param Length: Line length
Jerome Coutant 2:123b894b49dd 815 */
Jerome Coutant 2:123b894b49dd 816 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Jerome Coutant 2:123b894b49dd 817 {
Jerome Coutant 2:123b894b49dd 818 uint32_t Xaddress = 0;
Jerome Coutant 2:123b894b49dd 819
Jerome Coutant 2:123b894b49dd 820 /* Get the line address */
Jerome Coutant 2:123b894b49dd 821 Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 2:123b894b49dd 822
Jerome Coutant 2:123b894b49dd 823 /* Write line */
Jerome Coutant 2:123b894b49dd 824 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 825 }
Jerome Coutant 2:123b894b49dd 826
Jerome Coutant 2:123b894b49dd 827 /**
Jerome Coutant 2:123b894b49dd 828 * @brief Draws a vertical line in currently active layer.
Jerome Coutant 2:123b894b49dd 829 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 830 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 831 * @param Length: Line length
Jerome Coutant 2:123b894b49dd 832 */
Jerome Coutant 2:123b894b49dd 833 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Jerome Coutant 2:123b894b49dd 834 {
Jerome Coutant 2:123b894b49dd 835 uint32_t Xaddress = 0;
Jerome Coutant 2:123b894b49dd 836
Jerome Coutant 2:123b894b49dd 837 /* Get the line address */
Jerome Coutant 2:123b894b49dd 838 Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 2:123b894b49dd 839
Jerome Coutant 2:123b894b49dd 840 /* Write line */
Jerome Coutant 2:123b894b49dd 841 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 842 }
Jerome Coutant 2:123b894b49dd 843
Jerome Coutant 2:123b894b49dd 844 /**
Jerome Coutant 2:123b894b49dd 845 * @brief Draws an uni-line (between two points) in currently active layer.
Jerome Coutant 2:123b894b49dd 846 * @param x1: Point 1 X position
Jerome Coutant 2:123b894b49dd 847 * @param y1: Point 1 Y position
Jerome Coutant 2:123b894b49dd 848 * @param x2: Point 2 X position
Jerome Coutant 2:123b894b49dd 849 * @param y2: Point 2 Y position
Jerome Coutant 2:123b894b49dd 850 */
Jerome Coutant 2:123b894b49dd 851 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Jerome Coutant 2:123b894b49dd 852 {
Jerome Coutant 2:123b894b49dd 853 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
Jerome Coutant 2:123b894b49dd 854 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
Jerome Coutant 2:123b894b49dd 855 curpixel = 0;
Jerome Coutant 2:123b894b49dd 856
Jerome Coutant 2:123b894b49dd 857 deltax = ABS(x2 - x1); /* The difference between the x's */
Jerome Coutant 2:123b894b49dd 858 deltay = ABS(y2 - y1); /* The difference between the y's */
Jerome Coutant 2:123b894b49dd 859 x = x1; /* Start x off at the first pixel */
Jerome Coutant 2:123b894b49dd 860 y = y1; /* Start y off at the first pixel */
Jerome Coutant 2:123b894b49dd 861
Jerome Coutant 2:123b894b49dd 862 if (x2 >= x1) /* The x-values are increasing */
Jerome Coutant 2:123b894b49dd 863 {
Jerome Coutant 2:123b894b49dd 864 xinc1 = 1;
Jerome Coutant 2:123b894b49dd 865 xinc2 = 1;
Jerome Coutant 2:123b894b49dd 866 }
Jerome Coutant 2:123b894b49dd 867 else /* The x-values are decreasing */
Jerome Coutant 2:123b894b49dd 868 {
Jerome Coutant 2:123b894b49dd 869 xinc1 = -1;
Jerome Coutant 2:123b894b49dd 870 xinc2 = -1;
Jerome Coutant 2:123b894b49dd 871 }
Jerome Coutant 2:123b894b49dd 872
Jerome Coutant 2:123b894b49dd 873 if (y2 >= y1) /* The y-values are increasing */
Jerome Coutant 2:123b894b49dd 874 {
Jerome Coutant 2:123b894b49dd 875 yinc1 = 1;
Jerome Coutant 2:123b894b49dd 876 yinc2 = 1;
Jerome Coutant 2:123b894b49dd 877 }
Jerome Coutant 2:123b894b49dd 878 else /* The y-values are decreasing */
Jerome Coutant 2:123b894b49dd 879 {
Jerome Coutant 2:123b894b49dd 880 yinc1 = -1;
Jerome Coutant 2:123b894b49dd 881 yinc2 = -1;
Jerome Coutant 2:123b894b49dd 882 }
Jerome Coutant 2:123b894b49dd 883
Jerome Coutant 2:123b894b49dd 884 if (deltax >= deltay) /* There is at least one x-value for every y-value */
Jerome Coutant 2:123b894b49dd 885 {
Jerome Coutant 2:123b894b49dd 886 xinc1 = 0; /* Don't change the x when numerator >= denominator */
Jerome Coutant 2:123b894b49dd 887 yinc2 = 0; /* Don't change the y for every iteration */
Jerome Coutant 2:123b894b49dd 888 den = deltax;
Jerome Coutant 2:123b894b49dd 889 num = deltax / 2;
Jerome Coutant 2:123b894b49dd 890 numadd = deltay;
Jerome Coutant 2:123b894b49dd 891 numpixels = deltax; /* There are more x-values than y-values */
Jerome Coutant 2:123b894b49dd 892 }
Jerome Coutant 2:123b894b49dd 893 else /* There is at least one y-value for every x-value */
Jerome Coutant 2:123b894b49dd 894 {
Jerome Coutant 2:123b894b49dd 895 xinc2 = 0; /* Don't change the x for every iteration */
Jerome Coutant 2:123b894b49dd 896 yinc1 = 0; /* Don't change the y when numerator >= denominator */
Jerome Coutant 2:123b894b49dd 897 den = deltay;
Jerome Coutant 2:123b894b49dd 898 num = deltay / 2;
Jerome Coutant 2:123b894b49dd 899 numadd = deltax;
Jerome Coutant 2:123b894b49dd 900 numpixels = deltay; /* There are more y-values than x-values */
Jerome Coutant 2:123b894b49dd 901 }
Jerome Coutant 2:123b894b49dd 902
Jerome Coutant 2:123b894b49dd 903 for (curpixel = 0; curpixel <= numpixels; curpixel++)
Jerome Coutant 2:123b894b49dd 904 {
Jerome Coutant 2:123b894b49dd 905 BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */
Jerome Coutant 2:123b894b49dd 906 num += numadd; /* Increase the numerator by the top of the fraction */
Jerome Coutant 2:123b894b49dd 907 if (num >= den) /* Check if numerator >= denominator */
Jerome Coutant 2:123b894b49dd 908 {
Jerome Coutant 2:123b894b49dd 909 num -= den; /* Calculate the new numerator value */
Jerome Coutant 2:123b894b49dd 910 x += xinc1; /* Change the x as appropriate */
Jerome Coutant 2:123b894b49dd 911 y += yinc1; /* Change the y as appropriate */
Jerome Coutant 2:123b894b49dd 912 }
Jerome Coutant 2:123b894b49dd 913 x += xinc2; /* Change the x as appropriate */
Jerome Coutant 2:123b894b49dd 914 y += yinc2; /* Change the y as appropriate */
Jerome Coutant 2:123b894b49dd 915 }
Jerome Coutant 2:123b894b49dd 916 }
Jerome Coutant 2:123b894b49dd 917
Jerome Coutant 2:123b894b49dd 918 /**
Jerome Coutant 2:123b894b49dd 919 * @brief Draws a rectangle in currently active layer.
Jerome Coutant 2:123b894b49dd 920 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 921 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 922 * @param Width: Rectangle width
Jerome Coutant 2:123b894b49dd 923 * @param Height: Rectangle height
Jerome Coutant 2:123b894b49dd 924 */
Jerome Coutant 2:123b894b49dd 925 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 2:123b894b49dd 926 {
Jerome Coutant 2:123b894b49dd 927 /* Draw horizontal lines */
Jerome Coutant 2:123b894b49dd 928 BSP_LCD_DrawHLine(Xpos, Ypos, Width);
Jerome Coutant 2:123b894b49dd 929 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
Jerome Coutant 2:123b894b49dd 930
Jerome Coutant 2:123b894b49dd 931 /* Draw vertical lines */
Jerome Coutant 2:123b894b49dd 932 BSP_LCD_DrawVLine(Xpos, Ypos, Height);
Jerome Coutant 2:123b894b49dd 933 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
Jerome Coutant 2:123b894b49dd 934 }
Jerome Coutant 2:123b894b49dd 935
Jerome Coutant 2:123b894b49dd 936 /**
Jerome Coutant 2:123b894b49dd 937 * @brief Draws a circle in currently active layer.
Jerome Coutant 2:123b894b49dd 938 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 939 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 940 * @param Radius: Circle radius
Jerome Coutant 2:123b894b49dd 941 */
Jerome Coutant 2:123b894b49dd 942 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Jerome Coutant 2:123b894b49dd 943 {
Jerome Coutant 2:123b894b49dd 944 int32_t D; /* Decision Variable */
Jerome Coutant 2:123b894b49dd 945 uint32_t CurX; /* Current X Value */
Jerome Coutant 2:123b894b49dd 946 uint32_t CurY; /* Current Y Value */
Jerome Coutant 2:123b894b49dd 947
Jerome Coutant 2:123b894b49dd 948 D = 3 - (Radius << 1);
Jerome Coutant 2:123b894b49dd 949 CurX = 0;
Jerome Coutant 2:123b894b49dd 950 CurY = Radius;
Jerome Coutant 2:123b894b49dd 951
Jerome Coutant 2:123b894b49dd 952 while (CurX <= CurY)
Jerome Coutant 2:123b894b49dd 953 {
Jerome Coutant 2:123b894b49dd 954 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 955
Jerome Coutant 2:123b894b49dd 956 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 957
Jerome Coutant 2:123b894b49dd 958 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 959
Jerome Coutant 2:123b894b49dd 960 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 961
Jerome Coutant 2:123b894b49dd 962 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 963
Jerome Coutant 2:123b894b49dd 964 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 965
Jerome Coutant 2:123b894b49dd 966 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 967
Jerome Coutant 2:123b894b49dd 968 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 969
Jerome Coutant 2:123b894b49dd 970 if (D < 0)
Jerome Coutant 2:123b894b49dd 971 {
Jerome Coutant 2:123b894b49dd 972 D += (CurX << 2) + 6;
Jerome Coutant 2:123b894b49dd 973 }
Jerome Coutant 2:123b894b49dd 974 else
Jerome Coutant 2:123b894b49dd 975 {
Jerome Coutant 2:123b894b49dd 976 D += ((CurX - CurY) << 2) + 10;
Jerome Coutant 2:123b894b49dd 977 CurY--;
Jerome Coutant 2:123b894b49dd 978 }
Jerome Coutant 2:123b894b49dd 979 CurX++;
Jerome Coutant 2:123b894b49dd 980 }
Jerome Coutant 2:123b894b49dd 981 }
Jerome Coutant 2:123b894b49dd 982
Jerome Coutant 2:123b894b49dd 983 /**
Jerome Coutant 2:123b894b49dd 984 * @brief Draws an poly-line (between many points) in currently active layer.
Jerome Coutant 2:123b894b49dd 985 * @param Points: Pointer to the points array
Jerome Coutant 2:123b894b49dd 986 * @param PointCount: Number of points
Jerome Coutant 2:123b894b49dd 987 */
Jerome Coutant 2:123b894b49dd 988 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
Jerome Coutant 2:123b894b49dd 989 {
Jerome Coutant 2:123b894b49dd 990 int16_t X = 0, Y = 0;
Jerome Coutant 2:123b894b49dd 991
Jerome Coutant 2:123b894b49dd 992 if(PointCount < 2)
Jerome Coutant 2:123b894b49dd 993 {
Jerome Coutant 2:123b894b49dd 994 return;
Jerome Coutant 2:123b894b49dd 995 }
Jerome Coutant 2:123b894b49dd 996
Jerome Coutant 2:123b894b49dd 997 BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
Jerome Coutant 2:123b894b49dd 998
Jerome Coutant 2:123b894b49dd 999 while(--PointCount)
Jerome Coutant 2:123b894b49dd 1000 {
Jerome Coutant 2:123b894b49dd 1001 X = Points->X;
Jerome Coutant 2:123b894b49dd 1002 Y = Points->Y;
Jerome Coutant 2:123b894b49dd 1003 Points++;
Jerome Coutant 2:123b894b49dd 1004 BSP_LCD_DrawLine(X, Y, Points->X, Points->Y);
Jerome Coutant 2:123b894b49dd 1005 }
Jerome Coutant 2:123b894b49dd 1006 }
Jerome Coutant 2:123b894b49dd 1007
Jerome Coutant 2:123b894b49dd 1008 /**
Jerome Coutant 2:123b894b49dd 1009 * @brief Draws an ellipse on LCD in currently active layer.
Jerome Coutant 2:123b894b49dd 1010 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1011 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1012 * @param XRadius: Ellipse X radius
Jerome Coutant 2:123b894b49dd 1013 * @param YRadius: Ellipse Y radius
Jerome Coutant 2:123b894b49dd 1014 */
Jerome Coutant 2:123b894b49dd 1015 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Jerome Coutant 2:123b894b49dd 1016 {
Jerome Coutant 2:123b894b49dd 1017 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
Jerome Coutant 2:123b894b49dd 1018 float K = 0, rad1 = 0, rad2 = 0;
Jerome Coutant 2:123b894b49dd 1019
Jerome Coutant 2:123b894b49dd 1020 rad1 = XRadius;
Jerome Coutant 2:123b894b49dd 1021 rad2 = YRadius;
Jerome Coutant 2:123b894b49dd 1022
Jerome Coutant 2:123b894b49dd 1023 K = (float)(rad2/rad1);
Jerome Coutant 2:123b894b49dd 1024
Jerome Coutant 2:123b894b49dd 1025 do {
Jerome Coutant 2:123b894b49dd 1026 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1027 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1028 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1029 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1030
Jerome Coutant 2:123b894b49dd 1031 e2 = err;
Jerome Coutant 2:123b894b49dd 1032 if (e2 <= x) {
Jerome Coutant 2:123b894b49dd 1033 err += ++x*2+1;
Jerome Coutant 2:123b894b49dd 1034 if (-y == x && e2 <= y) e2 = 0;
Jerome Coutant 2:123b894b49dd 1035 }
Jerome Coutant 2:123b894b49dd 1036 if (e2 > y) err += ++y*2+1;
Jerome Coutant 2:123b894b49dd 1037 }
Jerome Coutant 2:123b894b49dd 1038 while (y <= 0);
Jerome Coutant 2:123b894b49dd 1039 }
Jerome Coutant 2:123b894b49dd 1040
Jerome Coutant 2:123b894b49dd 1041 /**
Jerome Coutant 2:123b894b49dd 1042 * @brief Draws a bitmap picture loaded in the internal Flash (32 bpp) in currently active layer.
Jerome Coutant 2:123b894b49dd 1043 * @param Xpos: Bmp X position in the LCD
Jerome Coutant 2:123b894b49dd 1044 * @param Ypos: Bmp Y position in the LCD
Jerome Coutant 2:123b894b49dd 1045 * @param pbmp: Pointer to Bmp picture address in the internal Flash
Jerome Coutant 2:123b894b49dd 1046 */
Jerome Coutant 2:123b894b49dd 1047 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
Jerome Coutant 2:123b894b49dd 1048 {
Jerome Coutant 2:123b894b49dd 1049 uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
Jerome Coutant 2:123b894b49dd 1050 uint32_t Address;
Jerome Coutant 2:123b894b49dd 1051 uint32_t InputColorMode = 0;
Jerome Coutant 2:123b894b49dd 1052
Jerome Coutant 2:123b894b49dd 1053 /* Get bitmap data address offset */
Jerome Coutant 2:123b894b49dd 1054 index = *(__IO uint16_t *) (pbmp + 10);
Jerome Coutant 2:123b894b49dd 1055 index |= (*(__IO uint16_t *) (pbmp + 12)) << 16;
Jerome Coutant 2:123b894b49dd 1056
Jerome Coutant 2:123b894b49dd 1057 /* Read bitmap width */
Jerome Coutant 2:123b894b49dd 1058 width = *(uint16_t *) (pbmp + 18);
Jerome Coutant 2:123b894b49dd 1059 width |= (*(uint16_t *) (pbmp + 20)) << 16;
Jerome Coutant 2:123b894b49dd 1060
Jerome Coutant 2:123b894b49dd 1061 /* Read bitmap height */
Jerome Coutant 2:123b894b49dd 1062 height = *(uint16_t *) (pbmp + 22);
Jerome Coutant 2:123b894b49dd 1063 height |= (*(uint16_t *) (pbmp + 24)) << 16;
Jerome Coutant 2:123b894b49dd 1064
Jerome Coutant 2:123b894b49dd 1065 /* Read bit/pixel */
Jerome Coutant 2:123b894b49dd 1066 bit_pixel = *(uint16_t *) (pbmp + 28);
Jerome Coutant 2:123b894b49dd 1067
Jerome Coutant 2:123b894b49dd 1068 /* Set the address */
Jerome Coutant 2:123b894b49dd 1069 Address = hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
Jerome Coutant 2:123b894b49dd 1070
Jerome Coutant 2:123b894b49dd 1071 /* Get the layer pixel format */
Jerome Coutant 2:123b894b49dd 1072 if ((bit_pixel/8) == 4)
Jerome Coutant 2:123b894b49dd 1073 {
Jerome Coutant 2:123b894b49dd 1074 InputColorMode = CM_ARGB8888;
Jerome Coutant 2:123b894b49dd 1075 }
Jerome Coutant 2:123b894b49dd 1076 else if ((bit_pixel/8) == 2)
Jerome Coutant 2:123b894b49dd 1077 {
Jerome Coutant 2:123b894b49dd 1078 InputColorMode = CM_RGB565;
Jerome Coutant 2:123b894b49dd 1079 }
Jerome Coutant 2:123b894b49dd 1080 else
Jerome Coutant 2:123b894b49dd 1081 {
Jerome Coutant 2:123b894b49dd 1082 InputColorMode = CM_RGB888;
Jerome Coutant 2:123b894b49dd 1083 }
Jerome Coutant 2:123b894b49dd 1084
Jerome Coutant 2:123b894b49dd 1085 /* Bypass the bitmap header */
Jerome Coutant 2:123b894b49dd 1086 pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
Jerome Coutant 2:123b894b49dd 1087
Jerome Coutant 2:123b894b49dd 1088 /* Convert picture to ARGB8888 pixel format */
Jerome Coutant 2:123b894b49dd 1089 for(index=0; index < height; index++)
Jerome Coutant 2:123b894b49dd 1090 {
Jerome Coutant 2:123b894b49dd 1091 /* Pixel format conversion */
Jerome Coutant 2:123b894b49dd 1092 LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode);
Jerome Coutant 2:123b894b49dd 1093
Jerome Coutant 2:123b894b49dd 1094 /* Increment the source and destination buffers */
Jerome Coutant 2:123b894b49dd 1095 Address+= (BSP_LCD_GetXSize()*4);
Jerome Coutant 2:123b894b49dd 1096 pbmp -= width*(bit_pixel/8);
Jerome Coutant 2:123b894b49dd 1097 }
Jerome Coutant 2:123b894b49dd 1098 }
Jerome Coutant 2:123b894b49dd 1099
Jerome Coutant 2:123b894b49dd 1100 /**
Jerome Coutant 2:123b894b49dd 1101 * @brief Draws a full rectangle in currently active layer.
Jerome Coutant 2:123b894b49dd 1102 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1103 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1104 * @param Width: Rectangle width
Jerome Coutant 2:123b894b49dd 1105 * @param Height: Rectangle height
Jerome Coutant 2:123b894b49dd 1106 */
Jerome Coutant 2:123b894b49dd 1107 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 2:123b894b49dd 1108 {
Jerome Coutant 2:123b894b49dd 1109 uint32_t Xaddress = 0;
Jerome Coutant 2:123b894b49dd 1110
Jerome Coutant 2:123b894b49dd 1111 /* Set the text color */
Jerome Coutant 2:123b894b49dd 1112 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1113
Jerome Coutant 2:123b894b49dd 1114 /* Get the rectangle start address */
Jerome Coutant 2:123b894b49dd 1115 Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 2:123b894b49dd 1116
Jerome Coutant 2:123b894b49dd 1117 /* Fill the rectangle */
Jerome Coutant 2:123b894b49dd 1118 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1119 }
Jerome Coutant 2:123b894b49dd 1120
Jerome Coutant 2:123b894b49dd 1121 /**
Jerome Coutant 2:123b894b49dd 1122 * @brief Draws a full circle in currently active layer.
Jerome Coutant 2:123b894b49dd 1123 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1124 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1125 * @param Radius: Circle radius
Jerome Coutant 2:123b894b49dd 1126 */
Jerome Coutant 2:123b894b49dd 1127 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Jerome Coutant 2:123b894b49dd 1128 {
Jerome Coutant 2:123b894b49dd 1129 int32_t D; /* Decision Variable */
Jerome Coutant 2:123b894b49dd 1130 uint32_t CurX; /* Current X Value */
Jerome Coutant 2:123b894b49dd 1131 uint32_t CurY; /* Current Y Value */
Jerome Coutant 2:123b894b49dd 1132
Jerome Coutant 2:123b894b49dd 1133 D = 3 - (Radius << 1);
Jerome Coutant 2:123b894b49dd 1134
Jerome Coutant 2:123b894b49dd 1135 CurX = 0;
Jerome Coutant 2:123b894b49dd 1136 CurY = Radius;
Jerome Coutant 2:123b894b49dd 1137
Jerome Coutant 2:123b894b49dd 1138 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1139
Jerome Coutant 2:123b894b49dd 1140 while (CurX <= CurY)
Jerome Coutant 2:123b894b49dd 1141 {
Jerome Coutant 2:123b894b49dd 1142 if(CurY > 0)
Jerome Coutant 2:123b894b49dd 1143 {
Jerome Coutant 2:123b894b49dd 1144 BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
Jerome Coutant 2:123b894b49dd 1145 BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
Jerome Coutant 2:123b894b49dd 1146 }
Jerome Coutant 2:123b894b49dd 1147
Jerome Coutant 2:123b894b49dd 1148 if(CurX > 0)
Jerome Coutant 2:123b894b49dd 1149 {
Jerome Coutant 2:123b894b49dd 1150 BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
Jerome Coutant 2:123b894b49dd 1151 BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
Jerome Coutant 2:123b894b49dd 1152 }
Jerome Coutant 2:123b894b49dd 1153 if (D < 0)
Jerome Coutant 2:123b894b49dd 1154 {
Jerome Coutant 2:123b894b49dd 1155 D += (CurX << 2) + 6;
Jerome Coutant 2:123b894b49dd 1156 }
Jerome Coutant 2:123b894b49dd 1157 else
Jerome Coutant 2:123b894b49dd 1158 {
Jerome Coutant 2:123b894b49dd 1159 D += ((CurX - CurY) << 2) + 10;
Jerome Coutant 2:123b894b49dd 1160 CurY--;
Jerome Coutant 2:123b894b49dd 1161 }
Jerome Coutant 2:123b894b49dd 1162 CurX++;
Jerome Coutant 2:123b894b49dd 1163 }
Jerome Coutant 2:123b894b49dd 1164
Jerome Coutant 2:123b894b49dd 1165 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1166 BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
Jerome Coutant 2:123b894b49dd 1167 }
Jerome Coutant 2:123b894b49dd 1168
Jerome Coutant 2:123b894b49dd 1169 /**
Jerome Coutant 2:123b894b49dd 1170 * @brief Draws a full poly-line (between many points) in currently active layer.
Jerome Coutant 2:123b894b49dd 1171 * @param Points: Pointer to the points array
Jerome Coutant 2:123b894b49dd 1172 * @param PointCount: Number of points
Jerome Coutant 2:123b894b49dd 1173 */
Jerome Coutant 2:123b894b49dd 1174 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
Jerome Coutant 2:123b894b49dd 1175 {
Jerome Coutant 2:123b894b49dd 1176 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;
Jerome Coutant 2:123b894b49dd 1177 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
Jerome Coutant 2:123b894b49dd 1178
Jerome Coutant 2:123b894b49dd 1179 IMAGE_LEFT = IMAGE_RIGHT = Points->X;
Jerome Coutant 2:123b894b49dd 1180 IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
Jerome Coutant 2:123b894b49dd 1181
Jerome Coutant 2:123b894b49dd 1182 for(counter = 1; counter < PointCount; counter++)
Jerome Coutant 2:123b894b49dd 1183 {
Jerome Coutant 2:123b894b49dd 1184 pixelX = POLY_X(counter);
Jerome Coutant 2:123b894b49dd 1185 if(pixelX < IMAGE_LEFT)
Jerome Coutant 2:123b894b49dd 1186 {
Jerome Coutant 2:123b894b49dd 1187 IMAGE_LEFT = pixelX;
Jerome Coutant 2:123b894b49dd 1188 }
Jerome Coutant 2:123b894b49dd 1189 if(pixelX > IMAGE_RIGHT)
Jerome Coutant 2:123b894b49dd 1190 {
Jerome Coutant 2:123b894b49dd 1191 IMAGE_RIGHT = pixelX;
Jerome Coutant 2:123b894b49dd 1192 }
Jerome Coutant 2:123b894b49dd 1193
Jerome Coutant 2:123b894b49dd 1194 pixelY = POLY_Y(counter);
Jerome Coutant 2:123b894b49dd 1195 if(pixelY < IMAGE_TOP)
Jerome Coutant 2:123b894b49dd 1196 {
Jerome Coutant 2:123b894b49dd 1197 IMAGE_TOP = pixelY;
Jerome Coutant 2:123b894b49dd 1198 }
Jerome Coutant 2:123b894b49dd 1199 if(pixelY > IMAGE_BOTTOM)
Jerome Coutant 2:123b894b49dd 1200 {
Jerome Coutant 2:123b894b49dd 1201 IMAGE_BOTTOM = pixelY;
Jerome Coutant 2:123b894b49dd 1202 }
Jerome Coutant 2:123b894b49dd 1203 }
Jerome Coutant 2:123b894b49dd 1204
Jerome Coutant 2:123b894b49dd 1205 if(PointCount < 2)
Jerome Coutant 2:123b894b49dd 1206 {
Jerome Coutant 2:123b894b49dd 1207 return;
Jerome Coutant 2:123b894b49dd 1208 }
Jerome Coutant 2:123b894b49dd 1209
Jerome Coutant 2:123b894b49dd 1210 X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
Jerome Coutant 2:123b894b49dd 1211 Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
Jerome Coutant 2:123b894b49dd 1212
Jerome Coutant 2:123b894b49dd 1213 X_first = Points->X;
Jerome Coutant 2:123b894b49dd 1214 Y_first = Points->Y;
Jerome Coutant 2:123b894b49dd 1215
Jerome Coutant 2:123b894b49dd 1216 while(--PointCount)
Jerome Coutant 2:123b894b49dd 1217 {
Jerome Coutant 2:123b894b49dd 1218 X = Points->X;
Jerome Coutant 2:123b894b49dd 1219 Y = Points->Y;
Jerome Coutant 2:123b894b49dd 1220 Points++;
Jerome Coutant 2:123b894b49dd 1221 X2 = Points->X;
Jerome Coutant 2:123b894b49dd 1222 Y2 = Points->Y;
Jerome Coutant 2:123b894b49dd 1223
Jerome Coutant 2:123b894b49dd 1224 FillTriangle(X, X2, X_center, Y, Y2, Y_center);
Jerome Coutant 2:123b894b49dd 1225 FillTriangle(X, X_center, X2, Y, Y_center, Y2);
Jerome Coutant 2:123b894b49dd 1226 FillTriangle(X_center, X2, X, Y_center, Y2, Y);
Jerome Coutant 2:123b894b49dd 1227 }
Jerome Coutant 2:123b894b49dd 1228
Jerome Coutant 2:123b894b49dd 1229 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
Jerome Coutant 2:123b894b49dd 1230 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
Jerome Coutant 2:123b894b49dd 1231 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
Jerome Coutant 2:123b894b49dd 1232 }
Jerome Coutant 2:123b894b49dd 1233
Jerome Coutant 2:123b894b49dd 1234 /**
Jerome Coutant 2:123b894b49dd 1235 * @brief Draws a full ellipse in currently active layer.
Jerome Coutant 2:123b894b49dd 1236 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1237 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1238 * @param XRadius: Ellipse X radius
Jerome Coutant 2:123b894b49dd 1239 * @param YRadius: Ellipse Y radius
Jerome Coutant 2:123b894b49dd 1240 */
Jerome Coutant 2:123b894b49dd 1241 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Jerome Coutant 2:123b894b49dd 1242 {
Jerome Coutant 2:123b894b49dd 1243 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
Jerome Coutant 2:123b894b49dd 1244 float K = 0, rad1 = 0, rad2 = 0;
Jerome Coutant 2:123b894b49dd 1245
Jerome Coutant 2:123b894b49dd 1246 rad1 = XRadius;
Jerome Coutant 2:123b894b49dd 1247 rad2 = YRadius;
Jerome Coutant 2:123b894b49dd 1248
Jerome Coutant 2:123b894b49dd 1249 K = (float)(rad2/rad1);
Jerome Coutant 2:123b894b49dd 1250
Jerome Coutant 2:123b894b49dd 1251 do
Jerome Coutant 2:123b894b49dd 1252 {
Jerome Coutant 2:123b894b49dd 1253 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 2:123b894b49dd 1254 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 2:123b894b49dd 1255
Jerome Coutant 2:123b894b49dd 1256 e2 = err;
Jerome Coutant 2:123b894b49dd 1257 if (e2 <= x)
Jerome Coutant 2:123b894b49dd 1258 {
Jerome Coutant 2:123b894b49dd 1259 err += ++x*2+1;
Jerome Coutant 2:123b894b49dd 1260 if (-y == x && e2 <= y) e2 = 0;
Jerome Coutant 2:123b894b49dd 1261 }
Jerome Coutant 2:123b894b49dd 1262 if (e2 > y) err += ++y*2+1;
Jerome Coutant 2:123b894b49dd 1263 }
Jerome Coutant 2:123b894b49dd 1264 while (y <= 0);
Jerome Coutant 2:123b894b49dd 1265 }
Jerome Coutant 2:123b894b49dd 1266
Jerome Coutant 2:123b894b49dd 1267 /**
Jerome Coutant 2:123b894b49dd 1268 * @brief Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff().
Jerome Coutant 2:123b894b49dd 1269 * Exit DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 2:123b894b49dd 1270 */
Jerome Coutant 2:123b894b49dd 1271 void BSP_LCD_DisplayOn(void)
Jerome Coutant 2:123b894b49dd 1272 {
Jerome Coutant 2:123b894b49dd 1273 /* Send Display on DCS command to display */
Jerome Coutant 2:123b894b49dd 1274 HAL_DSI_ShortWrite(&(hdsi_eval),
Jerome Coutant 2:123b894b49dd 1275 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 2:123b894b49dd 1276 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 2:123b894b49dd 1277 OTM8009A_CMD_DISPON,
Jerome Coutant 2:123b894b49dd 1278 0x00);
Jerome Coutant 2:123b894b49dd 1279
Jerome Coutant 2:123b894b49dd 1280 }
Jerome Coutant 2:123b894b49dd 1281
Jerome Coutant 2:123b894b49dd 1282 /**
Jerome Coutant 2:123b894b49dd 1283 * @brief Switch Off the display.
Jerome Coutant 2:123b894b49dd 1284 * Enter DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 2:123b894b49dd 1285 */
Jerome Coutant 2:123b894b49dd 1286 void BSP_LCD_DisplayOff(void)
Jerome Coutant 2:123b894b49dd 1287 {
Jerome Coutant 2:123b894b49dd 1288 /* Send Display off DCS Command to display */
Jerome Coutant 2:123b894b49dd 1289 HAL_DSI_ShortWrite(&(hdsi_eval),
Jerome Coutant 2:123b894b49dd 1290 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 2:123b894b49dd 1291 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 2:123b894b49dd 1292 OTM8009A_CMD_DISPOFF,
Jerome Coutant 2:123b894b49dd 1293 0x00);
Jerome Coutant 2:123b894b49dd 1294
Jerome Coutant 2:123b894b49dd 1295 }
Jerome Coutant 2:123b894b49dd 1296
Jerome Coutant 2:123b894b49dd 1297 /**
Jerome Coutant 2:123b894b49dd 1298 * @brief DCS or Generic short/long write command
Jerome Coutant 2:123b894b49dd 1299 * @param NbrParams: Number of parameters. It indicates the write command mode:
Jerome Coutant 2:123b894b49dd 1300 * If inferior to 2, a long write command is performed else short.
Jerome Coutant 2:123b894b49dd 1301 * @param pParams: Pointer to parameter values table.
Jerome Coutant 2:123b894b49dd 1302 * @retval HAL status
Jerome Coutant 2:123b894b49dd 1303 */
Jerome Coutant 2:123b894b49dd 1304 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
Jerome Coutant 2:123b894b49dd 1305 {
Jerome Coutant 2:123b894b49dd 1306 if(NbrParams <= 1)
Jerome Coutant 2:123b894b49dd 1307 {
Jerome Coutant 2:123b894b49dd 1308 HAL_DSI_ShortWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
Jerome Coutant 2:123b894b49dd 1309 }
Jerome Coutant 2:123b894b49dd 1310 else
Jerome Coutant 2:123b894b49dd 1311 {
Jerome Coutant 2:123b894b49dd 1312 HAL_DSI_LongWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
Jerome Coutant 2:123b894b49dd 1313 }
Jerome Coutant 2:123b894b49dd 1314 }
Jerome Coutant 2:123b894b49dd 1315
Jerome Coutant 2:123b894b49dd 1316 /*******************************************************************************
Jerome Coutant 2:123b894b49dd 1317 LTDC, DMA2D and DSI BSP Routines
Jerome Coutant 2:123b894b49dd 1318 *******************************************************************************/
Jerome Coutant 2:123b894b49dd 1319 /**
Jerome Coutant 2:123b894b49dd 1320 * @brief Handles DMA2D interrupt request.
Jerome Coutant 2:123b894b49dd 1321 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1322 */
Jerome Coutant 2:123b894b49dd 1323 __weak void BSP_LCD_DMA2D_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1324 {
Jerome Coutant 2:123b894b49dd 1325 HAL_DMA2D_IRQHandler(&hdma2d_eval);
Jerome Coutant 2:123b894b49dd 1326 }
Jerome Coutant 2:123b894b49dd 1327
Jerome Coutant 2:123b894b49dd 1328 /**
Jerome Coutant 2:123b894b49dd 1329 * @brief Handles DSI interrupt request.
Jerome Coutant 2:123b894b49dd 1330 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1331 */
Jerome Coutant 2:123b894b49dd 1332 __weak void BSP_LCD_DSI_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1333 {
Jerome Coutant 2:123b894b49dd 1334 HAL_DSI_IRQHandler(&(hdsi_eval));
Jerome Coutant 2:123b894b49dd 1335 }
Jerome Coutant 2:123b894b49dd 1336
Jerome Coutant 2:123b894b49dd 1337
Jerome Coutant 2:123b894b49dd 1338 /**
Jerome Coutant 2:123b894b49dd 1339 * @brief Handles LTDC interrupt request.
Jerome Coutant 2:123b894b49dd 1340 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1341 */
Jerome Coutant 2:123b894b49dd 1342 __weak void BSP_LCD_LTDC_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1343 {
Jerome Coutant 2:123b894b49dd 1344 HAL_LTDC_IRQHandler(&(hltdc_eval));
Jerome Coutant 2:123b894b49dd 1345 }
Jerome Coutant 2:123b894b49dd 1346
Jerome Coutant 2:123b894b49dd 1347 /**
Jerome Coutant 2:123b894b49dd 1348 * @brief De-Initializes the BSP LCD Msp
Jerome Coutant 2:123b894b49dd 1349 * Application can surcharge if needed this function implementation.
Jerome Coutant 2:123b894b49dd 1350 */
Jerome Coutant 2:123b894b49dd 1351 __weak void BSP_LCD_MspDeInit(void)
Jerome Coutant 2:123b894b49dd 1352 {
Jerome Coutant 2:123b894b49dd 1353 /** @brief Disable IRQ of LTDC IP */
Jerome Coutant 2:123b894b49dd 1354 HAL_NVIC_DisableIRQ(LTDC_IRQn);
Jerome Coutant 2:123b894b49dd 1355
Jerome Coutant 2:123b894b49dd 1356 /** @brief Disable IRQ of DMA2D IP */
Jerome Coutant 2:123b894b49dd 1357 HAL_NVIC_DisableIRQ(DMA2D_IRQn);
Jerome Coutant 2:123b894b49dd 1358
Jerome Coutant 2:123b894b49dd 1359 /** @brief Disable IRQ of DSI IP */
Jerome Coutant 2:123b894b49dd 1360 HAL_NVIC_DisableIRQ(DSI_IRQn);
Jerome Coutant 2:123b894b49dd 1361
Jerome Coutant 2:123b894b49dd 1362 /** @brief Force and let in reset state LTDC, DMA2D and DSI Host + Wrapper IPs */
Jerome Coutant 2:123b894b49dd 1363 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1364 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1365 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1366
Jerome Coutant 2:123b894b49dd 1367 /** @brief Disable the LTDC, DMA2D and DSI Host and Wrapper clocks */
Jerome Coutant 2:123b894b49dd 1368 __HAL_RCC_LTDC_CLK_DISABLE();
Jerome Coutant 2:123b894b49dd 1369 __HAL_RCC_DMA2D_CLK_DISABLE();
Jerome Coutant 2:123b894b49dd 1370 __HAL_RCC_DSI_CLK_DISABLE();
Jerome Coutant 2:123b894b49dd 1371 }
Jerome Coutant 2:123b894b49dd 1372
Jerome Coutant 2:123b894b49dd 1373 /**
Jerome Coutant 2:123b894b49dd 1374 * @brief Initialize the BSP LCD Msp.
Jerome Coutant 2:123b894b49dd 1375 * Application can surcharge if needed this function implementation
Jerome Coutant 2:123b894b49dd 1376 */
Jerome Coutant 2:123b894b49dd 1377 __weak void BSP_LCD_MspInit(void)
Jerome Coutant 2:123b894b49dd 1378 {
Jerome Coutant 2:123b894b49dd 1379 /** @brief Enable the LTDC clock */
Jerome Coutant 2:123b894b49dd 1380 __HAL_RCC_LTDC_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 1381
Jerome Coutant 2:123b894b49dd 1382 /** @brief Toggle Sw reset of LTDC IP */
Jerome Coutant 2:123b894b49dd 1383 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1384 __HAL_RCC_LTDC_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 1385
Jerome Coutant 2:123b894b49dd 1386 /** @brief Enable the DMA2D clock */
Jerome Coutant 2:123b894b49dd 1387 __HAL_RCC_DMA2D_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 1388
Jerome Coutant 2:123b894b49dd 1389 /** @brief Toggle Sw reset of DMA2D IP */
Jerome Coutant 2:123b894b49dd 1390 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1391 __HAL_RCC_DMA2D_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 1392
Jerome Coutant 2:123b894b49dd 1393 /** @brief Enable DSI Host and wrapper clocks */
Jerome Coutant 2:123b894b49dd 1394 __HAL_RCC_DSI_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 1395
Jerome Coutant 2:123b894b49dd 1396 /** @brief Soft Reset the DSI Host and wrapper */
Jerome Coutant 2:123b894b49dd 1397 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1398 __HAL_RCC_DSI_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 1399
Jerome Coutant 2:123b894b49dd 1400 /** @brief NVIC configuration for LTDC interrupt that is now enabled */
Jerome Coutant 2:123b894b49dd 1401 HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
Jerome Coutant 2:123b894b49dd 1402 HAL_NVIC_EnableIRQ(LTDC_IRQn);
Jerome Coutant 2:123b894b49dd 1403
Jerome Coutant 2:123b894b49dd 1404 /** @brief NVIC configuration for DMA2D interrupt that is now enabled */
Jerome Coutant 2:123b894b49dd 1405 HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0);
Jerome Coutant 2:123b894b49dd 1406 HAL_NVIC_EnableIRQ(DMA2D_IRQn);
Jerome Coutant 2:123b894b49dd 1407
Jerome Coutant 2:123b894b49dd 1408 /** @brief NVIC configuration for DSI interrupt that is now enabled */
Jerome Coutant 2:123b894b49dd 1409 HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
Jerome Coutant 2:123b894b49dd 1410 HAL_NVIC_EnableIRQ(DSI_IRQn);
Jerome Coutant 2:123b894b49dd 1411 }
Jerome Coutant 2:123b894b49dd 1412
Jerome Coutant 2:123b894b49dd 1413 /**
Jerome Coutant 2:123b894b49dd 1414 * @brief This function handles LTDC Error interrupt Handler.
Jerome Coutant 2:123b894b49dd 1415 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1416 */
Jerome Coutant 2:123b894b49dd 1417
Jerome Coutant 2:123b894b49dd 1418 __weak void BSP_LCD_LTDC_ER_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1419 {
Jerome Coutant 2:123b894b49dd 1420 HAL_LTDC_IRQHandler(&(hltdc_eval));
Jerome Coutant 2:123b894b49dd 1421 }
Jerome Coutant 2:123b894b49dd 1422
Jerome Coutant 2:123b894b49dd 1423
Jerome Coutant 2:123b894b49dd 1424 /**
Jerome Coutant 2:123b894b49dd 1425 * @brief Draws a pixel on LCD.
Jerome Coutant 2:123b894b49dd 1426 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1427 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1428 * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8)
Jerome Coutant 2:123b894b49dd 1429 */
Jerome Coutant 2:123b894b49dd 1430 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
Jerome Coutant 2:123b894b49dd 1431 {
Jerome Coutant 2:123b894b49dd 1432 /* Write data value to all SDRAM memory */
Jerome Coutant 2:123b894b49dd 1433 *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
Jerome Coutant 2:123b894b49dd 1434 }
Jerome Coutant 2:123b894b49dd 1435
Jerome Coutant 2:123b894b49dd 1436
Jerome Coutant 2:123b894b49dd 1437 /**
Jerome Coutant 2:123b894b49dd 1438 * @brief Draws a character on LCD.
Jerome Coutant 2:123b894b49dd 1439 * @param Xpos: Line where to display the character shape
Jerome Coutant 2:123b894b49dd 1440 * @param Ypos: Start column address
Jerome Coutant 2:123b894b49dd 1441 * @param c: Pointer to the character data
Jerome Coutant 2:123b894b49dd 1442 */
Jerome Coutant 2:123b894b49dd 1443 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
Jerome Coutant 2:123b894b49dd 1444 {
Jerome Coutant 2:123b894b49dd 1445 uint32_t i = 0, j = 0;
Jerome Coutant 2:123b894b49dd 1446 uint16_t height, width;
Jerome Coutant 2:123b894b49dd 1447 uint8_t offset;
Jerome Coutant 2:123b894b49dd 1448 uint8_t *pchar;
Jerome Coutant 2:123b894b49dd 1449 uint32_t line;
Jerome Coutant 2:123b894b49dd 1450
Jerome Coutant 2:123b894b49dd 1451 height = DrawProp[ActiveLayer].pFont->Height;
Jerome Coutant 2:123b894b49dd 1452 width = DrawProp[ActiveLayer].pFont->Width;
Jerome Coutant 2:123b894b49dd 1453
Jerome Coutant 2:123b894b49dd 1454 offset = 8 *((width + 7)/8) - width ;
Jerome Coutant 2:123b894b49dd 1455
Jerome Coutant 2:123b894b49dd 1456 for(i = 0; i < height; i++)
Jerome Coutant 2:123b894b49dd 1457 {
Jerome Coutant 2:123b894b49dd 1458 pchar = ((uint8_t *)c + (width + 7)/8 * i);
Jerome Coutant 2:123b894b49dd 1459
Jerome Coutant 2:123b894b49dd 1460 switch(((width + 7)/8))
Jerome Coutant 2:123b894b49dd 1461 {
Jerome Coutant 2:123b894b49dd 1462
Jerome Coutant 2:123b894b49dd 1463 case 1:
Jerome Coutant 2:123b894b49dd 1464 line = pchar[0];
Jerome Coutant 2:123b894b49dd 1465 break;
Jerome Coutant 2:123b894b49dd 1466
Jerome Coutant 2:123b894b49dd 1467 case 2:
Jerome Coutant 2:123b894b49dd 1468 line = (pchar[0]<< 8) | pchar[1];
Jerome Coutant 2:123b894b49dd 1469 break;
Jerome Coutant 2:123b894b49dd 1470
Jerome Coutant 2:123b894b49dd 1471 case 3:
Jerome Coutant 2:123b894b49dd 1472 default:
Jerome Coutant 2:123b894b49dd 1473 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
Jerome Coutant 2:123b894b49dd 1474 break;
Jerome Coutant 2:123b894b49dd 1475 }
Jerome Coutant 2:123b894b49dd 1476
Jerome Coutant 2:123b894b49dd 1477 for (j = 0; j < width; j++)
Jerome Coutant 2:123b894b49dd 1478 {
Jerome Coutant 2:123b894b49dd 1479 if(line & (1 << (width- j + offset- 1)))
Jerome Coutant 2:123b894b49dd 1480 {
Jerome Coutant 2:123b894b49dd 1481 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1482 }
Jerome Coutant 2:123b894b49dd 1483 else
Jerome Coutant 2:123b894b49dd 1484 {
Jerome Coutant 2:123b894b49dd 1485 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
Jerome Coutant 2:123b894b49dd 1486 }
Jerome Coutant 2:123b894b49dd 1487 }
Jerome Coutant 2:123b894b49dd 1488 Ypos++;
Jerome Coutant 2:123b894b49dd 1489 }
Jerome Coutant 2:123b894b49dd 1490 }
Jerome Coutant 2:123b894b49dd 1491
Jerome Coutant 2:123b894b49dd 1492 /**
Jerome Coutant 2:123b894b49dd 1493 * @brief Fills a triangle (between 3 points).
Jerome Coutant 2:123b894b49dd 1494 * @param x1: Point 1 X position
Jerome Coutant 2:123b894b49dd 1495 * @param y1: Point 1 Y position
Jerome Coutant 2:123b894b49dd 1496 * @param x2: Point 2 X position
Jerome Coutant 2:123b894b49dd 1497 * @param y2: Point 2 Y position
Jerome Coutant 2:123b894b49dd 1498 * @param x3: Point 3 X position
Jerome Coutant 2:123b894b49dd 1499 * @param y3: Point 3 Y position
Jerome Coutant 2:123b894b49dd 1500 */
Jerome Coutant 2:123b894b49dd 1501 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
Jerome Coutant 2:123b894b49dd 1502 {
Jerome Coutant 2:123b894b49dd 1503 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
Jerome Coutant 2:123b894b49dd 1504 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
Jerome Coutant 2:123b894b49dd 1505 curpixel = 0;
Jerome Coutant 2:123b894b49dd 1506
Jerome Coutant 2:123b894b49dd 1507 deltax = ABS(x2 - x1); /* The difference between the x's */
Jerome Coutant 2:123b894b49dd 1508 deltay = ABS(y2 - y1); /* The difference between the y's */
Jerome Coutant 2:123b894b49dd 1509 x = x1; /* Start x off at the first pixel */
Jerome Coutant 2:123b894b49dd 1510 y = y1; /* Start y off at the first pixel */
Jerome Coutant 2:123b894b49dd 1511
Jerome Coutant 2:123b894b49dd 1512 if (x2 >= x1) /* The x-values are increasing */
Jerome Coutant 2:123b894b49dd 1513 {
Jerome Coutant 2:123b894b49dd 1514 xinc1 = 1;
Jerome Coutant 2:123b894b49dd 1515 xinc2 = 1;
Jerome Coutant 2:123b894b49dd 1516 }
Jerome Coutant 2:123b894b49dd 1517 else /* The x-values are decreasing */
Jerome Coutant 2:123b894b49dd 1518 {
Jerome Coutant 2:123b894b49dd 1519 xinc1 = -1;
Jerome Coutant 2:123b894b49dd 1520 xinc2 = -1;
Jerome Coutant 2:123b894b49dd 1521 }
Jerome Coutant 2:123b894b49dd 1522
Jerome Coutant 2:123b894b49dd 1523 if (y2 >= y1) /* The y-values are increasing */
Jerome Coutant 2:123b894b49dd 1524 {
Jerome Coutant 2:123b894b49dd 1525 yinc1 = 1;
Jerome Coutant 2:123b894b49dd 1526 yinc2 = 1;
Jerome Coutant 2:123b894b49dd 1527 }
Jerome Coutant 2:123b894b49dd 1528 else /* The y-values are decreasing */
Jerome Coutant 2:123b894b49dd 1529 {
Jerome Coutant 2:123b894b49dd 1530 yinc1 = -1;
Jerome Coutant 2:123b894b49dd 1531 yinc2 = -1;
Jerome Coutant 2:123b894b49dd 1532 }
Jerome Coutant 2:123b894b49dd 1533
Jerome Coutant 2:123b894b49dd 1534 if (deltax >= deltay) /* There is at least one x-value for every y-value */
Jerome Coutant 2:123b894b49dd 1535 {
Jerome Coutant 2:123b894b49dd 1536 xinc1 = 0; /* Don't change the x when numerator >= denominator */
Jerome Coutant 2:123b894b49dd 1537 yinc2 = 0; /* Don't change the y for every iteration */
Jerome Coutant 2:123b894b49dd 1538 den = deltax;
Jerome Coutant 2:123b894b49dd 1539 num = deltax / 2;
Jerome Coutant 2:123b894b49dd 1540 numadd = deltay;
Jerome Coutant 2:123b894b49dd 1541 numpixels = deltax; /* There are more x-values than y-values */
Jerome Coutant 2:123b894b49dd 1542 }
Jerome Coutant 2:123b894b49dd 1543 else /* There is at least one y-value for every x-value */
Jerome Coutant 2:123b894b49dd 1544 {
Jerome Coutant 2:123b894b49dd 1545 xinc2 = 0; /* Don't change the x for every iteration */
Jerome Coutant 2:123b894b49dd 1546 yinc1 = 0; /* Don't change the y when numerator >= denominator */
Jerome Coutant 2:123b894b49dd 1547 den = deltay;
Jerome Coutant 2:123b894b49dd 1548 num = deltay / 2;
Jerome Coutant 2:123b894b49dd 1549 numadd = deltax;
Jerome Coutant 2:123b894b49dd 1550 numpixels = deltay; /* There are more y-values than x-values */
Jerome Coutant 2:123b894b49dd 1551 }
Jerome Coutant 2:123b894b49dd 1552
Jerome Coutant 2:123b894b49dd 1553 for (curpixel = 0; curpixel <= numpixels; curpixel++)
Jerome Coutant 2:123b894b49dd 1554 {
Jerome Coutant 2:123b894b49dd 1555 BSP_LCD_DrawLine(x, y, x3, y3);
Jerome Coutant 2:123b894b49dd 1556
Jerome Coutant 2:123b894b49dd 1557 num += numadd; /* Increase the numerator by the top of the fraction */
Jerome Coutant 2:123b894b49dd 1558 if (num >= den) /* Check if numerator >= denominator */
Jerome Coutant 2:123b894b49dd 1559 {
Jerome Coutant 2:123b894b49dd 1560 num -= den; /* Calculate the new numerator value */
Jerome Coutant 2:123b894b49dd 1561 x += xinc1; /* Change the x as appropriate */
Jerome Coutant 2:123b894b49dd 1562 y += yinc1; /* Change the y as appropriate */
Jerome Coutant 2:123b894b49dd 1563 }
Jerome Coutant 2:123b894b49dd 1564 x += xinc2; /* Change the x as appropriate */
Jerome Coutant 2:123b894b49dd 1565 y += yinc2; /* Change the y as appropriate */
Jerome Coutant 2:123b894b49dd 1566 }
Jerome Coutant 2:123b894b49dd 1567 }
Jerome Coutant 2:123b894b49dd 1568
Jerome Coutant 2:123b894b49dd 1569 /**
Jerome Coutant 2:123b894b49dd 1570 * @brief Fills a buffer.
Jerome Coutant 2:123b894b49dd 1571 * @param LayerIndex: Layer index
Jerome Coutant 2:123b894b49dd 1572 * @param pDst: Pointer to destination buffer
Jerome Coutant 2:123b894b49dd 1573 * @param xSize: Buffer width
Jerome Coutant 2:123b894b49dd 1574 * @param ySize: Buffer height
Jerome Coutant 2:123b894b49dd 1575 * @param OffLine: Offset
Jerome Coutant 2:123b894b49dd 1576 * @param ColorIndex: Color index
Jerome Coutant 2:123b894b49dd 1577 */
Jerome Coutant 2:123b894b49dd 1578 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
Jerome Coutant 2:123b894b49dd 1579 {
Jerome Coutant 2:123b894b49dd 1580 /* Register to memory mode with ARGB8888 as color Mode */
Jerome Coutant 2:123b894b49dd 1581 hdma2d_eval.Init.Mode = DMA2D_R2M;
Jerome Coutant 2:123b894b49dd 1582 hdma2d_eval.Init.ColorMode = DMA2D_ARGB8888;
Jerome Coutant 2:123b894b49dd 1583 hdma2d_eval.Init.OutputOffset = OffLine;
Jerome Coutant 2:123b894b49dd 1584
Jerome Coutant 2:123b894b49dd 1585 hdma2d_eval.Instance = DMA2D;
Jerome Coutant 2:123b894b49dd 1586
Jerome Coutant 2:123b894b49dd 1587 /* DMA2D Initialization */
Jerome Coutant 2:123b894b49dd 1588 if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1589 {
Jerome Coutant 2:123b894b49dd 1590 if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, LayerIndex) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1591 {
Jerome Coutant 2:123b894b49dd 1592 if (HAL_DMA2D_Start(&hdma2d_eval, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1593 {
Jerome Coutant 2:123b894b49dd 1594 /* Polling For DMA transfer */
Jerome Coutant 2:123b894b49dd 1595 HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
Jerome Coutant 2:123b894b49dd 1596 }
Jerome Coutant 2:123b894b49dd 1597 }
Jerome Coutant 2:123b894b49dd 1598 }
Jerome Coutant 2:123b894b49dd 1599 }
Jerome Coutant 2:123b894b49dd 1600
Jerome Coutant 2:123b894b49dd 1601 /**
Jerome Coutant 2:123b894b49dd 1602 * @brief Converts a line to an ARGB8888 pixel format.
Jerome Coutant 2:123b894b49dd 1603 * @param pSrc: Pointer to source buffer
Jerome Coutant 2:123b894b49dd 1604 * @param pDst: Output color
Jerome Coutant 2:123b894b49dd 1605 * @param xSize: Buffer width
Jerome Coutant 2:123b894b49dd 1606 * @param ColorMode: Input color mode
Jerome Coutant 2:123b894b49dd 1607 */
Jerome Coutant 2:123b894b49dd 1608 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
Jerome Coutant 2:123b894b49dd 1609 {
Jerome Coutant 2:123b894b49dd 1610 /* Configure the DMA2D Mode, Color Mode and output offset */
Jerome Coutant 2:123b894b49dd 1611 hdma2d_eval.Init.Mode = DMA2D_M2M_PFC;
Jerome Coutant 2:123b894b49dd 1612 hdma2d_eval.Init.ColorMode = DMA2D_ARGB8888;
Jerome Coutant 2:123b894b49dd 1613 hdma2d_eval.Init.OutputOffset = 0;
Jerome Coutant 2:123b894b49dd 1614
Jerome Coutant 2:123b894b49dd 1615 /* Foreground Configuration */
Jerome Coutant 2:123b894b49dd 1616 hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
Jerome Coutant 2:123b894b49dd 1617 hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF;
Jerome Coutant 2:123b894b49dd 1618 hdma2d_eval.LayerCfg[1].InputColorMode = ColorMode;
Jerome Coutant 2:123b894b49dd 1619 hdma2d_eval.LayerCfg[1].InputOffset = 0;
Jerome Coutant 2:123b894b49dd 1620
Jerome Coutant 2:123b894b49dd 1621 hdma2d_eval.Instance = DMA2D;
Jerome Coutant 2:123b894b49dd 1622
Jerome Coutant 2:123b894b49dd 1623 /* DMA2D Initialization */
Jerome Coutant 2:123b894b49dd 1624 if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1625 {
Jerome Coutant 2:123b894b49dd 1626 if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1627 {
Jerome Coutant 2:123b894b49dd 1628 if (HAL_DMA2D_Start(&hdma2d_eval, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1629 {
Jerome Coutant 2:123b894b49dd 1630 /* Polling For DMA transfer */
Jerome Coutant 2:123b894b49dd 1631 HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
Jerome Coutant 2:123b894b49dd 1632 }
Jerome Coutant 2:123b894b49dd 1633 }
Jerome Coutant 2:123b894b49dd 1634 }
Jerome Coutant 2:123b894b49dd 1635 }
Jerome Coutant 2:123b894b49dd 1636
Jerome Coutant 2:123b894b49dd 1637 /**
Jerome Coutant 2:123b894b49dd 1638 * @}
Jerome Coutant 2:123b894b49dd 1639 */
Jerome Coutant 2:123b894b49dd 1640
Jerome Coutant 2:123b894b49dd 1641 /**
Jerome Coutant 2:123b894b49dd 1642 * @}
Jerome Coutant 2:123b894b49dd 1643 */
Jerome Coutant 2:123b894b49dd 1644
Jerome Coutant 2:123b894b49dd 1645 /**
Jerome Coutant 2:123b894b49dd 1646 * @}
Jerome Coutant 2:123b894b49dd 1647 */
Jerome Coutant 2:123b894b49dd 1648
Jerome Coutant 2:123b894b49dd 1649 /**
Jerome Coutant 2:123b894b49dd 1650 * @}
Jerome Coutant 2:123b894b49dd 1651 */
Jerome Coutant 2:123b894b49dd 1652
Jerome Coutant 2:123b894b49dd 1653 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/