STM32F469NI Discovery board drivers

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

Committer:
aa6164
Date:
Wed Jun 09 12:45:23 2021 +0000
Revision:
4:27609b3a44ed
Parent:
3:3cdfcc4f7c9d
Updated wait_ms() to thread_sleep_for() for Mbed OS 6+

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 * @brief This file includes the driver for Liquid Crystal Display (LCD) module
Jerome Coutant 2:123b894b49dd 6 * mounted on STM32469I-Discovery evaluation board.
Jerome Coutant 2:123b894b49dd 7 ******************************************************************************
Jerome Coutant 2:123b894b49dd 8 * @attention
Jerome Coutant 2:123b894b49dd 9 *
Jerome Coutant 2:123b894b49dd 10 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
Jerome Coutant 2:123b894b49dd 11 *
Jerome Coutant 2:123b894b49dd 12 * Redistribution and use in source and binary forms, with or without modification,
Jerome Coutant 2:123b894b49dd 13 * are permitted provided that the following conditions are met:
Jerome Coutant 2:123b894b49dd 14 * 1. Redistributions of source code must retain the above copyright notice,
Jerome Coutant 2:123b894b49dd 15 * this list of conditions and the following disclaimer.
Jerome Coutant 2:123b894b49dd 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
Jerome Coutant 2:123b894b49dd 17 * this list of conditions and the following disclaimer in the documentation
Jerome Coutant 2:123b894b49dd 18 * and/or other materials provided with the distribution.
Jerome Coutant 2:123b894b49dd 19 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Jerome Coutant 2:123b894b49dd 20 * may be used to endorse or promote products derived from this software
Jerome Coutant 2:123b894b49dd 21 * without specific prior written permission.
Jerome Coutant 2:123b894b49dd 22 *
Jerome Coutant 2:123b894b49dd 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Jerome Coutant 2:123b894b49dd 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Jerome Coutant 2:123b894b49dd 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jerome Coutant 2:123b894b49dd 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Jerome Coutant 2:123b894b49dd 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Jerome Coutant 2:123b894b49dd 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Jerome Coutant 2:123b894b49dd 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Jerome Coutant 2:123b894b49dd 30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Jerome Coutant 2:123b894b49dd 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Jerome Coutant 2:123b894b49dd 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jerome Coutant 2:123b894b49dd 33 *
Jerome Coutant 2:123b894b49dd 34 ******************************************************************************
Jerome Coutant 2:123b894b49dd 35 */
Jerome Coutant 2:123b894b49dd 36
Jerome Coutant 2:123b894b49dd 37 /* File Info: ------------------------------------------------------------------
Jerome Coutant 2:123b894b49dd 38 User NOTES
Jerome Coutant 2:123b894b49dd 39 1. How To use this driver:
Jerome Coutant 2:123b894b49dd 40 --------------------------
Jerome Coutant 2:123b894b49dd 41 - This driver is used to drive directly in video mode a LCD TFT using the DSI interface.
Jerome Coutant 2:123b894b49dd 42 The following IPs are implied : DSI Host IP block working
Jerome Coutant 2:123b894b49dd 43 in conjunction to the LTDC controller.
Jerome Coutant 2:123b894b49dd 44 - This driver is linked by construction to LCD KoD mounted on board MB1166.
Jerome Coutant 2:123b894b49dd 45
Jerome Coutant 2:123b894b49dd 46 2. Driver description:
Jerome Coutant 2:123b894b49dd 47 ---------------------
Jerome Coutant 2:123b894b49dd 48 + Initialization steps:
Jerome Coutant 2:123b894b49dd 49 o Initialize the LCD using the BSP_LCD_Init() function.
Jerome Coutant 2:123b894b49dd 50 o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
Jerome Coutant 2:123b894b49dd 51 o Enable the LCD display using the BSP_LCD_DisplayOn() function.
Jerome Coutant 2:123b894b49dd 52
Jerome Coutant 2:123b894b49dd 53 + Options
Jerome Coutant 2:123b894b49dd 54 o Configure and enable the color keying functionality using the
Jerome Coutant 2:123b894b49dd 55 BSP_LCD_SetColorKeying() function.
Jerome Coutant 2:123b894b49dd 56 o Modify in the fly the transparency and/or the frame buffer address
Jerome Coutant 2:123b894b49dd 57 using the following functions:
Jerome Coutant 2:123b894b49dd 58 - BSP_LCD_SetTransparency()
Jerome Coutant 2:123b894b49dd 59 - BSP_LCD_SetLayerAddress()
Jerome Coutant 2:123b894b49dd 60
Jerome Coutant 2:123b894b49dd 61 + Display on LCD
Jerome Coutant 2:123b894b49dd 62 o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string
Jerome Coutant 2:123b894b49dd 63 line using the BSP_LCD_ClearStringLine() function.
Jerome Coutant 2:123b894b49dd 64 o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
Jerome Coutant 2:123b894b49dd 65 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 2:123b894b49dd 66 o Display a string line on the specified position (x,y in pixel) and align mode
Jerome Coutant 2:123b894b49dd 67 using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 2:123b894b49dd 68 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
Jerome Coutant 2:123b894b49dd 69 on LCD using the available set of functions.
Jerome Coutant 2:123b894b49dd 70
Jerome Coutant 2:123b894b49dd 71 ------------------------------------------------------------------------------*/
Jerome Coutant 2:123b894b49dd 72
Jerome Coutant 2:123b894b49dd 73 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 2:123b894b49dd 74 #include "stm32469i_discovery_lcd.h"
Jerome Coutant 2:123b894b49dd 75 #include "../Fonts/fonts.h"
Jerome Coutant 2:123b894b49dd 76 //#include "../../../Utilities/Fonts/font24.c"
Jerome Coutant 2:123b894b49dd 77 //#include "../../../Utilities/Fonts/font20.c"
Jerome Coutant 2:123b894b49dd 78 //#include "../../../Utilities/Fonts/font16.c"
Jerome Coutant 2:123b894b49dd 79 //#include "../../../Utilities/Fonts/font12.c"
Jerome Coutant 2:123b894b49dd 80 //#include "../../../Utilities/Fonts/font8.c"
Jerome Coutant 2:123b894b49dd 81
Jerome Coutant 2:123b894b49dd 82 /** @addtogroup BSP
Jerome Coutant 2:123b894b49dd 83 * @{
Jerome Coutant 2:123b894b49dd 84 */
Jerome Coutant 2:123b894b49dd 85
Jerome Coutant 2:123b894b49dd 86 /** @addtogroup STM32469I_Discovery
Jerome Coutant 2:123b894b49dd 87 * @{
Jerome Coutant 2:123b894b49dd 88 */
Jerome Coutant 2:123b894b49dd 89
Jerome Coutant 2:123b894b49dd 90 /** @defgroup STM32469I-Discovery_LCD STM32469I Discovery LCD
Jerome Coutant 2:123b894b49dd 91 * @{
Jerome Coutant 2:123b894b49dd 92 */
Jerome Coutant 2:123b894b49dd 93
Jerome Coutant 2:123b894b49dd 94 /** @defgroup STM32469I-Discovery_LCD_Private_TypesDefinitions STM32469I Discovery LCD Private TypesDefinitions
Jerome Coutant 2:123b894b49dd 95 * @{
Jerome Coutant 2:123b894b49dd 96 */
Jerome Coutant 2:123b894b49dd 97 static DSI_VidCfgTypeDef hdsivideo_handle;
Jerome Coutant 2:123b894b49dd 98
Jerome Coutant 2:123b894b49dd 99 /**
Jerome Coutant 2:123b894b49dd 100 * @}
Jerome Coutant 2:123b894b49dd 101 */
Jerome Coutant 2:123b894b49dd 102
Jerome Coutant 2:123b894b49dd 103 /** @defgroup STM32469I-Discovery_LCD_Private_Defines STM32469I Discovery LCD Private Defines
Jerome Coutant 2:123b894b49dd 104 * @{
Jerome Coutant 2:123b894b49dd 105 */
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 /** @defgroup STM32469I-Discovery_LCD_Private_Macros STM32469I Discovery LCD Private Macros
Jerome Coutant 2:123b894b49dd 111 * @{
Jerome Coutant 2:123b894b49dd 112 */
Jerome Coutant 2:123b894b49dd 113 #define ABS(X) ((X) > 0 ? (X) : -(X))
Jerome Coutant 2:123b894b49dd 114
Jerome Coutant 2:123b894b49dd 115 #define POLY_X(Z) ((int32_t)((Points + (Z))->X))
Jerome Coutant 2:123b894b49dd 116 #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y))
Jerome Coutant 2:123b894b49dd 117 /**
Jerome Coutant 2:123b894b49dd 118 * @}
Jerome Coutant 2:123b894b49dd 119 */
Jerome Coutant 2:123b894b49dd 120
Jerome Coutant 2:123b894b49dd 121 /** @defgroup STM32469I-Discovery_LCD_Exported_Variables STM32469I Discovery LCD Exported Variables
Jerome Coutant 2:123b894b49dd 122 * @{
Jerome Coutant 2:123b894b49dd 123 */
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 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables
Jerome Coutant 2:123b894b49dd 131 * @{
Jerome Coutant 2:123b894b49dd 132 */
Jerome Coutant 2:123b894b49dd 133
Jerome Coutant 2:123b894b49dd 134 DMA2D_HandleTypeDef hdma2d_eval;
Jerome Coutant 2:123b894b49dd 135 LTDC_HandleTypeDef hltdc_eval;
Jerome Coutant 2:123b894b49dd 136 DSI_HandleTypeDef hdsi_eval;
Jerome Coutant 2:123b894b49dd 137 uint32_t lcd_x_size = OTM8009A_800X480_WIDTH;
Jerome Coutant 2:123b894b49dd 138 uint32_t lcd_y_size = OTM8009A_800X480_HEIGHT;
Jerome Coutant 2:123b894b49dd 139
Jerome Coutant 2:123b894b49dd 140 /**
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 /** @defgroup STM32469I-Discovery_LCD_Private_Variables STM32469I Discovery LCD Private Variables
Jerome Coutant 2:123b894b49dd 146 * @{
Jerome Coutant 2:123b894b49dd 147 */
Jerome Coutant 2:123b894b49dd 148
Jerome Coutant 2:123b894b49dd 149 /**
Jerome Coutant 2:123b894b49dd 150 * @brief Default Active LTDC Layer in which drawing is made is LTDC Layer Background
Jerome Coutant 2:123b894b49dd 151 */
Jerome Coutant 2:123b894b49dd 152 static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
Jerome Coutant 2:123b894b49dd 153
Jerome Coutant 2:123b894b49dd 154 /**
Jerome Coutant 2:123b894b49dd 155 * @brief Current Drawing Layer properties variable
Jerome Coutant 2:123b894b49dd 156 */
Jerome Coutant 2:123b894b49dd 157 static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER];
Jerome Coutant 2:123b894b49dd 158 /**
Jerome Coutant 2:123b894b49dd 159 * @}
Jerome Coutant 2:123b894b49dd 160 */
Jerome Coutant 2:123b894b49dd 161
Jerome Coutant 2:123b894b49dd 162 /** @defgroup STM32469I-Discovery_LCD_Private_FunctionPrototypes STM32469I Discovery LCD Private FunctionPrototypes
Jerome Coutant 2:123b894b49dd 163 * @{
Jerome Coutant 2:123b894b49dd 164 */
Jerome Coutant 2:123b894b49dd 165 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
Jerome Coutant 2:123b894b49dd 166 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 167 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 168 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
Jerome Coutant 2:123b894b49dd 169 /**
Jerome Coutant 2:123b894b49dd 170 * @}
Jerome Coutant 2:123b894b49dd 171 */
Jerome Coutant 2:123b894b49dd 172
Jerome Coutant 2:123b894b49dd 173 /** @defgroup STM32469I-Discovery_LCD_Exported_Functions STM32469I Discovery LCD Exported Functions
Jerome Coutant 2:123b894b49dd 174 * @{
Jerome Coutant 2:123b894b49dd 175 */
Jerome Coutant 2:123b894b49dd 176
Jerome Coutant 2:123b894b49dd 177 /**
Jerome Coutant 2:123b894b49dd 178 * @brief Initializes the DSI LCD.
Jerome Coutant 2:123b894b49dd 179 * @retval LCD state
Jerome Coutant 2:123b894b49dd 180 */
Jerome Coutant 2:123b894b49dd 181 uint8_t BSP_LCD_Init(void)
Jerome Coutant 2:123b894b49dd 182 {
Jerome Coutant 2:123b894b49dd 183 return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE));
Jerome Coutant 2:123b894b49dd 184 }
Jerome Coutant 2:123b894b49dd 185
Jerome Coutant 2:123b894b49dd 186 /**
Jerome Coutant 2:123b894b49dd 187 * @brief Initializes the DSI LCD.
Jerome Coutant 2:123b894b49dd 188 * The ititialization is done as below:
Jerome Coutant 2:123b894b49dd 189 * - DSI PLL ititialization
Jerome Coutant 2:123b894b49dd 190 * - DSI ititialization
Jerome Coutant 2:123b894b49dd 191 * - LTDC ititialization
Jerome Coutant 2:123b894b49dd 192 * - OTM8009A LCD Display IC Driver ititialization
Jerome Coutant 2:123b894b49dd 193 * @retval LCD state
Jerome Coutant 2:123b894b49dd 194 */
Jerome Coutant 2:123b894b49dd 195 uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation)
Jerome Coutant 2:123b894b49dd 196 {
Jerome Coutant 2:123b894b49dd 197 DSI_PLLInitTypeDef dsiPllInit;
Jerome Coutant 2:123b894b49dd 198 DSI_PHY_TimerTypeDef PhyTimings;
Jerome Coutant 2:123b894b49dd 199 static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
Jerome Coutant 2:123b894b49dd 200 uint32_t LcdClock = 27429; /*!< LcdClk = 27429 kHz */
Jerome Coutant 2:123b894b49dd 201
Jerome Coutant 2:123b894b49dd 202 uint32_t laneByteClk_kHz = 0;
Jerome Coutant 2:123b894b49dd 203 uint32_t VSA; /*!< Vertical start active time in units of lines */
Jerome Coutant 2:123b894b49dd 204 uint32_t VBP; /*!< Vertical Back Porch time in units of lines */
Jerome Coutant 2:123b894b49dd 205 uint32_t VFP; /*!< Vertical Front Porch time in units of lines */
Jerome Coutant 2:123b894b49dd 206 uint32_t VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */
Jerome Coutant 2:123b894b49dd 207 uint32_t HSA; /*!< Horizontal start active time in units of lcdClk */
Jerome Coutant 2:123b894b49dd 208 uint32_t HBP; /*!< Horizontal Back Porch time in units of lcdClk */
Jerome Coutant 2:123b894b49dd 209 uint32_t HFP; /*!< Horizontal Front Porch time in units of lcdClk */
Jerome Coutant 2:123b894b49dd 210 uint32_t HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */
Jerome Coutant 2:123b894b49dd 211
Jerome Coutant 2:123b894b49dd 212
Jerome Coutant 2:123b894b49dd 213 /* Toggle Hardware Reset of the DSI LCD using
Jerome Coutant 2:123b894b49dd 214 * its XRES signal (active low) */
Jerome Coutant 2:123b894b49dd 215 BSP_LCD_Reset();
Jerome Coutant 2:123b894b49dd 216
Jerome Coutant 2:123b894b49dd 217 /* Call first MSP Initialize only in case of first initialization
Jerome Coutant 2:123b894b49dd 218 * This will set IP blocks LTDC, DSI and DMA2D
Jerome Coutant 2:123b894b49dd 219 * - out of reset
Jerome Coutant 2:123b894b49dd 220 * - clocked
Jerome Coutant 2:123b894b49dd 221 * - NVIC IRQ related to IP blocks enabled
Jerome Coutant 2:123b894b49dd 222 */
Jerome Coutant 2:123b894b49dd 223 BSP_LCD_MspInit();
Jerome Coutant 2:123b894b49dd 224
Jerome Coutant 2:123b894b49dd 225 /*************************DSI Initialization***********************************/
Jerome Coutant 2:123b894b49dd 226
Jerome Coutant 2:123b894b49dd 227 /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
Jerome Coutant 2:123b894b49dd 228 hdsi_eval.Instance = DSI;
Jerome Coutant 2:123b894b49dd 229
Jerome Coutant 2:123b894b49dd 230 HAL_DSI_DeInit(&(hdsi_eval));
Jerome Coutant 2:123b894b49dd 231
Jerome Coutant 2:123b894b49dd 232 #if !defined(USE_STM32469I_DISCO_REVA)
Jerome Coutant 2:123b894b49dd 233 dsiPllInit.PLLNDIV = 125;
Jerome Coutant 2:123b894b49dd 234 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV2;
Jerome Coutant 2:123b894b49dd 235 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
Jerome Coutant 2:123b894b49dd 236 #else
Jerome Coutant 2:123b894b49dd 237 dsiPllInit.PLLNDIV = 100;
Jerome Coutant 2:123b894b49dd 238 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
Jerome Coutant 2:123b894b49dd 239 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
Jerome Coutant 2:123b894b49dd 240 #endif
Jerome Coutant 2:123b894b49dd 241 laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
Jerome Coutant 2:123b894b49dd 242
Jerome Coutant 2:123b894b49dd 243 /* Set number of Lanes */
Jerome Coutant 2:123b894b49dd 244 hdsi_eval.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
Jerome Coutant 2:123b894b49dd 245
Jerome Coutant 2:123b894b49dd 246 /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
Jerome Coutant 2:123b894b49dd 247 hdsi_eval.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
Jerome Coutant 2:123b894b49dd 248
Jerome Coutant 2:123b894b49dd 249 HAL_DSI_Init(&(hdsi_eval), &(dsiPllInit));
Jerome Coutant 2:123b894b49dd 250
Jerome Coutant 2:123b894b49dd 251 /* Timing parameters for all Video modes
Jerome Coutant 2:123b894b49dd 252 * Set Timing parameters of LTDC depending on its chosen orientation
Jerome Coutant 2:123b894b49dd 253 */
Jerome Coutant 2:123b894b49dd 254 if(orientation == LCD_ORIENTATION_PORTRAIT)
Jerome Coutant 2:123b894b49dd 255 {
Jerome Coutant 2:123b894b49dd 256 lcd_x_size = OTM8009A_480X800_WIDTH; /* 480 */
Jerome Coutant 2:123b894b49dd 257 lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */
Jerome Coutant 2:123b894b49dd 258 }
Jerome Coutant 2:123b894b49dd 259 else
Jerome Coutant 2:123b894b49dd 260 {
Jerome Coutant 2:123b894b49dd 261 /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
Jerome Coutant 2:123b894b49dd 262 lcd_x_size = OTM8009A_800X480_WIDTH; /* 800 */
Jerome Coutant 2:123b894b49dd 263 lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */
Jerome Coutant 2:123b894b49dd 264 }
Jerome Coutant 2:123b894b49dd 265
Jerome Coutant 2:123b894b49dd 266 HACT = lcd_x_size;
Jerome Coutant 2:123b894b49dd 267 VACT = lcd_y_size;
Jerome Coutant 2:123b894b49dd 268
Jerome Coutant 2:123b894b49dd 269 /* The following values are same for portrait and landscape orientations */
Jerome Coutant 2:123b894b49dd 270 VSA = OTM8009A_480X800_VSYNC;
Jerome Coutant 2:123b894b49dd 271 VBP = OTM8009A_480X800_VBP;
Jerome Coutant 2:123b894b49dd 272 VFP = OTM8009A_480X800_VFP;
Jerome Coutant 2:123b894b49dd 273 HSA = OTM8009A_480X800_HSYNC;
Jerome Coutant 2:123b894b49dd 274 HBP = OTM8009A_480X800_HBP;
Jerome Coutant 2:123b894b49dd 275 HFP = OTM8009A_480X800_HFP;
Jerome Coutant 2:123b894b49dd 276
Jerome Coutant 2:123b894b49dd 277
Jerome Coutant 2:123b894b49dd 278 hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID;
Jerome Coutant 2:123b894b49dd 279 hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888;
Jerome Coutant 2:123b894b49dd 280 hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
Jerome Coutant 2:123b894b49dd 281 hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
Jerome Coutant 2:123b894b49dd 282 hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
Jerome Coutant 2:123b894b49dd 283 hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
Jerome Coutant 2:123b894b49dd 284 hdsivideo_handle.NullPacketSize = 0xFFF;
Jerome Coutant 2:123b894b49dd 285 hdsivideo_handle.NumberOfChunks = 0;
Jerome Coutant 2:123b894b49dd 286 hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 2:123b894b49dd 287 hdsivideo_handle.HorizontalSyncActive = (HSA * laneByteClk_kHz) / LcdClock;
Jerome Coutant 2:123b894b49dd 288 hdsivideo_handle.HorizontalBackPorch = (HBP * laneByteClk_kHz) / LcdClock;
Jerome Coutant 2:123b894b49dd 289 hdsivideo_handle.HorizontalLine = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz) / LcdClock; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 2:123b894b49dd 290 hdsivideo_handle.VerticalSyncActive = VSA;
Jerome Coutant 2:123b894b49dd 291 hdsivideo_handle.VerticalBackPorch = VBP;
Jerome Coutant 2:123b894b49dd 292 hdsivideo_handle.VerticalFrontPorch = VFP;
Jerome Coutant 2:123b894b49dd 293 hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 2:123b894b49dd 294
Jerome Coutant 2:123b894b49dd 295 /* Enable or disable sending LP command while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 296 hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
Jerome Coutant 2:123b894b49dd 297
Jerome Coutant 2:123b894b49dd 298 /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
Jerome Coutant 2:123b894b49dd 299 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 300 hdsivideo_handle.LPLargestPacketSize = 16;
Jerome Coutant 2:123b894b49dd 301
Jerome Coutant 2:123b894b49dd 302 /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
Jerome Coutant 2:123b894b49dd 303 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 304 hdsivideo_handle.LPVACTLargestPacketSize = 0;
Jerome Coutant 2:123b894b49dd 305
Jerome Coutant 2:123b894b49dd 306
Jerome Coutant 2:123b894b49dd 307 /* 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 308 /* while streaming is active in video mode */
Jerome Coutant 2:123b894b49dd 309 hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */
Jerome Coutant 2:123b894b49dd 310 hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */
Jerome Coutant 2:123b894b49dd 311 hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */
Jerome Coutant 2:123b894b49dd 312 hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */
Jerome Coutant 2:123b894b49dd 313 hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */
Jerome Coutant 2:123b894b49dd 314 hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
Jerome Coutant 2:123b894b49dd 315
Jerome Coutant 2:123b894b49dd 316 /* Configure DSI Video mode timings with settings set above */
Jerome Coutant 2:123b894b49dd 317 HAL_DSI_ConfigVideoMode(&(hdsi_eval), &(hdsivideo_handle));
Jerome Coutant 2:123b894b49dd 318
Jerome Coutant 2:123b894b49dd 319 /* Configure DSI PHY HS2LP and LP2HS timings */
Jerome Coutant 2:123b894b49dd 320 PhyTimings.ClockLaneHS2LPTime = 35;
Jerome Coutant 2:123b894b49dd 321 PhyTimings.ClockLaneLP2HSTime = 35;
Jerome Coutant 2:123b894b49dd 322 PhyTimings.DataLaneHS2LPTime = 35;
Jerome Coutant 2:123b894b49dd 323 PhyTimings.DataLaneLP2HSTime = 35;
Jerome Coutant 2:123b894b49dd 324 PhyTimings.DataLaneMaxReadTime = 0;
Jerome Coutant 2:123b894b49dd 325 PhyTimings.StopWaitTime = 10;
Jerome Coutant 2:123b894b49dd 326 HAL_DSI_ConfigPhyTimer(&hdsi_eval, &PhyTimings);
Jerome Coutant 2:123b894b49dd 327
Jerome Coutant 2:123b894b49dd 328 /*************************End DSI Initialization*******************************/
Jerome Coutant 2:123b894b49dd 329
Jerome Coutant 2:123b894b49dd 330
Jerome Coutant 2:123b894b49dd 331 /************************LTDC Initialization***********************************/
Jerome Coutant 2:123b894b49dd 332
Jerome Coutant 2:123b894b49dd 333 /* Timing Configuration */
Jerome Coutant 2:123b894b49dd 334 hltdc_eval.Init.HorizontalSync = (HSA - 1);
Jerome Coutant 2:123b894b49dd 335 hltdc_eval.Init.AccumulatedHBP = (HSA + HBP - 1);
Jerome Coutant 2:123b894b49dd 336 hltdc_eval.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
Jerome Coutant 2:123b894b49dd 337 hltdc_eval.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
Jerome Coutant 2:123b894b49dd 338
Jerome Coutant 2:123b894b49dd 339 /* Initialize the LCD pixel width and pixel height */
Jerome Coutant 2:123b894b49dd 340 hltdc_eval.LayerCfg->ImageWidth = lcd_x_size;
Jerome Coutant 2:123b894b49dd 341 hltdc_eval.LayerCfg->ImageHeight = lcd_y_size;
Jerome Coutant 2:123b894b49dd 342
Jerome Coutant 2:123b894b49dd 343
Jerome Coutant 2:123b894b49dd 344 /* LCD clock configuration */
Jerome Coutant 2:123b894b49dd 345 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
Jerome Coutant 2:123b894b49dd 346 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz */
Jerome Coutant 2:123b894b49dd 347 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.857 MHz */
Jerome Coutant 2:123b894b49dd 348 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.857 MHz / 2 = 27.429 MHz */
Jerome Coutant 2:123b894b49dd 349 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
Jerome Coutant 2:123b894b49dd 350 PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
Jerome Coutant 2:123b894b49dd 351 PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;
Jerome Coutant 2:123b894b49dd 352 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
Jerome Coutant 2:123b894b49dd 353 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
Jerome Coutant 2:123b894b49dd 354
Jerome Coutant 2:123b894b49dd 355 /* Background value */
Jerome Coutant 2:123b894b49dd 356 hltdc_eval.Init.Backcolor.Blue = 0;
Jerome Coutant 2:123b894b49dd 357 hltdc_eval.Init.Backcolor.Green = 0;
Jerome Coutant 2:123b894b49dd 358 hltdc_eval.Init.Backcolor.Red = 0;
Jerome Coutant 2:123b894b49dd 359 hltdc_eval.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
Jerome Coutant 2:123b894b49dd 360 hltdc_eval.Instance = LTDC;
Jerome Coutant 2:123b894b49dd 361
Jerome Coutant 2:123b894b49dd 362 /* Get LTDC Configuration from DSI Configuration */
Jerome Coutant 2:123b894b49dd 363 HAL_LTDCEx_StructInitFromVideoConfig(&(hltdc_eval), &(hdsivideo_handle));
Jerome Coutant 2:123b894b49dd 364
Jerome Coutant 2:123b894b49dd 365 /* Initialize the LTDC */
Jerome Coutant 2:123b894b49dd 366 HAL_LTDC_Init(&hltdc_eval);
Jerome Coutant 2:123b894b49dd 367
Jerome Coutant 2:123b894b49dd 368 /* Enable the DSI host and wrapper after the LTDC initialization
Jerome Coutant 2:123b894b49dd 369 To avoid any synchronization issue, the DSI shall be started after enabling the LTDC */
Jerome Coutant 2:123b894b49dd 370 HAL_DSI_Start(&(hdsi_eval));
Jerome Coutant 2:123b894b49dd 371
Jerome Coutant 2:123b894b49dd 372 #if !defined(DATA_IN_ExtSDRAM)
Jerome Coutant 2:123b894b49dd 373 /* Initialize the SDRAM */
Jerome Coutant 2:123b894b49dd 374 BSP_SDRAM_Init();
Jerome Coutant 2:123b894b49dd 375 #endif /* DATA_IN_ExtSDRAM */
Jerome Coutant 2:123b894b49dd 376
Jerome Coutant 2:123b894b49dd 377 /* Initialize the font */
Jerome Coutant 2:123b894b49dd 378 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
Jerome Coutant 2:123b894b49dd 379
Jerome Coutant 2:123b894b49dd 380 /************************End LTDC Initialization*******************************/
Jerome Coutant 2:123b894b49dd 381
Jerome Coutant 2:123b894b49dd 382
Jerome Coutant 2:123b894b49dd 383 /***********************OTM8009A Initialization********************************/
Jerome Coutant 2:123b894b49dd 384
Jerome Coutant 2:123b894b49dd 385 /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
Jerome Coutant 2:123b894b49dd 386 * depending on configuration set in 'hdsivideo_handle'.
Jerome Coutant 2:123b894b49dd 387 */
Jerome Coutant 2:123b894b49dd 388 OTM8009A_Init(OTM8009A_FORMAT_RGB888, orientation);
Jerome Coutant 2:123b894b49dd 389
Jerome Coutant 2:123b894b49dd 390 /***********************End OTM8009A Initialization****************************/
Jerome Coutant 2:123b894b49dd 391
Jerome Coutant 2:123b894b49dd 392 return LCD_OK;
Jerome Coutant 2:123b894b49dd 393 }
Jerome Coutant 2:123b894b49dd 394
Jerome Coutant 2:123b894b49dd 395 /**
Jerome Coutant 2:123b894b49dd 396 * @brief BSP LCD Reset
Jerome Coutant 2:123b894b49dd 397 * Hw reset the LCD DSI activating its XRES signal (active low for some time)
Jerome Coutant 2:123b894b49dd 398 * and desactivating it later.
Jerome Coutant 2:123b894b49dd 399 * This signal is only cabled on Discovery Rev B and beyond.
Jerome Coutant 2:123b894b49dd 400 */
Jerome Coutant 2:123b894b49dd 401 void BSP_LCD_Reset(void)
Jerome Coutant 2:123b894b49dd 402 {
Jerome Coutant 2:123b894b49dd 403 #if !defined(USE_STM32469I_DISCO_REVA)
Jerome Coutant 2:123b894b49dd 404 /* EVAL Rev B and beyond : reset the LCD by activation of XRES (active low) connected to PH7 */
Jerome Coutant 2:123b894b49dd 405 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 2:123b894b49dd 406
Jerome Coutant 2:123b894b49dd 407 __HAL_RCC_GPIOH_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 408
Jerome Coutant 2:123b894b49dd 409 /* Configure the GPIO on PH7 */
Jerome Coutant 2:123b894b49dd 410 gpio_init_structure.Pin = GPIO_PIN_7;
Jerome Coutant 2:123b894b49dd 411 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_OD;
Jerome Coutant 2:123b894b49dd 412 gpio_init_structure.Pull = GPIO_NOPULL;
Jerome Coutant 2:123b894b49dd 413 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
Jerome Coutant 2:123b894b49dd 414
Jerome Coutant 2:123b894b49dd 415 HAL_GPIO_Init(GPIOH, &gpio_init_structure);
Jerome Coutant 2:123b894b49dd 416
Jerome Coutant 2:123b894b49dd 417 /* Activate XRES active low */
Jerome Coutant 2:123b894b49dd 418 HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_RESET);
Jerome Coutant 2:123b894b49dd 419
Jerome Coutant 2:123b894b49dd 420 //HAL_Delay(20); /* wait 20 ms */
aa6164 4:27609b3a44ed 421 //wait_ms(20);
aa6164 4:27609b3a44ed 422 thread_sleep_for(10);
Jerome Coutant 2:123b894b49dd 423
Jerome Coutant 2:123b894b49dd 424 /* Desactivate XRES */
Jerome Coutant 2:123b894b49dd 425 HAL_GPIO_WritePin(GPIOH, GPIO_PIN_7, GPIO_PIN_SET);
Jerome Coutant 2:123b894b49dd 426
Jerome Coutant 2:123b894b49dd 427 /* Wait for 10ms after releasing XRES before sending commands */
Jerome Coutant 2:123b894b49dd 428 //HAL_Delay(10);
aa6164 4:27609b3a44ed 429 //wait_ms(10);
aa6164 4:27609b3a44ed 430 thread_sleep_for(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 3:3cdfcc4f7c9d 1054 index = pbmp[10] + (pbmp[11] << 8) + (pbmp[12] << 16) + (pbmp[13] << 24);
Jerome Coutant 2:123b894b49dd 1055
Jerome Coutant 2:123b894b49dd 1056 /* Read bitmap width */
Jerome Coutant 3:3cdfcc4f7c9d 1057 width = pbmp[18] + (pbmp[19] << 8) + (pbmp[20] << 16) + (pbmp[21] << 24);
Jerome Coutant 2:123b894b49dd 1058
Jerome Coutant 2:123b894b49dd 1059 /* Read bitmap height */
Jerome Coutant 3:3cdfcc4f7c9d 1060 height = pbmp[22] + (pbmp[23] << 8) + (pbmp[24] << 16) + (pbmp[25] << 24);
Jerome Coutant 2:123b894b49dd 1061
Jerome Coutant 2:123b894b49dd 1062 /* Read bit/pixel */
Jerome Coutant 3:3cdfcc4f7c9d 1063 bit_pixel = pbmp[28] + (pbmp[29] << 8);
Jerome Coutant 2:123b894b49dd 1064
Jerome Coutant 2:123b894b49dd 1065 /* Set the address */
Jerome Coutant 2:123b894b49dd 1066 Address = hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
Jerome Coutant 2:123b894b49dd 1067
Jerome Coutant 2:123b894b49dd 1068 /* Get the layer pixel format */
Jerome Coutant 2:123b894b49dd 1069 if ((bit_pixel/8) == 4)
Jerome Coutant 2:123b894b49dd 1070 {
Jerome Coutant 2:123b894b49dd 1071 InputColorMode = CM_ARGB8888;
Jerome Coutant 2:123b894b49dd 1072 }
Jerome Coutant 2:123b894b49dd 1073 else if ((bit_pixel/8) == 2)
Jerome Coutant 2:123b894b49dd 1074 {
Jerome Coutant 2:123b894b49dd 1075 InputColorMode = CM_RGB565;
Jerome Coutant 2:123b894b49dd 1076 }
Jerome Coutant 2:123b894b49dd 1077 else
Jerome Coutant 2:123b894b49dd 1078 {
Jerome Coutant 2:123b894b49dd 1079 InputColorMode = CM_RGB888;
Jerome Coutant 2:123b894b49dd 1080 }
Jerome Coutant 2:123b894b49dd 1081
Jerome Coutant 2:123b894b49dd 1082 /* Bypass the bitmap header */
Jerome Coutant 2:123b894b49dd 1083 pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
Jerome Coutant 2:123b894b49dd 1084
Jerome Coutant 2:123b894b49dd 1085 /* Convert picture to ARGB8888 pixel format */
Jerome Coutant 2:123b894b49dd 1086 for(index=0; index < height; index++)
Jerome Coutant 2:123b894b49dd 1087 {
Jerome Coutant 2:123b894b49dd 1088 /* Pixel format conversion */
Jerome Coutant 2:123b894b49dd 1089 LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode);
Jerome Coutant 2:123b894b49dd 1090
Jerome Coutant 2:123b894b49dd 1091 /* Increment the source and destination buffers */
Jerome Coutant 2:123b894b49dd 1092 Address+= (BSP_LCD_GetXSize()*4);
Jerome Coutant 2:123b894b49dd 1093 pbmp -= width*(bit_pixel/8);
Jerome Coutant 2:123b894b49dd 1094 }
Jerome Coutant 2:123b894b49dd 1095 }
Jerome Coutant 2:123b894b49dd 1096
Jerome Coutant 2:123b894b49dd 1097 /**
Jerome Coutant 2:123b894b49dd 1098 * @brief Draws a full rectangle in currently active layer.
Jerome Coutant 2:123b894b49dd 1099 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1100 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1101 * @param Width: Rectangle width
Jerome Coutant 2:123b894b49dd 1102 * @param Height: Rectangle height
Jerome Coutant 2:123b894b49dd 1103 */
Jerome Coutant 2:123b894b49dd 1104 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 2:123b894b49dd 1105 {
Jerome Coutant 2:123b894b49dd 1106 uint32_t Xaddress = 0;
Jerome Coutant 2:123b894b49dd 1107
Jerome Coutant 2:123b894b49dd 1108 /* Set the text color */
Jerome Coutant 2:123b894b49dd 1109 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1110
Jerome Coutant 2:123b894b49dd 1111 /* Get the rectangle start address */
Jerome Coutant 2:123b894b49dd 1112 Xaddress = (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 2:123b894b49dd 1113
Jerome Coutant 2:123b894b49dd 1114 /* Fill the rectangle */
Jerome Coutant 2:123b894b49dd 1115 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1116 }
Jerome Coutant 2:123b894b49dd 1117
Jerome Coutant 2:123b894b49dd 1118 /**
Jerome Coutant 2:123b894b49dd 1119 * @brief Draws a full circle in currently active layer.
Jerome Coutant 2:123b894b49dd 1120 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1121 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1122 * @param Radius: Circle radius
Jerome Coutant 2:123b894b49dd 1123 */
Jerome Coutant 2:123b894b49dd 1124 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Jerome Coutant 2:123b894b49dd 1125 {
Jerome Coutant 2:123b894b49dd 1126 int32_t D; /* Decision Variable */
Jerome Coutant 2:123b894b49dd 1127 uint32_t CurX; /* Current X Value */
Jerome Coutant 2:123b894b49dd 1128 uint32_t CurY; /* Current Y Value */
Jerome Coutant 2:123b894b49dd 1129
Jerome Coutant 2:123b894b49dd 1130 D = 3 - (Radius << 1);
Jerome Coutant 2:123b894b49dd 1131
Jerome Coutant 2:123b894b49dd 1132 CurX = 0;
Jerome Coutant 2:123b894b49dd 1133 CurY = Radius;
Jerome Coutant 2:123b894b49dd 1134
Jerome Coutant 2:123b894b49dd 1135 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1136
Jerome Coutant 2:123b894b49dd 1137 while (CurX <= CurY)
Jerome Coutant 2:123b894b49dd 1138 {
Jerome Coutant 2:123b894b49dd 1139 if(CurY > 0)
Jerome Coutant 2:123b894b49dd 1140 {
Jerome Coutant 2:123b894b49dd 1141 BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
Jerome Coutant 2:123b894b49dd 1142 BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
Jerome Coutant 2:123b894b49dd 1143 }
Jerome Coutant 2:123b894b49dd 1144
Jerome Coutant 2:123b894b49dd 1145 if(CurX > 0)
Jerome Coutant 2:123b894b49dd 1146 {
Jerome Coutant 2:123b894b49dd 1147 BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
Jerome Coutant 2:123b894b49dd 1148 BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
Jerome Coutant 2:123b894b49dd 1149 }
Jerome Coutant 2:123b894b49dd 1150 if (D < 0)
Jerome Coutant 2:123b894b49dd 1151 {
Jerome Coutant 2:123b894b49dd 1152 D += (CurX << 2) + 6;
Jerome Coutant 2:123b894b49dd 1153 }
Jerome Coutant 2:123b894b49dd 1154 else
Jerome Coutant 2:123b894b49dd 1155 {
Jerome Coutant 2:123b894b49dd 1156 D += ((CurX - CurY) << 2) + 10;
Jerome Coutant 2:123b894b49dd 1157 CurY--;
Jerome Coutant 2:123b894b49dd 1158 }
Jerome Coutant 2:123b894b49dd 1159 CurX++;
Jerome Coutant 2:123b894b49dd 1160 }
Jerome Coutant 2:123b894b49dd 1161
Jerome Coutant 2:123b894b49dd 1162 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1163 BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
Jerome Coutant 2:123b894b49dd 1164 }
Jerome Coutant 2:123b894b49dd 1165
Jerome Coutant 2:123b894b49dd 1166 /**
Jerome Coutant 2:123b894b49dd 1167 * @brief Draws a full poly-line (between many points) in currently active layer.
Jerome Coutant 2:123b894b49dd 1168 * @param Points: Pointer to the points array
Jerome Coutant 2:123b894b49dd 1169 * @param PointCount: Number of points
Jerome Coutant 2:123b894b49dd 1170 */
Jerome Coutant 2:123b894b49dd 1171 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
Jerome Coutant 2:123b894b49dd 1172 {
Jerome Coutant 2:123b894b49dd 1173 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 1174 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
Jerome Coutant 2:123b894b49dd 1175
Jerome Coutant 2:123b894b49dd 1176 IMAGE_LEFT = IMAGE_RIGHT = Points->X;
Jerome Coutant 2:123b894b49dd 1177 IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
Jerome Coutant 2:123b894b49dd 1178
Jerome Coutant 2:123b894b49dd 1179 for(counter = 1; counter < PointCount; counter++)
Jerome Coutant 2:123b894b49dd 1180 {
Jerome Coutant 2:123b894b49dd 1181 pixelX = POLY_X(counter);
Jerome Coutant 2:123b894b49dd 1182 if(pixelX < IMAGE_LEFT)
Jerome Coutant 2:123b894b49dd 1183 {
Jerome Coutant 2:123b894b49dd 1184 IMAGE_LEFT = pixelX;
Jerome Coutant 2:123b894b49dd 1185 }
Jerome Coutant 2:123b894b49dd 1186 if(pixelX > IMAGE_RIGHT)
Jerome Coutant 2:123b894b49dd 1187 {
Jerome Coutant 2:123b894b49dd 1188 IMAGE_RIGHT = pixelX;
Jerome Coutant 2:123b894b49dd 1189 }
Jerome Coutant 2:123b894b49dd 1190
Jerome Coutant 2:123b894b49dd 1191 pixelY = POLY_Y(counter);
Jerome Coutant 2:123b894b49dd 1192 if(pixelY < IMAGE_TOP)
Jerome Coutant 2:123b894b49dd 1193 {
Jerome Coutant 2:123b894b49dd 1194 IMAGE_TOP = pixelY;
Jerome Coutant 2:123b894b49dd 1195 }
Jerome Coutant 2:123b894b49dd 1196 if(pixelY > IMAGE_BOTTOM)
Jerome Coutant 2:123b894b49dd 1197 {
Jerome Coutant 2:123b894b49dd 1198 IMAGE_BOTTOM = pixelY;
Jerome Coutant 2:123b894b49dd 1199 }
Jerome Coutant 2:123b894b49dd 1200 }
Jerome Coutant 2:123b894b49dd 1201
Jerome Coutant 2:123b894b49dd 1202 if(PointCount < 2)
Jerome Coutant 2:123b894b49dd 1203 {
Jerome Coutant 2:123b894b49dd 1204 return;
Jerome Coutant 2:123b894b49dd 1205 }
Jerome Coutant 2:123b894b49dd 1206
Jerome Coutant 2:123b894b49dd 1207 X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
Jerome Coutant 2:123b894b49dd 1208 Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
Jerome Coutant 2:123b894b49dd 1209
Jerome Coutant 2:123b894b49dd 1210 X_first = Points->X;
Jerome Coutant 2:123b894b49dd 1211 Y_first = Points->Y;
Jerome Coutant 2:123b894b49dd 1212
Jerome Coutant 2:123b894b49dd 1213 while(--PointCount)
Jerome Coutant 2:123b894b49dd 1214 {
Jerome Coutant 2:123b894b49dd 1215 X = Points->X;
Jerome Coutant 2:123b894b49dd 1216 Y = Points->Y;
Jerome Coutant 2:123b894b49dd 1217 Points++;
Jerome Coutant 2:123b894b49dd 1218 X2 = Points->X;
Jerome Coutant 2:123b894b49dd 1219 Y2 = Points->Y;
Jerome Coutant 2:123b894b49dd 1220
Jerome Coutant 2:123b894b49dd 1221 FillTriangle(X, X2, X_center, Y, Y2, Y_center);
Jerome Coutant 2:123b894b49dd 1222 FillTriangle(X, X_center, X2, Y, Y_center, Y2);
Jerome Coutant 2:123b894b49dd 1223 FillTriangle(X_center, X2, X, Y_center, Y2, Y);
Jerome Coutant 2:123b894b49dd 1224 }
Jerome Coutant 2:123b894b49dd 1225
Jerome Coutant 2:123b894b49dd 1226 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
Jerome Coutant 2:123b894b49dd 1227 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
Jerome Coutant 2:123b894b49dd 1228 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
Jerome Coutant 2:123b894b49dd 1229 }
Jerome Coutant 2:123b894b49dd 1230
Jerome Coutant 2:123b894b49dd 1231 /**
Jerome Coutant 2:123b894b49dd 1232 * @brief Draws a full ellipse in currently active layer.
Jerome Coutant 2:123b894b49dd 1233 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1234 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1235 * @param XRadius: Ellipse X radius
Jerome Coutant 2:123b894b49dd 1236 * @param YRadius: Ellipse Y radius
Jerome Coutant 2:123b894b49dd 1237 */
Jerome Coutant 2:123b894b49dd 1238 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Jerome Coutant 2:123b894b49dd 1239 {
Jerome Coutant 2:123b894b49dd 1240 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
Jerome Coutant 2:123b894b49dd 1241 float K = 0, rad1 = 0, rad2 = 0;
Jerome Coutant 2:123b894b49dd 1242
Jerome Coutant 2:123b894b49dd 1243 rad1 = XRadius;
Jerome Coutant 2:123b894b49dd 1244 rad2 = YRadius;
Jerome Coutant 2:123b894b49dd 1245
Jerome Coutant 2:123b894b49dd 1246 K = (float)(rad2/rad1);
Jerome Coutant 2:123b894b49dd 1247
Jerome Coutant 2:123b894b49dd 1248 do
Jerome Coutant 2:123b894b49dd 1249 {
Jerome Coutant 2:123b894b49dd 1250 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 2:123b894b49dd 1251 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 2:123b894b49dd 1252
Jerome Coutant 2:123b894b49dd 1253 e2 = err;
Jerome Coutant 2:123b894b49dd 1254 if (e2 <= x)
Jerome Coutant 2:123b894b49dd 1255 {
Jerome Coutant 2:123b894b49dd 1256 err += ++x*2+1;
Jerome Coutant 2:123b894b49dd 1257 if (-y == x && e2 <= y) e2 = 0;
Jerome Coutant 2:123b894b49dd 1258 }
Jerome Coutant 2:123b894b49dd 1259 if (e2 > y) err += ++y*2+1;
Jerome Coutant 2:123b894b49dd 1260 }
Jerome Coutant 2:123b894b49dd 1261 while (y <= 0);
Jerome Coutant 2:123b894b49dd 1262 }
Jerome Coutant 2:123b894b49dd 1263
Jerome Coutant 2:123b894b49dd 1264 /**
Jerome Coutant 2:123b894b49dd 1265 * @brief Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff().
Jerome Coutant 2:123b894b49dd 1266 * Exit DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 2:123b894b49dd 1267 */
Jerome Coutant 2:123b894b49dd 1268 void BSP_LCD_DisplayOn(void)
Jerome Coutant 2:123b894b49dd 1269 {
Jerome Coutant 2:123b894b49dd 1270 /* Send Display on DCS command to display */
Jerome Coutant 2:123b894b49dd 1271 HAL_DSI_ShortWrite(&(hdsi_eval),
Jerome Coutant 2:123b894b49dd 1272 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 2:123b894b49dd 1273 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 2:123b894b49dd 1274 OTM8009A_CMD_DISPON,
Jerome Coutant 2:123b894b49dd 1275 0x00);
Jerome Coutant 2:123b894b49dd 1276
Jerome Coutant 2:123b894b49dd 1277 }
Jerome Coutant 2:123b894b49dd 1278
Jerome Coutant 2:123b894b49dd 1279 /**
Jerome Coutant 2:123b894b49dd 1280 * @brief Switch Off the display.
Jerome Coutant 2:123b894b49dd 1281 * Enter DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 2:123b894b49dd 1282 */
Jerome Coutant 2:123b894b49dd 1283 void BSP_LCD_DisplayOff(void)
Jerome Coutant 2:123b894b49dd 1284 {
Jerome Coutant 2:123b894b49dd 1285 /* Send Display off DCS Command to display */
Jerome Coutant 2:123b894b49dd 1286 HAL_DSI_ShortWrite(&(hdsi_eval),
Jerome Coutant 2:123b894b49dd 1287 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 2:123b894b49dd 1288 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 2:123b894b49dd 1289 OTM8009A_CMD_DISPOFF,
Jerome Coutant 2:123b894b49dd 1290 0x00);
Jerome Coutant 2:123b894b49dd 1291
Jerome Coutant 2:123b894b49dd 1292 }
Jerome Coutant 2:123b894b49dd 1293
Jerome Coutant 2:123b894b49dd 1294 /**
Jerome Coutant 2:123b894b49dd 1295 * @brief DCS or Generic short/long write command
Jerome Coutant 2:123b894b49dd 1296 * @param NbrParams: Number of parameters. It indicates the write command mode:
Jerome Coutant 2:123b894b49dd 1297 * If inferior to 2, a long write command is performed else short.
Jerome Coutant 2:123b894b49dd 1298 * @param pParams: Pointer to parameter values table.
Jerome Coutant 2:123b894b49dd 1299 * @retval HAL status
Jerome Coutant 2:123b894b49dd 1300 */
Jerome Coutant 2:123b894b49dd 1301 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
Jerome Coutant 2:123b894b49dd 1302 {
Jerome Coutant 2:123b894b49dd 1303 if(NbrParams <= 1)
Jerome Coutant 2:123b894b49dd 1304 {
Jerome Coutant 2:123b894b49dd 1305 HAL_DSI_ShortWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
Jerome Coutant 2:123b894b49dd 1306 }
Jerome Coutant 2:123b894b49dd 1307 else
Jerome Coutant 2:123b894b49dd 1308 {
Jerome Coutant 2:123b894b49dd 1309 HAL_DSI_LongWrite(&hdsi_eval, LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
Jerome Coutant 2:123b894b49dd 1310 }
Jerome Coutant 2:123b894b49dd 1311 }
Jerome Coutant 2:123b894b49dd 1312
Jerome Coutant 2:123b894b49dd 1313 /*******************************************************************************
Jerome Coutant 2:123b894b49dd 1314 LTDC, DMA2D and DSI BSP Routines
Jerome Coutant 2:123b894b49dd 1315 *******************************************************************************/
Jerome Coutant 2:123b894b49dd 1316 /**
Jerome Coutant 2:123b894b49dd 1317 * @brief Handles DMA2D interrupt request.
Jerome Coutant 2:123b894b49dd 1318 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1319 */
Jerome Coutant 2:123b894b49dd 1320 __weak void BSP_LCD_DMA2D_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1321 {
Jerome Coutant 2:123b894b49dd 1322 HAL_DMA2D_IRQHandler(&hdma2d_eval);
Jerome Coutant 2:123b894b49dd 1323 }
Jerome Coutant 2:123b894b49dd 1324
Jerome Coutant 2:123b894b49dd 1325 /**
Jerome Coutant 2:123b894b49dd 1326 * @brief Handles DSI interrupt request.
Jerome Coutant 2:123b894b49dd 1327 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1328 */
Jerome Coutant 2:123b894b49dd 1329 __weak void BSP_LCD_DSI_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1330 {
Jerome Coutant 2:123b894b49dd 1331 HAL_DSI_IRQHandler(&(hdsi_eval));
Jerome Coutant 2:123b894b49dd 1332 }
Jerome Coutant 2:123b894b49dd 1333
Jerome Coutant 2:123b894b49dd 1334
Jerome Coutant 2:123b894b49dd 1335 /**
Jerome Coutant 2:123b894b49dd 1336 * @brief Handles LTDC interrupt request.
Jerome Coutant 2:123b894b49dd 1337 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1338 */
Jerome Coutant 2:123b894b49dd 1339 __weak void BSP_LCD_LTDC_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1340 {
Jerome Coutant 2:123b894b49dd 1341 HAL_LTDC_IRQHandler(&(hltdc_eval));
Jerome Coutant 2:123b894b49dd 1342 }
Jerome Coutant 2:123b894b49dd 1343
Jerome Coutant 2:123b894b49dd 1344 /**
Jerome Coutant 2:123b894b49dd 1345 * @brief De-Initializes the BSP LCD Msp
Jerome Coutant 2:123b894b49dd 1346 * Application can surcharge if needed this function implementation.
Jerome Coutant 2:123b894b49dd 1347 */
Jerome Coutant 2:123b894b49dd 1348 __weak void BSP_LCD_MspDeInit(void)
Jerome Coutant 2:123b894b49dd 1349 {
Jerome Coutant 2:123b894b49dd 1350 /** @brief Disable IRQ of LTDC IP */
Jerome Coutant 2:123b894b49dd 1351 HAL_NVIC_DisableIRQ(LTDC_IRQn);
Jerome Coutant 2:123b894b49dd 1352
Jerome Coutant 2:123b894b49dd 1353 /** @brief Disable IRQ of DMA2D IP */
Jerome Coutant 2:123b894b49dd 1354 HAL_NVIC_DisableIRQ(DMA2D_IRQn);
Jerome Coutant 2:123b894b49dd 1355
Jerome Coutant 2:123b894b49dd 1356 /** @brief Disable IRQ of DSI IP */
Jerome Coutant 2:123b894b49dd 1357 HAL_NVIC_DisableIRQ(DSI_IRQn);
Jerome Coutant 2:123b894b49dd 1358
Jerome Coutant 2:123b894b49dd 1359 /** @brief Force and let in reset state LTDC, DMA2D and DSI Host + Wrapper IPs */
Jerome Coutant 2:123b894b49dd 1360 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1361 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1362 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1363
Jerome Coutant 2:123b894b49dd 1364 /** @brief Disable the LTDC, DMA2D and DSI Host and Wrapper clocks */
Jerome Coutant 2:123b894b49dd 1365 __HAL_RCC_LTDC_CLK_DISABLE();
Jerome Coutant 2:123b894b49dd 1366 __HAL_RCC_DMA2D_CLK_DISABLE();
Jerome Coutant 2:123b894b49dd 1367 __HAL_RCC_DSI_CLK_DISABLE();
Jerome Coutant 2:123b894b49dd 1368 }
Jerome Coutant 2:123b894b49dd 1369
Jerome Coutant 2:123b894b49dd 1370 /**
Jerome Coutant 2:123b894b49dd 1371 * @brief Initialize the BSP LCD Msp.
Jerome Coutant 2:123b894b49dd 1372 * Application can surcharge if needed this function implementation
Jerome Coutant 2:123b894b49dd 1373 */
Jerome Coutant 2:123b894b49dd 1374 __weak void BSP_LCD_MspInit(void)
Jerome Coutant 2:123b894b49dd 1375 {
Jerome Coutant 2:123b894b49dd 1376 /** @brief Enable the LTDC clock */
Jerome Coutant 2:123b894b49dd 1377 __HAL_RCC_LTDC_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 1378
Jerome Coutant 2:123b894b49dd 1379 /** @brief Toggle Sw reset of LTDC IP */
Jerome Coutant 2:123b894b49dd 1380 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1381 __HAL_RCC_LTDC_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 1382
Jerome Coutant 2:123b894b49dd 1383 /** @brief Enable the DMA2D clock */
Jerome Coutant 2:123b894b49dd 1384 __HAL_RCC_DMA2D_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 1385
Jerome Coutant 2:123b894b49dd 1386 /** @brief Toggle Sw reset of DMA2D IP */
Jerome Coutant 2:123b894b49dd 1387 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1388 __HAL_RCC_DMA2D_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 1389
Jerome Coutant 2:123b894b49dd 1390 /** @brief Enable DSI Host and wrapper clocks */
Jerome Coutant 2:123b894b49dd 1391 __HAL_RCC_DSI_CLK_ENABLE();
Jerome Coutant 2:123b894b49dd 1392
Jerome Coutant 2:123b894b49dd 1393 /** @brief Soft Reset the DSI Host and wrapper */
Jerome Coutant 2:123b894b49dd 1394 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 2:123b894b49dd 1395 __HAL_RCC_DSI_RELEASE_RESET();
Jerome Coutant 2:123b894b49dd 1396
Jerome Coutant 2:123b894b49dd 1397 /** @brief NVIC configuration for LTDC interrupt that is now enabled */
Jerome Coutant 2:123b894b49dd 1398 HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
Jerome Coutant 2:123b894b49dd 1399 HAL_NVIC_EnableIRQ(LTDC_IRQn);
Jerome Coutant 2:123b894b49dd 1400
Jerome Coutant 2:123b894b49dd 1401 /** @brief NVIC configuration for DMA2D interrupt that is now enabled */
Jerome Coutant 2:123b894b49dd 1402 HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0);
Jerome Coutant 2:123b894b49dd 1403 HAL_NVIC_EnableIRQ(DMA2D_IRQn);
Jerome Coutant 2:123b894b49dd 1404
Jerome Coutant 2:123b894b49dd 1405 /** @brief NVIC configuration for DSI interrupt that is now enabled */
Jerome Coutant 2:123b894b49dd 1406 HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
Jerome Coutant 2:123b894b49dd 1407 HAL_NVIC_EnableIRQ(DSI_IRQn);
Jerome Coutant 2:123b894b49dd 1408 }
Jerome Coutant 2:123b894b49dd 1409
Jerome Coutant 2:123b894b49dd 1410 /**
Jerome Coutant 2:123b894b49dd 1411 * @brief This function handles LTDC Error interrupt Handler.
Jerome Coutant 2:123b894b49dd 1412 * @note : Can be surcharged by application code implementation of the function.
Jerome Coutant 2:123b894b49dd 1413 */
Jerome Coutant 2:123b894b49dd 1414
Jerome Coutant 2:123b894b49dd 1415 __weak void BSP_LCD_LTDC_ER_IRQHandler(void)
Jerome Coutant 2:123b894b49dd 1416 {
Jerome Coutant 2:123b894b49dd 1417 HAL_LTDC_IRQHandler(&(hltdc_eval));
Jerome Coutant 2:123b894b49dd 1418 }
Jerome Coutant 2:123b894b49dd 1419
Jerome Coutant 2:123b894b49dd 1420
Jerome Coutant 2:123b894b49dd 1421 /**
Jerome Coutant 2:123b894b49dd 1422 * @brief Draws a pixel on LCD.
Jerome Coutant 2:123b894b49dd 1423 * @param Xpos: X position
Jerome Coutant 2:123b894b49dd 1424 * @param Ypos: Y position
Jerome Coutant 2:123b894b49dd 1425 * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8)
Jerome Coutant 2:123b894b49dd 1426 */
Jerome Coutant 2:123b894b49dd 1427 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
Jerome Coutant 2:123b894b49dd 1428 {
Jerome Coutant 2:123b894b49dd 1429 /* Write data value to all SDRAM memory */
Jerome Coutant 2:123b894b49dd 1430 *(__IO uint32_t*) (hltdc_eval.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
Jerome Coutant 2:123b894b49dd 1431 }
Jerome Coutant 2:123b894b49dd 1432
Jerome Coutant 2:123b894b49dd 1433
Jerome Coutant 2:123b894b49dd 1434 /**
Jerome Coutant 2:123b894b49dd 1435 * @brief Draws a character on LCD.
Jerome Coutant 2:123b894b49dd 1436 * @param Xpos: Line where to display the character shape
Jerome Coutant 2:123b894b49dd 1437 * @param Ypos: Start column address
Jerome Coutant 2:123b894b49dd 1438 * @param c: Pointer to the character data
Jerome Coutant 2:123b894b49dd 1439 */
Jerome Coutant 2:123b894b49dd 1440 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
Jerome Coutant 2:123b894b49dd 1441 {
Jerome Coutant 2:123b894b49dd 1442 uint32_t i = 0, j = 0;
Jerome Coutant 2:123b894b49dd 1443 uint16_t height, width;
Jerome Coutant 2:123b894b49dd 1444 uint8_t offset;
Jerome Coutant 2:123b894b49dd 1445 uint8_t *pchar;
Jerome Coutant 2:123b894b49dd 1446 uint32_t line;
Jerome Coutant 2:123b894b49dd 1447
Jerome Coutant 2:123b894b49dd 1448 height = DrawProp[ActiveLayer].pFont->Height;
Jerome Coutant 2:123b894b49dd 1449 width = DrawProp[ActiveLayer].pFont->Width;
Jerome Coutant 2:123b894b49dd 1450
Jerome Coutant 2:123b894b49dd 1451 offset = 8 *((width + 7)/8) - width ;
Jerome Coutant 2:123b894b49dd 1452
Jerome Coutant 2:123b894b49dd 1453 for(i = 0; i < height; i++)
Jerome Coutant 2:123b894b49dd 1454 {
Jerome Coutant 2:123b894b49dd 1455 pchar = ((uint8_t *)c + (width + 7)/8 * i);
Jerome Coutant 2:123b894b49dd 1456
Jerome Coutant 2:123b894b49dd 1457 switch(((width + 7)/8))
Jerome Coutant 2:123b894b49dd 1458 {
Jerome Coutant 2:123b894b49dd 1459
Jerome Coutant 2:123b894b49dd 1460 case 1:
Jerome Coutant 2:123b894b49dd 1461 line = pchar[0];
Jerome Coutant 2:123b894b49dd 1462 break;
Jerome Coutant 2:123b894b49dd 1463
Jerome Coutant 2:123b894b49dd 1464 case 2:
Jerome Coutant 2:123b894b49dd 1465 line = (pchar[0]<< 8) | pchar[1];
Jerome Coutant 2:123b894b49dd 1466 break;
Jerome Coutant 2:123b894b49dd 1467
Jerome Coutant 2:123b894b49dd 1468 case 3:
Jerome Coutant 2:123b894b49dd 1469 default:
Jerome Coutant 2:123b894b49dd 1470 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
Jerome Coutant 2:123b894b49dd 1471 break;
Jerome Coutant 2:123b894b49dd 1472 }
Jerome Coutant 2:123b894b49dd 1473
Jerome Coutant 2:123b894b49dd 1474 for (j = 0; j < width; j++)
Jerome Coutant 2:123b894b49dd 1475 {
Jerome Coutant 2:123b894b49dd 1476 if(line & (1 << (width- j + offset- 1)))
Jerome Coutant 2:123b894b49dd 1477 {
Jerome Coutant 2:123b894b49dd 1478 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
Jerome Coutant 2:123b894b49dd 1479 }
Jerome Coutant 2:123b894b49dd 1480 else
Jerome Coutant 2:123b894b49dd 1481 {
Jerome Coutant 2:123b894b49dd 1482 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
Jerome Coutant 2:123b894b49dd 1483 }
Jerome Coutant 2:123b894b49dd 1484 }
Jerome Coutant 2:123b894b49dd 1485 Ypos++;
Jerome Coutant 2:123b894b49dd 1486 }
Jerome Coutant 2:123b894b49dd 1487 }
Jerome Coutant 2:123b894b49dd 1488
Jerome Coutant 2:123b894b49dd 1489 /**
Jerome Coutant 2:123b894b49dd 1490 * @brief Fills a triangle (between 3 points).
Jerome Coutant 2:123b894b49dd 1491 * @param x1: Point 1 X position
Jerome Coutant 2:123b894b49dd 1492 * @param y1: Point 1 Y position
Jerome Coutant 2:123b894b49dd 1493 * @param x2: Point 2 X position
Jerome Coutant 2:123b894b49dd 1494 * @param y2: Point 2 Y position
Jerome Coutant 2:123b894b49dd 1495 * @param x3: Point 3 X position
Jerome Coutant 2:123b894b49dd 1496 * @param y3: Point 3 Y position
Jerome Coutant 2:123b894b49dd 1497 */
Jerome Coutant 2:123b894b49dd 1498 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 1499 {
Jerome Coutant 2:123b894b49dd 1500 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
Jerome Coutant 2:123b894b49dd 1501 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
Jerome Coutant 2:123b894b49dd 1502 curpixel = 0;
Jerome Coutant 2:123b894b49dd 1503
Jerome Coutant 2:123b894b49dd 1504 deltax = ABS(x2 - x1); /* The difference between the x's */
Jerome Coutant 2:123b894b49dd 1505 deltay = ABS(y2 - y1); /* The difference between the y's */
Jerome Coutant 2:123b894b49dd 1506 x = x1; /* Start x off at the first pixel */
Jerome Coutant 2:123b894b49dd 1507 y = y1; /* Start y off at the first pixel */
Jerome Coutant 2:123b894b49dd 1508
Jerome Coutant 2:123b894b49dd 1509 if (x2 >= x1) /* The x-values are increasing */
Jerome Coutant 2:123b894b49dd 1510 {
Jerome Coutant 2:123b894b49dd 1511 xinc1 = 1;
Jerome Coutant 2:123b894b49dd 1512 xinc2 = 1;
Jerome Coutant 2:123b894b49dd 1513 }
Jerome Coutant 2:123b894b49dd 1514 else /* The x-values are decreasing */
Jerome Coutant 2:123b894b49dd 1515 {
Jerome Coutant 2:123b894b49dd 1516 xinc1 = -1;
Jerome Coutant 2:123b894b49dd 1517 xinc2 = -1;
Jerome Coutant 2:123b894b49dd 1518 }
Jerome Coutant 2:123b894b49dd 1519
Jerome Coutant 2:123b894b49dd 1520 if (y2 >= y1) /* The y-values are increasing */
Jerome Coutant 2:123b894b49dd 1521 {
Jerome Coutant 2:123b894b49dd 1522 yinc1 = 1;
Jerome Coutant 2:123b894b49dd 1523 yinc2 = 1;
Jerome Coutant 2:123b894b49dd 1524 }
Jerome Coutant 2:123b894b49dd 1525 else /* The y-values are decreasing */
Jerome Coutant 2:123b894b49dd 1526 {
Jerome Coutant 2:123b894b49dd 1527 yinc1 = -1;
Jerome Coutant 2:123b894b49dd 1528 yinc2 = -1;
Jerome Coutant 2:123b894b49dd 1529 }
Jerome Coutant 2:123b894b49dd 1530
Jerome Coutant 2:123b894b49dd 1531 if (deltax >= deltay) /* There is at least one x-value for every y-value */
Jerome Coutant 2:123b894b49dd 1532 {
Jerome Coutant 2:123b894b49dd 1533 xinc1 = 0; /* Don't change the x when numerator >= denominator */
Jerome Coutant 2:123b894b49dd 1534 yinc2 = 0; /* Don't change the y for every iteration */
Jerome Coutant 2:123b894b49dd 1535 den = deltax;
Jerome Coutant 2:123b894b49dd 1536 num = deltax / 2;
Jerome Coutant 2:123b894b49dd 1537 numadd = deltay;
Jerome Coutant 2:123b894b49dd 1538 numpixels = deltax; /* There are more x-values than y-values */
Jerome Coutant 2:123b894b49dd 1539 }
Jerome Coutant 2:123b894b49dd 1540 else /* There is at least one y-value for every x-value */
Jerome Coutant 2:123b894b49dd 1541 {
Jerome Coutant 2:123b894b49dd 1542 xinc2 = 0; /* Don't change the x for every iteration */
Jerome Coutant 2:123b894b49dd 1543 yinc1 = 0; /* Don't change the y when numerator >= denominator */
Jerome Coutant 2:123b894b49dd 1544 den = deltay;
Jerome Coutant 2:123b894b49dd 1545 num = deltay / 2;
Jerome Coutant 2:123b894b49dd 1546 numadd = deltax;
Jerome Coutant 2:123b894b49dd 1547 numpixels = deltay; /* There are more y-values than x-values */
Jerome Coutant 2:123b894b49dd 1548 }
Jerome Coutant 2:123b894b49dd 1549
Jerome Coutant 2:123b894b49dd 1550 for (curpixel = 0; curpixel <= numpixels; curpixel++)
Jerome Coutant 2:123b894b49dd 1551 {
Jerome Coutant 2:123b894b49dd 1552 BSP_LCD_DrawLine(x, y, x3, y3);
Jerome Coutant 2:123b894b49dd 1553
Jerome Coutant 2:123b894b49dd 1554 num += numadd; /* Increase the numerator by the top of the fraction */
Jerome Coutant 2:123b894b49dd 1555 if (num >= den) /* Check if numerator >= denominator */
Jerome Coutant 2:123b894b49dd 1556 {
Jerome Coutant 2:123b894b49dd 1557 num -= den; /* Calculate the new numerator value */
Jerome Coutant 2:123b894b49dd 1558 x += xinc1; /* Change the x as appropriate */
Jerome Coutant 2:123b894b49dd 1559 y += yinc1; /* Change the y as appropriate */
Jerome Coutant 2:123b894b49dd 1560 }
Jerome Coutant 2:123b894b49dd 1561 x += xinc2; /* Change the x as appropriate */
Jerome Coutant 2:123b894b49dd 1562 y += yinc2; /* Change the y as appropriate */
Jerome Coutant 2:123b894b49dd 1563 }
Jerome Coutant 2:123b894b49dd 1564 }
Jerome Coutant 2:123b894b49dd 1565
Jerome Coutant 2:123b894b49dd 1566 /**
Jerome Coutant 2:123b894b49dd 1567 * @brief Fills a buffer.
Jerome Coutant 2:123b894b49dd 1568 * @param LayerIndex: Layer index
Jerome Coutant 2:123b894b49dd 1569 * @param pDst: Pointer to destination buffer
Jerome Coutant 2:123b894b49dd 1570 * @param xSize: Buffer width
Jerome Coutant 2:123b894b49dd 1571 * @param ySize: Buffer height
Jerome Coutant 2:123b894b49dd 1572 * @param OffLine: Offset
Jerome Coutant 2:123b894b49dd 1573 * @param ColorIndex: Color index
Jerome Coutant 2:123b894b49dd 1574 */
Jerome Coutant 2:123b894b49dd 1575 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 1576 {
Jerome Coutant 2:123b894b49dd 1577 /* Register to memory mode with ARGB8888 as color Mode */
Jerome Coutant 2:123b894b49dd 1578 hdma2d_eval.Init.Mode = DMA2D_R2M;
Jerome Coutant 2:123b894b49dd 1579 hdma2d_eval.Init.ColorMode = DMA2D_ARGB8888;
Jerome Coutant 2:123b894b49dd 1580 hdma2d_eval.Init.OutputOffset = OffLine;
Jerome Coutant 2:123b894b49dd 1581
Jerome Coutant 2:123b894b49dd 1582 hdma2d_eval.Instance = DMA2D;
Jerome Coutant 2:123b894b49dd 1583
Jerome Coutant 2:123b894b49dd 1584 /* DMA2D Initialization */
Jerome Coutant 2:123b894b49dd 1585 if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1586 {
Jerome Coutant 2:123b894b49dd 1587 if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, LayerIndex) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1588 {
Jerome Coutant 2:123b894b49dd 1589 if (HAL_DMA2D_Start(&hdma2d_eval, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1590 {
Jerome Coutant 2:123b894b49dd 1591 /* Polling For DMA transfer */
Jerome Coutant 2:123b894b49dd 1592 HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
Jerome Coutant 2:123b894b49dd 1593 }
Jerome Coutant 2:123b894b49dd 1594 }
Jerome Coutant 2:123b894b49dd 1595 }
Jerome Coutant 2:123b894b49dd 1596 }
Jerome Coutant 2:123b894b49dd 1597
Jerome Coutant 2:123b894b49dd 1598 /**
Jerome Coutant 2:123b894b49dd 1599 * @brief Converts a line to an ARGB8888 pixel format.
Jerome Coutant 2:123b894b49dd 1600 * @param pSrc: Pointer to source buffer
Jerome Coutant 2:123b894b49dd 1601 * @param pDst: Output color
Jerome Coutant 2:123b894b49dd 1602 * @param xSize: Buffer width
Jerome Coutant 2:123b894b49dd 1603 * @param ColorMode: Input color mode
Jerome Coutant 2:123b894b49dd 1604 */
Jerome Coutant 2:123b894b49dd 1605 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
Jerome Coutant 2:123b894b49dd 1606 {
Jerome Coutant 2:123b894b49dd 1607 /* Configure the DMA2D Mode, Color Mode and output offset */
Jerome Coutant 2:123b894b49dd 1608 hdma2d_eval.Init.Mode = DMA2D_M2M_PFC;
Jerome Coutant 2:123b894b49dd 1609 hdma2d_eval.Init.ColorMode = DMA2D_ARGB8888;
Jerome Coutant 2:123b894b49dd 1610 hdma2d_eval.Init.OutputOffset = 0;
Jerome Coutant 2:123b894b49dd 1611
Jerome Coutant 2:123b894b49dd 1612 /* Foreground Configuration */
Jerome Coutant 2:123b894b49dd 1613 hdma2d_eval.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
Jerome Coutant 2:123b894b49dd 1614 hdma2d_eval.LayerCfg[1].InputAlpha = 0xFF;
Jerome Coutant 2:123b894b49dd 1615 hdma2d_eval.LayerCfg[1].InputColorMode = ColorMode;
Jerome Coutant 2:123b894b49dd 1616 hdma2d_eval.LayerCfg[1].InputOffset = 0;
Jerome Coutant 2:123b894b49dd 1617
Jerome Coutant 2:123b894b49dd 1618 hdma2d_eval.Instance = DMA2D;
Jerome Coutant 2:123b894b49dd 1619
Jerome Coutant 2:123b894b49dd 1620 /* DMA2D Initialization */
Jerome Coutant 2:123b894b49dd 1621 if(HAL_DMA2D_Init(&hdma2d_eval) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1622 {
Jerome Coutant 2:123b894b49dd 1623 if(HAL_DMA2D_ConfigLayer(&hdma2d_eval, 1) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1624 {
Jerome Coutant 2:123b894b49dd 1625 if (HAL_DMA2D_Start(&hdma2d_eval, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
Jerome Coutant 2:123b894b49dd 1626 {
Jerome Coutant 2:123b894b49dd 1627 /* Polling For DMA transfer */
Jerome Coutant 2:123b894b49dd 1628 HAL_DMA2D_PollForTransfer(&hdma2d_eval, 10);
Jerome Coutant 2:123b894b49dd 1629 }
Jerome Coutant 2:123b894b49dd 1630 }
Jerome Coutant 2:123b894b49dd 1631 }
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 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/