STM32746G-Discovery board drivers V1.0.0

Dependents:   DISCO-F746NG_LCDTS_CC3000_NTP DISCO-F746NG_ROPE_WIFI F746_SpectralAnalysis_NoPhoto ecte433 ... more

Committer:
Jerome Coutant
Date:
Thu Jul 06 16:58:50 2017 +0200
Revision:
9:df2ea349c37a
Parent:
8:56384bddaba5
Child:
10:1050c589b2ad
replace HAL_Delay by wait_ms

Who changed what in which revision?

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