Additional font macro
STM32F429I-Discovery/stm32f429i_discovery_lcd.c@1:a6fd0931a9e9, 2016-02-05 (annotated)
- Committer:
- SomeRandomBloke
- Date:
- Fri Feb 05 09:20:30 2016 +0000
- Revision:
- 1:a6fd0931a9e9
- Parent:
- 0:e1d164542663
Added additional font macro
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:e1d164542663 | 1 | /** |
bcostm | 0:e1d164542663 | 2 | ****************************************************************************** |
bcostm | 0:e1d164542663 | 3 | * @file stm32f429i_discovery_lcd.c |
bcostm | 0:e1d164542663 | 4 | * @author MCD Application Team |
bcostm | 0:e1d164542663 | 5 | * @version V2.1.2 |
bcostm | 0:e1d164542663 | 6 | * @date 02-March-2015 |
bcostm | 0:e1d164542663 | 7 | * @brief This file includes the LCD driver for ILI9341 Liquid Crystal |
bcostm | 0:e1d164542663 | 8 | * Display Modules of STM32F429I-Discovery kit (MB1075). |
bcostm | 0:e1d164542663 | 9 | ****************************************************************************** |
bcostm | 0:e1d164542663 | 10 | * @attention |
bcostm | 0:e1d164542663 | 11 | * |
bcostm | 0:e1d164542663 | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
bcostm | 0:e1d164542663 | 13 | * |
bcostm | 0:e1d164542663 | 14 | * Redistribution and use in source and binary forms, with or without modification, |
bcostm | 0:e1d164542663 | 15 | * are permitted provided that the following conditions are met: |
bcostm | 0:e1d164542663 | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
bcostm | 0:e1d164542663 | 17 | * this list of conditions and the following disclaimer. |
bcostm | 0:e1d164542663 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
bcostm | 0:e1d164542663 | 19 | * this list of conditions and the following disclaimer in the documentation |
bcostm | 0:e1d164542663 | 20 | * and/or other materials provided with the distribution. |
bcostm | 0:e1d164542663 | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
bcostm | 0:e1d164542663 | 22 | * may be used to endorse or promote products derived from this software |
bcostm | 0:e1d164542663 | 23 | * without specific prior written permission. |
bcostm | 0:e1d164542663 | 24 | * |
bcostm | 0:e1d164542663 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
bcostm | 0:e1d164542663 | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
bcostm | 0:e1d164542663 | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bcostm | 0:e1d164542663 | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
bcostm | 0:e1d164542663 | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
bcostm | 0:e1d164542663 | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
bcostm | 0:e1d164542663 | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
bcostm | 0:e1d164542663 | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
bcostm | 0:e1d164542663 | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
bcostm | 0:e1d164542663 | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bcostm | 0:e1d164542663 | 35 | * |
bcostm | 0:e1d164542663 | 36 | ****************************************************************************** |
bcostm | 0:e1d164542663 | 37 | */ |
bcostm | 0:e1d164542663 | 38 | |
bcostm | 0:e1d164542663 | 39 | /* File Info : ----------------------------------------------------------------- |
bcostm | 0:e1d164542663 | 40 | User NOTES |
bcostm | 0:e1d164542663 | 41 | 1. How To use this driver: |
bcostm | 0:e1d164542663 | 42 | -------------------------- |
bcostm | 0:e1d164542663 | 43 | - This driver is used to drive directly an LCD TFT using LTDC controller. |
bcostm | 0:e1d164542663 | 44 | - This driver select dynamically the mounted LCD, ILI9341 240x320 LCD mounted |
bcostm | 0:e1d164542663 | 45 | on MB1075B discovery board, and use the adequate timing and setting for |
bcostm | 0:e1d164542663 | 46 | the specified LCD using device ID of the ILI9341 mounted on MB1075B discovery board |
bcostm | 0:e1d164542663 | 47 | |
bcostm | 0:e1d164542663 | 48 | 2. Driver description: |
bcostm | 0:e1d164542663 | 49 | --------------------- |
bcostm | 0:e1d164542663 | 50 | + Initialization steps : |
bcostm | 0:e1d164542663 | 51 | o Initialize the LCD using the LCD_Init() function. |
bcostm | 0:e1d164542663 | 52 | o Apply the Layer configuration using LCD_LayerDefaultInit() function |
bcostm | 0:e1d164542663 | 53 | o Select the LCD layer to be used using LCD_SelectLayer() function. |
bcostm | 0:e1d164542663 | 54 | o Enable the LCD display using LCD_DisplayOn() function. |
bcostm | 0:e1d164542663 | 55 | |
bcostm | 0:e1d164542663 | 56 | + Options |
bcostm | 0:e1d164542663 | 57 | o Configure and enable the color keying functionality using LCD_SetColorKeying() |
bcostm | 0:e1d164542663 | 58 | function. |
bcostm | 0:e1d164542663 | 59 | o Modify in the fly the transparency and/or the frame buffer address |
bcostm | 0:e1d164542663 | 60 | using the following functions : |
bcostm | 0:e1d164542663 | 61 | - LCD_SetTransparency() |
bcostm | 0:e1d164542663 | 62 | - LCD_SetLayerAddress() |
bcostm | 0:e1d164542663 | 63 | |
bcostm | 0:e1d164542663 | 64 | + Display on LCD |
bcostm | 0:e1d164542663 | 65 | o Clear the hole LCD using LCD_Clear() function or only one specified string |
bcostm | 0:e1d164542663 | 66 | line using LCD_ClearStringLine() function. |
bcostm | 0:e1d164542663 | 67 | o Display a character on the specified line and column using LCD_DisplayChar() |
bcostm | 0:e1d164542663 | 68 | function or a complete string line using LCD_DisplayStringAtLine() function. |
bcostm | 0:e1d164542663 | 69 | o Display a string line on the specified position (x,y in pixel) and align mode |
bcostm | 0:e1d164542663 | 70 | using LCD_DisplayStringAtLine() function. |
bcostm | 0:e1d164542663 | 71 | o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap) |
bcostm | 0:e1d164542663 | 72 | on LCD using the available set of functions |
bcostm | 0:e1d164542663 | 73 | |
bcostm | 0:e1d164542663 | 74 | ------------------------------------------------------------------------------*/ |
bcostm | 0:e1d164542663 | 75 | |
bcostm | 0:e1d164542663 | 76 | /* Includes ------------------------------------------------------------------*/ |
bcostm | 0:e1d164542663 | 77 | #include "stm32f429i_discovery_lcd.h" |
bcostm | 0:e1d164542663 | 78 | #include "../Fonts/fonts.h" |
bcostm | 0:e1d164542663 | 79 | //#include "../Fonts/font24.c" |
bcostm | 0:e1d164542663 | 80 | //#include "../Fonts/font20.c" |
bcostm | 0:e1d164542663 | 81 | //#include "../Fonts/font16.c" |
bcostm | 0:e1d164542663 | 82 | //#include "../Fonts/font12.c" |
bcostm | 0:e1d164542663 | 83 | //#include "../Fonts/font8.c" |
bcostm | 0:e1d164542663 | 84 | |
bcostm | 0:e1d164542663 | 85 | /** @addtogroup BSP |
bcostm | 0:e1d164542663 | 86 | * @{ |
bcostm | 0:e1d164542663 | 87 | */ |
bcostm | 0:e1d164542663 | 88 | |
bcostm | 0:e1d164542663 | 89 | /** @addtogroup STM32F429I_DISCOVERY |
bcostm | 0:e1d164542663 | 90 | * @{ |
bcostm | 0:e1d164542663 | 91 | */ |
bcostm | 0:e1d164542663 | 92 | |
bcostm | 0:e1d164542663 | 93 | /** @defgroup STM32F429I_DISCOVERY_LCD |
bcostm | 0:e1d164542663 | 94 | * @brief This file includes the LCD driver for (ILI9341) |
bcostm | 0:e1d164542663 | 95 | * @{ |
bcostm | 0:e1d164542663 | 96 | */ |
bcostm | 0:e1d164542663 | 97 | |
bcostm | 0:e1d164542663 | 98 | /** @defgroup STM32F429I_DISCOVERY_LCD_Private_TypesDefinitions |
bcostm | 0:e1d164542663 | 99 | * @{ |
bcostm | 0:e1d164542663 | 100 | */ |
bcostm | 0:e1d164542663 | 101 | /** |
bcostm | 0:e1d164542663 | 102 | * @} |
bcostm | 0:e1d164542663 | 103 | */ |
bcostm | 0:e1d164542663 | 104 | |
bcostm | 0:e1d164542663 | 105 | /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Defines |
bcostm | 0:e1d164542663 | 106 | * @{ |
bcostm | 0:e1d164542663 | 107 | */ |
bcostm | 0:e1d164542663 | 108 | #define POLY_X(Z) ((int32_t)((Points + Z)->X)) |
bcostm | 0:e1d164542663 | 109 | #define POLY_Y(Z) ((int32_t)((Points + Z)->Y)) |
bcostm | 0:e1d164542663 | 110 | /** |
bcostm | 0:e1d164542663 | 111 | * @} |
bcostm | 0:e1d164542663 | 112 | */ |
bcostm | 0:e1d164542663 | 113 | |
bcostm | 0:e1d164542663 | 114 | /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Macros |
bcostm | 0:e1d164542663 | 115 | * @{ |
bcostm | 0:e1d164542663 | 116 | */ |
bcostm | 0:e1d164542663 | 117 | #define ABS(X) ((X) > 0 ? (X) : -(X)) |
bcostm | 0:e1d164542663 | 118 | /** |
bcostm | 0:e1d164542663 | 119 | * @} |
bcostm | 0:e1d164542663 | 120 | */ |
bcostm | 0:e1d164542663 | 121 | |
bcostm | 0:e1d164542663 | 122 | /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Variables |
bcostm | 0:e1d164542663 | 123 | * @{ |
bcostm | 0:e1d164542663 | 124 | */ |
bcostm | 0:e1d164542663 | 125 | static LTDC_HandleTypeDef LtdcHandler; |
bcostm | 0:e1d164542663 | 126 | static DMA2D_HandleTypeDef Dma2dHandler; |
bcostm | 0:e1d164542663 | 127 | static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; |
bcostm | 0:e1d164542663 | 128 | |
bcostm | 0:e1d164542663 | 129 | /* Default LCD configuration with LCD Layer 1 */ |
bcostm | 0:e1d164542663 | 130 | static uint32_t ActiveLayer = 0; |
bcostm | 0:e1d164542663 | 131 | static LCD_DrawPropTypeDef DrawProp[MAX_LAYER_NUMBER]; |
bcostm | 0:e1d164542663 | 132 | LCD_DrvTypeDef *LcdDrv; |
bcostm | 0:e1d164542663 | 133 | /** |
bcostm | 0:e1d164542663 | 134 | * @} |
bcostm | 0:e1d164542663 | 135 | */ |
bcostm | 0:e1d164542663 | 136 | |
bcostm | 0:e1d164542663 | 137 | /** @defgroup STM32F429I_DISCOVERY_LCD_Private_FunctionPrototypes |
bcostm | 0:e1d164542663 | 138 | * @{ |
bcostm | 0:e1d164542663 | 139 | */ |
bcostm | 0:e1d164542663 | 140 | static void MspInit(void); |
bcostm | 0:e1d164542663 | 141 | static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c); |
bcostm | 0:e1d164542663 | 142 | static void FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex); |
bcostm | 0:e1d164542663 | 143 | static void ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode); |
bcostm | 0:e1d164542663 | 144 | /** |
bcostm | 0:e1d164542663 | 145 | * @} |
bcostm | 0:e1d164542663 | 146 | */ |
bcostm | 0:e1d164542663 | 147 | |
bcostm | 0:e1d164542663 | 148 | /** @defgroup STM32F429I_DISCOVERY_LCD_Private_Functions |
bcostm | 0:e1d164542663 | 149 | * @{ |
bcostm | 0:e1d164542663 | 150 | */ |
bcostm | 0:e1d164542663 | 151 | |
bcostm | 0:e1d164542663 | 152 | /** |
bcostm | 0:e1d164542663 | 153 | * @brief Initializes the LCD. |
bcostm | 0:e1d164542663 | 154 | * @param None |
bcostm | 0:e1d164542663 | 155 | * @retval LCD state |
bcostm | 0:e1d164542663 | 156 | */ |
bcostm | 0:e1d164542663 | 157 | uint8_t BSP_LCD_Init(void) |
bcostm | 0:e1d164542663 | 158 | { |
bcostm | 0:e1d164542663 | 159 | /* On STM32F429I-DISCO, it is not possible to read ILI9341 ID because */ |
bcostm | 0:e1d164542663 | 160 | /* PIN EXTC is not connected to VDD and then LCD_READ_ID4 is not accessible. */ |
bcostm | 0:e1d164542663 | 161 | /* In this case, ReadID function is bypassed.*/ |
bcostm | 0:e1d164542663 | 162 | /*if(ili9341_drv.ReadID() == ILI9341_ID)*/ |
bcostm | 0:e1d164542663 | 163 | |
bcostm | 0:e1d164542663 | 164 | /* LTDC Configuration ----------------------------------------------------*/ |
bcostm | 0:e1d164542663 | 165 | LtdcHandler.Instance = LTDC; |
bcostm | 0:e1d164542663 | 166 | |
bcostm | 0:e1d164542663 | 167 | /* Timing configuration (Typical configuration from ILI9341 datasheet) |
bcostm | 0:e1d164542663 | 168 | HSYNC=10 (9+1) |
bcostm | 0:e1d164542663 | 169 | HBP=20 (29-10+1) |
bcostm | 0:e1d164542663 | 170 | ActiveW=240 (269-20-10+1) |
bcostm | 0:e1d164542663 | 171 | HFP=10 (279-240-20-10+1) |
bcostm | 0:e1d164542663 | 172 | |
bcostm | 0:e1d164542663 | 173 | VSYNC=2 (1+1) |
bcostm | 0:e1d164542663 | 174 | VBP=2 (3-2+1) |
bcostm | 0:e1d164542663 | 175 | ActiveH=320 (323-2-2+1) |
bcostm | 0:e1d164542663 | 176 | VFP=4 (327-320-2-2+1) |
bcostm | 0:e1d164542663 | 177 | */ |
bcostm | 0:e1d164542663 | 178 | |
bcostm | 0:e1d164542663 | 179 | /* Configure horizontal synchronization width */ |
bcostm | 0:e1d164542663 | 180 | LtdcHandler.Init.HorizontalSync = ILI9341_HSYNC; |
bcostm | 0:e1d164542663 | 181 | /* Configure vertical synchronization height */ |
bcostm | 0:e1d164542663 | 182 | LtdcHandler.Init.VerticalSync = ILI9341_VSYNC; |
bcostm | 0:e1d164542663 | 183 | /* Configure accumulated horizontal back porch */ |
bcostm | 0:e1d164542663 | 184 | LtdcHandler.Init.AccumulatedHBP = ILI9341_HBP; |
bcostm | 0:e1d164542663 | 185 | /* Configure accumulated vertical back porch */ |
bcostm | 0:e1d164542663 | 186 | LtdcHandler.Init.AccumulatedVBP = ILI9341_VBP; |
bcostm | 0:e1d164542663 | 187 | /* Configure accumulated active width */ |
bcostm | 0:e1d164542663 | 188 | LtdcHandler.Init.AccumulatedActiveW = 269; |
bcostm | 0:e1d164542663 | 189 | /* Configure accumulated active height */ |
bcostm | 0:e1d164542663 | 190 | LtdcHandler.Init.AccumulatedActiveH = 323; |
bcostm | 0:e1d164542663 | 191 | /* Configure total width */ |
bcostm | 0:e1d164542663 | 192 | LtdcHandler.Init.TotalWidth = 279; |
bcostm | 0:e1d164542663 | 193 | /* Configure total height */ |
bcostm | 0:e1d164542663 | 194 | LtdcHandler.Init.TotalHeigh = 327; |
bcostm | 0:e1d164542663 | 195 | |
bcostm | 0:e1d164542663 | 196 | /* Configure R,G,B component values for LCD background color */ |
bcostm | 0:e1d164542663 | 197 | LtdcHandler.Init.Backcolor.Red= 0; |
bcostm | 0:e1d164542663 | 198 | LtdcHandler.Init.Backcolor.Blue= 0; |
bcostm | 0:e1d164542663 | 199 | LtdcHandler.Init.Backcolor.Green= 0; |
bcostm | 0:e1d164542663 | 200 | |
bcostm | 0:e1d164542663 | 201 | /* LCD clock configuration */ |
bcostm | 0:e1d164542663 | 202 | /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ |
bcostm | 0:e1d164542663 | 203 | /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 Mhz */ |
bcostm | 0:e1d164542663 | 204 | /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 Mhz */ |
bcostm | 0:e1d164542663 | 205 | /* LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_8 = 48/4 = 6Mhz */ |
bcostm | 0:e1d164542663 | 206 | PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; |
bcostm | 0:e1d164542663 | 207 | PeriphClkInitStruct.PLLSAI.PLLSAIN = 192; |
bcostm | 0:e1d164542663 | 208 | PeriphClkInitStruct.PLLSAI.PLLSAIR = 4; |
bcostm | 0:e1d164542663 | 209 | PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8; |
bcostm | 0:e1d164542663 | 210 | HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); |
bcostm | 0:e1d164542663 | 211 | |
bcostm | 0:e1d164542663 | 212 | /* Polarity */ |
bcostm | 0:e1d164542663 | 213 | LtdcHandler.Init.HSPolarity = LTDC_HSPOLARITY_AL; |
bcostm | 0:e1d164542663 | 214 | LtdcHandler.Init.VSPolarity = LTDC_VSPOLARITY_AL; |
bcostm | 0:e1d164542663 | 215 | LtdcHandler.Init.DEPolarity = LTDC_DEPOLARITY_AL; |
bcostm | 0:e1d164542663 | 216 | LtdcHandler.Init.PCPolarity = LTDC_PCPOLARITY_IPC; |
bcostm | 0:e1d164542663 | 217 | |
bcostm | 0:e1d164542663 | 218 | MspInit(); |
bcostm | 0:e1d164542663 | 219 | HAL_LTDC_Init(&LtdcHandler); |
bcostm | 0:e1d164542663 | 220 | |
bcostm | 0:e1d164542663 | 221 | /* Select the device */ |
bcostm | 0:e1d164542663 | 222 | LcdDrv = &ili9341_drv; |
bcostm | 0:e1d164542663 | 223 | |
bcostm | 0:e1d164542663 | 224 | /* LCD Init */ |
bcostm | 0:e1d164542663 | 225 | LcdDrv->Init(); |
bcostm | 0:e1d164542663 | 226 | |
bcostm | 0:e1d164542663 | 227 | /* Initialize the SDRAM */ |
bcostm | 0:e1d164542663 | 228 | BSP_SDRAM_Init(); |
bcostm | 0:e1d164542663 | 229 | |
bcostm | 0:e1d164542663 | 230 | /* Initialize the font */ |
bcostm | 0:e1d164542663 | 231 | BSP_LCD_SetFont(&LCD_DEFAULT_FONT); |
bcostm | 0:e1d164542663 | 232 | |
bcostm | 0:e1d164542663 | 233 | return LCD_OK; |
bcostm | 0:e1d164542663 | 234 | } |
bcostm | 0:e1d164542663 | 235 | |
bcostm | 0:e1d164542663 | 236 | /** |
bcostm | 0:e1d164542663 | 237 | * @brief Gets the LCD X size. |
bcostm | 0:e1d164542663 | 238 | * @param None |
bcostm | 0:e1d164542663 | 239 | * @retval The used LCD X size |
bcostm | 0:e1d164542663 | 240 | */ |
bcostm | 0:e1d164542663 | 241 | uint32_t BSP_LCD_GetXSize(void) |
bcostm | 0:e1d164542663 | 242 | { |
bcostm | 0:e1d164542663 | 243 | return LcdDrv->GetLcdPixelWidth(); |
bcostm | 0:e1d164542663 | 244 | } |
bcostm | 0:e1d164542663 | 245 | |
bcostm | 0:e1d164542663 | 246 | /** |
bcostm | 0:e1d164542663 | 247 | * @brief Gets the LCD Y size. |
bcostm | 0:e1d164542663 | 248 | * @param None |
bcostm | 0:e1d164542663 | 249 | * @retval The used LCD Y size |
bcostm | 0:e1d164542663 | 250 | */ |
bcostm | 0:e1d164542663 | 251 | uint32_t BSP_LCD_GetYSize(void) |
bcostm | 0:e1d164542663 | 252 | { |
bcostm | 0:e1d164542663 | 253 | return LcdDrv->GetLcdPixelHeight(); |
bcostm | 0:e1d164542663 | 254 | } |
bcostm | 0:e1d164542663 | 255 | |
bcostm | 0:e1d164542663 | 256 | /** |
bcostm | 0:e1d164542663 | 257 | * @brief Initializes the LCD layers. |
bcostm | 0:e1d164542663 | 258 | * @param LayerIndex: the layer foreground or background. |
bcostm | 0:e1d164542663 | 259 | * @param FB_Address: the layer frame buffer. |
bcostm | 0:e1d164542663 | 260 | * @retval None |
bcostm | 0:e1d164542663 | 261 | */ |
bcostm | 0:e1d164542663 | 262 | void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address) |
bcostm | 0:e1d164542663 | 263 | { |
bcostm | 0:e1d164542663 | 264 | LCD_LayerCfgTypeDef Layercfg; |
bcostm | 0:e1d164542663 | 265 | |
bcostm | 0:e1d164542663 | 266 | /* Layer Init */ |
bcostm | 0:e1d164542663 | 267 | Layercfg.WindowX0 = 0; |
bcostm | 0:e1d164542663 | 268 | Layercfg.WindowX1 = BSP_LCD_GetXSize(); |
bcostm | 0:e1d164542663 | 269 | Layercfg.WindowY0 = 0; |
bcostm | 0:e1d164542663 | 270 | Layercfg.WindowY1 = BSP_LCD_GetYSize(); |
bcostm | 0:e1d164542663 | 271 | Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888; |
bcostm | 0:e1d164542663 | 272 | Layercfg.FBStartAdress = FB_Address; |
bcostm | 0:e1d164542663 | 273 | Layercfg.Alpha = 255; |
bcostm | 0:e1d164542663 | 274 | Layercfg.Alpha0 = 0; |
bcostm | 0:e1d164542663 | 275 | Layercfg.Backcolor.Blue = 0; |
bcostm | 0:e1d164542663 | 276 | Layercfg.Backcolor.Green = 0; |
bcostm | 0:e1d164542663 | 277 | Layercfg.Backcolor.Red = 0; |
bcostm | 0:e1d164542663 | 278 | Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA; |
bcostm | 0:e1d164542663 | 279 | Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA; |
bcostm | 0:e1d164542663 | 280 | Layercfg.ImageWidth = BSP_LCD_GetXSize(); |
bcostm | 0:e1d164542663 | 281 | Layercfg.ImageHeight = BSP_LCD_GetYSize(); |
bcostm | 0:e1d164542663 | 282 | |
bcostm | 0:e1d164542663 | 283 | HAL_LTDC_ConfigLayer(&LtdcHandler, &Layercfg, LayerIndex); |
bcostm | 0:e1d164542663 | 284 | |
bcostm | 0:e1d164542663 | 285 | DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE; |
bcostm | 0:e1d164542663 | 286 | DrawProp[LayerIndex].pFont = &Font24; |
bcostm | 0:e1d164542663 | 287 | DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK; |
bcostm | 0:e1d164542663 | 288 | |
bcostm | 0:e1d164542663 | 289 | /* Dithering activation */ |
bcostm | 0:e1d164542663 | 290 | HAL_LTDC_EnableDither(&LtdcHandler); |
bcostm | 0:e1d164542663 | 291 | } |
bcostm | 0:e1d164542663 | 292 | |
bcostm | 0:e1d164542663 | 293 | /** |
bcostm | 0:e1d164542663 | 294 | * @brief Selects the LCD Layer. |
bcostm | 0:e1d164542663 | 295 | * @param LayerIndex: the Layer foreground or background. |
bcostm | 0:e1d164542663 | 296 | * @retval None |
bcostm | 0:e1d164542663 | 297 | */ |
bcostm | 0:e1d164542663 | 298 | void BSP_LCD_SelectLayer(uint32_t LayerIndex) |
bcostm | 0:e1d164542663 | 299 | { |
bcostm | 0:e1d164542663 | 300 | ActiveLayer = LayerIndex; |
bcostm | 0:e1d164542663 | 301 | } |
bcostm | 0:e1d164542663 | 302 | |
bcostm | 0:e1d164542663 | 303 | /** |
bcostm | 0:e1d164542663 | 304 | * @brief Sets a LCD Layer visible. |
bcostm | 0:e1d164542663 | 305 | * @param LayerIndex: the visible Layer. |
bcostm | 0:e1d164542663 | 306 | * @param state: new state of the specified layer. |
bcostm | 0:e1d164542663 | 307 | * This parameter can be: ENABLE or DISABLE. |
bcostm | 0:e1d164542663 | 308 | * @retval None |
bcostm | 0:e1d164542663 | 309 | */ |
bcostm | 0:e1d164542663 | 310 | void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState state) |
bcostm | 0:e1d164542663 | 311 | { |
bcostm | 0:e1d164542663 | 312 | if(state == ENABLE) |
bcostm | 0:e1d164542663 | 313 | { |
bcostm | 0:e1d164542663 | 314 | __HAL_LTDC_LAYER_ENABLE(&LtdcHandler, LayerIndex); |
bcostm | 0:e1d164542663 | 315 | } |
bcostm | 0:e1d164542663 | 316 | else |
bcostm | 0:e1d164542663 | 317 | { |
bcostm | 0:e1d164542663 | 318 | __HAL_LTDC_LAYER_DISABLE(&LtdcHandler, LayerIndex); |
bcostm | 0:e1d164542663 | 319 | } |
bcostm | 0:e1d164542663 | 320 | __HAL_LTDC_RELOAD_CONFIG(&LtdcHandler); |
bcostm | 0:e1d164542663 | 321 | } |
bcostm | 0:e1d164542663 | 322 | |
bcostm | 0:e1d164542663 | 323 | /** |
bcostm | 0:e1d164542663 | 324 | * @brief Configures the Transparency. |
bcostm | 0:e1d164542663 | 325 | * @param LayerIndex: the Layer foreground or background. |
bcostm | 0:e1d164542663 | 326 | * @param Transparency: the Transparency, |
bcostm | 0:e1d164542663 | 327 | * This parameter must range from 0x00 to 0xFF. |
bcostm | 0:e1d164542663 | 328 | * @retval None |
bcostm | 0:e1d164542663 | 329 | */ |
bcostm | 0:e1d164542663 | 330 | void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency) |
bcostm | 0:e1d164542663 | 331 | { |
bcostm | 0:e1d164542663 | 332 | HAL_LTDC_SetAlpha(&LtdcHandler, Transparency, LayerIndex); |
bcostm | 0:e1d164542663 | 333 | } |
bcostm | 0:e1d164542663 | 334 | |
bcostm | 0:e1d164542663 | 335 | /** |
bcostm | 0:e1d164542663 | 336 | * @brief Sets a LCD layer frame buffer address. |
bcostm | 0:e1d164542663 | 337 | * @param LayerIndex: specifies the Layer foreground or background |
bcostm | 0:e1d164542663 | 338 | * @param Address: new LCD frame buffer value |
bcostm | 0:e1d164542663 | 339 | * @retval None |
bcostm | 0:e1d164542663 | 340 | */ |
bcostm | 0:e1d164542663 | 341 | void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address) |
bcostm | 0:e1d164542663 | 342 | { |
bcostm | 0:e1d164542663 | 343 | HAL_LTDC_SetAddress(&LtdcHandler, Address, LayerIndex); |
bcostm | 0:e1d164542663 | 344 | } |
bcostm | 0:e1d164542663 | 345 | |
bcostm | 0:e1d164542663 | 346 | /** |
bcostm | 0:e1d164542663 | 347 | * @brief Sets the Display window. |
bcostm | 0:e1d164542663 | 348 | * @param LayerIndex: layer index |
bcostm | 0:e1d164542663 | 349 | * @param Xpos: LCD X position |
bcostm | 0:e1d164542663 | 350 | * @param Ypos: LCD Y position |
bcostm | 0:e1d164542663 | 351 | * @param Width: LCD window width |
bcostm | 0:e1d164542663 | 352 | * @param Height: LCD window height |
bcostm | 0:e1d164542663 | 353 | * @retval None |
bcostm | 0:e1d164542663 | 354 | */ |
bcostm | 0:e1d164542663 | 355 | void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) |
bcostm | 0:e1d164542663 | 356 | { |
bcostm | 0:e1d164542663 | 357 | /* reconfigure the layer size */ |
bcostm | 0:e1d164542663 | 358 | HAL_LTDC_SetWindowSize(&LtdcHandler, Width, Height, LayerIndex); |
bcostm | 0:e1d164542663 | 359 | |
bcostm | 0:e1d164542663 | 360 | /* reconfigure the layer position */ |
bcostm | 0:e1d164542663 | 361 | HAL_LTDC_SetWindowPosition(&LtdcHandler, Xpos, Ypos, LayerIndex); |
bcostm | 0:e1d164542663 | 362 | } |
bcostm | 0:e1d164542663 | 363 | |
bcostm | 0:e1d164542663 | 364 | /** |
bcostm | 0:e1d164542663 | 365 | * @brief Configures and sets the color Keying. |
bcostm | 0:e1d164542663 | 366 | * @param LayerIndex: the Layer foreground or background |
bcostm | 0:e1d164542663 | 367 | * @param RGBValue: the Color reference |
bcostm | 0:e1d164542663 | 368 | * @retval None |
bcostm | 0:e1d164542663 | 369 | */ |
bcostm | 0:e1d164542663 | 370 | void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue) |
bcostm | 0:e1d164542663 | 371 | { |
bcostm | 0:e1d164542663 | 372 | /* Configure and Enable the color Keying for LCD Layer */ |
bcostm | 0:e1d164542663 | 373 | HAL_LTDC_ConfigColorKeying(&LtdcHandler, RGBValue, LayerIndex); |
bcostm | 0:e1d164542663 | 374 | HAL_LTDC_EnableColorKeying(&LtdcHandler, LayerIndex); |
bcostm | 0:e1d164542663 | 375 | } |
bcostm | 0:e1d164542663 | 376 | |
bcostm | 0:e1d164542663 | 377 | /** |
bcostm | 0:e1d164542663 | 378 | * @brief Disables the color Keying. |
bcostm | 0:e1d164542663 | 379 | * @param LayerIndex: the Layer foreground or background |
bcostm | 0:e1d164542663 | 380 | * @retval None |
bcostm | 0:e1d164542663 | 381 | */ |
bcostm | 0:e1d164542663 | 382 | void BSP_LCD_ResetColorKeying(uint32_t LayerIndex) |
bcostm | 0:e1d164542663 | 383 | { |
bcostm | 0:e1d164542663 | 384 | /* Disable the color Keying for LCD Layer */ |
bcostm | 0:e1d164542663 | 385 | HAL_LTDC_DisableColorKeying(&LtdcHandler, LayerIndex); |
bcostm | 0:e1d164542663 | 386 | } |
bcostm | 0:e1d164542663 | 387 | |
bcostm | 0:e1d164542663 | 388 | /** |
bcostm | 0:e1d164542663 | 389 | * @brief Gets the LCD Text color. |
bcostm | 0:e1d164542663 | 390 | * @param None |
bcostm | 0:e1d164542663 | 391 | * @retval Text color |
bcostm | 0:e1d164542663 | 392 | */ |
bcostm | 0:e1d164542663 | 393 | uint32_t BSP_LCD_GetTextColor(void) |
bcostm | 0:e1d164542663 | 394 | { |
bcostm | 0:e1d164542663 | 395 | return DrawProp[ActiveLayer].TextColor; |
bcostm | 0:e1d164542663 | 396 | } |
bcostm | 0:e1d164542663 | 397 | |
bcostm | 0:e1d164542663 | 398 | /** |
bcostm | 0:e1d164542663 | 399 | * @brief Gets the LCD Background color. |
bcostm | 0:e1d164542663 | 400 | * @param None |
bcostm | 0:e1d164542663 | 401 | * @retval Background color |
bcostm | 0:e1d164542663 | 402 | */ |
bcostm | 0:e1d164542663 | 403 | uint32_t BSP_LCD_GetBackColor(void) |
bcostm | 0:e1d164542663 | 404 | { |
bcostm | 0:e1d164542663 | 405 | return DrawProp[ActiveLayer].BackColor; |
bcostm | 0:e1d164542663 | 406 | } |
bcostm | 0:e1d164542663 | 407 | |
bcostm | 0:e1d164542663 | 408 | /** |
bcostm | 0:e1d164542663 | 409 | * @brief Sets the Text color. |
bcostm | 0:e1d164542663 | 410 | * @param Color: the Text color code ARGB(8-8-8-8) |
bcostm | 0:e1d164542663 | 411 | * @retval None |
bcostm | 0:e1d164542663 | 412 | */ |
bcostm | 0:e1d164542663 | 413 | void BSP_LCD_SetTextColor(uint32_t Color) |
bcostm | 0:e1d164542663 | 414 | { |
bcostm | 0:e1d164542663 | 415 | DrawProp[ActiveLayer].TextColor = Color; |
bcostm | 0:e1d164542663 | 416 | } |
bcostm | 0:e1d164542663 | 417 | |
bcostm | 0:e1d164542663 | 418 | /** |
bcostm | 0:e1d164542663 | 419 | * @brief Sets the Background color. |
bcostm | 0:e1d164542663 | 420 | * @param Color: the layer Background color code ARGB(8-8-8-8) |
bcostm | 0:e1d164542663 | 421 | * @retval None |
bcostm | 0:e1d164542663 | 422 | */ |
bcostm | 0:e1d164542663 | 423 | void BSP_LCD_SetBackColor(uint32_t Color) |
bcostm | 0:e1d164542663 | 424 | { |
bcostm | 0:e1d164542663 | 425 | DrawProp[ActiveLayer].BackColor = Color; |
bcostm | 0:e1d164542663 | 426 | } |
bcostm | 0:e1d164542663 | 427 | |
bcostm | 0:e1d164542663 | 428 | /** |
bcostm | 0:e1d164542663 | 429 | * @brief Sets the Text Font. |
bcostm | 0:e1d164542663 | 430 | * @param pFonts: the layer font to be used |
bcostm | 0:e1d164542663 | 431 | * @retval None |
bcostm | 0:e1d164542663 | 432 | */ |
bcostm | 0:e1d164542663 | 433 | void BSP_LCD_SetFont(sFONT *pFonts) |
bcostm | 0:e1d164542663 | 434 | { |
bcostm | 0:e1d164542663 | 435 | DrawProp[ActiveLayer].pFont = pFonts; |
bcostm | 0:e1d164542663 | 436 | } |
bcostm | 0:e1d164542663 | 437 | |
bcostm | 0:e1d164542663 | 438 | /** |
bcostm | 0:e1d164542663 | 439 | * @brief Gets the Text Font. |
bcostm | 0:e1d164542663 | 440 | * @param None |
bcostm | 0:e1d164542663 | 441 | * @retval Layer font |
bcostm | 0:e1d164542663 | 442 | */ |
bcostm | 0:e1d164542663 | 443 | sFONT *BSP_LCD_GetFont(void) |
bcostm | 0:e1d164542663 | 444 | { |
bcostm | 0:e1d164542663 | 445 | return DrawProp[ActiveLayer].pFont; |
bcostm | 0:e1d164542663 | 446 | } |
bcostm | 0:e1d164542663 | 447 | |
bcostm | 0:e1d164542663 | 448 | /** |
bcostm | 0:e1d164542663 | 449 | * @brief Reads Pixel. |
bcostm | 0:e1d164542663 | 450 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 451 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 452 | * @retval RGB pixel color |
bcostm | 0:e1d164542663 | 453 | */ |
bcostm | 0:e1d164542663 | 454 | uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos) |
bcostm | 0:e1d164542663 | 455 | { |
bcostm | 0:e1d164542663 | 456 | uint32_t ret = 0; |
bcostm | 0:e1d164542663 | 457 | |
bcostm | 0:e1d164542663 | 458 | if(LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888) |
bcostm | 0:e1d164542663 | 459 | { |
bcostm | 0:e1d164542663 | 460 | /* Read data value from SDRAM memory */ |
bcostm | 0:e1d164542663 | 461 | ret = *(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); |
bcostm | 0:e1d164542663 | 462 | } |
bcostm | 0:e1d164542663 | 463 | else if(LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888) |
bcostm | 0:e1d164542663 | 464 | { |
bcostm | 0:e1d164542663 | 465 | /* Read data value from SDRAM memory */ |
bcostm | 0:e1d164542663 | 466 | ret = (*(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF); |
bcostm | 0:e1d164542663 | 467 | } |
bcostm | 0:e1d164542663 | 468 | else if((LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \ |
bcostm | 0:e1d164542663 | 469 | (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \ |
bcostm | 0:e1d164542663 | 470 | (LtdcHandler.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88)) |
bcostm | 0:e1d164542663 | 471 | { |
bcostm | 0:e1d164542663 | 472 | /* Read data value from SDRAM memory */ |
bcostm | 0:e1d164542663 | 473 | ret = *(__IO uint16_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); |
bcostm | 0:e1d164542663 | 474 | } |
bcostm | 0:e1d164542663 | 475 | else |
bcostm | 0:e1d164542663 | 476 | { |
bcostm | 0:e1d164542663 | 477 | /* Read data value from SDRAM memory */ |
bcostm | 0:e1d164542663 | 478 | ret = *(__IO uint8_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos))); |
bcostm | 0:e1d164542663 | 479 | } |
bcostm | 0:e1d164542663 | 480 | |
bcostm | 0:e1d164542663 | 481 | return ret; |
bcostm | 0:e1d164542663 | 482 | } |
bcostm | 0:e1d164542663 | 483 | |
bcostm | 0:e1d164542663 | 484 | /** |
bcostm | 0:e1d164542663 | 485 | * @brief Clears the hole LCD. |
bcostm | 0:e1d164542663 | 486 | * @param Color: the color of the background |
bcostm | 0:e1d164542663 | 487 | * @retval None |
bcostm | 0:e1d164542663 | 488 | */ |
bcostm | 0:e1d164542663 | 489 | void BSP_LCD_Clear(uint32_t Color) |
bcostm | 0:e1d164542663 | 490 | { |
bcostm | 0:e1d164542663 | 491 | /* Clear the LCD */ |
bcostm | 0:e1d164542663 | 492 | FillBuffer(ActiveLayer, (uint32_t *)(LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color); |
bcostm | 0:e1d164542663 | 493 | } |
bcostm | 0:e1d164542663 | 494 | |
bcostm | 0:e1d164542663 | 495 | /** |
bcostm | 0:e1d164542663 | 496 | * @brief Clears the selected line. |
bcostm | 0:e1d164542663 | 497 | * @param Line: the line to be cleared |
bcostm | 0:e1d164542663 | 498 | * @retval None |
bcostm | 0:e1d164542663 | 499 | */ |
bcostm | 0:e1d164542663 | 500 | void BSP_LCD_ClearStringLine(uint32_t Line) |
bcostm | 0:e1d164542663 | 501 | { |
bcostm | 0:e1d164542663 | 502 | uint32_t colorbackup = DrawProp[ActiveLayer].TextColor; |
bcostm | 0:e1d164542663 | 503 | DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor; |
bcostm | 0:e1d164542663 | 504 | |
bcostm | 0:e1d164542663 | 505 | /* Draw rectangle with background color */ |
bcostm | 0:e1d164542663 | 506 | BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height); |
bcostm | 0:e1d164542663 | 507 | |
bcostm | 0:e1d164542663 | 508 | DrawProp[ActiveLayer].TextColor = colorbackup; |
bcostm | 0:e1d164542663 | 509 | BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 510 | } |
bcostm | 0:e1d164542663 | 511 | |
bcostm | 0:e1d164542663 | 512 | /** |
bcostm | 0:e1d164542663 | 513 | * @brief Displays one character. |
bcostm | 0:e1d164542663 | 514 | * @param Xpos: start column address |
bcostm | 0:e1d164542663 | 515 | * @param Ypos: the Line where to display the character shape |
bcostm | 0:e1d164542663 | 516 | * @param Ascii: character ascii code, must be between 0x20 and 0x7E |
bcostm | 0:e1d164542663 | 517 | * @retval None |
bcostm | 0:e1d164542663 | 518 | */ |
bcostm | 0:e1d164542663 | 519 | void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) |
bcostm | 0:e1d164542663 | 520 | { |
bcostm | 0:e1d164542663 | 521 | DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\ |
bcostm | 0:e1d164542663 | 522 | DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]); |
bcostm | 0:e1d164542663 | 523 | } |
bcostm | 0:e1d164542663 | 524 | |
bcostm | 0:e1d164542663 | 525 | /** |
bcostm | 0:e1d164542663 | 526 | * @brief Displays a maximum of 60 char on the LCD. |
bcostm | 0:e1d164542663 | 527 | * @param X: pointer to x position (in pixel) |
bcostm | 0:e1d164542663 | 528 | * @param Y: pointer to y position (in pixel) |
bcostm | 0:e1d164542663 | 529 | * @param pText: pointer to string to display on LCD |
bcostm | 0:e1d164542663 | 530 | * @param mode: The display mode |
bcostm | 0:e1d164542663 | 531 | * This parameter can be one of the following values: |
bcostm | 0:e1d164542663 | 532 | * @arg CENTER_MODE |
bcostm | 0:e1d164542663 | 533 | * @arg RIGHT_MODE |
bcostm | 0:e1d164542663 | 534 | * @arg LEFT_MODE |
bcostm | 0:e1d164542663 | 535 | * @retval None |
bcostm | 0:e1d164542663 | 536 | */ |
bcostm | 0:e1d164542663 | 537 | void BSP_LCD_DisplayStringAt(uint16_t X, uint16_t Y, uint8_t *pText, Text_AlignModeTypdef mode) |
bcostm | 0:e1d164542663 | 538 | { |
bcostm | 0:e1d164542663 | 539 | uint16_t refcolumn = 1, i = 0; |
bcostm | 0:e1d164542663 | 540 | uint32_t size = 0, xsize = 0; |
bcostm | 0:e1d164542663 | 541 | uint8_t *ptr = pText; |
bcostm | 0:e1d164542663 | 542 | |
bcostm | 0:e1d164542663 | 543 | /* Get the text size */ |
bcostm | 0:e1d164542663 | 544 | while (*ptr++) size ++ ; |
bcostm | 0:e1d164542663 | 545 | |
bcostm | 0:e1d164542663 | 546 | /* Characters number per line */ |
bcostm | 0:e1d164542663 | 547 | xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width); |
bcostm | 0:e1d164542663 | 548 | |
bcostm | 0:e1d164542663 | 549 | switch (mode) |
bcostm | 0:e1d164542663 | 550 | { |
bcostm | 0:e1d164542663 | 551 | case CENTER_MODE: |
bcostm | 0:e1d164542663 | 552 | { |
bcostm | 0:e1d164542663 | 553 | refcolumn = X+ ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2; |
bcostm | 0:e1d164542663 | 554 | break; |
bcostm | 0:e1d164542663 | 555 | } |
bcostm | 0:e1d164542663 | 556 | case LEFT_MODE: |
bcostm | 0:e1d164542663 | 557 | { |
bcostm | 0:e1d164542663 | 558 | refcolumn = X; |
bcostm | 0:e1d164542663 | 559 | break; |
bcostm | 0:e1d164542663 | 560 | } |
bcostm | 0:e1d164542663 | 561 | case RIGHT_MODE: |
bcostm | 0:e1d164542663 | 562 | { |
bcostm | 0:e1d164542663 | 563 | refcolumn = X + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width); |
bcostm | 0:e1d164542663 | 564 | break; |
bcostm | 0:e1d164542663 | 565 | } |
bcostm | 0:e1d164542663 | 566 | default: |
bcostm | 0:e1d164542663 | 567 | { |
bcostm | 0:e1d164542663 | 568 | refcolumn = X; |
bcostm | 0:e1d164542663 | 569 | break; |
bcostm | 0:e1d164542663 | 570 | } |
bcostm | 0:e1d164542663 | 571 | } |
bcostm | 0:e1d164542663 | 572 | |
bcostm | 0:e1d164542663 | 573 | /* Send the string character by character on LCD */ |
bcostm | 0:e1d164542663 | 574 | while ((*pText != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width)) |
bcostm | 0:e1d164542663 | 575 | { |
bcostm | 0:e1d164542663 | 576 | /* Display one character on LCD */ |
bcostm | 0:e1d164542663 | 577 | BSP_LCD_DisplayChar(refcolumn, Y, *pText); |
bcostm | 0:e1d164542663 | 578 | /* Decrement the column position by 16 */ |
bcostm | 0:e1d164542663 | 579 | refcolumn += DrawProp[ActiveLayer].pFont->Width; |
bcostm | 0:e1d164542663 | 580 | /* Point on the next character */ |
bcostm | 0:e1d164542663 | 581 | pText++; |
bcostm | 0:e1d164542663 | 582 | i++; |
bcostm | 0:e1d164542663 | 583 | } |
bcostm | 0:e1d164542663 | 584 | } |
bcostm | 0:e1d164542663 | 585 | |
bcostm | 0:e1d164542663 | 586 | /** |
bcostm | 0:e1d164542663 | 587 | * @brief Displays a maximum of 20 char on the LCD. |
bcostm | 0:e1d164542663 | 588 | * @param Line: the Line where to display the character shape |
bcostm | 0:e1d164542663 | 589 | * @param ptr: pointer to string to display on LCD |
bcostm | 0:e1d164542663 | 590 | * @retval None |
bcostm | 0:e1d164542663 | 591 | */ |
bcostm | 0:e1d164542663 | 592 | void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr) |
bcostm | 0:e1d164542663 | 593 | { |
bcostm | 0:e1d164542663 | 594 | BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE); |
bcostm | 0:e1d164542663 | 595 | } |
bcostm | 0:e1d164542663 | 596 | |
bcostm | 0:e1d164542663 | 597 | /** |
bcostm | 0:e1d164542663 | 598 | * @brief Displays an horizontal line. |
bcostm | 0:e1d164542663 | 599 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 600 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 601 | * @param Length: line length |
bcostm | 0:e1d164542663 | 602 | * @retval None |
bcostm | 0:e1d164542663 | 603 | */ |
bcostm | 0:e1d164542663 | 604 | void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) |
bcostm | 0:e1d164542663 | 605 | { |
bcostm | 0:e1d164542663 | 606 | uint32_t xaddress = 0; |
bcostm | 0:e1d164542663 | 607 | |
bcostm | 0:e1d164542663 | 608 | /* Get the line address */ |
bcostm | 0:e1d164542663 | 609 | xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); |
bcostm | 0:e1d164542663 | 610 | |
bcostm | 0:e1d164542663 | 611 | /* Write line */ |
bcostm | 0:e1d164542663 | 612 | FillBuffer(ActiveLayer, (uint32_t *)xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 613 | } |
bcostm | 0:e1d164542663 | 614 | |
bcostm | 0:e1d164542663 | 615 | /** |
bcostm | 0:e1d164542663 | 616 | * @brief Displays a vertical line. |
bcostm | 0:e1d164542663 | 617 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 618 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 619 | * @param Length: line length |
bcostm | 0:e1d164542663 | 620 | * @retval None |
bcostm | 0:e1d164542663 | 621 | */ |
bcostm | 0:e1d164542663 | 622 | void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) |
bcostm | 0:e1d164542663 | 623 | { |
bcostm | 0:e1d164542663 | 624 | uint32_t xaddress = 0; |
bcostm | 0:e1d164542663 | 625 | |
bcostm | 0:e1d164542663 | 626 | /* Get the line address */ |
bcostm | 0:e1d164542663 | 627 | xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); |
bcostm | 0:e1d164542663 | 628 | |
bcostm | 0:e1d164542663 | 629 | /* Write line */ |
bcostm | 0:e1d164542663 | 630 | FillBuffer(ActiveLayer, (uint32_t *)xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 631 | } |
bcostm | 0:e1d164542663 | 632 | |
bcostm | 0:e1d164542663 | 633 | /** |
bcostm | 0:e1d164542663 | 634 | * @brief Displays an uni-line (between two points). |
bcostm | 0:e1d164542663 | 635 | * @param X1: the point 1 X position |
bcostm | 0:e1d164542663 | 636 | * @param Y1: the point 1 Y position |
bcostm | 0:e1d164542663 | 637 | * @param X2: the point 2 X position |
bcostm | 0:e1d164542663 | 638 | * @param Y2: the point 2 Y position |
bcostm | 0:e1d164542663 | 639 | * @retval None |
bcostm | 0:e1d164542663 | 640 | */ |
bcostm | 0:e1d164542663 | 641 | void BSP_LCD_DrawLine(uint16_t X1, uint16_t Y1, uint16_t X2, uint16_t Y2) |
bcostm | 0:e1d164542663 | 642 | { |
bcostm | 0:e1d164542663 | 643 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, |
bcostm | 0:e1d164542663 | 644 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, |
bcostm | 0:e1d164542663 | 645 | curpixel = 0; |
bcostm | 0:e1d164542663 | 646 | |
bcostm | 0:e1d164542663 | 647 | deltax = ABS(X2 - X1); /* The difference between the x's */ |
bcostm | 0:e1d164542663 | 648 | deltay = ABS(Y2 - Y1); /* The difference between the y's */ |
bcostm | 0:e1d164542663 | 649 | x = X1; /* Start x off at the first pixel */ |
bcostm | 0:e1d164542663 | 650 | y = Y1; /* Start y off at the first pixel */ |
bcostm | 0:e1d164542663 | 651 | |
bcostm | 0:e1d164542663 | 652 | if (X2 >= X1) /* The x-values are increasing */ |
bcostm | 0:e1d164542663 | 653 | { |
bcostm | 0:e1d164542663 | 654 | xinc1 = 1; |
bcostm | 0:e1d164542663 | 655 | xinc2 = 1; |
bcostm | 0:e1d164542663 | 656 | } |
bcostm | 0:e1d164542663 | 657 | else /* The x-values are decreasing */ |
bcostm | 0:e1d164542663 | 658 | { |
bcostm | 0:e1d164542663 | 659 | xinc1 = -1; |
bcostm | 0:e1d164542663 | 660 | xinc2 = -1; |
bcostm | 0:e1d164542663 | 661 | } |
bcostm | 0:e1d164542663 | 662 | |
bcostm | 0:e1d164542663 | 663 | if (Y2 >= Y1) /* The y-values are increasing */ |
bcostm | 0:e1d164542663 | 664 | { |
bcostm | 0:e1d164542663 | 665 | yinc1 = 1; |
bcostm | 0:e1d164542663 | 666 | yinc2 = 1; |
bcostm | 0:e1d164542663 | 667 | } |
bcostm | 0:e1d164542663 | 668 | else /* The y-values are decreasing */ |
bcostm | 0:e1d164542663 | 669 | { |
bcostm | 0:e1d164542663 | 670 | yinc1 = -1; |
bcostm | 0:e1d164542663 | 671 | yinc2 = -1; |
bcostm | 0:e1d164542663 | 672 | } |
bcostm | 0:e1d164542663 | 673 | |
bcostm | 0:e1d164542663 | 674 | if (deltax >= deltay) /* There is at least one x-value for every y-value */ |
bcostm | 0:e1d164542663 | 675 | { |
bcostm | 0:e1d164542663 | 676 | xinc1 = 0; /* Don't change the x when numerator >= denominator */ |
bcostm | 0:e1d164542663 | 677 | yinc2 = 0; /* Don't change the y for every iteration */ |
bcostm | 0:e1d164542663 | 678 | den = deltax; |
bcostm | 0:e1d164542663 | 679 | num = deltax / 2; |
bcostm | 0:e1d164542663 | 680 | numadd = deltay; |
bcostm | 0:e1d164542663 | 681 | numpixels = deltax; /* There are more x-values than y-values */ |
bcostm | 0:e1d164542663 | 682 | } |
bcostm | 0:e1d164542663 | 683 | else /* There is at least one y-value for every x-value */ |
bcostm | 0:e1d164542663 | 684 | { |
bcostm | 0:e1d164542663 | 685 | xinc2 = 0; /* Don't change the x for every iteration */ |
bcostm | 0:e1d164542663 | 686 | yinc1 = 0; /* Don't change the y when numerator >= denominator */ |
bcostm | 0:e1d164542663 | 687 | den = deltay; |
bcostm | 0:e1d164542663 | 688 | num = deltay / 2; |
bcostm | 0:e1d164542663 | 689 | numadd = deltax; |
bcostm | 0:e1d164542663 | 690 | numpixels = deltay; /* There are more y-values than x-values */ |
bcostm | 0:e1d164542663 | 691 | } |
bcostm | 0:e1d164542663 | 692 | |
bcostm | 0:e1d164542663 | 693 | for (curpixel = 0; curpixel <= numpixels; curpixel++) |
bcostm | 0:e1d164542663 | 694 | { |
bcostm | 0:e1d164542663 | 695 | BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */ |
bcostm | 0:e1d164542663 | 696 | num += numadd; /* Increase the numerator by the top of the fraction */ |
bcostm | 0:e1d164542663 | 697 | if (num >= den) /* Check if numerator >= denominator */ |
bcostm | 0:e1d164542663 | 698 | { |
bcostm | 0:e1d164542663 | 699 | num -= den; /* Calculate the new numerator value */ |
bcostm | 0:e1d164542663 | 700 | x += xinc1; /* Change the x as appropriate */ |
bcostm | 0:e1d164542663 | 701 | y += yinc1; /* Change the y as appropriate */ |
bcostm | 0:e1d164542663 | 702 | } |
bcostm | 0:e1d164542663 | 703 | x += xinc2; /* Change the x as appropriate */ |
bcostm | 0:e1d164542663 | 704 | y += yinc2; /* Change the y as appropriate */ |
bcostm | 0:e1d164542663 | 705 | } |
bcostm | 0:e1d164542663 | 706 | } |
bcostm | 0:e1d164542663 | 707 | |
bcostm | 0:e1d164542663 | 708 | /** |
bcostm | 0:e1d164542663 | 709 | * @brief Displays a rectangle. |
bcostm | 0:e1d164542663 | 710 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 711 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 712 | * @param Height: display rectangle height |
bcostm | 0:e1d164542663 | 713 | * @param Width: display rectangle width |
bcostm | 0:e1d164542663 | 714 | * @retval None |
bcostm | 0:e1d164542663 | 715 | */ |
bcostm | 0:e1d164542663 | 716 | void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) |
bcostm | 0:e1d164542663 | 717 | { |
bcostm | 0:e1d164542663 | 718 | /* Draw horizontal lines */ |
bcostm | 0:e1d164542663 | 719 | BSP_LCD_DrawHLine(Xpos, Ypos, Width); |
bcostm | 0:e1d164542663 | 720 | BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width); |
bcostm | 0:e1d164542663 | 721 | |
bcostm | 0:e1d164542663 | 722 | /* Draw vertical lines */ |
bcostm | 0:e1d164542663 | 723 | BSP_LCD_DrawVLine(Xpos, Ypos, Height); |
bcostm | 0:e1d164542663 | 724 | BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height); |
bcostm | 0:e1d164542663 | 725 | } |
bcostm | 0:e1d164542663 | 726 | |
bcostm | 0:e1d164542663 | 727 | /** |
bcostm | 0:e1d164542663 | 728 | * @brief Displays a circle. |
bcostm | 0:e1d164542663 | 729 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 730 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 731 | * @param Radius: the circle radius |
bcostm | 0:e1d164542663 | 732 | * @retval None |
bcostm | 0:e1d164542663 | 733 | */ |
bcostm | 0:e1d164542663 | 734 | void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) |
bcostm | 0:e1d164542663 | 735 | { |
bcostm | 0:e1d164542663 | 736 | int32_t d;/* Decision Variable */ |
bcostm | 0:e1d164542663 | 737 | uint32_t curx;/* Current X Value */ |
bcostm | 0:e1d164542663 | 738 | uint32_t cury;/* Current Y Value */ |
bcostm | 0:e1d164542663 | 739 | |
bcostm | 0:e1d164542663 | 740 | d = 3 - (Radius << 1); |
bcostm | 0:e1d164542663 | 741 | curx = 0; |
bcostm | 0:e1d164542663 | 742 | cury = Radius; |
bcostm | 0:e1d164542663 | 743 | |
bcostm | 0:e1d164542663 | 744 | while (curx <= cury) |
bcostm | 0:e1d164542663 | 745 | { |
bcostm | 0:e1d164542663 | 746 | BSP_LCD_DrawPixel((Xpos + curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 747 | BSP_LCD_DrawPixel((Xpos - curx), (Ypos - cury), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 748 | BSP_LCD_DrawPixel((Xpos + cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 749 | BSP_LCD_DrawPixel((Xpos - cury), (Ypos - curx), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 750 | BSP_LCD_DrawPixel((Xpos + curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 751 | BSP_LCD_DrawPixel((Xpos - curx), (Ypos + cury), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 752 | BSP_LCD_DrawPixel((Xpos + cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 753 | BSP_LCD_DrawPixel((Xpos - cury), (Ypos + curx), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 754 | |
bcostm | 0:e1d164542663 | 755 | if (d < 0) |
bcostm | 0:e1d164542663 | 756 | { |
bcostm | 0:e1d164542663 | 757 | d += (curx << 2) + 6; |
bcostm | 0:e1d164542663 | 758 | } |
bcostm | 0:e1d164542663 | 759 | else |
bcostm | 0:e1d164542663 | 760 | { |
bcostm | 0:e1d164542663 | 761 | d += ((curx - cury) << 2) + 10; |
bcostm | 0:e1d164542663 | 762 | cury--; |
bcostm | 0:e1d164542663 | 763 | } |
bcostm | 0:e1d164542663 | 764 | curx++; |
bcostm | 0:e1d164542663 | 765 | } |
bcostm | 0:e1d164542663 | 766 | } |
bcostm | 0:e1d164542663 | 767 | |
bcostm | 0:e1d164542663 | 768 | /** |
bcostm | 0:e1d164542663 | 769 | * @brief Displays an poly-line (between many points). |
bcostm | 0:e1d164542663 | 770 | * @param Points: pointer to the points array |
bcostm | 0:e1d164542663 | 771 | * @param PointCount: Number of points |
bcostm | 0:e1d164542663 | 772 | * @retval None |
bcostm | 0:e1d164542663 | 773 | */ |
bcostm | 0:e1d164542663 | 774 | void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount) |
bcostm | 0:e1d164542663 | 775 | { |
bcostm | 0:e1d164542663 | 776 | int16_t x = 0, y = 0; |
bcostm | 0:e1d164542663 | 777 | |
bcostm | 0:e1d164542663 | 778 | if(PointCount < 2) |
bcostm | 0:e1d164542663 | 779 | { |
bcostm | 0:e1d164542663 | 780 | return; |
bcostm | 0:e1d164542663 | 781 | } |
bcostm | 0:e1d164542663 | 782 | |
bcostm | 0:e1d164542663 | 783 | BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); |
bcostm | 0:e1d164542663 | 784 | |
bcostm | 0:e1d164542663 | 785 | while(--PointCount) |
bcostm | 0:e1d164542663 | 786 | { |
bcostm | 0:e1d164542663 | 787 | x = Points->X; |
bcostm | 0:e1d164542663 | 788 | y = Points->Y; |
bcostm | 0:e1d164542663 | 789 | Points++; |
bcostm | 0:e1d164542663 | 790 | BSP_LCD_DrawLine(x, y, Points->X, Points->Y); |
bcostm | 0:e1d164542663 | 791 | } |
bcostm | 0:e1d164542663 | 792 | } |
bcostm | 0:e1d164542663 | 793 | |
bcostm | 0:e1d164542663 | 794 | /** |
bcostm | 0:e1d164542663 | 795 | * @brief Displays an Ellipse. |
bcostm | 0:e1d164542663 | 796 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 797 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 798 | * @param XRadius: the X radius of ellipse |
bcostm | 0:e1d164542663 | 799 | * @param YRadius: the Y radius of ellipse |
bcostm | 0:e1d164542663 | 800 | * @retval None |
bcostm | 0:e1d164542663 | 801 | */ |
bcostm | 0:e1d164542663 | 802 | void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) |
bcostm | 0:e1d164542663 | 803 | { |
bcostm | 0:e1d164542663 | 804 | int x = 0, y = -YRadius, err = 2-2*XRadius, e2; |
bcostm | 0:e1d164542663 | 805 | float k = 0, rad1 = 0, rad2 = 0; |
bcostm | 0:e1d164542663 | 806 | |
bcostm | 0:e1d164542663 | 807 | rad1 = XRadius; |
bcostm | 0:e1d164542663 | 808 | rad2 = YRadius; |
bcostm | 0:e1d164542663 | 809 | |
bcostm | 0:e1d164542663 | 810 | k = (float)(rad2/rad1); |
bcostm | 0:e1d164542663 | 811 | |
bcostm | 0:e1d164542663 | 812 | do { |
bcostm | 0:e1d164542663 | 813 | BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 814 | BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 815 | BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 816 | BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 817 | |
bcostm | 0:e1d164542663 | 818 | e2 = err; |
bcostm | 0:e1d164542663 | 819 | if (e2 <= x) { |
bcostm | 0:e1d164542663 | 820 | err += ++x*2+1; |
bcostm | 0:e1d164542663 | 821 | if (-y == x && e2 <= y) e2 = 0; |
bcostm | 0:e1d164542663 | 822 | } |
bcostm | 0:e1d164542663 | 823 | if (e2 > y) err += ++y*2+1; |
bcostm | 0:e1d164542663 | 824 | } |
bcostm | 0:e1d164542663 | 825 | while (y <= 0); |
bcostm | 0:e1d164542663 | 826 | } |
bcostm | 0:e1d164542663 | 827 | |
bcostm | 0:e1d164542663 | 828 | /** |
bcostm | 0:e1d164542663 | 829 | * @brief Displays a bitmap picture loaded in the internal Flash (32 bpp). |
bcostm | 0:e1d164542663 | 830 | * @param X: the bmp x position in the LCD |
bcostm | 0:e1d164542663 | 831 | * @param Y: the bmp Y position in the LCD |
bcostm | 0:e1d164542663 | 832 | * @param pBmp: Bmp picture address in the internal Flash |
bcostm | 0:e1d164542663 | 833 | * @retval None |
bcostm | 0:e1d164542663 | 834 | */ |
bcostm | 0:e1d164542663 | 835 | void BSP_LCD_DrawBitmap(uint32_t X, uint32_t Y, uint8_t *pBmp) |
bcostm | 0:e1d164542663 | 836 | { |
bcostm | 0:e1d164542663 | 837 | uint32_t index = 0, width = 0, height = 0, bitpixel = 0; |
bcostm | 0:e1d164542663 | 838 | uint32_t address; |
bcostm | 0:e1d164542663 | 839 | uint32_t inputcolormode = 0; |
bcostm | 0:e1d164542663 | 840 | |
bcostm | 0:e1d164542663 | 841 | /* Get bitmap data address offset */ |
bcostm | 0:e1d164542663 | 842 | index = *(__IO uint16_t *) (pBmp + 10); |
bcostm | 0:e1d164542663 | 843 | index |= (*(__IO uint16_t *) (pBmp + 12)) << 16; |
bcostm | 0:e1d164542663 | 844 | |
bcostm | 0:e1d164542663 | 845 | /* Read bitmap width */ |
bcostm | 0:e1d164542663 | 846 | width = *(uint16_t *) (pBmp + 18); |
bcostm | 0:e1d164542663 | 847 | width |= (*(uint16_t *) (pBmp + 20)) << 16; |
bcostm | 0:e1d164542663 | 848 | |
bcostm | 0:e1d164542663 | 849 | /* Read bitmap height */ |
bcostm | 0:e1d164542663 | 850 | height = *(uint16_t *) (pBmp + 22); |
bcostm | 0:e1d164542663 | 851 | height |= (*(uint16_t *) (pBmp + 24)) << 16; |
bcostm | 0:e1d164542663 | 852 | |
bcostm | 0:e1d164542663 | 853 | /* Read bit/pixel */ |
bcostm | 0:e1d164542663 | 854 | bitpixel = *(uint16_t *) (pBmp + 28); |
bcostm | 0:e1d164542663 | 855 | |
bcostm | 0:e1d164542663 | 856 | /* Set Address */ |
bcostm | 0:e1d164542663 | 857 | address = LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Y) + X)*(4)); |
bcostm | 0:e1d164542663 | 858 | |
bcostm | 0:e1d164542663 | 859 | /* Get the Layer pixel format */ |
bcostm | 0:e1d164542663 | 860 | if ((bitpixel/8) == 4) |
bcostm | 0:e1d164542663 | 861 | { |
bcostm | 0:e1d164542663 | 862 | inputcolormode = CM_ARGB8888; |
bcostm | 0:e1d164542663 | 863 | } |
bcostm | 0:e1d164542663 | 864 | else if ((bitpixel/8) == 2) |
bcostm | 0:e1d164542663 | 865 | { |
bcostm | 0:e1d164542663 | 866 | inputcolormode = CM_RGB565; |
bcostm | 0:e1d164542663 | 867 | } |
bcostm | 0:e1d164542663 | 868 | else |
bcostm | 0:e1d164542663 | 869 | { |
bcostm | 0:e1d164542663 | 870 | inputcolormode = CM_RGB888; |
bcostm | 0:e1d164542663 | 871 | } |
bcostm | 0:e1d164542663 | 872 | |
bcostm | 0:e1d164542663 | 873 | /* bypass the bitmap header */ |
bcostm | 0:e1d164542663 | 874 | pBmp += (index + (width * (height - 1) * (bitpixel/8))); |
bcostm | 0:e1d164542663 | 875 | |
bcostm | 0:e1d164542663 | 876 | /* Convert picture to ARGB8888 pixel format */ |
bcostm | 0:e1d164542663 | 877 | for(index=0; index < height; index++) |
bcostm | 0:e1d164542663 | 878 | { |
bcostm | 0:e1d164542663 | 879 | /* Pixel format conversion */ |
bcostm | 0:e1d164542663 | 880 | ConvertLineToARGB8888((uint32_t *)pBmp, (uint32_t *)address, width, inputcolormode); |
bcostm | 0:e1d164542663 | 881 | |
bcostm | 0:e1d164542663 | 882 | /* Increment the source and destination buffers */ |
bcostm | 0:e1d164542663 | 883 | address+= ((BSP_LCD_GetXSize() - width + width)*4); |
bcostm | 0:e1d164542663 | 884 | pBmp -= width*(bitpixel/8); |
bcostm | 0:e1d164542663 | 885 | } |
bcostm | 0:e1d164542663 | 886 | } |
bcostm | 0:e1d164542663 | 887 | |
bcostm | 0:e1d164542663 | 888 | /** |
bcostm | 0:e1d164542663 | 889 | * @brief Displays a full rectangle. |
bcostm | 0:e1d164542663 | 890 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 891 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 892 | * @param Height: rectangle height |
bcostm | 0:e1d164542663 | 893 | * @param Width: rectangle width |
bcostm | 0:e1d164542663 | 894 | * @retval None |
bcostm | 0:e1d164542663 | 895 | */ |
bcostm | 0:e1d164542663 | 896 | void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) |
bcostm | 0:e1d164542663 | 897 | { |
bcostm | 0:e1d164542663 | 898 | uint32_t xaddress = 0; |
bcostm | 0:e1d164542663 | 899 | |
bcostm | 0:e1d164542663 | 900 | /* Set the text color */ |
bcostm | 0:e1d164542663 | 901 | BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 902 | |
bcostm | 0:e1d164542663 | 903 | /* Get the rectangle start address */ |
bcostm | 0:e1d164542663 | 904 | xaddress = (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos); |
bcostm | 0:e1d164542663 | 905 | |
bcostm | 0:e1d164542663 | 906 | /* Fill the rectangle */ |
bcostm | 0:e1d164542663 | 907 | FillBuffer(ActiveLayer, (uint32_t *)xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 908 | } |
bcostm | 0:e1d164542663 | 909 | |
bcostm | 0:e1d164542663 | 910 | /** |
bcostm | 0:e1d164542663 | 911 | * @brief Displays a full circle. |
bcostm | 0:e1d164542663 | 912 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 913 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 914 | * @param Radius: the circle radius |
bcostm | 0:e1d164542663 | 915 | * @retval None |
bcostm | 0:e1d164542663 | 916 | */ |
bcostm | 0:e1d164542663 | 917 | void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) |
bcostm | 0:e1d164542663 | 918 | { |
bcostm | 0:e1d164542663 | 919 | int32_t d; /* Decision Variable */ |
bcostm | 0:e1d164542663 | 920 | uint32_t curx;/* Current X Value */ |
bcostm | 0:e1d164542663 | 921 | uint32_t cury;/* Current Y Value */ |
bcostm | 0:e1d164542663 | 922 | |
bcostm | 0:e1d164542663 | 923 | d = 3 - (Radius << 1); |
bcostm | 0:e1d164542663 | 924 | |
bcostm | 0:e1d164542663 | 925 | curx = 0; |
bcostm | 0:e1d164542663 | 926 | cury = Radius; |
bcostm | 0:e1d164542663 | 927 | |
bcostm | 0:e1d164542663 | 928 | BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 929 | |
bcostm | 0:e1d164542663 | 930 | while (curx <= cury) |
bcostm | 0:e1d164542663 | 931 | { |
bcostm | 0:e1d164542663 | 932 | if(cury > 0) |
bcostm | 0:e1d164542663 | 933 | { |
bcostm | 0:e1d164542663 | 934 | BSP_LCD_DrawHLine(Xpos - cury, Ypos + curx, 2*cury); |
bcostm | 0:e1d164542663 | 935 | BSP_LCD_DrawHLine(Xpos - cury, Ypos - curx, 2*cury); |
bcostm | 0:e1d164542663 | 936 | } |
bcostm | 0:e1d164542663 | 937 | |
bcostm | 0:e1d164542663 | 938 | if(curx > 0) |
bcostm | 0:e1d164542663 | 939 | { |
bcostm | 0:e1d164542663 | 940 | BSP_LCD_DrawHLine(Xpos - curx, Ypos - cury, 2*curx); |
bcostm | 0:e1d164542663 | 941 | BSP_LCD_DrawHLine(Xpos - curx, Ypos + cury, 2*curx); |
bcostm | 0:e1d164542663 | 942 | } |
bcostm | 0:e1d164542663 | 943 | if (d < 0) |
bcostm | 0:e1d164542663 | 944 | { |
bcostm | 0:e1d164542663 | 945 | d += (curx << 2) + 6; |
bcostm | 0:e1d164542663 | 946 | } |
bcostm | 0:e1d164542663 | 947 | else |
bcostm | 0:e1d164542663 | 948 | { |
bcostm | 0:e1d164542663 | 949 | d += ((curx - cury) << 2) + 10; |
bcostm | 0:e1d164542663 | 950 | cury--; |
bcostm | 0:e1d164542663 | 951 | } |
bcostm | 0:e1d164542663 | 952 | curx++; |
bcostm | 0:e1d164542663 | 953 | } |
bcostm | 0:e1d164542663 | 954 | |
bcostm | 0:e1d164542663 | 955 | BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 956 | BSP_LCD_DrawCircle(Xpos, Ypos, Radius); |
bcostm | 0:e1d164542663 | 957 | } |
bcostm | 0:e1d164542663 | 958 | |
bcostm | 0:e1d164542663 | 959 | /** |
bcostm | 0:e1d164542663 | 960 | * @brief Fill triangle. |
bcostm | 0:e1d164542663 | 961 | * @param X1: the point 1 x position |
bcostm | 0:e1d164542663 | 962 | * @param Y1: the point 1 y position |
bcostm | 0:e1d164542663 | 963 | * @param X2: the point 2 x position |
bcostm | 0:e1d164542663 | 964 | * @param Y2: the point 2 y position |
bcostm | 0:e1d164542663 | 965 | * @param X3: the point 3 x position |
bcostm | 0:e1d164542663 | 966 | * @param Y3: the point 3 y position |
bcostm | 0:e1d164542663 | 967 | * @retval None |
bcostm | 0:e1d164542663 | 968 | */ |
bcostm | 0:e1d164542663 | 969 | void BSP_LCD_FillTriangle(uint16_t X1, uint16_t X2, uint16_t X3, uint16_t Y1, uint16_t Y2, uint16_t Y3) |
bcostm | 0:e1d164542663 | 970 | { |
bcostm | 0:e1d164542663 | 971 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, |
bcostm | 0:e1d164542663 | 972 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, |
bcostm | 0:e1d164542663 | 973 | curpixel = 0; |
bcostm | 0:e1d164542663 | 974 | |
bcostm | 0:e1d164542663 | 975 | deltax = ABS(X2 - X1); /* The difference between the x's */ |
bcostm | 0:e1d164542663 | 976 | deltay = ABS(Y2 - Y1); /* The difference between the y's */ |
bcostm | 0:e1d164542663 | 977 | x = X1; /* Start x off at the first pixel */ |
bcostm | 0:e1d164542663 | 978 | y = Y1; /* Start y off at the first pixel */ |
bcostm | 0:e1d164542663 | 979 | |
bcostm | 0:e1d164542663 | 980 | if (X2 >= X1) /* The x-values are increasing */ |
bcostm | 0:e1d164542663 | 981 | { |
bcostm | 0:e1d164542663 | 982 | xinc1 = 1; |
bcostm | 0:e1d164542663 | 983 | xinc2 = 1; |
bcostm | 0:e1d164542663 | 984 | } |
bcostm | 0:e1d164542663 | 985 | else /* The x-values are decreasing */ |
bcostm | 0:e1d164542663 | 986 | { |
bcostm | 0:e1d164542663 | 987 | xinc1 = -1; |
bcostm | 0:e1d164542663 | 988 | xinc2 = -1; |
bcostm | 0:e1d164542663 | 989 | } |
bcostm | 0:e1d164542663 | 990 | |
bcostm | 0:e1d164542663 | 991 | if (Y2 >= Y1) /* The y-values are increasing */ |
bcostm | 0:e1d164542663 | 992 | { |
bcostm | 0:e1d164542663 | 993 | yinc1 = 1; |
bcostm | 0:e1d164542663 | 994 | yinc2 = 1; |
bcostm | 0:e1d164542663 | 995 | } |
bcostm | 0:e1d164542663 | 996 | else /* The y-values are decreasing */ |
bcostm | 0:e1d164542663 | 997 | { |
bcostm | 0:e1d164542663 | 998 | yinc1 = -1; |
bcostm | 0:e1d164542663 | 999 | yinc2 = -1; |
bcostm | 0:e1d164542663 | 1000 | } |
bcostm | 0:e1d164542663 | 1001 | |
bcostm | 0:e1d164542663 | 1002 | if (deltax >= deltay) /* There is at least one x-value for every y-value */ |
bcostm | 0:e1d164542663 | 1003 | { |
bcostm | 0:e1d164542663 | 1004 | xinc1 = 0; /* Don't change the x when numerator >= denominator */ |
bcostm | 0:e1d164542663 | 1005 | yinc2 = 0; /* Don't change the y for every iteration */ |
bcostm | 0:e1d164542663 | 1006 | den = deltax; |
bcostm | 0:e1d164542663 | 1007 | num = deltax / 2; |
bcostm | 0:e1d164542663 | 1008 | numadd = deltay; |
bcostm | 0:e1d164542663 | 1009 | numpixels = deltax; /* There are more x-values than y-values */ |
bcostm | 0:e1d164542663 | 1010 | } |
bcostm | 0:e1d164542663 | 1011 | else /* There is at least one y-value for every x-value */ |
bcostm | 0:e1d164542663 | 1012 | { |
bcostm | 0:e1d164542663 | 1013 | xinc2 = 0; /* Don't change the x for every iteration */ |
bcostm | 0:e1d164542663 | 1014 | yinc1 = 0; /* Don't change the y when numerator >= denominator */ |
bcostm | 0:e1d164542663 | 1015 | den = deltay; |
bcostm | 0:e1d164542663 | 1016 | num = deltay / 2; |
bcostm | 0:e1d164542663 | 1017 | numadd = deltax; |
bcostm | 0:e1d164542663 | 1018 | numpixels = deltay; /* There are more y-values than x-values */ |
bcostm | 0:e1d164542663 | 1019 | } |
bcostm | 0:e1d164542663 | 1020 | |
bcostm | 0:e1d164542663 | 1021 | for (curpixel = 0; curpixel <= numpixels; curpixel++) |
bcostm | 0:e1d164542663 | 1022 | { |
bcostm | 0:e1d164542663 | 1023 | BSP_LCD_DrawLine(x, y, X3, Y3); |
bcostm | 0:e1d164542663 | 1024 | |
bcostm | 0:e1d164542663 | 1025 | num += numadd; /* Increase the numerator by the top of the fraction */ |
bcostm | 0:e1d164542663 | 1026 | if (num >= den) /* Check if numerator >= denominator */ |
bcostm | 0:e1d164542663 | 1027 | { |
bcostm | 0:e1d164542663 | 1028 | num -= den; /* Calculate the new numerator value */ |
bcostm | 0:e1d164542663 | 1029 | x += xinc1; /* Change the x as appropriate */ |
bcostm | 0:e1d164542663 | 1030 | y += yinc1; /* Change the y as appropriate */ |
bcostm | 0:e1d164542663 | 1031 | } |
bcostm | 0:e1d164542663 | 1032 | x += xinc2; /* Change the x as appropriate */ |
bcostm | 0:e1d164542663 | 1033 | y += yinc2; /* Change the y as appropriate */ |
bcostm | 0:e1d164542663 | 1034 | } |
bcostm | 0:e1d164542663 | 1035 | } |
bcostm | 0:e1d164542663 | 1036 | |
bcostm | 0:e1d164542663 | 1037 | /** |
bcostm | 0:e1d164542663 | 1038 | * @brief Displays a full poly-line (between many points). |
bcostm | 0:e1d164542663 | 1039 | * @param Points: pointer to the points array |
bcostm | 0:e1d164542663 | 1040 | * @param PointCount: Number of points |
bcostm | 0:e1d164542663 | 1041 | * @retval None |
bcostm | 0:e1d164542663 | 1042 | */ |
bcostm | 0:e1d164542663 | 1043 | void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) |
bcostm | 0:e1d164542663 | 1044 | { |
bcostm | 0:e1d164542663 | 1045 | |
bcostm | 0:e1d164542663 | 1046 | int16_t x = 0, y = 0, x2 = 0, y2 = 0, xcenter = 0, ycenter = 0, xfirst = 0, yfirst = 0, pixelx = 0, pixely = 0, counter = 0; |
bcostm | 0:e1d164542663 | 1047 | uint16_t imageleft = 0, imageright = 0, imagetop = 0, imagebottom = 0; |
bcostm | 0:e1d164542663 | 1048 | |
bcostm | 0:e1d164542663 | 1049 | imageleft = imageright = Points->X; |
bcostm | 0:e1d164542663 | 1050 | imagetop= imagebottom = Points->Y; |
bcostm | 0:e1d164542663 | 1051 | |
bcostm | 0:e1d164542663 | 1052 | for(counter = 1; counter < PointCount; counter++) |
bcostm | 0:e1d164542663 | 1053 | { |
bcostm | 0:e1d164542663 | 1054 | pixelx = POLY_X(counter); |
bcostm | 0:e1d164542663 | 1055 | if(pixelx < imageleft) |
bcostm | 0:e1d164542663 | 1056 | { |
bcostm | 0:e1d164542663 | 1057 | imageleft = pixelx; |
bcostm | 0:e1d164542663 | 1058 | } |
bcostm | 0:e1d164542663 | 1059 | if(pixelx > imageright) |
bcostm | 0:e1d164542663 | 1060 | { |
bcostm | 0:e1d164542663 | 1061 | imageright = pixelx; |
bcostm | 0:e1d164542663 | 1062 | } |
bcostm | 0:e1d164542663 | 1063 | |
bcostm | 0:e1d164542663 | 1064 | pixely = POLY_Y(counter); |
bcostm | 0:e1d164542663 | 1065 | if(pixely < imagetop) |
bcostm | 0:e1d164542663 | 1066 | { |
bcostm | 0:e1d164542663 | 1067 | imagetop = pixely; |
bcostm | 0:e1d164542663 | 1068 | } |
bcostm | 0:e1d164542663 | 1069 | if(pixely > imagebottom) |
bcostm | 0:e1d164542663 | 1070 | { |
bcostm | 0:e1d164542663 | 1071 | imagebottom = pixely; |
bcostm | 0:e1d164542663 | 1072 | } |
bcostm | 0:e1d164542663 | 1073 | } |
bcostm | 0:e1d164542663 | 1074 | |
bcostm | 0:e1d164542663 | 1075 | if(PointCount < 2) |
bcostm | 0:e1d164542663 | 1076 | { |
bcostm | 0:e1d164542663 | 1077 | return; |
bcostm | 0:e1d164542663 | 1078 | } |
bcostm | 0:e1d164542663 | 1079 | |
bcostm | 0:e1d164542663 | 1080 | xcenter = (imageleft + imageright)/2; |
bcostm | 0:e1d164542663 | 1081 | ycenter = (imagebottom + imagetop)/2; |
bcostm | 0:e1d164542663 | 1082 | |
bcostm | 0:e1d164542663 | 1083 | xfirst = Points->X; |
bcostm | 0:e1d164542663 | 1084 | yfirst = Points->Y; |
bcostm | 0:e1d164542663 | 1085 | |
bcostm | 0:e1d164542663 | 1086 | while(--PointCount) |
bcostm | 0:e1d164542663 | 1087 | { |
bcostm | 0:e1d164542663 | 1088 | x = Points->X; |
bcostm | 0:e1d164542663 | 1089 | y = Points->Y; |
bcostm | 0:e1d164542663 | 1090 | Points++; |
bcostm | 0:e1d164542663 | 1091 | x2 = Points->X; |
bcostm | 0:e1d164542663 | 1092 | y2 = Points->Y; |
bcostm | 0:e1d164542663 | 1093 | |
bcostm | 0:e1d164542663 | 1094 | BSP_LCD_FillTriangle(x, x2, xcenter, y, y2, ycenter); |
bcostm | 0:e1d164542663 | 1095 | BSP_LCD_FillTriangle(x, xcenter, x2, y, ycenter, y2); |
bcostm | 0:e1d164542663 | 1096 | BSP_LCD_FillTriangle(xcenter, x2, x, ycenter, y2, y); |
bcostm | 0:e1d164542663 | 1097 | } |
bcostm | 0:e1d164542663 | 1098 | |
bcostm | 0:e1d164542663 | 1099 | BSP_LCD_FillTriangle(xfirst, x2, xcenter, yfirst, y2, ycenter); |
bcostm | 0:e1d164542663 | 1100 | BSP_LCD_FillTriangle(xfirst, xcenter, x2, yfirst, ycenter, y2); |
bcostm | 0:e1d164542663 | 1101 | BSP_LCD_FillTriangle(xcenter, x2, xfirst, ycenter, y2, yfirst); |
bcostm | 0:e1d164542663 | 1102 | } |
bcostm | 0:e1d164542663 | 1103 | |
bcostm | 0:e1d164542663 | 1104 | /** |
bcostm | 0:e1d164542663 | 1105 | * @brief Draw a full ellipse. |
bcostm | 0:e1d164542663 | 1106 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 1107 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 1108 | * @param XRadius: X radius of ellipse |
bcostm | 0:e1d164542663 | 1109 | * @param YRadius: Y radius of ellipse. |
bcostm | 0:e1d164542663 | 1110 | * @retval None |
bcostm | 0:e1d164542663 | 1111 | */ |
bcostm | 0:e1d164542663 | 1112 | void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) |
bcostm | 0:e1d164542663 | 1113 | { |
bcostm | 0:e1d164542663 | 1114 | int x = 0, y = -YRadius, err = 2-2*XRadius, e2; |
bcostm | 0:e1d164542663 | 1115 | float K = 0, rad1 = 0, rad2 = 0; |
bcostm | 0:e1d164542663 | 1116 | |
bcostm | 0:e1d164542663 | 1117 | rad1 = XRadius; |
bcostm | 0:e1d164542663 | 1118 | rad2 = YRadius; |
bcostm | 0:e1d164542663 | 1119 | K = (float)(rad2/rad1); |
bcostm | 0:e1d164542663 | 1120 | |
bcostm | 0:e1d164542663 | 1121 | do |
bcostm | 0:e1d164542663 | 1122 | { |
bcostm | 0:e1d164542663 | 1123 | BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1)); |
bcostm | 0:e1d164542663 | 1124 | BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1)); |
bcostm | 0:e1d164542663 | 1125 | |
bcostm | 0:e1d164542663 | 1126 | e2 = err; |
bcostm | 0:e1d164542663 | 1127 | if (e2 <= x) |
bcostm | 0:e1d164542663 | 1128 | { |
bcostm | 0:e1d164542663 | 1129 | err += ++x*2+1; |
bcostm | 0:e1d164542663 | 1130 | if (-y == x && e2 <= y) e2 = 0; |
bcostm | 0:e1d164542663 | 1131 | } |
bcostm | 0:e1d164542663 | 1132 | if (e2 > y) err += ++y*2+1; |
bcostm | 0:e1d164542663 | 1133 | } |
bcostm | 0:e1d164542663 | 1134 | while (y <= 0); |
bcostm | 0:e1d164542663 | 1135 | } |
bcostm | 0:e1d164542663 | 1136 | |
bcostm | 0:e1d164542663 | 1137 | /** |
bcostm | 0:e1d164542663 | 1138 | * @brief Enables the Display. |
bcostm | 0:e1d164542663 | 1139 | * @param None |
bcostm | 0:e1d164542663 | 1140 | * @retval None |
bcostm | 0:e1d164542663 | 1141 | */ |
bcostm | 0:e1d164542663 | 1142 | void BSP_LCD_DisplayOn(void) |
bcostm | 0:e1d164542663 | 1143 | { |
bcostm | 0:e1d164542663 | 1144 | if(LcdDrv->DisplayOn != NULL) |
bcostm | 0:e1d164542663 | 1145 | { |
bcostm | 0:e1d164542663 | 1146 | LcdDrv->DisplayOn(); |
bcostm | 0:e1d164542663 | 1147 | } |
bcostm | 0:e1d164542663 | 1148 | } |
bcostm | 0:e1d164542663 | 1149 | |
bcostm | 0:e1d164542663 | 1150 | /** |
bcostm | 0:e1d164542663 | 1151 | * @brief Disables the Display. |
bcostm | 0:e1d164542663 | 1152 | * @param None |
bcostm | 0:e1d164542663 | 1153 | * @retval None |
bcostm | 0:e1d164542663 | 1154 | */ |
bcostm | 0:e1d164542663 | 1155 | void BSP_LCD_DisplayOff(void) |
bcostm | 0:e1d164542663 | 1156 | { |
bcostm | 0:e1d164542663 | 1157 | if(LcdDrv->DisplayOff != NULL) |
bcostm | 0:e1d164542663 | 1158 | { |
bcostm | 0:e1d164542663 | 1159 | LcdDrv->DisplayOff(); |
bcostm | 0:e1d164542663 | 1160 | } |
bcostm | 0:e1d164542663 | 1161 | } |
bcostm | 0:e1d164542663 | 1162 | |
bcostm | 0:e1d164542663 | 1163 | /******************************************************************************* |
bcostm | 0:e1d164542663 | 1164 | LTDC and DMA2D BSP Routines |
bcostm | 0:e1d164542663 | 1165 | *******************************************************************************/ |
bcostm | 0:e1d164542663 | 1166 | |
bcostm | 0:e1d164542663 | 1167 | /** |
bcostm | 0:e1d164542663 | 1168 | * @brief Initializes the LTDC MSP. |
bcostm | 0:e1d164542663 | 1169 | * @param None |
bcostm | 0:e1d164542663 | 1170 | * @retval None |
bcostm | 0:e1d164542663 | 1171 | */ |
bcostm | 0:e1d164542663 | 1172 | static void MspInit(void) |
bcostm | 0:e1d164542663 | 1173 | { |
bcostm | 0:e1d164542663 | 1174 | GPIO_InitTypeDef GPIO_InitStructure; |
bcostm | 0:e1d164542663 | 1175 | |
bcostm | 0:e1d164542663 | 1176 | /* Enable the LTDC and DMA2D Clock */ |
bcostm | 0:e1d164542663 | 1177 | __LTDC_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1178 | __DMA2D_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1179 | |
bcostm | 0:e1d164542663 | 1180 | /* Enable GPIOs clock */ |
bcostm | 0:e1d164542663 | 1181 | __GPIOA_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1182 | __GPIOB_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1183 | __GPIOC_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1184 | __GPIOD_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1185 | __GPIOF_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1186 | __GPIOG_CLK_ENABLE(); |
bcostm | 0:e1d164542663 | 1187 | |
bcostm | 0:e1d164542663 | 1188 | /* GPIOs Configuration */ |
bcostm | 0:e1d164542663 | 1189 | /* |
bcostm | 0:e1d164542663 | 1190 | +------------------------+-----------------------+----------------------------+ |
bcostm | 0:e1d164542663 | 1191 | + LCD pins assignment + |
bcostm | 0:e1d164542663 | 1192 | +------------------------+-----------------------+----------------------------+ |
bcostm | 0:e1d164542663 | 1193 | | LCD_TFT R2 <-> PC.10 | LCD_TFT G2 <-> PA.06 | LCD_TFT B2 <-> PD.06 | |
bcostm | 0:e1d164542663 | 1194 | | LCD_TFT R3 <-> PB.00 | LCD_TFT G3 <-> PG.10 | LCD_TFT B3 <-> PG.11 | |
bcostm | 0:e1d164542663 | 1195 | | LCD_TFT R4 <-> PA.11 | LCD_TFT G4 <-> PB.10 | LCD_TFT B4 <-> PG.12 | |
bcostm | 0:e1d164542663 | 1196 | | LCD_TFT R5 <-> PA.12 | LCD_TFT G5 <-> PB.11 | LCD_TFT B5 <-> PA.03 | |
bcostm | 0:e1d164542663 | 1197 | | LCD_TFT R6 <-> PB.01 | LCD_TFT G6 <-> PC.07 | LCD_TFT B6 <-> PB.08 | |
bcostm | 0:e1d164542663 | 1198 | | LCD_TFT R7 <-> PG.06 | LCD_TFT G7 <-> PD.03 | LCD_TFT B7 <-> PB.09 | |
bcostm | 0:e1d164542663 | 1199 | ------------------------------------------------------------------------------- |
bcostm | 0:e1d164542663 | 1200 | | LCD_TFT HSYNC <-> PC.06 | LCDTFT VSYNC <-> PA.04 | |
bcostm | 0:e1d164542663 | 1201 | | LCD_TFT CLK <-> PG.07 | LCD_TFT DE <-> PF.10 | |
bcostm | 0:e1d164542663 | 1202 | ----------------------------------------------------- |
bcostm | 0:e1d164542663 | 1203 | */ |
bcostm | 0:e1d164542663 | 1204 | |
bcostm | 0:e1d164542663 | 1205 | /* GPIOA configuration */ |
bcostm | 0:e1d164542663 | 1206 | GPIO_InitStructure.Pin = GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_6 | |
bcostm | 0:e1d164542663 | 1207 | GPIO_PIN_11 | GPIO_PIN_12; |
bcostm | 0:e1d164542663 | 1208 | GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; |
bcostm | 0:e1d164542663 | 1209 | GPIO_InitStructure.Pull = GPIO_NOPULL; |
bcostm | 0:e1d164542663 | 1210 | GPIO_InitStructure.Speed = GPIO_SPEED_FAST; |
bcostm | 0:e1d164542663 | 1211 | GPIO_InitStructure.Alternate= GPIO_AF14_LTDC; |
bcostm | 0:e1d164542663 | 1212 | HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1213 | |
bcostm | 0:e1d164542663 | 1214 | /* GPIOB configuration */ |
bcostm | 0:e1d164542663 | 1215 | GPIO_InitStructure.Pin = GPIO_PIN_8 | \ |
bcostm | 0:e1d164542663 | 1216 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11; |
bcostm | 0:e1d164542663 | 1217 | HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1218 | |
bcostm | 0:e1d164542663 | 1219 | /* GPIOC configuration */ |
bcostm | 0:e1d164542663 | 1220 | GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_10; |
bcostm | 0:e1d164542663 | 1221 | HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1222 | |
bcostm | 0:e1d164542663 | 1223 | /* GPIOD configuration */ |
bcostm | 0:e1d164542663 | 1224 | GPIO_InitStructure.Pin = GPIO_PIN_3 | GPIO_PIN_6; |
bcostm | 0:e1d164542663 | 1225 | HAL_GPIO_Init(GPIOD, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1226 | |
bcostm | 0:e1d164542663 | 1227 | /* GPIOF configuration */ |
bcostm | 0:e1d164542663 | 1228 | GPIO_InitStructure.Pin = GPIO_PIN_10; |
bcostm | 0:e1d164542663 | 1229 | HAL_GPIO_Init(GPIOF, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1230 | |
bcostm | 0:e1d164542663 | 1231 | /* GPIOG configuration */ |
bcostm | 0:e1d164542663 | 1232 | GPIO_InitStructure.Pin = GPIO_PIN_6 | GPIO_PIN_7 | \ |
bcostm | 0:e1d164542663 | 1233 | GPIO_PIN_11; |
bcostm | 0:e1d164542663 | 1234 | HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1235 | |
bcostm | 0:e1d164542663 | 1236 | /* GPIOB configuration */ |
bcostm | 0:e1d164542663 | 1237 | GPIO_InitStructure.Pin = GPIO_PIN_0 | GPIO_PIN_1; |
bcostm | 0:e1d164542663 | 1238 | GPIO_InitStructure.Alternate= GPIO_AF9_LTDC; |
bcostm | 0:e1d164542663 | 1239 | HAL_GPIO_Init(GPIOB, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1240 | |
bcostm | 0:e1d164542663 | 1241 | /* GPIOG configuration */ |
bcostm | 0:e1d164542663 | 1242 | GPIO_InitStructure.Pin = GPIO_PIN_10 | GPIO_PIN_12; |
bcostm | 0:e1d164542663 | 1243 | HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); |
bcostm | 0:e1d164542663 | 1244 | } |
bcostm | 0:e1d164542663 | 1245 | |
bcostm | 0:e1d164542663 | 1246 | /******************************************************************************* |
bcostm | 0:e1d164542663 | 1247 | Static Functions |
bcostm | 0:e1d164542663 | 1248 | *******************************************************************************/ |
bcostm | 0:e1d164542663 | 1249 | |
bcostm | 0:e1d164542663 | 1250 | /** |
bcostm | 0:e1d164542663 | 1251 | * @brief Writes Pixel. |
bcostm | 0:e1d164542663 | 1252 | * @param Xpos: the X position |
bcostm | 0:e1d164542663 | 1253 | * @param Ypos: the Y position |
bcostm | 0:e1d164542663 | 1254 | * @param RGB_Code: the pixel color in ARGB mode (8-8-8-8) |
bcostm | 0:e1d164542663 | 1255 | * @retval None |
bcostm | 0:e1d164542663 | 1256 | */ |
bcostm | 0:e1d164542663 | 1257 | void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code) |
bcostm | 0:e1d164542663 | 1258 | { |
bcostm | 0:e1d164542663 | 1259 | /* Write data value to all SDRAM memory */ |
bcostm | 0:e1d164542663 | 1260 | *(__IO uint32_t*) (LtdcHandler.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code; |
bcostm | 0:e1d164542663 | 1261 | } |
bcostm | 0:e1d164542663 | 1262 | |
bcostm | 0:e1d164542663 | 1263 | /** |
bcostm | 0:e1d164542663 | 1264 | * @brief Draws a character on LCD. |
bcostm | 0:e1d164542663 | 1265 | * @param Xpos: the Line where to display the character shape |
bcostm | 0:e1d164542663 | 1266 | * @param Ypos: start column address |
bcostm | 0:e1d164542663 | 1267 | * @param c: pointer to the character data |
bcostm | 0:e1d164542663 | 1268 | * @retval None |
bcostm | 0:e1d164542663 | 1269 | */ |
bcostm | 0:e1d164542663 | 1270 | static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c) |
bcostm | 0:e1d164542663 | 1271 | { |
bcostm | 0:e1d164542663 | 1272 | uint32_t i = 0, j = 0; |
bcostm | 0:e1d164542663 | 1273 | uint16_t height, width; |
bcostm | 0:e1d164542663 | 1274 | uint8_t offset; |
bcostm | 0:e1d164542663 | 1275 | uint8_t *pchar; |
bcostm | 0:e1d164542663 | 1276 | uint32_t line=0; |
bcostm | 0:e1d164542663 | 1277 | |
bcostm | 0:e1d164542663 | 1278 | height = DrawProp[ActiveLayer].pFont->Height; |
bcostm | 0:e1d164542663 | 1279 | width = DrawProp[ActiveLayer].pFont->Width; |
bcostm | 0:e1d164542663 | 1280 | |
bcostm | 0:e1d164542663 | 1281 | offset = 8 *((width + 7)/8) - width ; |
bcostm | 0:e1d164542663 | 1282 | |
bcostm | 0:e1d164542663 | 1283 | for(i = 0; i < height; i++) |
bcostm | 0:e1d164542663 | 1284 | { |
bcostm | 0:e1d164542663 | 1285 | pchar = ((uint8_t *)c + (width + 7)/8 * i); |
bcostm | 0:e1d164542663 | 1286 | |
bcostm | 0:e1d164542663 | 1287 | switch(((width + 7)/8)) |
bcostm | 0:e1d164542663 | 1288 | { |
bcostm | 0:e1d164542663 | 1289 | case 1: |
bcostm | 0:e1d164542663 | 1290 | line = pchar[0]; |
bcostm | 0:e1d164542663 | 1291 | break; |
bcostm | 0:e1d164542663 | 1292 | |
bcostm | 0:e1d164542663 | 1293 | case 2: |
bcostm | 0:e1d164542663 | 1294 | line = (pchar[0]<< 8) | pchar[1]; |
bcostm | 0:e1d164542663 | 1295 | break; |
bcostm | 0:e1d164542663 | 1296 | |
bcostm | 0:e1d164542663 | 1297 | case 3: |
bcostm | 0:e1d164542663 | 1298 | default: |
bcostm | 0:e1d164542663 | 1299 | line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; |
bcostm | 0:e1d164542663 | 1300 | break; |
bcostm | 0:e1d164542663 | 1301 | } |
bcostm | 0:e1d164542663 | 1302 | |
bcostm | 0:e1d164542663 | 1303 | for (j = 0; j < width; j++) |
bcostm | 0:e1d164542663 | 1304 | { |
bcostm | 0:e1d164542663 | 1305 | if(line & (1 << (width- j + offset- 1))) |
bcostm | 0:e1d164542663 | 1306 | { |
bcostm | 0:e1d164542663 | 1307 | BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor); |
bcostm | 0:e1d164542663 | 1308 | } |
bcostm | 0:e1d164542663 | 1309 | else |
bcostm | 0:e1d164542663 | 1310 | { |
bcostm | 0:e1d164542663 | 1311 | BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor); |
bcostm | 0:e1d164542663 | 1312 | } |
bcostm | 0:e1d164542663 | 1313 | } |
bcostm | 0:e1d164542663 | 1314 | Ypos++; |
bcostm | 0:e1d164542663 | 1315 | } |
bcostm | 0:e1d164542663 | 1316 | } |
bcostm | 0:e1d164542663 | 1317 | |
bcostm | 0:e1d164542663 | 1318 | /** |
bcostm | 0:e1d164542663 | 1319 | * @brief Fills buffer. |
bcostm | 0:e1d164542663 | 1320 | * @param LayerIndex: layer index |
bcostm | 0:e1d164542663 | 1321 | * @param pDst: output color |
bcostm | 0:e1d164542663 | 1322 | * @param xSize: buffer width |
bcostm | 0:e1d164542663 | 1323 | * @param ySize: buffer height |
bcostm | 0:e1d164542663 | 1324 | * @param OffLine: offset |
bcostm | 0:e1d164542663 | 1325 | * @param ColorIndex: color Index |
bcostm | 0:e1d164542663 | 1326 | * @retval None |
bcostm | 0:e1d164542663 | 1327 | */ |
bcostm | 0:e1d164542663 | 1328 | static void FillBuffer(uint32_t LayerIndex, void * pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex) |
bcostm | 0:e1d164542663 | 1329 | { |
bcostm | 0:e1d164542663 | 1330 | |
bcostm | 0:e1d164542663 | 1331 | /* Register to memory mode with ARGB8888 as color Mode */ |
bcostm | 0:e1d164542663 | 1332 | Dma2dHandler.Init.Mode = DMA2D_R2M; |
bcostm | 0:e1d164542663 | 1333 | Dma2dHandler.Init.ColorMode = DMA2D_ARGB8888; |
bcostm | 0:e1d164542663 | 1334 | Dma2dHandler.Init.OutputOffset = OffLine; |
bcostm | 0:e1d164542663 | 1335 | |
bcostm | 0:e1d164542663 | 1336 | Dma2dHandler.Instance = DMA2D; |
bcostm | 0:e1d164542663 | 1337 | |
bcostm | 0:e1d164542663 | 1338 | /* DMA2D Initialization */ |
bcostm | 0:e1d164542663 | 1339 | if(HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK) |
bcostm | 0:e1d164542663 | 1340 | { |
bcostm | 0:e1d164542663 | 1341 | if(HAL_DMA2D_ConfigLayer(&Dma2dHandler, LayerIndex) == HAL_OK) |
bcostm | 0:e1d164542663 | 1342 | { |
bcostm | 0:e1d164542663 | 1343 | if (HAL_DMA2D_Start(&Dma2dHandler, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK) |
bcostm | 0:e1d164542663 | 1344 | { |
bcostm | 0:e1d164542663 | 1345 | /* Polling For DMA transfer */ |
bcostm | 0:e1d164542663 | 1346 | HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10); |
bcostm | 0:e1d164542663 | 1347 | } |
bcostm | 0:e1d164542663 | 1348 | } |
bcostm | 0:e1d164542663 | 1349 | } |
bcostm | 0:e1d164542663 | 1350 | } |
bcostm | 0:e1d164542663 | 1351 | |
bcostm | 0:e1d164542663 | 1352 | /** |
bcostm | 0:e1d164542663 | 1353 | * @brief Converts Line to ARGB8888 pixel format. |
bcostm | 0:e1d164542663 | 1354 | * @param pSrc: pointer to source buffer |
bcostm | 0:e1d164542663 | 1355 | * @param pDst: output color |
bcostm | 0:e1d164542663 | 1356 | * @param xSize: buffer width |
bcostm | 0:e1d164542663 | 1357 | * @param ColorMode: input color mode |
bcostm | 0:e1d164542663 | 1358 | * @retval None |
bcostm | 0:e1d164542663 | 1359 | */ |
bcostm | 0:e1d164542663 | 1360 | static void ConvertLineToARGB8888(void * pSrc, void * pDst, uint32_t xSize, uint32_t ColorMode) |
bcostm | 0:e1d164542663 | 1361 | { |
bcostm | 0:e1d164542663 | 1362 | /* Configure the DMA2D Mode, Color Mode and output offset */ |
bcostm | 0:e1d164542663 | 1363 | Dma2dHandler.Init.Mode = DMA2D_M2M_PFC; |
bcostm | 0:e1d164542663 | 1364 | Dma2dHandler.Init.ColorMode = DMA2D_ARGB8888; |
bcostm | 0:e1d164542663 | 1365 | Dma2dHandler.Init.OutputOffset = 0; |
bcostm | 0:e1d164542663 | 1366 | |
bcostm | 0:e1d164542663 | 1367 | /* Foreground Configuration */ |
bcostm | 0:e1d164542663 | 1368 | Dma2dHandler.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA; |
bcostm | 0:e1d164542663 | 1369 | Dma2dHandler.LayerCfg[1].InputAlpha = 0xFF; |
bcostm | 0:e1d164542663 | 1370 | Dma2dHandler.LayerCfg[1].InputColorMode = ColorMode; |
bcostm | 0:e1d164542663 | 1371 | Dma2dHandler.LayerCfg[1].InputOffset = 0; |
bcostm | 0:e1d164542663 | 1372 | |
bcostm | 0:e1d164542663 | 1373 | Dma2dHandler.Instance = DMA2D; |
bcostm | 0:e1d164542663 | 1374 | |
bcostm | 0:e1d164542663 | 1375 | /* DMA2D Initialization */ |
bcostm | 0:e1d164542663 | 1376 | if(HAL_DMA2D_Init(&Dma2dHandler) == HAL_OK) |
bcostm | 0:e1d164542663 | 1377 | { |
bcostm | 0:e1d164542663 | 1378 | if(HAL_DMA2D_ConfigLayer(&Dma2dHandler, 1) == HAL_OK) |
bcostm | 0:e1d164542663 | 1379 | { |
bcostm | 0:e1d164542663 | 1380 | if (HAL_DMA2D_Start(&Dma2dHandler, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK) |
bcostm | 0:e1d164542663 | 1381 | { |
bcostm | 0:e1d164542663 | 1382 | /* Polling For DMA transfer */ |
bcostm | 0:e1d164542663 | 1383 | HAL_DMA2D_PollForTransfer(&Dma2dHandler, 10); |
bcostm | 0:e1d164542663 | 1384 | } |
bcostm | 0:e1d164542663 | 1385 | } |
bcostm | 0:e1d164542663 | 1386 | } |
bcostm | 0:e1d164542663 | 1387 | } |
bcostm | 0:e1d164542663 | 1388 | |
bcostm | 0:e1d164542663 | 1389 | /** |
bcostm | 0:e1d164542663 | 1390 | * @} |
bcostm | 0:e1d164542663 | 1391 | */ |
bcostm | 0:e1d164542663 | 1392 | |
bcostm | 0:e1d164542663 | 1393 | /** |
bcostm | 0:e1d164542663 | 1394 | * @} |
bcostm | 0:e1d164542663 | 1395 | */ |
bcostm | 0:e1d164542663 | 1396 | |
bcostm | 0:e1d164542663 | 1397 | /** |
bcostm | 0:e1d164542663 | 1398 | * @} |
bcostm | 0:e1d164542663 | 1399 | */ |
bcostm | 0:e1d164542663 | 1400 | |
bcostm | 0:e1d164542663 | 1401 | /** |
bcostm | 0:e1d164542663 | 1402 | * @} |
bcostm | 0:e1d164542663 | 1403 | */ |
bcostm | 0:e1d164542663 | 1404 | |
bcostm | 0:e1d164542663 | 1405 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |