BSP driver for DISCO_L496AG

Dependents:   DISCO_L496AG-LCD-prova_1 DISCO_L496AG-LCD-prova_2 DISCO_L496AG-LCD-demo DISCO_L496AG-SRAM-demo

Committer:
Jerome Coutant
Date:
Wed Nov 20 16:48:24 2019 +0100
Revision:
2:106c7b82e064
Parent:
1:753810620fe9
Update BSP files with CubeL4 V1.14.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:d83f1c8ca282 1 /**
bcostm 0:d83f1c8ca282 2 ******************************************************************************
bcostm 0:d83f1c8ca282 3 * @file stm32l496g_discovery_lcd.c
bcostm 0:d83f1c8ca282 4 * @author MCD Application Team
bcostm 0:d83f1c8ca282 5 * @brief This file includes the driver for Liquid Crystal Display (LCD) module
bcostm 0:d83f1c8ca282 6 * mounted on STM32L496G-DISCOVERY board.
bcostm 0:d83f1c8ca282 7 ******************************************************************************
bcostm 0:d83f1c8ca282 8 * @attention
bcostm 0:d83f1c8ca282 9 *
Jerome Coutant 2:106c7b82e064 10 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
Jerome Coutant 2:106c7b82e064 11 * All rights reserved.</center></h2>
bcostm 0:d83f1c8ca282 12 *
Jerome Coutant 2:106c7b82e064 13 * This software component is licensed by ST under BSD 3-Clause license,
Jerome Coutant 2:106c7b82e064 14 * the "License"; You may not use this file except in compliance with the
Jerome Coutant 2:106c7b82e064 15 * License. You may obtain a copy of the License at:
Jerome Coutant 2:106c7b82e064 16 * opensource.org/licenses/BSD-3-Clause
bcostm 0:d83f1c8ca282 17 *
bcostm 0:d83f1c8ca282 18 ******************************************************************************
bcostm 0:d83f1c8ca282 19 */
bcostm 0:d83f1c8ca282 20
bcostm 0:d83f1c8ca282 21 /* File Info : -----------------------------------------------------------------
bcostm 0:d83f1c8ca282 22 User NOTES
bcostm 0:d83f1c8ca282 23 1. How To use this driver:
bcostm 0:d83f1c8ca282 24 --------------------------
bcostm 0:d83f1c8ca282 25 - This driver is used to drive indirectly an LCD TFT.
bcostm 0:d83f1c8ca282 26 - This driver supports the LS016B8UY LCD.
bcostm 0:d83f1c8ca282 27 - The LS016B8UY and ST7789H2 components driver MUST be included with this driver.
bcostm 0:d83f1c8ca282 28
bcostm 0:d83f1c8ca282 29 2. Driver description:
bcostm 0:d83f1c8ca282 30 ---------------------
bcostm 0:d83f1c8ca282 31 + Initialization steps:
bcostm 0:d83f1c8ca282 32 o Initialize the LCD using the BSP_LCD_Init() function.
bcostm 0:d83f1c8ca282 33
bcostm 0:d83f1c8ca282 34 + Display on LCD
bcostm 0:d83f1c8ca282 35 o Clear the hole LCD using BSP_LCD_Clear() function or only one specified string
bcostm 0:d83f1c8ca282 36 line using the BSP_LCD_ClearStringLine() function.
bcostm 0:d83f1c8ca282 37 o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
bcostm 0:d83f1c8ca282 38 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
bcostm 0:d83f1c8ca282 39 o Display a string line on the specified position (x,y in pixel) and align mode
bcostm 0:d83f1c8ca282 40 using the BSP_LCD_DisplayStringAtLine() function.
bcostm 0:d83f1c8ca282 41 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
bcostm 0:d83f1c8ca282 42 on LCD using the available set of functions.
bcostm 0:d83f1c8ca282 43
bcostm 0:d83f1c8ca282 44 ------------------------------------------------------------------------------*/
bcostm 0:d83f1c8ca282 45
bcostm 0:d83f1c8ca282 46 /* Includes ------------------------------------------------------------------*/
bcostm 0:d83f1c8ca282 47 #include "stm32l496g_discovery_lcd.h"
bcostm 0:d83f1c8ca282 48 #include "../../../Utilities/Fonts/fonts.h"
bcostm 1:753810620fe9 49 /* Removed for MBED
bcostm 0:d83f1c8ca282 50 #include "../../../Utilities/Fonts/font24.c"
bcostm 0:d83f1c8ca282 51 #include "../../../Utilities/Fonts/font20.c"
bcostm 0:d83f1c8ca282 52 #include "../../../Utilities/Fonts/font16.c"
bcostm 0:d83f1c8ca282 53 #include "../../../Utilities/Fonts/font12.c"
bcostm 1:753810620fe9 54 #include "../../../Utilities/Fonts/font8.c" */
bcostm 0:d83f1c8ca282 55
bcostm 0:d83f1c8ca282 56
bcostm 0:d83f1c8ca282 57 static uint32_t bsp_lcd_initialized = 0;
bcostm 0:d83f1c8ca282 58 static uint8_t LCD_orientation = LCD_ORIENTATION_UNDEFINED;
bcostm 0:d83f1c8ca282 59
bcostm 0:d83f1c8ca282 60 uint32_t dimming_on = 0;
bcostm 0:d83f1c8ca282 61
bcostm 0:d83f1c8ca282 62 typedef struct dimming_config_s
bcostm 0:d83f1c8ca282 63 {
bcostm 0:d83f1c8ca282 64 uint8_t ongoing;
bcostm 0:d83f1c8ca282 65 uint8_t start;
bcostm 0:d83f1c8ca282 66 uint8_t stop;
bcostm 0:d83f1c8ca282 67 uint8_t step;
bcostm 0:d83f1c8ca282 68 uint8_t delay;
bcostm 0:d83f1c8ca282 69 } dimming_config_t;
bcostm 0:d83f1c8ca282 70
bcostm 0:d83f1c8ca282 71 #define __DIMMING_CYCLE_VALUE(value) (uint32_t)((PERIOD_VALUE * value)/100)
bcostm 0:d83f1c8ca282 72 static dimming_config_t dimming_config = { 0, 25, 5, 1, PULSE_DECREASE_DELAY };
bcostm 0:d83f1c8ca282 73
bcostm 0:d83f1c8ca282 74 #if defined(LPTIMER_DIMMING)
bcostm 0:d83f1c8ca282 75 LPTIM_HandleTypeDef LCD_LpTimHandle;
bcostm 0:d83f1c8ca282 76 #endif
bcostm 0:d83f1c8ca282 77 /* Timer handler declaration */
bcostm 0:d83f1c8ca282 78 TIM_HandleTypeDef LCD_TimHandle;
bcostm 0:d83f1c8ca282 79 /* Timer Output Compare Configuration Structure declaration */
bcostm 0:d83f1c8ca282 80 TIM_OC_InitTypeDef LCD_sConfig;
bcostm 0:d83f1c8ca282 81
bcostm 0:d83f1c8ca282 82 #if defined(LPTIMER_DIMMING)
bcostm 0:d83f1c8ca282 83 extern uint32_t dimming_enable;
bcostm 0:d83f1c8ca282 84 #endif
bcostm 0:d83f1c8ca282 85
bcostm 0:d83f1c8ca282 86
bcostm 0:d83f1c8ca282 87 extern uint32_t ts_io_init;
bcostm 0:d83f1c8ca282 88
bcostm 0:d83f1c8ca282 89 /* Use by application to not use backlight */
bcostm 0:d83f1c8ca282 90 FlagStatus WakeUpFromStandby;
bcostm 0:d83f1c8ca282 91 FlagStatus WakeUpFromShutdown;
bcostm 0:d83f1c8ca282 92
bcostm 0:d83f1c8ca282 93
bcostm 0:d83f1c8ca282 94 /** @addtogroup BSP
bcostm 0:d83f1c8ca282 95 * @{
bcostm 0:d83f1c8ca282 96 */
bcostm 0:d83f1c8ca282 97
bcostm 0:d83f1c8ca282 98 /** @addtogroup STM32L496G_DISCOVERY
bcostm 0:d83f1c8ca282 99 * @{
bcostm 0:d83f1c8ca282 100 */
bcostm 0:d83f1c8ca282 101
bcostm 0:d83f1c8ca282 102 /** @defgroup STM32L496G_DISCOVERY_LCD STM32L496G-DISCOVERY LCD
bcostm 0:d83f1c8ca282 103 * @{
bcostm 0:d83f1c8ca282 104 */
bcostm 0:d83f1c8ca282 105
bcostm 0:d83f1c8ca282 106 /** @defgroup STM32L496G_DISCOVERY_LCD_Private_TypesDefinitions STM32L496G Discovery Lcd Private TypesDef
bcostm 0:d83f1c8ca282 107 * @{
bcostm 0:d83f1c8ca282 108 */
bcostm 0:d83f1c8ca282 109 /**
bcostm 0:d83f1c8ca282 110 * @}
bcostm 0:d83f1c8ca282 111 */
bcostm 0:d83f1c8ca282 112
bcostm 0:d83f1c8ca282 113 /** @defgroup STM32L496G_DISCOVERY_LCD_Private_Defines STM32L496G Discovery Lcd Private Defines
bcostm 0:d83f1c8ca282 114 * @{
bcostm 0:d83f1c8ca282 115 */
bcostm 0:d83f1c8ca282 116 #define POLY_X(Z) ((int32_t)((Points + Z)->X))
bcostm 0:d83f1c8ca282 117 #define POLY_Y(Z) ((int32_t)((Points + Z)->Y))
bcostm 0:d83f1c8ca282 118 /**
bcostm 0:d83f1c8ca282 119 * @}
bcostm 0:d83f1c8ca282 120 */
bcostm 0:d83f1c8ca282 121
bcostm 0:d83f1c8ca282 122 /** @defgroup STM32L496G_DISCOVERY_LCD_Private_Macros STM32L496G Discovery Lcd Private Macros
bcostm 0:d83f1c8ca282 123 * @{
bcostm 0:d83f1c8ca282 124 */
bcostm 0:d83f1c8ca282 125 #define ABS(X) ((X) > 0 ? (X) : -(X))
bcostm 0:d83f1c8ca282 126 /**
bcostm 0:d83f1c8ca282 127 * @}
bcostm 0:d83f1c8ca282 128 */
bcostm 0:d83f1c8ca282 129
bcostm 0:d83f1c8ca282 130 /** @defgroup STM32L496G_DISCOVERY_LCD_Private_Variables STM32L496G Discovery Lcd Private Variables
bcostm 0:d83f1c8ca282 131 * @{
bcostm 0:d83f1c8ca282 132 */
bcostm 0:d83f1c8ca282 133 LCD_DrawPropTypeDef DrawProp;
bcostm 0:d83f1c8ca282 134 static LCD_DrvTypeDef *LcdDrv;
bcostm 0:d83f1c8ca282 135
bcostm 0:d83f1c8ca282 136
bcostm 0:d83f1c8ca282 137 /**
bcostm 0:d83f1c8ca282 138 * @}
bcostm 0:d83f1c8ca282 139 */
bcostm 0:d83f1c8ca282 140
bcostm 0:d83f1c8ca282 141 /** @defgroup STM32L496G_DISCOVERY_LCD_Private_FunctionPrototypes STM32L496G Discovery Lcd Private Prototypes
bcostm 0:d83f1c8ca282 142 * @{
bcostm 0:d83f1c8ca282 143 */
bcostm 0:d83f1c8ca282 144 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
bcostm 0:d83f1c8ca282 145 static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height);
bcostm 0:d83f1c8ca282 146 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
bcostm 0:d83f1c8ca282 147 /**
bcostm 0:d83f1c8ca282 148 * @}
bcostm 0:d83f1c8ca282 149 */
bcostm 0:d83f1c8ca282 150
bcostm 0:d83f1c8ca282 151 /** @defgroup STM32L496G_DISCOVERY_LCD_Private_Functions STM32L496G Discovery Lcd Private Functions
bcostm 0:d83f1c8ca282 152 * @{
bcostm 0:d83f1c8ca282 153 */
bcostm 0:d83f1c8ca282 154 /**
bcostm 0:d83f1c8ca282 155 * @brief Initializes the LCD.
bcostm 0:d83f1c8ca282 156 * @param None
bcostm 0:d83f1c8ca282 157 * @retval LCD state
bcostm 0:d83f1c8ca282 158 */
bcostm 0:d83f1c8ca282 159 uint8_t BSP_LCD_Init(void)
bcostm 0:d83f1c8ca282 160 {
bcostm 0:d83f1c8ca282 161 return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE));
bcostm 0:d83f1c8ca282 162 }
bcostm 0:d83f1c8ca282 163
bcostm 0:d83f1c8ca282 164 /**
bcostm 0:d83f1c8ca282 165 * @brief Initializes the LCD with a given orientation.
bcostm 0:d83f1c8ca282 166 * @param orientation: LCD_ORIENTATION_PORTRAIT or LCD_ORIENTATION_LANDSCAPE
bcostm 0:d83f1c8ca282 167 * @retval LCD state
bcostm 0:d83f1c8ca282 168 */
bcostm 0:d83f1c8ca282 169 uint8_t BSP_LCD_InitEx(uint32_t orientation)
bcostm 0:d83f1c8ca282 170 {
bcostm 0:d83f1c8ca282 171 uint8_t ret = LCD_ERROR;
bcostm 0:d83f1c8ca282 172 uint32_t i = 0;
bcostm 0:d83f1c8ca282 173
bcostm 0:d83f1c8ca282 174 if (bsp_lcd_initialized == 1)
bcostm 0:d83f1c8ca282 175 {
bcostm 0:d83f1c8ca282 176 ret = LCD_OK;
bcostm 0:d83f1c8ca282 177 }
bcostm 0:d83f1c8ca282 178 else
bcostm 0:d83f1c8ca282 179 {
bcostm 0:d83f1c8ca282 180 /* Initialize the IO functionalities */
bcostm 0:d83f1c8ca282 181 if (BSP_IO_Init() == IO_ERROR)
bcostm 0:d83f1c8ca282 182 {
bcostm 0:d83f1c8ca282 183 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 184 }
bcostm 0:d83f1c8ca282 185
bcostm 0:d83f1c8ca282 186 /* Initialize LCD special pins GPIOs */
bcostm 0:d83f1c8ca282 187 BSP_LCD_MspInit();
bcostm 0:d83f1c8ca282 188
bcostm 0:d83f1c8ca282 189 /* LCD Power On */
bcostm 0:d83f1c8ca282 190 HAL_GPIO_WritePin(LCD_PWR_CTRL_GPIO_PORT, LCD_PWR_CTRL_PIN, GPIO_PIN_RESET);
bcostm 0:d83f1c8ca282 191
bcostm 0:d83f1c8ca282 192 /* Default value for draw propriety */
bcostm 0:d83f1c8ca282 193 DrawProp.BackColor = 0xFFFF;
bcostm 0:d83f1c8ca282 194 DrawProp.pFont = &Font24;
bcostm 0:d83f1c8ca282 195 DrawProp.TextColor = 0x0000;
bcostm 0:d83f1c8ca282 196
bcostm 0:d83f1c8ca282 197 if ((WakeUpFromStandby == RESET) && (WakeUpFromShutdown == RESET))
bcostm 0:d83f1c8ca282 198 {
bcostm 0:d83f1c8ca282 199 /* Backlight control signal assertion */
bcostm 0:d83f1c8ca282 200 HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET);
bcostm 0:d83f1c8ca282 201 }
bcostm 0:d83f1c8ca282 202
bcostm 0:d83f1c8ca282 203 /* Reset the LCD */
bcostm 0:d83f1c8ca282 204 BSP_LCD_Reset();
bcostm 0:d83f1c8ca282 205
bcostm 0:d83f1c8ca282 206 if (ST7789H2_drv.ReadID() == ST7789H2_ID)
bcostm 0:d83f1c8ca282 207 {
bcostm 0:d83f1c8ca282 208 LcdDrv = &ST7789H2_drv;
bcostm 0:d83f1c8ca282 209
bcostm 0:d83f1c8ca282 210 /* LCD Init */
bcostm 0:d83f1c8ca282 211 LcdDrv->Init();
bcostm 0:d83f1c8ca282 212
bcostm 0:d83f1c8ca282 213 /* Fill LCD frame memory with white pixels (or black pixels if INIT_BLACK_LCD is enabled) */
bcostm 0:d83f1c8ca282 214 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t *)NULL, 0); /* RAM Write Data */
bcostm 0:d83f1c8ca282 215 for (i = 0; i < (ST7789H2_LCD_PIXEL_WIDTH * ST7789H2_LCD_PIXEL_HEIGHT); i++)
bcostm 0:d83f1c8ca282 216 {
bcostm 0:d83f1c8ca282 217 #if defined(INIT_BLACK_LCD)
bcostm 0:d83f1c8ca282 218 LCD_IO_WriteData(0x0);
bcostm 0:d83f1c8ca282 219 #else
bcostm 0:d83f1c8ca282 220 LCD_IO_WriteData(0xFFFF);
bcostm 0:d83f1c8ca282 221 #endif
bcostm 0:d83f1c8ca282 222 }
bcostm 0:d83f1c8ca282 223
bcostm 0:d83f1c8ca282 224 if (orientation == LCD_ORIENTATION_PORTRAIT)
bcostm 0:d83f1c8ca282 225 {
bcostm 0:d83f1c8ca282 226 ST7789H2_SetOrientation(ST7789H2_ORIENTATION_PORTRAIT);
bcostm 0:d83f1c8ca282 227 LCD_orientation = LCD_ORIENTATION_PORTRAIT;
bcostm 0:d83f1c8ca282 228 }
bcostm 0:d83f1c8ca282 229 else
bcostm 0:d83f1c8ca282 230 {
bcostm 0:d83f1c8ca282 231 LCD_orientation = LCD_ORIENTATION_LANDSCAPE;
bcostm 0:d83f1c8ca282 232 }
bcostm 0:d83f1c8ca282 233 /* Initialize the font */
bcostm 0:d83f1c8ca282 234 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
bcostm 0:d83f1c8ca282 235
bcostm 0:d83f1c8ca282 236 bsp_lcd_initialized = 1;
bcostm 0:d83f1c8ca282 237 ret = LCD_OK;
bcostm 0:d83f1c8ca282 238 }
bcostm 0:d83f1c8ca282 239 }
bcostm 0:d83f1c8ca282 240
bcostm 0:d83f1c8ca282 241 return ret;
bcostm 0:d83f1c8ca282 242 }
bcostm 0:d83f1c8ca282 243
bcostm 0:d83f1c8ca282 244 /**
bcostm 0:d83f1c8ca282 245 * @brief Reset the LCD.
bcostm 0:d83f1c8ca282 246 * @param None
bcostm 0:d83f1c8ca282 247 * @retval LCD state
bcostm 0:d83f1c8ca282 248 */
bcostm 0:d83f1c8ca282 249 void BSP_LCD_Reset(void)
bcostm 0:d83f1c8ca282 250 {
bcostm 0:d83f1c8ca282 251 /* Apply hardware reset according to procedure indicated in FRD154BP2901 documentation */
bcostm 0:d83f1c8ca282 252 BSP_IO_WritePin(LCD_RST_PIN, GPIO_PIN_RESET);
bcostm 0:d83f1c8ca282 253 HAL_Delay(5); /* Reset signal asserted during 5ms */
bcostm 0:d83f1c8ca282 254 BSP_IO_WritePin(LCD_RST_PIN, GPIO_PIN_SET);
bcostm 0:d83f1c8ca282 255 HAL_Delay(10); /* Reset signal released during 10ms */
bcostm 0:d83f1c8ca282 256 BSP_IO_WritePin(LCD_RST_PIN, GPIO_PIN_RESET);
bcostm 0:d83f1c8ca282 257 HAL_Delay(20); /* Reset signal asserted during 20ms */
bcostm 0:d83f1c8ca282 258 BSP_IO_WritePin(LCD_RST_PIN, GPIO_PIN_SET);
bcostm 0:d83f1c8ca282 259 HAL_Delay(10); /* Reset signal released during 10ms */
bcostm 0:d83f1c8ca282 260 }
bcostm 0:d83f1c8ca282 261
bcostm 0:d83f1c8ca282 262 /**
bcostm 0:d83f1c8ca282 263 * @brief DeInitializes the LCD.
bcostm 0:d83f1c8ca282 264 * @param None
bcostm 0:d83f1c8ca282 265 * @retval LCD state
bcostm 0:d83f1c8ca282 266 */
bcostm 0:d83f1c8ca282 267 uint8_t BSP_LCD_DeInit(void)
bcostm 0:d83f1c8ca282 268 {
bcostm 0:d83f1c8ca282 269 BSP_LCD_MspDeInit();
bcostm 0:d83f1c8ca282 270
bcostm 0:d83f1c8ca282 271 bsp_lcd_initialized = 0;
bcostm 0:d83f1c8ca282 272 ts_io_init = 0;
bcostm 0:d83f1c8ca282 273
bcostm 0:d83f1c8ca282 274 return LCD_OK;
bcostm 0:d83f1c8ca282 275 }
bcostm 0:d83f1c8ca282 276
bcostm 0:d83f1c8ca282 277 /**
bcostm 0:d83f1c8ca282 278 * @brief Gets the LCD X size.
bcostm 0:d83f1c8ca282 279 * @param None
bcostm 0:d83f1c8ca282 280 * @retval Used LCD X size
bcostm 0:d83f1c8ca282 281 */
bcostm 0:d83f1c8ca282 282 uint32_t BSP_LCD_GetXSize(void)
bcostm 0:d83f1c8ca282 283 {
bcostm 0:d83f1c8ca282 284 return (LcdDrv->GetLcdPixelWidth());
bcostm 0:d83f1c8ca282 285 }
bcostm 0:d83f1c8ca282 286
bcostm 0:d83f1c8ca282 287 /**
bcostm 0:d83f1c8ca282 288 * @brief Gets the LCD Y size.
bcostm 0:d83f1c8ca282 289 * @param None
bcostm 0:d83f1c8ca282 290 * @retval Used LCD Y size
bcostm 0:d83f1c8ca282 291 */
bcostm 0:d83f1c8ca282 292 uint32_t BSP_LCD_GetYSize(void)
bcostm 0:d83f1c8ca282 293 {
bcostm 0:d83f1c8ca282 294 return (LcdDrv->GetLcdPixelHeight());
bcostm 0:d83f1c8ca282 295 }
bcostm 0:d83f1c8ca282 296
bcostm 0:d83f1c8ca282 297 /**
bcostm 0:d83f1c8ca282 298 * @brief Gets the LCD text color.
bcostm 0:d83f1c8ca282 299 * @param None
bcostm 0:d83f1c8ca282 300 * @retval Used text color.
bcostm 0:d83f1c8ca282 301 */
bcostm 0:d83f1c8ca282 302 uint16_t BSP_LCD_GetTextColor(void)
bcostm 0:d83f1c8ca282 303 {
bcostm 0:d83f1c8ca282 304 return DrawProp.TextColor;
bcostm 0:d83f1c8ca282 305 }
bcostm 0:d83f1c8ca282 306
bcostm 0:d83f1c8ca282 307 /**
bcostm 0:d83f1c8ca282 308 * @brief Gets the LCD background color.
bcostm 0:d83f1c8ca282 309 * @param None
bcostm 0:d83f1c8ca282 310 * @retval Used background color
bcostm 0:d83f1c8ca282 311 */
bcostm 0:d83f1c8ca282 312 uint16_t BSP_LCD_GetBackColor(void)
bcostm 0:d83f1c8ca282 313 {
bcostm 0:d83f1c8ca282 314 return DrawProp.BackColor;
bcostm 0:d83f1c8ca282 315 }
bcostm 0:d83f1c8ca282 316
bcostm 0:d83f1c8ca282 317 /**
bcostm 0:d83f1c8ca282 318 * @brief Sets the LCD text color.
bcostm 0:d83f1c8ca282 319 * @param Color: Text color code RGB(5-6-5)
bcostm 0:d83f1c8ca282 320 * @retval None
bcostm 0:d83f1c8ca282 321 */
bcostm 0:d83f1c8ca282 322 void BSP_LCD_SetTextColor(uint16_t Color)
bcostm 0:d83f1c8ca282 323 {
bcostm 0:d83f1c8ca282 324 DrawProp.TextColor = Color;
bcostm 0:d83f1c8ca282 325 }
bcostm 0:d83f1c8ca282 326
bcostm 0:d83f1c8ca282 327 /**
bcostm 0:d83f1c8ca282 328 * @brief Sets the LCD background color.
bcostm 0:d83f1c8ca282 329 * @param Color: Background color code RGB(5-6-5)
bcostm 0:d83f1c8ca282 330 * @retval None
bcostm 0:d83f1c8ca282 331 */
bcostm 0:d83f1c8ca282 332 void BSP_LCD_SetBackColor(uint16_t Color)
bcostm 0:d83f1c8ca282 333 {
bcostm 0:d83f1c8ca282 334 DrawProp.BackColor = Color;
bcostm 0:d83f1c8ca282 335 }
bcostm 0:d83f1c8ca282 336
bcostm 0:d83f1c8ca282 337 /**
bcostm 0:d83f1c8ca282 338 * @brief Sets the LCD text font.
bcostm 0:d83f1c8ca282 339 * @param fonts: Font to be used
bcostm 0:d83f1c8ca282 340 * @retval None
bcostm 0:d83f1c8ca282 341 */
bcostm 0:d83f1c8ca282 342 void BSP_LCD_SetFont(sFONT *fonts)
bcostm 0:d83f1c8ca282 343 {
bcostm 0:d83f1c8ca282 344 DrawProp.pFont = fonts;
bcostm 0:d83f1c8ca282 345 }
bcostm 0:d83f1c8ca282 346
bcostm 0:d83f1c8ca282 347 /**
bcostm 0:d83f1c8ca282 348 * @brief Gets the LCD text font.
bcostm 0:d83f1c8ca282 349 * @param None
bcostm 0:d83f1c8ca282 350 * @retval Used font
bcostm 0:d83f1c8ca282 351 */
bcostm 0:d83f1c8ca282 352 sFONT *BSP_LCD_GetFont(void)
bcostm 0:d83f1c8ca282 353 {
bcostm 0:d83f1c8ca282 354 return DrawProp.pFont;
bcostm 0:d83f1c8ca282 355 }
bcostm 0:d83f1c8ca282 356
bcostm 0:d83f1c8ca282 357 /**
bcostm 0:d83f1c8ca282 358 * @brief Clears the hole LCD.
bcostm 0:d83f1c8ca282 359 * @param Color: Color of the background
bcostm 0:d83f1c8ca282 360 * @retval None
bcostm 0:d83f1c8ca282 361 */
bcostm 0:d83f1c8ca282 362 void BSP_LCD_Clear(uint16_t Color)
bcostm 0:d83f1c8ca282 363 {
bcostm 0:d83f1c8ca282 364 uint32_t counter = 0;
bcostm 0:d83f1c8ca282 365 uint32_t y_size = 0;
bcostm 0:d83f1c8ca282 366 uint32_t color_backup = DrawProp.TextColor;
bcostm 0:d83f1c8ca282 367
bcostm 0:d83f1c8ca282 368 DrawProp.TextColor = Color;
bcostm 0:d83f1c8ca282 369 y_size = BSP_LCD_GetYSize();
bcostm 0:d83f1c8ca282 370
bcostm 0:d83f1c8ca282 371 for (counter = 0; counter < y_size; counter++)
bcostm 0:d83f1c8ca282 372 {
bcostm 0:d83f1c8ca282 373 BSP_LCD_DrawHLine(0, counter, BSP_LCD_GetXSize());
bcostm 0:d83f1c8ca282 374 }
bcostm 0:d83f1c8ca282 375 DrawProp.TextColor = color_backup;
bcostm 0:d83f1c8ca282 376 BSP_LCD_SetTextColor(DrawProp.TextColor);
bcostm 0:d83f1c8ca282 377 }
bcostm 0:d83f1c8ca282 378
bcostm 0:d83f1c8ca282 379 /**
bcostm 0:d83f1c8ca282 380 * @brief Clears the selected line.
bcostm 0:d83f1c8ca282 381 * @param Line: Line to be cleared
bcostm 0:d83f1c8ca282 382 * This parameter can be one of the following values:
bcostm 0:d83f1c8ca282 383 * @arg 0..9: if the Current fonts is Font16x24
bcostm 0:d83f1c8ca282 384 * @arg 0..19: if the Current fonts is Font12x12 or Font8x12
bcostm 0:d83f1c8ca282 385 * @arg 0..29: if the Current fonts is Font8x8
bcostm 0:d83f1c8ca282 386 * @retval None
bcostm 0:d83f1c8ca282 387 */
bcostm 0:d83f1c8ca282 388 void BSP_LCD_ClearStringLine(uint16_t Line)
bcostm 0:d83f1c8ca282 389 {
bcostm 0:d83f1c8ca282 390 uint32_t color_backup = DrawProp.TextColor;
bcostm 0:d83f1c8ca282 391
bcostm 0:d83f1c8ca282 392 DrawProp.TextColor = DrawProp.BackColor;;
bcostm 0:d83f1c8ca282 393
bcostm 0:d83f1c8ca282 394 /* Draw a rectangle with background color */
bcostm 0:d83f1c8ca282 395 BSP_LCD_FillRect(0, (Line * DrawProp.pFont->Height), BSP_LCD_GetXSize(), DrawProp.pFont->Height);
bcostm 0:d83f1c8ca282 396
bcostm 0:d83f1c8ca282 397 DrawProp.TextColor = color_backup;
bcostm 0:d83f1c8ca282 398 BSP_LCD_SetTextColor(DrawProp.TextColor);
bcostm 0:d83f1c8ca282 399 }
bcostm 0:d83f1c8ca282 400
bcostm 0:d83f1c8ca282 401 /**
bcostm 0:d83f1c8ca282 402 * @brief Displays one character.
bcostm 0:d83f1c8ca282 403 * @param Xpos: Start column address
bcostm 0:d83f1c8ca282 404 * @param Ypos: Line where to display the character shape.
bcostm 0:d83f1c8ca282 405 * @param Ascii: Character ascii code
bcostm 0:d83f1c8ca282 406 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
bcostm 0:d83f1c8ca282 407 * @retval None
bcostm 0:d83f1c8ca282 408 */
bcostm 0:d83f1c8ca282 409 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
bcostm 0:d83f1c8ca282 410 {
bcostm 0:d83f1c8ca282 411 DrawChar(Xpos, Ypos, &DrawProp.pFont->table[(Ascii - ' ') *\
bcostm 0:d83f1c8ca282 412 DrawProp.pFont->Height * ((DrawProp.pFont->Width + 7) / 8)]);
bcostm 0:d83f1c8ca282 413 }
bcostm 0:d83f1c8ca282 414
bcostm 0:d83f1c8ca282 415 /**
bcostm 0:d83f1c8ca282 416 * @brief Displays characters on the LCD.
bcostm 0:d83f1c8ca282 417 * @param Xpos: X position (in pixel)
bcostm 0:d83f1c8ca282 418 * @param Ypos: Y position (in pixel)
bcostm 0:d83f1c8ca282 419 * @param Text: Pointer to string to display on LCD
bcostm 0:d83f1c8ca282 420 * @param Mode: Display mode
bcostm 0:d83f1c8ca282 421 * This parameter can be one of the following values:
bcostm 0:d83f1c8ca282 422 * @arg CENTER_MODE
bcostm 0:d83f1c8ca282 423 * @arg RIGHT_MODE
bcostm 0:d83f1c8ca282 424 * @arg LEFT_MODE
bcostm 0:d83f1c8ca282 425 * @retval None
bcostm 0:d83f1c8ca282 426 */
bcostm 0:d83f1c8ca282 427 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode)
bcostm 0:d83f1c8ca282 428 {
bcostm 0:d83f1c8ca282 429 uint16_t refcolumn = 1, i = 0;
bcostm 0:d83f1c8ca282 430 uint32_t size = 0, xsize = 0;
bcostm 0:d83f1c8ca282 431 uint8_t *ptr = Text;
bcostm 0:d83f1c8ca282 432
bcostm 0:d83f1c8ca282 433 /* Get the text size */
bcostm 0:d83f1c8ca282 434 while (*ptr++)
bcostm 0:d83f1c8ca282 435 {
bcostm 0:d83f1c8ca282 436 size ++ ;
bcostm 0:d83f1c8ca282 437 }
bcostm 0:d83f1c8ca282 438
bcostm 0:d83f1c8ca282 439 /* Characters number per line */
bcostm 0:d83f1c8ca282 440 xsize = (BSP_LCD_GetXSize() / DrawProp.pFont->Width);
bcostm 0:d83f1c8ca282 441
bcostm 0:d83f1c8ca282 442 switch (Mode)
bcostm 0:d83f1c8ca282 443 {
bcostm 0:d83f1c8ca282 444 case CENTER_MODE:
bcostm 0:d83f1c8ca282 445 {
bcostm 0:d83f1c8ca282 446 refcolumn = Xpos + ((xsize - size) * DrawProp.pFont->Width) / 2;
bcostm 0:d83f1c8ca282 447 break;
bcostm 0:d83f1c8ca282 448 }
bcostm 0:d83f1c8ca282 449 case LEFT_MODE:
bcostm 0:d83f1c8ca282 450 {
bcostm 0:d83f1c8ca282 451 refcolumn = Xpos;
bcostm 0:d83f1c8ca282 452 break;
bcostm 0:d83f1c8ca282 453 }
bcostm 0:d83f1c8ca282 454 case RIGHT_MODE:
bcostm 0:d83f1c8ca282 455 {
bcostm 0:d83f1c8ca282 456 refcolumn = - Xpos + ((xsize - size) * DrawProp.pFont->Width);
bcostm 0:d83f1c8ca282 457 break;
bcostm 0:d83f1c8ca282 458 }
bcostm 0:d83f1c8ca282 459 default:
bcostm 0:d83f1c8ca282 460 {
bcostm 0:d83f1c8ca282 461 refcolumn = Xpos;
bcostm 0:d83f1c8ca282 462 break;
bcostm 0:d83f1c8ca282 463 }
bcostm 0:d83f1c8ca282 464 }
bcostm 0:d83f1c8ca282 465
bcostm 0:d83f1c8ca282 466 /* Check that the Start column is located in the screen */
bcostm 0:d83f1c8ca282 467 if ((refcolumn < 1) || (refcolumn >= 0x8000))
bcostm 0:d83f1c8ca282 468 {
bcostm 0:d83f1c8ca282 469 refcolumn = 1;
bcostm 0:d83f1c8ca282 470 }
bcostm 0:d83f1c8ca282 471
bcostm 0:d83f1c8ca282 472 /* Send the string character by character on lCD */
Jerome Coutant 2:106c7b82e064 473 while ((*Text != 0) && (((BSP_LCD_GetXSize() - (i * DrawProp.pFont->Width)) & 0xFFFF) >= DrawProp.pFont->Width))
bcostm 0:d83f1c8ca282 474 {
bcostm 0:d83f1c8ca282 475 /* Display one character on LCD */
bcostm 0:d83f1c8ca282 476 BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
bcostm 0:d83f1c8ca282 477 /* Decrement the column position by 16 */
bcostm 0:d83f1c8ca282 478 refcolumn += DrawProp.pFont->Width;
bcostm 0:d83f1c8ca282 479 /* Point on the next character */
bcostm 0:d83f1c8ca282 480 Text++;
bcostm 0:d83f1c8ca282 481 i++;
bcostm 0:d83f1c8ca282 482 }
bcostm 0:d83f1c8ca282 483 }
bcostm 0:d83f1c8ca282 484
bcostm 0:d83f1c8ca282 485 /**
bcostm 0:d83f1c8ca282 486 * @brief Displays a character on the LCD.
bcostm 0:d83f1c8ca282 487 * @param Line: Line where to display the character shape
bcostm 0:d83f1c8ca282 488 * This parameter can be one of the following values:
bcostm 0:d83f1c8ca282 489 * @arg 0..9: if the Current fonts is Font16x24
bcostm 0:d83f1c8ca282 490 * @arg 0..19: if the Current fonts is Font12x12 or Font8x12
bcostm 0:d83f1c8ca282 491 * @arg 0..29: if the Current fonts is Font8x8
bcostm 0:d83f1c8ca282 492 * @param ptr: Pointer to string to display on LCD
bcostm 0:d83f1c8ca282 493 * @retval None
bcostm 0:d83f1c8ca282 494 */
bcostm 0:d83f1c8ca282 495 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
bcostm 0:d83f1c8ca282 496 {
bcostm 0:d83f1c8ca282 497 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
bcostm 0:d83f1c8ca282 498 }
bcostm 0:d83f1c8ca282 499
bcostm 0:d83f1c8ca282 500 /**
bcostm 0:d83f1c8ca282 501 * @brief Reads an LCD pixel.
bcostm 0:d83f1c8ca282 502 * @param Xpos: X position
bcostm 0:d83f1c8ca282 503 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 504 * @retval RGB pixel color
bcostm 0:d83f1c8ca282 505 */
bcostm 0:d83f1c8ca282 506 uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
bcostm 0:d83f1c8ca282 507 {
bcostm 0:d83f1c8ca282 508 uint16_t ret = 0;
bcostm 0:d83f1c8ca282 509
bcostm 0:d83f1c8ca282 510 if (LcdDrv->ReadPixel != NULL)
bcostm 0:d83f1c8ca282 511 {
bcostm 0:d83f1c8ca282 512 ret = LcdDrv->ReadPixel(Xpos, Ypos);
bcostm 0:d83f1c8ca282 513 }
bcostm 0:d83f1c8ca282 514
bcostm 0:d83f1c8ca282 515 return ret;
bcostm 0:d83f1c8ca282 516 }
bcostm 0:d83f1c8ca282 517
bcostm 0:d83f1c8ca282 518 /**
bcostm 0:d83f1c8ca282 519 * @brief Draws a pixel on LCD.
bcostm 0:d83f1c8ca282 520 * @param Xpos: X position
bcostm 0:d83f1c8ca282 521 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 522 * @param RGB_Code: Pixel color in RGB mode (5-6-5)
bcostm 0:d83f1c8ca282 523 * @retval None
bcostm 0:d83f1c8ca282 524 */
bcostm 0:d83f1c8ca282 525 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code)
bcostm 0:d83f1c8ca282 526 {
bcostm 0:d83f1c8ca282 527 if (LcdDrv->WritePixel != NULL)
bcostm 0:d83f1c8ca282 528 {
bcostm 0:d83f1c8ca282 529 LcdDrv->WritePixel(Xpos, Ypos, RGB_Code);
bcostm 0:d83f1c8ca282 530 }
bcostm 0:d83f1c8ca282 531 }
bcostm 0:d83f1c8ca282 532
bcostm 0:d83f1c8ca282 533 /**
bcostm 0:d83f1c8ca282 534 * @brief Draws an horizontal line.
bcostm 0:d83f1c8ca282 535 * @param Xpos: X position
bcostm 0:d83f1c8ca282 536 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 537 * @param Length: Line length
bcostm 0:d83f1c8ca282 538 * @retval None
bcostm 0:d83f1c8ca282 539 */
bcostm 0:d83f1c8ca282 540 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bcostm 0:d83f1c8ca282 541 {
bcostm 0:d83f1c8ca282 542 uint32_t index = 0;
bcostm 0:d83f1c8ca282 543
bcostm 0:d83f1c8ca282 544 if (LcdDrv->DrawHLine != NULL)
bcostm 0:d83f1c8ca282 545 {
bcostm 0:d83f1c8ca282 546 LcdDrv->DrawHLine(DrawProp.TextColor, Xpos, Ypos, Length);
bcostm 0:d83f1c8ca282 547 }
bcostm 0:d83f1c8ca282 548 else
bcostm 0:d83f1c8ca282 549 {
bcostm 0:d83f1c8ca282 550 for (index = 0; index < Length; index++)
bcostm 0:d83f1c8ca282 551 {
bcostm 0:d83f1c8ca282 552 BSP_LCD_DrawPixel((Xpos + index), Ypos, DrawProp.TextColor);
bcostm 0:d83f1c8ca282 553 }
bcostm 0:d83f1c8ca282 554 }
bcostm 0:d83f1c8ca282 555 }
bcostm 0:d83f1c8ca282 556
bcostm 0:d83f1c8ca282 557 /**
bcostm 0:d83f1c8ca282 558 * @brief Draws a vertical line.
bcostm 0:d83f1c8ca282 559 * @param Xpos: X position
bcostm 0:d83f1c8ca282 560 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 561 * @param Length: Line length
bcostm 0:d83f1c8ca282 562 * @retval None
bcostm 0:d83f1c8ca282 563 */
bcostm 0:d83f1c8ca282 564 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bcostm 0:d83f1c8ca282 565 {
bcostm 0:d83f1c8ca282 566 uint32_t index = 0;
bcostm 0:d83f1c8ca282 567
bcostm 0:d83f1c8ca282 568 if (LcdDrv->DrawVLine != NULL)
bcostm 0:d83f1c8ca282 569 {
bcostm 0:d83f1c8ca282 570 LcdDrv->DrawVLine(DrawProp.TextColor, Xpos, Ypos, Length);
bcostm 0:d83f1c8ca282 571 }
bcostm 0:d83f1c8ca282 572 else
bcostm 0:d83f1c8ca282 573 {
bcostm 0:d83f1c8ca282 574 for (index = 0; index < Length; index++)
bcostm 0:d83f1c8ca282 575 {
bcostm 0:d83f1c8ca282 576 BSP_LCD_DrawPixel(Xpos, Ypos + index, DrawProp.TextColor);
bcostm 0:d83f1c8ca282 577 }
bcostm 0:d83f1c8ca282 578 }
bcostm 0:d83f1c8ca282 579 }
bcostm 0:d83f1c8ca282 580
bcostm 0:d83f1c8ca282 581 /**
bcostm 0:d83f1c8ca282 582 * @brief Draws an uni-line (between two points).
bcostm 0:d83f1c8ca282 583 * @param x1: Point 1 X position
bcostm 0:d83f1c8ca282 584 * @param y1: Point 1 Y position
bcostm 0:d83f1c8ca282 585 * @param x2: Point 2 X position
bcostm 0:d83f1c8ca282 586 * @param y2: Point 2 Y position
bcostm 0:d83f1c8ca282 587 * @retval None
bcostm 0:d83f1c8ca282 588 */
bcostm 0:d83f1c8ca282 589 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
bcostm 0:d83f1c8ca282 590 {
bcostm 0:d83f1c8ca282 591 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
bcostm 0:d83f1c8ca282 592 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
bcostm 0:d83f1c8ca282 593 curpixel = 0;
bcostm 0:d83f1c8ca282 594
bcostm 0:d83f1c8ca282 595 deltax = ABS(x2 - x1); /* The difference between the x's */
bcostm 0:d83f1c8ca282 596 deltay = ABS(y2 - y1); /* The difference between the y's */
bcostm 0:d83f1c8ca282 597 x = x1; /* Start x off at the first pixel */
bcostm 0:d83f1c8ca282 598 y = y1; /* Start y off at the first pixel */
bcostm 0:d83f1c8ca282 599
bcostm 0:d83f1c8ca282 600 if (x2 >= x1) /* The x-values are increasing */
bcostm 0:d83f1c8ca282 601 {
bcostm 0:d83f1c8ca282 602 xinc1 = 1;
bcostm 0:d83f1c8ca282 603 xinc2 = 1;
bcostm 0:d83f1c8ca282 604 }
bcostm 0:d83f1c8ca282 605 else /* The x-values are decreasing */
bcostm 0:d83f1c8ca282 606 {
bcostm 0:d83f1c8ca282 607 xinc1 = -1;
bcostm 0:d83f1c8ca282 608 xinc2 = -1;
bcostm 0:d83f1c8ca282 609 }
bcostm 0:d83f1c8ca282 610
bcostm 0:d83f1c8ca282 611 if (y2 >= y1) /* The y-values are increasing */
bcostm 0:d83f1c8ca282 612 {
bcostm 0:d83f1c8ca282 613 yinc1 = 1;
bcostm 0:d83f1c8ca282 614 yinc2 = 1;
bcostm 0:d83f1c8ca282 615 }
bcostm 0:d83f1c8ca282 616 else /* The y-values are decreasing */
bcostm 0:d83f1c8ca282 617 {
bcostm 0:d83f1c8ca282 618 yinc1 = -1;
bcostm 0:d83f1c8ca282 619 yinc2 = -1;
bcostm 0:d83f1c8ca282 620 }
bcostm 0:d83f1c8ca282 621
bcostm 0:d83f1c8ca282 622 if (deltax >= deltay) /* There is at least one x-value for every y-value */
bcostm 0:d83f1c8ca282 623 {
bcostm 0:d83f1c8ca282 624 xinc1 = 0; /* Don't change the x when numerator >= denominator */
bcostm 0:d83f1c8ca282 625 yinc2 = 0; /* Don't change the y for every iteration */
bcostm 0:d83f1c8ca282 626 den = deltax;
bcostm 0:d83f1c8ca282 627 num = deltax / 2;
bcostm 0:d83f1c8ca282 628 numadd = deltay;
bcostm 0:d83f1c8ca282 629 numpixels = deltax; /* There are more x-values than y-values */
bcostm 0:d83f1c8ca282 630 }
bcostm 0:d83f1c8ca282 631 else /* There is at least one y-value for every x-value */
bcostm 0:d83f1c8ca282 632 {
bcostm 0:d83f1c8ca282 633 xinc2 = 0; /* Don't change the x for every iteration */
bcostm 0:d83f1c8ca282 634 yinc1 = 0; /* Don't change the y when numerator >= denominator */
bcostm 0:d83f1c8ca282 635 den = deltay;
bcostm 0:d83f1c8ca282 636 num = deltay / 2;
bcostm 0:d83f1c8ca282 637 numadd = deltax;
bcostm 0:d83f1c8ca282 638 numpixels = deltay; /* There are more y-values than x-values */
bcostm 0:d83f1c8ca282 639 }
bcostm 0:d83f1c8ca282 640
bcostm 0:d83f1c8ca282 641 for (curpixel = 0; curpixel <= numpixels; curpixel++)
bcostm 0:d83f1c8ca282 642 {
bcostm 0:d83f1c8ca282 643 BSP_LCD_DrawPixel(x, y, DrawProp.TextColor); /* Draw the current pixel */
bcostm 0:d83f1c8ca282 644 num += numadd; /* Increase the numerator by the top of the fraction */
bcostm 0:d83f1c8ca282 645 if (num >= den) /* Check if numerator >= denominator */
bcostm 0:d83f1c8ca282 646 {
bcostm 0:d83f1c8ca282 647 num -= den; /* Calculate the new numerator value */
bcostm 0:d83f1c8ca282 648 x += xinc1; /* Change the x as appropriate */
bcostm 0:d83f1c8ca282 649 y += yinc1; /* Change the y as appropriate */
bcostm 0:d83f1c8ca282 650 }
bcostm 0:d83f1c8ca282 651 x += xinc2; /* Change the x as appropriate */
bcostm 0:d83f1c8ca282 652 y += yinc2; /* Change the y as appropriate */
bcostm 0:d83f1c8ca282 653 }
bcostm 0:d83f1c8ca282 654 }
bcostm 0:d83f1c8ca282 655
bcostm 0:d83f1c8ca282 656 /**
bcostm 0:d83f1c8ca282 657 * @brief Draws a rectangle.
bcostm 0:d83f1c8ca282 658 * @param Xpos: X position
bcostm 0:d83f1c8ca282 659 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 660 * @param Width: Rectangle width
bcostm 0:d83f1c8ca282 661 * @param Height: Rectangle height
bcostm 0:d83f1c8ca282 662 * @retval None
bcostm 0:d83f1c8ca282 663 */
bcostm 0:d83f1c8ca282 664 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
bcostm 0:d83f1c8ca282 665 {
bcostm 0:d83f1c8ca282 666 /* Draw horizontal lines */
bcostm 0:d83f1c8ca282 667 BSP_LCD_DrawHLine(Xpos, Ypos, Width);
bcostm 0:d83f1c8ca282 668 BSP_LCD_DrawHLine(Xpos, (Ypos + Height), Width);
bcostm 0:d83f1c8ca282 669
bcostm 0:d83f1c8ca282 670 /* Draw vertical lines */
bcostm 0:d83f1c8ca282 671 BSP_LCD_DrawVLine(Xpos, Ypos, Height);
bcostm 0:d83f1c8ca282 672 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
bcostm 0:d83f1c8ca282 673 }
bcostm 0:d83f1c8ca282 674
bcostm 0:d83f1c8ca282 675 /**
bcostm 0:d83f1c8ca282 676 * @brief Draws a circle.
bcostm 0:d83f1c8ca282 677 * @param Xpos: X position
bcostm 0:d83f1c8ca282 678 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 679 * @param Radius: Circle radius
bcostm 0:d83f1c8ca282 680 * @retval None
bcostm 0:d83f1c8ca282 681 */
bcostm 0:d83f1c8ca282 682 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
bcostm 0:d83f1c8ca282 683 {
bcostm 0:d83f1c8ca282 684 int32_t decision; /* Decision Variable */
bcostm 0:d83f1c8ca282 685 uint32_t current_x; /* Current X Value */
bcostm 0:d83f1c8ca282 686 uint32_t current_y; /* Current Y Value */
bcostm 0:d83f1c8ca282 687
bcostm 0:d83f1c8ca282 688 decision = 3 - (Radius << 1);
bcostm 0:d83f1c8ca282 689 current_x = 0;
bcostm 0:d83f1c8ca282 690 current_y = Radius;
bcostm 0:d83f1c8ca282 691
bcostm 0:d83f1c8ca282 692 while (current_x <= current_y)
bcostm 0:d83f1c8ca282 693 {
bcostm 0:d83f1c8ca282 694 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos - current_y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 695
bcostm 0:d83f1c8ca282 696 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos - current_y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 697
bcostm 0:d83f1c8ca282 698 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos - current_x), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 699
bcostm 0:d83f1c8ca282 700 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos - current_x), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 701
bcostm 0:d83f1c8ca282 702 BSP_LCD_DrawPixel((Xpos + current_x), (Ypos + current_y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 703
bcostm 0:d83f1c8ca282 704 BSP_LCD_DrawPixel((Xpos - current_x), (Ypos + current_y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 705
bcostm 0:d83f1c8ca282 706 BSP_LCD_DrawPixel((Xpos + current_y), (Ypos + current_x), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 707
bcostm 0:d83f1c8ca282 708 BSP_LCD_DrawPixel((Xpos - current_y), (Ypos + current_x), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 709
bcostm 0:d83f1c8ca282 710 /* Initialize the font */
bcostm 0:d83f1c8ca282 711 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
bcostm 0:d83f1c8ca282 712
bcostm 0:d83f1c8ca282 713 if (decision < 0)
bcostm 0:d83f1c8ca282 714 {
bcostm 0:d83f1c8ca282 715 decision += (current_x << 2) + 6;
bcostm 0:d83f1c8ca282 716 }
bcostm 0:d83f1c8ca282 717 else
bcostm 0:d83f1c8ca282 718 {
bcostm 0:d83f1c8ca282 719 decision += ((current_x - current_y) << 2) + 10;
bcostm 0:d83f1c8ca282 720 current_y--;
bcostm 0:d83f1c8ca282 721 }
bcostm 0:d83f1c8ca282 722 current_x++;
bcostm 0:d83f1c8ca282 723 }
bcostm 0:d83f1c8ca282 724 }
bcostm 0:d83f1c8ca282 725
bcostm 0:d83f1c8ca282 726 /**
bcostm 0:d83f1c8ca282 727 * @brief Draws an poly-line (between many points).
bcostm 0:d83f1c8ca282 728 * @param Points: Pointer to the points array
bcostm 0:d83f1c8ca282 729 * @param PointCount: Number of points
bcostm 0:d83f1c8ca282 730 * @retval None
bcostm 0:d83f1c8ca282 731 */
bcostm 0:d83f1c8ca282 732 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
bcostm 0:d83f1c8ca282 733 {
bcostm 0:d83f1c8ca282 734 int16_t x = 0, y = 0;
bcostm 0:d83f1c8ca282 735
bcostm 0:d83f1c8ca282 736 if (PointCount < 2)
bcostm 0:d83f1c8ca282 737 {
bcostm 0:d83f1c8ca282 738 return;
bcostm 0:d83f1c8ca282 739 }
bcostm 0:d83f1c8ca282 740
bcostm 0:d83f1c8ca282 741 BSP_LCD_DrawLine(Points->X, Points->Y, (Points + PointCount - 1)->X, (Points + PointCount - 1)->Y);
bcostm 0:d83f1c8ca282 742
bcostm 0:d83f1c8ca282 743 while (--PointCount)
bcostm 0:d83f1c8ca282 744 {
bcostm 0:d83f1c8ca282 745 x = Points->X;
bcostm 0:d83f1c8ca282 746 y = Points->Y;
bcostm 0:d83f1c8ca282 747 Points++;
bcostm 0:d83f1c8ca282 748 BSP_LCD_DrawLine(x, y, Points->X, Points->Y);
bcostm 0:d83f1c8ca282 749 }
bcostm 0:d83f1c8ca282 750 }
bcostm 0:d83f1c8ca282 751
bcostm 0:d83f1c8ca282 752 /**
bcostm 0:d83f1c8ca282 753 * @brief Draws an ellipse on LCD.
bcostm 0:d83f1c8ca282 754 * @param Xpos: X position
bcostm 0:d83f1c8ca282 755 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 756 * @param XRadius: Ellipse X radius
bcostm 0:d83f1c8ca282 757 * @param YRadius: Ellipse Y radius
bcostm 0:d83f1c8ca282 758 * @retval None
bcostm 0:d83f1c8ca282 759 */
bcostm 0:d83f1c8ca282 760 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
bcostm 0:d83f1c8ca282 761 {
bcostm 0:d83f1c8ca282 762 int x = 0, y = -YRadius, err = 2 - 2 * XRadius, e2;
bcostm 0:d83f1c8ca282 763 float k = 0, rad1 = 0, rad2 = 0;
bcostm 0:d83f1c8ca282 764
bcostm 0:d83f1c8ca282 765 rad1 = XRadius;
bcostm 0:d83f1c8ca282 766 rad2 = YRadius;
bcostm 0:d83f1c8ca282 767
bcostm 0:d83f1c8ca282 768 k = (float)(rad2 / rad1);
bcostm 0:d83f1c8ca282 769
bcostm 0:d83f1c8ca282 770 do
bcostm 0:d83f1c8ca282 771 {
bcostm 0:d83f1c8ca282 772 BSP_LCD_DrawPixel((Xpos - (uint16_t)(x / k)), (Ypos + y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 773 BSP_LCD_DrawPixel((Xpos + (uint16_t)(x / k)), (Ypos + y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 774 BSP_LCD_DrawPixel((Xpos + (uint16_t)(x / k)), (Ypos - y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 775 BSP_LCD_DrawPixel((Xpos - (uint16_t)(x / k)), (Ypos - y), DrawProp.TextColor);
bcostm 0:d83f1c8ca282 776
bcostm 0:d83f1c8ca282 777 e2 = err;
bcostm 0:d83f1c8ca282 778 if (e2 <= x)
bcostm 0:d83f1c8ca282 779 {
bcostm 0:d83f1c8ca282 780 err += ++x * 2 + 1;
bcostm 0:d83f1c8ca282 781 if (-y == x && e2 <= y)
bcostm 0:d83f1c8ca282 782 {
bcostm 0:d83f1c8ca282 783 e2 = 0;
bcostm 0:d83f1c8ca282 784 }
bcostm 0:d83f1c8ca282 785 }
bcostm 0:d83f1c8ca282 786 if (e2 > y)
bcostm 0:d83f1c8ca282 787 {
bcostm 0:d83f1c8ca282 788 err += ++y * 2 + 1;
bcostm 0:d83f1c8ca282 789 }
bcostm 0:d83f1c8ca282 790 }
bcostm 0:d83f1c8ca282 791 while (y <= 0);
bcostm 0:d83f1c8ca282 792 }
bcostm 0:d83f1c8ca282 793
bcostm 0:d83f1c8ca282 794 /**
bcostm 0:d83f1c8ca282 795 * @brief Draws a bitmap picture (16 bpp).
bcostm 0:d83f1c8ca282 796 * @param Xpos: Bmp X position in the LCD
bcostm 0:d83f1c8ca282 797 * @param Ypos: Bmp Y position in the LCD
bcostm 0:d83f1c8ca282 798 * @param pbmp: Pointer to Bmp picture address.
bcostm 0:d83f1c8ca282 799 * @retval None
bcostm 0:d83f1c8ca282 800 */
bcostm 0:d83f1c8ca282 801 void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
bcostm 0:d83f1c8ca282 802 {
bcostm 0:d83f1c8ca282 803 uint32_t height = 0;
bcostm 0:d83f1c8ca282 804 uint32_t width = 0;
bcostm 0:d83f1c8ca282 805
bcostm 0:d83f1c8ca282 806
bcostm 0:d83f1c8ca282 807 /* Read bitmap width */
bcostm 0:d83f1c8ca282 808 width = *(uint16_t *)(pbmp + 18);
bcostm 0:d83f1c8ca282 809 width |= (*(uint16_t *)(pbmp + 20)) << 16;
bcostm 0:d83f1c8ca282 810
bcostm 0:d83f1c8ca282 811 /* Read bitmap height */
bcostm 0:d83f1c8ca282 812 height = *(uint16_t *)(pbmp + 22);
bcostm 0:d83f1c8ca282 813 height |= (*(uint16_t *)(pbmp + 24)) << 16;
bcostm 0:d83f1c8ca282 814
bcostm 0:d83f1c8ca282 815 SetDisplayWindow(Xpos, Ypos, width, height);
bcostm 0:d83f1c8ca282 816
bcostm 0:d83f1c8ca282 817 if (LcdDrv->DrawBitmap != NULL)
bcostm 0:d83f1c8ca282 818 {
bcostm 0:d83f1c8ca282 819 LcdDrv->DrawBitmap(Xpos, Ypos, pbmp);
bcostm 0:d83f1c8ca282 820 }
bcostm 0:d83f1c8ca282 821 SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
bcostm 0:d83f1c8ca282 822 }
bcostm 0:d83f1c8ca282 823
bcostm 0:d83f1c8ca282 824 /**
bcostm 0:d83f1c8ca282 825 * @brief Draws RGB Image (16 bpp).
bcostm 0:d83f1c8ca282 826 * @param Xpos: X position in the LCD
bcostm 0:d83f1c8ca282 827 * @param Ypos: Y position in the LCD
bcostm 0:d83f1c8ca282 828 * @param Xsize: X size in the LCD
bcostm 0:d83f1c8ca282 829 * @param Ysize: Y size in the LCD
bcostm 0:d83f1c8ca282 830 * @param pdata: Pointer to the RGB Image address.
bcostm 0:d83f1c8ca282 831 * @retval None
bcostm 0:d83f1c8ca282 832 */
bcostm 0:d83f1c8ca282 833 void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
bcostm 0:d83f1c8ca282 834 {
bcostm 0:d83f1c8ca282 835
bcostm 0:d83f1c8ca282 836 SetDisplayWindow(Xpos, Ypos, Xsize, Ysize);
bcostm 0:d83f1c8ca282 837
bcostm 0:d83f1c8ca282 838 if (LcdDrv->DrawRGBImage != NULL)
bcostm 0:d83f1c8ca282 839 {
bcostm 0:d83f1c8ca282 840 LcdDrv->DrawRGBImage(Xpos, Ypos, Xsize, Ysize, pdata);
bcostm 0:d83f1c8ca282 841 }
bcostm 0:d83f1c8ca282 842 SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
bcostm 0:d83f1c8ca282 843 }
bcostm 0:d83f1c8ca282 844
bcostm 0:d83f1c8ca282 845 /**
bcostm 0:d83f1c8ca282 846 * @brief Draws a full rectangle.
bcostm 0:d83f1c8ca282 847 * @param Xpos: X position
bcostm 0:d83f1c8ca282 848 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 849 * @param Width: Rectangle width
bcostm 0:d83f1c8ca282 850 * @param Height: Rectangle height
bcostm 0:d83f1c8ca282 851 * @retval None
bcostm 0:d83f1c8ca282 852 */
bcostm 0:d83f1c8ca282 853 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
bcostm 0:d83f1c8ca282 854 {
bcostm 0:d83f1c8ca282 855 BSP_LCD_SetTextColor(DrawProp.TextColor);
bcostm 0:d83f1c8ca282 856 do
bcostm 0:d83f1c8ca282 857 {
bcostm 0:d83f1c8ca282 858 BSP_LCD_DrawHLine(Xpos, Ypos++, Width);
bcostm 0:d83f1c8ca282 859 }
bcostm 0:d83f1c8ca282 860 while (Height--);
bcostm 0:d83f1c8ca282 861 }
bcostm 0:d83f1c8ca282 862
bcostm 0:d83f1c8ca282 863 /**
bcostm 0:d83f1c8ca282 864 * @brief Draws a full circle.
bcostm 0:d83f1c8ca282 865 * @param Xpos: X position
bcostm 0:d83f1c8ca282 866 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 867 * @param Radius: Circle radius
bcostm 0:d83f1c8ca282 868 * @retval None
bcostm 0:d83f1c8ca282 869 */
bcostm 0:d83f1c8ca282 870 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
bcostm 0:d83f1c8ca282 871 {
bcostm 0:d83f1c8ca282 872 int32_t decision; /* Decision Variable */
bcostm 0:d83f1c8ca282 873 uint32_t current_x; /* Current X Value */
bcostm 0:d83f1c8ca282 874 uint32_t current_y; /* Current Y Value */
bcostm 0:d83f1c8ca282 875
bcostm 0:d83f1c8ca282 876 decision = 3 - (Radius << 1);
bcostm 0:d83f1c8ca282 877
bcostm 0:d83f1c8ca282 878 current_x = 0;
bcostm 0:d83f1c8ca282 879 current_y = Radius;
bcostm 0:d83f1c8ca282 880
bcostm 0:d83f1c8ca282 881 BSP_LCD_SetTextColor(DrawProp.TextColor);
bcostm 0:d83f1c8ca282 882
bcostm 0:d83f1c8ca282 883 while (current_x <= current_y)
bcostm 0:d83f1c8ca282 884 {
bcostm 0:d83f1c8ca282 885 if (current_y > 0)
bcostm 0:d83f1c8ca282 886 {
bcostm 0:d83f1c8ca282 887 BSP_LCD_DrawHLine(Xpos - current_y, Ypos + current_x, 2 * current_y);
bcostm 0:d83f1c8ca282 888 BSP_LCD_DrawHLine(Xpos - current_y, Ypos - current_x, 2 * current_y);
bcostm 0:d83f1c8ca282 889 }
bcostm 0:d83f1c8ca282 890
bcostm 0:d83f1c8ca282 891 if (current_x > 0)
bcostm 0:d83f1c8ca282 892 {
bcostm 0:d83f1c8ca282 893 BSP_LCD_DrawHLine(Xpos - current_x, Ypos - current_y, 2 * current_x);
bcostm 0:d83f1c8ca282 894 BSP_LCD_DrawHLine(Xpos - current_x, Ypos + current_y, 2 * current_x);
bcostm 0:d83f1c8ca282 895 }
bcostm 0:d83f1c8ca282 896 if (decision < 0)
bcostm 0:d83f1c8ca282 897 {
bcostm 0:d83f1c8ca282 898 decision += (current_x << 2) + 6;
bcostm 0:d83f1c8ca282 899 }
bcostm 0:d83f1c8ca282 900 else
bcostm 0:d83f1c8ca282 901 {
bcostm 0:d83f1c8ca282 902 decision += ((current_x - current_y) << 2) + 10;
bcostm 0:d83f1c8ca282 903 current_y--;
bcostm 0:d83f1c8ca282 904 }
bcostm 0:d83f1c8ca282 905 current_x++;
bcostm 0:d83f1c8ca282 906 }
bcostm 0:d83f1c8ca282 907
bcostm 0:d83f1c8ca282 908 BSP_LCD_SetTextColor(DrawProp.TextColor);
bcostm 0:d83f1c8ca282 909 BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
bcostm 0:d83f1c8ca282 910 }
bcostm 0:d83f1c8ca282 911
bcostm 0:d83f1c8ca282 912 /**
bcostm 0:d83f1c8ca282 913 * @brief Draws a full poly-line (between many points).
bcostm 0:d83f1c8ca282 914 * @param Points: Pointer to the points array
bcostm 0:d83f1c8ca282 915 * @param PointCount: Number of points
bcostm 0:d83f1c8ca282 916 * @retval None
bcostm 0:d83f1c8ca282 917 */
bcostm 0:d83f1c8ca282 918 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
bcostm 0:d83f1c8ca282 919 {
bcostm 0:d83f1c8ca282 920 int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0;
bcostm 0:d83f1c8ca282 921 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
bcostm 0:d83f1c8ca282 922
bcostm 0:d83f1c8ca282 923 IMAGE_LEFT = IMAGE_RIGHT = Points->X;
bcostm 0:d83f1c8ca282 924 IMAGE_TOP = IMAGE_BOTTOM = Points->Y;
bcostm 0:d83f1c8ca282 925
bcostm 0:d83f1c8ca282 926 for (counter = 1; counter < PointCount; counter++)
bcostm 0:d83f1c8ca282 927 {
bcostm 0:d83f1c8ca282 928 pixelX = POLY_X(counter);
bcostm 0:d83f1c8ca282 929 if (pixelX < IMAGE_LEFT)
bcostm 0:d83f1c8ca282 930 {
bcostm 0:d83f1c8ca282 931 IMAGE_LEFT = pixelX;
bcostm 0:d83f1c8ca282 932 }
bcostm 0:d83f1c8ca282 933 if (pixelX > IMAGE_RIGHT)
bcostm 0:d83f1c8ca282 934 {
bcostm 0:d83f1c8ca282 935 IMAGE_RIGHT = pixelX;
bcostm 0:d83f1c8ca282 936 }
bcostm 0:d83f1c8ca282 937
bcostm 0:d83f1c8ca282 938 pixelY = POLY_Y(counter);
bcostm 0:d83f1c8ca282 939 if (pixelY < IMAGE_TOP)
bcostm 0:d83f1c8ca282 940 {
bcostm 0:d83f1c8ca282 941 IMAGE_TOP = pixelY;
bcostm 0:d83f1c8ca282 942 }
bcostm 0:d83f1c8ca282 943 if (pixelY > IMAGE_BOTTOM)
bcostm 0:d83f1c8ca282 944 {
bcostm 0:d83f1c8ca282 945 IMAGE_BOTTOM = pixelY;
bcostm 0:d83f1c8ca282 946 }
bcostm 0:d83f1c8ca282 947 }
bcostm 0:d83f1c8ca282 948
bcostm 0:d83f1c8ca282 949 if (PointCount < 2)
bcostm 0:d83f1c8ca282 950 {
bcostm 0:d83f1c8ca282 951 return;
bcostm 0:d83f1c8ca282 952 }
bcostm 0:d83f1c8ca282 953
bcostm 0:d83f1c8ca282 954 X_center = (IMAGE_LEFT + IMAGE_RIGHT) / 2;
bcostm 0:d83f1c8ca282 955 Y_center = (IMAGE_BOTTOM + IMAGE_TOP) / 2;
bcostm 0:d83f1c8ca282 956
bcostm 0:d83f1c8ca282 957 X_first = Points->X;
bcostm 0:d83f1c8ca282 958 Y_first = Points->Y;
bcostm 0:d83f1c8ca282 959
bcostm 0:d83f1c8ca282 960 while (--PointCount)
bcostm 0:d83f1c8ca282 961 {
bcostm 0:d83f1c8ca282 962 X = Points->X;
bcostm 0:d83f1c8ca282 963 Y = Points->Y;
bcostm 0:d83f1c8ca282 964 Points++;
bcostm 0:d83f1c8ca282 965 X2 = Points->X;
bcostm 0:d83f1c8ca282 966 Y2 = Points->Y;
bcostm 0:d83f1c8ca282 967
bcostm 0:d83f1c8ca282 968 FillTriangle(X, X2, X_center, Y, Y2, Y_center);
bcostm 0:d83f1c8ca282 969 FillTriangle(X, X_center, X2, Y, Y_center, Y2);
bcostm 0:d83f1c8ca282 970 FillTriangle(X_center, X2, X, Y_center, Y2, Y);
bcostm 0:d83f1c8ca282 971 }
bcostm 0:d83f1c8ca282 972
bcostm 0:d83f1c8ca282 973 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
bcostm 0:d83f1c8ca282 974 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
bcostm 0:d83f1c8ca282 975 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
bcostm 0:d83f1c8ca282 976 }
bcostm 0:d83f1c8ca282 977
bcostm 0:d83f1c8ca282 978 /**
bcostm 0:d83f1c8ca282 979 * @brief Draws a full ellipse.
bcostm 0:d83f1c8ca282 980 * @param Xpos: X position
bcostm 0:d83f1c8ca282 981 * @param Ypos: Y position
bcostm 0:d83f1c8ca282 982 * @param XRadius: Ellipse X radius
bcostm 0:d83f1c8ca282 983 * @param YRadius: Ellipse Y radius
bcostm 0:d83f1c8ca282 984 * @retval None
bcostm 0:d83f1c8ca282 985 */
bcostm 0:d83f1c8ca282 986 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
bcostm 0:d83f1c8ca282 987 {
bcostm 0:d83f1c8ca282 988 int x = 0, y = -YRadius, err = 2 - 2 * XRadius, e2;
bcostm 0:d83f1c8ca282 989 float k = 0, rad1 = 0, rad2 = 0;
bcostm 0:d83f1c8ca282 990
bcostm 0:d83f1c8ca282 991 rad1 = XRadius;
bcostm 0:d83f1c8ca282 992 rad2 = YRadius;
bcostm 0:d83f1c8ca282 993
bcostm 0:d83f1c8ca282 994 k = (float)(rad2 / rad1);
bcostm 0:d83f1c8ca282 995
bcostm 0:d83f1c8ca282 996 do
bcostm 0:d83f1c8ca282 997 {
bcostm 0:d83f1c8ca282 998 BSP_LCD_DrawHLine((Xpos - (uint16_t)(x / k)), (Ypos + y), (2 * (uint16_t)(x / k) + 1));
bcostm 0:d83f1c8ca282 999 BSP_LCD_DrawHLine((Xpos - (uint16_t)(x / k)), (Ypos - y), (2 * (uint16_t)(x / k) + 1));
bcostm 0:d83f1c8ca282 1000
bcostm 0:d83f1c8ca282 1001 e2 = err;
bcostm 0:d83f1c8ca282 1002 if (e2 <= x)
bcostm 0:d83f1c8ca282 1003 {
bcostm 0:d83f1c8ca282 1004 err += ++x * 2 + 1;
bcostm 0:d83f1c8ca282 1005 if (-y == x && e2 <= y)
bcostm 0:d83f1c8ca282 1006 {
bcostm 0:d83f1c8ca282 1007 e2 = 0;
bcostm 0:d83f1c8ca282 1008 }
bcostm 0:d83f1c8ca282 1009 }
bcostm 0:d83f1c8ca282 1010 if (e2 > y)
bcostm 0:d83f1c8ca282 1011 {
bcostm 0:d83f1c8ca282 1012 err += ++y * 2 + 1;
bcostm 0:d83f1c8ca282 1013 }
bcostm 0:d83f1c8ca282 1014 }
bcostm 0:d83f1c8ca282 1015 while (y <= 0);
bcostm 0:d83f1c8ca282 1016 }
bcostm 0:d83f1c8ca282 1017
bcostm 0:d83f1c8ca282 1018 /**
bcostm 0:d83f1c8ca282 1019 * @brief Enables the display.
bcostm 0:d83f1c8ca282 1020 * @param None
bcostm 0:d83f1c8ca282 1021 * @retval None
bcostm 0:d83f1c8ca282 1022 */
bcostm 0:d83f1c8ca282 1023 void BSP_LCD_DisplayOn(void)
bcostm 0:d83f1c8ca282 1024 {
bcostm 0:d83f1c8ca282 1025 LcdDrv->DisplayOn();
bcostm 0:d83f1c8ca282 1026 }
bcostm 0:d83f1c8ca282 1027
bcostm 0:d83f1c8ca282 1028 /**
bcostm 0:d83f1c8ca282 1029 * @brief Disables the display.
bcostm 0:d83f1c8ca282 1030 * @param None
bcostm 0:d83f1c8ca282 1031 * @retval None
bcostm 0:d83f1c8ca282 1032 */
bcostm 0:d83f1c8ca282 1033 void BSP_LCD_DisplayOff(void)
bcostm 0:d83f1c8ca282 1034 {
bcostm 0:d83f1c8ca282 1035 LcdDrv->DisplayOff();
bcostm 0:d83f1c8ca282 1036 }
bcostm 0:d83f1c8ca282 1037
bcostm 0:d83f1c8ca282 1038
bcostm 0:d83f1c8ca282 1039 /**
bcostm 0:d83f1c8ca282 1040 * @brief LCD screen dimming enable
bcostm 0:d83f1c8ca282 1041 * @note Screen brightness is gradually decreased
bcostm 0:d83f1c8ca282 1042 * @param start : value in percent to start from
bcostm 0:d83f1c8ca282 1043 * @param stop : value in percent to stop to
bcostm 0:d83f1c8ca282 1044 * @param step : step value in percent
bcostm 0:d83f1c8ca282 1045 * @param delay : delay in milliseconds between each step
bcostm 0:d83f1c8ca282 1046 * @retval None
bcostm 0:d83f1c8ca282 1047 */
bcostm 0:d83f1c8ca282 1048 void BSP_LCD_ScreenDimmingConfig(const uint8_t start, const uint8_t stop, const uint8_t step, const uint8_t delay)
bcostm 0:d83f1c8ca282 1049 {
bcostm 0:d83f1c8ca282 1050 if ((dimming_config.ongoing == 0)
bcostm 0:d83f1c8ca282 1051 && (start <= 100) && (stop <= 100)
bcostm 0:d83f1c8ca282 1052 && (step > 0) && (step < 100))
bcostm 0:d83f1c8ca282 1053 {
bcostm 0:d83f1c8ca282 1054 dimming_config.start = start;
bcostm 0:d83f1c8ca282 1055 dimming_config.stop = stop;
bcostm 0:d83f1c8ca282 1056 dimming_config.step = step;
bcostm 0:d83f1c8ca282 1057 dimming_config.delay = delay;
bcostm 0:d83f1c8ca282 1058 }
bcostm 0:d83f1c8ca282 1059 }
bcostm 0:d83f1c8ca282 1060
bcostm 0:d83f1c8ca282 1061
bcostm 0:d83f1c8ca282 1062 /**
bcostm 0:d83f1c8ca282 1063 * @brief LCD screen dimming enable
bcostm 0:d83f1c8ca282 1064 * @note Screen brightness is gradually decreased
bcostm 0:d83f1c8ca282 1065 * @param None
bcostm 0:d83f1c8ca282 1066 * @retval None
bcostm 0:d83f1c8ca282 1067 */
bcostm 0:d83f1c8ca282 1068 void BSP_LCD_ScreenDimmingOn(void)
bcostm 0:d83f1c8ca282 1069 {
bcostm 0:d83f1c8ca282 1070 static uint32_t i = 0;
bcostm 0:d83f1c8ca282 1071
bcostm 0:d83f1c8ca282 1072 #if defined(LPTIMER_DIMMING)
bcostm 0:d83f1c8ca282 1073 /* Set that dim feature is active */
bcostm 0:d83f1c8ca282 1074 if (dimming_on == 0)
bcostm 0:d83f1c8ca282 1075 {
bcostm 0:d83f1c8ca282 1076 dimming_on = 1;
bcostm 0:d83f1c8ca282 1077 i = PULSE_DECREASE_START;
bcostm 0:d83f1c8ca282 1078 /* Always redo the full initialization as there is no apriori knowledge
bcostm 0:d83f1c8ca282 1079 of IO or timer settings at this point (may have been modified by application) */
bcostm 0:d83f1c8ca282 1080
bcostm 0:d83f1c8ca282 1081 __HAL_RCC_LSI_ENABLE();
bcostm 0:d83f1c8ca282 1082 /* Select LSI as LPTIM1 clock source */
bcostm 0:d83f1c8ca282 1083 __HAL_RCC_LPTIM1_CONFIG(RCC_LPTIM1CLKSOURCE_LSI);
bcostm 0:d83f1c8ca282 1084
bcostm 0:d83f1c8ca282 1085
bcostm 0:d83f1c8ca282 1086 LCD_LpTimHandle.Instance = LPTIM1;
bcostm 0:d83f1c8ca282 1087 __HAL_LPTIM_RESET_HANDLE_STATE(&LCD_LpTimHandle); /* to force MSP call */
bcostm 0:d83f1c8ca282 1088
bcostm 0:d83f1c8ca282 1089 LCD_LpTimHandle.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
bcostm 0:d83f1c8ca282 1090 LCD_LpTimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
bcostm 0:d83f1c8ca282 1091 LCD_LpTimHandle.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
bcostm 0:d83f1c8ca282 1092 LCD_LpTimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
bcostm 0:d83f1c8ca282 1093 LCD_LpTimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
bcostm 0:d83f1c8ca282 1094 LCD_LpTimHandle.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
bcostm 0:d83f1c8ca282 1095 LCD_LpTimHandle.Init.Input1Source = LPTIM_INPUT1SOURCE_COMP1;
bcostm 0:d83f1c8ca282 1096
bcostm 0:d83f1c8ca282 1097 /* Initialize LPTIM peripheral according to the passed parameters */
bcostm 0:d83f1c8ca282 1098 if (HAL_LPTIM_Init(&LCD_LpTimHandle) != HAL_OK)
bcostm 0:d83f1c8ca282 1099 {
bcostm 0:d83f1c8ca282 1100 /* Initialization Error */
bcostm 0:d83f1c8ca282 1101 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1102 }
bcostm 0:d83f1c8ca282 1103
bcostm 0:d83f1c8ca282 1104 if (HAL_LPTIM_PWM_Start(&LCD_LpTimHandle, PERIOD_VALUE, i) != HAL_OK)
bcostm 0:d83f1c8ca282 1105 {
bcostm 0:d83f1c8ca282 1106 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1107 }
bcostm 0:d83f1c8ca282 1108
bcostm 0:d83f1c8ca282 1109
bcostm 0:d83f1c8ca282 1110 }
bcostm 0:d83f1c8ca282 1111 else
bcostm 0:d83f1c8ca282 1112 {
bcostm 0:d83f1c8ca282 1113 i++;
bcostm 0:d83f1c8ca282 1114 }
bcostm 0:d83f1c8ca282 1115
bcostm 0:d83f1c8ca282 1116 /* Optional delay to slow down the dimming transition. */
bcostm 0:d83f1c8ca282 1117 HAL_Delay(PULSE_DECREASE_DELAY);
bcostm 0:d83f1c8ca282 1118 if (HAL_LPTIM_PWM_Start(&LCD_LpTimHandle, PERIOD_VALUE, i) != HAL_OK)
bcostm 0:d83f1c8ca282 1119 {
bcostm 0:d83f1c8ca282 1120 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1121 }
bcostm 0:d83f1c8ca282 1122 if (i == PULSE_VALUE)
bcostm 0:d83f1c8ca282 1123 {
bcostm 0:d83f1c8ca282 1124 dimming_enable = 0;
bcostm 0:d83f1c8ca282 1125 }
bcostm 0:d83f1c8ca282 1126
bcostm 0:d83f1c8ca282 1127
bcostm 0:d83f1c8ca282 1128 #else
bcostm 0:d83f1c8ca282 1129 /* Counter Prescaler value */
bcostm 0:d83f1c8ca282 1130 uint32_t uhPrescalerValue = 0;
bcostm 0:d83f1c8ca282 1131 int32_t step;
bcostm 0:d83f1c8ca282 1132
bcostm 0:d83f1c8ca282 1133 /* Reject this while ongoing dimming */
bcostm 0:d83f1c8ca282 1134 if (dimming_config.ongoing)
bcostm 0:d83f1c8ca282 1135 {
bcostm 0:d83f1c8ca282 1136 return;
bcostm 0:d83f1c8ca282 1137 }
bcostm 0:d83f1c8ca282 1138
bcostm 0:d83f1c8ca282 1139 /* Set that dim feature is active */
bcostm 0:d83f1c8ca282 1140 dimming_on = 1;
bcostm 0:d83f1c8ca282 1141 dimming_config.ongoing = 1;
bcostm 0:d83f1c8ca282 1142
bcostm 0:d83f1c8ca282 1143 if (dimming_config.stop > dimming_config.start)
bcostm 0:d83f1c8ca282 1144 {
bcostm 0:d83f1c8ca282 1145 step = dimming_config.step;
bcostm 0:d83f1c8ca282 1146 }
bcostm 0:d83f1c8ca282 1147 else
bcostm 0:d83f1c8ca282 1148 {
bcostm 0:d83f1c8ca282 1149 step = -dimming_config.step;
bcostm 0:d83f1c8ca282 1150 }
bcostm 0:d83f1c8ca282 1151
bcostm 0:d83f1c8ca282 1152 /* Always redo the full initialization as there is no apriori knowledge
bcostm 0:d83f1c8ca282 1153 of IO or timer settings at this point (may have been modified by application) */
bcostm 0:d83f1c8ca282 1154
bcostm 0:d83f1c8ca282 1155 /* Compute the prescaler value to have TIM1 counter clock equal to 16000000 Hz */
bcostm 0:d83f1c8ca282 1156 uhPrescalerValue = (uint32_t)(SystemCoreClock / 16000000) - 1;
bcostm 0:d83f1c8ca282 1157
bcostm 0:d83f1c8ca282 1158 LCD_TimHandle.Instance = TIMx;
bcostm 0:d83f1c8ca282 1159
bcostm 0:d83f1c8ca282 1160 __HAL_TIM_RESET_HANDLE_STATE(&LCD_TimHandle); /* to force MSP call */
bcostm 0:d83f1c8ca282 1161 LCD_TimHandle.Init.Prescaler = uhPrescalerValue;
bcostm 0:d83f1c8ca282 1162 LCD_TimHandle.Init.Period = PERIOD_VALUE;
bcostm 0:d83f1c8ca282 1163 LCD_TimHandle.Init.ClockDivision = 0;
bcostm 0:d83f1c8ca282 1164 LCD_TimHandle.Init.CounterMode = (step > 0 ? TIM_COUNTERMODE_DOWN : TIM_COUNTERMODE_UP);
bcostm 0:d83f1c8ca282 1165 LCD_TimHandle.Init.RepetitionCounter = 0;
bcostm 0:d83f1c8ca282 1166 if (HAL_TIM_PWM_Init(&LCD_TimHandle) != HAL_OK)
bcostm 0:d83f1c8ca282 1167 {
bcostm 0:d83f1c8ca282 1168 /* Initialization Error */
bcostm 0:d83f1c8ca282 1169 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1170 }
bcostm 0:d83f1c8ca282 1171
bcostm 0:d83f1c8ca282 1172 /* Common configuration for all channels */
bcostm 0:d83f1c8ca282 1173 LCD_sConfig.OCMode = TIM_OCMODE_PWM1;
bcostm 0:d83f1c8ca282 1174 LCD_sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
bcostm 0:d83f1c8ca282 1175 LCD_sConfig.OCFastMode = TIM_OCFAST_DISABLE;
bcostm 0:d83f1c8ca282 1176 LCD_sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
bcostm 0:d83f1c8ca282 1177 LCD_sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
bcostm 0:d83f1c8ca282 1178
bcostm 0:d83f1c8ca282 1179 LCD_sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
bcostm 0:d83f1c8ca282 1180
bcostm 0:d83f1c8ca282 1181 /* Set the pulse value for channel */
bcostm 0:d83f1c8ca282 1182 LCD_sConfig.Pulse = __DIMMING_CYCLE_VALUE(dimming_config.start);
bcostm 0:d83f1c8ca282 1183 if (HAL_TIM_PWM_ConfigChannel(&LCD_TimHandle, &LCD_sConfig, TIMx_CHANNEL) != HAL_OK)
bcostm 0:d83f1c8ca282 1184 {
bcostm 0:d83f1c8ca282 1185 /* Configuration Error */
bcostm 0:d83f1c8ca282 1186 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1187 }
bcostm 0:d83f1c8ca282 1188
bcostm 0:d83f1c8ca282 1189 /* Start Timer channel */
bcostm 0:d83f1c8ca282 1190 if (HAL_TIM_PWM_Start(&LCD_TimHandle, TIMx_CHANNEL) != HAL_OK)
bcostm 0:d83f1c8ca282 1191 {
bcostm 0:d83f1c8ca282 1192 /* PWM Generation Error */
bcostm 0:d83f1c8ca282 1193 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1194 }
bcostm 0:d83f1c8ca282 1195
bcostm 0:d83f1c8ca282 1196 /* Set the pulse value for the timer channel */
bcostm 0:d83f1c8ca282 1197 i = dimming_config.start;
bcostm 0:d83f1c8ca282 1198 while (dimming_config.ongoing)
bcostm 0:d83f1c8ca282 1199 {
bcostm 0:d83f1c8ca282 1200 __HAL_TIM_SET_COMPARE(&LCD_TimHandle, TIMx_CHANNEL, __DIMMING_CYCLE_VALUE(i));
bcostm 0:d83f1c8ca282 1201
bcostm 0:d83f1c8ca282 1202 /* Exit if stop is reached */
bcostm 0:d83f1c8ca282 1203 if (((step > 0) && (i >= dimming_config.stop))
bcostm 0:d83f1c8ca282 1204 || ((step < 0) && (i <= dimming_config.stop)))
bcostm 0:d83f1c8ca282 1205 {
bcostm 0:d83f1c8ca282 1206 dimming_config.ongoing = 0;
bcostm 0:d83f1c8ca282 1207 }
bcostm 0:d83f1c8ca282 1208 else
bcostm 0:d83f1c8ca282 1209 {
bcostm 0:d83f1c8ca282 1210 HAL_Delay(dimming_config.delay);
bcostm 0:d83f1c8ca282 1211 i += step;
bcostm 0:d83f1c8ca282 1212 }
bcostm 0:d83f1c8ca282 1213 }
bcostm 0:d83f1c8ca282 1214 #endif
bcostm 0:d83f1c8ca282 1215 }
bcostm 0:d83f1c8ca282 1216
bcostm 0:d83f1c8ca282 1217 /**
bcostm 0:d83f1c8ca282 1218 * @brief LCD screen dimming disable
bcostm 0:d83f1c8ca282 1219 * @note Screen brightness is immediatly set to its highest level
bcostm 0:d83f1c8ca282 1220 * @param None
bcostm 0:d83f1c8ca282 1221 * @retval None
bcostm 0:d83f1c8ca282 1222 */
bcostm 0:d83f1c8ca282 1223 void BSP_LCD_ScreenDimmingOff(void)
bcostm 0:d83f1c8ca282 1224 {
bcostm 0:d83f1c8ca282 1225 #if defined(LPTIMER_DIMMING)
bcostm 0:d83f1c8ca282 1226 GPIO_InitTypeDef GPIO_InitStructure;
bcostm 0:d83f1c8ca282 1227 #endif
bcostm 0:d83f1c8ca282 1228
bcostm 0:d83f1c8ca282 1229 if (dimming_on == 1)
bcostm 0:d83f1c8ca282 1230 {
bcostm 0:d83f1c8ca282 1231 /* Stop ongoing dimming */
bcostm 0:d83f1c8ca282 1232 dimming_config.ongoing = 0;
bcostm 0:d83f1c8ca282 1233
bcostm 0:d83f1c8ca282 1234 #if defined(LPTIMER_DIMMING)
bcostm 0:d83f1c8ca282 1235
bcostm 0:d83f1c8ca282 1236 /* Restore LCD BL GPIO setting */
bcostm 0:d83f1c8ca282 1237 GPIO_InitStructure.Pin = LCD_BL_CTRL_PIN;
bcostm 0:d83f1c8ca282 1238 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 0:d83f1c8ca282 1239 GPIO_InitStructure.Pull = GPIO_NOPULL;
bcostm 0:d83f1c8ca282 1240 GPIO_InitStructure.Alternate = 0;
bcostm 0:d83f1c8ca282 1241 GPIO_InitStructure.Speed = GPIO_SPEED_LOW;
bcostm 0:d83f1c8ca282 1242 HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &GPIO_InitStructure);
bcostm 0:d83f1c8ca282 1243
bcostm 0:d83f1c8ca282 1244 /* Stop LP Timer channel */
bcostm 0:d83f1c8ca282 1245 if (HAL_LPTIM_PWM_Stop(&LCD_LpTimHandle) != HAL_OK)
bcostm 0:d83f1c8ca282 1246 {
bcostm 0:d83f1c8ca282 1247 /* PWM Generation Error */
bcostm 0:d83f1c8ca282 1248 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1249 }
bcostm 0:d83f1c8ca282 1250
bcostm 0:d83f1c8ca282 1251 /* Disable timer clock for power consumption reasons */
bcostm 0:d83f1c8ca282 1252 __HAL_RCC_LPTIM1_CLK_DISABLE();
bcostm 0:d83f1c8ca282 1253 #else
bcostm 0:d83f1c8ca282 1254 /* Stop Timer channel */
bcostm 0:d83f1c8ca282 1255 if (HAL_TIM_PWM_Stop(&LCD_TimHandle, TIMx_CHANNEL) != HAL_OK)
bcostm 0:d83f1c8ca282 1256 {
bcostm 0:d83f1c8ca282 1257 /* PWM Generation Error */
bcostm 0:d83f1c8ca282 1258 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1259 }
bcostm 0:d83f1c8ca282 1260
bcostm 0:d83f1c8ca282 1261 /* Disable timer clock for power consumption reasons */
bcostm 0:d83f1c8ca282 1262 TIMx_CLK_DISABLE();
bcostm 0:d83f1c8ca282 1263 #endif
bcostm 0:d83f1c8ca282 1264
bcostm 0:d83f1c8ca282 1265 dimming_on = 0;
bcostm 0:d83f1c8ca282 1266 }
bcostm 0:d83f1c8ca282 1267 }
bcostm 0:d83f1c8ca282 1268
bcostm 0:d83f1c8ca282 1269
bcostm 0:d83f1c8ca282 1270
bcostm 0:d83f1c8ca282 1271 /**
bcostm 0:d83f1c8ca282 1272 * @brief TIM MSP Initialization
bcostm 0:d83f1c8ca282 1273 * This function configures the hardware resources used for screen dimming:
bcostm 0:d83f1c8ca282 1274 * - Peripheral's clock enable
bcostm 0:d83f1c8ca282 1275 * - Peripheral's GPIO Configuration
bcostm 0:d83f1c8ca282 1276 * @param htim: TIM handle pointer
bcostm 0:d83f1c8ca282 1277 * @retval None
bcostm 0:d83f1c8ca282 1278 */
bcostm 0:d83f1c8ca282 1279 void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
bcostm 0:d83f1c8ca282 1280 {
bcostm 0:d83f1c8ca282 1281 GPIO_InitTypeDef GPIO_InitStruct;
bcostm 0:d83f1c8ca282 1282
bcostm 0:d83f1c8ca282 1283 /* TIMx Peripheral clock enable */
bcostm 0:d83f1c8ca282 1284 TIMx_CLK_ENABLE();
bcostm 0:d83f1c8ca282 1285
bcostm 0:d83f1c8ca282 1286 /* Timer channel configuration */
bcostm 0:d83f1c8ca282 1287
bcostm 0:d83f1c8ca282 1288 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
bcostm 0:d83f1c8ca282 1289 GPIO_InitStruct.Pull = GPIO_PULLUP;
bcostm 0:d83f1c8ca282 1290 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 0:d83f1c8ca282 1291
bcostm 0:d83f1c8ca282 1292 GPIO_InitStruct.Alternate = TIMx_CHANNEl_AF;
bcostm 0:d83f1c8ca282 1293 GPIO_InitStruct.Pin = GPIO_PIN_0;
bcostm 0:d83f1c8ca282 1294 HAL_GPIO_Init(GPIOI, &GPIO_InitStruct);
bcostm 0:d83f1c8ca282 1295 }
bcostm 0:d83f1c8ca282 1296
bcostm 0:d83f1c8ca282 1297
bcostm 0:d83f1c8ca282 1298 #if defined(LPTIMER_DIMMING)
bcostm 0:d83f1c8ca282 1299 /**
bcostm 0:d83f1c8ca282 1300 * @brief LPTIM MSP Init
bcostm 0:d83f1c8ca282 1301 * @param hlptim : LPTIM handle
bcostm 0:d83f1c8ca282 1302 * @retval None
bcostm 0:d83f1c8ca282 1303 */
bcostm 0:d83f1c8ca282 1304 void HAL_LPTIM_MspInit(LPTIM_HandleTypeDef *hlptim)
bcostm 0:d83f1c8ca282 1305 {
bcostm 0:d83f1c8ca282 1306 GPIO_InitTypeDef GPIO_InitStruct;
bcostm 0:d83f1c8ca282 1307
bcostm 0:d83f1c8ca282 1308 /* ## - 1 - Enable LPTIM clock ############################################ */
bcostm 0:d83f1c8ca282 1309 __HAL_RCC_LPTIM1_CLK_ENABLE();
bcostm 0:d83f1c8ca282 1310
bcostm 0:d83f1c8ca282 1311 /* ## - 2 - Force & Release the LPTIM Periheral Clock Reset ############### */
bcostm 0:d83f1c8ca282 1312 /* Force the LPTIM Periheral Clock Reset */
bcostm 0:d83f1c8ca282 1313 __HAL_RCC_LPTIM1_FORCE_RESET();
bcostm 0:d83f1c8ca282 1314
bcostm 0:d83f1c8ca282 1315 /* Release the LPTIM Periheral Clock Reset */
bcostm 0:d83f1c8ca282 1316 __HAL_RCC_LPTIM1_RELEASE_RESET();
bcostm 0:d83f1c8ca282 1317
bcostm 0:d83f1c8ca282 1318 /* ## - 3 - Enable & Configure LPTIM Ultra Low Power Input ################# */
bcostm 0:d83f1c8ca282 1319 /* Configure PG.15 (LPTIM1_OUT) in alternate function,
bcostm 0:d83f1c8ca282 1320 Low speed push-pull mode and pull-up enabled. */
bcostm 0:d83f1c8ca282 1321
bcostm 0:d83f1c8ca282 1322 /* Enable GPIO PORT(s)*/
bcostm 0:d83f1c8ca282 1323 LCD_BL_CTRL_GPIO_CLK_ENABLE();
bcostm 0:d83f1c8ca282 1324
bcostm 0:d83f1c8ca282 1325 /* Configure Backlight control pin GPIO */
bcostm 0:d83f1c8ca282 1326 GPIO_InitStruct.Pin = LCD_BL_CTRL_PIN;
bcostm 0:d83f1c8ca282 1327 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
bcostm 0:d83f1c8ca282 1328 GPIO_InitStruct.Pull = GPIO_PULLUP;
bcostm 0:d83f1c8ca282 1329 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
bcostm 0:d83f1c8ca282 1330 GPIO_InitStruct.Alternate = GPIO_AF1_LPTIM1;
bcostm 0:d83f1c8ca282 1331 HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &GPIO_InitStruct);
bcostm 0:d83f1c8ca282 1332 }
bcostm 0:d83f1c8ca282 1333 #endif /* defined(LPTIMER_DIMMING) */
bcostm 0:d83f1c8ca282 1334
bcostm 0:d83f1c8ca282 1335 uint8_t BSP_LCD_GetOrientation(void)
bcostm 0:d83f1c8ca282 1336 {
bcostm 0:d83f1c8ca282 1337 return LCD_orientation;
bcostm 0:d83f1c8ca282 1338 }
bcostm 0:d83f1c8ca282 1339
bcostm 0:d83f1c8ca282 1340 /**
bcostm 0:d83f1c8ca282 1341 * @brief Initializes the LCD GPIO special pins MSP.
bcostm 0:d83f1c8ca282 1342 * @param None
bcostm 0:d83f1c8ca282 1343 * @retval None
bcostm 0:d83f1c8ca282 1344 */
bcostm 0:d83f1c8ca282 1345 __weak void BSP_LCD_MspInit(void)
bcostm 0:d83f1c8ca282 1346 {
bcostm 0:d83f1c8ca282 1347 GPIO_InitTypeDef GPIO_InitStructure;
bcostm 0:d83f1c8ca282 1348
bcostm 0:d83f1c8ca282 1349 /* Enable GPIOs clock */
bcostm 0:d83f1c8ca282 1350 LCD_TE_GPIO_CLK_ENABLE();
bcostm 0:d83f1c8ca282 1351 LCD_BL_CTRL_GPIO_CLK_ENABLE();
bcostm 0:d83f1c8ca282 1352 LCD_PWR_CTRL_GPIO_CLK_ENABLE();
bcostm 0:d83f1c8ca282 1353
bcostm 0:d83f1c8ca282 1354 /* LCD_RESET GPIO configuration */
bcostm 0:d83f1c8ca282 1355 if (BSP_IO_Init() == IO_ERROR)
bcostm 0:d83f1c8ca282 1356 {
bcostm 0:d83f1c8ca282 1357 BSP_ErrorHandler();
bcostm 0:d83f1c8ca282 1358 }
bcostm 0:d83f1c8ca282 1359 BSP_IO_ConfigPin(LCD_RST_PIN, IO_MODE_OUTPUT);
bcostm 0:d83f1c8ca282 1360
bcostm 0:d83f1c8ca282 1361 /* LCD_BL_CTRL GPIO configuration */
bcostm 0:d83f1c8ca282 1362 GPIO_InitStructure.Pin = LCD_BL_CTRL_PIN; /* LCD_BL_CTRL pin has to be manually controlled */
bcostm 0:d83f1c8ca282 1363 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
bcostm 0:d83f1c8ca282 1364 GPIO_InitStructure.Pull = GPIO_NOPULL;
bcostm 0:d83f1c8ca282 1365 GPIO_InitStructure.Alternate = 0;
bcostm 0:d83f1c8ca282 1366 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
bcostm 0:d83f1c8ca282 1367 HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &GPIO_InitStructure);
bcostm 0:d83f1c8ca282 1368
bcostm 0:d83f1c8ca282 1369 /* Power on the screen (also done in Touch Screen driver ... */
bcostm 0:d83f1c8ca282 1370 GPIO_InitStructure.Pin = LCD_PWR_CTRL_PIN;
bcostm 0:d83f1c8ca282 1371 GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP /*GPIO_MODE_OUTPUT_PP*/;
bcostm 0:d83f1c8ca282 1372 GPIO_InitStructure.Pull = GPIO_NOPULL;
bcostm 0:d83f1c8ca282 1373 GPIO_InitStructure.Alternate = 0;
bcostm 0:d83f1c8ca282 1374 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
bcostm 0:d83f1c8ca282 1375 HAL_GPIO_Init(LCD_PWR_CTRL_GPIO_PORT, &GPIO_InitStructure);
bcostm 0:d83f1c8ca282 1376 }
bcostm 0:d83f1c8ca282 1377
bcostm 0:d83f1c8ca282 1378 /**
bcostm 0:d83f1c8ca282 1379 * @brief DeInitializes LCD GPIO special pins MSP.
bcostm 0:d83f1c8ca282 1380 * @param None
bcostm 0:d83f1c8ca282 1381 * @retval None
bcostm 0:d83f1c8ca282 1382 */
bcostm 0:d83f1c8ca282 1383 __weak void BSP_LCD_MspDeInit(void)
bcostm 0:d83f1c8ca282 1384 {
bcostm 0:d83f1c8ca282 1385 GPIO_InitTypeDef GPIO_InitStructure;
bcostm 0:d83f1c8ca282 1386
bcostm 0:d83f1c8ca282 1387 /* LCD_BL_CTRL GPIO deactivation */
bcostm 0:d83f1c8ca282 1388 GPIO_InitStructure.Pin = LCD_BL_CTRL_PIN;
bcostm 0:d83f1c8ca282 1389 HAL_GPIO_DeInit(LCD_BL_CTRL_GPIO_PORT, GPIO_InitStructure.Pin);
bcostm 0:d83f1c8ca282 1390
bcostm 0:d83f1c8ca282 1391 /* LCD_BL_CTRL GPIO deactivation */
bcostm 0:d83f1c8ca282 1392 GPIO_InitStructure.Pin = LCD_PWR_CTRL_PIN;
bcostm 0:d83f1c8ca282 1393 HAL_GPIO_DeInit(LCD_PWR_CTRL_GPIO_PORT, GPIO_InitStructure.Pin);
bcostm 0:d83f1c8ca282 1394
bcostm 0:d83f1c8ca282 1395 /* GPIO pins clock can be shut down in the application
bcostm 0:d83f1c8ca282 1396 by surcharging this __weak function */
bcostm 0:d83f1c8ca282 1397 }
bcostm 0:d83f1c8ca282 1398
bcostm 0:d83f1c8ca282 1399 /******************************************************************************
bcostm 0:d83f1c8ca282 1400 Static Functions
bcostm 0:d83f1c8ca282 1401 *******************************************************************************/
bcostm 0:d83f1c8ca282 1402
bcostm 0:d83f1c8ca282 1403 /**
bcostm 0:d83f1c8ca282 1404 * @brief Draws a character on LCD.
bcostm 0:d83f1c8ca282 1405 * @param Xpos: Line where to display the character shape
bcostm 0:d83f1c8ca282 1406 * @param Ypos: Start column address
bcostm 0:d83f1c8ca282 1407 * @param c: Pointer to the character data
bcostm 0:d83f1c8ca282 1408 * @retval None
bcostm 0:d83f1c8ca282 1409 */
bcostm 0:d83f1c8ca282 1410 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
bcostm 0:d83f1c8ca282 1411 {
bcostm 0:d83f1c8ca282 1412 uint32_t i = 0, j = 0;
bcostm 0:d83f1c8ca282 1413 uint16_t height, width;
bcostm 0:d83f1c8ca282 1414 uint8_t offset;
bcostm 0:d83f1c8ca282 1415 uint8_t *pchar;
bcostm 0:d83f1c8ca282 1416 uint32_t line;
bcostm 0:d83f1c8ca282 1417
bcostm 0:d83f1c8ca282 1418 height = DrawProp.pFont->Height;
bcostm 0:d83f1c8ca282 1419 width = DrawProp.pFont->Width;
bcostm 0:d83f1c8ca282 1420
bcostm 0:d83f1c8ca282 1421 offset = 8 * ((width + 7) / 8) - width ;
bcostm 0:d83f1c8ca282 1422
bcostm 0:d83f1c8ca282 1423 for (i = 0; i < height; i++)
bcostm 0:d83f1c8ca282 1424 {
bcostm 0:d83f1c8ca282 1425 pchar = ((uint8_t *)c + (width + 7) / 8 * i);
bcostm 0:d83f1c8ca282 1426
bcostm 0:d83f1c8ca282 1427 switch (((width + 7) / 8))
bcostm 0:d83f1c8ca282 1428 {
bcostm 0:d83f1c8ca282 1429 case 1:
bcostm 0:d83f1c8ca282 1430 line = pchar[0];
bcostm 0:d83f1c8ca282 1431 break;
bcostm 0:d83f1c8ca282 1432
bcostm 0:d83f1c8ca282 1433 case 2:
bcostm 0:d83f1c8ca282 1434 line = (pchar[0] << 8) | pchar[1];
bcostm 0:d83f1c8ca282 1435 break;
bcostm 0:d83f1c8ca282 1436
bcostm 0:d83f1c8ca282 1437 case 3:
bcostm 0:d83f1c8ca282 1438 default:
bcostm 0:d83f1c8ca282 1439 line = (pchar[0] << 16) | (pchar[1] << 8) | pchar[2];
bcostm 0:d83f1c8ca282 1440 break;
bcostm 0:d83f1c8ca282 1441 }
bcostm 0:d83f1c8ca282 1442
bcostm 0:d83f1c8ca282 1443 for (j = 0; j < width; j++)
bcostm 0:d83f1c8ca282 1444 {
Jerome Coutant 2:106c7b82e064 1445 if ((line & (1 << (width - j + offset - 1))) != 0)
bcostm 0:d83f1c8ca282 1446 {
bcostm 0:d83f1c8ca282 1447 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.TextColor);
bcostm 0:d83f1c8ca282 1448 }
bcostm 0:d83f1c8ca282 1449 else
bcostm 0:d83f1c8ca282 1450 {
bcostm 0:d83f1c8ca282 1451 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.BackColor);
bcostm 0:d83f1c8ca282 1452 }
bcostm 0:d83f1c8ca282 1453 }
bcostm 0:d83f1c8ca282 1454 Ypos++;
bcostm 0:d83f1c8ca282 1455 }
bcostm 0:d83f1c8ca282 1456 }
bcostm 0:d83f1c8ca282 1457
bcostm 0:d83f1c8ca282 1458 /**
bcostm 0:d83f1c8ca282 1459 * @brief Sets display window.
bcostm 0:d83f1c8ca282 1460 * @param LayerIndex: layer index
bcostm 0:d83f1c8ca282 1461 * @param Xpos: LCD X position
bcostm 0:d83f1c8ca282 1462 * @param Ypos: LCD Y position
bcostm 0:d83f1c8ca282 1463 * @param Width: LCD window width
bcostm 0:d83f1c8ca282 1464 * @param Height: LCD window height
bcostm 0:d83f1c8ca282 1465 * @retval None
bcostm 0:d83f1c8ca282 1466 */
bcostm 0:d83f1c8ca282 1467 static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
bcostm 0:d83f1c8ca282 1468 {
bcostm 0:d83f1c8ca282 1469 if (LcdDrv->SetDisplayWindow != NULL)
bcostm 0:d83f1c8ca282 1470 {
bcostm 0:d83f1c8ca282 1471 LcdDrv->SetDisplayWindow(Xpos, Ypos, Width, Height);
bcostm 0:d83f1c8ca282 1472 }
bcostm 0:d83f1c8ca282 1473 }
bcostm 0:d83f1c8ca282 1474
bcostm 0:d83f1c8ca282 1475 /**
bcostm 0:d83f1c8ca282 1476 * @brief Fills a triangle (between 3 points).
bcostm 0:d83f1c8ca282 1477 * @param Points: Pointer to the points array
bcostm 0:d83f1c8ca282 1478 * @param x1: Point 1 X position
bcostm 0:d83f1c8ca282 1479 * @param y1: Point 1 Y position
bcostm 0:d83f1c8ca282 1480 * @param x2: Point 2 X position
bcostm 0:d83f1c8ca282 1481 * @param y2: Point 2 Y position
bcostm 0:d83f1c8ca282 1482 * @param x3: Point 3 X position
bcostm 0:d83f1c8ca282 1483 * @param y3: Point 3 Y position
bcostm 0:d83f1c8ca282 1484 * @retval None
bcostm 0:d83f1c8ca282 1485 */
bcostm 0:d83f1c8ca282 1486 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
bcostm 0:d83f1c8ca282 1487 {
bcostm 0:d83f1c8ca282 1488 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
bcostm 0:d83f1c8ca282 1489 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
bcostm 0:d83f1c8ca282 1490 curpixel = 0;
bcostm 0:d83f1c8ca282 1491
bcostm 0:d83f1c8ca282 1492 deltax = ABS(x2 - x1); /* The difference between the x's */
bcostm 0:d83f1c8ca282 1493 deltay = ABS(y2 - y1); /* The difference between the y's */
bcostm 0:d83f1c8ca282 1494 x = x1; /* Start x off at the first pixel */
bcostm 0:d83f1c8ca282 1495 y = y1; /* Start y off at the first pixel */
bcostm 0:d83f1c8ca282 1496
bcostm 0:d83f1c8ca282 1497 if (x2 >= x1) /* The x-values are increasing */
bcostm 0:d83f1c8ca282 1498 {
bcostm 0:d83f1c8ca282 1499 xinc1 = 1;
bcostm 0:d83f1c8ca282 1500 xinc2 = 1;
bcostm 0:d83f1c8ca282 1501 }
bcostm 0:d83f1c8ca282 1502 else /* The x-values are decreasing */
bcostm 0:d83f1c8ca282 1503 {
bcostm 0:d83f1c8ca282 1504 xinc1 = -1;
bcostm 0:d83f1c8ca282 1505 xinc2 = -1;
bcostm 0:d83f1c8ca282 1506 }
bcostm 0:d83f1c8ca282 1507
bcostm 0:d83f1c8ca282 1508 if (y2 >= y1) /* The y-values are increasing */
bcostm 0:d83f1c8ca282 1509 {
bcostm 0:d83f1c8ca282 1510 yinc1 = 1;
bcostm 0:d83f1c8ca282 1511 yinc2 = 1;
bcostm 0:d83f1c8ca282 1512 }
bcostm 0:d83f1c8ca282 1513 else /* The y-values are decreasing */
bcostm 0:d83f1c8ca282 1514 {
bcostm 0:d83f1c8ca282 1515 yinc1 = -1;
bcostm 0:d83f1c8ca282 1516 yinc2 = -1;
bcostm 0:d83f1c8ca282 1517 }
bcostm 0:d83f1c8ca282 1518
bcostm 0:d83f1c8ca282 1519 if (deltax >= deltay) /* There is at least one x-value for every y-value */
bcostm 0:d83f1c8ca282 1520 {
bcostm 0:d83f1c8ca282 1521 xinc1 = 0; /* Don't change the x when numerator >= denominator */
bcostm 0:d83f1c8ca282 1522 yinc2 = 0; /* Don't change the y for every iteration */
bcostm 0:d83f1c8ca282 1523 den = deltax;
bcostm 0:d83f1c8ca282 1524 num = deltax / 2;
bcostm 0:d83f1c8ca282 1525 numadd = deltay;
bcostm 0:d83f1c8ca282 1526 numpixels = deltax; /* There are more x-values than y-values */
bcostm 0:d83f1c8ca282 1527 }
bcostm 0:d83f1c8ca282 1528 else /* There is at least one y-value for every x-value */
bcostm 0:d83f1c8ca282 1529 {
bcostm 0:d83f1c8ca282 1530 xinc2 = 0; /* Don't change the x for every iteration */
bcostm 0:d83f1c8ca282 1531 yinc1 = 0; /* Don't change the y when numerator >= denominator */
bcostm 0:d83f1c8ca282 1532 den = deltay;
bcostm 0:d83f1c8ca282 1533 num = deltay / 2;
bcostm 0:d83f1c8ca282 1534 numadd = deltax;
bcostm 0:d83f1c8ca282 1535 numpixels = deltay; /* There are more y-values than x-values */
bcostm 0:d83f1c8ca282 1536 }
bcostm 0:d83f1c8ca282 1537
bcostm 0:d83f1c8ca282 1538 for (curpixel = 0; curpixel <= numpixels; curpixel++)
bcostm 0:d83f1c8ca282 1539 {
bcostm 0:d83f1c8ca282 1540 BSP_LCD_DrawLine(x, y, x3, y3);
bcostm 0:d83f1c8ca282 1541
bcostm 0:d83f1c8ca282 1542 num += numadd; /* Increase the numerator by the top of the fraction */
bcostm 0:d83f1c8ca282 1543 if (num >= den) /* Check if numerator >= denominator */
bcostm 0:d83f1c8ca282 1544 {
bcostm 0:d83f1c8ca282 1545 num -= den; /* Calculate the new numerator value */
bcostm 0:d83f1c8ca282 1546 x += xinc1; /* Change the x as appropriate */
bcostm 0:d83f1c8ca282 1547 y += yinc1; /* Change the y as appropriate */
bcostm 0:d83f1c8ca282 1548 }
bcostm 0:d83f1c8ca282 1549 x += xinc2; /* Change the x as appropriate */
bcostm 0:d83f1c8ca282 1550 y += yinc2; /* Change the y as appropriate */
bcostm 0:d83f1c8ca282 1551 }
bcostm 0:d83f1c8ca282 1552 }
bcostm 0:d83f1c8ca282 1553
bcostm 0:d83f1c8ca282 1554 /**
bcostm 0:d83f1c8ca282 1555 * @}
bcostm 0:d83f1c8ca282 1556 */
bcostm 0:d83f1c8ca282 1557
bcostm 0:d83f1c8ca282 1558 /**
bcostm 0:d83f1c8ca282 1559 * @}
bcostm 0:d83f1c8ca282 1560 */
bcostm 0:d83f1c8ca282 1561
bcostm 0:d83f1c8ca282 1562 /**
bcostm 0:d83f1c8ca282 1563 * @}
bcostm 0:d83f1c8ca282 1564 */
bcostm 0:d83f1c8ca282 1565
bcostm 0:d83f1c8ca282 1566 /**
bcostm 0:d83f1c8ca282 1567 * @}
bcostm 0:d83f1c8ca282 1568 */
bcostm 0:d83f1c8ca282 1569
bcostm 0:d83f1c8ca282 1570 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/