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:
Tue Nov 12 11:24:03 2019 +0100
Revision:
10:1050c589b2ad
Parent:
8:56384bddaba5
STM32Cube_FW_F7_V1.15.0 BSP_DISCO_F746NG

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