Patched for Audio example - Add status check when DFSDM's filter and channel de-init.
Dependents: DISCO_F413ZH-AUDIO-demo
The base repository is https://os.mbed.com/teams/ST/code/BSP_DISCO_F413ZH/. I've just added workaround patch for Audio-in demo on DISCO_F413ZH board(Microphone U16, U17)
Drivers/BSP/STM32F413H-Discovery/stm32f413h_discovery_lcd.c@4:c051317d4051, 2020-01-31 (annotated)
- Committer:
- Daniel_Lee
- Date:
- Fri Jan 31 07:17:05 2020 +0000
- Revision:
- 4:c051317d4051
- Parent:
- 3:42b354f5069c
Patched for Audio example;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
arostm | 0:4af3ca173992 | 1 | /** |
arostm | 0:4af3ca173992 | 2 | ****************************************************************************** |
arostm | 0:4af3ca173992 | 3 | * @file stm32f413h_discovery_lcd.c |
arostm | 0:4af3ca173992 | 4 | * @author MCD Application Team |
arostm | 0:4af3ca173992 | 5 | * @brief This file includes the driver for Liquid Crystal Display (LCD) module |
arostm | 0:4af3ca173992 | 6 | * mounted on STM32F413H-DISCOVERY board. |
arostm | 0:4af3ca173992 | 7 | ****************************************************************************** |
arostm | 0:4af3ca173992 | 8 | * @attention |
arostm | 0:4af3ca173992 | 9 | * |
arostm | 0:4af3ca173992 | 10 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
arostm | 0:4af3ca173992 | 11 | * |
arostm | 0:4af3ca173992 | 12 | * Redistribution and use in source and binary forms, with or without modification, |
arostm | 0:4af3ca173992 | 13 | * are permitted provided that the following conditions are met: |
arostm | 0:4af3ca173992 | 14 | * 1. Redistributions of source code must retain the above copyright notice, |
arostm | 0:4af3ca173992 | 15 | * this list of conditions and the following disclaimer. |
arostm | 0:4af3ca173992 | 16 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
arostm | 0:4af3ca173992 | 17 | * this list of conditions and the following disclaimer in the documentation |
arostm | 0:4af3ca173992 | 18 | * and/or other materials provided with the distribution. |
arostm | 0:4af3ca173992 | 19 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
arostm | 0:4af3ca173992 | 20 | * may be used to endorse or promote products derived from this software |
arostm | 0:4af3ca173992 | 21 | * without specific prior written permission. |
arostm | 0:4af3ca173992 | 22 | * |
arostm | 0:4af3ca173992 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
arostm | 0:4af3ca173992 | 24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
arostm | 0:4af3ca173992 | 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
arostm | 0:4af3ca173992 | 26 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
arostm | 0:4af3ca173992 | 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
arostm | 0:4af3ca173992 | 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
arostm | 0:4af3ca173992 | 29 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
arostm | 0:4af3ca173992 | 30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
arostm | 0:4af3ca173992 | 31 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
arostm | 0:4af3ca173992 | 32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
arostm | 0:4af3ca173992 | 33 | * |
arostm | 0:4af3ca173992 | 34 | ****************************************************************************** |
arostm | 0:4af3ca173992 | 35 | */ |
arostm | 0:4af3ca173992 | 36 | |
arostm | 0:4af3ca173992 | 37 | /* File Info : ----------------------------------------------------------------- |
arostm | 0:4af3ca173992 | 38 | User NOTES |
arostm | 0:4af3ca173992 | 39 | 1. How To use this driver: |
arostm | 0:4af3ca173992 | 40 | -------------------------- |
arostm | 0:4af3ca173992 | 41 | - This driver is used to drive indirectly an LCD TFT. |
arostm | 0:4af3ca173992 | 42 | - This driver supports the LS016B8UY LCD. |
arostm | 0:4af3ca173992 | 43 | - The LS016B8UY component driver MUST be included with this driver. |
arostm | 0:4af3ca173992 | 44 | |
arostm | 0:4af3ca173992 | 45 | 2. Driver description: |
arostm | 0:4af3ca173992 | 46 | --------------------- |
arostm | 0:4af3ca173992 | 47 | + Initialization steps: |
arostm | 0:4af3ca173992 | 48 | o Initialize the LCD using the BSP_LCD_Init() function. |
arostm | 0:4af3ca173992 | 49 | |
arostm | 0:4af3ca173992 | 50 | + Display on LCD |
arostm | 0:4af3ca173992 | 51 | o Clear the hole LCD using BSP_LCD_Clear() function or only one specified string |
arostm | 0:4af3ca173992 | 52 | line using the BSP_LCD_ClearStringLine() function. |
arostm | 0:4af3ca173992 | 53 | o Display a character on the specified line and column using the BSP_LCD_DisplayChar() |
arostm | 0:4af3ca173992 | 54 | function or a complete string line using the BSP_LCD_DisplayStringAtLine() function. |
arostm | 0:4af3ca173992 | 55 | o Display a string line on the specified position (x,y in pixel) and align mode |
arostm | 0:4af3ca173992 | 56 | using the BSP_LCD_DisplayStringAtLine() function. |
arostm | 0:4af3ca173992 | 57 | o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap) |
arostm | 0:4af3ca173992 | 58 | on LCD using the available set of functions. |
arostm | 0:4af3ca173992 | 59 | |
arostm | 0:4af3ca173992 | 60 | ------------------------------------------------------------------------------*/ |
arostm | 0:4af3ca173992 | 61 | |
arostm | 0:4af3ca173992 | 62 | /* Includes ------------------------------------------------------------------*/ |
arostm | 0:4af3ca173992 | 63 | #include "stm32f413h_discovery_lcd.h" |
arostm | 0:4af3ca173992 | 64 | #include "../../../Utilities/Fonts/fonts.h" |
arostm | 1:a3f6b8b5a6bf | 65 | //#include "../../../Utilities/Fonts/font24.c" //Patch for mbed |
arostm | 1:a3f6b8b5a6bf | 66 | //#include "../../../Utilities/Fonts/font20.c" //Patch for mbed |
arostm | 1:a3f6b8b5a6bf | 67 | //#include "../../../Utilities/Fonts/font16.c" //Patch for mbed |
arostm | 1:a3f6b8b5a6bf | 68 | //#include "../../../Utilities/Fonts/font12.c" //Patch for mbed |
arostm | 1:a3f6b8b5a6bf | 69 | //#include "../../../Utilities/Fonts/font8.c" //Patch for mbed |
arostm | 0:4af3ca173992 | 70 | |
arostm | 0:4af3ca173992 | 71 | /** @addtogroup BSP |
arostm | 0:4af3ca173992 | 72 | * @{ |
arostm | 0:4af3ca173992 | 73 | */ |
arostm | 0:4af3ca173992 | 74 | |
arostm | 0:4af3ca173992 | 75 | /** @addtogroup STM32F413H_DISCOVERY |
arostm | 0:4af3ca173992 | 76 | * @{ |
arostm | 0:4af3ca173992 | 77 | */ |
arostm | 0:4af3ca173992 | 78 | |
arostm | 0:4af3ca173992 | 79 | /** @defgroup STM32F413H_DISCOVERY_LCD STM32F413H_DISCOVERY LCD |
arostm | 0:4af3ca173992 | 80 | * @{ |
arostm | 0:4af3ca173992 | 81 | */ |
arostm | 0:4af3ca173992 | 82 | |
arostm | 0:4af3ca173992 | 83 | /** @defgroup STM32F413H_DISCOVERY_LCD_Private_Macros STM32F413H DISCOVERY LCD Private Macros |
arostm | 0:4af3ca173992 | 84 | * @{ |
arostm | 0:4af3ca173992 | 85 | */ |
arostm | 0:4af3ca173992 | 86 | #define POLY_X(Z) ((int32_t)((Points + Z)->X)) |
arostm | 0:4af3ca173992 | 87 | #define POLY_Y(Z) ((int32_t)((Points + Z)->Y)) |
arostm | 0:4af3ca173992 | 88 | #define ABS(X) ((X) > 0 ? (X) : -(X)) |
arostm | 0:4af3ca173992 | 89 | /** |
arostm | 0:4af3ca173992 | 90 | * @} |
arostm | 0:4af3ca173992 | 91 | */ |
arostm | 0:4af3ca173992 | 92 | |
arostm | 0:4af3ca173992 | 93 | /** @defgroup STM32F413H_DISCOVERY_LCD_Private_Variables STM32F413H DISCOVERY LCD Private Variables |
arostm | 0:4af3ca173992 | 94 | * @{ |
arostm | 0:4af3ca173992 | 95 | */ |
arostm | 0:4af3ca173992 | 96 | LCD_DrawPropTypeDef DrawProp; |
arostm | 0:4af3ca173992 | 97 | static LCD_DrvTypeDef *LcdDrv; |
arostm | 0:4af3ca173992 | 98 | /** |
arostm | 0:4af3ca173992 | 99 | * @} |
arostm | 0:4af3ca173992 | 100 | */ |
arostm | 0:4af3ca173992 | 101 | |
arostm | 0:4af3ca173992 | 102 | /** @defgroup STM32F413H_DISCOVERY_LCD_Private_FunctionPrototypes STM32F413H DISCOVERY LCD Private Functions Prototypes |
arostm | 0:4af3ca173992 | 103 | * @{ |
arostm | 0:4af3ca173992 | 104 | */ |
arostm | 0:4af3ca173992 | 105 | static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c); |
arostm | 0:4af3ca173992 | 106 | static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); |
arostm | 0:4af3ca173992 | 107 | static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3); |
arostm | 0:4af3ca173992 | 108 | /** |
arostm | 0:4af3ca173992 | 109 | * @} |
arostm | 0:4af3ca173992 | 110 | */ |
arostm | 0:4af3ca173992 | 111 | |
arostm | 0:4af3ca173992 | 112 | /** @defgroup STM32F413H_DISCOVERY_LCD_Private_Functions STM32F413H DISCOVERY LCD Private Functions |
arostm | 0:4af3ca173992 | 113 | * @{ |
arostm | 0:4af3ca173992 | 114 | */ |
arostm | 0:4af3ca173992 | 115 | /** |
arostm | 0:4af3ca173992 | 116 | * @brief Initializes the LCD. |
arostm | 0:4af3ca173992 | 117 | * @retval LCD state |
arostm | 0:4af3ca173992 | 118 | */ |
arostm | 0:4af3ca173992 | 119 | uint8_t BSP_LCD_Init(void) |
arostm | 0:4af3ca173992 | 120 | { |
arostm | 0:4af3ca173992 | 121 | return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE)); |
arostm | 0:4af3ca173992 | 122 | } |
arostm | 0:4af3ca173992 | 123 | /** |
arostm | 0:4af3ca173992 | 124 | * @brief Initializes the LCD with a given orientation. |
arostm | 0:4af3ca173992 | 125 | * @param orientation: LCD_ORIENTATION_PORTRAIT or LCD_ORIENTATION_LANDSCAPE |
arostm | 0:4af3ca173992 | 126 | * or LCD_ORIENTATION_LANDSCAPE_ROT180 |
arostm | 0:4af3ca173992 | 127 | * @retval LCD state |
arostm | 0:4af3ca173992 | 128 | */ |
arostm | 0:4af3ca173992 | 129 | uint8_t BSP_LCD_InitEx(uint32_t orientation) |
arostm | 0:4af3ca173992 | 130 | { |
arostm | 0:4af3ca173992 | 131 | uint8_t ret = LCD_ERROR; |
arostm | 0:4af3ca173992 | 132 | |
arostm | 0:4af3ca173992 | 133 | /* Default value for draw propriety */ |
arostm | 0:4af3ca173992 | 134 | DrawProp.BackColor = 0xFFFF; |
arostm | 0:4af3ca173992 | 135 | DrawProp.pFont = &Font24; |
arostm | 0:4af3ca173992 | 136 | DrawProp.TextColor = 0x0000; |
arostm | 0:4af3ca173992 | 137 | |
arostm | 0:4af3ca173992 | 138 | /* Initialize LCD special pins GPIOs */ |
arostm | 0:4af3ca173992 | 139 | BSP_LCD_MspInit(); |
arostm | 0:4af3ca173992 | 140 | |
arostm | 0:4af3ca173992 | 141 | /* Backlight control signal assertion */ |
arostm | 0:4af3ca173992 | 142 | HAL_GPIO_WritePin(LCD_BL_CTRL_GPIO_PORT, LCD_BL_CTRL_PIN, GPIO_PIN_SET); |
arostm | 0:4af3ca173992 | 143 | |
arostm | 0:4af3ca173992 | 144 | /* Apply hardware reset according to procedure indicated in FRD154BP2901 documentation */ |
arostm | 0:4af3ca173992 | 145 | HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_RESET); |
arostm | 0:4af3ca173992 | 146 | HAL_Delay(5); /* Reset signal asserted during 5ms */ |
arostm | 0:4af3ca173992 | 147 | HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_SET); |
arostm | 0:4af3ca173992 | 148 | HAL_Delay(10); /* Reset signal released during 10ms */ |
arostm | 0:4af3ca173992 | 149 | HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_RESET); |
arostm | 0:4af3ca173992 | 150 | HAL_Delay(20); /* Reset signal asserted during 20ms */ |
arostm | 0:4af3ca173992 | 151 | HAL_GPIO_WritePin(LCD_RESET_GPIO_PORT, LCD_RESET_PIN, GPIO_PIN_SET); |
arostm | 0:4af3ca173992 | 152 | HAL_Delay(10); /* Reset signal released during 10ms */ |
arostm | 0:4af3ca173992 | 153 | |
arostm | 0:4af3ca173992 | 154 | if(ST7789H2_drv.ReadID() == ST7789H2_ID) |
arostm | 0:4af3ca173992 | 155 | { |
arostm | 0:4af3ca173992 | 156 | LcdDrv = &ST7789H2_drv; |
arostm | 0:4af3ca173992 | 157 | |
arostm | 0:4af3ca173992 | 158 | /* LCD Init */ |
arostm | 0:4af3ca173992 | 159 | LcdDrv->Init(); |
arostm | 0:4af3ca173992 | 160 | |
arostm | 0:4af3ca173992 | 161 | if(orientation == LCD_ORIENTATION_PORTRAIT) |
arostm | 0:4af3ca173992 | 162 | { |
arostm | 0:4af3ca173992 | 163 | ST7789H2_SetOrientation(ST7789H2_ORIENTATION_PORTRAIT); |
arostm | 0:4af3ca173992 | 164 | } |
arostm | 0:4af3ca173992 | 165 | else if(orientation == LCD_ORIENTATION_LANDSCAPE_ROT180) |
arostm | 0:4af3ca173992 | 166 | { |
arostm | 0:4af3ca173992 | 167 | ST7789H2_SetOrientation(ST7789H2_ORIENTATION_LANDSCAPE_ROT180); |
arostm | 0:4af3ca173992 | 168 | } |
arostm | 0:4af3ca173992 | 169 | else |
arostm | 0:4af3ca173992 | 170 | { |
arostm | 0:4af3ca173992 | 171 | /* Default landscape orientation is selected */ |
arostm | 0:4af3ca173992 | 172 | } |
arostm | 0:4af3ca173992 | 173 | /* Initialize the font */ |
arostm | 0:4af3ca173992 | 174 | BSP_LCD_SetFont(&LCD_DEFAULT_FONT); |
arostm | 0:4af3ca173992 | 175 | |
arostm | 0:4af3ca173992 | 176 | ret = LCD_OK; |
arostm | 0:4af3ca173992 | 177 | } |
arostm | 0:4af3ca173992 | 178 | |
arostm | 0:4af3ca173992 | 179 | return ret; |
arostm | 0:4af3ca173992 | 180 | } |
arostm | 0:4af3ca173992 | 181 | |
arostm | 0:4af3ca173992 | 182 | /** |
arostm | 0:4af3ca173992 | 183 | * @brief DeInitializes the LCD. |
arostm | 0:4af3ca173992 | 184 | * @retval LCD state |
arostm | 0:4af3ca173992 | 185 | */ |
arostm | 0:4af3ca173992 | 186 | uint8_t BSP_LCD_DeInit(void) |
arostm | 0:4af3ca173992 | 187 | { |
arostm | 0:4af3ca173992 | 188 | /* Actually LcdDrv does not provide a DeInit function */ |
arostm | 0:4af3ca173992 | 189 | return LCD_OK; |
arostm | 0:4af3ca173992 | 190 | } |
arostm | 0:4af3ca173992 | 191 | |
arostm | 0:4af3ca173992 | 192 | /** |
arostm | 0:4af3ca173992 | 193 | * @brief Gets the LCD X size. |
arostm | 0:4af3ca173992 | 194 | * @retval Used LCD X size |
arostm | 0:4af3ca173992 | 195 | */ |
arostm | 0:4af3ca173992 | 196 | uint32_t BSP_LCD_GetXSize(void) |
arostm | 0:4af3ca173992 | 197 | { |
arostm | 0:4af3ca173992 | 198 | return(LcdDrv->GetLcdPixelWidth()); |
arostm | 0:4af3ca173992 | 199 | } |
arostm | 0:4af3ca173992 | 200 | |
arostm | 0:4af3ca173992 | 201 | /** |
arostm | 0:4af3ca173992 | 202 | * @brief Gets the LCD Y size. |
arostm | 0:4af3ca173992 | 203 | * @retval Used LCD Y size |
arostm | 0:4af3ca173992 | 204 | */ |
arostm | 0:4af3ca173992 | 205 | uint32_t BSP_LCD_GetYSize(void) |
arostm | 0:4af3ca173992 | 206 | { |
arostm | 0:4af3ca173992 | 207 | return(LcdDrv->GetLcdPixelHeight()); |
arostm | 0:4af3ca173992 | 208 | } |
arostm | 0:4af3ca173992 | 209 | |
arostm | 0:4af3ca173992 | 210 | /** |
arostm | 0:4af3ca173992 | 211 | * @brief Gets the LCD text color. |
arostm | 0:4af3ca173992 | 212 | * @retval Used text color. |
arostm | 0:4af3ca173992 | 213 | */ |
arostm | 0:4af3ca173992 | 214 | uint16_t BSP_LCD_GetTextColor(void) |
arostm | 0:4af3ca173992 | 215 | { |
arostm | 0:4af3ca173992 | 216 | return DrawProp.TextColor; |
arostm | 0:4af3ca173992 | 217 | } |
arostm | 0:4af3ca173992 | 218 | |
arostm | 0:4af3ca173992 | 219 | /** |
arostm | 0:4af3ca173992 | 220 | * @brief Gets the LCD background color. |
arostm | 0:4af3ca173992 | 221 | * @retval Used background color |
arostm | 0:4af3ca173992 | 222 | */ |
arostm | 0:4af3ca173992 | 223 | uint16_t BSP_LCD_GetBackColor(void) |
arostm | 0:4af3ca173992 | 224 | { |
arostm | 0:4af3ca173992 | 225 | return DrawProp.BackColor; |
arostm | 0:4af3ca173992 | 226 | } |
arostm | 0:4af3ca173992 | 227 | |
arostm | 0:4af3ca173992 | 228 | /** |
arostm | 0:4af3ca173992 | 229 | * @brief Sets the LCD text color. |
arostm | 0:4af3ca173992 | 230 | * @param Color: Text color code |
arostm | 0:4af3ca173992 | 231 | */ |
arostm | 0:4af3ca173992 | 232 | void BSP_LCD_SetTextColor(uint16_t Color) |
arostm | 0:4af3ca173992 | 233 | { |
arostm | 0:4af3ca173992 | 234 | DrawProp.TextColor = Color; |
arostm | 0:4af3ca173992 | 235 | } |
arostm | 0:4af3ca173992 | 236 | |
arostm | 0:4af3ca173992 | 237 | /** |
arostm | 0:4af3ca173992 | 238 | * @brief Sets the LCD background color. |
arostm | 0:4af3ca173992 | 239 | * @param Color: Background color code |
arostm | 0:4af3ca173992 | 240 | */ |
arostm | 0:4af3ca173992 | 241 | void BSP_LCD_SetBackColor(uint16_t Color) |
arostm | 0:4af3ca173992 | 242 | { |
arostm | 0:4af3ca173992 | 243 | DrawProp.BackColor = Color; |
arostm | 0:4af3ca173992 | 244 | } |
arostm | 0:4af3ca173992 | 245 | |
arostm | 0:4af3ca173992 | 246 | /** |
arostm | 0:4af3ca173992 | 247 | * @brief Sets the LCD text font. |
arostm | 0:4af3ca173992 | 248 | * @param fonts: Font to be used |
arostm | 0:4af3ca173992 | 249 | */ |
arostm | 0:4af3ca173992 | 250 | void BSP_LCD_SetFont(sFONT *fonts) |
arostm | 0:4af3ca173992 | 251 | { |
arostm | 0:4af3ca173992 | 252 | DrawProp.pFont = fonts; |
arostm | 0:4af3ca173992 | 253 | } |
arostm | 0:4af3ca173992 | 254 | |
arostm | 0:4af3ca173992 | 255 | /** |
arostm | 0:4af3ca173992 | 256 | * @brief Gets the LCD text font. |
arostm | 0:4af3ca173992 | 257 | * @retval Used font |
arostm | 0:4af3ca173992 | 258 | */ |
arostm | 0:4af3ca173992 | 259 | sFONT *BSP_LCD_GetFont(void) |
arostm | 0:4af3ca173992 | 260 | { |
arostm | 0:4af3ca173992 | 261 | return DrawProp.pFont; |
arostm | 0:4af3ca173992 | 262 | } |
arostm | 0:4af3ca173992 | 263 | |
arostm | 0:4af3ca173992 | 264 | /** |
arostm | 0:4af3ca173992 | 265 | * @brief Clears the hole LCD. |
arostm | 0:4af3ca173992 | 266 | * @param Color: Color of the background |
arostm | 0:4af3ca173992 | 267 | */ |
arostm | 0:4af3ca173992 | 268 | void BSP_LCD_Clear(uint16_t Color) |
arostm | 0:4af3ca173992 | 269 | { |
arostm | 0:4af3ca173992 | 270 | uint32_t counter = 0; |
arostm | 0:4af3ca173992 | 271 | uint32_t y_size = 0; |
arostm | 0:4af3ca173992 | 272 | uint32_t color_backup = DrawProp.TextColor; |
arostm | 0:4af3ca173992 | 273 | |
arostm | 0:4af3ca173992 | 274 | DrawProp.TextColor = Color; |
arostm | 0:4af3ca173992 | 275 | y_size = BSP_LCD_GetYSize(); |
arostm | 0:4af3ca173992 | 276 | |
arostm | 0:4af3ca173992 | 277 | for(counter = 0; counter < y_size; counter++) |
arostm | 0:4af3ca173992 | 278 | { |
arostm | 0:4af3ca173992 | 279 | BSP_LCD_DrawHLine(0, counter, BSP_LCD_GetXSize()); |
arostm | 0:4af3ca173992 | 280 | } |
arostm | 0:4af3ca173992 | 281 | DrawProp.TextColor = color_backup; |
arostm | 0:4af3ca173992 | 282 | BSP_LCD_SetTextColor(DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 283 | } |
arostm | 0:4af3ca173992 | 284 | |
arostm | 0:4af3ca173992 | 285 | /** |
arostm | 0:4af3ca173992 | 286 | * @brief Clears the selected line. |
arostm | 0:4af3ca173992 | 287 | * @param Line: Line to be cleared |
arostm | 0:4af3ca173992 | 288 | * This parameter can be one of the following values: |
arostm | 0:4af3ca173992 | 289 | * @arg 0..9: if the Current fonts is Font16x24 |
arostm | 0:4af3ca173992 | 290 | * @arg 0..19: if the Current fonts is Font12x12 or Font8x12 |
arostm | 0:4af3ca173992 | 291 | * @arg 0..29: if the Current fonts is Font8x8 |
arostm | 0:4af3ca173992 | 292 | */ |
arostm | 0:4af3ca173992 | 293 | void BSP_LCD_ClearStringLine(uint16_t Line) |
arostm | 0:4af3ca173992 | 294 | { |
arostm | 0:4af3ca173992 | 295 | uint32_t color_backup = DrawProp.TextColor; |
arostm | 0:4af3ca173992 | 296 | |
arostm | 0:4af3ca173992 | 297 | DrawProp.TextColor = DrawProp.BackColor;; |
arostm | 0:4af3ca173992 | 298 | |
arostm | 0:4af3ca173992 | 299 | /* Draw a rectangle with background color */ |
arostm | 0:4af3ca173992 | 300 | BSP_LCD_FillRect(0, (Line * DrawProp.pFont->Height), BSP_LCD_GetXSize(), DrawProp.pFont->Height); |
arostm | 0:4af3ca173992 | 301 | |
arostm | 0:4af3ca173992 | 302 | DrawProp.TextColor = color_backup; |
arostm | 0:4af3ca173992 | 303 | BSP_LCD_SetTextColor(DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 304 | } |
arostm | 0:4af3ca173992 | 305 | |
arostm | 0:4af3ca173992 | 306 | /** |
arostm | 0:4af3ca173992 | 307 | * @brief Displays one character. |
arostm | 0:4af3ca173992 | 308 | * @param Xpos: Start column address |
arostm | 0:4af3ca173992 | 309 | * @param Ypos: Line where to display the character shape. |
arostm | 0:4af3ca173992 | 310 | * @param Ascii: Character ascii code |
arostm | 0:4af3ca173992 | 311 | * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E |
arostm | 0:4af3ca173992 | 312 | */ |
arostm | 0:4af3ca173992 | 313 | void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii) |
arostm | 0:4af3ca173992 | 314 | { |
arostm | 0:4af3ca173992 | 315 | DrawChar(Xpos, Ypos, &DrawProp.pFont->table[(Ascii-' ') *\ |
arostm | 0:4af3ca173992 | 316 | DrawProp.pFont->Height * ((DrawProp.pFont->Width + 7) / 8)]); |
arostm | 0:4af3ca173992 | 317 | } |
arostm | 0:4af3ca173992 | 318 | |
arostm | 0:4af3ca173992 | 319 | /** |
arostm | 0:4af3ca173992 | 320 | * @brief Displays characters on the LCD. |
arostm | 0:4af3ca173992 | 321 | * @param Xpos: X position (in pixel) |
arostm | 0:4af3ca173992 | 322 | * @param Ypos: Y position (in pixel) |
arostm | 0:4af3ca173992 | 323 | * @param Text: Pointer to string to display on LCD |
arostm | 0:4af3ca173992 | 324 | * @param Mode: Display mode |
arostm | 0:4af3ca173992 | 325 | * This parameter can be one of the following values: |
arostm | 0:4af3ca173992 | 326 | * @arg CENTER_MODE |
arostm | 0:4af3ca173992 | 327 | * @arg RIGHT_MODE |
arostm | 0:4af3ca173992 | 328 | * @arg LEFT_MODE |
arostm | 0:4af3ca173992 | 329 | */ |
arostm | 0:4af3ca173992 | 330 | void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Line_ModeTypdef Mode) |
arostm | 0:4af3ca173992 | 331 | { |
arostm | 0:4af3ca173992 | 332 | uint16_t refcolumn = 1, i = 0; |
arostm | 0:4af3ca173992 | 333 | uint32_t size = 0, xsize = 0; |
arostm | 0:4af3ca173992 | 334 | uint8_t *ptr = Text; |
arostm | 0:4af3ca173992 | 335 | |
arostm | 0:4af3ca173992 | 336 | /* Get the text size */ |
arostm | 0:4af3ca173992 | 337 | while (*ptr++) size ++ ; |
arostm | 0:4af3ca173992 | 338 | |
arostm | 0:4af3ca173992 | 339 | /* Characters number per line */ |
arostm | 0:4af3ca173992 | 340 | xsize = (BSP_LCD_GetXSize()/DrawProp.pFont->Width); |
arostm | 0:4af3ca173992 | 341 | |
arostm | 0:4af3ca173992 | 342 | switch (Mode) |
arostm | 0:4af3ca173992 | 343 | { |
arostm | 0:4af3ca173992 | 344 | case CENTER_MODE: |
arostm | 0:4af3ca173992 | 345 | { |
arostm | 0:4af3ca173992 | 346 | refcolumn = Xpos + ((xsize - size)* DrawProp.pFont->Width) / 2; |
arostm | 0:4af3ca173992 | 347 | break; |
arostm | 0:4af3ca173992 | 348 | } |
arostm | 0:4af3ca173992 | 349 | case LEFT_MODE: |
arostm | 0:4af3ca173992 | 350 | { |
arostm | 0:4af3ca173992 | 351 | refcolumn = Xpos; |
arostm | 0:4af3ca173992 | 352 | break; |
arostm | 0:4af3ca173992 | 353 | } |
arostm | 0:4af3ca173992 | 354 | case RIGHT_MODE: |
arostm | 0:4af3ca173992 | 355 | { |
arostm | 0:4af3ca173992 | 356 | refcolumn = - Xpos + ((xsize - size)*DrawProp.pFont->Width); |
arostm | 0:4af3ca173992 | 357 | break; |
arostm | 0:4af3ca173992 | 358 | } |
arostm | 0:4af3ca173992 | 359 | default: |
arostm | 0:4af3ca173992 | 360 | { |
arostm | 0:4af3ca173992 | 361 | refcolumn = Xpos; |
arostm | 0:4af3ca173992 | 362 | break; |
arostm | 0:4af3ca173992 | 363 | } |
arostm | 0:4af3ca173992 | 364 | } |
arostm | 0:4af3ca173992 | 365 | |
arostm | 0:4af3ca173992 | 366 | /* Check that the Start column is located in the screen */ |
arostm | 0:4af3ca173992 | 367 | if ((refcolumn < 1) || (refcolumn >= 0x8000)) |
arostm | 0:4af3ca173992 | 368 | { |
arostm | 0:4af3ca173992 | 369 | refcolumn = 1; |
arostm | 0:4af3ca173992 | 370 | } |
arostm | 0:4af3ca173992 | 371 | |
arostm | 0:4af3ca173992 | 372 | /* Send the string character by character on lCD */ |
arostm | 0:4af3ca173992 | 373 | while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp.pFont->Width)) & 0xFFFF) >= DrawProp.pFont->Width)) |
arostm | 0:4af3ca173992 | 374 | { |
arostm | 0:4af3ca173992 | 375 | /* Display one character on LCD */ |
arostm | 0:4af3ca173992 | 376 | BSP_LCD_DisplayChar(refcolumn, Ypos, *Text); |
arostm | 0:4af3ca173992 | 377 | /* Decrement the column position by 16 */ |
arostm | 0:4af3ca173992 | 378 | refcolumn += DrawProp.pFont->Width; |
arostm | 0:4af3ca173992 | 379 | /* Point on the next character */ |
arostm | 0:4af3ca173992 | 380 | Text++; |
arostm | 0:4af3ca173992 | 381 | i++; |
arostm | 0:4af3ca173992 | 382 | } |
arostm | 0:4af3ca173992 | 383 | } |
arostm | 0:4af3ca173992 | 384 | |
arostm | 0:4af3ca173992 | 385 | /** |
arostm | 0:4af3ca173992 | 386 | * @brief Displays a character on the LCD. |
arostm | 0:4af3ca173992 | 387 | * @param Line: Line where to display the character shape |
arostm | 0:4af3ca173992 | 388 | * This parameter can be one of the following values: |
arostm | 0:4af3ca173992 | 389 | * @arg 0..9: if the Current fonts is Font16x24 |
arostm | 0:4af3ca173992 | 390 | * @arg 0..19: if the Current fonts is Font12x12 or Font8x12 |
arostm | 0:4af3ca173992 | 391 | * @arg 0..29: if the Current fonts is Font8x8 |
arostm | 0:4af3ca173992 | 392 | * @param ptr: Pointer to string to display on LCD |
arostm | 0:4af3ca173992 | 393 | */ |
arostm | 0:4af3ca173992 | 394 | void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr) |
arostm | 0:4af3ca173992 | 395 | { |
arostm | 0:4af3ca173992 | 396 | BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE); |
arostm | 0:4af3ca173992 | 397 | } |
arostm | 0:4af3ca173992 | 398 | |
arostm | 0:4af3ca173992 | 399 | /** |
arostm | 0:4af3ca173992 | 400 | * @brief Reads an LCD pixel. |
arostm | 0:4af3ca173992 | 401 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 402 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 403 | * @retval RGB pixel color |
arostm | 0:4af3ca173992 | 404 | */ |
arostm | 0:4af3ca173992 | 405 | uint16_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos) |
arostm | 0:4af3ca173992 | 406 | { |
arostm | 0:4af3ca173992 | 407 | uint16_t ret = 0; |
arostm | 0:4af3ca173992 | 408 | |
arostm | 0:4af3ca173992 | 409 | if(LcdDrv->ReadPixel != NULL) |
arostm | 0:4af3ca173992 | 410 | { |
arostm | 0:4af3ca173992 | 411 | ret = LcdDrv->ReadPixel(Xpos, Ypos); |
arostm | 0:4af3ca173992 | 412 | } |
arostm | 0:4af3ca173992 | 413 | |
arostm | 0:4af3ca173992 | 414 | return ret; |
arostm | 0:4af3ca173992 | 415 | } |
arostm | 0:4af3ca173992 | 416 | |
arostm | 0:4af3ca173992 | 417 | /** |
arostm | 0:4af3ca173992 | 418 | * @brief Draws a pixel on LCD. |
arostm | 0:4af3ca173992 | 419 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 420 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 421 | * @param RGB_Code: Pixel color in RGB mode (5-6-5) |
arostm | 0:4af3ca173992 | 422 | */ |
arostm | 0:4af3ca173992 | 423 | void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGB_Code) |
arostm | 0:4af3ca173992 | 424 | { |
arostm | 0:4af3ca173992 | 425 | if(LcdDrv->WritePixel != NULL) |
arostm | 0:4af3ca173992 | 426 | { |
arostm | 0:4af3ca173992 | 427 | LcdDrv->WritePixel(Xpos, Ypos, RGB_Code); |
arostm | 0:4af3ca173992 | 428 | } |
arostm | 0:4af3ca173992 | 429 | } |
arostm | 0:4af3ca173992 | 430 | |
arostm | 0:4af3ca173992 | 431 | /** |
arostm | 0:4af3ca173992 | 432 | * @brief Draws an horizontal line. |
arostm | 0:4af3ca173992 | 433 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 434 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 435 | * @param Length: Line length |
arostm | 0:4af3ca173992 | 436 | */ |
arostm | 0:4af3ca173992 | 437 | void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) |
arostm | 0:4af3ca173992 | 438 | { |
arostm | 0:4af3ca173992 | 439 | uint32_t index = 0; |
arostm | 0:4af3ca173992 | 440 | |
arostm | 0:4af3ca173992 | 441 | if(LcdDrv->DrawHLine != NULL) |
arostm | 0:4af3ca173992 | 442 | { |
arostm | 0:4af3ca173992 | 443 | LcdDrv->DrawHLine(DrawProp.TextColor, Xpos, Ypos, Length); |
arostm | 0:4af3ca173992 | 444 | } |
arostm | 0:4af3ca173992 | 445 | else |
arostm | 0:4af3ca173992 | 446 | { |
arostm | 0:4af3ca173992 | 447 | for(index = 0; index < Length; index++) |
arostm | 0:4af3ca173992 | 448 | { |
arostm | 0:4af3ca173992 | 449 | BSP_LCD_DrawPixel((Xpos + index), Ypos, DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 450 | } |
arostm | 0:4af3ca173992 | 451 | } |
arostm | 0:4af3ca173992 | 452 | } |
arostm | 0:4af3ca173992 | 453 | |
arostm | 0:4af3ca173992 | 454 | /** |
arostm | 0:4af3ca173992 | 455 | * @brief Draws a vertical line. |
arostm | 0:4af3ca173992 | 456 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 457 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 458 | * @param Length: Line length |
arostm | 0:4af3ca173992 | 459 | */ |
arostm | 0:4af3ca173992 | 460 | void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length) |
arostm | 0:4af3ca173992 | 461 | { |
arostm | 0:4af3ca173992 | 462 | uint32_t index = 0; |
arostm | 0:4af3ca173992 | 463 | |
arostm | 0:4af3ca173992 | 464 | if(LcdDrv->DrawVLine != NULL) |
arostm | 0:4af3ca173992 | 465 | { |
arostm | 0:4af3ca173992 | 466 | LcdDrv->DrawVLine(DrawProp.TextColor, Xpos, Ypos, Length); |
arostm | 0:4af3ca173992 | 467 | } |
arostm | 0:4af3ca173992 | 468 | else |
arostm | 0:4af3ca173992 | 469 | { |
arostm | 0:4af3ca173992 | 470 | for(index = 0; index < Length; index++) |
arostm | 0:4af3ca173992 | 471 | { |
arostm | 0:4af3ca173992 | 472 | BSP_LCD_DrawPixel(Xpos, Ypos + index, DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 473 | } |
arostm | 0:4af3ca173992 | 474 | } |
arostm | 0:4af3ca173992 | 475 | } |
arostm | 0:4af3ca173992 | 476 | |
arostm | 0:4af3ca173992 | 477 | /** |
arostm | 0:4af3ca173992 | 478 | * @brief Draws an uni-line (between two points). |
arostm | 0:4af3ca173992 | 479 | * @param x1: Point 1 X position |
arostm | 0:4af3ca173992 | 480 | * @param y1: Point 1 Y position |
arostm | 0:4af3ca173992 | 481 | * @param x2: Point 2 X position |
arostm | 0:4af3ca173992 | 482 | * @param y2: Point 2 Y position |
arostm | 0:4af3ca173992 | 483 | */ |
arostm | 0:4af3ca173992 | 484 | void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) |
arostm | 0:4af3ca173992 | 485 | { |
arostm | 0:4af3ca173992 | 486 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, |
arostm | 0:4af3ca173992 | 487 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, |
arostm | 0:4af3ca173992 | 488 | curpixel = 0; |
arostm | 0:4af3ca173992 | 489 | |
arostm | 0:4af3ca173992 | 490 | deltax = ABS(x2 - x1); /* The difference between the x's */ |
arostm | 0:4af3ca173992 | 491 | deltay = ABS(y2 - y1); /* The difference between the y's */ |
arostm | 0:4af3ca173992 | 492 | x = x1; /* Start x off at the first pixel */ |
arostm | 0:4af3ca173992 | 493 | y = y1; /* Start y off at the first pixel */ |
arostm | 0:4af3ca173992 | 494 | |
arostm | 0:4af3ca173992 | 495 | if (x2 >= x1) /* The x-values are increasing */ |
arostm | 0:4af3ca173992 | 496 | { |
arostm | 0:4af3ca173992 | 497 | xinc1 = 1; |
arostm | 0:4af3ca173992 | 498 | xinc2 = 1; |
arostm | 0:4af3ca173992 | 499 | } |
arostm | 0:4af3ca173992 | 500 | else /* The x-values are decreasing */ |
arostm | 0:4af3ca173992 | 501 | { |
arostm | 0:4af3ca173992 | 502 | xinc1 = -1; |
arostm | 0:4af3ca173992 | 503 | xinc2 = -1; |
arostm | 0:4af3ca173992 | 504 | } |
arostm | 0:4af3ca173992 | 505 | |
arostm | 0:4af3ca173992 | 506 | if (y2 >= y1) /* The y-values are increasing */ |
arostm | 0:4af3ca173992 | 507 | { |
arostm | 0:4af3ca173992 | 508 | yinc1 = 1; |
arostm | 0:4af3ca173992 | 509 | yinc2 = 1; |
arostm | 0:4af3ca173992 | 510 | } |
arostm | 0:4af3ca173992 | 511 | else /* The y-values are decreasing */ |
arostm | 0:4af3ca173992 | 512 | { |
arostm | 0:4af3ca173992 | 513 | yinc1 = -1; |
arostm | 0:4af3ca173992 | 514 | yinc2 = -1; |
arostm | 0:4af3ca173992 | 515 | } |
arostm | 0:4af3ca173992 | 516 | |
arostm | 0:4af3ca173992 | 517 | if (deltax >= deltay) /* There is at least one x-value for every y-value */ |
arostm | 0:4af3ca173992 | 518 | { |
arostm | 0:4af3ca173992 | 519 | xinc1 = 0; /* Don't change the x when numerator >= denominator */ |
arostm | 0:4af3ca173992 | 520 | yinc2 = 0; /* Don't change the y for every iteration */ |
arostm | 0:4af3ca173992 | 521 | den = deltax; |
arostm | 0:4af3ca173992 | 522 | num = deltax / 2; |
arostm | 0:4af3ca173992 | 523 | numadd = deltay; |
arostm | 0:4af3ca173992 | 524 | numpixels = deltax; /* There are more x-values than y-values */ |
arostm | 0:4af3ca173992 | 525 | } |
arostm | 0:4af3ca173992 | 526 | else /* There is at least one y-value for every x-value */ |
arostm | 0:4af3ca173992 | 527 | { |
arostm | 0:4af3ca173992 | 528 | xinc2 = 0; /* Don't change the x for every iteration */ |
arostm | 0:4af3ca173992 | 529 | yinc1 = 0; /* Don't change the y when numerator >= denominator */ |
arostm | 0:4af3ca173992 | 530 | den = deltay; |
arostm | 0:4af3ca173992 | 531 | num = deltay / 2; |
arostm | 0:4af3ca173992 | 532 | numadd = deltax; |
arostm | 0:4af3ca173992 | 533 | numpixels = deltay; /* There are more y-values than x-values */ |
arostm | 0:4af3ca173992 | 534 | } |
arostm | 0:4af3ca173992 | 535 | |
arostm | 0:4af3ca173992 | 536 | for (curpixel = 0; curpixel <= numpixels; curpixel++) |
arostm | 0:4af3ca173992 | 537 | { |
arostm | 0:4af3ca173992 | 538 | BSP_LCD_DrawPixel(x, y, DrawProp.TextColor); /* Draw the current pixel */ |
arostm | 0:4af3ca173992 | 539 | num += numadd; /* Increase the numerator by the top of the fraction */ |
arostm | 0:4af3ca173992 | 540 | if (num >= den) /* Check if numerator >= denominator */ |
arostm | 0:4af3ca173992 | 541 | { |
arostm | 0:4af3ca173992 | 542 | num -= den; /* Calculate the new numerator value */ |
arostm | 0:4af3ca173992 | 543 | x += xinc1; /* Change the x as appropriate */ |
arostm | 0:4af3ca173992 | 544 | y += yinc1; /* Change the y as appropriate */ |
arostm | 0:4af3ca173992 | 545 | } |
arostm | 0:4af3ca173992 | 546 | x += xinc2; /* Change the x as appropriate */ |
arostm | 0:4af3ca173992 | 547 | y += yinc2; /* Change the y as appropriate */ |
arostm | 0:4af3ca173992 | 548 | } |
arostm | 0:4af3ca173992 | 549 | } |
arostm | 0:4af3ca173992 | 550 | |
arostm | 0:4af3ca173992 | 551 | /** |
arostm | 0:4af3ca173992 | 552 | * @brief Draws a rectangle. |
arostm | 0:4af3ca173992 | 553 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 554 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 555 | * @param Width: Rectangle width |
arostm | 0:4af3ca173992 | 556 | * @param Height: Rectangle height |
arostm | 0:4af3ca173992 | 557 | */ |
arostm | 0:4af3ca173992 | 558 | void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) |
arostm | 0:4af3ca173992 | 559 | { |
arostm | 0:4af3ca173992 | 560 | /* Draw horizontal lines */ |
arostm | 0:4af3ca173992 | 561 | BSP_LCD_DrawHLine(Xpos, Ypos, Width); |
arostm | 0:4af3ca173992 | 562 | BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width); |
arostm | 0:4af3ca173992 | 563 | |
arostm | 0:4af3ca173992 | 564 | /* Draw vertical lines */ |
arostm | 0:4af3ca173992 | 565 | BSP_LCD_DrawVLine(Xpos, Ypos, Height); |
arostm | 0:4af3ca173992 | 566 | BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height); |
arostm | 0:4af3ca173992 | 567 | } |
arostm | 0:4af3ca173992 | 568 | |
arostm | 0:4af3ca173992 | 569 | /** |
arostm | 0:4af3ca173992 | 570 | * @brief Draws a circle. |
arostm | 0:4af3ca173992 | 571 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 572 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 573 | * @param Radius: Circle radius |
arostm | 0:4af3ca173992 | 574 | */ |
arostm | 0:4af3ca173992 | 575 | void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) |
arostm | 0:4af3ca173992 | 576 | { |
arostm | 0:4af3ca173992 | 577 | int32_t decision; /* Decision Variable */ |
arostm | 0:4af3ca173992 | 578 | uint32_t current_x; /* Current X Value */ |
arostm | 0:4af3ca173992 | 579 | uint32_t current_y; /* Current Y Value */ |
arostm | 0:4af3ca173992 | 580 | |
arostm | 0:4af3ca173992 | 581 | decision = 3 - (Radius << 1); |
arostm | 0:4af3ca173992 | 582 | current_x = 0; |
arostm | 0:4af3ca173992 | 583 | current_y = Radius; |
arostm | 0:4af3ca173992 | 584 | |
arostm | 0:4af3ca173992 | 585 | while (current_x <= current_y) |
arostm | 0:4af3ca173992 | 586 | { |
arostm | 0:4af3ca173992 | 587 | BSP_LCD_DrawPixel((Xpos + current_x), (Ypos - current_y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 588 | |
arostm | 0:4af3ca173992 | 589 | BSP_LCD_DrawPixel((Xpos - current_x), (Ypos - current_y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 590 | |
arostm | 0:4af3ca173992 | 591 | BSP_LCD_DrawPixel((Xpos + current_y), (Ypos - current_x), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 592 | |
arostm | 0:4af3ca173992 | 593 | BSP_LCD_DrawPixel((Xpos - current_y), (Ypos - current_x), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 594 | |
arostm | 0:4af3ca173992 | 595 | BSP_LCD_DrawPixel((Xpos + current_x), (Ypos + current_y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 596 | |
arostm | 0:4af3ca173992 | 597 | BSP_LCD_DrawPixel((Xpos - current_x), (Ypos + current_y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 598 | |
arostm | 0:4af3ca173992 | 599 | BSP_LCD_DrawPixel((Xpos + current_y), (Ypos + current_x), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 600 | |
arostm | 0:4af3ca173992 | 601 | BSP_LCD_DrawPixel((Xpos - current_y), (Ypos + current_x), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 602 | |
arostm | 0:4af3ca173992 | 603 | /* Initialize the font */ |
arostm | 0:4af3ca173992 | 604 | BSP_LCD_SetFont(&LCD_DEFAULT_FONT); |
arostm | 0:4af3ca173992 | 605 | |
arostm | 0:4af3ca173992 | 606 | if (decision < 0) |
arostm | 0:4af3ca173992 | 607 | { |
arostm | 0:4af3ca173992 | 608 | decision += (current_x << 2) + 6; |
arostm | 0:4af3ca173992 | 609 | } |
arostm | 0:4af3ca173992 | 610 | else |
arostm | 0:4af3ca173992 | 611 | { |
arostm | 0:4af3ca173992 | 612 | decision += ((current_x - current_y) << 2) + 10; |
arostm | 0:4af3ca173992 | 613 | current_y--; |
arostm | 0:4af3ca173992 | 614 | } |
arostm | 0:4af3ca173992 | 615 | current_x++; |
arostm | 0:4af3ca173992 | 616 | } |
arostm | 0:4af3ca173992 | 617 | } |
arostm | 0:4af3ca173992 | 618 | |
arostm | 0:4af3ca173992 | 619 | /** |
arostm | 0:4af3ca173992 | 620 | * @brief Draws an poly-line (between many points). |
arostm | 0:4af3ca173992 | 621 | * @param Points: Pointer to the points array |
arostm | 0:4af3ca173992 | 622 | * @param PointCount: Number of points |
arostm | 0:4af3ca173992 | 623 | */ |
arostm | 0:4af3ca173992 | 624 | void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount) |
arostm | 0:4af3ca173992 | 625 | { |
arostm | 0:4af3ca173992 | 626 | int16_t x = 0, y = 0; |
arostm | 0:4af3ca173992 | 627 | |
arostm | 0:4af3ca173992 | 628 | if(PointCount < 2) |
arostm | 0:4af3ca173992 | 629 | { |
arostm | 0:4af3ca173992 | 630 | return; |
arostm | 0:4af3ca173992 | 631 | } |
arostm | 0:4af3ca173992 | 632 | |
arostm | 0:4af3ca173992 | 633 | BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); |
arostm | 0:4af3ca173992 | 634 | |
arostm | 0:4af3ca173992 | 635 | while(--PointCount) |
arostm | 0:4af3ca173992 | 636 | { |
arostm | 0:4af3ca173992 | 637 | x = Points->X; |
arostm | 0:4af3ca173992 | 638 | y = Points->Y; |
arostm | 0:4af3ca173992 | 639 | Points++; |
arostm | 0:4af3ca173992 | 640 | BSP_LCD_DrawLine(x, y, Points->X, Points->Y); |
arostm | 0:4af3ca173992 | 641 | } |
arostm | 0:4af3ca173992 | 642 | } |
arostm | 0:4af3ca173992 | 643 | |
arostm | 0:4af3ca173992 | 644 | /** |
arostm | 0:4af3ca173992 | 645 | * @brief Draws an ellipse on LCD. |
arostm | 0:4af3ca173992 | 646 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 647 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 648 | * @param XRadius: Ellipse X radius |
arostm | 0:4af3ca173992 | 649 | * @param YRadius: Ellipse Y radius |
arostm | 0:4af3ca173992 | 650 | */ |
arostm | 0:4af3ca173992 | 651 | void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius) |
arostm | 0:4af3ca173992 | 652 | { |
arostm | 0:4af3ca173992 | 653 | int x = 0, y = -YRadius, err = 2-2*XRadius, e2; |
arostm | 0:4af3ca173992 | 654 | float k = 0, rad1 = 0, rad2 = 0; |
arostm | 0:4af3ca173992 | 655 | |
arostm | 0:4af3ca173992 | 656 | rad1 = XRadius; |
arostm | 0:4af3ca173992 | 657 | rad2 = YRadius; |
arostm | 0:4af3ca173992 | 658 | |
arostm | 0:4af3ca173992 | 659 | k = (float)(rad2/rad1); |
arostm | 0:4af3ca173992 | 660 | |
arostm | 0:4af3ca173992 | 661 | do { |
arostm | 0:4af3ca173992 | 662 | BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos+y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 663 | BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos+y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 664 | BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/k)), (Ypos-y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 665 | BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/k)), (Ypos-y), DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 666 | |
arostm | 0:4af3ca173992 | 667 | e2 = err; |
arostm | 0:4af3ca173992 | 668 | if (e2 <= x) { |
arostm | 0:4af3ca173992 | 669 | err += ++x*2+1; |
arostm | 0:4af3ca173992 | 670 | if (-y == x && e2 <= y) e2 = 0; |
arostm | 0:4af3ca173992 | 671 | } |
arostm | 0:4af3ca173992 | 672 | if (e2 > y) err += ++y*2+1; |
arostm | 0:4af3ca173992 | 673 | } |
arostm | 0:4af3ca173992 | 674 | while (y <= 0); |
arostm | 0:4af3ca173992 | 675 | } |
arostm | 0:4af3ca173992 | 676 | |
arostm | 0:4af3ca173992 | 677 | /** |
arostm | 0:4af3ca173992 | 678 | * @brief Draws a bitmap picture (16 bpp). |
arostm | 0:4af3ca173992 | 679 | * @param Xpos: Bmp X position in the LCD |
arostm | 0:4af3ca173992 | 680 | * @param Ypos: Bmp Y position in the LCD |
arostm | 0:4af3ca173992 | 681 | * @param pbmp: Pointer to Bmp picture address. |
arostm | 0:4af3ca173992 | 682 | */ |
arostm | 0:4af3ca173992 | 683 | void BSP_LCD_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp) |
arostm | 0:4af3ca173992 | 684 | { |
arostm | 0:4af3ca173992 | 685 | uint32_t height = 0; |
arostm | 0:4af3ca173992 | 686 | uint32_t width = 0; |
arostm | 0:4af3ca173992 | 687 | |
arostm | 0:4af3ca173992 | 688 | /* Read bitmap width */ |
Jerome Coutant
3:42b354f5069c
|
689
|
width = pbmp[18] + (pbmp[19] << 8) + (pbmp[20] << 16) + (pbmp[21] << 24);
|
|
Jerome Coutant
3:42b354f5069c
|
690
|
|
|
arostm | 0:4af3ca173992 | 691 | /* Read bitmap height */ |
Jerome Coutant
3:42b354f5069c
|
692
|
height = pbmp[22] + (pbmp[23] << 8) + (pbmp[24] << 16) + (pbmp[25] << 24);
|
|
arostm | 0:4af3ca173992 | 693 | |
arostm | 0:4af3ca173992 | 694 | SetDisplayWindow(Xpos, Ypos, width, height); |
arostm | 0:4af3ca173992 | 695 | |
arostm | 0:4af3ca173992 | 696 | if(LcdDrv->DrawBitmap != NULL) |
arostm | 0:4af3ca173992 | 697 | { |
arostm | 0:4af3ca173992 | 698 | LcdDrv->DrawBitmap(Xpos, Ypos, pbmp); |
arostm | 0:4af3ca173992 | 699 | } |
arostm | 0:4af3ca173992 | 700 | SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); |
arostm | 0:4af3ca173992 | 701 | } |
arostm | 0:4af3ca173992 | 702 | |
arostm | 0:4af3ca173992 | 703 | /** |
arostm | 0:4af3ca173992 | 704 | * @brief Draws RGB Image (16 bpp). |
arostm | 0:4af3ca173992 | 705 | * @param Xpos: X position in the LCD |
arostm | 0:4af3ca173992 | 706 | * @param Ypos: Y position in the LCD |
arostm | 0:4af3ca173992 | 707 | * @param Xsize: X size in the LCD |
arostm | 0:4af3ca173992 | 708 | * @param Ysize: Y size in the LCD |
arostm | 0:4af3ca173992 | 709 | * @param pdata: Pointer to the RGB Image address. |
arostm | 0:4af3ca173992 | 710 | */ |
arostm | 0:4af3ca173992 | 711 | void BSP_LCD_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata) |
arostm | 0:4af3ca173992 | 712 | { |
arostm | 0:4af3ca173992 | 713 | |
arostm | 0:4af3ca173992 | 714 | SetDisplayWindow(Xpos, Ypos, Xsize, Ysize); |
arostm | 0:4af3ca173992 | 715 | |
arostm | 0:4af3ca173992 | 716 | if(LcdDrv->DrawRGBImage != NULL) |
arostm | 0:4af3ca173992 | 717 | { |
arostm | 0:4af3ca173992 | 718 | LcdDrv->DrawRGBImage(Xpos, Ypos, Xsize, Ysize, pdata); |
arostm | 0:4af3ca173992 | 719 | } |
arostm | 0:4af3ca173992 | 720 | SetDisplayWindow(0, 0, BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); |
arostm | 0:4af3ca173992 | 721 | } |
arostm | 0:4af3ca173992 | 722 | |
arostm | 0:4af3ca173992 | 723 | /** |
arostm | 0:4af3ca173992 | 724 | * @brief Draws a full rectangle. |
arostm | 0:4af3ca173992 | 725 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 726 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 727 | * @param Width: Rectangle width |
arostm | 0:4af3ca173992 | 728 | * @param Height: Rectangle height |
arostm | 0:4af3ca173992 | 729 | */ |
arostm | 0:4af3ca173992 | 730 | void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) |
arostm | 0:4af3ca173992 | 731 | { |
arostm | 0:4af3ca173992 | 732 | BSP_LCD_SetTextColor(DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 733 | do |
arostm | 0:4af3ca173992 | 734 | { |
arostm | 0:4af3ca173992 | 735 | BSP_LCD_DrawHLine(Xpos, Ypos++, Width); |
arostm | 0:4af3ca173992 | 736 | } |
arostm | 0:4af3ca173992 | 737 | while(Height--); |
arostm | 0:4af3ca173992 | 738 | } |
arostm | 0:4af3ca173992 | 739 | |
arostm | 0:4af3ca173992 | 740 | /** |
arostm | 0:4af3ca173992 | 741 | * @brief Draws a full circle. |
arostm | 0:4af3ca173992 | 742 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 743 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 744 | * @param Radius: Circle radius |
arostm | 0:4af3ca173992 | 745 | */ |
arostm | 0:4af3ca173992 | 746 | void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) |
arostm | 0:4af3ca173992 | 747 | { |
arostm | 0:4af3ca173992 | 748 | int32_t decision; /* Decision Variable */ |
arostm | 0:4af3ca173992 | 749 | uint32_t current_x; /* Current X Value */ |
arostm | 0:4af3ca173992 | 750 | uint32_t current_y; /* Current Y Value */ |
arostm | 0:4af3ca173992 | 751 | |
arostm | 0:4af3ca173992 | 752 | decision = 3 - (Radius << 1); |
arostm | 0:4af3ca173992 | 753 | |
arostm | 0:4af3ca173992 | 754 | current_x = 0; |
arostm | 0:4af3ca173992 | 755 | current_y = Radius; |
arostm | 0:4af3ca173992 | 756 | |
arostm | 0:4af3ca173992 | 757 | BSP_LCD_SetTextColor(DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 758 | |
arostm | 0:4af3ca173992 | 759 | while (current_x <= current_y) |
arostm | 0:4af3ca173992 | 760 | { |
arostm | 0:4af3ca173992 | 761 | if(current_y > 0) |
arostm | 0:4af3ca173992 | 762 | { |
arostm | 0:4af3ca173992 | 763 | BSP_LCD_DrawHLine(Xpos - current_y, Ypos + current_x, 2*current_y); |
arostm | 0:4af3ca173992 | 764 | BSP_LCD_DrawHLine(Xpos - current_y, Ypos - current_x, 2*current_y); |
arostm | 0:4af3ca173992 | 765 | } |
arostm | 0:4af3ca173992 | 766 | |
arostm | 0:4af3ca173992 | 767 | if(current_x > 0) |
arostm | 0:4af3ca173992 | 768 | { |
arostm | 0:4af3ca173992 | 769 | BSP_LCD_DrawHLine(Xpos - current_x, Ypos - current_y, 2*current_x); |
arostm | 0:4af3ca173992 | 770 | BSP_LCD_DrawHLine(Xpos - current_x, Ypos + current_y, 2*current_x); |
arostm | 0:4af3ca173992 | 771 | } |
arostm | 0:4af3ca173992 | 772 | if (decision < 0) |
arostm | 0:4af3ca173992 | 773 | { |
arostm | 0:4af3ca173992 | 774 | decision += (current_x << 2) + 6; |
arostm | 0:4af3ca173992 | 775 | } |
arostm | 0:4af3ca173992 | 776 | else |
arostm | 0:4af3ca173992 | 777 | { |
arostm | 0:4af3ca173992 | 778 | decision += ((current_x - current_y) << 2) + 10; |
arostm | 0:4af3ca173992 | 779 | current_y--; |
arostm | 0:4af3ca173992 | 780 | } |
arostm | 0:4af3ca173992 | 781 | current_x++; |
arostm | 0:4af3ca173992 | 782 | } |
arostm | 0:4af3ca173992 | 783 | |
arostm | 0:4af3ca173992 | 784 | BSP_LCD_SetTextColor(DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 785 | BSP_LCD_DrawCircle(Xpos, Ypos, Radius); |
arostm | 0:4af3ca173992 | 786 | } |
arostm | 0:4af3ca173992 | 787 | |
arostm | 0:4af3ca173992 | 788 | /** |
arostm | 0:4af3ca173992 | 789 | * @brief Draws a full poly-line (between many points). |
arostm | 0:4af3ca173992 | 790 | * @param Points: Pointer to the points array |
arostm | 0:4af3ca173992 | 791 | * @param PointCount: Number of points |
arostm | 0:4af3ca173992 | 792 | */ |
arostm | 0:4af3ca173992 | 793 | void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) |
arostm | 0:4af3ca173992 | 794 | { |
arostm | 0:4af3ca173992 | 795 | 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; |
arostm | 0:4af3ca173992 | 796 | uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0; |
arostm | 0:4af3ca173992 | 797 | |
arostm | 0:4af3ca173992 | 798 | IMAGE_LEFT = IMAGE_RIGHT = Points->X; |
arostm | 0:4af3ca173992 | 799 | IMAGE_TOP= IMAGE_BOTTOM = Points->Y; |
arostm | 0:4af3ca173992 | 800 | |
arostm | 0:4af3ca173992 | 801 | for(counter = 1; counter < PointCount; counter++) |
arostm | 0:4af3ca173992 | 802 | { |
arostm | 0:4af3ca173992 | 803 | pixelX = POLY_X(counter); |
arostm | 0:4af3ca173992 | 804 | if(pixelX < IMAGE_LEFT) |
arostm | 0:4af3ca173992 | 805 | { |
arostm | 0:4af3ca173992 | 806 | IMAGE_LEFT = pixelX; |
arostm | 0:4af3ca173992 | 807 | } |
arostm | 0:4af3ca173992 | 808 | if(pixelX > IMAGE_RIGHT) |
arostm | 0:4af3ca173992 | 809 | { |
arostm | 0:4af3ca173992 | 810 | IMAGE_RIGHT = pixelX; |
arostm | 0:4af3ca173992 | 811 | } |
arostm | 0:4af3ca173992 | 812 | |
arostm | 0:4af3ca173992 | 813 | pixelY = POLY_Y(counter); |
arostm | 0:4af3ca173992 | 814 | if(pixelY < IMAGE_TOP) |
arostm | 0:4af3ca173992 | 815 | { |
arostm | 0:4af3ca173992 | 816 | IMAGE_TOP = pixelY; |
arostm | 0:4af3ca173992 | 817 | } |
arostm | 0:4af3ca173992 | 818 | if(pixelY > IMAGE_BOTTOM) |
arostm | 0:4af3ca173992 | 819 | { |
arostm | 0:4af3ca173992 | 820 | IMAGE_BOTTOM = pixelY; |
arostm | 0:4af3ca173992 | 821 | } |
arostm | 0:4af3ca173992 | 822 | } |
arostm | 0:4af3ca173992 | 823 | |
arostm | 0:4af3ca173992 | 824 | if(PointCount < 2) |
arostm | 0:4af3ca173992 | 825 | { |
arostm | 0:4af3ca173992 | 826 | return; |
arostm | 0:4af3ca173992 | 827 | } |
arostm | 0:4af3ca173992 | 828 | |
arostm | 0:4af3ca173992 | 829 | X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2; |
arostm | 0:4af3ca173992 | 830 | Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2; |
arostm | 0:4af3ca173992 | 831 | |
arostm | 0:4af3ca173992 | 832 | X_first = Points->X; |
arostm | 0:4af3ca173992 | 833 | Y_first = Points->Y; |
arostm | 0:4af3ca173992 | 834 | |
arostm | 0:4af3ca173992 | 835 | while(--PointCount) |
arostm | 0:4af3ca173992 | 836 | { |
arostm | 0:4af3ca173992 | 837 | X = Points->X; |
arostm | 0:4af3ca173992 | 838 | Y = Points->Y; |
arostm | 0:4af3ca173992 | 839 | Points++; |
arostm | 0:4af3ca173992 | 840 | X2 = Points->X; |
arostm | 0:4af3ca173992 | 841 | Y2 = Points->Y; |
arostm | 0:4af3ca173992 | 842 | |
arostm | 0:4af3ca173992 | 843 | FillTriangle(X, X2, X_center, Y, Y2, Y_center); |
arostm | 0:4af3ca173992 | 844 | FillTriangle(X, X_center, X2, Y, Y_center, Y2); |
arostm | 0:4af3ca173992 | 845 | FillTriangle(X_center, X2, X, Y_center, Y2, Y); |
arostm | 0:4af3ca173992 | 846 | } |
arostm | 0:4af3ca173992 | 847 | |
arostm | 0:4af3ca173992 | 848 | FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); |
arostm | 0:4af3ca173992 | 849 | FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); |
arostm | 0:4af3ca173992 | 850 | FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); |
arostm | 0:4af3ca173992 | 851 | } |
arostm | 0:4af3ca173992 | 852 | |
arostm | 0:4af3ca173992 | 853 | /** |
arostm | 0:4af3ca173992 | 854 | * @brief Draws a full ellipse. |
arostm | 0:4af3ca173992 | 855 | * @param Xpos: X position |
arostm | 0:4af3ca173992 | 856 | * @param Ypos: Y position |
arostm | 0:4af3ca173992 | 857 | * @param XRadius: Ellipse X radius |
arostm | 0:4af3ca173992 | 858 | * @param YRadius: Ellipse Y radius |
arostm | 0:4af3ca173992 | 859 | */ |
arostm | 0:4af3ca173992 | 860 | void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius) |
arostm | 0:4af3ca173992 | 861 | { |
arostm | 0:4af3ca173992 | 862 | int x = 0, y = -YRadius, err = 2-2*XRadius, e2; |
arostm | 0:4af3ca173992 | 863 | float k = 0, rad1 = 0, rad2 = 0; |
arostm | 0:4af3ca173992 | 864 | |
arostm | 0:4af3ca173992 | 865 | rad1 = XRadius; |
arostm | 0:4af3ca173992 | 866 | rad2 = YRadius; |
arostm | 0:4af3ca173992 | 867 | |
arostm | 0:4af3ca173992 | 868 | k = (float)(rad2/rad1); |
arostm | 0:4af3ca173992 | 869 | |
arostm | 0:4af3ca173992 | 870 | do |
arostm | 0:4af3ca173992 | 871 | { |
arostm | 0:4af3ca173992 | 872 | BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos+y), (2*(uint16_t)(x/k) + 1)); |
arostm | 0:4af3ca173992 | 873 | BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/k)), (Ypos-y), (2*(uint16_t)(x/k) + 1)); |
arostm | 0:4af3ca173992 | 874 | |
arostm | 0:4af3ca173992 | 875 | e2 = err; |
arostm | 0:4af3ca173992 | 876 | if (e2 <= x) |
arostm | 0:4af3ca173992 | 877 | { |
arostm | 0:4af3ca173992 | 878 | err += ++x*2+1; |
arostm | 0:4af3ca173992 | 879 | if (-y == x && e2 <= y) e2 = 0; |
arostm | 0:4af3ca173992 | 880 | } |
arostm | 0:4af3ca173992 | 881 | if (e2 > y) err += ++y*2+1; |
arostm | 0:4af3ca173992 | 882 | } |
arostm | 0:4af3ca173992 | 883 | while (y <= 0); |
arostm | 0:4af3ca173992 | 884 | } |
arostm | 0:4af3ca173992 | 885 | |
arostm | 0:4af3ca173992 | 886 | /** |
arostm | 0:4af3ca173992 | 887 | * @brief Enables the display. |
arostm | 0:4af3ca173992 | 888 | */ |
arostm | 0:4af3ca173992 | 889 | void BSP_LCD_DisplayOn(void) |
arostm | 0:4af3ca173992 | 890 | { |
arostm | 0:4af3ca173992 | 891 | LcdDrv->DisplayOn(); |
arostm | 0:4af3ca173992 | 892 | } |
arostm | 0:4af3ca173992 | 893 | |
arostm | 0:4af3ca173992 | 894 | /** |
arostm | 0:4af3ca173992 | 895 | * @brief Disables the display. |
arostm | 0:4af3ca173992 | 896 | */ |
arostm | 0:4af3ca173992 | 897 | void BSP_LCD_DisplayOff(void) |
arostm | 0:4af3ca173992 | 898 | { |
arostm | 0:4af3ca173992 | 899 | LcdDrv->DisplayOff(); |
arostm | 0:4af3ca173992 | 900 | } |
arostm | 0:4af3ca173992 | 901 | |
arostm | 0:4af3ca173992 | 902 | /** |
arostm | 0:4af3ca173992 | 903 | * @brief Initializes the LCD GPIO special pins MSP. |
arostm | 0:4af3ca173992 | 904 | */ |
arostm | 0:4af3ca173992 | 905 | __weak void BSP_LCD_MspInit(void) |
arostm | 0:4af3ca173992 | 906 | { |
arostm | 0:4af3ca173992 | 907 | GPIO_InitTypeDef gpio_init_structure; |
arostm | 0:4af3ca173992 | 908 | |
arostm | 0:4af3ca173992 | 909 | /* Enable GPIOs clock */ |
arostm | 0:4af3ca173992 | 910 | LCD_RESET_GPIO_CLK_ENABLE(); |
arostm | 0:4af3ca173992 | 911 | LCD_TE_GPIO_CLK_ENABLE(); |
arostm | 0:4af3ca173992 | 912 | LCD_BL_CTRL_GPIO_CLK_ENABLE(); |
arostm | 0:4af3ca173992 | 913 | |
arostm | 0:4af3ca173992 | 914 | /* LCD_RESET GPIO configuration */ |
arostm | 0:4af3ca173992 | 915 | gpio_init_structure.Pin = LCD_RESET_PIN; /* LCD_RESET pin has to be manually controlled */ |
arostm | 0:4af3ca173992 | 916 | gpio_init_structure.Pull = GPIO_NOPULL; |
arostm | 0:4af3ca173992 | 917 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
arostm | 0:4af3ca173992 | 918 | gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; |
arostm | 0:4af3ca173992 | 919 | HAL_GPIO_Init(LCD_RESET_GPIO_PORT, &gpio_init_structure); |
arostm | 0:4af3ca173992 | 920 | |
arostm | 0:4af3ca173992 | 921 | /* LCD_TE GPIO configuration */ |
arostm | 0:4af3ca173992 | 922 | gpio_init_structure.Pin = LCD_TE_PIN; /* LCD_TE pin has to be manually managed */ |
arostm | 0:4af3ca173992 | 923 | gpio_init_structure.Mode = GPIO_MODE_INPUT; |
arostm | 0:4af3ca173992 | 924 | HAL_GPIO_Init(LCD_TE_GPIO_PORT, &gpio_init_structure); |
arostm | 0:4af3ca173992 | 925 | |
arostm | 0:4af3ca173992 | 926 | /* LCD_BL_CTRL GPIO configuration */ |
arostm | 0:4af3ca173992 | 927 | gpio_init_structure.Pin = LCD_BL_CTRL_PIN; /* LCD_BL_CTRL pin has to be manually controlled */ |
arostm | 0:4af3ca173992 | 928 | gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP; |
arostm | 0:4af3ca173992 | 929 | HAL_GPIO_Init(LCD_BL_CTRL_GPIO_PORT, &gpio_init_structure); |
arostm | 0:4af3ca173992 | 930 | } |
arostm | 0:4af3ca173992 | 931 | |
arostm | 0:4af3ca173992 | 932 | /** |
arostm | 0:4af3ca173992 | 933 | * @brief DeInitializes LCD GPIO special pins MSP. |
arostm | 0:4af3ca173992 | 934 | */ |
arostm | 0:4af3ca173992 | 935 | __weak void BSP_LCD_MspDeInit(void) |
arostm | 0:4af3ca173992 | 936 | { |
arostm | 0:4af3ca173992 | 937 | GPIO_InitTypeDef gpio_init_structure; |
arostm | 0:4af3ca173992 | 938 | |
arostm | 0:4af3ca173992 | 939 | /* LCD_RESET GPIO deactivation */ |
arostm | 0:4af3ca173992 | 940 | gpio_init_structure.Pin = LCD_RESET_PIN; |
arostm | 0:4af3ca173992 | 941 | HAL_GPIO_DeInit(LCD_RESET_GPIO_PORT, gpio_init_structure.Pin); |
arostm | 0:4af3ca173992 | 942 | |
arostm | 0:4af3ca173992 | 943 | /* LCD_TE GPIO deactivation */ |
arostm | 0:4af3ca173992 | 944 | gpio_init_structure.Pin = LCD_TE_PIN; |
arostm | 0:4af3ca173992 | 945 | HAL_GPIO_DeInit(LCD_TE_GPIO_PORT, gpio_init_structure.Pin); |
arostm | 0:4af3ca173992 | 946 | |
arostm | 0:4af3ca173992 | 947 | /* LCD_BL_CTRL GPIO deactivation */ |
arostm | 0:4af3ca173992 | 948 | gpio_init_structure.Pin = LCD_BL_CTRL_PIN; |
arostm | 0:4af3ca173992 | 949 | HAL_GPIO_DeInit(LCD_BL_CTRL_GPIO_PORT, gpio_init_structure.Pin); |
arostm | 0:4af3ca173992 | 950 | |
arostm | 0:4af3ca173992 | 951 | /* GPIO pins clock can be shut down in the application |
arostm | 0:4af3ca173992 | 952 | by surcharging this __weak function */ |
arostm | 0:4af3ca173992 | 953 | } |
arostm | 0:4af3ca173992 | 954 | |
arostm | 0:4af3ca173992 | 955 | /** |
arostm | 0:4af3ca173992 | 956 | * @} |
arostm | 0:4af3ca173992 | 957 | */ |
arostm | 0:4af3ca173992 | 958 | /****************************************************************************** |
arostm | 0:4af3ca173992 | 959 | Static Functions |
arostm | 0:4af3ca173992 | 960 | *******************************************************************************/ |
arostm | 0:4af3ca173992 | 961 | /** @addtogroup STM32F413H_DISCOVERY_LCD_Private_FunctionPrototypes |
arostm | 0:4af3ca173992 | 962 | * @{ |
arostm | 0:4af3ca173992 | 963 | */ |
arostm | 0:4af3ca173992 | 964 | |
arostm | 0:4af3ca173992 | 965 | /** |
arostm | 0:4af3ca173992 | 966 | * @brief Draws a character on LCD. |
arostm | 0:4af3ca173992 | 967 | * @param Xpos: Line where to display the character shape |
arostm | 0:4af3ca173992 | 968 | * @param Ypos: Start column address |
arostm | 0:4af3ca173992 | 969 | * @param c: Pointer to the character data |
arostm | 0:4af3ca173992 | 970 | */ |
arostm | 0:4af3ca173992 | 971 | static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c) |
arostm | 0:4af3ca173992 | 972 | { |
arostm | 0:4af3ca173992 | 973 | uint32_t i = 0, j = 0; |
arostm | 0:4af3ca173992 | 974 | uint16_t height, width; |
arostm | 0:4af3ca173992 | 975 | uint8_t offset; |
arostm | 0:4af3ca173992 | 976 | uint8_t *pchar; |
arostm | 0:4af3ca173992 | 977 | uint32_t line; |
arostm | 0:4af3ca173992 | 978 | |
arostm | 0:4af3ca173992 | 979 | height = DrawProp.pFont->Height; |
arostm | 0:4af3ca173992 | 980 | width = DrawProp.pFont->Width; |
arostm | 0:4af3ca173992 | 981 | |
arostm | 0:4af3ca173992 | 982 | offset = 8 *((width + 7)/8) - width ; |
arostm | 0:4af3ca173992 | 983 | |
arostm | 0:4af3ca173992 | 984 | for(i = 0; i < height; i++) |
arostm | 0:4af3ca173992 | 985 | { |
arostm | 0:4af3ca173992 | 986 | pchar = ((uint8_t *)c + (width + 7)/8 * i); |
arostm | 0:4af3ca173992 | 987 | |
arostm | 0:4af3ca173992 | 988 | switch(((width + 7)/8)) |
arostm | 0:4af3ca173992 | 989 | { |
arostm | 0:4af3ca173992 | 990 | case 1: |
arostm | 0:4af3ca173992 | 991 | line = pchar[0]; |
arostm | 0:4af3ca173992 | 992 | break; |
arostm | 0:4af3ca173992 | 993 | |
arostm | 0:4af3ca173992 | 994 | case 2: |
arostm | 0:4af3ca173992 | 995 | line = (pchar[0]<< 8) | pchar[1]; |
arostm | 0:4af3ca173992 | 996 | break; |
arostm | 0:4af3ca173992 | 997 | |
arostm | 0:4af3ca173992 | 998 | case 3: |
arostm | 0:4af3ca173992 | 999 | default: |
arostm | 0:4af3ca173992 | 1000 | line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2]; |
arostm | 0:4af3ca173992 | 1001 | break; |
arostm | 0:4af3ca173992 | 1002 | } |
arostm | 0:4af3ca173992 | 1003 | |
arostm | 0:4af3ca173992 | 1004 | for (j = 0; j < width; j++) |
arostm | 0:4af3ca173992 | 1005 | { |
arostm | 0:4af3ca173992 | 1006 | if(line & (1 << (width- j + offset- 1))) |
arostm | 0:4af3ca173992 | 1007 | { |
arostm | 0:4af3ca173992 | 1008 | BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.TextColor); |
arostm | 0:4af3ca173992 | 1009 | } |
arostm | 0:4af3ca173992 | 1010 | else |
arostm | 0:4af3ca173992 | 1011 | { |
arostm | 0:4af3ca173992 | 1012 | BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp.BackColor); |
arostm | 0:4af3ca173992 | 1013 | } |
arostm | 0:4af3ca173992 | 1014 | } |
arostm | 0:4af3ca173992 | 1015 | Ypos++; |
arostm | 0:4af3ca173992 | 1016 | } |
arostm | 0:4af3ca173992 | 1017 | } |
arostm | 0:4af3ca173992 | 1018 | |
arostm | 0:4af3ca173992 | 1019 | /** |
arostm | 0:4af3ca173992 | 1020 | * @brief Sets display window. |
arostm | 0:4af3ca173992 | 1021 | * @param Xpos: LCD X position |
arostm | 0:4af3ca173992 | 1022 | * @param Ypos: LCD Y position |
arostm | 0:4af3ca173992 | 1023 | * @param Width: LCD window width |
arostm | 0:4af3ca173992 | 1024 | * @param Height: LCD window height |
arostm | 0:4af3ca173992 | 1025 | */ |
arostm | 0:4af3ca173992 | 1026 | static void SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) |
arostm | 0:4af3ca173992 | 1027 | { |
arostm | 0:4af3ca173992 | 1028 | if(LcdDrv->SetDisplayWindow != NULL) |
arostm | 0:4af3ca173992 | 1029 | { |
arostm | 0:4af3ca173992 | 1030 | LcdDrv->SetDisplayWindow(Xpos, Ypos, Width, Height); |
arostm | 0:4af3ca173992 | 1031 | } |
arostm | 0:4af3ca173992 | 1032 | } |
arostm | 0:4af3ca173992 | 1033 | |
arostm | 0:4af3ca173992 | 1034 | /** |
arostm | 0:4af3ca173992 | 1035 | * @brief Fills a triangle (between 3 points). |
arostm | 0:4af3ca173992 | 1036 | * @param x1: Point 1 X position |
arostm | 0:4af3ca173992 | 1037 | * @param y1: Point 1 Y position |
arostm | 0:4af3ca173992 | 1038 | * @param x2: Point 2 X position |
arostm | 0:4af3ca173992 | 1039 | * @param y2: Point 2 Y position |
arostm | 0:4af3ca173992 | 1040 | * @param x3: Point 3 X position |
arostm | 0:4af3ca173992 | 1041 | * @param y3: Point 3 Y position |
arostm | 0:4af3ca173992 | 1042 | */ |
arostm | 0:4af3ca173992 | 1043 | static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3) |
arostm | 0:4af3ca173992 | 1044 | { |
arostm | 0:4af3ca173992 | 1045 | int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, |
arostm | 0:4af3ca173992 | 1046 | yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, |
arostm | 0:4af3ca173992 | 1047 | curpixel = 0; |
arostm | 0:4af3ca173992 | 1048 | |
arostm | 0:4af3ca173992 | 1049 | deltax = ABS(x2 - x1); /* The difference between the x's */ |
arostm | 0:4af3ca173992 | 1050 | deltay = ABS(y2 - y1); /* The difference between the y's */ |
arostm | 0:4af3ca173992 | 1051 | x = x1; /* Start x off at the first pixel */ |
arostm | 0:4af3ca173992 | 1052 | y = y1; /* Start y off at the first pixel */ |
arostm | 0:4af3ca173992 | 1053 | |
arostm | 0:4af3ca173992 | 1054 | if (x2 >= x1) /* The x-values are increasing */ |
arostm | 0:4af3ca173992 | 1055 | { |
arostm | 0:4af3ca173992 | 1056 | xinc1 = 1; |
arostm | 0:4af3ca173992 | 1057 | xinc2 = 1; |
arostm | 0:4af3ca173992 | 1058 | } |
arostm | 0:4af3ca173992 | 1059 | else /* The x-values are decreasing */ |
arostm | 0:4af3ca173992 | 1060 | { |
arostm | 0:4af3ca173992 | 1061 | xinc1 = -1; |
arostm | 0:4af3ca173992 | 1062 | xinc2 = -1; |
arostm | 0:4af3ca173992 | 1063 | } |
arostm | 0:4af3ca173992 | 1064 | |
arostm | 0:4af3ca173992 | 1065 | if (y2 >= y1) /* The y-values are increasing */ |
arostm | 0:4af3ca173992 | 1066 | { |
arostm | 0:4af3ca173992 | 1067 | yinc1 = 1; |
arostm | 0:4af3ca173992 | 1068 | yinc2 = 1; |
arostm | 0:4af3ca173992 | 1069 | } |
arostm | 0:4af3ca173992 | 1070 | else /* The y-values are decreasing */ |
arostm | 0:4af3ca173992 | 1071 | { |
arostm | 0:4af3ca173992 | 1072 | yinc1 = -1; |
arostm | 0:4af3ca173992 | 1073 | yinc2 = -1; |
arostm | 0:4af3ca173992 | 1074 | } |
arostm | 0:4af3ca173992 | 1075 | |
arostm | 0:4af3ca173992 | 1076 | if (deltax >= deltay) /* There is at least one x-value for every y-value */ |
arostm | 0:4af3ca173992 | 1077 | { |
arostm | 0:4af3ca173992 | 1078 | xinc1 = 0; /* Don't change the x when numerator >= denominator */ |
arostm | 0:4af3ca173992 | 1079 | yinc2 = 0; /* Don't change the y for every iteration */ |
arostm | 0:4af3ca173992 | 1080 | den = deltax; |
arostm | 0:4af3ca173992 | 1081 | num = deltax / 2; |
arostm | 0:4af3ca173992 | 1082 | numadd = deltay; |
arostm | 0:4af3ca173992 | 1083 | numpixels = deltax; /* There are more x-values than y-values */ |
arostm | 0:4af3ca173992 | 1084 | } |
arostm | 0:4af3ca173992 | 1085 | else /* There is at least one y-value for every x-value */ |
arostm | 0:4af3ca173992 | 1086 | { |
arostm | 0:4af3ca173992 | 1087 | xinc2 = 0; /* Don't change the x for every iteration */ |
arostm | 0:4af3ca173992 | 1088 | yinc1 = 0; /* Don't change the y when numerator >= denominator */ |
arostm | 0:4af3ca173992 | 1089 | den = deltay; |
arostm | 0:4af3ca173992 | 1090 | num = deltay / 2; |
arostm | 0:4af3ca173992 | 1091 | numadd = deltax; |
arostm | 0:4af3ca173992 | 1092 | numpixels = deltay; /* There are more y-values than x-values */ |
arostm | 0:4af3ca173992 | 1093 | } |
arostm | 0:4af3ca173992 | 1094 | |
arostm | 0:4af3ca173992 | 1095 | for (curpixel = 0; curpixel <= numpixels; curpixel++) |
arostm | 0:4af3ca173992 | 1096 | { |
arostm | 0:4af3ca173992 | 1097 | BSP_LCD_DrawLine(x, y, x3, y3); |
arostm | 0:4af3ca173992 | 1098 | |
arostm | 0:4af3ca173992 | 1099 | num += numadd; /* Increase the numerator by the top of the fraction */ |
arostm | 0:4af3ca173992 | 1100 | if (num >= den) /* Check if numerator >= denominator */ |
arostm | 0:4af3ca173992 | 1101 | { |
arostm | 0:4af3ca173992 | 1102 | num -= den; /* Calculate the new numerator value */ |
arostm | 0:4af3ca173992 | 1103 | x += xinc1; /* Change the x as appropriate */ |
arostm | 0:4af3ca173992 | 1104 | y += yinc1; /* Change the y as appropriate */ |
arostm | 0:4af3ca173992 | 1105 | } |
arostm | 0:4af3ca173992 | 1106 | x += xinc2; /* Change the x as appropriate */ |
arostm | 0:4af3ca173992 | 1107 | y += yinc2; /* Change the y as appropriate */ |
arostm | 0:4af3ca173992 | 1108 | } |
arostm | 0:4af3ca173992 | 1109 | } |
arostm | 0:4af3ca173992 | 1110 | |
arostm | 0:4af3ca173992 | 1111 | /** |
arostm | 0:4af3ca173992 | 1112 | * @} |
arostm | 0:4af3ca173992 | 1113 | */ |
arostm | 0:4af3ca173992 | 1114 | |
arostm | 0:4af3ca173992 | 1115 | /** |
arostm | 0:4af3ca173992 | 1116 | * @} |
arostm | 0:4af3ca173992 | 1117 | */ |
arostm | 0:4af3ca173992 | 1118 | |
arostm | 0:4af3ca173992 | 1119 | /** |
arostm | 0:4af3ca173992 | 1120 | * @} |
arostm | 0:4af3ca173992 | 1121 | */ |
arostm | 0:4af3ca173992 | 1122 | |
arostm | 0:4af3ca173992 | 1123 | /** |
arostm | 0:4af3ca173992 | 1124 | * @} |
arostm | 0:4af3ca173992 | 1125 | */ |
arostm | 0:4af3ca173992 | 1126 | |
arostm | 0:4af3ca173992 | 1127 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |