patch for F746 demo

Dependents:   F7DISCO_Demo

Fork of BSP_DISCO_F746NG by ST

Committer:
NirT
Date:
Mon Nov 02 23:35:17 2015 +0000
Revision:
1:e8fac4061a5b
Parent:
0:c9112f0c67e3
Error: Incomplete type is not allowed in "patch/LwIP/src/include/lwip/dhcp.h", Line: 83, Col: 4; ; and more like this.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:c9112f0c67e3 1 /**
bcostm 0:c9112f0c67e3 2 ******************************************************************************
bcostm 0:c9112f0c67e3 3 * @file stm32746g_discovery_lcd.c
bcostm 0:c9112f0c67e3 4 * @author MCD Application Team
bcostm 0:c9112f0c67e3 5 * @version V1.0.0
bcostm 0:c9112f0c67e3 6 * @date 25-June-2015
bcostm 0:c9112f0c67e3 7 * @brief This file includes the driver for Liquid Crystal Display (LCD) module
bcostm 0:c9112f0c67e3 8 * mounted on STM32746G-Discovery board.
bcostm 0:c9112f0c67e3 9 @verbatim
bcostm 0:c9112f0c67e3 10 1. How To use this driver:
bcostm 0:c9112f0c67e3 11 --------------------------
bcostm 0:c9112f0c67e3 12 - This driver is used to drive directly an LCD TFT using the LTDC controller.
bcostm 0:c9112f0c67e3 13 - This driver uses timing and setting for RK043FN48H LCD.
bcostm 0:c9112f0c67e3 14
bcostm 0:c9112f0c67e3 15 2. Driver description:
bcostm 0:c9112f0c67e3 16 ---------------------
bcostm 0:c9112f0c67e3 17 + Initialization steps:
bcostm 0:c9112f0c67e3 18 o Initialize the LCD using the BSP_LCD_Init() function.
bcostm 0:c9112f0c67e3 19 o Apply the Layer configuration using the BSP_LCD_LayerDefaultInit() function.
bcostm 0:c9112f0c67e3 20 o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
bcostm 0:c9112f0c67e3 21 o Enable the LCD display using the BSP_LCD_DisplayOn() function.
bcostm 0:c9112f0c67e3 22
bcostm 0:c9112f0c67e3 23 + Options
bcostm 0:c9112f0c67e3 24 o Configure and enable the color keying functionality using the
bcostm 0:c9112f0c67e3 25 BSP_LCD_SetColorKeying() function.
bcostm 0:c9112f0c67e3 26 o Modify in the fly the transparency and/or the frame buffer address
bcostm 0:c9112f0c67e3 27 using the following functions:
bcostm 0:c9112f0c67e3 28 - BSP_LCD_SetTransparency()
bcostm 0:c9112f0c67e3 29 - BSP_LCD_SetLayerAddress()
bcostm 0:c9112f0c67e3 30
bcostm 0:c9112f0c67e3 31 + Display on LCD
bcostm 0:c9112f0c67e3 32 o Clear the hole LCD using BSP_LCD_Clear() function or only one specified string
bcostm 0:c9112f0c67e3 33 line using the BSP_LCD_ClearStringLine() function.
bcostm 0:c9112f0c67e3 34 o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
bcostm 0:c9112f0c67e3 35 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
bcostm 0:c9112f0c67e3 36 o Display a string line on the specified position (x,y in pixel) and align mode
bcostm 0:c9112f0c67e3 37 using the BSP_LCD_DisplayStringAtLine() function.
bcostm 0:c9112f0c67e3 38 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
bcostm 0:c9112f0c67e3 39 on LCD using the available set of functions.
bcostm 0:c9112f0c67e3 40 @endverbatim
bcostm 0:c9112f0c67e3 41 ******************************************************************************
bcostm 0:c9112f0c67e3 42 * @attention
bcostm 0:c9112f0c67e3 43 *
bcostm 0:c9112f0c67e3 44 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
bcostm 0:c9112f0c67e3 45 *
bcostm 0:c9112f0c67e3 46 * Redistribution and use in source and binary forms, with or without modification,
bcostm 0:c9112f0c67e3 47 * are permitted provided that the following conditions are met:
bcostm 0:c9112f0c67e3 48 * 1. Redistributions of source code must retain the above copyright notice,
bcostm 0:c9112f0c67e3 49 * this list of conditions and the following disclaimer.
bcostm 0:c9112f0c67e3 50 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcostm 0:c9112f0c67e3 51 * this list of conditions and the following disclaimer in the documentation
bcostm 0:c9112f0c67e3 52 * and/or other materials provided with the distribution.
bcostm 0:c9112f0c67e3 53 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bcostm 0:c9112f0c67e3 54 * may be used to endorse or promote products derived from this software
bcostm 0:c9112f0c67e3 55 * without specific prior written permission.
bcostm 0:c9112f0c67e3 56 *
bcostm 0:c9112f0c67e3 57 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bcostm 0:c9112f0c67e3 58 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bcostm 0:c9112f0c67e3 59 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bcostm 0:c9112f0c67e3 60 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bcostm 0:c9112f0c67e3 61 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bcostm 0:c9112f0c67e3 62 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bcostm 0:c9112f0c67e3 63 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bcostm 0:c9112f0c67e3 64 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bcostm 0:c9112f0c67e3 65 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bcostm 0:c9112f0c67e3 66 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcostm 0:c9112f0c67e3 67 *
bcostm 0:c9112f0c67e3 68 ******************************************************************************
bcostm 0:c9112f0c67e3 69 */
bcostm 0:c9112f0c67e3 70
bcostm 0:c9112f0c67e3 71 /* Includes ------------------------------------------------------------------*/
bcostm 0:c9112f0c67e3 72 #include "stm32746g_discovery_lcd.h"
bcostm 0:c9112f0c67e3 73 #include "fonts.h"
bcostm 0:c9112f0c67e3 74 /*
bcostm 0:c9112f0c67e3 75 #include "font24.c"
bcostm 0:c9112f0c67e3 76 #include "font20.c"
bcostm 0:c9112f0c67e3 77 #include "font16.c"
bcostm 0:c9112f0c67e3 78 #include "font12.c"
bcostm 0:c9112f0c67e3 79 #include "font8.c"
bcostm 0:c9112f0c67e3 80 */
bcostm 0:c9112f0c67e3 81
bcostm 0:c9112f0c67e3 82 /** @addtogroup BSP
bcostm 0:c9112f0c67e3 83 * @{
bcostm 0:c9112f0c67e3 84 */
bcostm 0:c9112f0c67e3 85
bcostm 0:c9112f0c67e3 86 /** @addtogroup STM32746G_DISCOVERY
bcostm 0:c9112f0c67e3 87 * @{
bcostm 0:c9112f0c67e3 88 */
bcostm 0:c9112f0c67e3 89
bcostm 0:c9112f0c67e3 90 /** @addtogroup STM32746G_DISCOVERY_LCD
bcostm 0:c9112f0c67e3 91 * @{
bcostm 0:c9112f0c67e3 92 */
bcostm 0:c9112f0c67e3 93
bcostm 0:c9112f0c67e3 94 /** @defgroup STM32746G_DISCOVERY_LCD_Private_TypesDefinitions STM32746G_DISCOVERY_LCD Private Types Definitions
bcostm 0:c9112f0c67e3 95 * @{
bcostm 0:c9112f0c67e3 96 */
bcostm 0:c9112f0c67e3 97 /**
bcostm 0:c9112f0c67e3 98 * @}
bcostm 0:c9112f0c67e3 99 */
bcostm 0:c9112f0c67e3 100
bcostm 0:c9112f0c67e3 101 /** @defgroup STM32746G_DISCOVERY_LCD_Private_Defines STM32746G_DISCOVERY LCD Private Defines
bcostm 0:c9112f0c67e3 102 * @{
bcostm 0:c9112f0c67e3 103 */
bcostm 0:c9112f0c67e3 104 #define POLY_X(Z) ((int32_t)((Points + Z)->X))
bcostm 0:c9112f0c67e3 105 #define POLY_Y(Z) ((int32_t)((Points + Z)->Y))
bcostm 0:c9112f0c67e3 106 /**
bcostm 0:c9112f0c67e3 107 * @}
bcostm 0:c9112f0c67e3 108 */
bcostm 0:c9112f0c67e3 109
bcostm 0:c9112f0c67e3 110 /** @defgroup STM32746G_DISCOVERY_LCD_Private_Macros STM32746G_DISCOVERY_LCD Private Macros
bcostm 0:c9112f0c67e3 111 * @{
bcostm 0:c9112f0c67e3 112 */
bcostm 0:c9112f0c67e3 113 #define ABS(X) ((X) > 0 ? (X) : -(X))
bcostm 0:c9112f0c67e3 114 /**
bcostm 0:c9112f0c67e3 115 * @}
bcostm 0:c9112f0c67e3 116 */
bcostm 0:c9112f0c67e3 117
bcostm 0:c9112f0c67e3 118 /** @defgroup STM32746G_DISCOVERY_LCD_Private_Variables STM32746G_DISCOVERY_LCD Private Variables
bcostm 0:c9112f0c67e3 119 * @{
bcostm 0:c9112f0c67e3 120 */
bcostm 0:c9112f0c67e3 121 static LTDC_HandleTypeDef hLtdcHandler;
bcostm 0:c9112f0c67e3 122 static DMA2D_HandleTypeDef hDma2dHandler;
bcostm 0:c9112f0c67e3 123
bcostm 0:c9112f0c67e3 124 /* Default LCD configuration with LCD Layer 1 */
bcostm 0:c9112f0c67e3 125 static uint32_t ActiveLayer = 0;
bcostm 0:c9112f0c67e3 126 static LCD_DrawPropTypeDef DrawProp[MAX_LAYER_NUMBER];
bcostm 0:c9112f0c67e3 127 /**
bcostm 0:c9112f0c67e3 128 * @}
bcostm 0:c9112f0c67e3 129 */
bcostm 0:c9112f0c67e3 130
bcostm 0:c9112f0c67e3 131 /** @defgroup STM32746G_DISCOVERY_LCD_Private_FunctionPrototypes STM32746G_DISCOVERY_LCD Private Function Prototypes
bcostm 0:c9112f0c67e3 132 * @{
bcostm 0:c9112f0c67e3 133 */
bcostm 0:c9112f0c67e3 134 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
bcostm 0:c9112f0c67e3 135 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
bcostm 0:c9112f0c67e3 136 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
bcostm 0:c9112f0c67e3 137 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
bcostm 0:c9112f0c67e3 138 /**
bcostm 0:c9112f0c67e3 139 * @}
bcostm 0:c9112f0c67e3 140 */
bcostm 0:c9112f0c67e3 141
bcostm 0:c9112f0c67e3 142 /** @defgroup STM32746G_DISCOVERY_LCD_Exported_Functions STM32746G_DISCOVERY_LCD Exported Functions
bcostm 0:c9112f0c67e3 143 * @{
bcostm 0:c9112f0c67e3 144 */
bcostm 0:c9112f0c67e3 145
bcostm 0:c9112f0c67e3 146 /**
bcostm 0:c9112f0c67e3 147 * @brief Initializes the LCD.
bcostm 0:c9112f0c67e3 148 * @retval LCD state
bcostm 0:c9112f0c67e3 149 */
bcostm 0:c9112f0c67e3 150 uint8_t BSP_LCD_Init(void)
bcostm 0:c9112f0c67e3 151 {
bcostm 0:c9112f0c67e3 152 /* Select the used LCD */
bcostm 0:c9112f0c67e3 153
bcostm 0:c9112f0c67e3 154 /* The RK043FN48H LCD 480x272 is selected */
bcostm 0:c9112f0c67e3 155 /* Timing Configuration */
bcostm 0:c9112f0c67e3 156 hLtdcHandler.Init.HorizontalSync = (RK043FN48H_HSYNC - 1);
bcostm 0:c9112f0c67e3 157 hLtdcHandler.Init.VerticalSync = (RK043FN48H_VSYNC - 1);
bcostm 0:c9112f0c67e3 158 hLtdcHandler.Init.AccumulatedHBP = (RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
bcostm 0:c9112f0c67e3 159 hLtdcHandler.Init.AccumulatedVBP = (RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
bcostm 0:c9112f0c67e3 160 hLtdcHandler.Init.AccumulatedActiveH = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP - 1);
bcostm 0:c9112f0c67e3 161 hLtdcHandler.Init.AccumulatedActiveW = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP - 1);
bcostm 0:c9112f0c67e3 162 hLtdcHandler.Init.TotalHeigh = (RK043FN48H_HEIGHT + RK043FN48H_VSYNC + RK043FN48H_VBP + RK043FN48H_VFP - 1);
bcostm 0:c9112f0c67e3 163 hLtdcHandler.Init.TotalWidth = (RK043FN48H_WIDTH + RK043FN48H_HSYNC + RK043FN48H_HBP + RK043FN48H_HFP - 1);
bcostm 0:c9112f0c67e3 164
bcostm 0:c9112f0c67e3 165 /* LCD clock configuration */
bcostm 0:c9112f0c67e3 166 BSP_LCD_ClockConfig(&hLtdcHandler, NULL);
bcostm 0:c9112f0c67e3 167
bcostm 0:c9112f0c67e3 168 /* Initialize the LCD pixel width and pixel height */
bcostm 0:c9112f0c67e3 169 hLtdcHandler.LayerCfg->ImageWidth = RK043FN48H_WIDTH;
bcostm 0:c9112f0c67e3 170 hLtdcHandler.LayerCfg->ImageHeight = RK043FN48H_HEIGHT;
bcostm 0:c9112f0c67e3 171
bcostm 0:c9112f0c67e3 172 /* Background value */
bcostm 0:c9112f0c67e3 173 hLtdcHandler.Init.Backcolor.Blue = 0;
bcostm 0:c9112f0c67e3 174 hLtdcHandler.Init.Backcolor.Green = 0;
bcostm 0:c9112f0c67e3 175 hLtdcHandler.Init.Backcolor.Red = 0;
bcostm 0:c9112f0c67e3 176
bcostm 0:c9112f0c67e3 177 /* Polarity */
bcostm 0:c9112f0c67e3 178 hLtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL;
bcostm 0:c9112f0c67e3 179 hLtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL;
bcostm 0:c9112f0c67e3 180 hLtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL;
bcostm 0:c9112f0c67e3 181 hLtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
bcostm 0:c9112f0c67e3 182 hLtdcHandler.Instance = LTDC;
bcostm 0:c9112f0c67e3 183
bcostm 0:c9112f0c67e3 184 if(HAL_LTDC_GetState(&hLtdcHandler) == HAL_LTDC_STATE_RESET)
bcostm 0:c9112f0c67e3 185 {
bcostm 0:c9112f0c67e3 186 /* Initialize the LCD Msp: this __weak function can be rewritten by the application */
bcostm 0:c9112f0c67e3 187 BSP_LCD_MspInit(&hLtdcHandler, NULL);
bcostm 0:c9112f0c67e3 188 }
bcostm 0:c9112f0c67e3 189 HAL_LTDC_Init(&hLtdcHandler);
bcostm 0:c9112f0c67e3 190
bcostm 0:c9112f0c67e3 191 /* Assert display enable LCD_DISP pin */
bcostm 0:c9112f0c67e3 192 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_SET);
bcostm 0:c9112f0c67e3 193
bcostm 0:c9112f0c67e3 194 /* Assert backlight LCD_BL_CTRL pin */
bcostm 0:c9112f0c67e3 195 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET);
bcostm 0:c9112f0c67e3 196
bcostm 0:c9112f0c67e3 197 #if !defined(DATA_IN_ExtSDRAM)
bcostm 0:c9112f0c67e3 198 /* Initialize the SDRAM */
bcostm 0:c9112f0c67e3 199 BSP_SDRAM_Init();
bcostm 0:c9112f0c67e3 200 #endif
bcostm 0:c9112f0c67e3 201
bcostm 0:c9112f0c67e3 202 /* Initialize the font */
bcostm 0:c9112f0c67e3 203 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
bcostm 0:c9112f0c67e3 204
bcostm 0:c9112f0c67e3 205 return LCD_OK;
bcostm 0:c9112f0c67e3 206 }
bcostm 0:c9112f0c67e3 207
bcostm 0:c9112f0c67e3 208 /**
bcostm 0:c9112f0c67e3 209 * @brief DeInitializes the LCD.
bcostm 0:c9112f0c67e3 210 * @retval LCD state
bcostm 0:c9112f0c67e3 211 */
bcostm 0:c9112f0c67e3 212 uint8_t BSP_LCD_DeInit(void)
bcostm 0:c9112f0c67e3 213 {
bcostm 0:c9112f0c67e3 214 /* Initialize the hLtdcHandler Instance parameter */
bcostm 0:c9112f0c67e3 215 hLtdcHandler.Instance = LTDC;
bcostm 0:c9112f0c67e3 216
bcostm 0:c9112f0c67e3 217 /* Disable LTDC block */
bcostm 0:c9112f0c67e3 218 __HAL_LTDC_DISABLE(&hLtdcHandler);
bcostm 0:c9112f0c67e3 219
bcostm 0:c9112f0c67e3 220 /* DeInit the LTDC */
bcostm 0:c9112f0c67e3 221 HAL_LTDC_DeInit(&hLtdcHandler);
bcostm 0:c9112f0c67e3 222
bcostm 0:c9112f0c67e3 223 /* DeInit the LTDC MSP : this __weak function can be rewritten by the application */
bcostm 0:c9112f0c67e3 224 BSP_LCD_MspDeInit(&hLtdcHandler, NULL);
bcostm 0:c9112f0c67e3 225
bcostm 0:c9112f0c67e3 226 return LCD_OK;
bcostm 0:c9112f0c67e3 227 }
bcostm 0:c9112f0c67e3 228
bcostm 0:c9112f0c67e3 229 /**
bcostm 0:c9112f0c67e3 230 * @brief Gets the LCD X size.
bcostm 0:c9112f0c67e3 231 * @retval Used LCD X size
bcostm 0:c9112f0c67e3 232 */
bcostm 0:c9112f0c67e3 233 uint32_t BSP_LCD_GetXSize(void)
bcostm 0:c9112f0c67e3 234 {
bcostm 0:c9112f0c67e3 235 return hLtdcHandler.LayerCfg[ActiveLayer].ImageWidth;
bcostm 0:c9112f0c67e3 236 }
bcostm 0:c9112f0c67e3 237
bcostm 0:c9112f0c67e3 238 /**
bcostm 0:c9112f0c67e3 239 * @brief Gets the LCD Y size.
bcostm 0:c9112f0c67e3 240 * @retval Used LCD Y size
bcostm 0:c9112f0c67e3 241 */
bcostm 0:c9112f0c67e3 242 uint32_t BSP_LCD_GetYSize(void)
bcostm 0:c9112f0c67e3 243 {
bcostm 0:c9112f0c67e3 244 return hLtdcHandler.LayerCfg[ActiveLayer].ImageHeight;
bcostm 0:c9112f0c67e3 245 }
bcostm 0:c9112f0c67e3 246
bcostm 0:c9112f0c67e3 247 /**
bcostm 0:c9112f0c67e3 248 * @brief Set the LCD X size.
bcostm 0:c9112f0c67e3 249 * @param imageWidthPixels : image width in pixels unit
bcostm 0:c9112f0c67e3 250 * @retval None
bcostm 0:c9112f0c67e3 251 */
bcostm 0:c9112f0c67e3 252 void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
bcostm 0:c9112f0c67e3 253 {
bcostm 0:c9112f0c67e3 254 hLtdcHandler.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
bcostm 0:c9112f0c67e3 255 }
bcostm 0:c9112f0c67e3 256
bcostm 0:c9112f0c67e3 257 /**
bcostm 0:c9112f0c67e3 258 * @brief Set the LCD Y size.
bcostm 0:c9112f0c67e3 259 * @param imageHeightPixels : image height in lines unit
bcostm 0:c9112f0c67e3 260 * @retval None
bcostm 0:c9112f0c67e3 261 */
bcostm 0:c9112f0c67e3 262 void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
bcostm 0:c9112f0c67e3 263 {
bcostm 0:c9112f0c67e3 264 hLtdcHandler.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
bcostm 0:c9112f0c67e3 265 }
bcostm 0:c9112f0c67e3 266
bcostm 0:c9112f0c67e3 267 /**
bcostm 0:c9112f0c67e3 268 * @brief Initializes the LCD layer in ARGB8888 format (32 bits per pixel).
bcostm 0:c9112f0c67e3 269 * @param LayerIndex: Layer foreground or background
bcostm 0:c9112f0c67e3 270 * @param FB_Address: Layer frame buffer
bcostm 0:c9112f0c67e3 271 * @retval None
bcostm 0:c9112f0c67e3 272 */
bcostm 0:c9112f0c67e3 273 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
bcostm 0:c9112f0c67e3 274 {
bcostm 0:c9112f0c67e3 275 LCD_LayerCfgTypeDef layer_cfg;
bcostm 0:c9112f0c67e3 276
bcostm 0:c9112f0c67e3 277 /* Layer Init */
bcostm 0:c9112f0c67e3 278 layer_cfg.WindowX0 = 0;
bcostm 0:c9112f0c67e3 279 layer_cfg.WindowX1 = BSP_LCD_GetXSize();
bcostm 0:c9112f0c67e3 280 layer_cfg.WindowY0 = 0;
bcostm 0:c9112f0c67e3 281 layer_cfg.WindowY1 = BSP_LCD_GetYSize();
bcostm 0:c9112f0c67e3 282 layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
bcostm 0:c9112f0c67e3 283 layer_cfg.FBStartAdress = FB_Address;
bcostm 0:c9112f0c67e3 284 layer_cfg.Alpha = 255;
bcostm 0:c9112f0c67e3 285 layer_cfg.Alpha0 = 0;
bcostm 0:c9112f0c67e3 286 layer_cfg.Backcolor.Blue = 0;
bcostm 0:c9112f0c67e3 287 layer_cfg.Backcolor.Green = 0;
bcostm 0:c9112f0c67e3 288 layer_cfg.Backcolor.Red = 0;
bcostm 0:c9112f0c67e3 289 layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
bcostm 0:c9112f0c67e3 290 layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
bcostm 0:c9112f0c67e3 291 layer_cfg.ImageWidth = BSP_LCD_GetXSize();
bcostm 0:c9112f0c67e3 292 layer_cfg.ImageHeight = BSP_LCD_GetYSize();
bcostm 0:c9112f0c67e3 293
bcostm 0:c9112f0c67e3 294 HAL_LTDC_ConfigLayer(&hLtdcHandler, &layer_cfg, LayerIndex);
bcostm 0:c9112f0c67e3 295
bcostm 0:c9112f0c67e3 296 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
bcostm 0:c9112f0c67e3 297 DrawProp[LayerIndex].pFont = &Font24;
bcostm 0:c9112f0c67e3 298 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
bcostm 0:c9112f0c67e3 299 }
bcostm 0:c9112f0c67e3 300
bcostm 0:c9112f0c67e3 301 /**
bcostm 0:c9112f0c67e3 302 * @brief Initializes the LCD layer in RGB565 format (16 bits per pixel).
bcostm 0:c9112f0c67e3 303 * @param LayerIndex: Layer foreground or background
bcostm 0:c9112f0c67e3 304 * @param FB_Address: Layer frame buffer
bcostm 0:c9112f0c67e3 305 * @retval None
bcostm 0:c9112f0c67e3 306 */
bcostm 0:c9112f0c67e3 307 void BSP_LCD_LayerRgb565Init(uint16_t LayerIndex, uint32_t FB_Address)
bcostm 0:c9112f0c67e3 308 {
bcostm 0:c9112f0c67e3 309 LCD_LayerCfgTypeDef layer_cfg;
bcostm 0:c9112f0c67e3 310
bcostm 0:c9112f0c67e3 311 /* Layer Init */
bcostm 0:c9112f0c67e3 312 layer_cfg.WindowX0 = 0;
bcostm 0:c9112f0c67e3 313 layer_cfg.WindowX1 = BSP_LCD_GetXSize();
bcostm 0:c9112f0c67e3 314 layer_cfg.WindowY0 = 0;
bcostm 0:c9112f0c67e3 315 layer_cfg.WindowY1 = BSP_LCD_GetYSize();
bcostm 0:c9112f0c67e3 316 layer_cfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;
bcostm 0:c9112f0c67e3 317 layer_cfg.FBStartAdress = FB_Address;
bcostm 0:c9112f0c67e3 318 layer_cfg.Alpha = 255;
bcostm 0:c9112f0c67e3 319 layer_cfg.Alpha0 = 0;
bcostm 0:c9112f0c67e3 320 layer_cfg.Backcolor.Blue = 0;
bcostm 0:c9112f0c67e3 321 layer_cfg.Backcolor.Green = 0;
bcostm 0:c9112f0c67e3 322 layer_cfg.Backcolor.Red = 0;
bcostm 0:c9112f0c67e3 323 layer_cfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
bcostm 0:c9112f0c67e3 324 layer_cfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
bcostm 0:c9112f0c67e3 325 layer_cfg.ImageWidth = BSP_LCD_GetXSize();
bcostm 0:c9112f0c67e3 326 layer_cfg.ImageHeight = BSP_LCD_GetYSize();
bcostm 0:c9112f0c67e3 327
bcostm 0:c9112f0c67e3 328 HAL_LTDC_ConfigLayer(&hLtdcHandler, &layer_cfg, LayerIndex);
bcostm 0:c9112f0c67e3 329
bcostm 0:c9112f0c67e3 330 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
bcostm 0:c9112f0c67e3 331 DrawProp[LayerIndex].pFont = &Font24;
bcostm 0:c9112f0c67e3 332 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
bcostm 0:c9112f0c67e3 333 }
bcostm 0:c9112f0c67e3 334
bcostm 0:c9112f0c67e3 335 /**
bcostm 0:c9112f0c67e3 336 * @brief Selects the LCD Layer.
bcostm 0:c9112f0c67e3 337 * @param LayerIndex: Layer foreground or background
bcostm 0:c9112f0c67e3 338 * @retval None
bcostm 0:c9112f0c67e3 339 */
bcostm 0:c9112f0c67e3 340 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
bcostm 0:c9112f0c67e3 341 {
bcostm 0:c9112f0c67e3 342 ActiveLayer = LayerIndex;
bcostm 0:c9112f0c67e3 343 }
bcostm 0:c9112f0c67e3 344
bcostm 0:c9112f0c67e3 345 /**
bcostm 0:c9112f0c67e3 346 * @brief Sets an LCD Layer visible
bcostm 0:c9112f0c67e3 347 * @param LayerIndex: Visible Layer
bcostm 0:c9112f0c67e3 348 * @param State: New state of the specified layer
bcostm 0:c9112f0c67e3 349 * This parameter can be one of the following values:
bcostm 0:c9112f0c67e3 350 * @arg ENABLE
bcostm 0:c9112f0c67e3 351 * @arg DISABLE
bcostm 0:c9112f0c67e3 352 * @retval None
bcostm 0:c9112f0c67e3 353 */
bcostm 0:c9112f0c67e3 354 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
bcostm 0:c9112f0c67e3 355 {
bcostm 0:c9112f0c67e3 356 if(State == ENABLE)
bcostm 0:c9112f0c67e3 357 {
bcostm 0:c9112f0c67e3 358 __HAL_LTDC_LAYER_ENABLE(&hLtdcHandler, LayerIndex);
bcostm 0:c9112f0c67e3 359 }
bcostm 0:c9112f0c67e3 360 else
bcostm 0:c9112f0c67e3 361 {
bcostm 0:c9112f0c67e3 362 __HAL_LTDC_LAYER_DISABLE(&hLtdcHandler, LayerIndex);
bcostm 0:c9112f0c67e3 363 }
bcostm 0:c9112f0c67e3 364 __HAL_LTDC_RELOAD_CONFIG(&hLtdcHandler);
bcostm 0:c9112f0c67e3 365 }
bcostm 0:c9112f0c67e3 366
bcostm 0:c9112f0c67e3 367 /**
bcostm 0:c9112f0c67e3 368 * @brief Configures the transparency.
bcostm 0:c9112f0c67e3 369 * @param LayerIndex: Layer foreground or background.
bcostm 0:c9112f0c67e3 370 * @param Transparency: Transparency
bcostm 0:c9112f0c67e3 371 * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
bcostm 0:c9112f0c67e3 372 * @retval None
bcostm 0:c9112f0c67e3 373 */
bcostm 0:c9112f0c67e3 374 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
bcostm 0:c9112f0c67e3 375 {
bcostm 0:c9112f0c67e3 376 HAL_LTDC_SetAlpha(&hLtdcHandler, Transparency, LayerIndex);
bcostm 0:c9112f0c67e3 377 }
bcostm 0:c9112f0c67e3 378
bcostm 0:c9112f0c67e3 379 /**
bcostm 0:c9112f0c67e3 380 * @brief Sets an LCD layer frame buffer address.
bcostm 0:c9112f0c67e3 381 * @param LayerIndex: Layer foreground or background
bcostm 0:c9112f0c67e3 382 * @param Address: New LCD frame buffer value
bcostm 0:c9112f0c67e3 383 * @retval None
bcostm 0:c9112f0c67e3 384 */
bcostm 0:c9112f0c67e3 385 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
bcostm 0:c9112f0c67e3 386 {
bcostm 0:c9112f0c67e3 387 HAL_LTDC_SetAddress(&hLtdcHandler, Address, LayerIndex);
bcostm 0:c9112f0c67e3 388 }
bcostm 0:c9112f0c67e3 389
bcostm 0:c9112f0c67e3 390 /**
bcostm 0:c9112f0c67e3 391 * @brief Sets display window.
bcostm 0:c9112f0c67e3 392 * @param LayerIndex: Layer index
bcostm 0:c9112f0c67e3 393 * @param Xpos: LCD X position
bcostm 0:c9112f0c67e3 394 * @param Ypos: LCD Y position
bcostm 0:c9112f0c67e3 395 * @param Width: LCD window width
bcostm 0:c9112f0c67e3 396 * @param Height: LCD window height
bcostm 0:c9112f0c67e3 397 * @retval None
bcostm 0:c9112f0c67e3 398 */
bcostm 0:c9112f0c67e3 399 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
bcostm 0:c9112f0c67e3 400 {
bcostm 0:c9112f0c67e3 401 /* Reconfigure the layer size */
bcostm 0:c9112f0c67e3 402 HAL_LTDC_SetWindowSize(&hLtdcHandler, Width, Height, LayerIndex);
bcostm 0:c9112f0c67e3 403
bcostm 0:c9112f0c67e3 404 /* Reconfigure the layer position */
bcostm 0:c9112f0c67e3 405 HAL_LTDC_SetWindowPosition(&hLtdcHandler, Xpos, Ypos, LayerIndex);
bcostm 0:c9112f0c67e3 406 }
bcostm 0:c9112f0c67e3 407
bcostm 0:c9112f0c67e3 408 /**
bcostm 0:c9112f0c67e3 409 * @brief Configures and sets the color keying.
bcostm 0:c9112f0c67e3 410 * @param LayerIndex: Layer foreground or background
bcostm 0:c9112f0c67e3 411 * @param RGBValue: Color reference
bcostm 0:c9112f0c67e3 412 * @retval None
bcostm 0:c9112f0c67e3 413 */
bcostm 0:c9112f0c67e3 414 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
bcostm 0:c9112f0c67e3 415 {
bcostm 0:c9112f0c67e3 416 /* Configure and Enable the color Keying for LCD Layer */
bcostm 0:c9112f0c67e3 417 HAL_LTDC_ConfigColorKeying(&hLtdcHandler, RGBValue, LayerIndex);
bcostm 0:c9112f0c67e3 418 HAL_LTDC_EnableColorKeying(&hLtdcHandler, LayerIndex);
bcostm 0:c9112f0c67e3 419 }
bcostm 0:c9112f0c67e3 420
bcostm 0:c9112f0c67e3 421 /**
bcostm 0:c9112f0c67e3 422 * @brief Disables the color keying.
bcostm 0:c9112f0c67e3 423 * @param LayerIndex: Layer foreground or background
bcostm 0:c9112f0c67e3 424 * @retval None
bcostm 0:c9112f0c67e3 425 */
bcostm 0:c9112f0c67e3 426 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
bcostm 0:c9112f0c67e3 427 {
bcostm 0:c9112f0c67e3 428 /* Disable the color Keying for LCD Layer */
bcostm 0:c9112f0c67e3 429 HAL_LTDC_DisableColorKeying(&hLtdcHandler, LayerIndex);
bcostm 0:c9112f0c67e3 430 }
bcostm 0:c9112f0c67e3 431
bcostm 0:c9112f0c67e3 432 /**
bcostm 0:c9112f0c67e3 433 * @brief Sets the LCD text color.
bcostm 0:c9112f0c67e3 434 * @param Color: Text color code ARGB(8-8-8-8)
bcostm 0:c9112f0c67e3 435 * @retval None
bcostm 0:c9112f0c67e3 436 */
bcostm 0:c9112f0c67e3 437 void BSP_LCD_SetTextColor(uint32_t Color)
bcostm 0:c9112f0c67e3 438 {
bcostm 0:c9112f0c67e3 439 DrawProp[ActiveLayer].TextColor = Color;
bcostm 0:c9112f0c67e3 440 }
bcostm 0:c9112f0c67e3 441
bcostm 0:c9112f0c67e3 442 /**
bcostm 0:c9112f0c67e3 443 * @brief Gets the LCD text color.
bcostm 0:c9112f0c67e3 444 * @retval Used text color.
bcostm 0:c9112f0c67e3 445 */
bcostm 0:c9112f0c67e3 446 uint32_t BSP_LCD_GetTextColor(void)
bcostm 0:c9112f0c67e3 447 {
bcostm 0:c9112f0c67e3 448 return DrawProp[ActiveLayer].TextColor;
bcostm 0:c9112f0c67e3 449 }
bcostm 0:c9112f0c67e3 450
bcostm 0:c9112f0c67e3 451 /**
bcostm 0:c9112f0c67e3 452 * @brief Sets the LCD background color.
bcostm 0:c9112f0c67e3 453 * @param Color: Layer background color code ARGB(8-8-8-8)
bcostm 0:c9112f0c67e3 454 * @retval None
bcostm 0:c9112f0c67e3 455 */
bcostm 0:c9112f0c67e3 456 void BSP_LCD_SetBackColor(uint32_t Color)
bcostm 0:c9112f0c67e3 457 {
bcostm 0:c9112f0c67e3 458 DrawProp[ActiveLayer].BackColor = Color;
bcostm 0:c9112f0c67e3 459 }
bcostm 0:c9112f0c67e3 460
bcostm 0:c9112f0c67e3 461 /**
bcostm 0:c9112f0c67e3 462 * @brief Gets the LCD background color.
bcostm 0:c9112f0c67e3 463 * @retval Used background colour
bcostm 0:c9112f0c67e3 464 */
bcostm 0:c9112f0c67e3 465 uint32_t BSP_LCD_GetBackColor(void)
bcostm 0:c9112f0c67e3 466 {
bcostm 0:c9112f0c67e3 467 return DrawProp[ActiveLayer].BackColor;
bcostm 0:c9112f0c67e3 468 }
bcostm 0:c9112f0c67e3 469
bcostm 0:c9112f0c67e3 470 /**
bcostm 0:c9112f0c67e3 471 * @brief Sets the LCD text font.
bcostm 0:c9112f0c67e3 472 * @param fonts: Layer font to be used
bcostm 0:c9112f0c67e3 473 * @retval None
bcostm 0:c9112f0c67e3 474 */
bcostm 0:c9112f0c67e3 475 void BSP_LCD_SetFont(sFONT *fonts)
bcostm 0:c9112f0c67e3 476 {
bcostm 0:c9112f0c67e3 477 DrawProp[ActiveLayer].pFont = fonts;
bcostm 0:c9112f0c67e3 478 }
bcostm 0:c9112f0c67e3 479
bcostm 0:c9112f0c67e3 480 /**
bcostm 0:c9112f0c67e3 481 * @brief Gets the LCD text font.
bcostm 0:c9112f0c67e3 482 * @retval Used layer font
bcostm 0:c9112f0c67e3 483 */
bcostm 0:c9112f0c67e3 484 sFONT *BSP_LCD_GetFont(void)
bcostm 0:c9112f0c67e3 485 {
bcostm 0:c9112f0c67e3 486 return DrawProp[ActiveLayer].pFont;
bcostm 0:c9112f0c67e3 487 }
bcostm 0:c9112f0c67e3 488
bcostm 0:c9112f0c67e3 489 /**
bcostm 0:c9112f0c67e3 490 * @brief Reads an LCD pixel.
bcostm 0:c9112f0c67e3 491 * @param Xpos: X position
bcostm 0:c9112f0c67e3 492 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 493 * @retval RGB pixel color
bcostm 0:c9112f0c67e3 494 */
bcostm 0:c9112f0c67e3 495 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
bcostm 0:c9112f0c67e3 496 {
bcostm 0:c9112f0c67e3 497 uint32_t ret = 0;
bcostm 0:c9112f0c67e3 498
bcostm 0:c9112f0c67e3 499 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
bcostm 0:c9112f0c67e3 500 {
bcostm 0:c9112f0c67e3 501 /* Read data value from SDRAM memory */
bcostm 0:c9112f0c67e3 502 ret = *(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
bcostm 0:c9112f0c67e3 503 }
bcostm 0:c9112f0c67e3 504 else if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
bcostm 0:c9112f0c67e3 505 {
bcostm 0:c9112f0c67e3 506 /* Read data value from SDRAM memory */
bcostm 0:c9112f0c67e3 507 ret = (*(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
bcostm 0:c9112f0c67e3 508 }
bcostm 0:c9112f0c67e3 509 else if((hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
bcostm 0:c9112f0c67e3 510 (hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
bcostm 0:c9112f0c67e3 511 (hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
bcostm 0:c9112f0c67e3 512 {
bcostm 0:c9112f0c67e3 513 /* Read data value from SDRAM memory */
bcostm 0:c9112f0c67e3 514 ret = *(__IO uint16_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
bcostm 0:c9112f0c67e3 515 }
bcostm 0:c9112f0c67e3 516 else
bcostm 0:c9112f0c67e3 517 {
bcostm 0:c9112f0c67e3 518 /* Read data value from SDRAM memory */
bcostm 0:c9112f0c67e3 519 ret = *(__IO uint8_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
bcostm 0:c9112f0c67e3 520 }
bcostm 0:c9112f0c67e3 521
bcostm 0:c9112f0c67e3 522 return ret;
bcostm 0:c9112f0c67e3 523 }
bcostm 0:c9112f0c67e3 524
bcostm 0:c9112f0c67e3 525 /**
bcostm 0:c9112f0c67e3 526 * @brief Clears the hole LCD.
bcostm 0:c9112f0c67e3 527 * @param Color: Color of the background
bcostm 0:c9112f0c67e3 528 * @retval None
bcostm 0:c9112f0c67e3 529 */
bcostm 0:c9112f0c67e3 530 void BSP_LCD_Clear(uint32_t Color)
bcostm 0:c9112f0c67e3 531 {
bcostm 0:c9112f0c67e3 532 /* Clear the LCD */
bcostm 0:c9112f0c67e3 533 LL_FillBuffer(ActiveLayer, (uint32_t *)(hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
bcostm 0:c9112f0c67e3 534 }
bcostm 0:c9112f0c67e3 535
bcostm 0:c9112f0c67e3 536 /**
bcostm 0:c9112f0c67e3 537 * @brief Clears the selected line.
bcostm 0:c9112f0c67e3 538 * @param Line: Line to be cleared
bcostm 0:c9112f0c67e3 539 * @retval None
bcostm 0:c9112f0c67e3 540 */
bcostm 0:c9112f0c67e3 541 void BSP_LCD_ClearStringLine(uint32_t Line)
bcostm 0:c9112f0c67e3 542 {
bcostm 0:c9112f0c67e3 543 uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
bcostm 0:c9112f0c67e3 544 DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
bcostm 0:c9112f0c67e3 545
bcostm 0:c9112f0c67e3 546 /* Draw rectangle with background color */
bcostm 0:c9112f0c67e3 547 BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
bcostm 0:c9112f0c67e3 548
bcostm 0:c9112f0c67e3 549 DrawProp[ActiveLayer].TextColor = color_backup;
bcostm 0:c9112f0c67e3 550 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 551 }
bcostm 0:c9112f0c67e3 552
bcostm 0:c9112f0c67e3 553 /**
bcostm 0:c9112f0c67e3 554 * @brief Displays one character.
bcostm 0:c9112f0c67e3 555 * @param Xpos: Start column address
bcostm 0:c9112f0c67e3 556 * @param Ypos: Line where to display the character shape.
bcostm 0:c9112f0c67e3 557 * @param Ascii: Character ascii code
bcostm 0:c9112f0c67e3 558 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
bcostm 0:c9112f0c67e3 559 * @retval None
bcostm 0:c9112f0c67e3 560 */
bcostm 0:c9112f0c67e3 561 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
bcostm 0:c9112f0c67e3 562 {
bcostm 0:c9112f0c67e3 563 DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
bcostm 0:c9112f0c67e3 564 DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
bcostm 0:c9112f0c67e3 565 }
bcostm 0:c9112f0c67e3 566
bcostm 0:c9112f0c67e3 567 /**
bcostm 0:c9112f0c67e3 568 * @brief Displays characters on the LCD.
bcostm 0:c9112f0c67e3 569 * @param Xpos: X position (in pixel)
bcostm 0:c9112f0c67e3 570 * @param Ypos: Y position (in pixel)
bcostm 0:c9112f0c67e3 571 * @param Text: Pointer to string to display on LCD
bcostm 0:c9112f0c67e3 572 * @param Mode: Display mode
bcostm 0:c9112f0c67e3 573 * This parameter can be one of the following values:
bcostm 0:c9112f0c67e3 574 * @arg CENTER_MODE
bcostm 0:c9112f0c67e3 575 * @arg RIGHT_MODE
bcostm 0:c9112f0c67e3 576 * @arg LEFT_MODE
bcostm 0:c9112f0c67e3 577 * @retval None
bcostm 0:c9112f0c67e3 578 */
bcostm 0:c9112f0c67e3 579 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
bcostm 0:c9112f0c67e3 580 {
bcostm 0:c9112f0c67e3 581 uint16_t ref_column = 1, i = 0;
bcostm 0:c9112f0c67e3 582 uint32_t size = 0, xsize = 0;
bcostm 0:c9112f0c67e3 583 uint8_t *ptr = Text;
bcostm 0:c9112f0c67e3 584
bcostm 0:c9112f0c67e3 585 /* Get the text size */
bcostm 0:c9112f0c67e3 586 while (*ptr++) size ++ ;
bcostm 0:c9112f0c67e3 587
bcostm 0:c9112f0c67e3 588 /* Characters number per line */
bcostm 0:c9112f0c67e3 589 xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
bcostm 0:c9112f0c67e3 590
bcostm 0:c9112f0c67e3 591 switch (Mode)
bcostm 0:c9112f0c67e3 592 {
bcostm 0:c9112f0c67e3 593 case CENTER_MODE:
bcostm 0:c9112f0c67e3 594 {
bcostm 0:c9112f0c67e3 595 ref_column = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
bcostm 0:c9112f0c67e3 596 break;
bcostm 0:c9112f0c67e3 597 }
bcostm 0:c9112f0c67e3 598 case LEFT_MODE:
bcostm 0:c9112f0c67e3 599 {
bcostm 0:c9112f0c67e3 600 ref_column = Xpos;
bcostm 0:c9112f0c67e3 601 break;
bcostm 0:c9112f0c67e3 602 }
bcostm 0:c9112f0c67e3 603 case RIGHT_MODE:
bcostm 0:c9112f0c67e3 604 {
bcostm 0:c9112f0c67e3 605 ref_column = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
bcostm 0:c9112f0c67e3 606 break;
bcostm 0:c9112f0c67e3 607 }
bcostm 0:c9112f0c67e3 608 default:
bcostm 0:c9112f0c67e3 609 {
bcostm 0:c9112f0c67e3 610 ref_column = Xpos;
bcostm 0:c9112f0c67e3 611 break;
bcostm 0:c9112f0c67e3 612 }
bcostm 0:c9112f0c67e3 613 }
bcostm 0:c9112f0c67e3 614
bcostm 0:c9112f0c67e3 615 /* Check that the Start column is located in the screen */
bcostm 0:c9112f0c67e3 616 if ((ref_column < 1) || (ref_column >= 0x8000))
bcostm 0:c9112f0c67e3 617 {
bcostm 0:c9112f0c67e3 618 ref_column = 1;
bcostm 0:c9112f0c67e3 619 }
bcostm 0:c9112f0c67e3 620
bcostm 0:c9112f0c67e3 621 /* Send the string character by character on LCD */
bcostm 0:c9112f0c67e3 622 while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
bcostm 0:c9112f0c67e3 623 {
bcostm 0:c9112f0c67e3 624 /* Display one character on LCD */
bcostm 0:c9112f0c67e3 625 BSP_LCD_DisplayChar(ref_column, Ypos, *Text);
bcostm 0:c9112f0c67e3 626 /* Decrement the column position by 16 */
bcostm 0:c9112f0c67e3 627 ref_column += DrawProp[ActiveLayer].pFont->Width;
bcostm 0:c9112f0c67e3 628 /* Point on the next character */
bcostm 0:c9112f0c67e3 629 Text++;
bcostm 0:c9112f0c67e3 630 i++;
bcostm 0:c9112f0c67e3 631 }
bcostm 0:c9112f0c67e3 632 }
bcostm 0:c9112f0c67e3 633
bcostm 0:c9112f0c67e3 634 /**
bcostm 0:c9112f0c67e3 635 * @brief Displays a maximum of 60 characters on the LCD.
bcostm 0:c9112f0c67e3 636 * @param Line: Line where to display the character shape
bcostm 0:c9112f0c67e3 637 * @param ptr: Pointer to string to display on LCD
bcostm 0:c9112f0c67e3 638 * @retval None
bcostm 0:c9112f0c67e3 639 */
bcostm 0:c9112f0c67e3 640 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
bcostm 0:c9112f0c67e3 641 {
bcostm 0:c9112f0c67e3 642 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
bcostm 0:c9112f0c67e3 643 }
bcostm 0:c9112f0c67e3 644
bcostm 0:c9112f0c67e3 645 /**
bcostm 0:c9112f0c67e3 646 * @brief Draws an horizontal line.
bcostm 0:c9112f0c67e3 647 * @param Xpos: X position
bcostm 0:c9112f0c67e3 648 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 649 * @param Length: Line length
bcostm 0:c9112f0c67e3 650 * @retval None
bcostm 0:c9112f0c67e3 651 */
bcostm 0:c9112f0c67e3 652 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bcostm 0:c9112f0c67e3 653 {
bcostm 0:c9112f0c67e3 654 uint32_t Xaddress = 0;
bcostm 0:c9112f0c67e3 655
bcostm 0:c9112f0c67e3 656 /* Get the line address */
bcostm 0:c9112f0c67e3 657 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565)
bcostm 0:c9112f0c67e3 658 { /* RGB565 format */
bcostm 0:c9112f0c67e3 659 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos);
bcostm 0:c9112f0c67e3 660 }
bcostm 0:c9112f0c67e3 661 else
bcostm 0:c9112f0c67e3 662 { /* ARGB8888 format */
bcostm 0:c9112f0c67e3 663 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
bcostm 0:c9112f0c67e3 664 }
bcostm 0:c9112f0c67e3 665
bcostm 0:c9112f0c67e3 666 /* Write line */
bcostm 0:c9112f0c67e3 667 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 668 }
bcostm 0:c9112f0c67e3 669
bcostm 0:c9112f0c67e3 670 /**
bcostm 0:c9112f0c67e3 671 * @brief Draws a vertical line.
bcostm 0:c9112f0c67e3 672 * @param Xpos: X position
bcostm 0:c9112f0c67e3 673 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 674 * @param Length: Line length
bcostm 0:c9112f0c67e3 675 * @retval None
bcostm 0:c9112f0c67e3 676 */
bcostm 0:c9112f0c67e3 677 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bcostm 0:c9112f0c67e3 678 {
bcostm 0:c9112f0c67e3 679 uint32_t Xaddress = 0;
bcostm 0:c9112f0c67e3 680
bcostm 0:c9112f0c67e3 681 /* Get the line address */
bcostm 0:c9112f0c67e3 682 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565)
bcostm 0:c9112f0c67e3 683 { /* RGB565 format */
bcostm 0:c9112f0c67e3 684 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos);
bcostm 0:c9112f0c67e3 685 }
bcostm 0:c9112f0c67e3 686 else
bcostm 0:c9112f0c67e3 687 { /* ARGB8888 format */
bcostm 0:c9112f0c67e3 688 Xaddress = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
bcostm 0:c9112f0c67e3 689 }
bcostm 0:c9112f0c67e3 690
bcostm 0:c9112f0c67e3 691 /* Write line */
bcostm 0:c9112f0c67e3 692 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 693 }
bcostm 0:c9112f0c67e3 694
bcostm 0:c9112f0c67e3 695 /**
bcostm 0:c9112f0c67e3 696 * @brief Draws an uni-line (between two points).
bcostm 0:c9112f0c67e3 697 * @param x1: Point 1 X position
bcostm 0:c9112f0c67e3 698 * @param y1: Point 1 Y position
bcostm 0:c9112f0c67e3 699 * @param x2: Point 2 X position
bcostm 0:c9112f0c67e3 700 * @param y2: Point 2 Y position
bcostm 0:c9112f0c67e3 701 * @retval None
bcostm 0:c9112f0c67e3 702 */
bcostm 0:c9112f0c67e3 703 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
bcostm 0:c9112f0c67e3 704 {
bcostm 0:c9112f0c67e3 705 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
bcostm 0:c9112f0c67e3 706 yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
bcostm 0:c9112f0c67e3 707 curpixel = 0;
bcostm 0:c9112f0c67e3 708
bcostm 0:c9112f0c67e3 709 deltax = ABS(x2 - x1); /* The difference between the x's */
bcostm 0:c9112f0c67e3 710 deltay = ABS(y2 - y1); /* The difference between the y's */
bcostm 0:c9112f0c67e3 711 x = x1; /* Start x off at the first pixel */
bcostm 0:c9112f0c67e3 712 y = y1; /* Start y off at the first pixel */
bcostm 0:c9112f0c67e3 713
bcostm 0:c9112f0c67e3 714 if (x2 >= x1) /* The x-values are increasing */
bcostm 0:c9112f0c67e3 715 {
bcostm 0:c9112f0c67e3 716 xinc1 = 1;
bcostm 0:c9112f0c67e3 717 xinc2 = 1;
bcostm 0:c9112f0c67e3 718 }
bcostm 0:c9112f0c67e3 719 else /* The x-values are decreasing */
bcostm 0:c9112f0c67e3 720 {
bcostm 0:c9112f0c67e3 721 xinc1 = -1;
bcostm 0:c9112f0c67e3 722 xinc2 = -1;
bcostm 0:c9112f0c67e3 723 }
bcostm 0:c9112f0c67e3 724
bcostm 0:c9112f0c67e3 725 if (y2 >= y1) /* The y-values are increasing */
bcostm 0:c9112f0c67e3 726 {
bcostm 0:c9112f0c67e3 727 yinc1 = 1;
bcostm 0:c9112f0c67e3 728 yinc2 = 1;
bcostm 0:c9112f0c67e3 729 }
bcostm 0:c9112f0c67e3 730 else /* The y-values are decreasing */
bcostm 0:c9112f0c67e3 731 {
bcostm 0:c9112f0c67e3 732 yinc1 = -1;
bcostm 0:c9112f0c67e3 733 yinc2 = -1;
bcostm 0:c9112f0c67e3 734 }
bcostm 0:c9112f0c67e3 735
bcostm 0:c9112f0c67e3 736 if (deltax >= deltay) /* There is at least one x-value for every y-value */
bcostm 0:c9112f0c67e3 737 {
bcostm 0:c9112f0c67e3 738 xinc1 = 0; /* Don't change the x when numerator >= denominator */
bcostm 0:c9112f0c67e3 739 yinc2 = 0; /* Don't change the y for every iteration */
bcostm 0:c9112f0c67e3 740 den = deltax;
bcostm 0:c9112f0c67e3 741 num = deltax / 2;
bcostm 0:c9112f0c67e3 742 num_add = deltay;
bcostm 0:c9112f0c67e3 743 num_pixels = deltax; /* There are more x-values than y-values */
bcostm 0:c9112f0c67e3 744 }
bcostm 0:c9112f0c67e3 745 else /* There is at least one y-value for every x-value */
bcostm 0:c9112f0c67e3 746 {
bcostm 0:c9112f0c67e3 747 xinc2 = 0; /* Don't change the x for every iteration */
bcostm 0:c9112f0c67e3 748 yinc1 = 0; /* Don't change the y when numerator >= denominator */
bcostm 0:c9112f0c67e3 749 den = deltay;
bcostm 0:c9112f0c67e3 750 num = deltay / 2;
bcostm 0:c9112f0c67e3 751 num_add = deltax;
bcostm 0:c9112f0c67e3 752 num_pixels = deltay; /* There are more y-values than x-values */
bcostm 0:c9112f0c67e3 753 }
bcostm 0:c9112f0c67e3 754
bcostm 0:c9112f0c67e3 755 for (curpixel = 0; curpixel <= num_pixels; curpixel++)
bcostm 0:c9112f0c67e3 756 {
bcostm 0:c9112f0c67e3 757 BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */
bcostm 0:c9112f0c67e3 758 num += num_add; /* Increase the numerator by the top of the fraction */
bcostm 0:c9112f0c67e3 759 if (num >= den) /* Check if numerator >= denominator */
bcostm 0:c9112f0c67e3 760 {
bcostm 0:c9112f0c67e3 761 num -= den; /* Calculate the new numerator value */
bcostm 0:c9112f0c67e3 762 x += xinc1; /* Change the x as appropriate */
bcostm 0:c9112f0c67e3 763 y += yinc1; /* Change the y as appropriate */
bcostm 0:c9112f0c67e3 764 }
bcostm 0:c9112f0c67e3 765 x += xinc2; /* Change the x as appropriate */
bcostm 0:c9112f0c67e3 766 y += yinc2; /* Change the y as appropriate */
bcostm 0:c9112f0c67e3 767 }
bcostm 0:c9112f0c67e3 768 }
bcostm 0:c9112f0c67e3 769
bcostm 0:c9112f0c67e3 770 /**
bcostm 0:c9112f0c67e3 771 * @brief Draws a rectangle.
bcostm 0:c9112f0c67e3 772 * @param Xpos: X position
bcostm 0:c9112f0c67e3 773 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 774 * @param Width: Rectangle width
bcostm 0:c9112f0c67e3 775 * @param Height: Rectangle height
bcostm 0:c9112f0c67e3 776 * @retval None
bcostm 0:c9112f0c67e3 777 */
bcostm 0:c9112f0c67e3 778 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
bcostm 0:c9112f0c67e3 779 {
bcostm 0:c9112f0c67e3 780 /* Draw horizontal lines */
bcostm 0:c9112f0c67e3 781 BSP_LCD_DrawHLine(Xpos, Ypos, Width);
bcostm 0:c9112f0c67e3 782 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
bcostm 0:c9112f0c67e3 783
bcostm 0:c9112f0c67e3 784 /* Draw vertical lines */
bcostm 0:c9112f0c67e3 785 BSP_LCD_DrawVLine(Xpos, Ypos, Height);
bcostm 0:c9112f0c67e3 786 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
bcostm 0:c9112f0c67e3 787 }
bcostm 0:c9112f0c67e3 788
bcostm 0:c9112f0c67e3 789 /**
bcostm 0:c9112f0c67e3 790 * @brief Draws a circle.
bcostm 0:c9112f0c67e3 791 * @param Xpos: X position
bcostm 0:c9112f0c67e3 792 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 793 * @param Radius: Circle radius
bcostm 0:c9112f0c67e3 794 * @retval None
bcostm 0:c9112f0c67e3 795 */
bcostm 0:c9112f0c67e3 796 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
bcostm 0:c9112f0c67e3 797 {
bcostm 0:c9112f0c67e3 798 int32_t decision; /* Decision Variable */
bcostm 0:c9112f0c67e3 799 uint32_t current_x; /* Current X Value */
bcostm 0:c9112f0c67e3 800 uint32_t current_y; /* Current Y Value */
bcostm 0:c9112f0c67e3 801
bcostm 0:c9112f0c67e3 802 decision = 3 - (Radius << 1);
bcostm 0:c9112f0c67e3 803 current_x = 0;
bcostm 0:c9112f0c67e3 804 current_y = Radius;
bcostm 0:c9112f0c67e3 805
bcostm 0:c9112f0c67e3 806 while (current_x <= current_y)
bcostm 0:c9112f0c67e3 807 {
bcostm 0:c9112f0c67e3 808 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos - current_y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 809
bcostm 0:c9112f0c67e3 810 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos - current_y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 811
bcostm 0:c9112f0c67e3 812 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos - current_x), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 813
bcostm 0:c9112f0c67e3 814 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos - current_x), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 815
bcostm 0:c9112f0c67e3 816 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos + current_y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 817
bcostm 0:c9112f0c67e3 818 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos + current_y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 819
bcostm 0:c9112f0c67e3 820 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos + current_x), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 821
bcostm 0:c9112f0c67e3 822 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos + current_x), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 823
bcostm 0:c9112f0c67e3 824 if (decision < 0)
bcostm 0:c9112f0c67e3 825 {
bcostm 0:c9112f0c67e3 826 decision += (current_x << 2) + 6;
bcostm 0:c9112f0c67e3 827 }
bcostm 0:c9112f0c67e3 828 else
bcostm 0:c9112f0c67e3 829 {
bcostm 0:c9112f0c67e3 830 decision += ((current_x - current_y) << 2) + 10;
bcostm 0:c9112f0c67e3 831 current_y--;
bcostm 0:c9112f0c67e3 832 }
bcostm 0:c9112f0c67e3 833 current_x++;
bcostm 0:c9112f0c67e3 834 }
bcostm 0:c9112f0c67e3 835 }
bcostm 0:c9112f0c67e3 836
bcostm 0:c9112f0c67e3 837 /**
bcostm 0:c9112f0c67e3 838 * @brief Draws an poly-line (between many points).
bcostm 0:c9112f0c67e3 839 * @param Points: Pointer to the points array
bcostm 0:c9112f0c67e3 840 * @param PointCount: Number of points
bcostm 0:c9112f0c67e3 841 * @retval None
bcostm 0:c9112f0c67e3 842 */
bcostm 0:c9112f0c67e3 843 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
bcostm 0:c9112f0c67e3 844 {
bcostm 0:c9112f0c67e3 845 int16_t x = 0, y = 0;
bcostm 0:c9112f0c67e3 846
bcostm 0:c9112f0c67e3 847 if(PointCount < 2)
bcostm 0:c9112f0c67e3 848 {
bcostm 0:c9112f0c67e3 849 return;
bcostm 0:c9112f0c67e3 850 }
bcostm 0:c9112f0c67e3 851
bcostm 0:c9112f0c67e3 852 BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
bcostm 0:c9112f0c67e3 853
bcostm 0:c9112f0c67e3 854 while(--PointCount)
bcostm 0:c9112f0c67e3 855 {
bcostm 0:c9112f0c67e3 856 x = Points->X;
bcostm 0:c9112f0c67e3 857 y = Points->Y;
bcostm 0:c9112f0c67e3 858 Points++;
bcostm 0:c9112f0c67e3 859 BSP_LCD_DrawLine(x, y, Points->X, Points->Y);
bcostm 0:c9112f0c67e3 860 }
bcostm 0:c9112f0c67e3 861 }
bcostm 0:c9112f0c67e3 862
bcostm 0:c9112f0c67e3 863 /**
bcostm 0:c9112f0c67e3 864 * @brief Draws an ellipse on LCD.
bcostm 0:c9112f0c67e3 865 * @param Xpos: X position
bcostm 0:c9112f0c67e3 866 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 867 * @param XRadius: Ellipse X radius
bcostm 0:c9112f0c67e3 868 * @param YRadius: Ellipse Y radius
bcostm 0:c9112f0c67e3 869 * @retval None
bcostm 0:c9112f0c67e3 870 */
bcostm 0:c9112f0c67e3 871 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
bcostm 0:c9112f0c67e3 872 {
bcostm 0:c9112f0c67e3 873 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
bcostm 0:c9112f0c67e3 874 float k = 0, rad1 = 0, rad2 = 0;
bcostm 0:c9112f0c67e3 875
bcostm 0:c9112f0c67e3 876 rad1 = XRadius;
bcostm 0:c9112f0c67e3 877 rad2 = YRadius;
bcostm 0:c9112f0c67e3 878
bcostm 0:c9112f0c67e3 879 k = (float)(rad2/rad1);
bcostm 0:c9112f0c67e3 880
bcostm 0:c9112f0c67e3 881 do {
bcostm 0:c9112f0c67e3 882 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 883 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 884 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 885 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 886
bcostm 0:c9112f0c67e3 887 e2 = err;
bcostm 0:c9112f0c67e3 888 if (e2 <= x) {
bcostm 0:c9112f0c67e3 889 err += ++x*2+1;
bcostm 0:c9112f0c67e3 890 if (-y == x && e2 <= y) e2 = 0;
bcostm 0:c9112f0c67e3 891 }
bcostm 0:c9112f0c67e3 892 if (e2 > y) err += ++y*2+1;
bcostm 0:c9112f0c67e3 893 }
bcostm 0:c9112f0c67e3 894 while (y <= 0);
bcostm 0:c9112f0c67e3 895 }
bcostm 0:c9112f0c67e3 896
bcostm 0:c9112f0c67e3 897 /**
bcostm 0:c9112f0c67e3 898 * @brief Draws a pixel on LCD.
bcostm 0:c9112f0c67e3 899 * @param Xpos: X position
bcostm 0:c9112f0c67e3 900 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 901 * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8)
bcostm 0:c9112f0c67e3 902 * @retval None
bcostm 0:c9112f0c67e3 903 */
bcostm 0:c9112f0c67e3 904 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
bcostm 0:c9112f0c67e3 905 {
bcostm 0:c9112f0c67e3 906 /* Write data value to all SDRAM memory */
bcostm 0:c9112f0c67e3 907 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565)
bcostm 0:c9112f0c67e3 908 { /* RGB565 format */
bcostm 0:c9112f0c67e3 909 *(__IO uint16_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) = (uint16_t)RGB_Code;
bcostm 0:c9112f0c67e3 910 }
bcostm 0:c9112f0c67e3 911 else
bcostm 0:c9112f0c67e3 912 { /* ARGB8888 format */
bcostm 0:c9112f0c67e3 913 *(__IO uint32_t*) (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
bcostm 0:c9112f0c67e3 914 }
bcostm 0:c9112f0c67e3 915 }
bcostm 0:c9112f0c67e3 916
bcostm 0:c9112f0c67e3 917 /**
bcostm 0:c9112f0c67e3 918 * @brief Draws a bitmap picture loaded in the internal Flash in ARGB888 format (32 bits per pixel).
bcostm 0:c9112f0c67e3 919 * @param Xpos: Bmp X position in the LCD
bcostm 0:c9112f0c67e3 920 * @param Ypos: Bmp Y position in the LCD
bcostm 0:c9112f0c67e3 921 * @param pbmp: Pointer to Bmp picture address in the internal Flash
bcostm 0:c9112f0c67e3 922 * @retval None
bcostm 0:c9112f0c67e3 923 */
bcostm 0:c9112f0c67e3 924 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
bcostm 0:c9112f0c67e3 925 {
bcostm 0:c9112f0c67e3 926 uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
bcostm 0:c9112f0c67e3 927 uint32_t address;
bcostm 0:c9112f0c67e3 928 uint32_t input_color_mode = 0;
bcostm 0:c9112f0c67e3 929
bcostm 0:c9112f0c67e3 930 /* Get bitmap data address offset */
bcostm 0:c9112f0c67e3 931 index = *(__IO uint16_t *) (pbmp + 10);
bcostm 0:c9112f0c67e3 932 index |= (*(__IO uint16_t *) (pbmp + 12)) << 16;
bcostm 0:c9112f0c67e3 933
bcostm 0:c9112f0c67e3 934 /* Read bitmap width */
bcostm 0:c9112f0c67e3 935 width = *(uint16_t *) (pbmp + 18);
bcostm 0:c9112f0c67e3 936 width |= (*(uint16_t *) (pbmp + 20)) << 16;
bcostm 0:c9112f0c67e3 937
bcostm 0:c9112f0c67e3 938 /* Read bitmap height */
bcostm 0:c9112f0c67e3 939 height = *(uint16_t *) (pbmp + 22);
bcostm 0:c9112f0c67e3 940 height |= (*(uint16_t *) (pbmp + 24)) << 16;
bcostm 0:c9112f0c67e3 941
bcostm 0:c9112f0c67e3 942 /* Read bit/pixel */
bcostm 0:c9112f0c67e3 943 bit_pixel = *(uint16_t *) (pbmp + 28);
bcostm 0:c9112f0c67e3 944
bcostm 0:c9112f0c67e3 945 /* Set the address */
bcostm 0:c9112f0c67e3 946 address = hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
bcostm 0:c9112f0c67e3 947
bcostm 0:c9112f0c67e3 948 /* Get the layer pixel format */
bcostm 0:c9112f0c67e3 949 if ((bit_pixel/8) == 4)
bcostm 0:c9112f0c67e3 950 {
bcostm 0:c9112f0c67e3 951 input_color_mode = CM_ARGB8888;
bcostm 0:c9112f0c67e3 952 }
bcostm 0:c9112f0c67e3 953 else if ((bit_pixel/8) == 2)
bcostm 0:c9112f0c67e3 954 {
bcostm 0:c9112f0c67e3 955 input_color_mode = CM_RGB565;
bcostm 0:c9112f0c67e3 956 }
bcostm 0:c9112f0c67e3 957 else
bcostm 0:c9112f0c67e3 958 {
bcostm 0:c9112f0c67e3 959 input_color_mode = CM_RGB888;
bcostm 0:c9112f0c67e3 960 }
bcostm 0:c9112f0c67e3 961
bcostm 0:c9112f0c67e3 962 /* Bypass the bitmap header */
bcostm 0:c9112f0c67e3 963 pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
bcostm 0:c9112f0c67e3 964
bcostm 0:c9112f0c67e3 965 /* Convert picture to ARGB8888 pixel format */
bcostm 0:c9112f0c67e3 966 for(index=0; index < height; index++)
bcostm 0:c9112f0c67e3 967 {
bcostm 0:c9112f0c67e3 968 /* Pixel format conversion */
bcostm 0:c9112f0c67e3 969 LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)address, width, input_color_mode);
bcostm 0:c9112f0c67e3 970
bcostm 0:c9112f0c67e3 971 /* Increment the source and destination buffers */
bcostm 0:c9112f0c67e3 972 address+= (BSP_LCD_GetXSize()*4);
bcostm 0:c9112f0c67e3 973 pbmp -= width*(bit_pixel/8);
bcostm 0:c9112f0c67e3 974 }
bcostm 0:c9112f0c67e3 975 }
bcostm 0:c9112f0c67e3 976
bcostm 0:c9112f0c67e3 977 /**
bcostm 0:c9112f0c67e3 978 * @brief Draws a full rectangle.
bcostm 0:c9112f0c67e3 979 * @param Xpos: X position
bcostm 0:c9112f0c67e3 980 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 981 * @param Width: Rectangle width
bcostm 0:c9112f0c67e3 982 * @param Height: Rectangle height
bcostm 0:c9112f0c67e3 983 * @retval None
bcostm 0:c9112f0c67e3 984 */
bcostm 0:c9112f0c67e3 985 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
bcostm 0:c9112f0c67e3 986 {
bcostm 0:c9112f0c67e3 987 uint32_t x_address = 0;
bcostm 0:c9112f0c67e3 988
bcostm 0:c9112f0c67e3 989 /* Set the text color */
bcostm 0:c9112f0c67e3 990 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 991
bcostm 0:c9112f0c67e3 992 /* Get the rectangle start address */
bcostm 0:c9112f0c67e3 993 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565)
bcostm 0:c9112f0c67e3 994 { /* RGB565 format */
bcostm 0:c9112f0c67e3 995 x_address = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 2*(BSP_LCD_GetXSize()*Ypos + Xpos);
bcostm 0:c9112f0c67e3 996 }
bcostm 0:c9112f0c67e3 997 else
bcostm 0:c9112f0c67e3 998 { /* ARGB8888 format */
bcostm 0:c9112f0c67e3 999 x_address = (hLtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
bcostm 0:c9112f0c67e3 1000 }
bcostm 0:c9112f0c67e3 1001 /* Fill the rectangle */
bcostm 0:c9112f0c67e3 1002 LL_FillBuffer(ActiveLayer, (uint32_t *)x_address, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 1003 }
bcostm 0:c9112f0c67e3 1004
bcostm 0:c9112f0c67e3 1005 /**
bcostm 0:c9112f0c67e3 1006 * @brief Draws a full circle.
bcostm 0:c9112f0c67e3 1007 * @param Xpos: X position
bcostm 0:c9112f0c67e3 1008 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 1009 * @param Radius: Circle radius
bcostm 0:c9112f0c67e3 1010 * @retval None
bcostm 0:c9112f0c67e3 1011 */
bcostm 0:c9112f0c67e3 1012 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
bcostm 0:c9112f0c67e3 1013 {
bcostm 0:c9112f0c67e3 1014 int32_t decision; /* Decision Variable */
bcostm 0:c9112f0c67e3 1015 uint32_t current_x; /* Current X Value */
bcostm 0:c9112f0c67e3 1016 uint32_t current_y; /* Current Y Value */
bcostm 0:c9112f0c67e3 1017
bcostm 0:c9112f0c67e3 1018 decision = 3 - (Radius << 1);
bcostm 0:c9112f0c67e3 1019
bcostm 0:c9112f0c67e3 1020 current_x = 0;
bcostm 0:c9112f0c67e3 1021 current_y = Radius;
bcostm 0:c9112f0c67e3 1022
bcostm 0:c9112f0c67e3 1023 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 1024
bcostm 0:c9112f0c67e3 1025 while (current_x <= current_y)
bcostm 0:c9112f0c67e3 1026 {
bcostm 0:c9112f0c67e3 1027 if(current_y > 0)
bcostm 0:c9112f0c67e3 1028 {
bcostm 0:c9112f0c67e3 1029 BSP_LCD_DrawHLine(Xpos - current_y, Ypos + current_x, 2*current_y);
bcostm 0:c9112f0c67e3 1030 BSP_LCD_DrawHLine(Xpos - current_y, Ypos - current_x, 2*current_y);
bcostm 0:c9112f0c67e3 1031 }
bcostm 0:c9112f0c67e3 1032
bcostm 0:c9112f0c67e3 1033 if(current_x > 0)
bcostm 0:c9112f0c67e3 1034 {
bcostm 0:c9112f0c67e3 1035 BSP_LCD_DrawHLine(Xpos - current_x, Ypos - current_y, 2*current_x);
bcostm 0:c9112f0c67e3 1036 BSP_LCD_DrawHLine(Xpos - current_x, Ypos + current_y, 2*current_x);
bcostm 0:c9112f0c67e3 1037 }
bcostm 0:c9112f0c67e3 1038 if (decision < 0)
bcostm 0:c9112f0c67e3 1039 {
bcostm 0:c9112f0c67e3 1040 decision += (current_x << 2) + 6;
bcostm 0:c9112f0c67e3 1041 }
bcostm 0:c9112f0c67e3 1042 else
bcostm 0:c9112f0c67e3 1043 {
bcostm 0:c9112f0c67e3 1044 decision += ((current_x - current_y) << 2) + 10;
bcostm 0:c9112f0c67e3 1045 current_y--;
bcostm 0:c9112f0c67e3 1046 }
bcostm 0:c9112f0c67e3 1047 current_x++;
bcostm 0:c9112f0c67e3 1048 }
bcostm 0:c9112f0c67e3 1049
bcostm 0:c9112f0c67e3 1050 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 1051 BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
bcostm 0:c9112f0c67e3 1052 }
bcostm 0:c9112f0c67e3 1053
bcostm 0:c9112f0c67e3 1054 /**
bcostm 0:c9112f0c67e3 1055 * @brief Draws a full poly-line (between many points).
bcostm 0:c9112f0c67e3 1056 * @param Points: Pointer to the points array
bcostm 0:c9112f0c67e3 1057 * @param PointCount: Number of points
bcostm 0:c9112f0c67e3 1058 * @retval None
bcostm 0:c9112f0c67e3 1059 */
bcostm 0:c9112f0c67e3 1060 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
bcostm 0:c9112f0c67e3 1061 {
bcostm 0:c9112f0c67e3 1062 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;
bcostm 0:c9112f0c67e3 1063 uint16_t image_left = 0, image_right = 0, image_top = 0, image_bottom = 0;
bcostm 0:c9112f0c67e3 1064
bcostm 0:c9112f0c67e3 1065 image_left = image_right = Points->X;
bcostm 0:c9112f0c67e3 1066 image_top= image_bottom = Points->Y;
bcostm 0:c9112f0c67e3 1067
bcostm 0:c9112f0c67e3 1068 for(counter = 1; counter < PointCount; counter++)
bcostm 0:c9112f0c67e3 1069 {
bcostm 0:c9112f0c67e3 1070 pixelX = POLY_X(counter);
bcostm 0:c9112f0c67e3 1071 if(pixelX < image_left)
bcostm 0:c9112f0c67e3 1072 {
bcostm 0:c9112f0c67e3 1073 image_left = pixelX;
bcostm 0:c9112f0c67e3 1074 }
bcostm 0:c9112f0c67e3 1075 if(pixelX > image_right)
bcostm 0:c9112f0c67e3 1076 {
bcostm 0:c9112f0c67e3 1077 image_right = pixelX;
bcostm 0:c9112f0c67e3 1078 }
bcostm 0:c9112f0c67e3 1079
bcostm 0:c9112f0c67e3 1080 pixelY = POLY_Y(counter);
bcostm 0:c9112f0c67e3 1081 if(pixelY < image_top)
bcostm 0:c9112f0c67e3 1082 {
bcostm 0:c9112f0c67e3 1083 image_top = pixelY;
bcostm 0:c9112f0c67e3 1084 }
bcostm 0:c9112f0c67e3 1085 if(pixelY > image_bottom)
bcostm 0:c9112f0c67e3 1086 {
bcostm 0:c9112f0c67e3 1087 image_bottom = pixelY;
bcostm 0:c9112f0c67e3 1088 }
bcostm 0:c9112f0c67e3 1089 }
bcostm 0:c9112f0c67e3 1090
bcostm 0:c9112f0c67e3 1091 if(PointCount < 2)
bcostm 0:c9112f0c67e3 1092 {
bcostm 0:c9112f0c67e3 1093 return;
bcostm 0:c9112f0c67e3 1094 }
bcostm 0:c9112f0c67e3 1095
bcostm 0:c9112f0c67e3 1096 X_center = (image_left + image_right)/2;
bcostm 0:c9112f0c67e3 1097 Y_center = (image_bottom + image_top)/2;
bcostm 0:c9112f0c67e3 1098
bcostm 0:c9112f0c67e3 1099 X_first = Points->X;
bcostm 0:c9112f0c67e3 1100 Y_first = Points->Y;
bcostm 0:c9112f0c67e3 1101
bcostm 0:c9112f0c67e3 1102 while(--PointCount)
bcostm 0:c9112f0c67e3 1103 {
bcostm 0:c9112f0c67e3 1104 X = Points->X;
bcostm 0:c9112f0c67e3 1105 Y = Points->Y;
bcostm 0:c9112f0c67e3 1106 Points++;
bcostm 0:c9112f0c67e3 1107 X2 = Points->X;
bcostm 0:c9112f0c67e3 1108 Y2 = Points->Y;
bcostm 0:c9112f0c67e3 1109
bcostm 0:c9112f0c67e3 1110 FillTriangle(X, X2, X_center, Y, Y2, Y_center);
bcostm 0:c9112f0c67e3 1111 FillTriangle(X, X_center, X2, Y, Y_center, Y2);
bcostm 0:c9112f0c67e3 1112 FillTriangle(X_center, X2, X, Y_center, Y2, Y);
bcostm 0:c9112f0c67e3 1113 }
bcostm 0:c9112f0c67e3 1114
bcostm 0:c9112f0c67e3 1115 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
bcostm 0:c9112f0c67e3 1116 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
bcostm 0:c9112f0c67e3 1117 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
bcostm 0:c9112f0c67e3 1118 }
bcostm 0:c9112f0c67e3 1119
bcostm 0:c9112f0c67e3 1120 /**
bcostm 0:c9112f0c67e3 1121 * @brief Draws a full ellipse.
bcostm 0:c9112f0c67e3 1122 * @param Xpos: X position
bcostm 0:c9112f0c67e3 1123 * @param Ypos: Y position
bcostm 0:c9112f0c67e3 1124 * @param XRadius: Ellipse X radius
bcostm 0:c9112f0c67e3 1125 * @param YRadius: Ellipse Y radius
bcostm 0:c9112f0c67e3 1126 * @retval None
bcostm 0:c9112f0c67e3 1127 */
bcostm 0:c9112f0c67e3 1128 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
bcostm 0:c9112f0c67e3 1129 {
bcostm 0:c9112f0c67e3 1130 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
bcostm 0:c9112f0c67e3 1131 float k = 0, rad1 = 0, rad2 = 0;
bcostm 0:c9112f0c67e3 1132
bcostm 0:c9112f0c67e3 1133 rad1 = XRadius;
bcostm 0:c9112f0c67e3 1134 rad2 = YRadius;
bcostm 0:c9112f0c67e3 1135
bcostm 0:c9112f0c67e3 1136 k = (float)(rad2/rad1);
bcostm 0:c9112f0c67e3 1137
bcostm 0:c9112f0c67e3 1138 do
bcostm 0:c9112f0c67e3 1139 {
bcostm 0:c9112f0c67e3 1140 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos+y), (2*(uint16_t)(x/k) + 1));
bcostm 0:c9112f0c67e3 1141 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos-y), (2*(uint16_t)(x/k) + 1));
bcostm 0:c9112f0c67e3 1142
bcostm 0:c9112f0c67e3 1143 e2 = err;
bcostm 0:c9112f0c67e3 1144 if (e2 <= x)
bcostm 0:c9112f0c67e3 1145 {
bcostm 0:c9112f0c67e3 1146 err += ++x*2+1;
bcostm 0:c9112f0c67e3 1147 if (-y == x && e2 <= y) e2 = 0;
bcostm 0:c9112f0c67e3 1148 }
bcostm 0:c9112f0c67e3 1149 if (e2 > y) err += ++y*2+1;
bcostm 0:c9112f0c67e3 1150 }
bcostm 0:c9112f0c67e3 1151 while (y <= 0);
bcostm 0:c9112f0c67e3 1152 }
bcostm 0:c9112f0c67e3 1153
bcostm 0:c9112f0c67e3 1154 /**
bcostm 0:c9112f0c67e3 1155 * @brief Enables the display.
bcostm 0:c9112f0c67e3 1156 * @retval None
bcostm 0:c9112f0c67e3 1157 */
bcostm 0:c9112f0c67e3 1158 void BSP_LCD_DisplayOn(void)
bcostm 0:c9112f0c67e3 1159 {
bcostm 0:c9112f0c67e3 1160 /* Display On */
bcostm 0:c9112f0c67e3 1161 __HAL_LTDC_ENABLE(&hLtdcHandler);
bcostm 0:c9112f0c67e3 1162 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_SET); /* Assert LCD_DISP pin */
bcostm 0:c9112f0c67e3 1163 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET); /* Assert LCD_BL_CTRL pin */
bcostm 0:c9112f0c67e3 1164 }
bcostm 0:c9112f0c67e3 1165
bcostm 0:c9112f0c67e3 1166 /**
bcostm 0:c9112f0c67e3 1167 * @brief Disables the display.
bcostm 0:c9112f0c67e3 1168 * @retval None
bcostm 0:c9112f0c67e3 1169 */
bcostm 0:c9112f0c67e3 1170 void BSP_LCD_DisplayOff(void)
bcostm 0:c9112f0c67e3 1171 {
bcostm 0:c9112f0c67e3 1172 /* Display Off */
bcostm 0:c9112f0c67e3 1173 __HAL_LTDC_DISABLE(&hLtdcHandler);
bcostm 0:c9112f0c67e3 1174 HAL_GPIO_WritePin(LCD_DISP_GPIO_PORT, LCD_DISP_PIN, GPIO_PIN_RESET); /* De-assert LCD_DISP pin */
bcostm 0:c9112f0c67e3 1175 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_RESET);/* De-assert LCD_BL_CTRL pin */
bcostm 0:c9112f0c67e3 1176 }
bcostm 0:c9112f0c67e3 1177
bcostm 0:c9112f0c67e3 1178 /**
bcostm 0:c9112f0c67e3 1179 * @brief Initializes the LTDC MSP.
bcostm 0:c9112f0c67e3 1180 * @param hltdc: LTDC handle
bcostm 0:c9112f0c67e3 1181 * @param Params
bcostm 0:c9112f0c67e3 1182 * @retval None
bcostm 0:c9112f0c67e3 1183 */
bcostm 0:c9112f0c67e3 1184 __weak void BSP_LCD_MspInit(LTDC_HandleTypeDef *hltdc, void *Params)
bcostm 0:c9112f0c67e3 1185 {
bcostm 0:c9112f0c67e3 1186 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:c9112f0c67e3 1187
bcostm 0:c9112f0c67e3 1188 /* Enable the LTDC and DMA2D clocks */
bcostm 0:c9112f0c67e3 1189 __HAL_RCC_LTDC_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1190 __HAL_RCC_DMA2D_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1191
bcostm 0:c9112f0c67e3 1192 /* Enable GPIOs clock */
bcostm 0:c9112f0c67e3 1193 __HAL_RCC_GPIOE_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1194 __HAL_RCC_GPIOG_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1195 __HAL_RCC_GPIOI_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1196 __HAL_RCC_GPIOJ_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1197 __HAL_RCC_GPIOK_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1198 LCD_DISP_GPIO_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1199 LCD_BL_CTRL_GPIO_CLK_ENABLE();
bcostm 0:c9112f0c67e3 1200
bcostm 0:c9112f0c67e3 1201 /*** LTDC Pins configuration ***/
bcostm 0:c9112f0c67e3 1202 /* GPIOE configuration */
bcostm 0:c9112f0c67e3 1203 gpio_init_structure.Pin = GPIO_PIN_4;
bcostm 0:c9112f0c67e3 1204 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 0:c9112f0c67e3 1205 gpio_init_structure.Pull = GPIO_NOPULL;
bcostm 0:c9112f0c67e3 1206 gpio_init_structure.Speed = GPIO_SPEED_FAST;
bcostm 0:c9112f0c67e3 1207 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
bcostm 0:c9112f0c67e3 1208 HAL_GPIO_Init(GPIOE, &gpio_init_structure);
bcostm 0:c9112f0c67e3 1209
bcostm 0:c9112f0c67e3 1210 /* GPIOG configuration */
bcostm 0:c9112f0c67e3 1211 gpio_init_structure.Pin = GPIO_PIN_12;
bcostm 0:c9112f0c67e3 1212 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 0:c9112f0c67e3 1213 gpio_init_structure.Alternate = GPIO_AF9_LTDC;
bcostm 0:c9112f0c67e3 1214 HAL_GPIO_Init(GPIOG, &gpio_init_structure);
bcostm 0:c9112f0c67e3 1215
bcostm 0:c9112f0c67e3 1216 /* GPIOI LTDC alternate configuration */
bcostm 0:c9112f0c67e3 1217 gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | \
bcostm 0:c9112f0c67e3 1218 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
bcostm 0:c9112f0c67e3 1219 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 0:c9112f0c67e3 1220 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
bcostm 0:c9112f0c67e3 1221 HAL_GPIO_Init(GPIOI, &gpio_init_structure);
bcostm 0:c9112f0c67e3 1222
bcostm 0:c9112f0c67e3 1223 /* GPIOJ configuration */
bcostm 0:c9112f0c67e3 1224 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | \
bcostm 0:c9112f0c67e3 1225 GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | \
bcostm 0:c9112f0c67e3 1226 GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \
bcostm 0:c9112f0c67e3 1227 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
bcostm 0:c9112f0c67e3 1228 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 0:c9112f0c67e3 1229 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
bcostm 0:c9112f0c67e3 1230 HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
bcostm 0:c9112f0c67e3 1231
bcostm 0:c9112f0c67e3 1232 /* GPIOK configuration */
bcostm 0:c9112f0c67e3 1233 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4 | \
bcostm 0:c9112f0c67e3 1234 GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
bcostm 0:c9112f0c67e3 1235 gpio_init_structure.Mode = GPIO_MODE_AF_PP;
bcostm 0:c9112f0c67e3 1236 gpio_init_structure.Alternate = GPIO_AF14_LTDC;
bcostm 0:c9112f0c67e3 1237 HAL_GPIO_Init(GPIOK, &gpio_init_structure);
bcostm 0:c9112f0c67e3 1238
bcostm 0:c9112f0c67e3 1239 /* LCD_DISP GPIO configuration */
bcostm 0:c9112f0c67e3 1240 gpio_init_structure.Pin = LCD_DISP_PIN; /* LCD_DISP pin has to be manually controlled */
bcostm 0:c9112f0c67e3 1241 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 0:c9112f0c67e3 1242 HAL_GPIO_Init(LCD_DISP_GPIO_PORT, &gpio_init_structure);
bcostm 0:c9112f0c67e3 1243
bcostm 0:c9112f0c67e3 1244 /* LCD_BL_CTRL GPIO configuration */
bcostm 0:c9112f0c67e3 1245 gpio_init_structure.Pin = LCD_BL_CTRL_PIN; /* LCD_BL_CTRL pin has to be manually controlled */
bcostm 0:c9112f0c67e3 1246 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 0:c9112f0c67e3 1247 HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &gpio_init_structure);
bcostm 0:c9112f0c67e3 1248 }
bcostm 0:c9112f0c67e3 1249
bcostm 0:c9112f0c67e3 1250 /**
bcostm 0:c9112f0c67e3 1251 * @brief DeInitializes BSP_LCD MSP.
bcostm 0:c9112f0c67e3 1252 * @param hltdc: LTDC handle
bcostm 0:c9112f0c67e3 1253 * @param Params
bcostm 0:c9112f0c67e3 1254 * @retval None
bcostm 0:c9112f0c67e3 1255 */
bcostm 0:c9112f0c67e3 1256 __weak void BSP_LCD_MspDeInit(LTDC_HandleTypeDef *hltdc, void *Params)
bcostm 0:c9112f0c67e3 1257 {
bcostm 0:c9112f0c67e3 1258 GPIO_InitTypeDef gpio_init_structure;
bcostm 0:c9112f0c67e3 1259
bcostm 0:c9112f0c67e3 1260 /* Disable LTDC block */
bcostm 0:c9112f0c67e3 1261 __HAL_LTDC_DISABLE(hltdc);
bcostm 0:c9112f0c67e3 1262
bcostm 0:c9112f0c67e3 1263 /* LTDC Pins deactivation */
bcostm 0:c9112f0c67e3 1264
bcostm 0:c9112f0c67e3 1265 /* GPIOE deactivation */
bcostm 0:c9112f0c67e3 1266 gpio_init_structure.Pin = GPIO_PIN_4;
bcostm 0:c9112f0c67e3 1267 HAL_GPIO_DeInit(GPIOE, gpio_init_structure.Pin);
bcostm 0:c9112f0c67e3 1268
bcostm 0:c9112f0c67e3 1269 /* GPIOG deactivation */
bcostm 0:c9112f0c67e3 1270 gpio_init_structure.Pin = GPIO_PIN_12;
bcostm 0:c9112f0c67e3 1271 HAL_GPIO_DeInit(GPIOG, gpio_init_structure.Pin);
bcostm 0:c9112f0c67e3 1272
bcostm 0:c9112f0c67e3 1273 /* GPIOI deactivation */
bcostm 0:c9112f0c67e3 1274 gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_12 | \
bcostm 0:c9112f0c67e3 1275 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
bcostm 0:c9112f0c67e3 1276 HAL_GPIO_DeInit(GPIOI, gpio_init_structure.Pin);
bcostm 0:c9112f0c67e3 1277
bcostm 0:c9112f0c67e3 1278 /* GPIOJ deactivation */
bcostm 0:c9112f0c67e3 1279 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | \
bcostm 0:c9112f0c67e3 1280 GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | \
bcostm 0:c9112f0c67e3 1281 GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | \
bcostm 0:c9112f0c67e3 1282 GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
bcostm 0:c9112f0c67e3 1283 HAL_GPIO_DeInit(GPIOJ, gpio_init_structure.Pin);
bcostm 0:c9112f0c67e3 1284
bcostm 0:c9112f0c67e3 1285 /* GPIOK deactivation */
bcostm 0:c9112f0c67e3 1286 gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_4 | \
bcostm 0:c9112f0c67e3 1287 GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
bcostm 0:c9112f0c67e3 1288 HAL_GPIO_DeInit(GPIOK, gpio_init_structure.Pin);
bcostm 0:c9112f0c67e3 1289
bcostm 0:c9112f0c67e3 1290 /* Disable LTDC clock */
bcostm 0:c9112f0c67e3 1291 __HAL_RCC_LTDC_CLK_DISABLE();
bcostm 0:c9112f0c67e3 1292
bcostm 0:c9112f0c67e3 1293 /* GPIO pins clock can be shut down in the application
bcostm 0:c9112f0c67e3 1294 by surcharging this __weak function */
bcostm 0:c9112f0c67e3 1295 }
bcostm 0:c9112f0c67e3 1296
bcostm 0:c9112f0c67e3 1297 /**
bcostm 0:c9112f0c67e3 1298 * @brief Clock Config.
bcostm 0:c9112f0c67e3 1299 * @param hltdc: LTDC handle
bcostm 0:c9112f0c67e3 1300 * @param Params
bcostm 0:c9112f0c67e3 1301 * @note This API is called by BSP_LCD_Init()
bcostm 0:c9112f0c67e3 1302 * Being __weak it can be overwritten by the application
bcostm 0:c9112f0c67e3 1303 * @retval None
bcostm 0:c9112f0c67e3 1304 */
bcostm 0:c9112f0c67e3 1305 __weak void BSP_LCD_ClockConfig(LTDC_HandleTypeDef *hltdc, void *Params)
bcostm 0:c9112f0c67e3 1306 {
bcostm 0:c9112f0c67e3 1307 static RCC_PeriphCLKInitTypeDef periph_clk_init_struct;
bcostm 0:c9112f0c67e3 1308
bcostm 0:c9112f0c67e3 1309 /* RK043FN48H LCD clock configuration */
bcostm 0:c9112f0c67e3 1310 /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
bcostm 0:c9112f0c67e3 1311 /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */
bcostm 0:c9112f0c67e3 1312 /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/5 = 38.4 Mhz */
bcostm 0:c9112f0c67e3 1313 /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_4 = 38.4/4 = 9.6Mhz */
bcostm 0:c9112f0c67e3 1314 periph_clk_init_struct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
bcostm 0:c9112f0c67e3 1315 periph_clk_init_struct.PLLSAI.PLLSAIN = 192;
bcostm 0:c9112f0c67e3 1316 periph_clk_init_struct.PLLSAI.PLLSAIR = RK043FN48H_FREQUENCY_DIVIDER;
bcostm 0:c9112f0c67e3 1317 periph_clk_init_struct.PLLSAIDivR = RCC_PLLSAIDIVR_4;
bcostm 0:c9112f0c67e3 1318 HAL_RCCEx_PeriphCLKConfig(&periph_clk_init_struct);
bcostm 0:c9112f0c67e3 1319 }
bcostm 0:c9112f0c67e3 1320
bcostm 0:c9112f0c67e3 1321
bcostm 0:c9112f0c67e3 1322 /*******************************************************************************
bcostm 0:c9112f0c67e3 1323 Static Functions
bcostm 0:c9112f0c67e3 1324 *******************************************************************************/
bcostm 0:c9112f0c67e3 1325
bcostm 0:c9112f0c67e3 1326 /**
bcostm 0:c9112f0c67e3 1327 * @brief Draws a character on LCD.
bcostm 0:c9112f0c67e3 1328 * @param Xpos: Line where to display the character shape
bcostm 0:c9112f0c67e3 1329 * @param Ypos: Start column address
bcostm 0:c9112f0c67e3 1330 * @param c: Pointer to the character data
bcostm 0:c9112f0c67e3 1331 * @retval None
bcostm 0:c9112f0c67e3 1332 */
bcostm 0:c9112f0c67e3 1333 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
bcostm 0:c9112f0c67e3 1334 {
bcostm 0:c9112f0c67e3 1335 uint32_t i = 0, j = 0;
bcostm 0:c9112f0c67e3 1336 uint16_t height, width;
bcostm 0:c9112f0c67e3 1337 uint8_t offset;
bcostm 0:c9112f0c67e3 1338 uint8_t *pchar;
bcostm 0:c9112f0c67e3 1339 uint32_t line;
bcostm 0:c9112f0c67e3 1340
bcostm 0:c9112f0c67e3 1341 height = DrawProp[ActiveLayer].pFont->Height;
bcostm 0:c9112f0c67e3 1342 width = DrawProp[ActiveLayer].pFont->Width;
bcostm 0:c9112f0c67e3 1343
bcostm 0:c9112f0c67e3 1344 offset = 8 *((width + 7)/8) - width ;
bcostm 0:c9112f0c67e3 1345
bcostm 0:c9112f0c67e3 1346 for(i = 0; i < height; i++)
bcostm 0:c9112f0c67e3 1347 {
bcostm 0:c9112f0c67e3 1348 pchar = ((uint8_t *)c + (width + 7)/8 * i);
bcostm 0:c9112f0c67e3 1349
bcostm 0:c9112f0c67e3 1350 switch(((width + 7)/8))
bcostm 0:c9112f0c67e3 1351 {
bcostm 0:c9112f0c67e3 1352
bcostm 0:c9112f0c67e3 1353 case 1:
bcostm 0:c9112f0c67e3 1354 line = pchar[0];
bcostm 0:c9112f0c67e3 1355 break;
bcostm 0:c9112f0c67e3 1356
bcostm 0:c9112f0c67e3 1357 case 2:
bcostm 0:c9112f0c67e3 1358 line = (pchar[0]<< 8) | pchar[1];
bcostm 0:c9112f0c67e3 1359 break;
bcostm 0:c9112f0c67e3 1360
bcostm 0:c9112f0c67e3 1361 case 3:
bcostm 0:c9112f0c67e3 1362 default:
bcostm 0:c9112f0c67e3 1363 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
bcostm 0:c9112f0c67e3 1364 break;
bcostm 0:c9112f0c67e3 1365 }
bcostm 0:c9112f0c67e3 1366
bcostm 0:c9112f0c67e3 1367 for (j = 0; j < width; j++)
bcostm 0:c9112f0c67e3 1368 {
bcostm 0:c9112f0c67e3 1369 if(line & (1 << (width- j + offset- 1)))
bcostm 0:c9112f0c67e3 1370 {
bcostm 0:c9112f0c67e3 1371 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
bcostm 0:c9112f0c67e3 1372 }
bcostm 0:c9112f0c67e3 1373 else
bcostm 0:c9112f0c67e3 1374 {
bcostm 0:c9112f0c67e3 1375 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
bcostm 0:c9112f0c67e3 1376 }
bcostm 0:c9112f0c67e3 1377 }
bcostm 0:c9112f0c67e3 1378 Ypos++;
bcostm 0:c9112f0c67e3 1379 }
bcostm 0:c9112f0c67e3 1380 }
bcostm 0:c9112f0c67e3 1381
bcostm 0:c9112f0c67e3 1382 /**
bcostm 0:c9112f0c67e3 1383 * @brief Fills a triangle (between 3 points).
bcostm 0:c9112f0c67e3 1384 * @param x1: Point 1 X position
bcostm 0:c9112f0c67e3 1385 * @param y1: Point 1 Y position
bcostm 0:c9112f0c67e3 1386 * @param x2: Point 2 X position
bcostm 0:c9112f0c67e3 1387 * @param y2: Point 2 Y position
bcostm 0:c9112f0c67e3 1388 * @param x3: Point 3 X position
bcostm 0:c9112f0c67e3 1389 * @param y3: Point 3 Y position
bcostm 0:c9112f0c67e3 1390 * @retval None
bcostm 0:c9112f0c67e3 1391 */
bcostm 0:c9112f0c67e3 1392 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
bcostm 0:c9112f0c67e3 1393 {
bcostm 0:c9112f0c67e3 1394 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
bcostm 0:c9112f0c67e3 1395 yinc1 = 0, yinc2 = 0, den = 0, num = 0, num_add = 0, num_pixels = 0,
bcostm 0:c9112f0c67e3 1396 curpixel = 0;
bcostm 0:c9112f0c67e3 1397
bcostm 0:c9112f0c67e3 1398 deltax = ABS(x2 - x1); /* The difference between the x's */
bcostm 0:c9112f0c67e3 1399 deltay = ABS(y2 - y1); /* The difference between the y's */
bcostm 0:c9112f0c67e3 1400 x = x1; /* Start x off at the first pixel */
bcostm 0:c9112f0c67e3 1401 y = y1; /* Start y off at the first pixel */
bcostm 0:c9112f0c67e3 1402
bcostm 0:c9112f0c67e3 1403 if (x2 >= x1) /* The x-values are increasing */
bcostm 0:c9112f0c67e3 1404 {
bcostm 0:c9112f0c67e3 1405 xinc1 = 1;
bcostm 0:c9112f0c67e3 1406 xinc2 = 1;
bcostm 0:c9112f0c67e3 1407 }
bcostm 0:c9112f0c67e3 1408 else /* The x-values are decreasing */
bcostm 0:c9112f0c67e3 1409 {
bcostm 0:c9112f0c67e3 1410 xinc1 = -1;
bcostm 0:c9112f0c67e3 1411 xinc2 = -1;
bcostm 0:c9112f0c67e3 1412 }
bcostm 0:c9112f0c67e3 1413
bcostm 0:c9112f0c67e3 1414 if (y2 >= y1) /* The y-values are increasing */
bcostm 0:c9112f0c67e3 1415 {
bcostm 0:c9112f0c67e3 1416 yinc1 = 1;
bcostm 0:c9112f0c67e3 1417 yinc2 = 1;
bcostm 0:c9112f0c67e3 1418 }
bcostm 0:c9112f0c67e3 1419 else /* The y-values are decreasing */
bcostm 0:c9112f0c67e3 1420 {
bcostm 0:c9112f0c67e3 1421 yinc1 = -1;
bcostm 0:c9112f0c67e3 1422 yinc2 = -1;
bcostm 0:c9112f0c67e3 1423 }
bcostm 0:c9112f0c67e3 1424
bcostm 0:c9112f0c67e3 1425 if (deltax >= deltay) /* There is at least one x-value for every y-value */
bcostm 0:c9112f0c67e3 1426 {
bcostm 0:c9112f0c67e3 1427 xinc1 = 0; /* Don't change the x when numerator >= denominator */
bcostm 0:c9112f0c67e3 1428 yinc2 = 0; /* Don't change the y for every iteration */
bcostm 0:c9112f0c67e3 1429 den = deltax;
bcostm 0:c9112f0c67e3 1430 num = deltax / 2;
bcostm 0:c9112f0c67e3 1431 num_add = deltay;
bcostm 0:c9112f0c67e3 1432 num_pixels = deltax; /* There are more x-values than y-values */
bcostm 0:c9112f0c67e3 1433 }
bcostm 0:c9112f0c67e3 1434 else /* There is at least one y-value for every x-value */
bcostm 0:c9112f0c67e3 1435 {
bcostm 0:c9112f0c67e3 1436 xinc2 = 0; /* Don't change the x for every iteration */
bcostm 0:c9112f0c67e3 1437 yinc1 = 0; /* Don't change the y when numerator >= denominator */
bcostm 0:c9112f0c67e3 1438 den = deltay;
bcostm 0:c9112f0c67e3 1439 num = deltay / 2;
bcostm 0:c9112f0c67e3 1440 num_add = deltax;
bcostm 0:c9112f0c67e3 1441 num_pixels = deltay; /* There are more y-values than x-values */
bcostm 0:c9112f0c67e3 1442 }
bcostm 0:c9112f0c67e3 1443
bcostm 0:c9112f0c67e3 1444 for (curpixel = 0; curpixel <= num_pixels; curpixel++)
bcostm 0:c9112f0c67e3 1445 {
bcostm 0:c9112f0c67e3 1446 BSP_LCD_DrawLine(x, y, x3, y3);
bcostm 0:c9112f0c67e3 1447
bcostm 0:c9112f0c67e3 1448 num += num_add; /* Increase the numerator by the top of the fraction */
bcostm 0:c9112f0c67e3 1449 if (num >= den) /* Check if numerator >= denominator */
bcostm 0:c9112f0c67e3 1450 {
bcostm 0:c9112f0c67e3 1451 num -= den; /* Calculate the new numerator value */
bcostm 0:c9112f0c67e3 1452 x += xinc1; /* Change the x as appropriate */
bcostm 0:c9112f0c67e3 1453 y += yinc1; /* Change the y as appropriate */
bcostm 0:c9112f0c67e3 1454 }
bcostm 0:c9112f0c67e3 1455 x += xinc2; /* Change the x as appropriate */
bcostm 0:c9112f0c67e3 1456 y += yinc2; /* Change the y as appropriate */
bcostm 0:c9112f0c67e3 1457 }
bcostm 0:c9112f0c67e3 1458 }
bcostm 0:c9112f0c67e3 1459
bcostm 0:c9112f0c67e3 1460 /**
bcostm 0:c9112f0c67e3 1461 * @brief Fills a buffer.
bcostm 0:c9112f0c67e3 1462 * @param LayerIndex: Layer index
bcostm 0:c9112f0c67e3 1463 * @param pDst: Pointer to destination buffer
bcostm 0:c9112f0c67e3 1464 * @param xSize: Buffer width
bcostm 0:c9112f0c67e3 1465 * @param ySize: Buffer height
bcostm 0:c9112f0c67e3 1466 * @param OffLine: Offset
bcostm 0:c9112f0c67e3 1467 * @param ColorIndex: Color index
bcostm 0:c9112f0c67e3 1468 * @retval None
bcostm 0:c9112f0c67e3 1469 */
bcostm 0:c9112f0c67e3 1470 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
bcostm 0:c9112f0c67e3 1471 {
bcostm 0:c9112f0c67e3 1472 /* Register to memory mode with ARGB8888 as color Mode */
bcostm 0:c9112f0c67e3 1473 hDma2dHandler.Init.Mode = DMA2D_R2M;
bcostm 0:c9112f0c67e3 1474 if(hLtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565)
bcostm 0:c9112f0c67e3 1475 { /* RGB565 format */
bcostm 0:c9112f0c67e3 1476 hDma2dHandler.Init.ColorMode = DMA2D_RGB565;
bcostm 0:c9112f0c67e3 1477 }
bcostm 0:c9112f0c67e3 1478 else
bcostm 0:c9112f0c67e3 1479 { /* ARGB8888 format */
bcostm 0:c9112f0c67e3 1480 hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888;
bcostm 0:c9112f0c67e3 1481 }
bcostm 0:c9112f0c67e3 1482 hDma2dHandler.Init.OutputOffset = OffLine;
bcostm 0:c9112f0c67e3 1483
bcostm 0:c9112f0c67e3 1484 hDma2dHandler.Instance = DMA2D;
bcostm 0:c9112f0c67e3 1485
bcostm 0:c9112f0c67e3 1486 /* DMA2D Initialization */
bcostm 0:c9112f0c67e3 1487 if(HAL_DMA2D_Init(&hDma2dHandler) == HAL_OK)
bcostm 0:c9112f0c67e3 1488 {
bcostm 0:c9112f0c67e3 1489 if(HAL_DMA2D_ConfigLayer(&hDma2dHandler, LayerIndex) == HAL_OK)
bcostm 0:c9112f0c67e3 1490 {
bcostm 0:c9112f0c67e3 1491 if (HAL_DMA2D_Start(&hDma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
bcostm 0:c9112f0c67e3 1492 {
bcostm 0:c9112f0c67e3 1493 /* Polling For DMA transfer */
bcostm 0:c9112f0c67e3 1494 HAL_DMA2D_PollForTransfer(&hDma2dHandler, 10);
bcostm 0:c9112f0c67e3 1495 }
bcostm 0:c9112f0c67e3 1496 }
bcostm 0:c9112f0c67e3 1497 }
bcostm 0:c9112f0c67e3 1498 }
bcostm 0:c9112f0c67e3 1499
bcostm 0:c9112f0c67e3 1500 /**
bcostm 0:c9112f0c67e3 1501 * @brief Converts a line to an ARGB8888 pixel format.
bcostm 0:c9112f0c67e3 1502 * @param pSrc: Pointer to source buffer
bcostm 0:c9112f0c67e3 1503 * @param pDst: Output color
bcostm 0:c9112f0c67e3 1504 * @param xSize: Buffer width
bcostm 0:c9112f0c67e3 1505 * @param ColorMode: Input color mode
bcostm 0:c9112f0c67e3 1506 * @retval None
bcostm 0:c9112f0c67e3 1507 */
bcostm 0:c9112f0c67e3 1508 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
bcostm 0:c9112f0c67e3 1509 {
bcostm 0:c9112f0c67e3 1510 /* Configure the DMA2D Mode, Color Mode and output offset */
bcostm 0:c9112f0c67e3 1511 hDma2dHandler.Init.Mode = DMA2D_M2M_PFC;
bcostm 0:c9112f0c67e3 1512 hDma2dHandler.Init.ColorMode = DMA2D_ARGB8888;
bcostm 0:c9112f0c67e3 1513 hDma2dHandler.Init.OutputOffset = 0;
bcostm 0:c9112f0c67e3 1514
bcostm 0:c9112f0c67e3 1515 /* Foreground Configuration */
bcostm 0:c9112f0c67e3 1516 hDma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
bcostm 0:c9112f0c67e3 1517 hDma2dHandler.LayerCfg[1].InputAlpha = 0xFF;
bcostm 0:c9112f0c67e3 1518 hDma2dHandler.LayerCfg[1].InputColorMode = ColorMode;
bcostm 0:c9112f0c67e3 1519 hDma2dHandler.LayerCfg[1].InputOffset = 0;
bcostm 0:c9112f0c67e3 1520
bcostm 0:c9112f0c67e3 1521 hDma2dHandler.Instance = DMA2D;
bcostm 0:c9112f0c67e3 1522
bcostm 0:c9112f0c67e3 1523 /* DMA2D Initialization */
bcostm 0:c9112f0c67e3 1524 if(HAL_DMA2D_Init(&hDma2dHandler) == HAL_OK)
bcostm 0:c9112f0c67e3 1525 {
bcostm 0:c9112f0c67e3 1526 if(HAL_DMA2D_ConfigLayer(&hDma2dHandler, 1) == HAL_OK)
bcostm 0:c9112f0c67e3 1527 {
bcostm 0:c9112f0c67e3 1528 if (HAL_DMA2D_Start(&hDma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
bcostm 0:c9112f0c67e3 1529 {
bcostm 0:c9112f0c67e3 1530 /* Polling For DMA transfer */
bcostm 0:c9112f0c67e3 1531 HAL_DMA2D_PollForTransfer(&hDma2dHandler, 10);
bcostm 0:c9112f0c67e3 1532 }
bcostm 0:c9112f0c67e3 1533 }
bcostm 0:c9112f0c67e3 1534 }
bcostm 0:c9112f0c67e3 1535 }
bcostm 0:c9112f0c67e3 1536
bcostm 0:c9112f0c67e3 1537 /**
bcostm 0:c9112f0c67e3 1538 * @}
bcostm 0:c9112f0c67e3 1539 */
bcostm 0:c9112f0c67e3 1540
bcostm 0:c9112f0c67e3 1541 /**
bcostm 0:c9112f0c67e3 1542 * @}
bcostm 0:c9112f0c67e3 1543 */
bcostm 0:c9112f0c67e3 1544
bcostm 0:c9112f0c67e3 1545 /**
bcostm 0:c9112f0c67e3 1546 * @}
bcostm 0:c9112f0c67e3 1547 */
bcostm 0:c9112f0c67e3 1548
bcostm 0:c9112f0c67e3 1549 /**
bcostm 0:c9112f0c67e3 1550 * @}
bcostm 0:c9112f0c67e3 1551 */
bcostm 0:c9112f0c67e3 1552
bcostm 0:c9112f0c67e3 1553 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/