BSP files for STM32H747I-Discovery Copy from ST Cube delivery

Dependents:   DISCO_H747I_LCD_demo DISCO_H747I_AUDIO_demo

Committer:
Jerome Coutant
Date:
Wed Nov 06 11:32:01 2019 +0100
Revision:
3:bc403474b366
Parent:
0:146cf26a9bbb
Add PDM lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jerome Coutant 0:146cf26a9bbb 1 /**
Jerome Coutant 0:146cf26a9bbb 2 ******************************************************************************
Jerome Coutant 0:146cf26a9bbb 3 * @file stm32h747i_discovery_lcd.c
Jerome Coutant 0:146cf26a9bbb 4 * @author MCD Application Team
Jerome Coutant 0:146cf26a9bbb 5 * @brief This file includes the driver for Liquid Crystal Display (LCD) module
Jerome Coutant 0:146cf26a9bbb 6 * mounted on STM32H747I_DISCOVERY board.
Jerome Coutant 0:146cf26a9bbb 7 ******************************************************************************
Jerome Coutant 0:146cf26a9bbb 8 * @attention
Jerome Coutant 0:146cf26a9bbb 9 *
Jerome Coutant 0:146cf26a9bbb 10 * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
Jerome Coutant 0:146cf26a9bbb 11 * All rights reserved.</center></h2>
Jerome Coutant 0:146cf26a9bbb 12 *
Jerome Coutant 0:146cf26a9bbb 13 * This software component is licensed by ST under BSD 3-Clause license,
Jerome Coutant 0:146cf26a9bbb 14 * the "License"; You may not use this file except in compliance with the
Jerome Coutant 0:146cf26a9bbb 15 * License. You may obtain a copy of the License at:
Jerome Coutant 0:146cf26a9bbb 16 * opensource.org/licenses/BSD-3-Clause
Jerome Coutant 0:146cf26a9bbb 17 *
Jerome Coutant 0:146cf26a9bbb 18 ******************************************************************************
Jerome Coutant 0:146cf26a9bbb 19 */
Jerome Coutant 0:146cf26a9bbb 20
Jerome Coutant 0:146cf26a9bbb 21 /* File Info: ------------------------------------------------------------------
Jerome Coutant 0:146cf26a9bbb 22 User NOTES
Jerome Coutant 0:146cf26a9bbb 23 1. How To use this driver:
Jerome Coutant 0:146cf26a9bbb 24 --------------------------
Jerome Coutant 0:146cf26a9bbb 25 - This driver is used to drive directly in video mode a LCD TFT using the DSI interface.
Jerome Coutant 0:146cf26a9bbb 26 The following IPs are implied : DSI Host IP block working
Jerome Coutant 0:146cf26a9bbb 27 in conjunction to the LTDC controller.
Jerome Coutant 0:146cf26a9bbb 28 - This driver is linked by construction to LCD KoD mounted on board MB1166.
Jerome Coutant 0:146cf26a9bbb 29
Jerome Coutant 0:146cf26a9bbb 30 2. Driver description:
Jerome Coutant 0:146cf26a9bbb 31 ---------------------
Jerome Coutant 0:146cf26a9bbb 32 + Initialization steps:
Jerome Coutant 0:146cf26a9bbb 33 o Initialize the LCD using the BSP_LCD_Init() function.
Jerome Coutant 0:146cf26a9bbb 34 o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
Jerome Coutant 0:146cf26a9bbb 35 o Enable the LCD display using the BSP_LCD_DisplayOn() function.
Jerome Coutant 0:146cf26a9bbb 36
Jerome Coutant 0:146cf26a9bbb 37 + Options
Jerome Coutant 0:146cf26a9bbb 38 o Configure and enable the color keying functionality using the
Jerome Coutant 0:146cf26a9bbb 39 BSP_LCD_SetColorKeying() function.
Jerome Coutant 0:146cf26a9bbb 40 o Modify in the fly the transparency and/or the frame buffer address
Jerome Coutant 0:146cf26a9bbb 41 using the following functions:
Jerome Coutant 0:146cf26a9bbb 42 - BSP_LCD_SetTransparency()
Jerome Coutant 0:146cf26a9bbb 43 - BSP_LCD_SetLayerAddress()
Jerome Coutant 0:146cf26a9bbb 44
Jerome Coutant 0:146cf26a9bbb 45 + Display on LCD
Jerome Coutant 0:146cf26a9bbb 46 o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string
Jerome Coutant 0:146cf26a9bbb 47 line using the BSP_LCD_ClearStringLine() function.
Jerome Coutant 0:146cf26a9bbb 48 o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
Jerome Coutant 0:146cf26a9bbb 49 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 0:146cf26a9bbb 50 o Display a string line on the specified position (x,y in pixel) and align mode
Jerome Coutant 0:146cf26a9bbb 51 using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 0:146cf26a9bbb 52 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
Jerome Coutant 0:146cf26a9bbb 53 on LCD using the available set of functions.
Jerome Coutant 0:146cf26a9bbb 54
Jerome Coutant 0:146cf26a9bbb 55 ------------------------------------------------------------------------------*/
Jerome Coutant 0:146cf26a9bbb 56
Jerome Coutant 0:146cf26a9bbb 57 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 0:146cf26a9bbb 58 #include "stm32h747i_discovery_lcd.h"
Jerome Coutant 0:146cf26a9bbb 59 #include "../Utilities/Fonts/fonts.h"
Jerome Coutant 0:146cf26a9bbb 60 // #include "../Utilities/Fonts/font24.c"
Jerome Coutant 0:146cf26a9bbb 61 // #include "../Utilities/Fonts/font20.c"
Jerome Coutant 0:146cf26a9bbb 62 // #include "../Utilities/Fonts/font16.c"
Jerome Coutant 0:146cf26a9bbb 63 // #include "../Utilities/Fonts/font12.c"
Jerome Coutant 0:146cf26a9bbb 64 // #include "../Utilities/Fonts/font8.c"
Jerome Coutant 0:146cf26a9bbb 65
Jerome Coutant 0:146cf26a9bbb 66 /** @addtogroup BSP
Jerome Coutant 0:146cf26a9bbb 67 * @{
Jerome Coutant 0:146cf26a9bbb 68 */
Jerome Coutant 0:146cf26a9bbb 69
Jerome Coutant 0:146cf26a9bbb 70 /** @addtogroup STM32H747I_DISCOVERY
Jerome Coutant 0:146cf26a9bbb 71 * @{
Jerome Coutant 0:146cf26a9bbb 72 */
Jerome Coutant 0:146cf26a9bbb 73
Jerome Coutant 0:146cf26a9bbb 74 /** @defgroup STM32H747I_DISCOVERY_LCD STM32H747I_DISCOVERY_LCD
Jerome Coutant 0:146cf26a9bbb 75 * @{
Jerome Coutant 0:146cf26a9bbb 76 */
Jerome Coutant 0:146cf26a9bbb 77
Jerome Coutant 0:146cf26a9bbb 78 /** @defgroup STM32H747I_DISCOVERY_LCD_Private_Defines Private Defines
Jerome Coutant 0:146cf26a9bbb 79 * @{
Jerome Coutant 0:146cf26a9bbb 80 */
Jerome Coutant 0:146cf26a9bbb 81
Jerome Coutant 0:146cf26a9bbb 82 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 83 #define HDMI_ASPECT_RATIO_16_9 ADV7533_ASPECT_RATIO_16_9
Jerome Coutant 0:146cf26a9bbb 84 #define HDMI_ASPECT_RATIO_4_3 ADV7533_ASPECT_RATIO_4_3
Jerome Coutant 0:146cf26a9bbb 85 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 86 #define LCD_DSI_ID 0x11
Jerome Coutant 0:146cf26a9bbb 87 #define LCD_DSI_ID_REG 0xA8
Jerome Coutant 0:146cf26a9bbb 88 /**
Jerome Coutant 0:146cf26a9bbb 89 * @}
Jerome Coutant 0:146cf26a9bbb 90 */
Jerome Coutant 0:146cf26a9bbb 91
Jerome Coutant 0:146cf26a9bbb 92 /** @defgroup STM32H747I_DISCOVERY_LCD_Private_Types Private Types
Jerome Coutant 0:146cf26a9bbb 93 * @{
Jerome Coutant 0:146cf26a9bbb 94 */
Jerome Coutant 0:146cf26a9bbb 95
Jerome Coutant 0:146cf26a9bbb 96 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 97 /**
Jerome Coutant 0:146cf26a9bbb 98 * @brief DSI timming params used for different HDMI adpater
Jerome Coutant 0:146cf26a9bbb 99 */
Jerome Coutant 0:146cf26a9bbb 100 typedef struct
Jerome Coutant 0:146cf26a9bbb 101 {
Jerome Coutant 0:146cf26a9bbb 102 uint16_t HACT;
Jerome Coutant 0:146cf26a9bbb 103 uint16_t HSYNC;
Jerome Coutant 0:146cf26a9bbb 104 uint16_t HBP;
Jerome Coutant 0:146cf26a9bbb 105 uint16_t HFP;
Jerome Coutant 0:146cf26a9bbb 106 uint16_t VACT;
Jerome Coutant 0:146cf26a9bbb 107 uint16_t VSYNC;
Jerome Coutant 0:146cf26a9bbb 108 uint16_t VBP;
Jerome Coutant 0:146cf26a9bbb 109 uint16_t VFP;
Jerome Coutant 0:146cf26a9bbb 110 uint8_t ASPECT_RATIO;
Jerome Coutant 0:146cf26a9bbb 111 uint8_t RGB_CODING;
Jerome Coutant 0:146cf26a9bbb 112 } HDMI_FormatTypeDef;
Jerome Coutant 0:146cf26a9bbb 113
Jerome Coutant 0:146cf26a9bbb 114 /**
Jerome Coutant 0:146cf26a9bbb 115 * @brief DSI packet params used for different HDMI adpater
Jerome Coutant 0:146cf26a9bbb 116 */
Jerome Coutant 0:146cf26a9bbb 117 typedef struct
Jerome Coutant 0:146cf26a9bbb 118 {
Jerome Coutant 0:146cf26a9bbb 119 uint16_t NullPacketSize;
Jerome Coutant 0:146cf26a9bbb 120 uint16_t NumberOfChunks;
Jerome Coutant 0:146cf26a9bbb 121 uint16_t PacketSize;
Jerome Coutant 0:146cf26a9bbb 122 } HDMI_DSIPacketTypeDef;
Jerome Coutant 0:146cf26a9bbb 123
Jerome Coutant 0:146cf26a9bbb 124 /**
Jerome Coutant 0:146cf26a9bbb 125 * @brief LTDC PLL params used for different HDMI adpater
Jerome Coutant 0:146cf26a9bbb 126 */
Jerome Coutant 0:146cf26a9bbb 127 typedef struct
Jerome Coutant 0:146cf26a9bbb 128 {
Jerome Coutant 0:146cf26a9bbb 129 uint16_t PLL_LTDC_N;
Jerome Coutant 0:146cf26a9bbb 130 uint16_t PLL_LTDC_R;
Jerome Coutant 0:146cf26a9bbb 131 uint32_t PCLK;
Jerome Coutant 0:146cf26a9bbb 132 uint16_t IDF;
Jerome Coutant 0:146cf26a9bbb 133 uint16_t NDIV;
Jerome Coutant 0:146cf26a9bbb 134 uint16_t ODF;
Jerome Coutant 0:146cf26a9bbb 135 uint16_t LaneByteClock;
Jerome Coutant 0:146cf26a9bbb 136 uint16_t TXEscapeCkdiv;
Jerome Coutant 0:146cf26a9bbb 137 } HDMI_PLLConfigTypeDef;
Jerome Coutant 0:146cf26a9bbb 138
Jerome Coutant 0:146cf26a9bbb 139 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 140 /**
Jerome Coutant 0:146cf26a9bbb 141 * @}
Jerome Coutant 0:146cf26a9bbb 142 */
Jerome Coutant 0:146cf26a9bbb 143
Jerome Coutant 0:146cf26a9bbb 144 /** @defgroup STM32H747I_DISCOVERY_LCD_Private_Macros Private Macros
Jerome Coutant 0:146cf26a9bbb 145 * @{
Jerome Coutant 0:146cf26a9bbb 146 */
Jerome Coutant 0:146cf26a9bbb 147 #define ABS(X) ((X) > 0 ? (X) : -(X))
Jerome Coutant 0:146cf26a9bbb 148 #define POLY_X(Z) ((int32_t)((Points + (Z))->X))
Jerome Coutant 0:146cf26a9bbb 149 #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y))
Jerome Coutant 0:146cf26a9bbb 150 /**
Jerome Coutant 0:146cf26a9bbb 151 * @}
Jerome Coutant 0:146cf26a9bbb 152 */
Jerome Coutant 0:146cf26a9bbb 153
Jerome Coutant 0:146cf26a9bbb 154 /** @defgroup STM32H747I_DISCOVERY_LCD_Exported_Variables Exported Variables
Jerome Coutant 0:146cf26a9bbb 155 * @{
Jerome Coutant 0:146cf26a9bbb 156 */
Jerome Coutant 0:146cf26a9bbb 157 DMA2D_HandleTypeDef hdma2d_discovery;
Jerome Coutant 0:146cf26a9bbb 158 LTDC_HandleTypeDef hltdc_discovery;
Jerome Coutant 0:146cf26a9bbb 159 DSI_HandleTypeDef hdsi_discovery;
Jerome Coutant 0:146cf26a9bbb 160
Jerome Coutant 0:146cf26a9bbb 161 /**
Jerome Coutant 0:146cf26a9bbb 162 * @}
Jerome Coutant 0:146cf26a9bbb 163 */
Jerome Coutant 0:146cf26a9bbb 164
Jerome Coutant 0:146cf26a9bbb 165 /** @defgroup STM32H747I_DISCOVERY_LCD_Private_Variables Private Variables
Jerome Coutant 0:146cf26a9bbb 166 * @{
Jerome Coutant 0:146cf26a9bbb 167 */
Jerome Coutant 0:146cf26a9bbb 168 static DSI_VidCfgTypeDef hdsivideo_handle;
Jerome Coutant 0:146cf26a9bbb 169 uint32_t lcd_x_size = OTM8009A_800X480_WIDTH;
Jerome Coutant 0:146cf26a9bbb 170 uint32_t lcd_y_size = OTM8009A_800X480_HEIGHT;
Jerome Coutant 0:146cf26a9bbb 171
Jerome Coutant 0:146cf26a9bbb 172 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 173 /**
Jerome Coutant 0:146cf26a9bbb 174 * @brief DSI timming used for different HDMI resolution (720x480 and 720x576)
Jerome Coutant 0:146cf26a9bbb 175 */
Jerome Coutant 0:146cf26a9bbb 176 HDMI_FormatTypeDef HDMI_Format[2] =
Jerome Coutant 0:146cf26a9bbb 177 {
Jerome Coutant 0:146cf26a9bbb 178 /* HA HS HB HF VA VS VB VF ASPECT BPP */
Jerome Coutant 0:146cf26a9bbb 179 {720, 62, 60, 30, 480, 6, 19, 9, HDMI_ASPECT_RATIO_4_3, LCD_DSI_PIXEL_DATA_FMT_RBG888},
Jerome Coutant 0:146cf26a9bbb 180 {720, 64, 68, 12, 576, 5, 39, 5, HDMI_ASPECT_RATIO_16_9, LCD_DSI_PIXEL_DATA_FMT_RBG888}
Jerome Coutant 0:146cf26a9bbb 181
Jerome Coutant 0:146cf26a9bbb 182 };
Jerome Coutant 0:146cf26a9bbb 183
Jerome Coutant 0:146cf26a9bbb 184 /**
Jerome Coutant 0:146cf26a9bbb 185 * @brief DSI packet size used for different HDMI resolution (720x480 and 720x576)
Jerome Coutant 0:146cf26a9bbb 186 */
Jerome Coutant 0:146cf26a9bbb 187 HDMI_DSIPacketTypeDef HDMI_DSIPacket[2] =
Jerome Coutant 0:146cf26a9bbb 188 {
Jerome Coutant 0:146cf26a9bbb 189 /* NP NC VP */
Jerome Coutant 0:146cf26a9bbb 190 {0, 1, 720},
Jerome Coutant 0:146cf26a9bbb 191 {0, 1, 720}
Jerome Coutant 0:146cf26a9bbb 192 };
Jerome Coutant 0:146cf26a9bbb 193
Jerome Coutant 0:146cf26a9bbb 194 /**
Jerome Coutant 0:146cf26a9bbb 195 * @brief LTDC PLL settings used for different HDMI resolution (720x480 and 720x576)
Jerome Coutant 0:146cf26a9bbb 196 */
Jerome Coutant 0:146cf26a9bbb 197 HDMI_PLLConfigTypeDef HDMI_PLLConfig[4] =
Jerome Coutant 0:146cf26a9bbb 198 {
Jerome Coutant 0:146cf26a9bbb 199 /* N DIV Pclk IDF NDIV ODF LBClk TXEscapeCkdiv*/
Jerome Coutant 0:146cf26a9bbb 200 {13, 12, 27083, DSI_PLL_IN_DIV5, 65, DSI_PLL_OUT_DIV1, 40625, 3},
Jerome Coutant 0:146cf26a9bbb 201 {13, 12, 27083, DSI_PLL_IN_DIV5, 65, DSI_PLL_OUT_DIV1, 40625, 3},
Jerome Coutant 0:146cf26a9bbb 202
Jerome Coutant 0:146cf26a9bbb 203 };
Jerome Coutant 0:146cf26a9bbb 204 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 205
Jerome Coutant 0:146cf26a9bbb 206 /**
Jerome Coutant 0:146cf26a9bbb 207 * @brief Default Active LTDC Layer in which drawing is made is LTDC Layer Background
Jerome Coutant 0:146cf26a9bbb 208 */
Jerome Coutant 0:146cf26a9bbb 209 static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
Jerome Coutant 0:146cf26a9bbb 210
Jerome Coutant 0:146cf26a9bbb 211 /**
Jerome Coutant 0:146cf26a9bbb 212 * @brief Current Drawing Layer properties variable
Jerome Coutant 0:146cf26a9bbb 213 */
Jerome Coutant 0:146cf26a9bbb 214 static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER];
Jerome Coutant 0:146cf26a9bbb 215 /**
Jerome Coutant 0:146cf26a9bbb 216 * @}
Jerome Coutant 0:146cf26a9bbb 217 */
Jerome Coutant 0:146cf26a9bbb 218
Jerome Coutant 0:146cf26a9bbb 219 /** @defgroup STM32H747I_DISCOVERY_LCD_Private_FunctionPrototypes Private FunctionPrototypes
Jerome Coutant 0:146cf26a9bbb 220 * @{
Jerome Coutant 0:146cf26a9bbb 221 */
Jerome Coutant 0:146cf26a9bbb 222 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
Jerome Coutant 0:146cf26a9bbb 223 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
Jerome Coutant 0:146cf26a9bbb 224 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
Jerome Coutant 0:146cf26a9bbb 225 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
Jerome Coutant 0:146cf26a9bbb 226 static uint16_t LCD_IO_GetID(void);
Jerome Coutant 0:146cf26a9bbb 227 /**
Jerome Coutant 0:146cf26a9bbb 228 * @}
Jerome Coutant 0:146cf26a9bbb 229 */
Jerome Coutant 0:146cf26a9bbb 230
Jerome Coutant 0:146cf26a9bbb 231 /** @defgroup STM32H747I_DISCOVERY_LCD_Exported_Functions Exported Functions
Jerome Coutant 0:146cf26a9bbb 232 * @{
Jerome Coutant 0:146cf26a9bbb 233 */
Jerome Coutant 0:146cf26a9bbb 234
Jerome Coutant 0:146cf26a9bbb 235 /**
Jerome Coutant 0:146cf26a9bbb 236 * @brief Initializes the DSI LCD.
Jerome Coutant 0:146cf26a9bbb 237 * @retval LCD state
Jerome Coutant 0:146cf26a9bbb 238 */
Jerome Coutant 0:146cf26a9bbb 239 uint8_t BSP_LCD_Init(void)
Jerome Coutant 0:146cf26a9bbb 240 {
Jerome Coutant 0:146cf26a9bbb 241 return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE));
Jerome Coutant 0:146cf26a9bbb 242 }
Jerome Coutant 0:146cf26a9bbb 243
Jerome Coutant 0:146cf26a9bbb 244 /**
Jerome Coutant 0:146cf26a9bbb 245 * @brief Initializes the DSI LCD.
Jerome Coutant 0:146cf26a9bbb 246 * The ititialization is done as below:
Jerome Coutant 0:146cf26a9bbb 247 * - DSI PLL ititialization
Jerome Coutant 0:146cf26a9bbb 248 * - DSI ititialization
Jerome Coutant 0:146cf26a9bbb 249 * - LTDC ititialization
Jerome Coutant 0:146cf26a9bbb 250 * - OTM8009A LCD Display IC Driver ititialization
Jerome Coutant 0:146cf26a9bbb 251 * @param orientation Display orientation
Jerome Coutant 0:146cf26a9bbb 252 * @retval LCD state
Jerome Coutant 0:146cf26a9bbb 253 */
Jerome Coutant 0:146cf26a9bbb 254 uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation)
Jerome Coutant 0:146cf26a9bbb 255 {
Jerome Coutant 0:146cf26a9bbb 256 DSI_PLLInitTypeDef dsiPllInit;
Jerome Coutant 0:146cf26a9bbb 257 DSI_PHY_TimerTypeDef PhyTimings;
Jerome Coutant 0:146cf26a9bbb 258 static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
Jerome Coutant 0:146cf26a9bbb 259 uint32_t LcdClock = 26400; /*!< LcdClk = 26400 kHz */
Jerome Coutant 0:146cf26a9bbb 260 uint16_t read_id = 0;
Jerome Coutant 0:146cf26a9bbb 261
Jerome Coutant 0:146cf26a9bbb 262 uint32_t laneByteClk_kHz = 0;
Jerome Coutant 0:146cf26a9bbb 263 uint32_t VSA; /*!< Vertical start active time in units of lines */
Jerome Coutant 0:146cf26a9bbb 264 uint32_t VBP; /*!< Vertical Back Porch time in units of lines */
Jerome Coutant 0:146cf26a9bbb 265 uint32_t VFP; /*!< Vertical Front Porch time in units of lines */
Jerome Coutant 0:146cf26a9bbb 266 uint32_t VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */
Jerome Coutant 0:146cf26a9bbb 267 uint32_t HSA; /*!< Horizontal start active time in units of lcdClk */
Jerome Coutant 0:146cf26a9bbb 268 uint32_t HBP; /*!< Horizontal Back Porch time in units of lcdClk */
Jerome Coutant 0:146cf26a9bbb 269 uint32_t HFP; /*!< Horizontal Front Porch time in units of lcdClk */
Jerome Coutant 0:146cf26a9bbb 270 uint32_t HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */
Jerome Coutant 0:146cf26a9bbb 271
Jerome Coutant 0:146cf26a9bbb 272 /* Toggle Hardware Reset of the DSI LCD using
Jerome Coutant 0:146cf26a9bbb 273 * its XRES signal (active low) */
Jerome Coutant 0:146cf26a9bbb 274 BSP_LCD_Reset();
Jerome Coutant 0:146cf26a9bbb 275
Jerome Coutant 0:146cf26a9bbb 276 /* Check the connected monitor */
Jerome Coutant 0:146cf26a9bbb 277 read_id = LCD_IO_GetID();
Jerome Coutant 0:146cf26a9bbb 278
Jerome Coutant 0:146cf26a9bbb 279 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 280 if(read_id == ADV7533_ID)
Jerome Coutant 0:146cf26a9bbb 281 {
Jerome Coutant 0:146cf26a9bbb 282 return BSP_LCD_HDMIInitEx(HDMI_FORMAT_720_576);
Jerome Coutant 0:146cf26a9bbb 283 }
Jerome Coutant 0:146cf26a9bbb 284 else if(read_id != LCD_DSI_ID)
Jerome Coutant 0:146cf26a9bbb 285 {
Jerome Coutant 0:146cf26a9bbb 286 return LCD_ERROR;
Jerome Coutant 0:146cf26a9bbb 287 }
Jerome Coutant 0:146cf26a9bbb 288 #else
Jerome Coutant 0:146cf26a9bbb 289 if(read_id != LCD_DSI_ID)
Jerome Coutant 0:146cf26a9bbb 290 {
Jerome Coutant 0:146cf26a9bbb 291 return LCD_ERROR;
Jerome Coutant 0:146cf26a9bbb 292 }
Jerome Coutant 0:146cf26a9bbb 293 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 294
Jerome Coutant 0:146cf26a9bbb 295 /* Call first MSP Initialize only in case of first initialization
Jerome Coutant 0:146cf26a9bbb 296 * This will set IP blocks LTDC, DSI and DMA2D
Jerome Coutant 0:146cf26a9bbb 297 * - out of reset
Jerome Coutant 0:146cf26a9bbb 298 * - clocked
Jerome Coutant 0:146cf26a9bbb 299 * - NVIC IRQ related to IP blocks enabled
Jerome Coutant 0:146cf26a9bbb 300 */
Jerome Coutant 0:146cf26a9bbb 301 BSP_LCD_MspInit();
Jerome Coutant 0:146cf26a9bbb 302
Jerome Coutant 0:146cf26a9bbb 303 /*************************DSI Initialization***********************************/
Jerome Coutant 0:146cf26a9bbb 304
Jerome Coutant 0:146cf26a9bbb 305 /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
Jerome Coutant 0:146cf26a9bbb 306 hdsi_discovery.Instance = DSI;
Jerome Coutant 0:146cf26a9bbb 307
Jerome Coutant 0:146cf26a9bbb 308 HAL_DSI_DeInit(&(hdsi_discovery));
Jerome Coutant 0:146cf26a9bbb 309
Jerome Coutant 0:146cf26a9bbb 310 dsiPllInit.PLLNDIV = 100;
Jerome Coutant 0:146cf26a9bbb 311 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
Jerome Coutant 0:146cf26a9bbb 312 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
Jerome Coutant 0:146cf26a9bbb 313 laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
Jerome Coutant 0:146cf26a9bbb 314
Jerome Coutant 0:146cf26a9bbb 315 /* Set number of Lanes */
Jerome Coutant 0:146cf26a9bbb 316 hdsi_discovery.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
Jerome Coutant 0:146cf26a9bbb 317
Jerome Coutant 0:146cf26a9bbb 318 /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
Jerome Coutant 0:146cf26a9bbb 319 hdsi_discovery.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
Jerome Coutant 0:146cf26a9bbb 320
Jerome Coutant 0:146cf26a9bbb 321 HAL_DSI_Init(&(hdsi_discovery), &(dsiPllInit));
Jerome Coutant 0:146cf26a9bbb 322
Jerome Coutant 0:146cf26a9bbb 323 /* Timing parameters for all Video modes
Jerome Coutant 0:146cf26a9bbb 324 * Set Timing parameters of LTDC depending on its chosen orientation
Jerome Coutant 0:146cf26a9bbb 325 */
Jerome Coutant 0:146cf26a9bbb 326 if(orientation == LCD_ORIENTATION_PORTRAIT)
Jerome Coutant 0:146cf26a9bbb 327 {
Jerome Coutant 0:146cf26a9bbb 328 lcd_x_size = OTM8009A_480X800_WIDTH; /* 480 */
Jerome Coutant 0:146cf26a9bbb 329 lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */
Jerome Coutant 0:146cf26a9bbb 330 }
Jerome Coutant 0:146cf26a9bbb 331 else
Jerome Coutant 0:146cf26a9bbb 332 {
Jerome Coutant 0:146cf26a9bbb 333 /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
Jerome Coutant 0:146cf26a9bbb 334 lcd_x_size = OTM8009A_800X480_WIDTH; /* 800 */
Jerome Coutant 0:146cf26a9bbb 335 lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */
Jerome Coutant 0:146cf26a9bbb 336 }
Jerome Coutant 0:146cf26a9bbb 337
Jerome Coutant 0:146cf26a9bbb 338 HACT = lcd_x_size;
Jerome Coutant 0:146cf26a9bbb 339 VACT = lcd_y_size;
Jerome Coutant 0:146cf26a9bbb 340
Jerome Coutant 0:146cf26a9bbb 341 /* The following values are same for portrait and landscape orientations */
Jerome Coutant 0:146cf26a9bbb 342 VSA = OTM8009A_480X800_VSYNC; /* 10 */
Jerome Coutant 0:146cf26a9bbb 343 VBP = OTM8009A_480X800_VBP; /* 15 */
Jerome Coutant 0:146cf26a9bbb 344 VFP = OTM8009A_480X800_VFP; /* 16 */
Jerome Coutant 0:146cf26a9bbb 345 HSA = OTM8009A_480X800_HSYNC; /* 2 */
Jerome Coutant 0:146cf26a9bbb 346 HBP = OTM8009A_480X800_HBP; /* 20 */
Jerome Coutant 0:146cf26a9bbb 347 HFP = OTM8009A_480X800_HFP; /* 20 */
Jerome Coutant 0:146cf26a9bbb 348
Jerome Coutant 0:146cf26a9bbb 349
Jerome Coutant 0:146cf26a9bbb 350 hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID;
Jerome Coutant 0:146cf26a9bbb 351 hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888;
Jerome Coutant 0:146cf26a9bbb 352 hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
Jerome Coutant 0:146cf26a9bbb 353 hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
Jerome Coutant 0:146cf26a9bbb 354 hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
Jerome Coutant 0:146cf26a9bbb 355 hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
Jerome Coutant 0:146cf26a9bbb 356 hdsivideo_handle.NullPacketSize = 0xFFF;
Jerome Coutant 0:146cf26a9bbb 357 hdsivideo_handle.NumberOfChunks = 0;
Jerome Coutant 0:146cf26a9bbb 358 hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 0:146cf26a9bbb 359 hdsivideo_handle.HorizontalSyncActive = (HSA * laneByteClk_kHz)/LcdClock;
Jerome Coutant 0:146cf26a9bbb 360 hdsivideo_handle.HorizontalBackPorch = (HBP * laneByteClk_kHz)/LcdClock;
Jerome Coutant 0:146cf26a9bbb 361 hdsivideo_handle.HorizontalLine = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz)/LcdClock; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 0:146cf26a9bbb 362 hdsivideo_handle.VerticalSyncActive = VSA;
Jerome Coutant 0:146cf26a9bbb 363 hdsivideo_handle.VerticalBackPorch = VBP;
Jerome Coutant 0:146cf26a9bbb 364 hdsivideo_handle.VerticalFrontPorch = VFP;
Jerome Coutant 0:146cf26a9bbb 365 hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 0:146cf26a9bbb 366
Jerome Coutant 0:146cf26a9bbb 367 /* Enable or disable sending LP command while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 368 hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
Jerome Coutant 0:146cf26a9bbb 369
Jerome Coutant 0:146cf26a9bbb 370 /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
Jerome Coutant 0:146cf26a9bbb 371 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 372 hdsivideo_handle.LPLargestPacketSize = 16;
Jerome Coutant 0:146cf26a9bbb 373
Jerome Coutant 0:146cf26a9bbb 374 /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
Jerome Coutant 0:146cf26a9bbb 375 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 376 hdsivideo_handle.LPVACTLargestPacketSize = 0;
Jerome Coutant 0:146cf26a9bbb 377
Jerome Coutant 0:146cf26a9bbb 378
Jerome Coutant 0:146cf26a9bbb 379 /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */
Jerome Coutant 0:146cf26a9bbb 380 /* while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 381 hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */
Jerome Coutant 0:146cf26a9bbb 382 hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */
Jerome Coutant 0:146cf26a9bbb 383 hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */
Jerome Coutant 0:146cf26a9bbb 384 hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */
Jerome Coutant 0:146cf26a9bbb 385 hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */
Jerome Coutant 0:146cf26a9bbb 386 hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
Jerome Coutant 0:146cf26a9bbb 387
Jerome Coutant 0:146cf26a9bbb 388 /* Configure DSI Video mode timings with settings set above */
Jerome Coutant 0:146cf26a9bbb 389 HAL_DSI_ConfigVideoMode(&(hdsi_discovery), &(hdsivideo_handle));
Jerome Coutant 0:146cf26a9bbb 390
Jerome Coutant 0:146cf26a9bbb 391 /* Configure DSI PHY HS2LP and LP2HS timings */
Jerome Coutant 0:146cf26a9bbb 392 PhyTimings.ClockLaneHS2LPTime = 35;
Jerome Coutant 0:146cf26a9bbb 393 PhyTimings.ClockLaneLP2HSTime = 35;
Jerome Coutant 0:146cf26a9bbb 394 PhyTimings.DataLaneHS2LPTime = 35;
Jerome Coutant 0:146cf26a9bbb 395 PhyTimings.DataLaneLP2HSTime = 35;
Jerome Coutant 0:146cf26a9bbb 396 PhyTimings.DataLaneMaxReadTime = 0;
Jerome Coutant 0:146cf26a9bbb 397 PhyTimings.StopWaitTime = 10;
Jerome Coutant 0:146cf26a9bbb 398 HAL_DSI_ConfigPhyTimer(&hdsi_discovery, &PhyTimings);
Jerome Coutant 0:146cf26a9bbb 399
Jerome Coutant 0:146cf26a9bbb 400 /*************************End DSI Initialization*******************************/
Jerome Coutant 0:146cf26a9bbb 401
Jerome Coutant 0:146cf26a9bbb 402
Jerome Coutant 0:146cf26a9bbb 403 /************************LTDC Initialization***********************************/
Jerome Coutant 0:146cf26a9bbb 404
Jerome Coutant 0:146cf26a9bbb 405 /* Timing Configuration */
Jerome Coutant 0:146cf26a9bbb 406 hltdc_discovery.Init.HorizontalSync = (HSA - 1);
Jerome Coutant 0:146cf26a9bbb 407 hltdc_discovery.Init.AccumulatedHBP = (HSA + HBP - 1);
Jerome Coutant 0:146cf26a9bbb 408 hltdc_discovery.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
Jerome Coutant 0:146cf26a9bbb 409 hltdc_discovery.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
Jerome Coutant 0:146cf26a9bbb 410
Jerome Coutant 0:146cf26a9bbb 411 /* Initialize the LCD pixel width and pixel height */
Jerome Coutant 0:146cf26a9bbb 412 hltdc_discovery.LayerCfg->ImageWidth = lcd_x_size;
Jerome Coutant 0:146cf26a9bbb 413 hltdc_discovery.LayerCfg->ImageHeight = lcd_y_size;
Jerome Coutant 0:146cf26a9bbb 414
Jerome Coutant 0:146cf26a9bbb 415
Jerome Coutant 0:146cf26a9bbb 416 /* LCD clock configuration */
Jerome Coutant 0:146cf26a9bbb 417 /* PLL3_VCO Input = HSE_VALUE/PLL3M = 5 Mhz */
Jerome Coutant 0:146cf26a9bbb 418 /* PLL3_VCO Output = PLL3_VCO Input * PLL3N = 480 Mhz */
Jerome Coutant 0:146cf26a9bbb 419 /* PLLLCDCLK = PLL3_VCO Output/PLL3R = 480/18 = 26.666 Mhz */
Jerome Coutant 0:146cf26a9bbb 420 /* LTDC clock frequency = PLLLCDCLK = 26.666 Mhz */
Jerome Coutant 0:146cf26a9bbb 421 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
Jerome Coutant 0:146cf26a9bbb 422 PeriphClkInitStruct.PLL3.PLL3M = 5;
Jerome Coutant 0:146cf26a9bbb 423 PeriphClkInitStruct.PLL3.PLL3N = 96;
Jerome Coutant 0:146cf26a9bbb 424 PeriphClkInitStruct.PLL3.PLL3P = 2;
Jerome Coutant 0:146cf26a9bbb 425 PeriphClkInitStruct.PLL3.PLL3Q = 10;
Jerome Coutant 0:146cf26a9bbb 426 PeriphClkInitStruct.PLL3.PLL3R = 18;
Jerome Coutant 0:146cf26a9bbb 427 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
Jerome Coutant 0:146cf26a9bbb 428
Jerome Coutant 0:146cf26a9bbb 429 /* Background value */
Jerome Coutant 0:146cf26a9bbb 430 hltdc_discovery.Init.Backcolor.Blue = 0;
Jerome Coutant 0:146cf26a9bbb 431 hltdc_discovery.Init.Backcolor.Green = 0;
Jerome Coutant 0:146cf26a9bbb 432 hltdc_discovery.Init.Backcolor.Red = 0;
Jerome Coutant 0:146cf26a9bbb 433 hltdc_discovery.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
Jerome Coutant 0:146cf26a9bbb 434 hltdc_discovery.Instance = LTDC;
Jerome Coutant 0:146cf26a9bbb 435
Jerome Coutant 0:146cf26a9bbb 436 /* Get LTDC Configuration from DSI Configuration */
Jerome Coutant 0:146cf26a9bbb 437 HAL_LTDC_StructInitFromVideoConfig(&(hltdc_discovery), &(hdsivideo_handle));
Jerome Coutant 0:146cf26a9bbb 438
Jerome Coutant 0:146cf26a9bbb 439 /* Initialize the LTDC */
Jerome Coutant 0:146cf26a9bbb 440 HAL_LTDC_Init(&hltdc_discovery);
Jerome Coutant 0:146cf26a9bbb 441
Jerome Coutant 0:146cf26a9bbb 442 /* Enable the DSI host and wrapper : after LTDC */
Jerome Coutant 0:146cf26a9bbb 443 /* To avoid any synchronization issue, the DSI shall be started after enabling the LTDC */
Jerome Coutant 0:146cf26a9bbb 444 HAL_DSI_Start(&hdsi_discovery);
Jerome Coutant 0:146cf26a9bbb 445
Jerome Coutant 0:146cf26a9bbb 446 #if !defined(DATA_IN_ExtSDRAM)
Jerome Coutant 0:146cf26a9bbb 447 /* Initialize the SDRAM */
Jerome Coutant 0:146cf26a9bbb 448 BSP_SDRAM_Init();
Jerome Coutant 0:146cf26a9bbb 449 #endif /* DATA_IN_ExtSDRAM */
Jerome Coutant 0:146cf26a9bbb 450
Jerome Coutant 0:146cf26a9bbb 451 /* Initialize the font */
Jerome Coutant 0:146cf26a9bbb 452 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
Jerome Coutant 0:146cf26a9bbb 453
Jerome Coutant 0:146cf26a9bbb 454 /************************End LTDC Initialization*******************************/
Jerome Coutant 0:146cf26a9bbb 455
Jerome Coutant 0:146cf26a9bbb 456
Jerome Coutant 0:146cf26a9bbb 457 /***********************OTM8009A Initialization********************************/
Jerome Coutant 0:146cf26a9bbb 458
Jerome Coutant 0:146cf26a9bbb 459 /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
Jerome Coutant 0:146cf26a9bbb 460 * depending on configuration set in 'hdsivideo_handle'.
Jerome Coutant 0:146cf26a9bbb 461 */
Jerome Coutant 0:146cf26a9bbb 462 OTM8009A_Init(OTM8009A_FORMAT_RGB888, orientation);
Jerome Coutant 0:146cf26a9bbb 463
Jerome Coutant 0:146cf26a9bbb 464 /***********************End OTM8009A Initialization****************************/
Jerome Coutant 0:146cf26a9bbb 465
Jerome Coutant 0:146cf26a9bbb 466 return LCD_OK;
Jerome Coutant 0:146cf26a9bbb 467 }
Jerome Coutant 0:146cf26a9bbb 468
Jerome Coutant 0:146cf26a9bbb 469 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 470 /**
Jerome Coutant 0:146cf26a9bbb 471 * @brief Initializes the DSI for HDMI monitor.
Jerome Coutant 0:146cf26a9bbb 472 * The ititialization is done as below:
Jerome Coutant 0:146cf26a9bbb 473 * - DSI PLL ititialization
Jerome Coutant 0:146cf26a9bbb 474 * - DSI ititialization
Jerome Coutant 0:146cf26a9bbb 475 * - LTDC ititialization
Jerome Coutant 0:146cf26a9bbb 476 * - DSI-HDMI ADV7533 adapter device ititialization
Jerome Coutant 0:146cf26a9bbb 477 * @param format : HDMI format could be HDMI_FORMAT_720_480 or HDMI_FORMAT_720_576
Jerome Coutant 0:146cf26a9bbb 478 * @retval LCD state
Jerome Coutant 0:146cf26a9bbb 479 */
Jerome Coutant 0:146cf26a9bbb 480 uint8_t BSP_LCD_HDMIInitEx(uint8_t format)
Jerome Coutant 0:146cf26a9bbb 481 {
Jerome Coutant 0:146cf26a9bbb 482 /************************ADV7533 Initialization******************************/
Jerome Coutant 0:146cf26a9bbb 483
Jerome Coutant 0:146cf26a9bbb 484 /* Initialize the ADV7533 HDMI Bridge
Jerome Coutant 0:146cf26a9bbb 485 depending on configuration set in 'hdsivideo_handle'. */
Jerome Coutant 0:146cf26a9bbb 486 adv7533ConfigTypeDef adv7533_config;
Jerome Coutant 0:146cf26a9bbb 487
Jerome Coutant 0:146cf26a9bbb 488 adv7533_config.DSI_LANES = 2;
Jerome Coutant 0:146cf26a9bbb 489 adv7533_config.HACT = HDMI_Format[format].HACT;
Jerome Coutant 0:146cf26a9bbb 490 adv7533_config.HSYNC = HDMI_Format[format].HSYNC;
Jerome Coutant 0:146cf26a9bbb 491 adv7533_config.HBP = HDMI_Format[format].HBP;
Jerome Coutant 0:146cf26a9bbb 492 adv7533_config.HFP = HDMI_Format[format].HFP;
Jerome Coutant 0:146cf26a9bbb 493 adv7533_config.VACT = HDMI_Format[format].VACT;
Jerome Coutant 0:146cf26a9bbb 494 adv7533_config.VSYNC = HDMI_Format[format].VSYNC;
Jerome Coutant 0:146cf26a9bbb 495 adv7533_config.VBP = HDMI_Format[format].VBP;
Jerome Coutant 0:146cf26a9bbb 496 adv7533_config.VFP = HDMI_Format[format].VFP;
Jerome Coutant 0:146cf26a9bbb 497
Jerome Coutant 0:146cf26a9bbb 498 ADV7533_Init();
Jerome Coutant 0:146cf26a9bbb 499 ADV7533_Configure(&adv7533_config);
Jerome Coutant 0:146cf26a9bbb 500 ADV7533_PowerOn();
Jerome Coutant 0:146cf26a9bbb 501
Jerome Coutant 0:146cf26a9bbb 502 /************************ Update hdmi_x_size and hdmi_y_size *****************/
Jerome Coutant 0:146cf26a9bbb 503 lcd_x_size = HDMI_Format[format].HACT;
Jerome Coutant 0:146cf26a9bbb 504 lcd_y_size = HDMI_Format[format].VACT;
Jerome Coutant 0:146cf26a9bbb 505
Jerome Coutant 0:146cf26a9bbb 506 /***********************End ADV7533 Initialization****************************/
Jerome Coutant 0:146cf26a9bbb 507
Jerome Coutant 0:146cf26a9bbb 508 DSI_PLLInitTypeDef dsiPllInit;
Jerome Coutant 0:146cf26a9bbb 509 DSI_PHY_TimerTypeDef dsiPhyInit;
Jerome Coutant 0:146cf26a9bbb 510 static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
Jerome Coutant 0:146cf26a9bbb 511
Jerome Coutant 0:146cf26a9bbb 512 /* Call first MSP Initialize only in case of first initialization
Jerome Coutant 0:146cf26a9bbb 513 * This will set IP blocks LTDC and DSI
Jerome Coutant 0:146cf26a9bbb 514 * - out of reset
Jerome Coutant 0:146cf26a9bbb 515 * - clocked
Jerome Coutant 0:146cf26a9bbb 516 * - NVIC IRQ related to IP blocks enabled
Jerome Coutant 0:146cf26a9bbb 517 */
Jerome Coutant 0:146cf26a9bbb 518 BSP_LCD_MspInit();
Jerome Coutant 0:146cf26a9bbb 519
Jerome Coutant 0:146cf26a9bbb 520 /*************************DSI Initialization***********************************/
Jerome Coutant 0:146cf26a9bbb 521
Jerome Coutant 0:146cf26a9bbb 522 /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
Jerome Coutant 0:146cf26a9bbb 523 hdsi_discovery.Instance = DSI;
Jerome Coutant 0:146cf26a9bbb 524
Jerome Coutant 0:146cf26a9bbb 525 HAL_DSI_DeInit(&(hdsi_discovery));
Jerome Coutant 0:146cf26a9bbb 526
Jerome Coutant 0:146cf26a9bbb 527 /* Configure the DSI PLL */
Jerome Coutant 0:146cf26a9bbb 528 dsiPllInit.PLLNDIV = HDMI_PLLConfig[format].NDIV;
Jerome Coutant 0:146cf26a9bbb 529 dsiPllInit.PLLIDF = HDMI_PLLConfig[format].IDF;
Jerome Coutant 0:146cf26a9bbb 530 dsiPllInit.PLLODF = HDMI_PLLConfig[format].ODF;
Jerome Coutant 0:146cf26a9bbb 531
Jerome Coutant 0:146cf26a9bbb 532 /* Set number of Lanes */
Jerome Coutant 0:146cf26a9bbb 533 hdsi_discovery.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
Jerome Coutant 0:146cf26a9bbb 534 /* Set the TX escape clock division ratio */
Jerome Coutant 0:146cf26a9bbb 535 hdsi_discovery.Init.TXEscapeCkdiv = HDMI_PLLConfig[format].TXEscapeCkdiv;
Jerome Coutant 0:146cf26a9bbb 536 /* Disable the automatic clock lane control (the ADV7533 must be clocked) */
Jerome Coutant 0:146cf26a9bbb 537 hdsi_discovery.Init.AutomaticClockLaneControl = DSI_AUTO_CLK_LANE_CTRL_DISABLE;
Jerome Coutant 0:146cf26a9bbb 538
Jerome Coutant 0:146cf26a9bbb 539 /* Init the DSI */
Jerome Coutant 0:146cf26a9bbb 540 HAL_DSI_Init(&hdsi_discovery, &dsiPllInit);
Jerome Coutant 0:146cf26a9bbb 541
Jerome Coutant 0:146cf26a9bbb 542 /* Configure the D-PHY Timings */
Jerome Coutant 0:146cf26a9bbb 543 dsiPhyInit.ClockLaneHS2LPTime = 0x14;
Jerome Coutant 0:146cf26a9bbb 544 dsiPhyInit.ClockLaneLP2HSTime = 0x14;
Jerome Coutant 0:146cf26a9bbb 545 dsiPhyInit.DataLaneHS2LPTime = 0x0A;
Jerome Coutant 0:146cf26a9bbb 546 dsiPhyInit.DataLaneLP2HSTime = 0x0A;
Jerome Coutant 0:146cf26a9bbb 547 dsiPhyInit.DataLaneMaxReadTime = 0x00;
Jerome Coutant 0:146cf26a9bbb 548 dsiPhyInit.StopWaitTime = 0x0;
Jerome Coutant 0:146cf26a9bbb 549 HAL_DSI_ConfigPhyTimer(&hdsi_discovery, &dsiPhyInit);
Jerome Coutant 0:146cf26a9bbb 550
Jerome Coutant 0:146cf26a9bbb 551 /* Virutal channel used by the ADV7533 */
Jerome Coutant 0:146cf26a9bbb 552 hdsivideo_handle.VirtualChannelID = HDMI_ADV7533_ID;
Jerome Coutant 0:146cf26a9bbb 553
Jerome Coutant 0:146cf26a9bbb 554 /* Timing parameters for Video modes
Jerome Coutant 0:146cf26a9bbb 555 Set Timing parameters of DSI depending on its chosen format */
Jerome Coutant 0:146cf26a9bbb 556 hdsivideo_handle.ColorCoding = HDMI_Format[format].RGB_CODING;
Jerome Coutant 0:146cf26a9bbb 557 hdsivideo_handle.LooselyPacked = DSI_LOOSELY_PACKED_DISABLE;
Jerome Coutant 0:146cf26a9bbb 558 hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_LOW;
Jerome Coutant 0:146cf26a9bbb 559 hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_LOW;
Jerome Coutant 0:146cf26a9bbb 560 hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
Jerome Coutant 0:146cf26a9bbb 561 hdsivideo_handle.Mode = DSI_VID_MODE_NB_PULSES;
Jerome Coutant 0:146cf26a9bbb 562 hdsivideo_handle.NullPacketSize = HDMI_DSIPacket[format].NullPacketSize;
Jerome Coutant 0:146cf26a9bbb 563 hdsivideo_handle.NumberOfChunks = HDMI_DSIPacket[format].NumberOfChunks;
Jerome Coutant 0:146cf26a9bbb 564 hdsivideo_handle.PacketSize = HDMI_DSIPacket[format].PacketSize;
Jerome Coutant 0:146cf26a9bbb 565 hdsivideo_handle.HorizontalSyncActive = HDMI_Format[format].HSYNC*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
Jerome Coutant 0:146cf26a9bbb 566 hdsivideo_handle.HorizontalBackPorch = HDMI_Format[format].HBP*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
Jerome Coutant 0:146cf26a9bbb 567 hdsivideo_handle.HorizontalLine = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP + HDMI_Format[format].HFP)*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
Jerome Coutant 0:146cf26a9bbb 568 hdsivideo_handle.VerticalSyncActive = HDMI_Format[format].VSYNC;
Jerome Coutant 0:146cf26a9bbb 569 hdsivideo_handle.VerticalBackPorch = HDMI_Format[format].VBP;
Jerome Coutant 0:146cf26a9bbb 570 hdsivideo_handle.VerticalFrontPorch = HDMI_Format[format].VFP;
Jerome Coutant 0:146cf26a9bbb 571 hdsivideo_handle.VerticalActive = HDMI_Format[format].VACT;
Jerome Coutant 0:146cf26a9bbb 572
Jerome Coutant 0:146cf26a9bbb 573 /* Enable or disable sending LP command while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 574 hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_DISABLE; /* Enable sending commands in mode LP (Low Power) */
Jerome Coutant 0:146cf26a9bbb 575
Jerome Coutant 0:146cf26a9bbb 576 /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
Jerome Coutant 0:146cf26a9bbb 577 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 578 hdsivideo_handle.LPLargestPacketSize = 4;
Jerome Coutant 0:146cf26a9bbb 579
Jerome Coutant 0:146cf26a9bbb 580 /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
Jerome Coutant 0:146cf26a9bbb 581 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 582 hdsivideo_handle.LPVACTLargestPacketSize = 4;
Jerome Coutant 0:146cf26a9bbb 583
Jerome Coutant 0:146cf26a9bbb 584 /* Specify for each region, if the going in LP mode is allowed */
Jerome Coutant 0:146cf26a9bbb 585 /* while streaming is active in video mode */
Jerome Coutant 0:146cf26a9bbb 586 hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_DISABLE;
Jerome Coutant 0:146cf26a9bbb 587 hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_DISABLE;
Jerome Coutant 0:146cf26a9bbb 588 hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_DISABLE;
Jerome Coutant 0:146cf26a9bbb 589 hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_DISABLE;
Jerome Coutant 0:146cf26a9bbb 590 hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_DISABLE;
Jerome Coutant 0:146cf26a9bbb 591 hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_DISABLE;
Jerome Coutant 0:146cf26a9bbb 592
Jerome Coutant 0:146cf26a9bbb 593 /* No acknoledge at the end of a frame */
Jerome Coutant 0:146cf26a9bbb 594 hdsivideo_handle.FrameBTAAcknowledgeEnable = DSI_FBTAA_DISABLE;
Jerome Coutant 0:146cf26a9bbb 595
Jerome Coutant 0:146cf26a9bbb 596 /* Configure DSI Video mode timings with settings set above */
Jerome Coutant 0:146cf26a9bbb 597 HAL_DSI_ConfigVideoMode(&hdsi_discovery, &hdsivideo_handle);
Jerome Coutant 0:146cf26a9bbb 598
Jerome Coutant 0:146cf26a9bbb 599 /* Enable the DSI host and wrapper : but LTDC is not started yet at this stage */
Jerome Coutant 0:146cf26a9bbb 600 HAL_DSI_Start(&hdsi_discovery);
Jerome Coutant 0:146cf26a9bbb 601
Jerome Coutant 0:146cf26a9bbb 602 /*************************End DSI Initialization*******************************/
Jerome Coutant 0:146cf26a9bbb 603
Jerome Coutant 0:146cf26a9bbb 604
Jerome Coutant 0:146cf26a9bbb 605 /************************LTDC Initialization***********************************/
Jerome Coutant 0:146cf26a9bbb 606
Jerome Coutant 0:146cf26a9bbb 607 /* LCD clock configuration */
Jerome Coutant 0:146cf26a9bbb 608 /* LCD clock configuration */
Jerome Coutant 0:146cf26a9bbb 609 /* PLL3_VCO Input = HSE_VALUE/PLL3M = 25 Mhz */
Jerome Coutant 0:146cf26a9bbb 610 /* PLL3_VCO Output = PLL3_VCO Input * PLL3N */
Jerome Coutant 0:146cf26a9bbb 611 /* PLLLCDCLK = PLL3_VCO Output/PLL3R */
Jerome Coutant 0:146cf26a9bbb 612 /* LTDC clock frequency = PLLLCDCLK */
Jerome Coutant 0:146cf26a9bbb 613 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
Jerome Coutant 0:146cf26a9bbb 614 PeriphClkInitStruct.PLL3.PLL3M = 1;
Jerome Coutant 0:146cf26a9bbb 615 PeriphClkInitStruct.PLL3.PLL3N = HDMI_PLLConfig[format].PLL_LTDC_N;
Jerome Coutant 0:146cf26a9bbb 616 PeriphClkInitStruct.PLL3.PLL3P = 2;
Jerome Coutant 0:146cf26a9bbb 617 PeriphClkInitStruct.PLL3.PLL3Q = 2;
Jerome Coutant 0:146cf26a9bbb 618 PeriphClkInitStruct.PLL3.PLL3R = HDMI_PLLConfig[format].PLL_LTDC_R;
Jerome Coutant 0:146cf26a9bbb 619 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
Jerome Coutant 0:146cf26a9bbb 620
Jerome Coutant 0:146cf26a9bbb 621 /* Base address of LTDC registers to be set before calling De-Init */
Jerome Coutant 0:146cf26a9bbb 622 hltdc_discovery.Instance = LTDC;
Jerome Coutant 0:146cf26a9bbb 623
Jerome Coutant 0:146cf26a9bbb 624 HAL_LTDC_DeInit(&(hltdc_discovery));
Jerome Coutant 0:146cf26a9bbb 625
Jerome Coutant 0:146cf26a9bbb 626 /* Timing Configuration */
Jerome Coutant 0:146cf26a9bbb 627 hltdc_discovery.Init.HorizontalSync = (HDMI_Format[format].HSYNC - 1);
Jerome Coutant 0:146cf26a9bbb 628 hltdc_discovery.Init.AccumulatedHBP = (HDMI_Format[format].HSYNC + HDMI_Format[format].HBP - 1);
Jerome Coutant 0:146cf26a9bbb 629 hltdc_discovery.Init.AccumulatedActiveW = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP - 1);
Jerome Coutant 0:146cf26a9bbb 630 hltdc_discovery.Init.TotalWidth = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP + HDMI_Format[format].HFP - 1);
Jerome Coutant 0:146cf26a9bbb 631 hltdc_discovery.Init.VerticalSync = (HDMI_Format[format].VSYNC - 1);
Jerome Coutant 0:146cf26a9bbb 632 hltdc_discovery.Init.AccumulatedVBP = (HDMI_Format[format].VSYNC + HDMI_Format[format].VBP - 1);
Jerome Coutant 0:146cf26a9bbb 633 hltdc_discovery.Init.AccumulatedActiveH = (HDMI_Format[format].VACT + HDMI_Format[format].VSYNC + HDMI_Format[format].VBP - 1);
Jerome Coutant 0:146cf26a9bbb 634 hltdc_discovery.Init.TotalHeigh = (HDMI_Format[format].VACT + HDMI_Format[format].VSYNC + HDMI_Format[format].VBP + HDMI_Format[format].VFP - 1);
Jerome Coutant 0:146cf26a9bbb 635
Jerome Coutant 0:146cf26a9bbb 636 /* background value */
Jerome Coutant 0:146cf26a9bbb 637 hltdc_discovery.Init.Backcolor.Blue = 0x00;
Jerome Coutant 0:146cf26a9bbb 638 hltdc_discovery.Init.Backcolor.Green = 0xFF;
Jerome Coutant 0:146cf26a9bbb 639 hltdc_discovery.Init.Backcolor.Red = 0xFF;
Jerome Coutant 0:146cf26a9bbb 640
Jerome Coutant 0:146cf26a9bbb 641 /* Polarity */
Jerome Coutant 0:146cf26a9bbb 642 hltdc_discovery.Init.HSPolarity = LTDC_HSPOLARITY_AL;
Jerome Coutant 0:146cf26a9bbb 643 hltdc_discovery.Init.VSPolarity = LTDC_VSPOLARITY_AL;
Jerome Coutant 0:146cf26a9bbb 644 hltdc_discovery.Init.DEPolarity = LTDC_DEPOLARITY_AL;
Jerome Coutant 0:146cf26a9bbb 645 hltdc_discovery.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
Jerome Coutant 0:146cf26a9bbb 646
Jerome Coutant 0:146cf26a9bbb 647 /* Initialize & Start the LTDC */
Jerome Coutant 0:146cf26a9bbb 648 HAL_LTDC_Init(&hltdc_discovery);
Jerome Coutant 0:146cf26a9bbb 649
Jerome Coutant 0:146cf26a9bbb 650 #if !defined(DATA_IN_ExtSDRAM)
Jerome Coutant 0:146cf26a9bbb 651 /* Initialize the SDRAM */
Jerome Coutant 0:146cf26a9bbb 652 BSP_SDRAM_Init();
Jerome Coutant 0:146cf26a9bbb 653 #endif /* DATA_IN_ExtSDRAM */
Jerome Coutant 0:146cf26a9bbb 654
Jerome Coutant 0:146cf26a9bbb 655 /* Initialize the font */
Jerome Coutant 0:146cf26a9bbb 656 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
Jerome Coutant 0:146cf26a9bbb 657 /************************End LTDC Initialization*******************************/
Jerome Coutant 0:146cf26a9bbb 658
Jerome Coutant 0:146cf26a9bbb 659 return LCD_OK;
Jerome Coutant 0:146cf26a9bbb 660 }
Jerome Coutant 0:146cf26a9bbb 661 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 662
Jerome Coutant 0:146cf26a9bbb 663 /**
Jerome Coutant 0:146cf26a9bbb 664 * @brief BSP LCD Reset
Jerome Coutant 0:146cf26a9bbb 665 * Hw reset the LCD DSI activating its XRES signal (active low for some time)
Jerome Coutant 0:146cf26a9bbb 666 * and deactivating it later.
Jerome Coutant 0:146cf26a9bbb 667 * @retval None
Jerome Coutant 0:146cf26a9bbb 668 */
Jerome Coutant 0:146cf26a9bbb 669 void BSP_LCD_Reset(void)
Jerome Coutant 0:146cf26a9bbb 670 {
Jerome Coutant 0:146cf26a9bbb 671 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:146cf26a9bbb 672
Jerome Coutant 0:146cf26a9bbb 673 __HAL_RCC_GPIOG_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 674
Jerome Coutant 0:146cf26a9bbb 675 /* Configure the GPIO on PG3 */
Jerome Coutant 0:146cf26a9bbb 676 gpio_init_structure.Pin = GPIO_PIN_3;
Jerome Coutant 0:146cf26a9bbb 677 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 0:146cf26a9bbb 678 gpio_init_structure.Pull = GPIO_PULLUP;
Jerome Coutant 0:146cf26a9bbb 679 gpio_init_structure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
Jerome Coutant 0:146cf26a9bbb 680
Jerome Coutant 0:146cf26a9bbb 681 HAL_GPIO_Init(GPIOG, &gpio_init_structure);
Jerome Coutant 0:146cf26a9bbb 682
Jerome Coutant 0:146cf26a9bbb 683 /* Activate XRES active low */
Jerome Coutant 0:146cf26a9bbb 684 HAL_GPIO_WritePin(GPIOG, GPIO_PIN_3, GPIO_PIN_RESET);
Jerome Coutant 0:146cf26a9bbb 685
Jerome Coutant 0:146cf26a9bbb 686 HAL_Delay(20); /* wait 20 ms */
Jerome Coutant 0:146cf26a9bbb 687
Jerome Coutant 0:146cf26a9bbb 688 /* Desactivate XRES */
Jerome Coutant 0:146cf26a9bbb 689 HAL_GPIO_WritePin(GPIOG, GPIO_PIN_3, GPIO_PIN_SET);
Jerome Coutant 0:146cf26a9bbb 690
Jerome Coutant 0:146cf26a9bbb 691 /* Wait for 10ms after releasing XRES before sending commands */
Jerome Coutant 0:146cf26a9bbb 692 HAL_Delay(10);
Jerome Coutant 0:146cf26a9bbb 693 }
Jerome Coutant 0:146cf26a9bbb 694
Jerome Coutant 0:146cf26a9bbb 695 /**
Jerome Coutant 0:146cf26a9bbb 696 * @brief Gets the LCD X size.
Jerome Coutant 0:146cf26a9bbb 697 * @retval Used LCD X size
Jerome Coutant 0:146cf26a9bbb 698 */
Jerome Coutant 0:146cf26a9bbb 699 uint32_t BSP_LCD_GetXSize(void)
Jerome Coutant 0:146cf26a9bbb 700 {
Jerome Coutant 0:146cf26a9bbb 701 return (lcd_x_size);
Jerome Coutant 0:146cf26a9bbb 702 }
Jerome Coutant 0:146cf26a9bbb 703
Jerome Coutant 0:146cf26a9bbb 704 /**
Jerome Coutant 0:146cf26a9bbb 705 * @brief Gets the LCD Y size.
Jerome Coutant 0:146cf26a9bbb 706 * @retval Used LCD Y size
Jerome Coutant 0:146cf26a9bbb 707 */
Jerome Coutant 0:146cf26a9bbb 708 uint32_t BSP_LCD_GetYSize(void)
Jerome Coutant 0:146cf26a9bbb 709 {
Jerome Coutant 0:146cf26a9bbb 710 return (lcd_y_size);
Jerome Coutant 0:146cf26a9bbb 711 }
Jerome Coutant 0:146cf26a9bbb 712
Jerome Coutant 0:146cf26a9bbb 713 /**
Jerome Coutant 0:146cf26a9bbb 714 * @brief Set the LCD X size.
Jerome Coutant 0:146cf26a9bbb 715 * @param imageWidthPixels : uint32_t image width in pixels unit
Jerome Coutant 0:146cf26a9bbb 716 * @retval None
Jerome Coutant 0:146cf26a9bbb 717 */
Jerome Coutant 0:146cf26a9bbb 718 void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
Jerome Coutant 0:146cf26a9bbb 719 {
Jerome Coutant 0:146cf26a9bbb 720 hltdc_discovery.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
Jerome Coutant 0:146cf26a9bbb 721 }
Jerome Coutant 0:146cf26a9bbb 722
Jerome Coutant 0:146cf26a9bbb 723 /**
Jerome Coutant 0:146cf26a9bbb 724 * @brief Set the LCD Y size.
Jerome Coutant 0:146cf26a9bbb 725 * @param imageHeightPixels : uint32_t image height in lines unit
Jerome Coutant 0:146cf26a9bbb 726 */
Jerome Coutant 0:146cf26a9bbb 727 void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
Jerome Coutant 0:146cf26a9bbb 728 {
Jerome Coutant 0:146cf26a9bbb 729 hltdc_discovery.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
Jerome Coutant 0:146cf26a9bbb 730 }
Jerome Coutant 0:146cf26a9bbb 731
Jerome Coutant 0:146cf26a9bbb 732
Jerome Coutant 0:146cf26a9bbb 733 /**
Jerome Coutant 0:146cf26a9bbb 734 * @brief Initializes the LCD layers.
Jerome Coutant 0:146cf26a9bbb 735 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:146cf26a9bbb 736 * @param FB_Address: Layer frame buffer
Jerome Coutant 0:146cf26a9bbb 737 * @retval None
Jerome Coutant 0:146cf26a9bbb 738 */
Jerome Coutant 0:146cf26a9bbb 739 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
Jerome Coutant 0:146cf26a9bbb 740 {
Jerome Coutant 0:146cf26a9bbb 741 LCD_LayerCfgTypeDef Layercfg;
Jerome Coutant 0:146cf26a9bbb 742
Jerome Coutant 0:146cf26a9bbb 743 /* Layer Init */
Jerome Coutant 0:146cf26a9bbb 744 Layercfg.WindowX0 = 0;
Jerome Coutant 0:146cf26a9bbb 745 Layercfg.WindowX1 = BSP_LCD_GetXSize();
Jerome Coutant 0:146cf26a9bbb 746 Layercfg.WindowY0 = 0;
Jerome Coutant 0:146cf26a9bbb 747 Layercfg.WindowY1 = BSP_LCD_GetYSize();
Jerome Coutant 0:146cf26a9bbb 748 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
Jerome Coutant 0:146cf26a9bbb 749 Layercfg.FBStartAdress = FB_Address;
Jerome Coutant 0:146cf26a9bbb 750 Layercfg.Alpha = 255;
Jerome Coutant 0:146cf26a9bbb 751 Layercfg.Alpha0 = 0;
Jerome Coutant 0:146cf26a9bbb 752 Layercfg.Backcolor.Blue = 0;
Jerome Coutant 0:146cf26a9bbb 753 Layercfg.Backcolor.Green = 0;
Jerome Coutant 0:146cf26a9bbb 754 Layercfg.Backcolor.Red = 0;
Jerome Coutant 0:146cf26a9bbb 755 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
Jerome Coutant 0:146cf26a9bbb 756 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
Jerome Coutant 0:146cf26a9bbb 757 Layercfg.ImageWidth = BSP_LCD_GetXSize();
Jerome Coutant 0:146cf26a9bbb 758 Layercfg.ImageHeight = BSP_LCD_GetYSize();
Jerome Coutant 0:146cf26a9bbb 759
Jerome Coutant 0:146cf26a9bbb 760 HAL_LTDC_ConfigLayer(&hltdc_discovery, &Layercfg, LayerIndex);
Jerome Coutant 0:146cf26a9bbb 761
Jerome Coutant 0:146cf26a9bbb 762 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
Jerome Coutant 0:146cf26a9bbb 763 DrawProp[LayerIndex].pFont = &Font24;
Jerome Coutant 0:146cf26a9bbb 764 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
Jerome Coutant 0:146cf26a9bbb 765 }
Jerome Coutant 0:146cf26a9bbb 766
Jerome Coutant 0:146cf26a9bbb 767
Jerome Coutant 0:146cf26a9bbb 768 /**
Jerome Coutant 0:146cf26a9bbb 769 * @brief Selects the LCD Layer.
Jerome Coutant 0:146cf26a9bbb 770 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:146cf26a9bbb 771 */
Jerome Coutant 0:146cf26a9bbb 772 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
Jerome Coutant 0:146cf26a9bbb 773 {
Jerome Coutant 0:146cf26a9bbb 774 ActiveLayer = LayerIndex;
Jerome Coutant 0:146cf26a9bbb 775 }
Jerome Coutant 0:146cf26a9bbb 776
Jerome Coutant 0:146cf26a9bbb 777 /**
Jerome Coutant 0:146cf26a9bbb 778 * @brief Sets an LCD Layer visible
Jerome Coutant 0:146cf26a9bbb 779 * @param LayerIndex: Visible Layer
Jerome Coutant 0:146cf26a9bbb 780 * @param State: New state of the specified layer
Jerome Coutant 0:146cf26a9bbb 781 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 782 * @arg ENABLE
Jerome Coutant 0:146cf26a9bbb 783 * @arg DISABLE
Jerome Coutant 0:146cf26a9bbb 784 */
Jerome Coutant 0:146cf26a9bbb 785 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
Jerome Coutant 0:146cf26a9bbb 786 {
Jerome Coutant 0:146cf26a9bbb 787 if(State == ENABLE)
Jerome Coutant 0:146cf26a9bbb 788 {
Jerome Coutant 0:146cf26a9bbb 789 __HAL_LTDC_LAYER_ENABLE(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:146cf26a9bbb 790 }
Jerome Coutant 0:146cf26a9bbb 791 else
Jerome Coutant 0:146cf26a9bbb 792 {
Jerome Coutant 0:146cf26a9bbb 793 __HAL_LTDC_LAYER_DISABLE(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:146cf26a9bbb 794 }
Jerome Coutant 0:146cf26a9bbb 795 __HAL_LTDC_RELOAD_CONFIG(&(hltdc_discovery));
Jerome Coutant 0:146cf26a9bbb 796
Jerome Coutant 0:146cf26a9bbb 797 }
Jerome Coutant 0:146cf26a9bbb 798
Jerome Coutant 0:146cf26a9bbb 799 /**
Jerome Coutant 0:146cf26a9bbb 800 * @brief Configures the transparency.
Jerome Coutant 0:146cf26a9bbb 801 * @param LayerIndex: Layer foreground or background.
Jerome Coutant 0:146cf26a9bbb 802 * @param Transparency: Transparency
Jerome Coutant 0:146cf26a9bbb 803 * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
Jerome Coutant 0:146cf26a9bbb 804 */
Jerome Coutant 0:146cf26a9bbb 805 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
Jerome Coutant 0:146cf26a9bbb 806 {
Jerome Coutant 0:146cf26a9bbb 807
Jerome Coutant 0:146cf26a9bbb 808 HAL_LTDC_SetAlpha(&(hltdc_discovery), Transparency, LayerIndex);
Jerome Coutant 0:146cf26a9bbb 809
Jerome Coutant 0:146cf26a9bbb 810 }
Jerome Coutant 0:146cf26a9bbb 811
Jerome Coutant 0:146cf26a9bbb 812 /**
Jerome Coutant 0:146cf26a9bbb 813 * @brief Sets an LCD layer frame buffer address.
Jerome Coutant 0:146cf26a9bbb 814 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:146cf26a9bbb 815 * @param Address: New LCD frame buffer value
Jerome Coutant 0:146cf26a9bbb 816 */
Jerome Coutant 0:146cf26a9bbb 817 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
Jerome Coutant 0:146cf26a9bbb 818 {
Jerome Coutant 0:146cf26a9bbb 819
Jerome Coutant 0:146cf26a9bbb 820 HAL_LTDC_SetAddress(&(hltdc_discovery), Address, LayerIndex);
Jerome Coutant 0:146cf26a9bbb 821
Jerome Coutant 0:146cf26a9bbb 822 }
Jerome Coutant 0:146cf26a9bbb 823
Jerome Coutant 0:146cf26a9bbb 824 /**
Jerome Coutant 0:146cf26a9bbb 825 * @brief Sets display window.
Jerome Coutant 0:146cf26a9bbb 826 * @param LayerIndex: Layer index
Jerome Coutant 0:146cf26a9bbb 827 * @param Xpos: LCD X position
Jerome Coutant 0:146cf26a9bbb 828 * @param Ypos: LCD Y position
Jerome Coutant 0:146cf26a9bbb 829 * @param Width: LCD window width
Jerome Coutant 0:146cf26a9bbb 830 * @param Height: LCD window height
Jerome Coutant 0:146cf26a9bbb 831 */
Jerome Coutant 0:146cf26a9bbb 832 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 0:146cf26a9bbb 833 {
Jerome Coutant 0:146cf26a9bbb 834 /* Reconfigure the layer size */
Jerome Coutant 0:146cf26a9bbb 835 HAL_LTDC_SetWindowSize(&(hltdc_discovery), Width, Height, LayerIndex);
Jerome Coutant 0:146cf26a9bbb 836
Jerome Coutant 0:146cf26a9bbb 837 /* Reconfigure the layer position */
Jerome Coutant 0:146cf26a9bbb 838 HAL_LTDC_SetWindowPosition(&(hltdc_discovery), Xpos, Ypos, LayerIndex);
Jerome Coutant 0:146cf26a9bbb 839
Jerome Coutant 0:146cf26a9bbb 840 }
Jerome Coutant 0:146cf26a9bbb 841
Jerome Coutant 0:146cf26a9bbb 842 /**
Jerome Coutant 0:146cf26a9bbb 843 * @brief Configures and sets the color keying.
Jerome Coutant 0:146cf26a9bbb 844 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:146cf26a9bbb 845 * @param RGBValue: Color reference
Jerome Coutant 0:146cf26a9bbb 846 */
Jerome Coutant 0:146cf26a9bbb 847 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
Jerome Coutant 0:146cf26a9bbb 848 {
Jerome Coutant 0:146cf26a9bbb 849 /* Configure and Enable the color Keying for LCD Layer */
Jerome Coutant 0:146cf26a9bbb 850 HAL_LTDC_ConfigColorKeying(&(hltdc_discovery), RGBValue, LayerIndex);
Jerome Coutant 0:146cf26a9bbb 851 HAL_LTDC_EnableColorKeying(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:146cf26a9bbb 852 }
Jerome Coutant 0:146cf26a9bbb 853
Jerome Coutant 0:146cf26a9bbb 854 /**
Jerome Coutant 0:146cf26a9bbb 855 * @brief Disables the color keying.
Jerome Coutant 0:146cf26a9bbb 856 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:146cf26a9bbb 857 */
Jerome Coutant 0:146cf26a9bbb 858 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
Jerome Coutant 0:146cf26a9bbb 859 {
Jerome Coutant 0:146cf26a9bbb 860 /* Disable the color Keying for LCD Layer */
Jerome Coutant 0:146cf26a9bbb 861 HAL_LTDC_DisableColorKeying(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:146cf26a9bbb 862 }
Jerome Coutant 0:146cf26a9bbb 863
Jerome Coutant 0:146cf26a9bbb 864 /**
Jerome Coutant 0:146cf26a9bbb 865 * @brief Sets the LCD text color.
Jerome Coutant 0:146cf26a9bbb 866 * @param Color: Text color code ARGB(8-8-8-8)
Jerome Coutant 0:146cf26a9bbb 867 */
Jerome Coutant 0:146cf26a9bbb 868 void BSP_LCD_SetTextColor(uint32_t Color)
Jerome Coutant 0:146cf26a9bbb 869 {
Jerome Coutant 0:146cf26a9bbb 870 DrawProp[ActiveLayer].TextColor = Color;
Jerome Coutant 0:146cf26a9bbb 871 }
Jerome Coutant 0:146cf26a9bbb 872
Jerome Coutant 0:146cf26a9bbb 873 /**
Jerome Coutant 0:146cf26a9bbb 874 * @brief Gets the LCD text color.
Jerome Coutant 0:146cf26a9bbb 875 * @retval Used text color.
Jerome Coutant 0:146cf26a9bbb 876 */
Jerome Coutant 0:146cf26a9bbb 877 uint32_t BSP_LCD_GetTextColor(void)
Jerome Coutant 0:146cf26a9bbb 878 {
Jerome Coutant 0:146cf26a9bbb 879 return DrawProp[ActiveLayer].TextColor;
Jerome Coutant 0:146cf26a9bbb 880 }
Jerome Coutant 0:146cf26a9bbb 881
Jerome Coutant 0:146cf26a9bbb 882 /**
Jerome Coutant 0:146cf26a9bbb 883 * @brief Sets the LCD background color.
Jerome Coutant 0:146cf26a9bbb 884 * @param Color: Layer background color code ARGB(8-8-8-8)
Jerome Coutant 0:146cf26a9bbb 885 */
Jerome Coutant 0:146cf26a9bbb 886 void BSP_LCD_SetBackColor(uint32_t Color)
Jerome Coutant 0:146cf26a9bbb 887 {
Jerome Coutant 0:146cf26a9bbb 888 DrawProp[ActiveLayer].BackColor = Color;
Jerome Coutant 0:146cf26a9bbb 889 }
Jerome Coutant 0:146cf26a9bbb 890
Jerome Coutant 0:146cf26a9bbb 891 /**
Jerome Coutant 0:146cf26a9bbb 892 * @brief Gets the LCD background color.
Jerome Coutant 0:146cf26a9bbb 893 * @retval Used background color
Jerome Coutant 0:146cf26a9bbb 894 */
Jerome Coutant 0:146cf26a9bbb 895 uint32_t BSP_LCD_GetBackColor(void)
Jerome Coutant 0:146cf26a9bbb 896 {
Jerome Coutant 0:146cf26a9bbb 897 return DrawProp[ActiveLayer].BackColor;
Jerome Coutant 0:146cf26a9bbb 898 }
Jerome Coutant 0:146cf26a9bbb 899
Jerome Coutant 0:146cf26a9bbb 900 /**
Jerome Coutant 0:146cf26a9bbb 901 * @brief Sets the LCD text font.
Jerome Coutant 0:146cf26a9bbb 902 * @param fonts: Layer font to be used
Jerome Coutant 0:146cf26a9bbb 903 */
Jerome Coutant 0:146cf26a9bbb 904 void BSP_LCD_SetFont(sFONT *fonts)
Jerome Coutant 0:146cf26a9bbb 905 {
Jerome Coutant 0:146cf26a9bbb 906 DrawProp[ActiveLayer].pFont = fonts;
Jerome Coutant 0:146cf26a9bbb 907 }
Jerome Coutant 0:146cf26a9bbb 908
Jerome Coutant 0:146cf26a9bbb 909 /**
Jerome Coutant 0:146cf26a9bbb 910 * @brief Gets the LCD text font.
Jerome Coutant 0:146cf26a9bbb 911 * @retval Used layer font
Jerome Coutant 0:146cf26a9bbb 912 */
Jerome Coutant 0:146cf26a9bbb 913 sFONT *BSP_LCD_GetFont(void)
Jerome Coutant 0:146cf26a9bbb 914 {
Jerome Coutant 0:146cf26a9bbb 915 return DrawProp[ActiveLayer].pFont;
Jerome Coutant 0:146cf26a9bbb 916 }
Jerome Coutant 0:146cf26a9bbb 917
Jerome Coutant 0:146cf26a9bbb 918 /**
Jerome Coutant 0:146cf26a9bbb 919 * @brief Reads an LCD pixel.
Jerome Coutant 0:146cf26a9bbb 920 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 921 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 922 * @retval RGB pixel color
Jerome Coutant 0:146cf26a9bbb 923 */
Jerome Coutant 0:146cf26a9bbb 924 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
Jerome Coutant 0:146cf26a9bbb 925 {
Jerome Coutant 0:146cf26a9bbb 926 uint32_t ret = 0;
Jerome Coutant 0:146cf26a9bbb 927
Jerome Coutant 0:146cf26a9bbb 928 if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
Jerome Coutant 0:146cf26a9bbb 929 {
Jerome Coutant 0:146cf26a9bbb 930 /* Read data value from SDRAM memory */
Jerome Coutant 0:146cf26a9bbb 931 ret = *(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 0:146cf26a9bbb 932 }
Jerome Coutant 0:146cf26a9bbb 933 else if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
Jerome Coutant 0:146cf26a9bbb 934 {
Jerome Coutant 0:146cf26a9bbb 935 /* Read data value from SDRAM memory */
Jerome Coutant 0:146cf26a9bbb 936 ret = (*(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
Jerome Coutant 0:146cf26a9bbb 937 }
Jerome Coutant 0:146cf26a9bbb 938 else if((hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
Jerome Coutant 0:146cf26a9bbb 939 (hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
Jerome Coutant 0:146cf26a9bbb 940 (hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
Jerome Coutant 0:146cf26a9bbb 941 {
Jerome Coutant 0:146cf26a9bbb 942 /* Read data value from SDRAM memory */
Jerome Coutant 0:146cf26a9bbb 943 ret = *(__IO uint16_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 0:146cf26a9bbb 944 }
Jerome Coutant 0:146cf26a9bbb 945 else
Jerome Coutant 0:146cf26a9bbb 946 {
Jerome Coutant 0:146cf26a9bbb 947 /* Read data value from SDRAM memory */
Jerome Coutant 0:146cf26a9bbb 948 ret = *(__IO uint8_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 0:146cf26a9bbb 949 }
Jerome Coutant 0:146cf26a9bbb 950
Jerome Coutant 0:146cf26a9bbb 951 return ret;
Jerome Coutant 0:146cf26a9bbb 952 }
Jerome Coutant 0:146cf26a9bbb 953
Jerome Coutant 0:146cf26a9bbb 954 /**
Jerome Coutant 0:146cf26a9bbb 955 * @brief Clears the whole currently active layer of LTDC.
Jerome Coutant 0:146cf26a9bbb 956 * @param Color: Color of the background
Jerome Coutant 0:146cf26a9bbb 957 * @retval None
Jerome Coutant 0:146cf26a9bbb 958 */
Jerome Coutant 0:146cf26a9bbb 959 void BSP_LCD_Clear(uint32_t Color)
Jerome Coutant 0:146cf26a9bbb 960 {
Jerome Coutant 0:146cf26a9bbb 961 /* Clear the LCD */
Jerome Coutant 0:146cf26a9bbb 962 LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
Jerome Coutant 0:146cf26a9bbb 963 }
Jerome Coutant 0:146cf26a9bbb 964
Jerome Coutant 0:146cf26a9bbb 965 /**
Jerome Coutant 0:146cf26a9bbb 966 * @brief Clears the selected line in currently active layer.
Jerome Coutant 0:146cf26a9bbb 967 * @param Line: Line to be cleared
Jerome Coutant 0:146cf26a9bbb 968 * @retval None
Jerome Coutant 0:146cf26a9bbb 969 */
Jerome Coutant 0:146cf26a9bbb 970 void BSP_LCD_ClearStringLine(uint32_t Line)
Jerome Coutant 0:146cf26a9bbb 971 {
Jerome Coutant 0:146cf26a9bbb 972 uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
Jerome Coutant 0:146cf26a9bbb 973 DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
Jerome Coutant 0:146cf26a9bbb 974
Jerome Coutant 0:146cf26a9bbb 975 /* Draw rectangle with background color */
Jerome Coutant 0:146cf26a9bbb 976 BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
Jerome Coutant 0:146cf26a9bbb 977
Jerome Coutant 0:146cf26a9bbb 978 DrawProp[ActiveLayer].TextColor = color_backup;
Jerome Coutant 0:146cf26a9bbb 979 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 980 }
Jerome Coutant 0:146cf26a9bbb 981
Jerome Coutant 0:146cf26a9bbb 982 /**
Jerome Coutant 0:146cf26a9bbb 983 * @brief Displays one character in currently active layer.
Jerome Coutant 0:146cf26a9bbb 984 * @param Xpos: Start column address
Jerome Coutant 0:146cf26a9bbb 985 * @param Ypos: Line where to display the character shape.
Jerome Coutant 0:146cf26a9bbb 986 * @param Ascii: Character ascii code
Jerome Coutant 0:146cf26a9bbb 987 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
Jerome Coutant 0:146cf26a9bbb 988 * @retval None
Jerome Coutant 0:146cf26a9bbb 989 */
Jerome Coutant 0:146cf26a9bbb 990 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
Jerome Coutant 0:146cf26a9bbb 991 {
Jerome Coutant 0:146cf26a9bbb 992 DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
Jerome Coutant 0:146cf26a9bbb 993 DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
Jerome Coutant 0:146cf26a9bbb 994 }
Jerome Coutant 0:146cf26a9bbb 995
Jerome Coutant 0:146cf26a9bbb 996 /**
Jerome Coutant 0:146cf26a9bbb 997 * @brief Displays characters in currently active layer.
Jerome Coutant 0:146cf26a9bbb 998 * @param Xpos: X position (in pixel)
Jerome Coutant 0:146cf26a9bbb 999 * @param Ypos: Y position (in pixel)
Jerome Coutant 0:146cf26a9bbb 1000 * @param Text: Pointer to string to display on LCD
Jerome Coutant 0:146cf26a9bbb 1001 * @param Mode: Display mode
Jerome Coutant 0:146cf26a9bbb 1002 * This parameter can be one of the following values:
Jerome Coutant 0:146cf26a9bbb 1003 * @arg CENTER_MODE
Jerome Coutant 0:146cf26a9bbb 1004 * @arg RIGHT_MODE
Jerome Coutant 0:146cf26a9bbb 1005 * @arg LEFT_MODE
Jerome Coutant 0:146cf26a9bbb 1006 * @retval None
Jerome Coutant 0:146cf26a9bbb 1007 */
Jerome Coutant 0:146cf26a9bbb 1008 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
Jerome Coutant 0:146cf26a9bbb 1009 {
Jerome Coutant 0:146cf26a9bbb 1010 uint16_t refcolumn = 1, i = 0;
Jerome Coutant 0:146cf26a9bbb 1011 uint32_t size = 0, xsize = 0;
Jerome Coutant 0:146cf26a9bbb 1012 uint8_t *ptr = Text;
Jerome Coutant 0:146cf26a9bbb 1013
Jerome Coutant 0:146cf26a9bbb 1014 /* Get the text size */
Jerome Coutant 0:146cf26a9bbb 1015 while (*ptr++) size ++ ;
Jerome Coutant 0:146cf26a9bbb 1016
Jerome Coutant 0:146cf26a9bbb 1017 /* Characters number per line */
Jerome Coutant 0:146cf26a9bbb 1018 xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
Jerome Coutant 0:146cf26a9bbb 1019
Jerome Coutant 0:146cf26a9bbb 1020 switch (Mode)
Jerome Coutant 0:146cf26a9bbb 1021 {
Jerome Coutant 0:146cf26a9bbb 1022 case CENTER_MODE:
Jerome Coutant 0:146cf26a9bbb 1023 {
Jerome Coutant 0:146cf26a9bbb 1024 refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
Jerome Coutant 0:146cf26a9bbb 1025 break;
Jerome Coutant 0:146cf26a9bbb 1026 }
Jerome Coutant 0:146cf26a9bbb 1027 case LEFT_MODE:
Jerome Coutant 0:146cf26a9bbb 1028 {
Jerome Coutant 0:146cf26a9bbb 1029 refcolumn = Xpos;
Jerome Coutant 0:146cf26a9bbb 1030 break;
Jerome Coutant 0:146cf26a9bbb 1031 }
Jerome Coutant 0:146cf26a9bbb 1032 case RIGHT_MODE:
Jerome Coutant 0:146cf26a9bbb 1033 {
Jerome Coutant 0:146cf26a9bbb 1034 refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
Jerome Coutant 0:146cf26a9bbb 1035 break;
Jerome Coutant 0:146cf26a9bbb 1036 }
Jerome Coutant 0:146cf26a9bbb 1037 default:
Jerome Coutant 0:146cf26a9bbb 1038 {
Jerome Coutant 0:146cf26a9bbb 1039 refcolumn = Xpos;
Jerome Coutant 0:146cf26a9bbb 1040 break;
Jerome Coutant 0:146cf26a9bbb 1041 }
Jerome Coutant 0:146cf26a9bbb 1042 }
Jerome Coutant 0:146cf26a9bbb 1043
Jerome Coutant 0:146cf26a9bbb 1044 /* Check that the Start column is located in the screen */
Jerome Coutant 0:146cf26a9bbb 1045 if ((refcolumn < 1) || (refcolumn >= 0x8000))
Jerome Coutant 0:146cf26a9bbb 1046 {
Jerome Coutant 0:146cf26a9bbb 1047 refcolumn = 1;
Jerome Coutant 0:146cf26a9bbb 1048 }
Jerome Coutant 0:146cf26a9bbb 1049
Jerome Coutant 0:146cf26a9bbb 1050 /* Send the string character by character on LCD */
Jerome Coutant 0:146cf26a9bbb 1051 while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
Jerome Coutant 0:146cf26a9bbb 1052 {
Jerome Coutant 0:146cf26a9bbb 1053 /* Display one character on LCD */
Jerome Coutant 0:146cf26a9bbb 1054 BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
Jerome Coutant 0:146cf26a9bbb 1055 /* Decrement the column position by 16 */
Jerome Coutant 0:146cf26a9bbb 1056 refcolumn += DrawProp[ActiveLayer].pFont->Width;
Jerome Coutant 0:146cf26a9bbb 1057
Jerome Coutant 0:146cf26a9bbb 1058 /* Point on the next character */
Jerome Coutant 0:146cf26a9bbb 1059 Text++;
Jerome Coutant 0:146cf26a9bbb 1060 i++;
Jerome Coutant 0:146cf26a9bbb 1061 }
Jerome Coutant 0:146cf26a9bbb 1062
Jerome Coutant 0:146cf26a9bbb 1063 }
Jerome Coutant 0:146cf26a9bbb 1064
Jerome Coutant 0:146cf26a9bbb 1065 /**
Jerome Coutant 0:146cf26a9bbb 1066 * @brief Displays a maximum of 60 characters on the LCD.
Jerome Coutant 0:146cf26a9bbb 1067 * @param Line: Line where to display the character shape
Jerome Coutant 0:146cf26a9bbb 1068 * @param ptr: Pointer to string to display on LCD
Jerome Coutant 0:146cf26a9bbb 1069 * @retval None
Jerome Coutant 0:146cf26a9bbb 1070 */
Jerome Coutant 0:146cf26a9bbb 1071 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
Jerome Coutant 0:146cf26a9bbb 1072 {
Jerome Coutant 0:146cf26a9bbb 1073 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
Jerome Coutant 0:146cf26a9bbb 1074 }
Jerome Coutant 0:146cf26a9bbb 1075
Jerome Coutant 0:146cf26a9bbb 1076 /**
Jerome Coutant 0:146cf26a9bbb 1077 * @brief Draws an horizontal line in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1078 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1079 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1080 * @param Length: Line length
Jerome Coutant 0:146cf26a9bbb 1081 * @retval None
Jerome Coutant 0:146cf26a9bbb 1082 */
Jerome Coutant 0:146cf26a9bbb 1083 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Jerome Coutant 0:146cf26a9bbb 1084 {
Jerome Coutant 0:146cf26a9bbb 1085 uint32_t Xaddress = 0;
Jerome Coutant 0:146cf26a9bbb 1086
Jerome Coutant 0:146cf26a9bbb 1087 /* Get the line address */
Jerome Coutant 0:146cf26a9bbb 1088 Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 0:146cf26a9bbb 1089
Jerome Coutant 0:146cf26a9bbb 1090 /* Write line */
Jerome Coutant 0:146cf26a9bbb 1091 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1092 }
Jerome Coutant 0:146cf26a9bbb 1093
Jerome Coutant 0:146cf26a9bbb 1094 /**
Jerome Coutant 0:146cf26a9bbb 1095 * @brief Draws a vertical line in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1096 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1097 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1098 * @param Length: Line length
Jerome Coutant 0:146cf26a9bbb 1099 * @retval None
Jerome Coutant 0:146cf26a9bbb 1100 */
Jerome Coutant 0:146cf26a9bbb 1101 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Jerome Coutant 0:146cf26a9bbb 1102 {
Jerome Coutant 0:146cf26a9bbb 1103 uint32_t Xaddress = 0;
Jerome Coutant 0:146cf26a9bbb 1104
Jerome Coutant 0:146cf26a9bbb 1105 /* Get the line address */
Jerome Coutant 0:146cf26a9bbb 1106 Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 0:146cf26a9bbb 1107
Jerome Coutant 0:146cf26a9bbb 1108 /* Write line */
Jerome Coutant 0:146cf26a9bbb 1109 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1110 }
Jerome Coutant 0:146cf26a9bbb 1111
Jerome Coutant 0:146cf26a9bbb 1112 /**
Jerome Coutant 0:146cf26a9bbb 1113 * @brief Draws an uni-line (between two points) in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1114 * @param x1: Point 1 X position
Jerome Coutant 0:146cf26a9bbb 1115 * @param y1: Point 1 Y position
Jerome Coutant 0:146cf26a9bbb 1116 * @param x2: Point 2 X position
Jerome Coutant 0:146cf26a9bbb 1117 * @param y2: Point 2 Y position
Jerome Coutant 0:146cf26a9bbb 1118 * @retval None
Jerome Coutant 0:146cf26a9bbb 1119 */
Jerome Coutant 0:146cf26a9bbb 1120 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Jerome Coutant 0:146cf26a9bbb 1121 {
Jerome Coutant 0:146cf26a9bbb 1122 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
Jerome Coutant 0:146cf26a9bbb 1123 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
Jerome Coutant 0:146cf26a9bbb 1124 curpixel = 0;
Jerome Coutant 0:146cf26a9bbb 1125
Jerome Coutant 0:146cf26a9bbb 1126 deltax = ABS(x2 - x1); /* The difference between the x's */
Jerome Coutant 0:146cf26a9bbb 1127 deltay = ABS(y2 - y1); /* The difference between the y's */
Jerome Coutant 0:146cf26a9bbb 1128 x = x1; /* Start x off at the first pixel */
Jerome Coutant 0:146cf26a9bbb 1129 y = y1; /* Start y off at the first pixel */
Jerome Coutant 0:146cf26a9bbb 1130
Jerome Coutant 0:146cf26a9bbb 1131 if (x2 >= x1) /* The x-values are increasing */
Jerome Coutant 0:146cf26a9bbb 1132 {
Jerome Coutant 0:146cf26a9bbb 1133 xinc1 = 1;
Jerome Coutant 0:146cf26a9bbb 1134 xinc2 = 1;
Jerome Coutant 0:146cf26a9bbb 1135 }
Jerome Coutant 0:146cf26a9bbb 1136 else /* The x-values are decreasing */
Jerome Coutant 0:146cf26a9bbb 1137 {
Jerome Coutant 0:146cf26a9bbb 1138 xinc1 = -1;
Jerome Coutant 0:146cf26a9bbb 1139 xinc2 = -1;
Jerome Coutant 0:146cf26a9bbb 1140 }
Jerome Coutant 0:146cf26a9bbb 1141
Jerome Coutant 0:146cf26a9bbb 1142 if (y2 >= y1) /* The y-values are increasing */
Jerome Coutant 0:146cf26a9bbb 1143 {
Jerome Coutant 0:146cf26a9bbb 1144 yinc1 = 1;
Jerome Coutant 0:146cf26a9bbb 1145 yinc2 = 1;
Jerome Coutant 0:146cf26a9bbb 1146 }
Jerome Coutant 0:146cf26a9bbb 1147 else /* The y-values are decreasing */
Jerome Coutant 0:146cf26a9bbb 1148 {
Jerome Coutant 0:146cf26a9bbb 1149 yinc1 = -1;
Jerome Coutant 0:146cf26a9bbb 1150 yinc2 = -1;
Jerome Coutant 0:146cf26a9bbb 1151 }
Jerome Coutant 0:146cf26a9bbb 1152
Jerome Coutant 0:146cf26a9bbb 1153 if (deltax >= deltay) /* There is at least one x-value for every y-value */
Jerome Coutant 0:146cf26a9bbb 1154 {
Jerome Coutant 0:146cf26a9bbb 1155 xinc1 = 0; /* Don't change the x when numerator >= denominator */
Jerome Coutant 0:146cf26a9bbb 1156 yinc2 = 0; /* Don't change the y for every iteration */
Jerome Coutant 0:146cf26a9bbb 1157 den = deltax;
Jerome Coutant 0:146cf26a9bbb 1158 num = deltax / 2;
Jerome Coutant 0:146cf26a9bbb 1159 numadd = deltay;
Jerome Coutant 0:146cf26a9bbb 1160 numpixels = deltax; /* There are more x-values than y-values */
Jerome Coutant 0:146cf26a9bbb 1161 }
Jerome Coutant 0:146cf26a9bbb 1162 else /* There is at least one y-value for every x-value */
Jerome Coutant 0:146cf26a9bbb 1163 {
Jerome Coutant 0:146cf26a9bbb 1164 xinc2 = 0; /* Don't change the x for every iteration */
Jerome Coutant 0:146cf26a9bbb 1165 yinc1 = 0; /* Don't change the y when numerator >= denominator */
Jerome Coutant 0:146cf26a9bbb 1166 den = deltay;
Jerome Coutant 0:146cf26a9bbb 1167 num = deltay / 2;
Jerome Coutant 0:146cf26a9bbb 1168 numadd = deltax;
Jerome Coutant 0:146cf26a9bbb 1169 numpixels = deltay; /* There are more y-values than x-values */
Jerome Coutant 0:146cf26a9bbb 1170 }
Jerome Coutant 0:146cf26a9bbb 1171
Jerome Coutant 0:146cf26a9bbb 1172 for (curpixel = 0; curpixel <= numpixels; curpixel++)
Jerome Coutant 0:146cf26a9bbb 1173 {
Jerome Coutant 0:146cf26a9bbb 1174 BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */
Jerome Coutant 0:146cf26a9bbb 1175 num += numadd; /* Increase the numerator by the top of the fraction */
Jerome Coutant 0:146cf26a9bbb 1176 if (num >= den) /* Check if numerator >= denominator */
Jerome Coutant 0:146cf26a9bbb 1177 {
Jerome Coutant 0:146cf26a9bbb 1178 num -= den; /* Calculate the new numerator value */
Jerome Coutant 0:146cf26a9bbb 1179 x += xinc1; /* Change the x as appropriate */
Jerome Coutant 0:146cf26a9bbb 1180 y += yinc1; /* Change the y as appropriate */
Jerome Coutant 0:146cf26a9bbb 1181 }
Jerome Coutant 0:146cf26a9bbb 1182 x += xinc2; /* Change the x as appropriate */
Jerome Coutant 0:146cf26a9bbb 1183 y += yinc2; /* Change the y as appropriate */
Jerome Coutant 0:146cf26a9bbb 1184 }
Jerome Coutant 0:146cf26a9bbb 1185 }
Jerome Coutant 0:146cf26a9bbb 1186
Jerome Coutant 0:146cf26a9bbb 1187 /**
Jerome Coutant 0:146cf26a9bbb 1188 * @brief Draws a rectangle in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1189 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1190 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1191 * @param Width: Rectangle width
Jerome Coutant 0:146cf26a9bbb 1192 * @param Height: Rectangle height
Jerome Coutant 0:146cf26a9bbb 1193 * @retval None
Jerome Coutant 0:146cf26a9bbb 1194 */
Jerome Coutant 0:146cf26a9bbb 1195 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 0:146cf26a9bbb 1196 {
Jerome Coutant 0:146cf26a9bbb 1197 /* Draw horizontal lines */
Jerome Coutant 0:146cf26a9bbb 1198 BSP_LCD_DrawHLine(Xpos, Ypos, Width);
Jerome Coutant 0:146cf26a9bbb 1199 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
Jerome Coutant 0:146cf26a9bbb 1200
Jerome Coutant 0:146cf26a9bbb 1201 /* Draw vertical lines */
Jerome Coutant 0:146cf26a9bbb 1202 BSP_LCD_DrawVLine(Xpos, Ypos, Height);
Jerome Coutant 0:146cf26a9bbb 1203 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
Jerome Coutant 0:146cf26a9bbb 1204 }
Jerome Coutant 0:146cf26a9bbb 1205
Jerome Coutant 0:146cf26a9bbb 1206 /**
Jerome Coutant 0:146cf26a9bbb 1207 * @brief Draws a circle in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1208 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1209 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1210 * @param Radius: Circle radius
Jerome Coutant 0:146cf26a9bbb 1211 * @retval None
Jerome Coutant 0:146cf26a9bbb 1212 */
Jerome Coutant 0:146cf26a9bbb 1213 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Jerome Coutant 0:146cf26a9bbb 1214 {
Jerome Coutant 0:146cf26a9bbb 1215 int32_t D; /* Decision Variable */
Jerome Coutant 0:146cf26a9bbb 1216 uint32_t CurX; /* Current X Value */
Jerome Coutant 0:146cf26a9bbb 1217 uint32_t CurY; /* Current Y Value */
Jerome Coutant 0:146cf26a9bbb 1218
Jerome Coutant 0:146cf26a9bbb 1219 D = 3 - (Radius << 1);
Jerome Coutant 0:146cf26a9bbb 1220 CurX = 0;
Jerome Coutant 0:146cf26a9bbb 1221 CurY = Radius;
Jerome Coutant 0:146cf26a9bbb 1222
Jerome Coutant 0:146cf26a9bbb 1223 while (CurX <= CurY)
Jerome Coutant 0:146cf26a9bbb 1224 {
Jerome Coutant 0:146cf26a9bbb 1225 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1226
Jerome Coutant 0:146cf26a9bbb 1227 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1228
Jerome Coutant 0:146cf26a9bbb 1229 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1230
Jerome Coutant 0:146cf26a9bbb 1231 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1232
Jerome Coutant 0:146cf26a9bbb 1233 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1234
Jerome Coutant 0:146cf26a9bbb 1235 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1236
Jerome Coutant 0:146cf26a9bbb 1237 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1238
Jerome Coutant 0:146cf26a9bbb 1239 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1240
Jerome Coutant 0:146cf26a9bbb 1241 if (D < 0)
Jerome Coutant 0:146cf26a9bbb 1242 {
Jerome Coutant 0:146cf26a9bbb 1243 D += (CurX << 2) + 6;
Jerome Coutant 0:146cf26a9bbb 1244 }
Jerome Coutant 0:146cf26a9bbb 1245 else
Jerome Coutant 0:146cf26a9bbb 1246 {
Jerome Coutant 0:146cf26a9bbb 1247 D += ((CurX - CurY) << 2) + 10;
Jerome Coutant 0:146cf26a9bbb 1248 CurY--;
Jerome Coutant 0:146cf26a9bbb 1249 }
Jerome Coutant 0:146cf26a9bbb 1250 CurX++;
Jerome Coutant 0:146cf26a9bbb 1251 }
Jerome Coutant 0:146cf26a9bbb 1252 }
Jerome Coutant 0:146cf26a9bbb 1253
Jerome Coutant 0:146cf26a9bbb 1254 /**
Jerome Coutant 0:146cf26a9bbb 1255 * @brief Draws an poly-line (between many points) in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1256 * @param Points: Pointer to the points array
Jerome Coutant 0:146cf26a9bbb 1257 * @param PointCount: Number of points
Jerome Coutant 0:146cf26a9bbb 1258 * @retval None
Jerome Coutant 0:146cf26a9bbb 1259 */
Jerome Coutant 0:146cf26a9bbb 1260 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
Jerome Coutant 0:146cf26a9bbb 1261 {
Jerome Coutant 0:146cf26a9bbb 1262 int16_t X = 0, Y = 0;
Jerome Coutant 0:146cf26a9bbb 1263
Jerome Coutant 0:146cf26a9bbb 1264 if(PointCount < 2)
Jerome Coutant 0:146cf26a9bbb 1265 {
Jerome Coutant 0:146cf26a9bbb 1266 return;
Jerome Coutant 0:146cf26a9bbb 1267 }
Jerome Coutant 0:146cf26a9bbb 1268
Jerome Coutant 0:146cf26a9bbb 1269 BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
Jerome Coutant 0:146cf26a9bbb 1270
Jerome Coutant 0:146cf26a9bbb 1271 while(--PointCount)
Jerome Coutant 0:146cf26a9bbb 1272 {
Jerome Coutant 0:146cf26a9bbb 1273 X = Points->X;
Jerome Coutant 0:146cf26a9bbb 1274 Y = Points->Y;
Jerome Coutant 0:146cf26a9bbb 1275 Points++;
Jerome Coutant 0:146cf26a9bbb 1276 BSP_LCD_DrawLine(X, Y, Points->X, Points->Y);
Jerome Coutant 0:146cf26a9bbb 1277 }
Jerome Coutant 0:146cf26a9bbb 1278 }
Jerome Coutant 0:146cf26a9bbb 1279
Jerome Coutant 0:146cf26a9bbb 1280 /**
Jerome Coutant 0:146cf26a9bbb 1281 * @brief Draws an ellipse on LCD in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1282 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1283 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1284 * @param XRadius: Ellipse X radius
Jerome Coutant 0:146cf26a9bbb 1285 * @param YRadius: Ellipse Y radius
Jerome Coutant 0:146cf26a9bbb 1286 * @retval None
Jerome Coutant 0:146cf26a9bbb 1287 */
Jerome Coutant 0:146cf26a9bbb 1288 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Jerome Coutant 0:146cf26a9bbb 1289 {
Jerome Coutant 0:146cf26a9bbb 1290 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
Jerome Coutant 0:146cf26a9bbb 1291 float K = 0, rad1 = 0, rad2 = 0;
Jerome Coutant 0:146cf26a9bbb 1292
Jerome Coutant 0:146cf26a9bbb 1293 rad1 = XRadius;
Jerome Coutant 0:146cf26a9bbb 1294 rad2 = YRadius;
Jerome Coutant 0:146cf26a9bbb 1295
Jerome Coutant 0:146cf26a9bbb 1296 K = (float)(rad2/rad1);
Jerome Coutant 0:146cf26a9bbb 1297
Jerome Coutant 0:146cf26a9bbb 1298 do {
Jerome Coutant 0:146cf26a9bbb 1299 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1300 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1301 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1302 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1303
Jerome Coutant 0:146cf26a9bbb 1304 e2 = err;
Jerome Coutant 0:146cf26a9bbb 1305 if (e2 <= x) {
Jerome Coutant 0:146cf26a9bbb 1306 err += ++x*2+1;
Jerome Coutant 0:146cf26a9bbb 1307 if (-y == x && e2 <= y) e2 = 0;
Jerome Coutant 0:146cf26a9bbb 1308 }
Jerome Coutant 0:146cf26a9bbb 1309 if (e2 > y) err += ++y*2+1;
Jerome Coutant 0:146cf26a9bbb 1310 }
Jerome Coutant 0:146cf26a9bbb 1311 while (y <= 0);
Jerome Coutant 0:146cf26a9bbb 1312 }
Jerome Coutant 0:146cf26a9bbb 1313
Jerome Coutant 0:146cf26a9bbb 1314 /**
Jerome Coutant 0:146cf26a9bbb 1315 * @brief Draws a bitmap picture loaded in the internal Flash (32 bpp) in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1316 * @param Xpos: Bmp X position in the LCD
Jerome Coutant 0:146cf26a9bbb 1317 * @param Ypos: Bmp Y position in the LCD
Jerome Coutant 0:146cf26a9bbb 1318 * @param pbmp: Pointer to Bmp picture address in the internal Flash
Jerome Coutant 0:146cf26a9bbb 1319 * @retval None
Jerome Coutant 0:146cf26a9bbb 1320 */
Jerome Coutant 0:146cf26a9bbb 1321 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
Jerome Coutant 0:146cf26a9bbb 1322 {
Jerome Coutant 0:146cf26a9bbb 1323 uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
Jerome Coutant 0:146cf26a9bbb 1324 uint32_t Address;
Jerome Coutant 0:146cf26a9bbb 1325 uint32_t InputColorMode = 0;
Jerome Coutant 0:146cf26a9bbb 1326
Jerome Coutant 0:146cf26a9bbb 1327 /* Get bitmap data address offset */
Jerome Coutant 0:146cf26a9bbb 1328 index = *(__IO uint16_t *) (pbmp + 10);
Jerome Coutant 0:146cf26a9bbb 1329 index |= (*(__IO uint16_t *) (pbmp + 12)) << 16;
Jerome Coutant 0:146cf26a9bbb 1330
Jerome Coutant 0:146cf26a9bbb 1331 /* Read bitmap width */
Jerome Coutant 0:146cf26a9bbb 1332 width = *(uint16_t *) (pbmp + 18);
Jerome Coutant 0:146cf26a9bbb 1333 width |= (*(uint16_t *) (pbmp + 20)) << 16;
Jerome Coutant 0:146cf26a9bbb 1334
Jerome Coutant 0:146cf26a9bbb 1335 /* Read bitmap height */
Jerome Coutant 0:146cf26a9bbb 1336 height = *(uint16_t *) (pbmp + 22);
Jerome Coutant 0:146cf26a9bbb 1337 height |= (*(uint16_t *) (pbmp + 24)) << 16;
Jerome Coutant 0:146cf26a9bbb 1338
Jerome Coutant 0:146cf26a9bbb 1339 /* Read bit/pixel */
Jerome Coutant 0:146cf26a9bbb 1340 bit_pixel = *(uint16_t *) (pbmp + 28);
Jerome Coutant 0:146cf26a9bbb 1341
Jerome Coutant 0:146cf26a9bbb 1342 /* Set the address */
Jerome Coutant 0:146cf26a9bbb 1343 Address = hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
Jerome Coutant 0:146cf26a9bbb 1344
Jerome Coutant 0:146cf26a9bbb 1345 /* Get the layer pixel format */
Jerome Coutant 0:146cf26a9bbb 1346 if ((bit_pixel/8) == 4)
Jerome Coutant 0:146cf26a9bbb 1347 {
Jerome Coutant 0:146cf26a9bbb 1348 InputColorMode = DMA2D_INPUT_ARGB8888;
Jerome Coutant 0:146cf26a9bbb 1349 }
Jerome Coutant 0:146cf26a9bbb 1350 else if ((bit_pixel/8) == 2)
Jerome Coutant 0:146cf26a9bbb 1351 {
Jerome Coutant 0:146cf26a9bbb 1352 InputColorMode = DMA2D_INPUT_RGB565;
Jerome Coutant 0:146cf26a9bbb 1353 }
Jerome Coutant 0:146cf26a9bbb 1354 else
Jerome Coutant 0:146cf26a9bbb 1355 {
Jerome Coutant 0:146cf26a9bbb 1356 InputColorMode = DMA2D_INPUT_RGB888;
Jerome Coutant 0:146cf26a9bbb 1357 }
Jerome Coutant 0:146cf26a9bbb 1358
Jerome Coutant 0:146cf26a9bbb 1359 /* Bypass the bitmap header */
Jerome Coutant 0:146cf26a9bbb 1360 pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
Jerome Coutant 0:146cf26a9bbb 1361
Jerome Coutant 0:146cf26a9bbb 1362 /* Convert picture to ARGB8888 pixel format */
Jerome Coutant 0:146cf26a9bbb 1363 for(index=0; index < height; index++)
Jerome Coutant 0:146cf26a9bbb 1364 {
Jerome Coutant 0:146cf26a9bbb 1365 /* Pixel format conversion */
Jerome Coutant 0:146cf26a9bbb 1366 LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode);
Jerome Coutant 0:146cf26a9bbb 1367
Jerome Coutant 0:146cf26a9bbb 1368 /* Increment the source and destination buffers */
Jerome Coutant 0:146cf26a9bbb 1369 Address+= (BSP_LCD_GetXSize()*4);
Jerome Coutant 0:146cf26a9bbb 1370 pbmp -= width*(bit_pixel/8);
Jerome Coutant 0:146cf26a9bbb 1371 }
Jerome Coutant 0:146cf26a9bbb 1372 }
Jerome Coutant 0:146cf26a9bbb 1373
Jerome Coutant 0:146cf26a9bbb 1374 /**
Jerome Coutant 0:146cf26a9bbb 1375 * @brief Draws a full rectangle in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1376 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1377 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1378 * @param Width: Rectangle width
Jerome Coutant 0:146cf26a9bbb 1379 * @param Height: Rectangle height
Jerome Coutant 0:146cf26a9bbb 1380 * @retval None
Jerome Coutant 0:146cf26a9bbb 1381 */
Jerome Coutant 0:146cf26a9bbb 1382 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 0:146cf26a9bbb 1383 {
Jerome Coutant 0:146cf26a9bbb 1384 uint32_t Xaddress = 0;
Jerome Coutant 0:146cf26a9bbb 1385
Jerome Coutant 0:146cf26a9bbb 1386 /* Set the text color */
Jerome Coutant 0:146cf26a9bbb 1387 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1388
Jerome Coutant 0:146cf26a9bbb 1389 /* Get the rectangle start address */
Jerome Coutant 0:146cf26a9bbb 1390 Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 0:146cf26a9bbb 1391
Jerome Coutant 0:146cf26a9bbb 1392 /* Fill the rectangle */
Jerome Coutant 0:146cf26a9bbb 1393 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1394 }
Jerome Coutant 0:146cf26a9bbb 1395
Jerome Coutant 0:146cf26a9bbb 1396 /**
Jerome Coutant 0:146cf26a9bbb 1397 * @brief Draws a full circle in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1398 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1399 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1400 * @param Radius: Circle radius
Jerome Coutant 0:146cf26a9bbb 1401 * @retval None
Jerome Coutant 0:146cf26a9bbb 1402 */
Jerome Coutant 0:146cf26a9bbb 1403 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Jerome Coutant 0:146cf26a9bbb 1404 {
Jerome Coutant 0:146cf26a9bbb 1405 int32_t D; /* Decision Variable */
Jerome Coutant 0:146cf26a9bbb 1406 uint32_t CurX; /* Current X Value */
Jerome Coutant 0:146cf26a9bbb 1407 uint32_t CurY; /* Current Y Value */
Jerome Coutant 0:146cf26a9bbb 1408
Jerome Coutant 0:146cf26a9bbb 1409 D = 3 - (Radius << 1);
Jerome Coutant 0:146cf26a9bbb 1410
Jerome Coutant 0:146cf26a9bbb 1411 CurX = 0;
Jerome Coutant 0:146cf26a9bbb 1412 CurY = Radius;
Jerome Coutant 0:146cf26a9bbb 1413
Jerome Coutant 0:146cf26a9bbb 1414 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1415
Jerome Coutant 0:146cf26a9bbb 1416 while (CurX <= CurY)
Jerome Coutant 0:146cf26a9bbb 1417 {
Jerome Coutant 0:146cf26a9bbb 1418 if(CurY > 0)
Jerome Coutant 0:146cf26a9bbb 1419 {
Jerome Coutant 0:146cf26a9bbb 1420 BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
Jerome Coutant 0:146cf26a9bbb 1421 BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
Jerome Coutant 0:146cf26a9bbb 1422 }
Jerome Coutant 0:146cf26a9bbb 1423
Jerome Coutant 0:146cf26a9bbb 1424 if(CurX > 0)
Jerome Coutant 0:146cf26a9bbb 1425 {
Jerome Coutant 0:146cf26a9bbb 1426 BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
Jerome Coutant 0:146cf26a9bbb 1427 BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
Jerome Coutant 0:146cf26a9bbb 1428 }
Jerome Coutant 0:146cf26a9bbb 1429 if (D < 0)
Jerome Coutant 0:146cf26a9bbb 1430 {
Jerome Coutant 0:146cf26a9bbb 1431 D += (CurX << 2) + 6;
Jerome Coutant 0:146cf26a9bbb 1432 }
Jerome Coutant 0:146cf26a9bbb 1433 else
Jerome Coutant 0:146cf26a9bbb 1434 {
Jerome Coutant 0:146cf26a9bbb 1435 D += ((CurX - CurY) << 2) + 10;
Jerome Coutant 0:146cf26a9bbb 1436 CurY--;
Jerome Coutant 0:146cf26a9bbb 1437 }
Jerome Coutant 0:146cf26a9bbb 1438 CurX++;
Jerome Coutant 0:146cf26a9bbb 1439 }
Jerome Coutant 0:146cf26a9bbb 1440
Jerome Coutant 0:146cf26a9bbb 1441 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1442 BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
Jerome Coutant 0:146cf26a9bbb 1443 }
Jerome Coutant 0:146cf26a9bbb 1444
Jerome Coutant 0:146cf26a9bbb 1445 /**
Jerome Coutant 0:146cf26a9bbb 1446 * @brief Draws a full poly-line (between many points) in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1447 * @param Points: Pointer to the points array
Jerome Coutant 0:146cf26a9bbb 1448 * @param PointCount: Number of points
Jerome Coutant 0:146cf26a9bbb 1449 * @retval None
Jerome Coutant 0:146cf26a9bbb 1450 */
Jerome Coutant 0:146cf26a9bbb 1451 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
Jerome Coutant 0:146cf26a9bbb 1452 {
Jerome Coutant 0:146cf26a9bbb 1453 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 0:146cf26a9bbb 1454 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
Jerome Coutant 0:146cf26a9bbb 1455
Jerome Coutant 0:146cf26a9bbb 1456 IMAGE_LEFT = IMAGE_RIGHT = Points->X;
Jerome Coutant 0:146cf26a9bbb 1457 IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
Jerome Coutant 0:146cf26a9bbb 1458
Jerome Coutant 0:146cf26a9bbb 1459 for(counter = 1; counter < PointCount; counter++)
Jerome Coutant 0:146cf26a9bbb 1460 {
Jerome Coutant 0:146cf26a9bbb 1461 pixelX = POLY_X(counter);
Jerome Coutant 0:146cf26a9bbb 1462 if(pixelX < IMAGE_LEFT)
Jerome Coutant 0:146cf26a9bbb 1463 {
Jerome Coutant 0:146cf26a9bbb 1464 IMAGE_LEFT = pixelX;
Jerome Coutant 0:146cf26a9bbb 1465 }
Jerome Coutant 0:146cf26a9bbb 1466 if(pixelX > IMAGE_RIGHT)
Jerome Coutant 0:146cf26a9bbb 1467 {
Jerome Coutant 0:146cf26a9bbb 1468 IMAGE_RIGHT = pixelX;
Jerome Coutant 0:146cf26a9bbb 1469 }
Jerome Coutant 0:146cf26a9bbb 1470
Jerome Coutant 0:146cf26a9bbb 1471 pixelY = POLY_Y(counter);
Jerome Coutant 0:146cf26a9bbb 1472 if(pixelY < IMAGE_TOP)
Jerome Coutant 0:146cf26a9bbb 1473 {
Jerome Coutant 0:146cf26a9bbb 1474 IMAGE_TOP = pixelY;
Jerome Coutant 0:146cf26a9bbb 1475 }
Jerome Coutant 0:146cf26a9bbb 1476 if(pixelY > IMAGE_BOTTOM)
Jerome Coutant 0:146cf26a9bbb 1477 {
Jerome Coutant 0:146cf26a9bbb 1478 IMAGE_BOTTOM = pixelY;
Jerome Coutant 0:146cf26a9bbb 1479 }
Jerome Coutant 0:146cf26a9bbb 1480 }
Jerome Coutant 0:146cf26a9bbb 1481
Jerome Coutant 0:146cf26a9bbb 1482 if(PointCount < 2)
Jerome Coutant 0:146cf26a9bbb 1483 {
Jerome Coutant 0:146cf26a9bbb 1484 return;
Jerome Coutant 0:146cf26a9bbb 1485 }
Jerome Coutant 0:146cf26a9bbb 1486
Jerome Coutant 0:146cf26a9bbb 1487 X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
Jerome Coutant 0:146cf26a9bbb 1488 Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
Jerome Coutant 0:146cf26a9bbb 1489
Jerome Coutant 0:146cf26a9bbb 1490 X_first = Points->X;
Jerome Coutant 0:146cf26a9bbb 1491 Y_first = Points->Y;
Jerome Coutant 0:146cf26a9bbb 1492
Jerome Coutant 0:146cf26a9bbb 1493 while(--PointCount)
Jerome Coutant 0:146cf26a9bbb 1494 {
Jerome Coutant 0:146cf26a9bbb 1495 X = Points->X;
Jerome Coutant 0:146cf26a9bbb 1496 Y = Points->Y;
Jerome Coutant 0:146cf26a9bbb 1497 Points++;
Jerome Coutant 0:146cf26a9bbb 1498 X2 = Points->X;
Jerome Coutant 0:146cf26a9bbb 1499 Y2 = Points->Y;
Jerome Coutant 0:146cf26a9bbb 1500
Jerome Coutant 0:146cf26a9bbb 1501 FillTriangle(X, X2, X_center, Y, Y2, Y_center);
Jerome Coutant 0:146cf26a9bbb 1502 FillTriangle(X, X_center, X2, Y, Y_center, Y2);
Jerome Coutant 0:146cf26a9bbb 1503 FillTriangle(X_center, X2, X, Y_center, Y2, Y);
Jerome Coutant 0:146cf26a9bbb 1504 }
Jerome Coutant 0:146cf26a9bbb 1505
Jerome Coutant 0:146cf26a9bbb 1506 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
Jerome Coutant 0:146cf26a9bbb 1507 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
Jerome Coutant 0:146cf26a9bbb 1508 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
Jerome Coutant 0:146cf26a9bbb 1509 }
Jerome Coutant 0:146cf26a9bbb 1510
Jerome Coutant 0:146cf26a9bbb 1511 /**
Jerome Coutant 0:146cf26a9bbb 1512 * @brief Draws a full ellipse in currently active layer.
Jerome Coutant 0:146cf26a9bbb 1513 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1514 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1515 * @param XRadius: Ellipse X radius
Jerome Coutant 0:146cf26a9bbb 1516 * @param YRadius: Ellipse Y radius
Jerome Coutant 0:146cf26a9bbb 1517 * @retval None
Jerome Coutant 0:146cf26a9bbb 1518 */
Jerome Coutant 0:146cf26a9bbb 1519 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Jerome Coutant 0:146cf26a9bbb 1520 {
Jerome Coutant 0:146cf26a9bbb 1521 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
Jerome Coutant 0:146cf26a9bbb 1522 float K = 0, rad1 = 0, rad2 = 0;
Jerome Coutant 0:146cf26a9bbb 1523
Jerome Coutant 0:146cf26a9bbb 1524 rad1 = XRadius;
Jerome Coutant 0:146cf26a9bbb 1525 rad2 = YRadius;
Jerome Coutant 0:146cf26a9bbb 1526
Jerome Coutant 0:146cf26a9bbb 1527 K = (float)(rad2/rad1);
Jerome Coutant 0:146cf26a9bbb 1528
Jerome Coutant 0:146cf26a9bbb 1529 do
Jerome Coutant 0:146cf26a9bbb 1530 {
Jerome Coutant 0:146cf26a9bbb 1531 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 0:146cf26a9bbb 1532 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 0:146cf26a9bbb 1533
Jerome Coutant 0:146cf26a9bbb 1534 e2 = err;
Jerome Coutant 0:146cf26a9bbb 1535 if (e2 <= x)
Jerome Coutant 0:146cf26a9bbb 1536 {
Jerome Coutant 0:146cf26a9bbb 1537 err += ++x*2+1;
Jerome Coutant 0:146cf26a9bbb 1538 if (-y == x && e2 <= y) e2 = 0;
Jerome Coutant 0:146cf26a9bbb 1539 }
Jerome Coutant 0:146cf26a9bbb 1540 if (e2 > y) err += ++y*2+1;
Jerome Coutant 0:146cf26a9bbb 1541 }
Jerome Coutant 0:146cf26a9bbb 1542 while (y <= 0);
Jerome Coutant 0:146cf26a9bbb 1543 }
Jerome Coutant 0:146cf26a9bbb 1544
Jerome Coutant 0:146cf26a9bbb 1545 /**
Jerome Coutant 0:146cf26a9bbb 1546 * @brief Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff().
Jerome Coutant 0:146cf26a9bbb 1547 * Exit DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 0:146cf26a9bbb 1548 * @retval None
Jerome Coutant 0:146cf26a9bbb 1549 */
Jerome Coutant 0:146cf26a9bbb 1550 void BSP_LCD_DisplayOn(void)
Jerome Coutant 0:146cf26a9bbb 1551 {
Jerome Coutant 0:146cf26a9bbb 1552 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 1553 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:146cf26a9bbb 1554 {
Jerome Coutant 0:146cf26a9bbb 1555 return ; /* Not supported for HDMI display */
Jerome Coutant 0:146cf26a9bbb 1556 }
Jerome Coutant 0:146cf26a9bbb 1557 else
Jerome Coutant 0:146cf26a9bbb 1558 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 1559 {
Jerome Coutant 0:146cf26a9bbb 1560
Jerome Coutant 0:146cf26a9bbb 1561 /* Send Display on DCS command to display */
Jerome Coutant 0:146cf26a9bbb 1562 HAL_DSI_ShortWrite(&(hdsi_discovery),
Jerome Coutant 0:146cf26a9bbb 1563 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 0:146cf26a9bbb 1564 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 0:146cf26a9bbb 1565 OTM8009A_CMD_DISPON,
Jerome Coutant 0:146cf26a9bbb 1566 0x00);
Jerome Coutant 0:146cf26a9bbb 1567 }
Jerome Coutant 0:146cf26a9bbb 1568
Jerome Coutant 0:146cf26a9bbb 1569 }
Jerome Coutant 0:146cf26a9bbb 1570
Jerome Coutant 0:146cf26a9bbb 1571 /**
Jerome Coutant 0:146cf26a9bbb 1572 * @brief Switch Off the display.
Jerome Coutant 0:146cf26a9bbb 1573 * Enter DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 0:146cf26a9bbb 1574 * @retval None
Jerome Coutant 0:146cf26a9bbb 1575 */
Jerome Coutant 0:146cf26a9bbb 1576 void BSP_LCD_DisplayOff(void)
Jerome Coutant 0:146cf26a9bbb 1577 {
Jerome Coutant 0:146cf26a9bbb 1578 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 1579 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:146cf26a9bbb 1580 {
Jerome Coutant 0:146cf26a9bbb 1581 return ; /* Not supported for HDMI yet */
Jerome Coutant 0:146cf26a9bbb 1582 }
Jerome Coutant 0:146cf26a9bbb 1583 else
Jerome Coutant 0:146cf26a9bbb 1584 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 1585 {
Jerome Coutant 0:146cf26a9bbb 1586 /* Send Display off DCS Command to display */
Jerome Coutant 0:146cf26a9bbb 1587 HAL_DSI_ShortWrite(&(hdsi_discovery),
Jerome Coutant 0:146cf26a9bbb 1588 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 0:146cf26a9bbb 1589 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 0:146cf26a9bbb 1590 OTM8009A_CMD_DISPOFF,
Jerome Coutant 0:146cf26a9bbb 1591 0x00);
Jerome Coutant 0:146cf26a9bbb 1592 }
Jerome Coutant 0:146cf26a9bbb 1593
Jerome Coutant 0:146cf26a9bbb 1594 }
Jerome Coutant 0:146cf26a9bbb 1595
Jerome Coutant 0:146cf26a9bbb 1596 /**
Jerome Coutant 0:146cf26a9bbb 1597 * @brief Set the brightness value
Jerome Coutant 0:146cf26a9bbb 1598 * @param BrightnessValue: [00: Min (black), 100 Max]
Jerome Coutant 0:146cf26a9bbb 1599 * @retval None
Jerome Coutant 0:146cf26a9bbb 1600 */
Jerome Coutant 0:146cf26a9bbb 1601 void BSP_LCD_SetBrightness(uint8_t BrightnessValue)
Jerome Coutant 0:146cf26a9bbb 1602 {
Jerome Coutant 0:146cf26a9bbb 1603 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 1604 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:146cf26a9bbb 1605 {
Jerome Coutant 0:146cf26a9bbb 1606 return ; /* Not supported for HDMI display */
Jerome Coutant 0:146cf26a9bbb 1607 }
Jerome Coutant 0:146cf26a9bbb 1608 else
Jerome Coutant 0:146cf26a9bbb 1609 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 1610 {
Jerome Coutant 0:146cf26a9bbb 1611 /* Send Display on DCS command to display */
Jerome Coutant 0:146cf26a9bbb 1612 HAL_DSI_ShortWrite(&hdsi_discovery,
Jerome Coutant 0:146cf26a9bbb 1613 LCD_OTM8009A_ID,
Jerome Coutant 0:146cf26a9bbb 1614 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 0:146cf26a9bbb 1615 OTM8009A_CMD_WRDISBV, (uint16_t)(BrightnessValue * 255)/100);
Jerome Coutant 0:146cf26a9bbb 1616 }
Jerome Coutant 0:146cf26a9bbb 1617
Jerome Coutant 0:146cf26a9bbb 1618 }
Jerome Coutant 0:146cf26a9bbb 1619
Jerome Coutant 0:146cf26a9bbb 1620 /**
Jerome Coutant 0:146cf26a9bbb 1621 * @brief DCS or Generic short/long write command
Jerome Coutant 0:146cf26a9bbb 1622 * @param NbrParams: Number of parameters. It indicates the write command mode:
Jerome Coutant 0:146cf26a9bbb 1623 * If inferior to 2, a long write command is performed else short.
Jerome Coutant 0:146cf26a9bbb 1624 * @param pParams: Pointer to parameter values table.
Jerome Coutant 0:146cf26a9bbb 1625 * @retval None
Jerome Coutant 0:146cf26a9bbb 1626 */
Jerome Coutant 0:146cf26a9bbb 1627 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
Jerome Coutant 0:146cf26a9bbb 1628 {
Jerome Coutant 0:146cf26a9bbb 1629 if(NbrParams <= 1)
Jerome Coutant 0:146cf26a9bbb 1630 {
Jerome Coutant 0:146cf26a9bbb 1631 HAL_DSI_ShortWrite(&hdsi_discovery, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
Jerome Coutant 0:146cf26a9bbb 1632 }
Jerome Coutant 0:146cf26a9bbb 1633 else
Jerome Coutant 0:146cf26a9bbb 1634 {
Jerome Coutant 0:146cf26a9bbb 1635 HAL_DSI_LongWrite(&hdsi_discovery, LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
Jerome Coutant 0:146cf26a9bbb 1636 }
Jerome Coutant 0:146cf26a9bbb 1637 }
Jerome Coutant 0:146cf26a9bbb 1638
Jerome Coutant 0:146cf26a9bbb 1639 /**
Jerome Coutant 0:146cf26a9bbb 1640 * @brief Returns the ID of connected screen by checking the HDMI
Jerome Coutant 0:146cf26a9bbb 1641 * (adv7533 component) ID or LCD DSI (via TS ID) ID.
Jerome Coutant 0:146cf26a9bbb 1642 * @retval LCD ID
Jerome Coutant 0:146cf26a9bbb 1643 */
Jerome Coutant 0:146cf26a9bbb 1644 static uint16_t LCD_IO_GetID(void)
Jerome Coutant 0:146cf26a9bbb 1645 {
Jerome Coutant 0:146cf26a9bbb 1646 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:146cf26a9bbb 1647 HDMI_IO_Init();
Jerome Coutant 0:146cf26a9bbb 1648
Jerome Coutant 0:146cf26a9bbb 1649 HDMI_IO_Delay(120);
Jerome Coutant 0:146cf26a9bbb 1650
Jerome Coutant 0:146cf26a9bbb 1651 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:146cf26a9bbb 1652 {
Jerome Coutant 0:146cf26a9bbb 1653 return ADV7533_ID;
Jerome Coutant 0:146cf26a9bbb 1654 }
Jerome Coutant 0:146cf26a9bbb 1655 else if(((HDMI_IO_Read(LCD_DSI_ADDRESS, LCD_DSI_ID_REG) == LCD_DSI_ID)) || \
Jerome Coutant 0:146cf26a9bbb 1656 (HDMI_IO_Read(LCD_DSI_ADDRESS_A02, LCD_DSI_ID_REG) == LCD_DSI_ID))
Jerome Coutant 0:146cf26a9bbb 1657 {
Jerome Coutant 0:146cf26a9bbb 1658 return LCD_DSI_ID;
Jerome Coutant 0:146cf26a9bbb 1659 }
Jerome Coutant 0:146cf26a9bbb 1660 else
Jerome Coutant 0:146cf26a9bbb 1661 {
Jerome Coutant 0:146cf26a9bbb 1662 return 0;
Jerome Coutant 0:146cf26a9bbb 1663 }
Jerome Coutant 0:146cf26a9bbb 1664 #else
Jerome Coutant 0:146cf26a9bbb 1665 return LCD_DSI_ID;
Jerome Coutant 0:146cf26a9bbb 1666 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:146cf26a9bbb 1667
Jerome Coutant 0:146cf26a9bbb 1668 }
Jerome Coutant 0:146cf26a9bbb 1669
Jerome Coutant 0:146cf26a9bbb 1670 /*******************************************************************************
Jerome Coutant 0:146cf26a9bbb 1671 LTDC, DMA2D and DSI BSP Routines
Jerome Coutant 0:146cf26a9bbb 1672 *******************************************************************************/
Jerome Coutant 0:146cf26a9bbb 1673 /**
Jerome Coutant 0:146cf26a9bbb 1674 * @brief De-Initializes the BSP LCD Msp
Jerome Coutant 0:146cf26a9bbb 1675 * Application can surcharge if needed this function implementation.
Jerome Coutant 0:146cf26a9bbb 1676 * @retval None
Jerome Coutant 0:146cf26a9bbb 1677 */
Jerome Coutant 0:146cf26a9bbb 1678 __weak void BSP_LCD_MspDeInit(void)
Jerome Coutant 0:146cf26a9bbb 1679 {
Jerome Coutant 0:146cf26a9bbb 1680 /** @brief Disable IRQ of LTDC IP */
Jerome Coutant 0:146cf26a9bbb 1681 HAL_NVIC_DisableIRQ(LTDC_IRQn);
Jerome Coutant 0:146cf26a9bbb 1682
Jerome Coutant 0:146cf26a9bbb 1683 /** @brief Disable IRQ of DMA2D IP */
Jerome Coutant 0:146cf26a9bbb 1684 HAL_NVIC_DisableIRQ(DMA2D_IRQn);
Jerome Coutant 0:146cf26a9bbb 1685
Jerome Coutant 0:146cf26a9bbb 1686 /** @brief Disable IRQ of DSI IP */
Jerome Coutant 0:146cf26a9bbb 1687 HAL_NVIC_DisableIRQ(DSI_IRQn);
Jerome Coutant 0:146cf26a9bbb 1688
Jerome Coutant 0:146cf26a9bbb 1689 /** @brief Force and let in reset state LTDC, DMA2D and DSI Host + Wrapper IPs */
Jerome Coutant 0:146cf26a9bbb 1690 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 0:146cf26a9bbb 1691 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 0:146cf26a9bbb 1692 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 0:146cf26a9bbb 1693
Jerome Coutant 0:146cf26a9bbb 1694 /** @brief Disable the LTDC, DMA2D and DSI Host and Wrapper clocks */
Jerome Coutant 0:146cf26a9bbb 1695 __HAL_RCC_LTDC_CLK_DISABLE();
Jerome Coutant 0:146cf26a9bbb 1696 __HAL_RCC_DMA2D_CLK_DISABLE();
Jerome Coutant 0:146cf26a9bbb 1697 __HAL_RCC_DSI_CLK_DISABLE();
Jerome Coutant 0:146cf26a9bbb 1698 }
Jerome Coutant 0:146cf26a9bbb 1699
Jerome Coutant 0:146cf26a9bbb 1700 /**
Jerome Coutant 0:146cf26a9bbb 1701 * @brief Initialize the BSP LCD Msp.
Jerome Coutant 0:146cf26a9bbb 1702 * Application can surcharge if needed this function implementation
Jerome Coutant 0:146cf26a9bbb 1703 * @retval None
Jerome Coutant 0:146cf26a9bbb 1704 */
Jerome Coutant 0:146cf26a9bbb 1705 __weak void BSP_LCD_MspInit(void)
Jerome Coutant 0:146cf26a9bbb 1706 {
Jerome Coutant 0:146cf26a9bbb 1707 /** @brief Enable the LTDC clock */
Jerome Coutant 0:146cf26a9bbb 1708 __HAL_RCC_LTDC_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 1709
Jerome Coutant 0:146cf26a9bbb 1710 /** @brief Toggle Sw reset of LTDC IP */
Jerome Coutant 0:146cf26a9bbb 1711 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 0:146cf26a9bbb 1712 __HAL_RCC_LTDC_RELEASE_RESET();
Jerome Coutant 0:146cf26a9bbb 1713
Jerome Coutant 0:146cf26a9bbb 1714 /** @brief Enable the DMA2D clock */
Jerome Coutant 0:146cf26a9bbb 1715 __HAL_RCC_DMA2D_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 1716
Jerome Coutant 0:146cf26a9bbb 1717 /** @brief Toggle Sw reset of DMA2D IP */
Jerome Coutant 0:146cf26a9bbb 1718 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 0:146cf26a9bbb 1719 __HAL_RCC_DMA2D_RELEASE_RESET();
Jerome Coutant 0:146cf26a9bbb 1720
Jerome Coutant 0:146cf26a9bbb 1721 /** @brief Enable DSI Host and wrapper clocks */
Jerome Coutant 0:146cf26a9bbb 1722 __HAL_RCC_DSI_CLK_ENABLE();
Jerome Coutant 0:146cf26a9bbb 1723
Jerome Coutant 0:146cf26a9bbb 1724 /** @brief Soft Reset the DSI Host and wrapper */
Jerome Coutant 0:146cf26a9bbb 1725 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 0:146cf26a9bbb 1726 __HAL_RCC_DSI_RELEASE_RESET();
Jerome Coutant 0:146cf26a9bbb 1727
Jerome Coutant 0:146cf26a9bbb 1728 /** @brief NVIC configuration for LTDC interrupt that is now enabled */
Jerome Coutant 0:146cf26a9bbb 1729 HAL_NVIC_SetPriority(LTDC_IRQn, 0x0F, 0);
Jerome Coutant 0:146cf26a9bbb 1730 HAL_NVIC_EnableIRQ(LTDC_IRQn);
Jerome Coutant 0:146cf26a9bbb 1731
Jerome Coutant 0:146cf26a9bbb 1732 /** @brief NVIC configuration for DMA2D interrupt that is now enabled */
Jerome Coutant 0:146cf26a9bbb 1733 HAL_NVIC_SetPriority(DMA2D_IRQn, 0x0F, 0);
Jerome Coutant 0:146cf26a9bbb 1734 HAL_NVIC_EnableIRQ(DMA2D_IRQn);
Jerome Coutant 0:146cf26a9bbb 1735
Jerome Coutant 0:146cf26a9bbb 1736 /** @brief NVIC configuration for DSI interrupt that is now enabled */
Jerome Coutant 0:146cf26a9bbb 1737 HAL_NVIC_SetPriority(DSI_IRQn, 0x0F, 0);
Jerome Coutant 0:146cf26a9bbb 1738 HAL_NVIC_EnableIRQ(DSI_IRQn);
Jerome Coutant 0:146cf26a9bbb 1739 }
Jerome Coutant 0:146cf26a9bbb 1740
Jerome Coutant 0:146cf26a9bbb 1741 /**
Jerome Coutant 0:146cf26a9bbb 1742 * @brief Draws a pixel on LCD.
Jerome Coutant 0:146cf26a9bbb 1743 * @param Xpos: X position
Jerome Coutant 0:146cf26a9bbb 1744 * @param Ypos: Y position
Jerome Coutant 0:146cf26a9bbb 1745 * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8)
Jerome Coutant 0:146cf26a9bbb 1746 * @retval None
Jerome Coutant 0:146cf26a9bbb 1747 */
Jerome Coutant 0:146cf26a9bbb 1748 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
Jerome Coutant 0:146cf26a9bbb 1749 {
Jerome Coutant 0:146cf26a9bbb 1750 /* Write data value to all SDRAM memory */
Jerome Coutant 0:146cf26a9bbb 1751 *(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
Jerome Coutant 0:146cf26a9bbb 1752 }
Jerome Coutant 0:146cf26a9bbb 1753 /**
Jerome Coutant 0:146cf26a9bbb 1754 * @}
Jerome Coutant 0:146cf26a9bbb 1755 */
Jerome Coutant 0:146cf26a9bbb 1756
Jerome Coutant 0:146cf26a9bbb 1757 /** @defgroup STM32H747I_DISCOVERY_LCD_Private_Functions Private Functions
Jerome Coutant 0:146cf26a9bbb 1758 * @{
Jerome Coutant 0:146cf26a9bbb 1759 */
Jerome Coutant 0:146cf26a9bbb 1760
Jerome Coutant 0:146cf26a9bbb 1761 /**
Jerome Coutant 0:146cf26a9bbb 1762 * @brief Draws a character on LCD.
Jerome Coutant 0:146cf26a9bbb 1763 * @param Xpos: Line where to display the character shape
Jerome Coutant 0:146cf26a9bbb 1764 * @param Ypos: Start column address
Jerome Coutant 0:146cf26a9bbb 1765 * @param c: Pointer to the character data
Jerome Coutant 0:146cf26a9bbb 1766 * @retval None
Jerome Coutant 0:146cf26a9bbb 1767 */
Jerome Coutant 0:146cf26a9bbb 1768 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
Jerome Coutant 0:146cf26a9bbb 1769 {
Jerome Coutant 0:146cf26a9bbb 1770 uint32_t i = 0, j = 0;
Jerome Coutant 0:146cf26a9bbb 1771 uint16_t height, width;
Jerome Coutant 0:146cf26a9bbb 1772 uint8_t offset;
Jerome Coutant 0:146cf26a9bbb 1773 uint8_t *pchar;
Jerome Coutant 0:146cf26a9bbb 1774 uint32_t line;
Jerome Coutant 0:146cf26a9bbb 1775
Jerome Coutant 0:146cf26a9bbb 1776 height = DrawProp[ActiveLayer].pFont->Height;
Jerome Coutant 0:146cf26a9bbb 1777 width = DrawProp[ActiveLayer].pFont->Width;
Jerome Coutant 0:146cf26a9bbb 1778
Jerome Coutant 0:146cf26a9bbb 1779 offset = 8 *((width + 7)/8) - width ;
Jerome Coutant 0:146cf26a9bbb 1780
Jerome Coutant 0:146cf26a9bbb 1781 for(i = 0; i < height; i++)
Jerome Coutant 0:146cf26a9bbb 1782 {
Jerome Coutant 0:146cf26a9bbb 1783 pchar = ((uint8_t *)c + (width + 7)/8 * i);
Jerome Coutant 0:146cf26a9bbb 1784
Jerome Coutant 0:146cf26a9bbb 1785 switch(((width + 7)/8))
Jerome Coutant 0:146cf26a9bbb 1786 {
Jerome Coutant 0:146cf26a9bbb 1787
Jerome Coutant 0:146cf26a9bbb 1788 case 1:
Jerome Coutant 0:146cf26a9bbb 1789 line = pchar[0];
Jerome Coutant 0:146cf26a9bbb 1790 break;
Jerome Coutant 0:146cf26a9bbb 1791
Jerome Coutant 0:146cf26a9bbb 1792 case 2:
Jerome Coutant 0:146cf26a9bbb 1793 line = (pchar[0]<< 8) | pchar[1];
Jerome Coutant 0:146cf26a9bbb 1794 break;
Jerome Coutant 0:146cf26a9bbb 1795
Jerome Coutant 0:146cf26a9bbb 1796 case 3:
Jerome Coutant 0:146cf26a9bbb 1797 default:
Jerome Coutant 0:146cf26a9bbb 1798 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
Jerome Coutant 0:146cf26a9bbb 1799 break;
Jerome Coutant 0:146cf26a9bbb 1800 }
Jerome Coutant 0:146cf26a9bbb 1801
Jerome Coutant 0:146cf26a9bbb 1802 for (j = 0; j < width; j++)
Jerome Coutant 0:146cf26a9bbb 1803 {
Jerome Coutant 0:146cf26a9bbb 1804 if(line & (1 << (width- j + offset- 1)))
Jerome Coutant 0:146cf26a9bbb 1805 {
Jerome Coutant 0:146cf26a9bbb 1806 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:146cf26a9bbb 1807 }
Jerome Coutant 0:146cf26a9bbb 1808 else
Jerome Coutant 0:146cf26a9bbb 1809 {
Jerome Coutant 0:146cf26a9bbb 1810 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
Jerome Coutant 0:146cf26a9bbb 1811 }
Jerome Coutant 0:146cf26a9bbb 1812 }
Jerome Coutant 0:146cf26a9bbb 1813 Ypos++;
Jerome Coutant 0:146cf26a9bbb 1814 }
Jerome Coutant 0:146cf26a9bbb 1815 }
Jerome Coutant 0:146cf26a9bbb 1816
Jerome Coutant 0:146cf26a9bbb 1817 /**
Jerome Coutant 0:146cf26a9bbb 1818 * @brief Fills a triangle (between 3 points).
Jerome Coutant 0:146cf26a9bbb 1819 * @param x1: Point 1 X position
Jerome Coutant 0:146cf26a9bbb 1820 * @param y1: Point 1 Y position
Jerome Coutant 0:146cf26a9bbb 1821 * @param x2: Point 2 X position
Jerome Coutant 0:146cf26a9bbb 1822 * @param y2: Point 2 Y position
Jerome Coutant 0:146cf26a9bbb 1823 * @param x3: Point 3 X position
Jerome Coutant 0:146cf26a9bbb 1824 * @param y3: Point 3 Y position
Jerome Coutant 0:146cf26a9bbb 1825 * @retval None
Jerome Coutant 0:146cf26a9bbb 1826 */
Jerome Coutant 0:146cf26a9bbb 1827 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
Jerome Coutant 0:146cf26a9bbb 1828 {
Jerome Coutant 0:146cf26a9bbb 1829 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
Jerome Coutant 0:146cf26a9bbb 1830 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
Jerome Coutant 0:146cf26a9bbb 1831 curpixel = 0;
Jerome Coutant 0:146cf26a9bbb 1832
Jerome Coutant 0:146cf26a9bbb 1833 deltax = ABS(x2 - x1); /* The difference between the x's */
Jerome Coutant 0:146cf26a9bbb 1834 deltay = ABS(y2 - y1); /* The difference between the y's */
Jerome Coutant 0:146cf26a9bbb 1835 x = x1; /* Start x off at the first pixel */
Jerome Coutant 0:146cf26a9bbb 1836 y = y1; /* Start y off at the first pixel */
Jerome Coutant 0:146cf26a9bbb 1837
Jerome Coutant 0:146cf26a9bbb 1838 if (x2 >= x1) /* The x-values are increasing */
Jerome Coutant 0:146cf26a9bbb 1839 {
Jerome Coutant 0:146cf26a9bbb 1840 xinc1 = 1;
Jerome Coutant 0:146cf26a9bbb 1841 xinc2 = 1;
Jerome Coutant 0:146cf26a9bbb 1842 }
Jerome Coutant 0:146cf26a9bbb 1843 else /* The x-values are decreasing */
Jerome Coutant 0:146cf26a9bbb 1844 {
Jerome Coutant 0:146cf26a9bbb 1845 xinc1 = -1;
Jerome Coutant 0:146cf26a9bbb 1846 xinc2 = -1;
Jerome Coutant 0:146cf26a9bbb 1847 }
Jerome Coutant 0:146cf26a9bbb 1848
Jerome Coutant 0:146cf26a9bbb 1849 if (y2 >= y1) /* The y-values are increasing */
Jerome Coutant 0:146cf26a9bbb 1850 {
Jerome Coutant 0:146cf26a9bbb 1851 yinc1 = 1;
Jerome Coutant 0:146cf26a9bbb 1852 yinc2 = 1;
Jerome Coutant 0:146cf26a9bbb 1853 }
Jerome Coutant 0:146cf26a9bbb 1854 else /* The y-values are decreasing */
Jerome Coutant 0:146cf26a9bbb 1855 {
Jerome Coutant 0:146cf26a9bbb 1856 yinc1 = -1;
Jerome Coutant 0:146cf26a9bbb 1857 yinc2 = -1;
Jerome Coutant 0:146cf26a9bbb 1858 }
Jerome Coutant 0:146cf26a9bbb 1859
Jerome Coutant 0:146cf26a9bbb 1860 if (deltax >= deltay) /* There is at least one x-value for every y-value */
Jerome Coutant 0:146cf26a9bbb 1861 {
Jerome Coutant 0:146cf26a9bbb 1862 xinc1 = 0; /* Don't change the x when numerator >= denominator */
Jerome Coutant 0:146cf26a9bbb 1863 yinc2 = 0; /* Don't change the y for every iteration */
Jerome Coutant 0:146cf26a9bbb 1864 den = deltax;
Jerome Coutant 0:146cf26a9bbb 1865 num = deltax / 2;
Jerome Coutant 0:146cf26a9bbb 1866 numadd = deltay;
Jerome Coutant 0:146cf26a9bbb 1867 numpixels = deltax; /* There are more x-values than y-values */
Jerome Coutant 0:146cf26a9bbb 1868 }
Jerome Coutant 0:146cf26a9bbb 1869 else /* There is at least one y-value for every x-value */
Jerome Coutant 0:146cf26a9bbb 1870 {
Jerome Coutant 0:146cf26a9bbb 1871 xinc2 = 0; /* Don't change the x for every iteration */
Jerome Coutant 0:146cf26a9bbb 1872 yinc1 = 0; /* Don't change the y when numerator >= denominator */
Jerome Coutant 0:146cf26a9bbb 1873 den = deltay;
Jerome Coutant 0:146cf26a9bbb 1874 num = deltay / 2;
Jerome Coutant 0:146cf26a9bbb 1875 numadd = deltax;
Jerome Coutant 0:146cf26a9bbb 1876 numpixels = deltay; /* There are more y-values than x-values */
Jerome Coutant 0:146cf26a9bbb 1877 }
Jerome Coutant 0:146cf26a9bbb 1878
Jerome Coutant 0:146cf26a9bbb 1879 for (curpixel = 0; curpixel <= numpixels; curpixel++)
Jerome Coutant 0:146cf26a9bbb 1880 {
Jerome Coutant 0:146cf26a9bbb 1881 BSP_LCD_DrawLine(x, y, x3, y3);
Jerome Coutant 0:146cf26a9bbb 1882
Jerome Coutant 0:146cf26a9bbb 1883 num += numadd; /* Increase the numerator by the top of the fraction */
Jerome Coutant 0:146cf26a9bbb 1884 if (num >= den) /* Check if numerator >= denominator */
Jerome Coutant 0:146cf26a9bbb 1885 {
Jerome Coutant 0:146cf26a9bbb 1886 num -= den; /* Calculate the new numerator value */
Jerome Coutant 0:146cf26a9bbb 1887 x += xinc1; /* Change the x as appropriate */
Jerome Coutant 0:146cf26a9bbb 1888 y += yinc1; /* Change the y as appropriate */
Jerome Coutant 0:146cf26a9bbb 1889 }
Jerome Coutant 0:146cf26a9bbb 1890 x += xinc2; /* Change the x as appropriate */
Jerome Coutant 0:146cf26a9bbb 1891 y += yinc2; /* Change the y as appropriate */
Jerome Coutant 0:146cf26a9bbb 1892 }
Jerome Coutant 0:146cf26a9bbb 1893 }
Jerome Coutant 0:146cf26a9bbb 1894
Jerome Coutant 0:146cf26a9bbb 1895 /**
Jerome Coutant 0:146cf26a9bbb 1896 * @brief Fills a buffer.
Jerome Coutant 0:146cf26a9bbb 1897 * @param LayerIndex: Layer index
Jerome Coutant 0:146cf26a9bbb 1898 * @param pDst: Pointer to destination buffer
Jerome Coutant 0:146cf26a9bbb 1899 * @param xSize: Buffer width
Jerome Coutant 0:146cf26a9bbb 1900 * @param ySize: Buffer height
Jerome Coutant 0:146cf26a9bbb 1901 * @param OffLine: Offset
Jerome Coutant 0:146cf26a9bbb 1902 * @param ColorIndex: Color index
Jerome Coutant 0:146cf26a9bbb 1903 * @retval None
Jerome Coutant 0:146cf26a9bbb 1904 */
Jerome Coutant 0:146cf26a9bbb 1905 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
Jerome Coutant 0:146cf26a9bbb 1906 {
Jerome Coutant 0:146cf26a9bbb 1907 /* Register to memory mode with ARGB8888 as color Mode */
Jerome Coutant 0:146cf26a9bbb 1908 hdma2d_discovery.Init.Mode = DMA2D_R2M;
Jerome Coutant 0:146cf26a9bbb 1909 hdma2d_discovery.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
Jerome Coutant 0:146cf26a9bbb 1910 hdma2d_discovery.Init.OutputOffset = OffLine;
Jerome Coutant 0:146cf26a9bbb 1911
Jerome Coutant 0:146cf26a9bbb 1912 hdma2d_discovery.Instance = DMA2D;
Jerome Coutant 0:146cf26a9bbb 1913
Jerome Coutant 0:146cf26a9bbb 1914 /* DMA2D Initialization */
Jerome Coutant 0:146cf26a9bbb 1915 if(HAL_DMA2D_Init(&hdma2d_discovery) == HAL_OK)
Jerome Coutant 0:146cf26a9bbb 1916 {
Jerome Coutant 0:146cf26a9bbb 1917 if(HAL_DMA2D_ConfigLayer(&hdma2d_discovery, 1) == HAL_OK)
Jerome Coutant 0:146cf26a9bbb 1918 {
Jerome Coutant 0:146cf26a9bbb 1919 if (HAL_DMA2D_Start(&hdma2d_discovery, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
Jerome Coutant 0:146cf26a9bbb 1920 {
Jerome Coutant 0:146cf26a9bbb 1921 /* Polling For DMA transfer */
Jerome Coutant 0:146cf26a9bbb 1922 HAL_DMA2D_PollForTransfer(&hdma2d_discovery, 25);
Jerome Coutant 0:146cf26a9bbb 1923 }
Jerome Coutant 0:146cf26a9bbb 1924 }
Jerome Coutant 0:146cf26a9bbb 1925 }
Jerome Coutant 0:146cf26a9bbb 1926 }
Jerome Coutant 0:146cf26a9bbb 1927
Jerome Coutant 0:146cf26a9bbb 1928 /**
Jerome Coutant 0:146cf26a9bbb 1929 * @brief Converts a line to an ARGB8888 pixel format.
Jerome Coutant 0:146cf26a9bbb 1930 * @param pSrc: Pointer to source buffer
Jerome Coutant 0:146cf26a9bbb 1931 * @param pDst: Output color
Jerome Coutant 0:146cf26a9bbb 1932 * @param xSize: Buffer width
Jerome Coutant 0:146cf26a9bbb 1933 * @param ColorMode: Input color mode
Jerome Coutant 0:146cf26a9bbb 1934 * @retval None
Jerome Coutant 0:146cf26a9bbb 1935 */
Jerome Coutant 0:146cf26a9bbb 1936 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
Jerome Coutant 0:146cf26a9bbb 1937 {
Jerome Coutant 0:146cf26a9bbb 1938 /* Configure the DMA2D Mode, Color Mode and output offset */
Jerome Coutant 0:146cf26a9bbb 1939 hdma2d_discovery.Init.Mode = DMA2D_M2M_PFC;
Jerome Coutant 0:146cf26a9bbb 1940 hdma2d_discovery.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
Jerome Coutant 0:146cf26a9bbb 1941 hdma2d_discovery.Init.OutputOffset = 0;
Jerome Coutant 0:146cf26a9bbb 1942
Jerome Coutant 0:146cf26a9bbb 1943 /* Foreground Configuration */
Jerome Coutant 0:146cf26a9bbb 1944 hdma2d_discovery.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
Jerome Coutant 0:146cf26a9bbb 1945 hdma2d_discovery.LayerCfg[1].InputAlpha = 0xFF;
Jerome Coutant 0:146cf26a9bbb 1946 hdma2d_discovery.LayerCfg[1].InputColorMode = ColorMode;
Jerome Coutant 0:146cf26a9bbb 1947 hdma2d_discovery.LayerCfg[1].InputOffset = 0;
Jerome Coutant 0:146cf26a9bbb 1948
Jerome Coutant 0:146cf26a9bbb 1949 hdma2d_discovery.Instance = DMA2D;
Jerome Coutant 0:146cf26a9bbb 1950
Jerome Coutant 0:146cf26a9bbb 1951 /* DMA2D Initialization */
Jerome Coutant 0:146cf26a9bbb 1952 if(HAL_DMA2D_Init(&hdma2d_discovery) == HAL_OK)
Jerome Coutant 0:146cf26a9bbb 1953 {
Jerome Coutant 0:146cf26a9bbb 1954 if(HAL_DMA2D_ConfigLayer(&hdma2d_discovery, 1) == HAL_OK)
Jerome Coutant 0:146cf26a9bbb 1955 {
Jerome Coutant 0:146cf26a9bbb 1956 if (HAL_DMA2D_Start(&hdma2d_discovery, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
Jerome Coutant 0:146cf26a9bbb 1957 {
Jerome Coutant 0:146cf26a9bbb 1958 /* Polling For DMA transfer */
Jerome Coutant 0:146cf26a9bbb 1959 HAL_DMA2D_PollForTransfer(&hdma2d_discovery, 25);
Jerome Coutant 0:146cf26a9bbb 1960 }
Jerome Coutant 0:146cf26a9bbb 1961 }
Jerome Coutant 0:146cf26a9bbb 1962 }
Jerome Coutant 0:146cf26a9bbb 1963 }
Jerome Coutant 0:146cf26a9bbb 1964
Jerome Coutant 0:146cf26a9bbb 1965 /**
Jerome Coutant 0:146cf26a9bbb 1966 * @}
Jerome Coutant 0:146cf26a9bbb 1967 */
Jerome Coutant 0:146cf26a9bbb 1968
Jerome Coutant 0:146cf26a9bbb 1969 /**
Jerome Coutant 0:146cf26a9bbb 1970 * @}
Jerome Coutant 0:146cf26a9bbb 1971 */
Jerome Coutant 0:146cf26a9bbb 1972
Jerome Coutant 0:146cf26a9bbb 1973 /**
Jerome Coutant 0:146cf26a9bbb 1974 * @}
Jerome Coutant 0:146cf26a9bbb 1975 */
Jerome Coutant 0:146cf26a9bbb 1976
Jerome Coutant 0:146cf26a9bbb 1977 /**
Jerome Coutant 0:146cf26a9bbb 1978 * @}
Jerome Coutant 0:146cf26a9bbb 1979 */
Jerome Coutant 0:146cf26a9bbb 1980
Jerome Coutant 0:146cf26a9bbb 1981 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/