bsp disco lib

Dependents:   grove_stream_jpa_sd2 grove_stream_jpa_sd2 grove_stream_jpa_sd2-2 grove_stream_jpa_sd2-3

Committer:
38domo
Date:
Mon Aug 31 17:51:44 2020 +0000
Revision:
14:ed51426706bd
Parent:
6:e1d9da7fe856
bsp lib

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