STM32Cube BSP FW for STM32F769I-Discovery

Dependents:   mbed-os-example-blinky-5 DISCO-F769NI_TOUCHSCREEN_demo_custom_1 Datarecorder2 DISCO-F769NI_TOUCHSCREEN_demo ... more

Committer:
Jerome Coutant
Date:
Thu Jul 06 16:48:52 2017 +0200
Revision:
3:145e714557cf
Parent:
1:3e58f8a39705
Child:
4:72a949940ad6
Child:
6:05b81d60cdae
replace HAL_Delay by wait_ms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jerome Coutant 3:145e714557cf 1 /**
Jerome Coutant 0:c0f3bbab73d2 2 ******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 3 * @file stm32f769i_discovery_lcd.c
Jerome Coutant 0:c0f3bbab73d2 4 * @author MCD Application Team
Jerome Coutant 1:3e58f8a39705 5 * @version V2.0.0
Jerome Coutant 1:3e58f8a39705 6 * @date 30-December-2016
Jerome Coutant 0:c0f3bbab73d2 7 * @brief This file includes the driver for Liquid Crystal Display (LCD) module
Jerome Coutant 0:c0f3bbab73d2 8 * mounted on STM32F769I-DISCOVERY board.
Jerome Coutant 0:c0f3bbab73d2 9 ******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 10 * @attention
Jerome Coutant 0:c0f3bbab73d2 11 *
Jerome Coutant 0:c0f3bbab73d2 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
Jerome Coutant 0:c0f3bbab73d2 13 *
Jerome Coutant 0:c0f3bbab73d2 14 * Redistribution and use in source and binary forms, with or without modification,
Jerome Coutant 0:c0f3bbab73d2 15 * are permitted provided that the following conditions are met:
Jerome Coutant 0:c0f3bbab73d2 16 * 1. Redistributions of source code must retain the above copyright notice,
Jerome Coutant 0:c0f3bbab73d2 17 * this list of conditions and the following disclaimer.
Jerome Coutant 0:c0f3bbab73d2 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Jerome Coutant 0:c0f3bbab73d2 19 * this list of conditions and the following disclaimer in the documentation
Jerome Coutant 0:c0f3bbab73d2 20 * and/or other materials provided with the distribution.
Jerome Coutant 0:c0f3bbab73d2 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Jerome Coutant 0:c0f3bbab73d2 22 * may be used to endorse or promote products derived from this software
Jerome Coutant 0:c0f3bbab73d2 23 * without specific prior written permission.
Jerome Coutant 0:c0f3bbab73d2 24 *
Jerome Coutant 0:c0f3bbab73d2 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Jerome Coutant 0:c0f3bbab73d2 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Jerome Coutant 0:c0f3bbab73d2 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Jerome Coutant 0:c0f3bbab73d2 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Jerome Coutant 0:c0f3bbab73d2 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Jerome Coutant 0:c0f3bbab73d2 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Jerome Coutant 0:c0f3bbab73d2 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Jerome Coutant 0:c0f3bbab73d2 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Jerome Coutant 0:c0f3bbab73d2 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Jerome Coutant 0:c0f3bbab73d2 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jerome Coutant 0:c0f3bbab73d2 35 *
Jerome Coutant 0:c0f3bbab73d2 36 ******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 37 */
Jerome Coutant 0:c0f3bbab73d2 38
Jerome Coutant 0:c0f3bbab73d2 39 /* File Info: ------------------------------------------------------------------
Jerome Coutant 0:c0f3bbab73d2 40 User NOTES
Jerome Coutant 0:c0f3bbab73d2 41 1. How To use this driver:
Jerome Coutant 0:c0f3bbab73d2 42 --------------------------
Jerome Coutant 0:c0f3bbab73d2 43 - This driver is used to drive directly in video mode a LCD TFT using the DSI interface.
Jerome Coutant 0:c0f3bbab73d2 44 The following IPs are implied : DSI Host IP block working
Jerome Coutant 0:c0f3bbab73d2 45 in conjunction to the LTDC controller.
Jerome Coutant 0:c0f3bbab73d2 46 - This driver is linked by construction to LCD KoD mounted on board MB1166.
Jerome Coutant 0:c0f3bbab73d2 47
Jerome Coutant 0:c0f3bbab73d2 48 2. Driver description:
Jerome Coutant 0:c0f3bbab73d2 49 ---------------------
Jerome Coutant 0:c0f3bbab73d2 50 + Initialization steps:
Jerome Coutant 0:c0f3bbab73d2 51 o Initialize the LCD using the BSP_LCD_Init() function.
Jerome Coutant 0:c0f3bbab73d2 52 o Select the LCD layer to be used using the BSP_LCD_SelectLayer() function.
Jerome Coutant 0:c0f3bbab73d2 53 o Enable the LCD display using the BSP_LCD_DisplayOn() function.
Jerome Coutant 0:c0f3bbab73d2 54
Jerome Coutant 0:c0f3bbab73d2 55 + Options
Jerome Coutant 0:c0f3bbab73d2 56 o Configure and enable the color keying functionality using the
Jerome Coutant 0:c0f3bbab73d2 57 BSP_LCD_SetColorKeying() function.
Jerome Coutant 0:c0f3bbab73d2 58 o Modify in the fly the transparency and/or the frame buffer address
Jerome Coutant 0:c0f3bbab73d2 59 using the following functions:
Jerome Coutant 0:c0f3bbab73d2 60 - BSP_LCD_SetTransparency()
Jerome Coutant 0:c0f3bbab73d2 61 - BSP_LCD_SetLayerAddress()
Jerome Coutant 0:c0f3bbab73d2 62
Jerome Coutant 0:c0f3bbab73d2 63 + Display on LCD
Jerome Coutant 0:c0f3bbab73d2 64 o Clear the whole LCD using BSP_LCD_Clear() function or only one specified string
Jerome Coutant 0:c0f3bbab73d2 65 line using the BSP_LCD_ClearStringLine() function.
Jerome Coutant 0:c0f3bbab73d2 66 o Display a character on the specified line and column using the BSP_LCD_DisplayChar()
Jerome Coutant 0:c0f3bbab73d2 67 function or a complete string line using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 0:c0f3bbab73d2 68 o Display a string line on the specified position (x,y in pixel) and align mode
Jerome Coutant 0:c0f3bbab73d2 69 using the BSP_LCD_DisplayStringAtLine() function.
Jerome Coutant 0:c0f3bbab73d2 70 o Draw and fill a basic shapes (dot, line, rectangle, circle, ellipse, .. bitmap)
Jerome Coutant 0:c0f3bbab73d2 71 on LCD using the available set of functions.
Jerome Coutant 0:c0f3bbab73d2 72
Jerome Coutant 0:c0f3bbab73d2 73 ------------------------------------------------------------------------------*/
Jerome Coutant 0:c0f3bbab73d2 74
Jerome Coutant 0:c0f3bbab73d2 75 /* Includes ------------------------------------------------------------------*/
Jerome Coutant 0:c0f3bbab73d2 76 #include "stm32f769i_discovery_lcd.h"
Jerome Coutant 3:145e714557cf 77 #include "mbed_wait_api.h" // MBED: replace HAL_Delay by wait_ms
Jerome Coutant 0:c0f3bbab73d2 78 #include "../../../Utilities/Fonts/fonts.h"
Jerome Coutant 0:c0f3bbab73d2 79 //#include "../../../Utilities/Fonts/font24.c" // patch for MBED
Jerome Coutant 0:c0f3bbab73d2 80 //#include "../../../Utilities/Fonts/font20.c" // patch for MBED
Jerome Coutant 0:c0f3bbab73d2 81 //#include "../../../Utilities/Fonts/font16.c" // patch for MBED
Jerome Coutant 0:c0f3bbab73d2 82 //#include "../../../Utilities/Fonts/font12.c" // patch for MBED
Jerome Coutant 0:c0f3bbab73d2 83 //#include "../../../Utilities/Fonts/font8.c" // patch for MBED
Jerome Coutant 0:c0f3bbab73d2 84
Jerome Coutant 0:c0f3bbab73d2 85 /** @addtogroup BSP
Jerome Coutant 0:c0f3bbab73d2 86 * @{
Jerome Coutant 0:c0f3bbab73d2 87 */
Jerome Coutant 0:c0f3bbab73d2 88
Jerome Coutant 1:3e58f8a39705 89 /** @addtogroup STM32F769I_DISCOVERY
Jerome Coutant 0:c0f3bbab73d2 90 * @{
Jerome Coutant 0:c0f3bbab73d2 91 */
Jerome Coutant 0:c0f3bbab73d2 92
Jerome Coutant 1:3e58f8a39705 93 /** @defgroup STM32F769I_DISCOVERY_LCD STM32F769I_DISCOVERY LCD
Jerome Coutant 0:c0f3bbab73d2 94 * @{
Jerome Coutant 0:c0f3bbab73d2 95 */
Jerome Coutant 0:c0f3bbab73d2 96
Jerome Coutant 1:3e58f8a39705 97 /** @defgroup STM32F769I_DISCOVERY_LCD_Private_Defines LCD Private Defines
Jerome Coutant 0:c0f3bbab73d2 98 * @{
Jerome Coutant 0:c0f3bbab73d2 99 */
Jerome Coutant 0:c0f3bbab73d2 100 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 101 #define HDMI_ASPECT_RATIO_16_9 ADV7533_ASPECT_RATIO_16_9
Jerome Coutant 0:c0f3bbab73d2 102 #define HDMI_ASPECT_RATIO_4_3 ADV7533_ASPECT_RATIO_4_3
Jerome Coutant 0:c0f3bbab73d2 103 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 104 #define LCD_DSI_ID 0x11
Jerome Coutant 0:c0f3bbab73d2 105 #define LCD_DSI_ADDRESS TS_I2C_ADDRESS
Jerome Coutant 0:c0f3bbab73d2 106 #define LCD_DSI_ID_REG 0xA8
Jerome Coutant 0:c0f3bbab73d2 107
Jerome Coutant 0:c0f3bbab73d2 108 static DSI_VidCfgTypeDef hdsivideo_handle;
Jerome Coutant 0:c0f3bbab73d2 109 /**
Jerome Coutant 0:c0f3bbab73d2 110 * @}
Jerome Coutant 0:c0f3bbab73d2 111 */
Jerome Coutant 0:c0f3bbab73d2 112
Jerome Coutant 1:3e58f8a39705 113 /** @defgroup STM32F769I_DISCOVERY_LCD_Private_TypesDefinitions LCD Private TypesDefinitions
Jerome Coutant 0:c0f3bbab73d2 114 * @{
Jerome Coutant 0:c0f3bbab73d2 115 */
Jerome Coutant 0:c0f3bbab73d2 116 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 117 /**
Jerome Coutant 0:c0f3bbab73d2 118 * @brief DSI timming params used for different HDMI adpater
Jerome Coutant 0:c0f3bbab73d2 119 */
Jerome Coutant 0:c0f3bbab73d2 120 typedef struct
Jerome Coutant 0:c0f3bbab73d2 121 {
Jerome Coutant 0:c0f3bbab73d2 122 uint16_t HACT;
Jerome Coutant 0:c0f3bbab73d2 123 uint16_t HSYNC;
Jerome Coutant 0:c0f3bbab73d2 124 uint16_t HBP;
Jerome Coutant 0:c0f3bbab73d2 125 uint16_t HFP;
Jerome Coutant 0:c0f3bbab73d2 126 uint16_t VACT;
Jerome Coutant 0:c0f3bbab73d2 127 uint16_t VSYNC;
Jerome Coutant 0:c0f3bbab73d2 128 uint16_t VBP;
Jerome Coutant 0:c0f3bbab73d2 129 uint16_t VFP;
Jerome Coutant 0:c0f3bbab73d2 130 uint8_t ASPECT_RATIO;
Jerome Coutant 0:c0f3bbab73d2 131 uint8_t RGB_CODING;
Jerome Coutant 0:c0f3bbab73d2 132 } HDMI_FormatTypeDef;
Jerome Coutant 0:c0f3bbab73d2 133
Jerome Coutant 0:c0f3bbab73d2 134 /**
Jerome Coutant 0:c0f3bbab73d2 135 * @brief DSI packet params used for different HDMI adpater
Jerome Coutant 0:c0f3bbab73d2 136 */
Jerome Coutant 0:c0f3bbab73d2 137 typedef struct
Jerome Coutant 0:c0f3bbab73d2 138 {
Jerome Coutant 0:c0f3bbab73d2 139 uint16_t NullPacketSize;
Jerome Coutant 0:c0f3bbab73d2 140 uint16_t NumberOfChunks;
Jerome Coutant 0:c0f3bbab73d2 141 uint16_t PacketSize;
Jerome Coutant 0:c0f3bbab73d2 142 } HDMI_DSIPacketTypeDef;
Jerome Coutant 0:c0f3bbab73d2 143
Jerome Coutant 0:c0f3bbab73d2 144 /**
Jerome Coutant 0:c0f3bbab73d2 145 * @brief LTDC PLL params used for different HDMI adpater
Jerome Coutant 0:c0f3bbab73d2 146 */
Jerome Coutant 0:c0f3bbab73d2 147 typedef struct
Jerome Coutant 0:c0f3bbab73d2 148 {
Jerome Coutant 0:c0f3bbab73d2 149 uint16_t PLLSAIN;
Jerome Coutant 0:c0f3bbab73d2 150 uint16_t PLLSAIR;
Jerome Coutant 0:c0f3bbab73d2 151 uint32_t PCLK;
Jerome Coutant 0:c0f3bbab73d2 152 uint16_t IDF;
Jerome Coutant 0:c0f3bbab73d2 153 uint16_t NDIV;
Jerome Coutant 0:c0f3bbab73d2 154 uint16_t ODF;
Jerome Coutant 0:c0f3bbab73d2 155 uint16_t LaneByteClock;
Jerome Coutant 0:c0f3bbab73d2 156 uint16_t TXEscapeCkdiv;
Jerome Coutant 0:c0f3bbab73d2 157 } HDMI_PLLConfigTypeDef;
Jerome Coutant 0:c0f3bbab73d2 158 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 159 /**
Jerome Coutant 0:c0f3bbab73d2 160 * @}
Jerome Coutant 0:c0f3bbab73d2 161 */
Jerome Coutant 0:c0f3bbab73d2 162
Jerome Coutant 0:c0f3bbab73d2 163
Jerome Coutant 0:c0f3bbab73d2 164
Jerome Coutant 1:3e58f8a39705 165 /** @defgroup STM32F769I_DISCOVERY_LCD_Private_Macros LCD Private Macros
Jerome Coutant 0:c0f3bbab73d2 166 * @{
Jerome Coutant 0:c0f3bbab73d2 167 */
Jerome Coutant 0:c0f3bbab73d2 168 #define ABS(X) ((X) > 0 ? (X) : -(X))
Jerome Coutant 0:c0f3bbab73d2 169
Jerome Coutant 0:c0f3bbab73d2 170 #define POLY_X(Z) ((int32_t)((Points + (Z))->X))
Jerome Coutant 0:c0f3bbab73d2 171 #define POLY_Y(Z) ((int32_t)((Points + (Z))->Y))
Jerome Coutant 0:c0f3bbab73d2 172 /**
Jerome Coutant 0:c0f3bbab73d2 173 * @}
Jerome Coutant 0:c0f3bbab73d2 174 */
Jerome Coutant 0:c0f3bbab73d2 175
Jerome Coutant 1:3e58f8a39705 176 /** @defgroup STM32F769I_DISCOVERY_LCD_Exported_Variables STM32F769I DISCOVERY LCD Exported Variables
Jerome Coutant 0:c0f3bbab73d2 177 * @{
Jerome Coutant 0:c0f3bbab73d2 178 */
Jerome Coutant 0:c0f3bbab73d2 179 DMA2D_HandleTypeDef hdma2d_discovery;
Jerome Coutant 0:c0f3bbab73d2 180 LTDC_HandleTypeDef hltdc_discovery;
Jerome Coutant 0:c0f3bbab73d2 181 DSI_HandleTypeDef hdsi_discovery;
Jerome Coutant 0:c0f3bbab73d2 182 uint32_t lcd_x_size = OTM8009A_800X480_WIDTH;
Jerome Coutant 0:c0f3bbab73d2 183 uint32_t lcd_y_size = OTM8009A_800X480_HEIGHT;
Jerome Coutant 0:c0f3bbab73d2 184 /**
Jerome Coutant 0:c0f3bbab73d2 185 * @}
Jerome Coutant 0:c0f3bbab73d2 186 */
Jerome Coutant 0:c0f3bbab73d2 187
Jerome Coutant 0:c0f3bbab73d2 188
Jerome Coutant 1:3e58f8a39705 189 /** @defgroup STM32F769I_DISCOVERY_LCD_Private_Variables LCD Private Variables
Jerome Coutant 0:c0f3bbab73d2 190 * @{
Jerome Coutant 0:c0f3bbab73d2 191 */
Jerome Coutant 0:c0f3bbab73d2 192 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 193 /**
Jerome Coutant 0:c0f3bbab73d2 194 * @brief DSI timming used for different HDMI resolution (720x480 and 720x576)
Jerome Coutant 0:c0f3bbab73d2 195 */
Jerome Coutant 0:c0f3bbab73d2 196 HDMI_FormatTypeDef HDMI_Format[2] =
Jerome Coutant 0:c0f3bbab73d2 197 {
Jerome Coutant 0:c0f3bbab73d2 198 /* HA HS HB HF VA VS VB VF ASPECT BPP */
Jerome Coutant 0:c0f3bbab73d2 199 {720, 62, 60, 30, 480, 6, 19, 9, HDMI_ASPECT_RATIO_4_3, LCD_DSI_PIXEL_DATA_FMT_RBG888},
Jerome Coutant 0:c0f3bbab73d2 200 {720, 64, 68, 12, 576, 5, 39, 5, HDMI_ASPECT_RATIO_16_9, LCD_DSI_PIXEL_DATA_FMT_RBG888}
Jerome Coutant 0:c0f3bbab73d2 201
Jerome Coutant 0:c0f3bbab73d2 202 };
Jerome Coutant 0:c0f3bbab73d2 203
Jerome Coutant 0:c0f3bbab73d2 204 /**
Jerome Coutant 0:c0f3bbab73d2 205 * @brief DSI packet size used for different HDMI resolution (720x480 and 720x576)
Jerome Coutant 0:c0f3bbab73d2 206 */
Jerome Coutant 0:c0f3bbab73d2 207 HDMI_DSIPacketTypeDef HDMI_DSIPacket[2] =
Jerome Coutant 0:c0f3bbab73d2 208 {
Jerome Coutant 0:c0f3bbab73d2 209 /* NP NC VP */
Jerome Coutant 0:c0f3bbab73d2 210 {0, 1, 720},
Jerome Coutant 0:c0f3bbab73d2 211 {0, 1, 720}
Jerome Coutant 0:c0f3bbab73d2 212 };
Jerome Coutant 0:c0f3bbab73d2 213
Jerome Coutant 0:c0f3bbab73d2 214 /**
Jerome Coutant 0:c0f3bbab73d2 215 * @brief LTDC PLL settings used for different HDMI resolution (720x480 and 720x576)
Jerome Coutant 0:c0f3bbab73d2 216 */
Jerome Coutant 0:c0f3bbab73d2 217 HDMI_PLLConfigTypeDef HDMI_PLLConfig[4] =
Jerome Coutant 0:c0f3bbab73d2 218 {
Jerome Coutant 0:c0f3bbab73d2 219 /* N DIV Pclk IDF NDIV ODF LBClk TXEscapeCkdiv*/
Jerome Coutant 0:c0f3bbab73d2 220 {325, 6, 27083, DSI_PLL_IN_DIV5, 65, DSI_PLL_OUT_DIV1, 40625, 3},
Jerome Coutant 0:c0f3bbab73d2 221 {325, 6, 27083, DSI_PLL_IN_DIV5, 65, DSI_PLL_OUT_DIV1, 40625, 3}
Jerome Coutant 0:c0f3bbab73d2 222
Jerome Coutant 0:c0f3bbab73d2 223 };
Jerome Coutant 0:c0f3bbab73d2 224 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 225 /**
Jerome Coutant 0:c0f3bbab73d2 226 * @brief Default Active LTDC Layer in which drawing is made is LTDC Layer Background
Jerome Coutant 0:c0f3bbab73d2 227 */
Jerome Coutant 0:c0f3bbab73d2 228 static uint32_t ActiveLayer = LTDC_ACTIVE_LAYER_BACKGROUND;
Jerome Coutant 0:c0f3bbab73d2 229
Jerome Coutant 0:c0f3bbab73d2 230 /**
Jerome Coutant 0:c0f3bbab73d2 231 * @brief Current Drawing Layer properties variable
Jerome Coutant 0:c0f3bbab73d2 232 */
Jerome Coutant 0:c0f3bbab73d2 233 static LCD_DrawPropTypeDef DrawProp[LTDC_MAX_LAYER_NUMBER];
Jerome Coutant 0:c0f3bbab73d2 234 /**
Jerome Coutant 0:c0f3bbab73d2 235 * @}
Jerome Coutant 0:c0f3bbab73d2 236 */
Jerome Coutant 0:c0f3bbab73d2 237
Jerome Coutant 1:3e58f8a39705 238 /** @defgroup STM32F769I_DISCOVERY_LCD_Private_FunctionPrototypes LCD Private FunctionPrototypes
Jerome Coutant 0:c0f3bbab73d2 239 * @{
Jerome Coutant 0:c0f3bbab73d2 240 */
Jerome Coutant 0:c0f3bbab73d2 241 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c);
Jerome Coutant 0:c0f3bbab73d2 242 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3);
Jerome Coutant 0:c0f3bbab73d2 243 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex);
Jerome Coutant 0:c0f3bbab73d2 244 static void LL_ConvertLineToARGB8888(void * pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode);
Jerome Coutant 0:c0f3bbab73d2 245 static uint16_t LCD_IO_GetID(void);
Jerome Coutant 0:c0f3bbab73d2 246 /**
Jerome Coutant 0:c0f3bbab73d2 247 * @}
Jerome Coutant 0:c0f3bbab73d2 248 */
Jerome Coutant 0:c0f3bbab73d2 249
Jerome Coutant 1:3e58f8a39705 250 /** @defgroup STM32F769I_DISCOVERY_LCD_Exported_Functions LCD Exported Functions
Jerome Coutant 0:c0f3bbab73d2 251 * @{
Jerome Coutant 0:c0f3bbab73d2 252 */
Jerome Coutant 0:c0f3bbab73d2 253
Jerome Coutant 0:c0f3bbab73d2 254 /**
Jerome Coutant 0:c0f3bbab73d2 255 * @brief Initializes the DSI LCD.
Jerome Coutant 0:c0f3bbab73d2 256 * @retval LCD state
Jerome Coutant 0:c0f3bbab73d2 257 */
Jerome Coutant 0:c0f3bbab73d2 258 uint8_t BSP_LCD_Init(void)
Jerome Coutant 0:c0f3bbab73d2 259 {
Jerome Coutant 0:c0f3bbab73d2 260 return (BSP_LCD_InitEx(LCD_ORIENTATION_LANDSCAPE));
Jerome Coutant 0:c0f3bbab73d2 261 }
Jerome Coutant 0:c0f3bbab73d2 262
Jerome Coutant 0:c0f3bbab73d2 263 /**
Jerome Coutant 0:c0f3bbab73d2 264 * @brief Initializes the DSI LCD.
Jerome Coutant 0:c0f3bbab73d2 265 * The ititialization is done as below:
Jerome Coutant 0:c0f3bbab73d2 266 * - DSI PLL ititialization
Jerome Coutant 0:c0f3bbab73d2 267 * - DSI ititialization
Jerome Coutant 0:c0f3bbab73d2 268 * - LTDC ititialization
Jerome Coutant 0:c0f3bbab73d2 269 * - OTM8009A LCD Display IC Driver ititialization
Jerome Coutant 1:3e58f8a39705 270 * @param orientation: LCD orientation, can be LCD_ORIENTATION_PORTRAIT or LCD_ORIENTATION_LANDSCAPE
Jerome Coutant 0:c0f3bbab73d2 271 * @retval LCD state
Jerome Coutant 0:c0f3bbab73d2 272 */
Jerome Coutant 0:c0f3bbab73d2 273 uint8_t BSP_LCD_InitEx(LCD_OrientationTypeDef orientation)
Jerome Coutant 0:c0f3bbab73d2 274 {
Jerome Coutant 0:c0f3bbab73d2 275 DSI_PLLInitTypeDef dsiPllInit;
Jerome Coutant 0:c0f3bbab73d2 276 static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
Jerome Coutant 0:c0f3bbab73d2 277 uint32_t LcdClock = 27429; /*!< LcdClk = 27429 kHz */
Jerome Coutant 0:c0f3bbab73d2 278 uint16_t read_id = 0;
Jerome Coutant 0:c0f3bbab73d2 279
Jerome Coutant 0:c0f3bbab73d2 280 uint32_t laneByteClk_kHz = 0;
Jerome Coutant 0:c0f3bbab73d2 281 uint32_t VSA; /*!< Vertical start active time in units of lines */
Jerome Coutant 0:c0f3bbab73d2 282 uint32_t VBP; /*!< Vertical Back Porch time in units of lines */
Jerome Coutant 0:c0f3bbab73d2 283 uint32_t VFP; /*!< Vertical Front Porch time in units of lines */
Jerome Coutant 0:c0f3bbab73d2 284 uint32_t VACT; /*!< Vertical Active time in units of lines = imageSize Y in pixels to display */
Jerome Coutant 0:c0f3bbab73d2 285 uint32_t HSA; /*!< Horizontal start active time in units of lcdClk */
Jerome Coutant 0:c0f3bbab73d2 286 uint32_t HBP; /*!< Horizontal Back Porch time in units of lcdClk */
Jerome Coutant 0:c0f3bbab73d2 287 uint32_t HFP; /*!< Horizontal Front Porch time in units of lcdClk */
Jerome Coutant 0:c0f3bbab73d2 288 uint32_t HACT; /*!< Horizontal Active time in units of lcdClk = imageSize X in pixels to display */
Jerome Coutant 0:c0f3bbab73d2 289
Jerome Coutant 0:c0f3bbab73d2 290 /* Toggle Hardware Reset of the DSI LCD using
Jerome Coutant 0:c0f3bbab73d2 291 * its XRES signal (active low) */
Jerome Coutant 0:c0f3bbab73d2 292 BSP_LCD_Reset();
Jerome Coutant 0:c0f3bbab73d2 293
Jerome Coutant 0:c0f3bbab73d2 294 /* Check the connected monitor */
Jerome Coutant 0:c0f3bbab73d2 295 read_id = LCD_IO_GetID();
Jerome Coutant 0:c0f3bbab73d2 296
Jerome Coutant 0:c0f3bbab73d2 297 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 298 if(read_id == ADV7533_ID)
Jerome Coutant 0:c0f3bbab73d2 299 {
Jerome Coutant 0:c0f3bbab73d2 300 return BSP_LCD_HDMIInitEx(HDMI_FORMAT_720_576);
Jerome Coutant 0:c0f3bbab73d2 301 }
Jerome Coutant 0:c0f3bbab73d2 302 else if(read_id != LCD_DSI_ID)
Jerome Coutant 0:c0f3bbab73d2 303 {
Jerome Coutant 0:c0f3bbab73d2 304 return LCD_ERROR;
Jerome Coutant 0:c0f3bbab73d2 305 }
Jerome Coutant 0:c0f3bbab73d2 306 #else
Jerome Coutant 0:c0f3bbab73d2 307 if(read_id != LCD_DSI_ID)
Jerome Coutant 0:c0f3bbab73d2 308 {
Jerome Coutant 0:c0f3bbab73d2 309 return LCD_ERROR;
Jerome Coutant 0:c0f3bbab73d2 310 }
Jerome Coutant 0:c0f3bbab73d2 311 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 312
Jerome Coutant 0:c0f3bbab73d2 313 /* Call first MSP Initialize only in case of first initialization
Jerome Coutant 0:c0f3bbab73d2 314 * This will set IP blocks LTDC, DSI and DMA2D
Jerome Coutant 0:c0f3bbab73d2 315 * - out of reset
Jerome Coutant 0:c0f3bbab73d2 316 * - clocked
Jerome Coutant 0:c0f3bbab73d2 317 * - NVIC IRQ related to IP blocks enabled
Jerome Coutant 0:c0f3bbab73d2 318 */
Jerome Coutant 0:c0f3bbab73d2 319 BSP_LCD_MspInit();
Jerome Coutant 0:c0f3bbab73d2 320
Jerome Coutant 0:c0f3bbab73d2 321 /*************************DSI Initialization***********************************/
Jerome Coutant 0:c0f3bbab73d2 322
Jerome Coutant 0:c0f3bbab73d2 323 /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
Jerome Coutant 0:c0f3bbab73d2 324 hdsi_discovery.Instance = DSI;
Jerome Coutant 0:c0f3bbab73d2 325
Jerome Coutant 0:c0f3bbab73d2 326 HAL_DSI_DeInit(&(hdsi_discovery));
Jerome Coutant 0:c0f3bbab73d2 327
Jerome Coutant 0:c0f3bbab73d2 328 dsiPllInit.PLLNDIV = 100;
Jerome Coutant 0:c0f3bbab73d2 329 dsiPllInit.PLLIDF = DSI_PLL_IN_DIV5;
Jerome Coutant 0:c0f3bbab73d2 330 dsiPllInit.PLLODF = DSI_PLL_OUT_DIV1;
Jerome Coutant 0:c0f3bbab73d2 331 laneByteClk_kHz = 62500; /* 500 MHz / 8 = 62.5 MHz = 62500 kHz */
Jerome Coutant 0:c0f3bbab73d2 332
Jerome Coutant 0:c0f3bbab73d2 333 /* Set number of Lanes */
Jerome Coutant 0:c0f3bbab73d2 334 hdsi_discovery.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
Jerome Coutant 0:c0f3bbab73d2 335
Jerome Coutant 0:c0f3bbab73d2 336 /* TXEscapeCkdiv = f(LaneByteClk)/15.62 = 4 */
Jerome Coutant 0:c0f3bbab73d2 337 hdsi_discovery.Init.TXEscapeCkdiv = laneByteClk_kHz/15620;
Jerome Coutant 0:c0f3bbab73d2 338
Jerome Coutant 0:c0f3bbab73d2 339 HAL_DSI_Init(&(hdsi_discovery), &(dsiPllInit));
Jerome Coutant 0:c0f3bbab73d2 340
Jerome Coutant 0:c0f3bbab73d2 341 /* Timing parameters for all Video modes
Jerome Coutant 0:c0f3bbab73d2 342 * Set Timing parameters of LTDC depending on its chosen orientation
Jerome Coutant 0:c0f3bbab73d2 343 */
Jerome Coutant 0:c0f3bbab73d2 344 if(orientation == LCD_ORIENTATION_PORTRAIT)
Jerome Coutant 0:c0f3bbab73d2 345 {
Jerome Coutant 0:c0f3bbab73d2 346 lcd_x_size = OTM8009A_480X800_WIDTH; /* 480 */
Jerome Coutant 0:c0f3bbab73d2 347 lcd_y_size = OTM8009A_480X800_HEIGHT; /* 800 */
Jerome Coutant 0:c0f3bbab73d2 348 }
Jerome Coutant 0:c0f3bbab73d2 349 else
Jerome Coutant 0:c0f3bbab73d2 350 {
Jerome Coutant 0:c0f3bbab73d2 351 /* lcd_orientation == LCD_ORIENTATION_LANDSCAPE */
Jerome Coutant 0:c0f3bbab73d2 352 lcd_x_size = OTM8009A_800X480_WIDTH; /* 800 */
Jerome Coutant 0:c0f3bbab73d2 353 lcd_y_size = OTM8009A_800X480_HEIGHT; /* 480 */
Jerome Coutant 0:c0f3bbab73d2 354 }
Jerome Coutant 0:c0f3bbab73d2 355
Jerome Coutant 0:c0f3bbab73d2 356 HACT = lcd_x_size;
Jerome Coutant 0:c0f3bbab73d2 357 VACT = lcd_y_size;
Jerome Coutant 0:c0f3bbab73d2 358
Jerome Coutant 0:c0f3bbab73d2 359 /* The following values are same for portrait and landscape orientations */
Jerome Coutant 0:c0f3bbab73d2 360 VSA = OTM8009A_480X800_VSYNC; /* 12 */
Jerome Coutant 0:c0f3bbab73d2 361 VBP = OTM8009A_480X800_VBP; /* 12 */
Jerome Coutant 0:c0f3bbab73d2 362 VFP = OTM8009A_480X800_VFP; /* 12 */
Jerome Coutant 0:c0f3bbab73d2 363 HSA = OTM8009A_480X800_HSYNC; /* 63 */
Jerome Coutant 0:c0f3bbab73d2 364 HBP = OTM8009A_480X800_HBP; /* 120 */
Jerome Coutant 0:c0f3bbab73d2 365 HFP = OTM8009A_480X800_HFP; /* 120 */
Jerome Coutant 0:c0f3bbab73d2 366
Jerome Coutant 0:c0f3bbab73d2 367 hdsivideo_handle.VirtualChannelID = LCD_OTM8009A_ID;
Jerome Coutant 0:c0f3bbab73d2 368 hdsivideo_handle.ColorCoding = LCD_DSI_PIXEL_DATA_FMT_RBG888;
Jerome Coutant 0:c0f3bbab73d2 369 hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_HIGH;
Jerome Coutant 0:c0f3bbab73d2 370 hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_HIGH;
Jerome Coutant 0:c0f3bbab73d2 371 hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
Jerome Coutant 0:c0f3bbab73d2 372 hdsivideo_handle.Mode = DSI_VID_MODE_BURST; /* Mode Video burst ie : one LgP per line */
Jerome Coutant 0:c0f3bbab73d2 373 hdsivideo_handle.NullPacketSize = 0xFFF;
Jerome Coutant 0:c0f3bbab73d2 374 hdsivideo_handle.NumberOfChunks = 0;
Jerome Coutant 0:c0f3bbab73d2 375 hdsivideo_handle.PacketSize = HACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 0:c0f3bbab73d2 376 hdsivideo_handle.HorizontalSyncActive = (HSA * laneByteClk_kHz)/LcdClock;
Jerome Coutant 0:c0f3bbab73d2 377 hdsivideo_handle.HorizontalBackPorch = (HBP * laneByteClk_kHz)/LcdClock;
Jerome Coutant 0:c0f3bbab73d2 378 hdsivideo_handle.HorizontalLine = ((HACT + HSA + HBP + HFP) * laneByteClk_kHz)/LcdClock; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 0:c0f3bbab73d2 379 hdsivideo_handle.VerticalSyncActive = VSA;
Jerome Coutant 0:c0f3bbab73d2 380 hdsivideo_handle.VerticalBackPorch = VBP;
Jerome Coutant 0:c0f3bbab73d2 381 hdsivideo_handle.VerticalFrontPorch = VFP;
Jerome Coutant 0:c0f3bbab73d2 382 hdsivideo_handle.VerticalActive = VACT; /* Value depending on display orientation choice portrait/landscape */
Jerome Coutant 0:c0f3bbab73d2 383
Jerome Coutant 0:c0f3bbab73d2 384 /* Enable or disable sending LP command while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 385 hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_ENABLE; /* Enable sending commands in mode LP (Low Power) */
Jerome Coutant 0:c0f3bbab73d2 386
Jerome Coutant 0:c0f3bbab73d2 387 /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
Jerome Coutant 0:c0f3bbab73d2 388 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 389 hdsivideo_handle.LPLargestPacketSize = 16;
Jerome Coutant 0:c0f3bbab73d2 390
Jerome Coutant 0:c0f3bbab73d2 391 /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
Jerome Coutant 0:c0f3bbab73d2 392 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 393 hdsivideo_handle.LPVACTLargestPacketSize = 0;
Jerome Coutant 0:c0f3bbab73d2 394
Jerome Coutant 0:c0f3bbab73d2 395 /* Specify for each region of the video frame, if the transmission of command in LP mode is allowed in this region */
Jerome Coutant 0:c0f3bbab73d2 396 /* while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 397 hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_ENABLE; /* Allow sending LP commands during HFP period */
Jerome Coutant 0:c0f3bbab73d2 398 hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_ENABLE; /* Allow sending LP commands during HBP period */
Jerome Coutant 0:c0f3bbab73d2 399 hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_ENABLE; /* Allow sending LP commands during VACT period */
Jerome Coutant 0:c0f3bbab73d2 400 hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_ENABLE; /* Allow sending LP commands during VFP period */
Jerome Coutant 0:c0f3bbab73d2 401 hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_ENABLE; /* Allow sending LP commands during VBP period */
Jerome Coutant 0:c0f3bbab73d2 402 hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_ENABLE; /* Allow sending LP commands during VSync = VSA period */
Jerome Coutant 0:c0f3bbab73d2 403
Jerome Coutant 0:c0f3bbab73d2 404 /* Configure DSI Video mode timings with settings set above */
Jerome Coutant 0:c0f3bbab73d2 405 HAL_DSI_ConfigVideoMode(&(hdsi_discovery), &(hdsivideo_handle));
Jerome Coutant 0:c0f3bbab73d2 406
Jerome Coutant 0:c0f3bbab73d2 407 /*************************End DSI Initialization*******************************/
Jerome Coutant 0:c0f3bbab73d2 408
Jerome Coutant 0:c0f3bbab73d2 409
Jerome Coutant 0:c0f3bbab73d2 410 /************************LTDC Initialization***********************************/
Jerome Coutant 0:c0f3bbab73d2 411
Jerome Coutant 0:c0f3bbab73d2 412 /* Timing Configuration */
Jerome Coutant 0:c0f3bbab73d2 413 hltdc_discovery.Init.HorizontalSync = (HSA - 1);
Jerome Coutant 0:c0f3bbab73d2 414 hltdc_discovery.Init.AccumulatedHBP = (HSA + HBP - 1);
Jerome Coutant 0:c0f3bbab73d2 415 hltdc_discovery.Init.AccumulatedActiveW = (lcd_x_size + HSA + HBP - 1);
Jerome Coutant 0:c0f3bbab73d2 416 hltdc_discovery.Init.TotalWidth = (lcd_x_size + HSA + HBP + HFP - 1);
Jerome Coutant 0:c0f3bbab73d2 417
Jerome Coutant 0:c0f3bbab73d2 418 /* Initialize the LCD pixel width and pixel height */
Jerome Coutant 0:c0f3bbab73d2 419 hltdc_discovery.LayerCfg->ImageWidth = lcd_x_size;
Jerome Coutant 0:c0f3bbab73d2 420 hltdc_discovery.LayerCfg->ImageHeight = lcd_y_size;
Jerome Coutant 0:c0f3bbab73d2 421
Jerome Coutant 0:c0f3bbab73d2 422 /** LCD clock configuration
Jerome Coutant 0:c0f3bbab73d2 423 * Note: The following values should not be changed as the PLLSAI is also used
Jerome Coutant 0:c0f3bbab73d2 424 * to clock the USB FS
Jerome Coutant 0:c0f3bbab73d2 425 * PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz
Jerome Coutant 0:c0f3bbab73d2 426 * PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 384 Mhz
Jerome Coutant 0:c0f3bbab73d2 427 * PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 384 MHz / 7 = 54.85 MHz
Jerome Coutant 0:c0f3bbab73d2 428 * LTDC clock frequency = PLLLCDCLK / LTDC_PLLSAI_DIVR_2 = 54.85 MHz / 2 = 27.429 MHz
Jerome Coutant 0:c0f3bbab73d2 429 */
Jerome Coutant 0:c0f3bbab73d2 430 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
Jerome Coutant 0:c0f3bbab73d2 431 PeriphClkInitStruct.PLLSAI.PLLSAIN = 384;
Jerome Coutant 0:c0f3bbab73d2 432 PeriphClkInitStruct.PLLSAI.PLLSAIR = 7;
Jerome Coutant 0:c0f3bbab73d2 433 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
Jerome Coutant 0:c0f3bbab73d2 434 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
Jerome Coutant 0:c0f3bbab73d2 435
Jerome Coutant 0:c0f3bbab73d2 436 /* Background value */
Jerome Coutant 0:c0f3bbab73d2 437 hltdc_discovery.Init.Backcolor.Blue = 0;
Jerome Coutant 0:c0f3bbab73d2 438 hltdc_discovery.Init.Backcolor.Green = 0;
Jerome Coutant 0:c0f3bbab73d2 439 hltdc_discovery.Init.Backcolor.Red = 0;
Jerome Coutant 0:c0f3bbab73d2 440 hltdc_discovery.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
Jerome Coutant 0:c0f3bbab73d2 441 hltdc_discovery.Instance = LTDC;
Jerome Coutant 0:c0f3bbab73d2 442
Jerome Coutant 0:c0f3bbab73d2 443 /* Get LTDC Configuration from DSI Configuration */
Jerome Coutant 0:c0f3bbab73d2 444 HAL_LTDC_StructInitFromVideoConfig(&(hltdc_discovery), &(hdsivideo_handle));
Jerome Coutant 0:c0f3bbab73d2 445
Jerome Coutant 0:c0f3bbab73d2 446 /* Initialize the LTDC */
Jerome Coutant 0:c0f3bbab73d2 447 HAL_LTDC_Init(&hltdc_discovery);
Jerome Coutant 0:c0f3bbab73d2 448
Jerome Coutant 0:c0f3bbab73d2 449 /* Enable the DSI host and wrapper after the LTDC initialization
Jerome Coutant 0:c0f3bbab73d2 450 To avoid any synchronization issue, the DSI shall be started after enabling the LTDC */
Jerome Coutant 0:c0f3bbab73d2 451 HAL_DSI_Start(&hdsi_discovery);
Jerome Coutant 0:c0f3bbab73d2 452
Jerome Coutant 0:c0f3bbab73d2 453 #if !defined(DATA_IN_ExtSDRAM)
Jerome Coutant 0:c0f3bbab73d2 454 /* Initialize the SDRAM */
Jerome Coutant 0:c0f3bbab73d2 455 BSP_SDRAM_Init();
Jerome Coutant 0:c0f3bbab73d2 456 #endif /* DATA_IN_ExtSDRAM */
Jerome Coutant 0:c0f3bbab73d2 457
Jerome Coutant 0:c0f3bbab73d2 458 /* Initialize the font */
Jerome Coutant 0:c0f3bbab73d2 459 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
Jerome Coutant 0:c0f3bbab73d2 460
Jerome Coutant 0:c0f3bbab73d2 461 /************************End LTDC Initialization*******************************/
Jerome Coutant 0:c0f3bbab73d2 462
Jerome Coutant 0:c0f3bbab73d2 463
Jerome Coutant 0:c0f3bbab73d2 464 /***********************OTM8009A Initialization********************************/
Jerome Coutant 0:c0f3bbab73d2 465
Jerome Coutant 0:c0f3bbab73d2 466 /* Initialize the OTM8009A LCD Display IC Driver (KoD LCD IC Driver)
Jerome Coutant 0:c0f3bbab73d2 467 * depending on configuration set in 'hdsivideo_handle'.
Jerome Coutant 0:c0f3bbab73d2 468 */
Jerome Coutant 0:c0f3bbab73d2 469 OTM8009A_Init(OTM8009A_FORMAT_RGB888, orientation);
Jerome Coutant 0:c0f3bbab73d2 470
Jerome Coutant 0:c0f3bbab73d2 471 /***********************End OTM8009A Initialization****************************/
Jerome Coutant 0:c0f3bbab73d2 472
Jerome Coutant 0:c0f3bbab73d2 473 return LCD_OK;
Jerome Coutant 0:c0f3bbab73d2 474 }
Jerome Coutant 0:c0f3bbab73d2 475
Jerome Coutant 0:c0f3bbab73d2 476 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 477 /**
Jerome Coutant 0:c0f3bbab73d2 478 * @brief Initializes the DSI for HDMI monitor.
Jerome Coutant 0:c0f3bbab73d2 479 * The ititialization is done as below:
Jerome Coutant 0:c0f3bbab73d2 480 * - DSI PLL ititialization
Jerome Coutant 0:c0f3bbab73d2 481 * - DSI ititialization
Jerome Coutant 0:c0f3bbab73d2 482 * - LTDC ititialization
Jerome Coutant 0:c0f3bbab73d2 483 * - DSI-HDMI ADV7533 adapter device ititialization
Jerome Coutant 0:c0f3bbab73d2 484 * @param format : HDMI format could be HDMI_FORMAT_720_480 or HDMI_FORMAT_720_576
Jerome Coutant 0:c0f3bbab73d2 485 * @retval LCD state
Jerome Coutant 0:c0f3bbab73d2 486 */
Jerome Coutant 0:c0f3bbab73d2 487 uint8_t BSP_LCD_HDMIInitEx(uint8_t format)
Jerome Coutant 0:c0f3bbab73d2 488 {
Jerome Coutant 0:c0f3bbab73d2 489 /************************ADV7533 Initialization********************************/
Jerome Coutant 0:c0f3bbab73d2 490
Jerome Coutant 0:c0f3bbab73d2 491 /* Initialize the ADV7533 HDMI Bridge
Jerome Coutant 0:c0f3bbab73d2 492 * depending on configuration set in 'hdsivideo_handle'.
Jerome Coutant 0:c0f3bbab73d2 493 */
Jerome Coutant 0:c0f3bbab73d2 494 adv7533ConfigTypeDef adv7533_config;
Jerome Coutant 0:c0f3bbab73d2 495
Jerome Coutant 0:c0f3bbab73d2 496 adv7533_config.DSI_LANES = 2;
Jerome Coutant 0:c0f3bbab73d2 497 adv7533_config.HACT = HDMI_Format[format].HACT;
Jerome Coutant 0:c0f3bbab73d2 498 adv7533_config.HSYNC = HDMI_Format[format].HSYNC;
Jerome Coutant 0:c0f3bbab73d2 499 adv7533_config.HBP = HDMI_Format[format].HBP;
Jerome Coutant 0:c0f3bbab73d2 500 adv7533_config.HFP = HDMI_Format[format].HFP;
Jerome Coutant 0:c0f3bbab73d2 501 adv7533_config.VACT = HDMI_Format[format].VACT;
Jerome Coutant 0:c0f3bbab73d2 502 adv7533_config.VSYNC = HDMI_Format[format].VSYNC;
Jerome Coutant 0:c0f3bbab73d2 503 adv7533_config.VBP = HDMI_Format[format].VBP;
Jerome Coutant 0:c0f3bbab73d2 504 adv7533_config.VFP = HDMI_Format[format].VFP;
Jerome Coutant 0:c0f3bbab73d2 505
Jerome Coutant 0:c0f3bbab73d2 506 ADV7533_Init();
Jerome Coutant 0:c0f3bbab73d2 507 ADV7533_Configure(&adv7533_config);
Jerome Coutant 0:c0f3bbab73d2 508 ADV7533_PowerOn();
Jerome Coutant 0:c0f3bbab73d2 509
Jerome Coutant 0:c0f3bbab73d2 510 /************************ Update hdmi_x_size and hdmi_y_size *****************/
Jerome Coutant 0:c0f3bbab73d2 511 lcd_x_size = HDMI_Format[format].HACT;
Jerome Coutant 0:c0f3bbab73d2 512 lcd_y_size = HDMI_Format[format].VACT;
Jerome Coutant 0:c0f3bbab73d2 513
Jerome Coutant 0:c0f3bbab73d2 514 /***********************End ADV7533 Initialization****************************/
Jerome Coutant 0:c0f3bbab73d2 515 DSI_PLLInitTypeDef dsiPllInit;
Jerome Coutant 0:c0f3bbab73d2 516 DSI_PHY_TimerTypeDef dsiPhyInit;
Jerome Coutant 0:c0f3bbab73d2 517 static RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
Jerome Coutant 0:c0f3bbab73d2 518
Jerome Coutant 0:c0f3bbab73d2 519 /* Call first MSP Initialize only in case of first initialization
Jerome Coutant 0:c0f3bbab73d2 520 * This will set IP blocks LTDC and DSI
Jerome Coutant 0:c0f3bbab73d2 521 * - out of reset
Jerome Coutant 0:c0f3bbab73d2 522 * - clocked
Jerome Coutant 0:c0f3bbab73d2 523 * - NVIC IRQ related to IP blocks enabled
Jerome Coutant 0:c0f3bbab73d2 524 */
Jerome Coutant 0:c0f3bbab73d2 525 BSP_LCD_MspInit();
Jerome Coutant 0:c0f3bbab73d2 526
Jerome Coutant 0:c0f3bbab73d2 527 /*************************DSI Initialization***********************************/
Jerome Coutant 0:c0f3bbab73d2 528
Jerome Coutant 0:c0f3bbab73d2 529 /* Base address of DSI Host/Wrapper registers to be set before calling De-Init */
Jerome Coutant 0:c0f3bbab73d2 530 hdsi_discovery.Instance = DSI;
Jerome Coutant 0:c0f3bbab73d2 531
Jerome Coutant 0:c0f3bbab73d2 532 HAL_DSI_DeInit(&(hdsi_discovery));
Jerome Coutant 0:c0f3bbab73d2 533
Jerome Coutant 0:c0f3bbab73d2 534 /* Configure the DSI PLL */
Jerome Coutant 0:c0f3bbab73d2 535 dsiPllInit.PLLNDIV = HDMI_PLLConfig[format].NDIV;
Jerome Coutant 0:c0f3bbab73d2 536 dsiPllInit.PLLIDF = HDMI_PLLConfig[format].IDF;
Jerome Coutant 0:c0f3bbab73d2 537 dsiPllInit.PLLODF = HDMI_PLLConfig[format].ODF;
Jerome Coutant 0:c0f3bbab73d2 538
Jerome Coutant 0:c0f3bbab73d2 539 /* Set number of Lanes */
Jerome Coutant 0:c0f3bbab73d2 540 hdsi_discovery.Init.NumberOfLanes = DSI_TWO_DATA_LANES;
Jerome Coutant 0:c0f3bbab73d2 541 /* Set the TX escape clock division ratio */
Jerome Coutant 0:c0f3bbab73d2 542 hdsi_discovery.Init.TXEscapeCkdiv = HDMI_PLLConfig[format].TXEscapeCkdiv;
Jerome Coutant 0:c0f3bbab73d2 543 /* Disable the automatic clock lane control (the ADV7533 must be clocked) */
Jerome Coutant 0:c0f3bbab73d2 544 hdsi_discovery.Init.AutomaticClockLaneControl = DSI_AUTO_CLK_LANE_CTRL_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 545
Jerome Coutant 0:c0f3bbab73d2 546 /* Init the DSI */
Jerome Coutant 0:c0f3bbab73d2 547 HAL_DSI_Init(&hdsi_discovery, &dsiPllInit);
Jerome Coutant 0:c0f3bbab73d2 548
Jerome Coutant 0:c0f3bbab73d2 549 /* Configure the D-PHY Timings */
Jerome Coutant 0:c0f3bbab73d2 550 dsiPhyInit.ClockLaneHS2LPTime = 0x14;
Jerome Coutant 0:c0f3bbab73d2 551 dsiPhyInit.ClockLaneLP2HSTime = 0x14;
Jerome Coutant 0:c0f3bbab73d2 552 dsiPhyInit.DataLaneHS2LPTime = 0x0A;
Jerome Coutant 0:c0f3bbab73d2 553 dsiPhyInit.DataLaneLP2HSTime = 0x0A;
Jerome Coutant 0:c0f3bbab73d2 554 dsiPhyInit.DataLaneMaxReadTime = 0x00;
Jerome Coutant 0:c0f3bbab73d2 555 dsiPhyInit.StopWaitTime = 0x0;
Jerome Coutant 0:c0f3bbab73d2 556 HAL_DSI_ConfigPhyTimer(&hdsi_discovery, &dsiPhyInit);
Jerome Coutant 0:c0f3bbab73d2 557
Jerome Coutant 0:c0f3bbab73d2 558 /* Virutal channel used by the ADV7533 */
Jerome Coutant 0:c0f3bbab73d2 559 hdsivideo_handle.VirtualChannelID = HDMI_ADV7533_ID;
Jerome Coutant 0:c0f3bbab73d2 560
Jerome Coutant 0:c0f3bbab73d2 561 /* Timing parameters for Video modes
Jerome Coutant 0:c0f3bbab73d2 562 Set Timing parameters of DSI depending on its chosen format */
Jerome Coutant 0:c0f3bbab73d2 563 hdsivideo_handle.ColorCoding = HDMI_Format[format].RGB_CODING;
Jerome Coutant 0:c0f3bbab73d2 564 hdsivideo_handle.LooselyPacked = DSI_LOOSELY_PACKED_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 565 hdsivideo_handle.VSPolarity = DSI_VSYNC_ACTIVE_LOW;
Jerome Coutant 0:c0f3bbab73d2 566 hdsivideo_handle.HSPolarity = DSI_HSYNC_ACTIVE_LOW;
Jerome Coutant 0:c0f3bbab73d2 567 hdsivideo_handle.DEPolarity = DSI_DATA_ENABLE_ACTIVE_HIGH;
Jerome Coutant 0:c0f3bbab73d2 568 hdsivideo_handle.Mode = DSI_VID_MODE_NB_PULSES;
Jerome Coutant 0:c0f3bbab73d2 569 hdsivideo_handle.NullPacketSize = HDMI_DSIPacket[format].NullPacketSize;
Jerome Coutant 0:c0f3bbab73d2 570 hdsivideo_handle.NumberOfChunks = HDMI_DSIPacket[format].NumberOfChunks;
Jerome Coutant 0:c0f3bbab73d2 571 hdsivideo_handle.PacketSize = HDMI_DSIPacket[format].PacketSize;
Jerome Coutant 0:c0f3bbab73d2 572 hdsivideo_handle.HorizontalSyncActive = HDMI_Format[format].HSYNC*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
Jerome Coutant 0:c0f3bbab73d2 573 hdsivideo_handle.HorizontalBackPorch = HDMI_Format[format].HBP*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
Jerome Coutant 0:c0f3bbab73d2 574 hdsivideo_handle.HorizontalLine = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP + HDMI_Format[format].HFP)*HDMI_PLLConfig[format].LaneByteClock/HDMI_PLLConfig[format].PCLK;
Jerome Coutant 0:c0f3bbab73d2 575 hdsivideo_handle.VerticalSyncActive = HDMI_Format[format].VSYNC;
Jerome Coutant 0:c0f3bbab73d2 576 hdsivideo_handle.VerticalBackPorch = HDMI_Format[format].VBP;
Jerome Coutant 0:c0f3bbab73d2 577 hdsivideo_handle.VerticalFrontPorch = HDMI_Format[format].VFP;
Jerome Coutant 0:c0f3bbab73d2 578 hdsivideo_handle.VerticalActive = HDMI_Format[format].VACT;
Jerome Coutant 0:c0f3bbab73d2 579
Jerome Coutant 0:c0f3bbab73d2 580 /* Enable or disable sending LP command while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 581 hdsivideo_handle.LPCommandEnable = DSI_LP_COMMAND_DISABLE; /* Enable sending commands in mode LP (Low Power) */
Jerome Coutant 0:c0f3bbab73d2 582
Jerome Coutant 0:c0f3bbab73d2 583 /* Largest packet size possible to transmit in LP mode in VSA, VBP, VFP regions */
Jerome Coutant 0:c0f3bbab73d2 584 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 585 hdsivideo_handle.LPLargestPacketSize = 4;
Jerome Coutant 0:c0f3bbab73d2 586
Jerome Coutant 0:c0f3bbab73d2 587 /* Largest packet size possible to transmit in LP mode in HFP region during VACT period */
Jerome Coutant 0:c0f3bbab73d2 588 /* Only useful when sending LP packets is allowed while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 589 hdsivideo_handle.LPVACTLargestPacketSize = 4;
Jerome Coutant 0:c0f3bbab73d2 590
Jerome Coutant 0:c0f3bbab73d2 591 /* Specify for each region, if the going in LP mode is allowed */
Jerome Coutant 0:c0f3bbab73d2 592 /* while streaming is active in video mode */
Jerome Coutant 0:c0f3bbab73d2 593 hdsivideo_handle.LPHorizontalFrontPorchEnable = DSI_LP_HFP_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 594 hdsivideo_handle.LPHorizontalBackPorchEnable = DSI_LP_HBP_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 595 hdsivideo_handle.LPVerticalActiveEnable = DSI_LP_VACT_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 596 hdsivideo_handle.LPVerticalFrontPorchEnable = DSI_LP_VFP_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 597 hdsivideo_handle.LPVerticalBackPorchEnable = DSI_LP_VBP_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 598 hdsivideo_handle.LPVerticalSyncActiveEnable = DSI_LP_VSYNC_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 599
Jerome Coutant 0:c0f3bbab73d2 600 /* No acknoledge at the end of a frame */
Jerome Coutant 0:c0f3bbab73d2 601 hdsivideo_handle.FrameBTAAcknowledgeEnable = DSI_FBTAA_DISABLE;
Jerome Coutant 0:c0f3bbab73d2 602
Jerome Coutant 0:c0f3bbab73d2 603 /* Configure DSI Video mode timings with settings set above */
Jerome Coutant 0:c0f3bbab73d2 604 HAL_DSI_ConfigVideoMode(&hdsi_discovery, &hdsivideo_handle);
Jerome Coutant 0:c0f3bbab73d2 605
Jerome Coutant 0:c0f3bbab73d2 606 /* Enable the DSI host and wrapper : but LTDC is not started yet at this stage */
Jerome Coutant 0:c0f3bbab73d2 607 HAL_DSI_Start(&hdsi_discovery);
Jerome Coutant 0:c0f3bbab73d2 608
Jerome Coutant 0:c0f3bbab73d2 609 /*************************End DSI Initialization*******************************/
Jerome Coutant 0:c0f3bbab73d2 610
Jerome Coutant 0:c0f3bbab73d2 611
Jerome Coutant 0:c0f3bbab73d2 612 /************************LTDC Initialization***********************************/
Jerome Coutant 0:c0f3bbab73d2 613
Jerome Coutant 0:c0f3bbab73d2 614 /* LTDC clock configuration */
Jerome Coutant 0:c0f3bbab73d2 615 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
Jerome Coutant 0:c0f3bbab73d2 616 PeriphClkInitStruct.PLLSAI.PLLSAIN = HDMI_PLLConfig[format].PLLSAIN;
Jerome Coutant 0:c0f3bbab73d2 617 PeriphClkInitStruct.PLLSAI.PLLSAIR = HDMI_PLLConfig[format].PLLSAIR;
Jerome Coutant 0:c0f3bbab73d2 618 PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
Jerome Coutant 0:c0f3bbab73d2 619 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
Jerome Coutant 0:c0f3bbab73d2 620
Jerome Coutant 0:c0f3bbab73d2 621 /* Base address of LTDC registers to be set before calling De-Init */
Jerome Coutant 0:c0f3bbab73d2 622 hltdc_discovery.Instance = LTDC;
Jerome Coutant 0:c0f3bbab73d2 623
Jerome Coutant 0:c0f3bbab73d2 624 HAL_LTDC_DeInit(&(hltdc_discovery));
Jerome Coutant 0:c0f3bbab73d2 625
Jerome Coutant 0:c0f3bbab73d2 626 /* Timing Configuration */
Jerome Coutant 0:c0f3bbab73d2 627 hltdc_discovery.Init.HorizontalSync = (HDMI_Format[format].HSYNC - 1);
Jerome Coutant 0:c0f3bbab73d2 628 hltdc_discovery.Init.AccumulatedHBP = (HDMI_Format[format].HSYNC + HDMI_Format[format].HBP - 1);
Jerome Coutant 0:c0f3bbab73d2 629 hltdc_discovery.Init.AccumulatedActiveW = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP - 1);
Jerome Coutant 0:c0f3bbab73d2 630 hltdc_discovery.Init.TotalWidth = (HDMI_Format[format].HACT + HDMI_Format[format].HSYNC + HDMI_Format[format].HBP + HDMI_Format[format].HFP - 1);
Jerome Coutant 0:c0f3bbab73d2 631 hltdc_discovery.Init.VerticalSync = (HDMI_Format[format].VSYNC - 1);
Jerome Coutant 0:c0f3bbab73d2 632 hltdc_discovery.Init.AccumulatedVBP = (HDMI_Format[format].VSYNC + HDMI_Format[format].VBP - 1);
Jerome Coutant 0:c0f3bbab73d2 633 hltdc_discovery.Init.AccumulatedActiveH = (HDMI_Format[format].VACT + HDMI_Format[format].VSYNC + HDMI_Format[format].VBP - 1);
Jerome Coutant 0:c0f3bbab73d2 634 hltdc_discovery.Init.TotalHeigh = (HDMI_Format[format].VACT + HDMI_Format[format].VSYNC + HDMI_Format[format].VBP + HDMI_Format[format].VFP - 1);
Jerome Coutant 0:c0f3bbab73d2 635
Jerome Coutant 0:c0f3bbab73d2 636 /* background value */
Jerome Coutant 0:c0f3bbab73d2 637 hltdc_discovery.Init.Backcolor.Blue = 0x00;
Jerome Coutant 0:c0f3bbab73d2 638 hltdc_discovery.Init.Backcolor.Green = 0xFF;
Jerome Coutant 0:c0f3bbab73d2 639 hltdc_discovery.Init.Backcolor.Red = 0xFF;
Jerome Coutant 0:c0f3bbab73d2 640
Jerome Coutant 0:c0f3bbab73d2 641 /* Polarity */
Jerome Coutant 0:c0f3bbab73d2 642 hltdc_discovery.Init.HSPolarity = LTDC_HSPOLARITY_AL;
Jerome Coutant 0:c0f3bbab73d2 643 hltdc_discovery.Init.VSPolarity = LTDC_VSPOLARITY_AL;
Jerome Coutant 0:c0f3bbab73d2 644 hltdc_discovery.Init.DEPolarity = LTDC_DEPOLARITY_AL;
Jerome Coutant 0:c0f3bbab73d2 645 hltdc_discovery.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
Jerome Coutant 0:c0f3bbab73d2 646
Jerome Coutant 0:c0f3bbab73d2 647 /* Initialize & Start the LTDC */
Jerome Coutant 0:c0f3bbab73d2 648 HAL_LTDC_Init(&hltdc_discovery);
Jerome Coutant 0:c0f3bbab73d2 649
Jerome Coutant 0:c0f3bbab73d2 650 #if !defined(DATA_IN_ExtSDRAM)
Jerome Coutant 0:c0f3bbab73d2 651 /* Initialize the SDRAM */
Jerome Coutant 0:c0f3bbab73d2 652 BSP_SDRAM_Init();
Jerome Coutant 0:c0f3bbab73d2 653 #endif /* DATA_IN_ExtSDRAM */
Jerome Coutant 0:c0f3bbab73d2 654
Jerome Coutant 0:c0f3bbab73d2 655 /* Initialize the font */
Jerome Coutant 0:c0f3bbab73d2 656 BSP_LCD_SetFont(&LCD_DEFAULT_FONT);
Jerome Coutant 0:c0f3bbab73d2 657 /************************End LTDC Initialization*******************************/
Jerome Coutant 0:c0f3bbab73d2 658
Jerome Coutant 0:c0f3bbab73d2 659 return LCD_OK;
Jerome Coutant 0:c0f3bbab73d2 660 }
Jerome Coutant 0:c0f3bbab73d2 661 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 662
Jerome Coutant 0:c0f3bbab73d2 663 /**
Jerome Coutant 0:c0f3bbab73d2 664 * @brief BSP LCD Reset
Jerome Coutant 0:c0f3bbab73d2 665 * Hw reset the LCD DSI activating its XRES signal (active low for some time)
Jerome Coutant 0:c0f3bbab73d2 666 * and desactivating it later.
Jerome Coutant 0:c0f3bbab73d2 667 */
Jerome Coutant 0:c0f3bbab73d2 668 void BSP_LCD_Reset(void)
Jerome Coutant 0:c0f3bbab73d2 669 {
Jerome Coutant 0:c0f3bbab73d2 670 GPIO_InitTypeDef gpio_init_structure;
Jerome Coutant 0:c0f3bbab73d2 671
Jerome Coutant 0:c0f3bbab73d2 672 __HAL_RCC_GPIOJ_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 673
Jerome Coutant 0:c0f3bbab73d2 674 /* Configure the GPIO on PJ15 */
Jerome Coutant 0:c0f3bbab73d2 675 gpio_init_structure.Pin = GPIO_PIN_15;
Jerome Coutant 0:c0f3bbab73d2 676 gpio_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
Jerome Coutant 0:c0f3bbab73d2 677 gpio_init_structure.Pull = GPIO_PULLUP;
Jerome Coutant 0:c0f3bbab73d2 678 gpio_init_structure.Speed = GPIO_SPEED_HIGH;
Jerome Coutant 0:c0f3bbab73d2 679
Jerome Coutant 0:c0f3bbab73d2 680 HAL_GPIO_Init(GPIOJ, &gpio_init_structure);
Jerome Coutant 0:c0f3bbab73d2 681
Jerome Coutant 0:c0f3bbab73d2 682 /* Activate XRES active low */
Jerome Coutant 0:c0f3bbab73d2 683 HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, GPIO_PIN_RESET);
Jerome Coutant 0:c0f3bbab73d2 684
Jerome Coutant 3:145e714557cf 685 wait_ms(20); /* wait 20 ms */
Jerome Coutant 0:c0f3bbab73d2 686
Jerome Coutant 0:c0f3bbab73d2 687 /* Desactivate XRES */
Jerome Coutant 0:c0f3bbab73d2 688 HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, GPIO_PIN_SET);
Jerome Coutant 0:c0f3bbab73d2 689
Jerome Coutant 0:c0f3bbab73d2 690 /* Wait for 10ms after releasing XRES before sending commands */
Jerome Coutant 3:145e714557cf 691 wait_ms(10);
Jerome Coutant 0:c0f3bbab73d2 692 }
Jerome Coutant 0:c0f3bbab73d2 693
Jerome Coutant 0:c0f3bbab73d2 694 /**
Jerome Coutant 0:c0f3bbab73d2 695 * @brief Gets the LCD X size.
Jerome Coutant 0:c0f3bbab73d2 696 * @retval Used LCD X size
Jerome Coutant 0:c0f3bbab73d2 697 */
Jerome Coutant 0:c0f3bbab73d2 698 uint32_t BSP_LCD_GetXSize(void)
Jerome Coutant 0:c0f3bbab73d2 699 {
Jerome Coutant 0:c0f3bbab73d2 700 return (lcd_x_size);
Jerome Coutant 0:c0f3bbab73d2 701 }
Jerome Coutant 0:c0f3bbab73d2 702
Jerome Coutant 0:c0f3bbab73d2 703 /**
Jerome Coutant 0:c0f3bbab73d2 704 * @brief Gets the LCD Y size.
Jerome Coutant 0:c0f3bbab73d2 705 * @retval Used LCD Y size
Jerome Coutant 0:c0f3bbab73d2 706 */
Jerome Coutant 0:c0f3bbab73d2 707 uint32_t BSP_LCD_GetYSize(void)
Jerome Coutant 0:c0f3bbab73d2 708 {
Jerome Coutant 0:c0f3bbab73d2 709 return (lcd_y_size);
Jerome Coutant 0:c0f3bbab73d2 710 }
Jerome Coutant 0:c0f3bbab73d2 711
Jerome Coutant 0:c0f3bbab73d2 712 /**
Jerome Coutant 0:c0f3bbab73d2 713 * @brief Set the LCD X size.
Jerome Coutant 0:c0f3bbab73d2 714 * @param imageWidthPixels : uint32_t image width in pixels unit
Jerome Coutant 0:c0f3bbab73d2 715 * @retval None
Jerome Coutant 0:c0f3bbab73d2 716 */
Jerome Coutant 0:c0f3bbab73d2 717 void BSP_LCD_SetXSize(uint32_t imageWidthPixels)
Jerome Coutant 0:c0f3bbab73d2 718 {
Jerome Coutant 0:c0f3bbab73d2 719 hltdc_discovery.LayerCfg[ActiveLayer].ImageWidth = imageWidthPixels;
Jerome Coutant 0:c0f3bbab73d2 720 }
Jerome Coutant 0:c0f3bbab73d2 721
Jerome Coutant 0:c0f3bbab73d2 722 /**
Jerome Coutant 0:c0f3bbab73d2 723 * @brief Set the LCD Y size.
Jerome Coutant 0:c0f3bbab73d2 724 * @param imageHeightPixels : uint32_t image height in lines unit
Jerome Coutant 0:c0f3bbab73d2 725 */
Jerome Coutant 0:c0f3bbab73d2 726 void BSP_LCD_SetYSize(uint32_t imageHeightPixels)
Jerome Coutant 0:c0f3bbab73d2 727 {
Jerome Coutant 0:c0f3bbab73d2 728 hltdc_discovery.LayerCfg[ActiveLayer].ImageHeight = imageHeightPixels;
Jerome Coutant 0:c0f3bbab73d2 729 }
Jerome Coutant 0:c0f3bbab73d2 730
Jerome Coutant 0:c0f3bbab73d2 731
Jerome Coutant 0:c0f3bbab73d2 732 /**
Jerome Coutant 0:c0f3bbab73d2 733 * @brief Initializes the LCD layers.
Jerome Coutant 0:c0f3bbab73d2 734 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:c0f3bbab73d2 735 * @param FB_Address: Layer frame buffer
Jerome Coutant 0:c0f3bbab73d2 736 * @retval None
Jerome Coutant 0:c0f3bbab73d2 737 */
Jerome Coutant 0:c0f3bbab73d2 738 void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address)
Jerome Coutant 0:c0f3bbab73d2 739 {
Jerome Coutant 0:c0f3bbab73d2 740 LCD_LayerCfgTypeDef Layercfg;
Jerome Coutant 0:c0f3bbab73d2 741
Jerome Coutant 0:c0f3bbab73d2 742 /* Layer Init */
Jerome Coutant 0:c0f3bbab73d2 743 Layercfg.WindowX0 = 0;
Jerome Coutant 0:c0f3bbab73d2 744 Layercfg.WindowX1 = BSP_LCD_GetXSize();
Jerome Coutant 0:c0f3bbab73d2 745 Layercfg.WindowY0 = 0;
Jerome Coutant 0:c0f3bbab73d2 746 Layercfg.WindowY1 = BSP_LCD_GetYSize();
Jerome Coutant 0:c0f3bbab73d2 747 Layercfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888;
Jerome Coutant 0:c0f3bbab73d2 748 Layercfg.FBStartAdress = FB_Address;
Jerome Coutant 0:c0f3bbab73d2 749 Layercfg.Alpha = 255;
Jerome Coutant 0:c0f3bbab73d2 750 Layercfg.Alpha0 = 0;
Jerome Coutant 0:c0f3bbab73d2 751 Layercfg.Backcolor.Blue = 0;
Jerome Coutant 0:c0f3bbab73d2 752 Layercfg.Backcolor.Green = 0;
Jerome Coutant 0:c0f3bbab73d2 753 Layercfg.Backcolor.Red = 0;
Jerome Coutant 0:c0f3bbab73d2 754 Layercfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
Jerome Coutant 0:c0f3bbab73d2 755 Layercfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;
Jerome Coutant 0:c0f3bbab73d2 756 Layercfg.ImageWidth = BSP_LCD_GetXSize();
Jerome Coutant 0:c0f3bbab73d2 757 Layercfg.ImageHeight = BSP_LCD_GetYSize();
Jerome Coutant 0:c0f3bbab73d2 758
Jerome Coutant 0:c0f3bbab73d2 759 HAL_LTDC_ConfigLayer(&hltdc_discovery, &Layercfg, LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 760
Jerome Coutant 0:c0f3bbab73d2 761 DrawProp[LayerIndex].BackColor = LCD_COLOR_WHITE;
Jerome Coutant 0:c0f3bbab73d2 762 DrawProp[LayerIndex].pFont = &Font24;
Jerome Coutant 0:c0f3bbab73d2 763 DrawProp[LayerIndex].TextColor = LCD_COLOR_BLACK;
Jerome Coutant 0:c0f3bbab73d2 764 }
Jerome Coutant 0:c0f3bbab73d2 765
Jerome Coutant 0:c0f3bbab73d2 766
Jerome Coutant 0:c0f3bbab73d2 767 /**
Jerome Coutant 0:c0f3bbab73d2 768 * @brief Selects the LCD Layer.
Jerome Coutant 0:c0f3bbab73d2 769 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:c0f3bbab73d2 770 */
Jerome Coutant 0:c0f3bbab73d2 771 void BSP_LCD_SelectLayer(uint32_t LayerIndex)
Jerome Coutant 0:c0f3bbab73d2 772 {
Jerome Coutant 0:c0f3bbab73d2 773 ActiveLayer = LayerIndex;
Jerome Coutant 0:c0f3bbab73d2 774 }
Jerome Coutant 0:c0f3bbab73d2 775
Jerome Coutant 0:c0f3bbab73d2 776 /**
Jerome Coutant 0:c0f3bbab73d2 777 * @brief Sets an LCD Layer visible
Jerome Coutant 0:c0f3bbab73d2 778 * @param LayerIndex: Visible Layer
Jerome Coutant 0:c0f3bbab73d2 779 * @param State: New state of the specified layer
Jerome Coutant 0:c0f3bbab73d2 780 * This parameter can be one of the following values:
Jerome Coutant 0:c0f3bbab73d2 781 * @arg ENABLE
Jerome Coutant 0:c0f3bbab73d2 782 * @arg DISABLE
Jerome Coutant 0:c0f3bbab73d2 783 */
Jerome Coutant 0:c0f3bbab73d2 784 void BSP_LCD_SetLayerVisible(uint32_t LayerIndex, FunctionalState State)
Jerome Coutant 0:c0f3bbab73d2 785 {
Jerome Coutant 0:c0f3bbab73d2 786 if(State == ENABLE)
Jerome Coutant 0:c0f3bbab73d2 787 {
Jerome Coutant 0:c0f3bbab73d2 788 __HAL_LTDC_LAYER_ENABLE(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 789 }
Jerome Coutant 0:c0f3bbab73d2 790 else
Jerome Coutant 0:c0f3bbab73d2 791 {
Jerome Coutant 0:c0f3bbab73d2 792 __HAL_LTDC_LAYER_DISABLE(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 793 }
Jerome Coutant 0:c0f3bbab73d2 794 __HAL_LTDC_RELOAD_CONFIG(&(hltdc_discovery));
Jerome Coutant 0:c0f3bbab73d2 795
Jerome Coutant 0:c0f3bbab73d2 796 }
Jerome Coutant 0:c0f3bbab73d2 797
Jerome Coutant 0:c0f3bbab73d2 798 /**
Jerome Coutant 0:c0f3bbab73d2 799 * @brief Configures the transparency.
Jerome Coutant 0:c0f3bbab73d2 800 * @param LayerIndex: Layer foreground or background.
Jerome Coutant 0:c0f3bbab73d2 801 * @param Transparency: Transparency
Jerome Coutant 0:c0f3bbab73d2 802 * This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF
Jerome Coutant 0:c0f3bbab73d2 803 */
Jerome Coutant 0:c0f3bbab73d2 804 void BSP_LCD_SetTransparency(uint32_t LayerIndex, uint8_t Transparency)
Jerome Coutant 0:c0f3bbab73d2 805 {
Jerome Coutant 0:c0f3bbab73d2 806
Jerome Coutant 0:c0f3bbab73d2 807 HAL_LTDC_SetAlpha(&(hltdc_discovery), Transparency, LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 808
Jerome Coutant 0:c0f3bbab73d2 809 }
Jerome Coutant 0:c0f3bbab73d2 810
Jerome Coutant 0:c0f3bbab73d2 811 /**
Jerome Coutant 0:c0f3bbab73d2 812 * @brief Sets an LCD layer frame buffer address.
Jerome Coutant 0:c0f3bbab73d2 813 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:c0f3bbab73d2 814 * @param Address: New LCD frame buffer value
Jerome Coutant 0:c0f3bbab73d2 815 */
Jerome Coutant 0:c0f3bbab73d2 816 void BSP_LCD_SetLayerAddress(uint32_t LayerIndex, uint32_t Address)
Jerome Coutant 0:c0f3bbab73d2 817 {
Jerome Coutant 0:c0f3bbab73d2 818
Jerome Coutant 0:c0f3bbab73d2 819 HAL_LTDC_SetAddress(&(hltdc_discovery), Address, LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 820
Jerome Coutant 0:c0f3bbab73d2 821 }
Jerome Coutant 0:c0f3bbab73d2 822
Jerome Coutant 0:c0f3bbab73d2 823 /**
Jerome Coutant 0:c0f3bbab73d2 824 * @brief Sets display window.
Jerome Coutant 0:c0f3bbab73d2 825 * @param LayerIndex: Layer index
Jerome Coutant 0:c0f3bbab73d2 826 * @param Xpos: LCD X position
Jerome Coutant 0:c0f3bbab73d2 827 * @param Ypos: LCD Y position
Jerome Coutant 0:c0f3bbab73d2 828 * @param Width: LCD window width
Jerome Coutant 0:c0f3bbab73d2 829 * @param Height: LCD window height
Jerome Coutant 0:c0f3bbab73d2 830 */
Jerome Coutant 0:c0f3bbab73d2 831 void BSP_LCD_SetLayerWindow(uint16_t LayerIndex, uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 0:c0f3bbab73d2 832 {
Jerome Coutant 0:c0f3bbab73d2 833 /* Reconfigure the layer size */
Jerome Coutant 0:c0f3bbab73d2 834 HAL_LTDC_SetWindowSize(&(hltdc_discovery), Width, Height, LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 835
Jerome Coutant 0:c0f3bbab73d2 836 /* Reconfigure the layer position */
Jerome Coutant 0:c0f3bbab73d2 837 HAL_LTDC_SetWindowPosition(&(hltdc_discovery), Xpos, Ypos, LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 838
Jerome Coutant 0:c0f3bbab73d2 839 }
Jerome Coutant 0:c0f3bbab73d2 840
Jerome Coutant 0:c0f3bbab73d2 841 /**
Jerome Coutant 0:c0f3bbab73d2 842 * @brief Configures and sets the color keying.
Jerome Coutant 0:c0f3bbab73d2 843 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:c0f3bbab73d2 844 * @param RGBValue: Color reference
Jerome Coutant 0:c0f3bbab73d2 845 */
Jerome Coutant 0:c0f3bbab73d2 846 void BSP_LCD_SetColorKeying(uint32_t LayerIndex, uint32_t RGBValue)
Jerome Coutant 0:c0f3bbab73d2 847 {
Jerome Coutant 0:c0f3bbab73d2 848 /* Configure and Enable the color Keying for LCD Layer */
Jerome Coutant 0:c0f3bbab73d2 849 HAL_LTDC_ConfigColorKeying(&(hltdc_discovery), RGBValue, LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 850 HAL_LTDC_EnableColorKeying(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 851 }
Jerome Coutant 0:c0f3bbab73d2 852
Jerome Coutant 0:c0f3bbab73d2 853 /**
Jerome Coutant 0:c0f3bbab73d2 854 * @brief Disables the color keying.
Jerome Coutant 0:c0f3bbab73d2 855 * @param LayerIndex: Layer foreground or background
Jerome Coutant 0:c0f3bbab73d2 856 */
Jerome Coutant 0:c0f3bbab73d2 857 void BSP_LCD_ResetColorKeying(uint32_t LayerIndex)
Jerome Coutant 0:c0f3bbab73d2 858 {
Jerome Coutant 0:c0f3bbab73d2 859 /* Disable the color Keying for LCD Layer */
Jerome Coutant 0:c0f3bbab73d2 860 HAL_LTDC_DisableColorKeying(&(hltdc_discovery), LayerIndex);
Jerome Coutant 0:c0f3bbab73d2 861 }
Jerome Coutant 0:c0f3bbab73d2 862
Jerome Coutant 0:c0f3bbab73d2 863 /**
Jerome Coutant 0:c0f3bbab73d2 864 * @brief Sets the LCD text color.
Jerome Coutant 0:c0f3bbab73d2 865 * @param Color: Text color code ARGB(8-8-8-8)
Jerome Coutant 0:c0f3bbab73d2 866 */
Jerome Coutant 0:c0f3bbab73d2 867 void BSP_LCD_SetTextColor(uint32_t Color)
Jerome Coutant 0:c0f3bbab73d2 868 {
Jerome Coutant 0:c0f3bbab73d2 869 DrawProp[ActiveLayer].TextColor = Color;
Jerome Coutant 0:c0f3bbab73d2 870 }
Jerome Coutant 0:c0f3bbab73d2 871
Jerome Coutant 0:c0f3bbab73d2 872 /**
Jerome Coutant 0:c0f3bbab73d2 873 * @brief Gets the LCD text color.
Jerome Coutant 0:c0f3bbab73d2 874 * @retval Used text color.
Jerome Coutant 0:c0f3bbab73d2 875 */
Jerome Coutant 0:c0f3bbab73d2 876 uint32_t BSP_LCD_GetTextColor(void)
Jerome Coutant 0:c0f3bbab73d2 877 {
Jerome Coutant 0:c0f3bbab73d2 878 return DrawProp[ActiveLayer].TextColor;
Jerome Coutant 0:c0f3bbab73d2 879 }
Jerome Coutant 0:c0f3bbab73d2 880
Jerome Coutant 0:c0f3bbab73d2 881 /**
Jerome Coutant 0:c0f3bbab73d2 882 * @brief Sets the LCD background color.
Jerome Coutant 0:c0f3bbab73d2 883 * @param Color: Layer background color code ARGB(8-8-8-8)
Jerome Coutant 0:c0f3bbab73d2 884 */
Jerome Coutant 0:c0f3bbab73d2 885 void BSP_LCD_SetBackColor(uint32_t Color)
Jerome Coutant 0:c0f3bbab73d2 886 {
Jerome Coutant 0:c0f3bbab73d2 887 DrawProp[ActiveLayer].BackColor = Color;
Jerome Coutant 0:c0f3bbab73d2 888 }
Jerome Coutant 0:c0f3bbab73d2 889
Jerome Coutant 0:c0f3bbab73d2 890 /**
Jerome Coutant 0:c0f3bbab73d2 891 * @brief Gets the LCD background color.
Jerome Coutant 0:c0f3bbab73d2 892 * @retval Used background color
Jerome Coutant 0:c0f3bbab73d2 893 */
Jerome Coutant 0:c0f3bbab73d2 894 uint32_t BSP_LCD_GetBackColor(void)
Jerome Coutant 0:c0f3bbab73d2 895 {
Jerome Coutant 0:c0f3bbab73d2 896 return DrawProp[ActiveLayer].BackColor;
Jerome Coutant 0:c0f3bbab73d2 897 }
Jerome Coutant 0:c0f3bbab73d2 898
Jerome Coutant 0:c0f3bbab73d2 899 /**
Jerome Coutant 0:c0f3bbab73d2 900 * @brief Sets the LCD text font.
Jerome Coutant 0:c0f3bbab73d2 901 * @param fonts: Layer font to be used
Jerome Coutant 0:c0f3bbab73d2 902 */
Jerome Coutant 0:c0f3bbab73d2 903 void BSP_LCD_SetFont(sFONT *fonts)
Jerome Coutant 0:c0f3bbab73d2 904 {
Jerome Coutant 0:c0f3bbab73d2 905 DrawProp[ActiveLayer].pFont = fonts;
Jerome Coutant 0:c0f3bbab73d2 906 }
Jerome Coutant 0:c0f3bbab73d2 907
Jerome Coutant 0:c0f3bbab73d2 908 /**
Jerome Coutant 0:c0f3bbab73d2 909 * @brief Gets the LCD text font.
Jerome Coutant 0:c0f3bbab73d2 910 * @retval Used layer font
Jerome Coutant 0:c0f3bbab73d2 911 */
Jerome Coutant 0:c0f3bbab73d2 912 sFONT *BSP_LCD_GetFont(void)
Jerome Coutant 0:c0f3bbab73d2 913 {
Jerome Coutant 0:c0f3bbab73d2 914 return DrawProp[ActiveLayer].pFont;
Jerome Coutant 0:c0f3bbab73d2 915 }
Jerome Coutant 0:c0f3bbab73d2 916
Jerome Coutant 0:c0f3bbab73d2 917 /**
Jerome Coutant 0:c0f3bbab73d2 918 * @brief Reads an LCD pixel.
Jerome Coutant 0:c0f3bbab73d2 919 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 920 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 921 * @retval RGB pixel color
Jerome Coutant 0:c0f3bbab73d2 922 */
Jerome Coutant 0:c0f3bbab73d2 923 uint32_t BSP_LCD_ReadPixel(uint16_t Xpos, uint16_t Ypos)
Jerome Coutant 0:c0f3bbab73d2 924 {
Jerome Coutant 0:c0f3bbab73d2 925 uint32_t ret = 0;
Jerome Coutant 0:c0f3bbab73d2 926
Jerome Coutant 0:c0f3bbab73d2 927 if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
Jerome Coutant 0:c0f3bbab73d2 928 {
Jerome Coutant 0:c0f3bbab73d2 929 /* Read data value from SDRAM memory */
Jerome Coutant 1:3e58f8a39705 930 ret = *(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 0:c0f3bbab73d2 931 }
Jerome Coutant 0:c0f3bbab73d2 932 else if(hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
Jerome Coutant 0:c0f3bbab73d2 933 {
Jerome Coutant 0:c0f3bbab73d2 934 /* Read data value from SDRAM memory */
Jerome Coutant 1:3e58f8a39705 935 ret = (*(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) & 0x00FFFFFF);
Jerome Coutant 0:c0f3bbab73d2 936 }
Jerome Coutant 0:c0f3bbab73d2 937 else if((hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
Jerome Coutant 0:c0f3bbab73d2 938 (hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
Jerome Coutant 0:c0f3bbab73d2 939 (hltdc_discovery.LayerCfg[ActiveLayer].PixelFormat == LTDC_PIXEL_FORMAT_AL88))
Jerome Coutant 0:c0f3bbab73d2 940 {
Jerome Coutant 0:c0f3bbab73d2 941 /* Read data value from SDRAM memory */
Jerome Coutant 0:c0f3bbab73d2 942 ret = *(__IO uint16_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 0:c0f3bbab73d2 943 }
Jerome Coutant 0:c0f3bbab73d2 944 else
Jerome Coutant 0:c0f3bbab73d2 945 {
Jerome Coutant 0:c0f3bbab73d2 946 /* Read data value from SDRAM memory */
Jerome Coutant 0:c0f3bbab73d2 947 ret = *(__IO uint8_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (2*(Ypos*BSP_LCD_GetXSize() + Xpos)));
Jerome Coutant 0:c0f3bbab73d2 948 }
Jerome Coutant 0:c0f3bbab73d2 949
Jerome Coutant 0:c0f3bbab73d2 950 return ret;
Jerome Coutant 0:c0f3bbab73d2 951 }
Jerome Coutant 0:c0f3bbab73d2 952
Jerome Coutant 0:c0f3bbab73d2 953 /**
Jerome Coutant 0:c0f3bbab73d2 954 * @brief Clears the whole currently active layer of LTDC.
Jerome Coutant 0:c0f3bbab73d2 955 * @param Color: Color of the background
Jerome Coutant 0:c0f3bbab73d2 956 */
Jerome Coutant 0:c0f3bbab73d2 957 void BSP_LCD_Clear(uint32_t Color)
Jerome Coutant 0:c0f3bbab73d2 958 {
Jerome Coutant 0:c0f3bbab73d2 959 /* Clear the LCD */
Jerome Coutant 0:c0f3bbab73d2 960 LL_FillBuffer(ActiveLayer, (uint32_t *)(hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress), BSP_LCD_GetXSize(), BSP_LCD_GetYSize(), 0, Color);
Jerome Coutant 0:c0f3bbab73d2 961 }
Jerome Coutant 0:c0f3bbab73d2 962
Jerome Coutant 0:c0f3bbab73d2 963 /**
Jerome Coutant 0:c0f3bbab73d2 964 * @brief Clears the selected line in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 965 * @param Line: Line to be cleared
Jerome Coutant 0:c0f3bbab73d2 966 */
Jerome Coutant 0:c0f3bbab73d2 967 void BSP_LCD_ClearStringLine(uint32_t Line)
Jerome Coutant 0:c0f3bbab73d2 968 {
Jerome Coutant 0:c0f3bbab73d2 969 uint32_t color_backup = DrawProp[ActiveLayer].TextColor;
Jerome Coutant 0:c0f3bbab73d2 970 DrawProp[ActiveLayer].TextColor = DrawProp[ActiveLayer].BackColor;
Jerome Coutant 0:c0f3bbab73d2 971
Jerome Coutant 0:c0f3bbab73d2 972 /* Draw rectangle with background color */
Jerome Coutant 0:c0f3bbab73d2 973 BSP_LCD_FillRect(0, (Line * DrawProp[ActiveLayer].pFont->Height), BSP_LCD_GetXSize(), DrawProp[ActiveLayer].pFont->Height);
Jerome Coutant 0:c0f3bbab73d2 974
Jerome Coutant 0:c0f3bbab73d2 975 DrawProp[ActiveLayer].TextColor = color_backup;
Jerome Coutant 0:c0f3bbab73d2 976 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 977 }
Jerome Coutant 0:c0f3bbab73d2 978
Jerome Coutant 0:c0f3bbab73d2 979 /**
Jerome Coutant 0:c0f3bbab73d2 980 * @brief Displays one character in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 981 * @param Xpos: Start column address
Jerome Coutant 0:c0f3bbab73d2 982 * @param Ypos: Line where to display the character shape.
Jerome Coutant 0:c0f3bbab73d2 983 * @param Ascii: Character ascii code
Jerome Coutant 0:c0f3bbab73d2 984 * This parameter must be a number between Min_Data = 0x20 and Max_Data = 0x7E
Jerome Coutant 0:c0f3bbab73d2 985 */
Jerome Coutant 0:c0f3bbab73d2 986 void BSP_LCD_DisplayChar(uint16_t Xpos, uint16_t Ypos, uint8_t Ascii)
Jerome Coutant 0:c0f3bbab73d2 987 {
Jerome Coutant 0:c0f3bbab73d2 988 DrawChar(Xpos, Ypos, &DrawProp[ActiveLayer].pFont->table[(Ascii-' ') *\
Jerome Coutant 0:c0f3bbab73d2 989 DrawProp[ActiveLayer].pFont->Height * ((DrawProp[ActiveLayer].pFont->Width + 7) / 8)]);
Jerome Coutant 0:c0f3bbab73d2 990 }
Jerome Coutant 0:c0f3bbab73d2 991
Jerome Coutant 0:c0f3bbab73d2 992 /**
Jerome Coutant 0:c0f3bbab73d2 993 * @brief Displays characters in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 994 * @param Xpos: X position (in pixel)
Jerome Coutant 0:c0f3bbab73d2 995 * @param Ypos: Y position (in pixel)
Jerome Coutant 0:c0f3bbab73d2 996 * @param Text: Pointer to string to display on LCD
Jerome Coutant 0:c0f3bbab73d2 997 * @param Mode: Display mode
Jerome Coutant 0:c0f3bbab73d2 998 * This parameter can be one of the following values:
Jerome Coutant 0:c0f3bbab73d2 999 * @arg CENTER_MODE
Jerome Coutant 0:c0f3bbab73d2 1000 * @arg RIGHT_MODE
Jerome Coutant 0:c0f3bbab73d2 1001 * @arg LEFT_MODE
Jerome Coutant 0:c0f3bbab73d2 1002 */
Jerome Coutant 0:c0f3bbab73d2 1003 void BSP_LCD_DisplayStringAt(uint16_t Xpos, uint16_t Ypos, uint8_t *Text, Text_AlignModeTypdef Mode)
Jerome Coutant 0:c0f3bbab73d2 1004 {
Jerome Coutant 0:c0f3bbab73d2 1005 uint16_t refcolumn = 1, i = 0;
Jerome Coutant 0:c0f3bbab73d2 1006 uint32_t size = 0, xsize = 0;
Jerome Coutant 0:c0f3bbab73d2 1007 uint8_t *ptr = Text;
Jerome Coutant 0:c0f3bbab73d2 1008
Jerome Coutant 0:c0f3bbab73d2 1009 /* Get the text size */
Jerome Coutant 0:c0f3bbab73d2 1010 while (*ptr++) size ++ ;
Jerome Coutant 0:c0f3bbab73d2 1011
Jerome Coutant 0:c0f3bbab73d2 1012 /* Characters number per line */
Jerome Coutant 0:c0f3bbab73d2 1013 xsize = (BSP_LCD_GetXSize()/DrawProp[ActiveLayer].pFont->Width);
Jerome Coutant 0:c0f3bbab73d2 1014
Jerome Coutant 0:c0f3bbab73d2 1015 switch (Mode)
Jerome Coutant 0:c0f3bbab73d2 1016 {
Jerome Coutant 0:c0f3bbab73d2 1017 case CENTER_MODE:
Jerome Coutant 0:c0f3bbab73d2 1018 {
Jerome Coutant 0:c0f3bbab73d2 1019 refcolumn = Xpos + ((xsize - size)* DrawProp[ActiveLayer].pFont->Width) / 2;
Jerome Coutant 0:c0f3bbab73d2 1020 break;
Jerome Coutant 0:c0f3bbab73d2 1021 }
Jerome Coutant 0:c0f3bbab73d2 1022 case LEFT_MODE:
Jerome Coutant 0:c0f3bbab73d2 1023 {
Jerome Coutant 0:c0f3bbab73d2 1024 refcolumn = Xpos;
Jerome Coutant 0:c0f3bbab73d2 1025 break;
Jerome Coutant 0:c0f3bbab73d2 1026 }
Jerome Coutant 0:c0f3bbab73d2 1027 case RIGHT_MODE:
Jerome Coutant 0:c0f3bbab73d2 1028 {
Jerome Coutant 0:c0f3bbab73d2 1029 refcolumn = - Xpos + ((xsize - size)*DrawProp[ActiveLayer].pFont->Width);
Jerome Coutant 0:c0f3bbab73d2 1030 break;
Jerome Coutant 0:c0f3bbab73d2 1031 }
Jerome Coutant 0:c0f3bbab73d2 1032 default:
Jerome Coutant 0:c0f3bbab73d2 1033 {
Jerome Coutant 0:c0f3bbab73d2 1034 refcolumn = Xpos;
Jerome Coutant 0:c0f3bbab73d2 1035 break;
Jerome Coutant 0:c0f3bbab73d2 1036 }
Jerome Coutant 0:c0f3bbab73d2 1037 }
Jerome Coutant 0:c0f3bbab73d2 1038
Jerome Coutant 0:c0f3bbab73d2 1039 /* Check that the Start column is located in the screen */
Jerome Coutant 0:c0f3bbab73d2 1040 if ((refcolumn < 1) || (refcolumn >= 0x8000))
Jerome Coutant 0:c0f3bbab73d2 1041 {
Jerome Coutant 0:c0f3bbab73d2 1042 refcolumn = 1;
Jerome Coutant 0:c0f3bbab73d2 1043 }
Jerome Coutant 0:c0f3bbab73d2 1044
Jerome Coutant 0:c0f3bbab73d2 1045 /* Send the string character by character on LCD */
Jerome Coutant 0:c0f3bbab73d2 1046 while ((*Text != 0) & (((BSP_LCD_GetXSize() - (i*DrawProp[ActiveLayer].pFont->Width)) & 0xFFFF) >= DrawProp[ActiveLayer].pFont->Width))
Jerome Coutant 0:c0f3bbab73d2 1047 {
Jerome Coutant 0:c0f3bbab73d2 1048 /* Display one character on LCD */
Jerome Coutant 0:c0f3bbab73d2 1049 BSP_LCD_DisplayChar(refcolumn, Ypos, *Text);
Jerome Coutant 0:c0f3bbab73d2 1050 /* Decrement the column position by 16 */
Jerome Coutant 0:c0f3bbab73d2 1051 refcolumn += DrawProp[ActiveLayer].pFont->Width;
Jerome Coutant 0:c0f3bbab73d2 1052
Jerome Coutant 0:c0f3bbab73d2 1053 /* Point on the next character */
Jerome Coutant 0:c0f3bbab73d2 1054 Text++;
Jerome Coutant 0:c0f3bbab73d2 1055 i++;
Jerome Coutant 0:c0f3bbab73d2 1056 }
Jerome Coutant 0:c0f3bbab73d2 1057
Jerome Coutant 0:c0f3bbab73d2 1058 }
Jerome Coutant 0:c0f3bbab73d2 1059
Jerome Coutant 0:c0f3bbab73d2 1060 /**
Jerome Coutant 0:c0f3bbab73d2 1061 * @brief Displays a maximum of 60 characters on the LCD.
Jerome Coutant 0:c0f3bbab73d2 1062 * @param Line: Line where to display the character shape
Jerome Coutant 0:c0f3bbab73d2 1063 * @param ptr: Pointer to string to display on LCD
Jerome Coutant 0:c0f3bbab73d2 1064 */
Jerome Coutant 0:c0f3bbab73d2 1065 void BSP_LCD_DisplayStringAtLine(uint16_t Line, uint8_t *ptr)
Jerome Coutant 0:c0f3bbab73d2 1066 {
Jerome Coutant 0:c0f3bbab73d2 1067 BSP_LCD_DisplayStringAt(0, LINE(Line), ptr, LEFT_MODE);
Jerome Coutant 0:c0f3bbab73d2 1068 }
Jerome Coutant 0:c0f3bbab73d2 1069
Jerome Coutant 0:c0f3bbab73d2 1070 /**
Jerome Coutant 0:c0f3bbab73d2 1071 * @brief Draws an horizontal line in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1072 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1073 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1074 * @param Length: Line length
Jerome Coutant 0:c0f3bbab73d2 1075 */
Jerome Coutant 0:c0f3bbab73d2 1076 void BSP_LCD_DrawHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Jerome Coutant 0:c0f3bbab73d2 1077 {
Jerome Coutant 0:c0f3bbab73d2 1078 uint32_t Xaddress = 0;
Jerome Coutant 0:c0f3bbab73d2 1079
Jerome Coutant 0:c0f3bbab73d2 1080 /* Get the line address */
Jerome Coutant 0:c0f3bbab73d2 1081 Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 0:c0f3bbab73d2 1082
Jerome Coutant 0:c0f3bbab73d2 1083 /* Write line */
Jerome Coutant 0:c0f3bbab73d2 1084 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Length, 1, 0, DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1085 }
Jerome Coutant 0:c0f3bbab73d2 1086
Jerome Coutant 0:c0f3bbab73d2 1087 /**
Jerome Coutant 0:c0f3bbab73d2 1088 * @brief Draws a vertical line in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1089 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1090 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1091 * @param Length: Line length
Jerome Coutant 0:c0f3bbab73d2 1092 */
Jerome Coutant 0:c0f3bbab73d2 1093 void BSP_LCD_DrawVLine(uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Jerome Coutant 0:c0f3bbab73d2 1094 {
Jerome Coutant 0:c0f3bbab73d2 1095 uint32_t Xaddress = 0;
Jerome Coutant 0:c0f3bbab73d2 1096
Jerome Coutant 0:c0f3bbab73d2 1097 /* Get the line address */
Jerome Coutant 0:c0f3bbab73d2 1098 Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 0:c0f3bbab73d2 1099
Jerome Coutant 0:c0f3bbab73d2 1100 /* Write line */
Jerome Coutant 0:c0f3bbab73d2 1101 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, 1, Length, (BSP_LCD_GetXSize() - 1), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1102 }
Jerome Coutant 0:c0f3bbab73d2 1103
Jerome Coutant 0:c0f3bbab73d2 1104 /**
Jerome Coutant 0:c0f3bbab73d2 1105 * @brief Draws an uni-line (between two points) in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1106 * @param x1: Point 1 X position
Jerome Coutant 0:c0f3bbab73d2 1107 * @param y1: Point 1 Y position
Jerome Coutant 0:c0f3bbab73d2 1108 * @param x2: Point 2 X position
Jerome Coutant 0:c0f3bbab73d2 1109 * @param y2: Point 2 Y position
Jerome Coutant 0:c0f3bbab73d2 1110 */
Jerome Coutant 0:c0f3bbab73d2 1111 void BSP_LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Jerome Coutant 0:c0f3bbab73d2 1112 {
Jerome Coutant 0:c0f3bbab73d2 1113 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
Jerome Coutant 0:c0f3bbab73d2 1114 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
Jerome Coutant 0:c0f3bbab73d2 1115 curpixel = 0;
Jerome Coutant 0:c0f3bbab73d2 1116
Jerome Coutant 0:c0f3bbab73d2 1117 deltax = ABS(x2 - x1); /* The difference between the x's */
Jerome Coutant 0:c0f3bbab73d2 1118 deltay = ABS(y2 - y1); /* The difference between the y's */
Jerome Coutant 0:c0f3bbab73d2 1119 x = x1; /* Start x off at the first pixel */
Jerome Coutant 0:c0f3bbab73d2 1120 y = y1; /* Start y off at the first pixel */
Jerome Coutant 0:c0f3bbab73d2 1121
Jerome Coutant 0:c0f3bbab73d2 1122 if (x2 >= x1) /* The x-values are increasing */
Jerome Coutant 0:c0f3bbab73d2 1123 {
Jerome Coutant 0:c0f3bbab73d2 1124 xinc1 = 1;
Jerome Coutant 0:c0f3bbab73d2 1125 xinc2 = 1;
Jerome Coutant 0:c0f3bbab73d2 1126 }
Jerome Coutant 0:c0f3bbab73d2 1127 else /* The x-values are decreasing */
Jerome Coutant 0:c0f3bbab73d2 1128 {
Jerome Coutant 0:c0f3bbab73d2 1129 xinc1 = -1;
Jerome Coutant 0:c0f3bbab73d2 1130 xinc2 = -1;
Jerome Coutant 0:c0f3bbab73d2 1131 }
Jerome Coutant 0:c0f3bbab73d2 1132
Jerome Coutant 0:c0f3bbab73d2 1133 if (y2 >= y1) /* The y-values are increasing */
Jerome Coutant 0:c0f3bbab73d2 1134 {
Jerome Coutant 0:c0f3bbab73d2 1135 yinc1 = 1;
Jerome Coutant 0:c0f3bbab73d2 1136 yinc2 = 1;
Jerome Coutant 0:c0f3bbab73d2 1137 }
Jerome Coutant 0:c0f3bbab73d2 1138 else /* The y-values are decreasing */
Jerome Coutant 0:c0f3bbab73d2 1139 {
Jerome Coutant 0:c0f3bbab73d2 1140 yinc1 = -1;
Jerome Coutant 0:c0f3bbab73d2 1141 yinc2 = -1;
Jerome Coutant 0:c0f3bbab73d2 1142 }
Jerome Coutant 0:c0f3bbab73d2 1143
Jerome Coutant 0:c0f3bbab73d2 1144 if (deltax >= deltay) /* There is at least one x-value for every y-value */
Jerome Coutant 0:c0f3bbab73d2 1145 {
Jerome Coutant 0:c0f3bbab73d2 1146 xinc1 = 0; /* Don't change the x when numerator >= denominator */
Jerome Coutant 0:c0f3bbab73d2 1147 yinc2 = 0; /* Don't change the y for every iteration */
Jerome Coutant 0:c0f3bbab73d2 1148 den = deltax;
Jerome Coutant 0:c0f3bbab73d2 1149 num = deltax / 2;
Jerome Coutant 0:c0f3bbab73d2 1150 numadd = deltay;
Jerome Coutant 0:c0f3bbab73d2 1151 numpixels = deltax; /* There are more x-values than y-values */
Jerome Coutant 0:c0f3bbab73d2 1152 }
Jerome Coutant 0:c0f3bbab73d2 1153 else /* There is at least one y-value for every x-value */
Jerome Coutant 0:c0f3bbab73d2 1154 {
Jerome Coutant 0:c0f3bbab73d2 1155 xinc2 = 0; /* Don't change the x for every iteration */
Jerome Coutant 0:c0f3bbab73d2 1156 yinc1 = 0; /* Don't change the y when numerator >= denominator */
Jerome Coutant 0:c0f3bbab73d2 1157 den = deltay;
Jerome Coutant 0:c0f3bbab73d2 1158 num = deltay / 2;
Jerome Coutant 0:c0f3bbab73d2 1159 numadd = deltax;
Jerome Coutant 0:c0f3bbab73d2 1160 numpixels = deltay; /* There are more y-values than x-values */
Jerome Coutant 0:c0f3bbab73d2 1161 }
Jerome Coutant 0:c0f3bbab73d2 1162
Jerome Coutant 0:c0f3bbab73d2 1163 for (curpixel = 0; curpixel <= numpixels; curpixel++)
Jerome Coutant 0:c0f3bbab73d2 1164 {
Jerome Coutant 0:c0f3bbab73d2 1165 BSP_LCD_DrawPixel(x, y, DrawProp[ActiveLayer].TextColor); /* Draw the current pixel */
Jerome Coutant 0:c0f3bbab73d2 1166 num += numadd; /* Increase the numerator by the top of the fraction */
Jerome Coutant 0:c0f3bbab73d2 1167 if (num >= den) /* Check if numerator >= denominator */
Jerome Coutant 0:c0f3bbab73d2 1168 {
Jerome Coutant 0:c0f3bbab73d2 1169 num -= den; /* Calculate the new numerator value */
Jerome Coutant 0:c0f3bbab73d2 1170 x += xinc1; /* Change the x as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1171 y += yinc1; /* Change the y as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1172 }
Jerome Coutant 0:c0f3bbab73d2 1173 x += xinc2; /* Change the x as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1174 y += yinc2; /* Change the y as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1175 }
Jerome Coutant 0:c0f3bbab73d2 1176 }
Jerome Coutant 0:c0f3bbab73d2 1177
Jerome Coutant 0:c0f3bbab73d2 1178 /**
Jerome Coutant 0:c0f3bbab73d2 1179 * @brief Draws a rectangle in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1180 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1181 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1182 * @param Width: Rectangle width
Jerome Coutant 0:c0f3bbab73d2 1183 * @param Height: Rectangle height
Jerome Coutant 0:c0f3bbab73d2 1184 */
Jerome Coutant 0:c0f3bbab73d2 1185 void BSP_LCD_DrawRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 0:c0f3bbab73d2 1186 {
Jerome Coutant 0:c0f3bbab73d2 1187 /* Draw horizontal lines */
Jerome Coutant 0:c0f3bbab73d2 1188 BSP_LCD_DrawHLine(Xpos, Ypos, Width);
Jerome Coutant 0:c0f3bbab73d2 1189 BSP_LCD_DrawHLine(Xpos, (Ypos+ Height), Width);
Jerome Coutant 0:c0f3bbab73d2 1190
Jerome Coutant 0:c0f3bbab73d2 1191 /* Draw vertical lines */
Jerome Coutant 0:c0f3bbab73d2 1192 BSP_LCD_DrawVLine(Xpos, Ypos, Height);
Jerome Coutant 0:c0f3bbab73d2 1193 BSP_LCD_DrawVLine((Xpos + Width), Ypos, Height);
Jerome Coutant 0:c0f3bbab73d2 1194 }
Jerome Coutant 0:c0f3bbab73d2 1195
Jerome Coutant 0:c0f3bbab73d2 1196 /**
Jerome Coutant 0:c0f3bbab73d2 1197 * @brief Draws a circle in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1198 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1199 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1200 * @param Radius: Circle radius
Jerome Coutant 0:c0f3bbab73d2 1201 */
Jerome Coutant 0:c0f3bbab73d2 1202 void BSP_LCD_DrawCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Jerome Coutant 0:c0f3bbab73d2 1203 {
Jerome Coutant 0:c0f3bbab73d2 1204 int32_t D; /* Decision Variable */
Jerome Coutant 0:c0f3bbab73d2 1205 uint32_t CurX; /* Current X Value */
Jerome Coutant 0:c0f3bbab73d2 1206 uint32_t CurY; /* Current Y Value */
Jerome Coutant 0:c0f3bbab73d2 1207
Jerome Coutant 0:c0f3bbab73d2 1208 D = 3 - (Radius << 1);
Jerome Coutant 0:c0f3bbab73d2 1209 CurX = 0;
Jerome Coutant 0:c0f3bbab73d2 1210 CurY = Radius;
Jerome Coutant 0:c0f3bbab73d2 1211
Jerome Coutant 0:c0f3bbab73d2 1212 while (CurX <= CurY)
Jerome Coutant 0:c0f3bbab73d2 1213 {
Jerome Coutant 0:c0f3bbab73d2 1214 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1215
Jerome Coutant 0:c0f3bbab73d2 1216 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos - CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1217
Jerome Coutant 0:c0f3bbab73d2 1218 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1219
Jerome Coutant 0:c0f3bbab73d2 1220 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos - CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1221
Jerome Coutant 0:c0f3bbab73d2 1222 BSP_LCD_DrawPixel((Xpos + CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1223
Jerome Coutant 0:c0f3bbab73d2 1224 BSP_LCD_DrawPixel((Xpos - CurX), (Ypos + CurY), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1225
Jerome Coutant 0:c0f3bbab73d2 1226 BSP_LCD_DrawPixel((Xpos + CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1227
Jerome Coutant 0:c0f3bbab73d2 1228 BSP_LCD_DrawPixel((Xpos - CurY), (Ypos + CurX), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1229
Jerome Coutant 0:c0f3bbab73d2 1230 if (D < 0)
Jerome Coutant 0:c0f3bbab73d2 1231 {
Jerome Coutant 0:c0f3bbab73d2 1232 D += (CurX << 2) + 6;
Jerome Coutant 0:c0f3bbab73d2 1233 }
Jerome Coutant 0:c0f3bbab73d2 1234 else
Jerome Coutant 0:c0f3bbab73d2 1235 {
Jerome Coutant 0:c0f3bbab73d2 1236 D += ((CurX - CurY) << 2) + 10;
Jerome Coutant 0:c0f3bbab73d2 1237 CurY--;
Jerome Coutant 0:c0f3bbab73d2 1238 }
Jerome Coutant 0:c0f3bbab73d2 1239 CurX++;
Jerome Coutant 0:c0f3bbab73d2 1240 }
Jerome Coutant 0:c0f3bbab73d2 1241 }
Jerome Coutant 0:c0f3bbab73d2 1242
Jerome Coutant 0:c0f3bbab73d2 1243 /**
Jerome Coutant 0:c0f3bbab73d2 1244 * @brief Draws an poly-line (between many points) in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1245 * @param Points: Pointer to the points array
Jerome Coutant 0:c0f3bbab73d2 1246 * @param PointCount: Number of points
Jerome Coutant 0:c0f3bbab73d2 1247 */
Jerome Coutant 0:c0f3bbab73d2 1248 void BSP_LCD_DrawPolygon(pPoint Points, uint16_t PointCount)
Jerome Coutant 0:c0f3bbab73d2 1249 {
Jerome Coutant 0:c0f3bbab73d2 1250 int16_t X = 0, Y = 0;
Jerome Coutant 0:c0f3bbab73d2 1251
Jerome Coutant 0:c0f3bbab73d2 1252 if(PointCount < 2)
Jerome Coutant 0:c0f3bbab73d2 1253 {
Jerome Coutant 0:c0f3bbab73d2 1254 return;
Jerome Coutant 0:c0f3bbab73d2 1255 }
Jerome Coutant 0:c0f3bbab73d2 1256
Jerome Coutant 0:c0f3bbab73d2 1257 BSP_LCD_DrawLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
Jerome Coutant 0:c0f3bbab73d2 1258
Jerome Coutant 0:c0f3bbab73d2 1259 while(--PointCount)
Jerome Coutant 0:c0f3bbab73d2 1260 {
Jerome Coutant 0:c0f3bbab73d2 1261 X = Points->X;
Jerome Coutant 0:c0f3bbab73d2 1262 Y = Points->Y;
Jerome Coutant 0:c0f3bbab73d2 1263 Points++;
Jerome Coutant 0:c0f3bbab73d2 1264 BSP_LCD_DrawLine(X, Y, Points->X, Points->Y);
Jerome Coutant 0:c0f3bbab73d2 1265 }
Jerome Coutant 0:c0f3bbab73d2 1266 }
Jerome Coutant 0:c0f3bbab73d2 1267
Jerome Coutant 0:c0f3bbab73d2 1268 /**
Jerome Coutant 0:c0f3bbab73d2 1269 * @brief Draws an ellipse on LCD in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1270 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1271 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1272 * @param XRadius: Ellipse X radius
Jerome Coutant 0:c0f3bbab73d2 1273 * @param YRadius: Ellipse Y radius
Jerome Coutant 0:c0f3bbab73d2 1274 */
Jerome Coutant 0:c0f3bbab73d2 1275 void BSP_LCD_DrawEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Jerome Coutant 0:c0f3bbab73d2 1276 {
Jerome Coutant 0:c0f3bbab73d2 1277 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
Jerome Coutant 0:c0f3bbab73d2 1278 float K = 0, rad1 = 0, rad2 = 0;
Jerome Coutant 0:c0f3bbab73d2 1279
Jerome Coutant 0:c0f3bbab73d2 1280 rad1 = XRadius;
Jerome Coutant 0:c0f3bbab73d2 1281 rad2 = YRadius;
Jerome Coutant 0:c0f3bbab73d2 1282
Jerome Coutant 0:c0f3bbab73d2 1283 K = (float)(rad2/rad1);
Jerome Coutant 0:c0f3bbab73d2 1284
Jerome Coutant 0:c0f3bbab73d2 1285 do {
Jerome Coutant 0:c0f3bbab73d2 1286 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1287 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos+y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1288 BSP_LCD_DrawPixel((Xpos+(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1289 BSP_LCD_DrawPixel((Xpos-(uint16_t)(x/K)), (Ypos-y), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1290
Jerome Coutant 0:c0f3bbab73d2 1291 e2 = err;
Jerome Coutant 0:c0f3bbab73d2 1292 if (e2 <= x) {
Jerome Coutant 0:c0f3bbab73d2 1293 err += ++x*2+1;
Jerome Coutant 0:c0f3bbab73d2 1294 if (-y == x && e2 <= y) e2 = 0;
Jerome Coutant 0:c0f3bbab73d2 1295 }
Jerome Coutant 0:c0f3bbab73d2 1296 if (e2 > y) err += ++y*2+1;
Jerome Coutant 0:c0f3bbab73d2 1297 }
Jerome Coutant 0:c0f3bbab73d2 1298 while (y <= 0);
Jerome Coutant 0:c0f3bbab73d2 1299 }
Jerome Coutant 0:c0f3bbab73d2 1300
Jerome Coutant 0:c0f3bbab73d2 1301 /**
Jerome Coutant 0:c0f3bbab73d2 1302 * @brief Draws a bitmap picture loaded in the internal Flash (32 bpp) in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1303 * @param Xpos: Bmp X position in the LCD
Jerome Coutant 0:c0f3bbab73d2 1304 * @param Ypos: Bmp Y position in the LCD
Jerome Coutant 0:c0f3bbab73d2 1305 * @param pbmp: Pointer to Bmp picture address in the internal Flash
Jerome Coutant 0:c0f3bbab73d2 1306 */
Jerome Coutant 0:c0f3bbab73d2 1307 void BSP_LCD_DrawBitmap(uint32_t Xpos, uint32_t Ypos, uint8_t *pbmp)
Jerome Coutant 0:c0f3bbab73d2 1308 {
Jerome Coutant 0:c0f3bbab73d2 1309 uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
Jerome Coutant 0:c0f3bbab73d2 1310 uint32_t Address;
Jerome Coutant 0:c0f3bbab73d2 1311 uint32_t InputColorMode = 0;
Jerome Coutant 0:c0f3bbab73d2 1312
Jerome Coutant 0:c0f3bbab73d2 1313 /* Get bitmap data address offset */
Jerome Coutant 0:c0f3bbab73d2 1314 index = *(__IO uint16_t *) (pbmp + 10);
Jerome Coutant 0:c0f3bbab73d2 1315 index |= (*(__IO uint16_t *) (pbmp + 12)) << 16;
Jerome Coutant 0:c0f3bbab73d2 1316
Jerome Coutant 0:c0f3bbab73d2 1317 /* Read bitmap width */
Jerome Coutant 0:c0f3bbab73d2 1318 width = *(uint16_t *) (pbmp + 18);
Jerome Coutant 0:c0f3bbab73d2 1319 width |= (*(uint16_t *) (pbmp + 20)) << 16;
Jerome Coutant 0:c0f3bbab73d2 1320
Jerome Coutant 0:c0f3bbab73d2 1321 /* Read bitmap height */
Jerome Coutant 0:c0f3bbab73d2 1322 height = *(uint16_t *) (pbmp + 22);
Jerome Coutant 0:c0f3bbab73d2 1323 height |= (*(uint16_t *) (pbmp + 24)) << 16;
Jerome Coutant 0:c0f3bbab73d2 1324
Jerome Coutant 0:c0f3bbab73d2 1325 /* Read bit/pixel */
Jerome Coutant 0:c0f3bbab73d2 1326 bit_pixel = *(uint16_t *) (pbmp + 28);
Jerome Coutant 0:c0f3bbab73d2 1327
Jerome Coutant 0:c0f3bbab73d2 1328 /* Set the address */
Jerome Coutant 0:c0f3bbab73d2 1329 Address = hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (((BSP_LCD_GetXSize()*Ypos) + Xpos)*(4));
Jerome Coutant 0:c0f3bbab73d2 1330
Jerome Coutant 0:c0f3bbab73d2 1331 /* Get the layer pixel format */
Jerome Coutant 0:c0f3bbab73d2 1332 if ((bit_pixel/8) == 4)
Jerome Coutant 0:c0f3bbab73d2 1333 {
Jerome Coutant 0:c0f3bbab73d2 1334 InputColorMode = DMA2D_INPUT_ARGB8888;
Jerome Coutant 0:c0f3bbab73d2 1335 }
Jerome Coutant 0:c0f3bbab73d2 1336 else if ((bit_pixel/8) == 2)
Jerome Coutant 0:c0f3bbab73d2 1337 {
Jerome Coutant 0:c0f3bbab73d2 1338 InputColorMode = DMA2D_INPUT_RGB565;
Jerome Coutant 0:c0f3bbab73d2 1339 }
Jerome Coutant 0:c0f3bbab73d2 1340 else
Jerome Coutant 0:c0f3bbab73d2 1341 {
Jerome Coutant 0:c0f3bbab73d2 1342 InputColorMode = DMA2D_INPUT_RGB888;
Jerome Coutant 0:c0f3bbab73d2 1343 }
Jerome Coutant 0:c0f3bbab73d2 1344
Jerome Coutant 0:c0f3bbab73d2 1345 /* Bypass the bitmap header */
Jerome Coutant 0:c0f3bbab73d2 1346 pbmp += (index + (width * (height - 1) * (bit_pixel/8)));
Jerome Coutant 0:c0f3bbab73d2 1347
Jerome Coutant 0:c0f3bbab73d2 1348 /* Convert picture to ARGB8888 pixel format */
Jerome Coutant 0:c0f3bbab73d2 1349 for(index=0; index < height; index++)
Jerome Coutant 0:c0f3bbab73d2 1350 {
Jerome Coutant 0:c0f3bbab73d2 1351 /* Pixel format conversion */
Jerome Coutant 0:c0f3bbab73d2 1352 LL_ConvertLineToARGB8888((uint32_t *)pbmp, (uint32_t *)Address, width, InputColorMode);
Jerome Coutant 0:c0f3bbab73d2 1353
Jerome Coutant 0:c0f3bbab73d2 1354 /* Increment the source and destination buffers */
Jerome Coutant 0:c0f3bbab73d2 1355 Address+= (BSP_LCD_GetXSize()*4);
Jerome Coutant 0:c0f3bbab73d2 1356 pbmp -= width*(bit_pixel/8);
Jerome Coutant 0:c0f3bbab73d2 1357 }
Jerome Coutant 0:c0f3bbab73d2 1358 }
Jerome Coutant 0:c0f3bbab73d2 1359
Jerome Coutant 0:c0f3bbab73d2 1360 /**
Jerome Coutant 0:c0f3bbab73d2 1361 * @brief Draws a full rectangle in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1362 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1363 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1364 * @param Width: Rectangle width
Jerome Coutant 0:c0f3bbab73d2 1365 * @param Height: Rectangle height
Jerome Coutant 0:c0f3bbab73d2 1366 */
Jerome Coutant 0:c0f3bbab73d2 1367 void BSP_LCD_FillRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Jerome Coutant 0:c0f3bbab73d2 1368 {
Jerome Coutant 0:c0f3bbab73d2 1369 uint32_t Xaddress = 0;
Jerome Coutant 0:c0f3bbab73d2 1370
Jerome Coutant 0:c0f3bbab73d2 1371 /* Set the text color */
Jerome Coutant 0:c0f3bbab73d2 1372 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1373
Jerome Coutant 0:c0f3bbab73d2 1374 /* Get the rectangle start address */
Jerome Coutant 0:c0f3bbab73d2 1375 Xaddress = (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress) + 4*(BSP_LCD_GetXSize()*Ypos + Xpos);
Jerome Coutant 0:c0f3bbab73d2 1376
Jerome Coutant 0:c0f3bbab73d2 1377 /* Fill the rectangle */
Jerome Coutant 0:c0f3bbab73d2 1378 LL_FillBuffer(ActiveLayer, (uint32_t *)Xaddress, Width, Height, (BSP_LCD_GetXSize() - Width), DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1379 }
Jerome Coutant 0:c0f3bbab73d2 1380
Jerome Coutant 0:c0f3bbab73d2 1381 /**
Jerome Coutant 0:c0f3bbab73d2 1382 * @brief Draws a full circle in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1383 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1384 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1385 * @param Radius: Circle radius
Jerome Coutant 0:c0f3bbab73d2 1386 */
Jerome Coutant 0:c0f3bbab73d2 1387 void BSP_LCD_FillCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
Jerome Coutant 0:c0f3bbab73d2 1388 {
Jerome Coutant 0:c0f3bbab73d2 1389 int32_t D; /* Decision Variable */
Jerome Coutant 0:c0f3bbab73d2 1390 uint32_t CurX; /* Current X Value */
Jerome Coutant 0:c0f3bbab73d2 1391 uint32_t CurY; /* Current Y Value */
Jerome Coutant 0:c0f3bbab73d2 1392
Jerome Coutant 0:c0f3bbab73d2 1393 D = 3 - (Radius << 1);
Jerome Coutant 0:c0f3bbab73d2 1394
Jerome Coutant 0:c0f3bbab73d2 1395 CurX = 0;
Jerome Coutant 0:c0f3bbab73d2 1396 CurY = Radius;
Jerome Coutant 0:c0f3bbab73d2 1397
Jerome Coutant 0:c0f3bbab73d2 1398 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1399
Jerome Coutant 0:c0f3bbab73d2 1400 while (CurX <= CurY)
Jerome Coutant 0:c0f3bbab73d2 1401 {
Jerome Coutant 0:c0f3bbab73d2 1402 if(CurY > 0)
Jerome Coutant 0:c0f3bbab73d2 1403 {
Jerome Coutant 0:c0f3bbab73d2 1404 BSP_LCD_DrawHLine(Xpos - CurY, Ypos + CurX, 2*CurY);
Jerome Coutant 0:c0f3bbab73d2 1405 BSP_LCD_DrawHLine(Xpos - CurY, Ypos - CurX, 2*CurY);
Jerome Coutant 0:c0f3bbab73d2 1406 }
Jerome Coutant 0:c0f3bbab73d2 1407
Jerome Coutant 0:c0f3bbab73d2 1408 if(CurX > 0)
Jerome Coutant 0:c0f3bbab73d2 1409 {
Jerome Coutant 0:c0f3bbab73d2 1410 BSP_LCD_DrawHLine(Xpos - CurX, Ypos - CurY, 2*CurX);
Jerome Coutant 0:c0f3bbab73d2 1411 BSP_LCD_DrawHLine(Xpos - CurX, Ypos + CurY, 2*CurX);
Jerome Coutant 0:c0f3bbab73d2 1412 }
Jerome Coutant 0:c0f3bbab73d2 1413 if (D < 0)
Jerome Coutant 0:c0f3bbab73d2 1414 {
Jerome Coutant 0:c0f3bbab73d2 1415 D += (CurX << 2) + 6;
Jerome Coutant 0:c0f3bbab73d2 1416 }
Jerome Coutant 0:c0f3bbab73d2 1417 else
Jerome Coutant 0:c0f3bbab73d2 1418 {
Jerome Coutant 0:c0f3bbab73d2 1419 D += ((CurX - CurY) << 2) + 10;
Jerome Coutant 0:c0f3bbab73d2 1420 CurY--;
Jerome Coutant 0:c0f3bbab73d2 1421 }
Jerome Coutant 0:c0f3bbab73d2 1422 CurX++;
Jerome Coutant 0:c0f3bbab73d2 1423 }
Jerome Coutant 0:c0f3bbab73d2 1424
Jerome Coutant 0:c0f3bbab73d2 1425 BSP_LCD_SetTextColor(DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1426 BSP_LCD_DrawCircle(Xpos, Ypos, Radius);
Jerome Coutant 0:c0f3bbab73d2 1427 }
Jerome Coutant 0:c0f3bbab73d2 1428
Jerome Coutant 0:c0f3bbab73d2 1429 /**
Jerome Coutant 0:c0f3bbab73d2 1430 * @brief Draws a full poly-line (between many points) in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1431 * @param Points: Pointer to the points array
Jerome Coutant 0:c0f3bbab73d2 1432 * @param PointCount: Number of points
Jerome Coutant 0:c0f3bbab73d2 1433 */
Jerome Coutant 0:c0f3bbab73d2 1434 void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount)
Jerome Coutant 0:c0f3bbab73d2 1435 {
Jerome Coutant 0:c0f3bbab73d2 1436 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;
Jerome Coutant 0:c0f3bbab73d2 1437 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
Jerome Coutant 0:c0f3bbab73d2 1438
Jerome Coutant 0:c0f3bbab73d2 1439 IMAGE_LEFT = IMAGE_RIGHT = Points->X;
Jerome Coutant 0:c0f3bbab73d2 1440 IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
Jerome Coutant 0:c0f3bbab73d2 1441
Jerome Coutant 0:c0f3bbab73d2 1442 for(counter = 1; counter < PointCount; counter++)
Jerome Coutant 0:c0f3bbab73d2 1443 {
Jerome Coutant 0:c0f3bbab73d2 1444 pixelX = POLY_X(counter);
Jerome Coutant 0:c0f3bbab73d2 1445 if(pixelX < IMAGE_LEFT)
Jerome Coutant 0:c0f3bbab73d2 1446 {
Jerome Coutant 0:c0f3bbab73d2 1447 IMAGE_LEFT = pixelX;
Jerome Coutant 0:c0f3bbab73d2 1448 }
Jerome Coutant 0:c0f3bbab73d2 1449 if(pixelX > IMAGE_RIGHT)
Jerome Coutant 0:c0f3bbab73d2 1450 {
Jerome Coutant 0:c0f3bbab73d2 1451 IMAGE_RIGHT = pixelX;
Jerome Coutant 0:c0f3bbab73d2 1452 }
Jerome Coutant 0:c0f3bbab73d2 1453
Jerome Coutant 0:c0f3bbab73d2 1454 pixelY = POLY_Y(counter);
Jerome Coutant 0:c0f3bbab73d2 1455 if(pixelY < IMAGE_TOP)
Jerome Coutant 0:c0f3bbab73d2 1456 {
Jerome Coutant 0:c0f3bbab73d2 1457 IMAGE_TOP = pixelY;
Jerome Coutant 0:c0f3bbab73d2 1458 }
Jerome Coutant 0:c0f3bbab73d2 1459 if(pixelY > IMAGE_BOTTOM)
Jerome Coutant 0:c0f3bbab73d2 1460 {
Jerome Coutant 0:c0f3bbab73d2 1461 IMAGE_BOTTOM = pixelY;
Jerome Coutant 0:c0f3bbab73d2 1462 }
Jerome Coutant 0:c0f3bbab73d2 1463 }
Jerome Coutant 0:c0f3bbab73d2 1464
Jerome Coutant 0:c0f3bbab73d2 1465 if(PointCount < 2)
Jerome Coutant 0:c0f3bbab73d2 1466 {
Jerome Coutant 0:c0f3bbab73d2 1467 return;
Jerome Coutant 0:c0f3bbab73d2 1468 }
Jerome Coutant 0:c0f3bbab73d2 1469
Jerome Coutant 0:c0f3bbab73d2 1470 X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2;
Jerome Coutant 0:c0f3bbab73d2 1471 Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2;
Jerome Coutant 0:c0f3bbab73d2 1472
Jerome Coutant 0:c0f3bbab73d2 1473 X_first = Points->X;
Jerome Coutant 0:c0f3bbab73d2 1474 Y_first = Points->Y;
Jerome Coutant 0:c0f3bbab73d2 1475
Jerome Coutant 0:c0f3bbab73d2 1476 while(--PointCount)
Jerome Coutant 0:c0f3bbab73d2 1477 {
Jerome Coutant 0:c0f3bbab73d2 1478 X = Points->X;
Jerome Coutant 0:c0f3bbab73d2 1479 Y = Points->Y;
Jerome Coutant 0:c0f3bbab73d2 1480 Points++;
Jerome Coutant 0:c0f3bbab73d2 1481 X2 = Points->X;
Jerome Coutant 0:c0f3bbab73d2 1482 Y2 = Points->Y;
Jerome Coutant 0:c0f3bbab73d2 1483
Jerome Coutant 0:c0f3bbab73d2 1484 FillTriangle(X, X2, X_center, Y, Y2, Y_center);
Jerome Coutant 0:c0f3bbab73d2 1485 FillTriangle(X, X_center, X2, Y, Y_center, Y2);
Jerome Coutant 0:c0f3bbab73d2 1486 FillTriangle(X_center, X2, X, Y_center, Y2, Y);
Jerome Coutant 0:c0f3bbab73d2 1487 }
Jerome Coutant 0:c0f3bbab73d2 1488
Jerome Coutant 0:c0f3bbab73d2 1489 FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center);
Jerome Coutant 0:c0f3bbab73d2 1490 FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2);
Jerome Coutant 0:c0f3bbab73d2 1491 FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first);
Jerome Coutant 0:c0f3bbab73d2 1492 }
Jerome Coutant 0:c0f3bbab73d2 1493
Jerome Coutant 0:c0f3bbab73d2 1494 /**
Jerome Coutant 0:c0f3bbab73d2 1495 * @brief Draws a full ellipse in currently active layer.
Jerome Coutant 0:c0f3bbab73d2 1496 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1497 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1498 * @param XRadius: Ellipse X radius
Jerome Coutant 0:c0f3bbab73d2 1499 * @param YRadius: Ellipse Y radius
Jerome Coutant 0:c0f3bbab73d2 1500 */
Jerome Coutant 0:c0f3bbab73d2 1501 void BSP_LCD_FillEllipse(int Xpos, int Ypos, int XRadius, int YRadius)
Jerome Coutant 0:c0f3bbab73d2 1502 {
Jerome Coutant 0:c0f3bbab73d2 1503 int x = 0, y = -YRadius, err = 2-2*XRadius, e2;
Jerome Coutant 0:c0f3bbab73d2 1504 float K = 0, rad1 = 0, rad2 = 0;
Jerome Coutant 0:c0f3bbab73d2 1505
Jerome Coutant 0:c0f3bbab73d2 1506 rad1 = XRadius;
Jerome Coutant 0:c0f3bbab73d2 1507 rad2 = YRadius;
Jerome Coutant 0:c0f3bbab73d2 1508
Jerome Coutant 0:c0f3bbab73d2 1509 K = (float)(rad2/rad1);
Jerome Coutant 0:c0f3bbab73d2 1510
Jerome Coutant 0:c0f3bbab73d2 1511 do
Jerome Coutant 0:c0f3bbab73d2 1512 {
Jerome Coutant 0:c0f3bbab73d2 1513 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos+y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 0:c0f3bbab73d2 1514 BSP_LCD_DrawHLine((Xpos-(uint16_t)(x/K)), (Ypos-y), (2*(uint16_t)(x/K) + 1));
Jerome Coutant 0:c0f3bbab73d2 1515
Jerome Coutant 0:c0f3bbab73d2 1516 e2 = err;
Jerome Coutant 0:c0f3bbab73d2 1517 if (e2 <= x)
Jerome Coutant 0:c0f3bbab73d2 1518 {
Jerome Coutant 0:c0f3bbab73d2 1519 err += ++x*2+1;
Jerome Coutant 0:c0f3bbab73d2 1520 if (-y == x && e2 <= y) e2 = 0;
Jerome Coutant 0:c0f3bbab73d2 1521 }
Jerome Coutant 0:c0f3bbab73d2 1522 if (e2 > y) err += ++y*2+1;
Jerome Coutant 0:c0f3bbab73d2 1523 }
Jerome Coutant 0:c0f3bbab73d2 1524 while (y <= 0);
Jerome Coutant 0:c0f3bbab73d2 1525 }
Jerome Coutant 0:c0f3bbab73d2 1526
Jerome Coutant 0:c0f3bbab73d2 1527 /**
Jerome Coutant 0:c0f3bbab73d2 1528 * @brief Switch back on the display if was switched off by previous call of BSP_LCD_DisplayOff().
Jerome Coutant 0:c0f3bbab73d2 1529 * Exit DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 0:c0f3bbab73d2 1530 */
Jerome Coutant 0:c0f3bbab73d2 1531 void BSP_LCD_DisplayOn(void)
Jerome Coutant 0:c0f3bbab73d2 1532 {
Jerome Coutant 0:c0f3bbab73d2 1533 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 1534 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:c0f3bbab73d2 1535 {
Jerome Coutant 0:c0f3bbab73d2 1536 return ; /* Not supported for HDMI display */
Jerome Coutant 0:c0f3bbab73d2 1537 }
Jerome Coutant 0:c0f3bbab73d2 1538 else
Jerome Coutant 0:c0f3bbab73d2 1539 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 1540 {
Jerome Coutant 0:c0f3bbab73d2 1541 /* Send Display on DCS command to display */
Jerome Coutant 0:c0f3bbab73d2 1542 HAL_DSI_ShortWrite(&(hdsi_discovery),
Jerome Coutant 0:c0f3bbab73d2 1543 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 0:c0f3bbab73d2 1544 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 0:c0f3bbab73d2 1545 OTM8009A_CMD_DISPON,
Jerome Coutant 0:c0f3bbab73d2 1546 0x00);
Jerome Coutant 0:c0f3bbab73d2 1547 }
Jerome Coutant 0:c0f3bbab73d2 1548 }
Jerome Coutant 0:c0f3bbab73d2 1549
Jerome Coutant 0:c0f3bbab73d2 1550 /**
Jerome Coutant 0:c0f3bbab73d2 1551 * @brief Switch Off the display.
Jerome Coutant 0:c0f3bbab73d2 1552 * Enter DSI ULPM mode if was allowed and configured in Dsi Configuration.
Jerome Coutant 0:c0f3bbab73d2 1553 */
Jerome Coutant 0:c0f3bbab73d2 1554 void BSP_LCD_DisplayOff(void)
Jerome Coutant 0:c0f3bbab73d2 1555 {
Jerome Coutant 0:c0f3bbab73d2 1556 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 1557 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:c0f3bbab73d2 1558 {
Jerome Coutant 0:c0f3bbab73d2 1559 return ; /* Not supported for HDMI display */
Jerome Coutant 0:c0f3bbab73d2 1560 }
Jerome Coutant 0:c0f3bbab73d2 1561 else
Jerome Coutant 0:c0f3bbab73d2 1562 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 1563 {
Jerome Coutant 0:c0f3bbab73d2 1564 /* Send Display off DCS Command to display */
Jerome Coutant 0:c0f3bbab73d2 1565 HAL_DSI_ShortWrite(&(hdsi_discovery),
Jerome Coutant 0:c0f3bbab73d2 1566 hdsivideo_handle.VirtualChannelID,
Jerome Coutant 0:c0f3bbab73d2 1567 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 0:c0f3bbab73d2 1568 OTM8009A_CMD_DISPOFF,
Jerome Coutant 0:c0f3bbab73d2 1569 0x00);
Jerome Coutant 0:c0f3bbab73d2 1570 }
Jerome Coutant 0:c0f3bbab73d2 1571 }
Jerome Coutant 0:c0f3bbab73d2 1572
Jerome Coutant 0:c0f3bbab73d2 1573 /**
Jerome Coutant 0:c0f3bbab73d2 1574 * @brief Set the brightness value
Jerome Coutant 0:c0f3bbab73d2 1575 * @param BrightnessValue: [00: Min (black), 100 Max]
Jerome Coutant 0:c0f3bbab73d2 1576 */
Jerome Coutant 0:c0f3bbab73d2 1577 void BSP_LCD_SetBrightness(uint8_t BrightnessValue)
Jerome Coutant 0:c0f3bbab73d2 1578 {
Jerome Coutant 0:c0f3bbab73d2 1579 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 1580 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:c0f3bbab73d2 1581 {
Jerome Coutant 0:c0f3bbab73d2 1582 return ; /* Not supported for HDMI display */
Jerome Coutant 0:c0f3bbab73d2 1583 }
Jerome Coutant 0:c0f3bbab73d2 1584 else
Jerome Coutant 0:c0f3bbab73d2 1585 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 1586 {
Jerome Coutant 0:c0f3bbab73d2 1587 /* Send Display on DCS command to display */
Jerome Coutant 0:c0f3bbab73d2 1588 HAL_DSI_ShortWrite(&hdsi_discovery,
Jerome Coutant 0:c0f3bbab73d2 1589 LCD_OTM8009A_ID,
Jerome Coutant 0:c0f3bbab73d2 1590 DSI_DCS_SHORT_PKT_WRITE_P1,
Jerome Coutant 0:c0f3bbab73d2 1591 OTM8009A_CMD_WRDISBV, (uint16_t)(BrightnessValue * 255)/100);
Jerome Coutant 0:c0f3bbab73d2 1592 }
Jerome Coutant 0:c0f3bbab73d2 1593 }
Jerome Coutant 0:c0f3bbab73d2 1594
Jerome Coutant 0:c0f3bbab73d2 1595 /**
Jerome Coutant 0:c0f3bbab73d2 1596 * @brief DCS or Generic short/long write command
Jerome Coutant 1:3e58f8a39705 1597 * @param NbrParams: Number of parameters. It indicates the write command mode:
Jerome Coutant 0:c0f3bbab73d2 1598 * If inferior to 2, a long write command is performed else short.
Jerome Coutant 0:c0f3bbab73d2 1599 * @param pParams: Pointer to parameter values table.
Jerome Coutant 0:c0f3bbab73d2 1600 * @retval HAL status
Jerome Coutant 0:c0f3bbab73d2 1601 */
Jerome Coutant 0:c0f3bbab73d2 1602 void DSI_IO_WriteCmd(uint32_t NbrParams, uint8_t *pParams)
Jerome Coutant 0:c0f3bbab73d2 1603 {
Jerome Coutant 0:c0f3bbab73d2 1604 if(NbrParams <= 1)
Jerome Coutant 0:c0f3bbab73d2 1605 {
Jerome Coutant 0:c0f3bbab73d2 1606 HAL_DSI_ShortWrite(&hdsi_discovery, LCD_OTM8009A_ID, DSI_DCS_SHORT_PKT_WRITE_P1, pParams[0], pParams[1]);
Jerome Coutant 0:c0f3bbab73d2 1607 }
Jerome Coutant 0:c0f3bbab73d2 1608 else
Jerome Coutant 0:c0f3bbab73d2 1609 {
Jerome Coutant 0:c0f3bbab73d2 1610 HAL_DSI_LongWrite(&hdsi_discovery, LCD_OTM8009A_ID, DSI_DCS_LONG_PKT_WRITE, NbrParams, pParams[NbrParams], pParams);
Jerome Coutant 0:c0f3bbab73d2 1611 }
Jerome Coutant 0:c0f3bbab73d2 1612 }
Jerome Coutant 0:c0f3bbab73d2 1613
Jerome Coutant 0:c0f3bbab73d2 1614 /**
Jerome Coutant 0:c0f3bbab73d2 1615 * @brief Returns the ID of connected screen by checking the HDMI
Jerome Coutant 0:c0f3bbab73d2 1616 * (adv7533 component) ID or LCD DSI (via TS ID) ID.
Jerome Coutant 0:c0f3bbab73d2 1617 * @retval LCD ID
Jerome Coutant 0:c0f3bbab73d2 1618 */
Jerome Coutant 0:c0f3bbab73d2 1619 static uint16_t LCD_IO_GetID(void)
Jerome Coutant 0:c0f3bbab73d2 1620 {
Jerome Coutant 0:c0f3bbab73d2 1621 #if defined(USE_LCD_HDMI)
Jerome Coutant 0:c0f3bbab73d2 1622 HDMI_IO_Init();
Jerome Coutant 0:c0f3bbab73d2 1623
Jerome Coutant 0:c0f3bbab73d2 1624 HDMI_IO_Delay(60);
Jerome Coutant 0:c0f3bbab73d2 1625
Jerome Coutant 0:c0f3bbab73d2 1626 if(ADV7533_ID == adv7533_drv.ReadID(ADV7533_CEC_DSI_I2C_ADDR))
Jerome Coutant 0:c0f3bbab73d2 1627 {
Jerome Coutant 0:c0f3bbab73d2 1628 return ADV7533_ID;
Jerome Coutant 0:c0f3bbab73d2 1629 }
Jerome Coutant 0:c0f3bbab73d2 1630 else if(HDMI_IO_Read(LCD_DSI_ADDRESS, LCD_DSI_ID_REG) == LCD_DSI_ID)
Jerome Coutant 0:c0f3bbab73d2 1631 {
Jerome Coutant 0:c0f3bbab73d2 1632 return LCD_DSI_ID;
Jerome Coutant 0:c0f3bbab73d2 1633 }
Jerome Coutant 0:c0f3bbab73d2 1634 else
Jerome Coutant 0:c0f3bbab73d2 1635 {
Jerome Coutant 0:c0f3bbab73d2 1636 return 0;
Jerome Coutant 0:c0f3bbab73d2 1637 }
Jerome Coutant 0:c0f3bbab73d2 1638 #else
Jerome Coutant 0:c0f3bbab73d2 1639 return LCD_DSI_ID;
Jerome Coutant 0:c0f3bbab73d2 1640 #endif /* USE_LCD_HDMI */
Jerome Coutant 0:c0f3bbab73d2 1641 }
Jerome Coutant 0:c0f3bbab73d2 1642
Jerome Coutant 0:c0f3bbab73d2 1643 /*******************************************************************************
Jerome Coutant 0:c0f3bbab73d2 1644 LTDC, DMA2D and DSI BSP Routines
Jerome Coutant 0:c0f3bbab73d2 1645 *******************************************************************************/
Jerome Coutant 0:c0f3bbab73d2 1646 /**
Jerome Coutant 0:c0f3bbab73d2 1647 * @brief De-Initializes the BSP LCD Msp
Jerome Coutant 0:c0f3bbab73d2 1648 * Application can surcharge if needed this function implementation.
Jerome Coutant 0:c0f3bbab73d2 1649 */
Jerome Coutant 0:c0f3bbab73d2 1650 __weak void BSP_LCD_MspDeInit(void)
Jerome Coutant 0:c0f3bbab73d2 1651 {
Jerome Coutant 0:c0f3bbab73d2 1652 /** @brief Disable IRQ of LTDC IP */
Jerome Coutant 0:c0f3bbab73d2 1653 HAL_NVIC_DisableIRQ(LTDC_IRQn);
Jerome Coutant 0:c0f3bbab73d2 1654
Jerome Coutant 0:c0f3bbab73d2 1655 /** @brief Disable IRQ of DMA2D IP */
Jerome Coutant 0:c0f3bbab73d2 1656 HAL_NVIC_DisableIRQ(DMA2D_IRQn);
Jerome Coutant 0:c0f3bbab73d2 1657
Jerome Coutant 0:c0f3bbab73d2 1658 /** @brief Disable IRQ of DSI IP */
Jerome Coutant 0:c0f3bbab73d2 1659 HAL_NVIC_DisableIRQ(DSI_IRQn);
Jerome Coutant 0:c0f3bbab73d2 1660
Jerome Coutant 0:c0f3bbab73d2 1661 /** @brief Force and let in reset state LTDC, DMA2D and DSI Host + Wrapper IPs */
Jerome Coutant 0:c0f3bbab73d2 1662 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1663 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1664 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1665
Jerome Coutant 0:c0f3bbab73d2 1666 /** @brief Disable the LTDC, DMA2D and DSI Host and Wrapper clocks */
Jerome Coutant 0:c0f3bbab73d2 1667 __HAL_RCC_LTDC_CLK_DISABLE();
Jerome Coutant 0:c0f3bbab73d2 1668 __HAL_RCC_DMA2D_CLK_DISABLE();
Jerome Coutant 0:c0f3bbab73d2 1669 __HAL_RCC_DSI_CLK_DISABLE();
Jerome Coutant 0:c0f3bbab73d2 1670 }
Jerome Coutant 0:c0f3bbab73d2 1671
Jerome Coutant 0:c0f3bbab73d2 1672 /**
Jerome Coutant 0:c0f3bbab73d2 1673 * @brief Initialize the BSP LCD Msp.
Jerome Coutant 0:c0f3bbab73d2 1674 * Application can surcharge if needed this function implementation
Jerome Coutant 0:c0f3bbab73d2 1675 */
Jerome Coutant 0:c0f3bbab73d2 1676 __weak void BSP_LCD_MspInit(void)
Jerome Coutant 0:c0f3bbab73d2 1677 {
Jerome Coutant 0:c0f3bbab73d2 1678 /** @brief Enable the LTDC clock */
Jerome Coutant 0:c0f3bbab73d2 1679 __HAL_RCC_LTDC_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 1680
Jerome Coutant 0:c0f3bbab73d2 1681 /** @brief Toggle Sw reset of LTDC IP */
Jerome Coutant 0:c0f3bbab73d2 1682 __HAL_RCC_LTDC_FORCE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1683 __HAL_RCC_LTDC_RELEASE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1684
Jerome Coutant 0:c0f3bbab73d2 1685 /** @brief Enable the DMA2D clock */
Jerome Coutant 0:c0f3bbab73d2 1686 __HAL_RCC_DMA2D_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 1687
Jerome Coutant 0:c0f3bbab73d2 1688 /** @brief Toggle Sw reset of DMA2D IP */
Jerome Coutant 0:c0f3bbab73d2 1689 __HAL_RCC_DMA2D_FORCE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1690 __HAL_RCC_DMA2D_RELEASE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1691
Jerome Coutant 0:c0f3bbab73d2 1692 /** @brief Enable DSI Host and wrapper clocks */
Jerome Coutant 0:c0f3bbab73d2 1693 __HAL_RCC_DSI_CLK_ENABLE();
Jerome Coutant 0:c0f3bbab73d2 1694
Jerome Coutant 0:c0f3bbab73d2 1695 /** @brief Soft Reset the DSI Host and wrapper */
Jerome Coutant 0:c0f3bbab73d2 1696 __HAL_RCC_DSI_FORCE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1697 __HAL_RCC_DSI_RELEASE_RESET();
Jerome Coutant 0:c0f3bbab73d2 1698
Jerome Coutant 0:c0f3bbab73d2 1699 /** @brief NVIC configuration for LTDC interrupt that is now enabled */
Jerome Coutant 0:c0f3bbab73d2 1700 HAL_NVIC_SetPriority(LTDC_IRQn, 3, 0);
Jerome Coutant 0:c0f3bbab73d2 1701 HAL_NVIC_EnableIRQ(LTDC_IRQn);
Jerome Coutant 0:c0f3bbab73d2 1702
Jerome Coutant 0:c0f3bbab73d2 1703 /** @brief NVIC configuration for DMA2D interrupt that is now enabled */
Jerome Coutant 0:c0f3bbab73d2 1704 HAL_NVIC_SetPriority(DMA2D_IRQn, 3, 0);
Jerome Coutant 0:c0f3bbab73d2 1705 HAL_NVIC_EnableIRQ(DMA2D_IRQn);
Jerome Coutant 0:c0f3bbab73d2 1706
Jerome Coutant 0:c0f3bbab73d2 1707 /** @brief NVIC configuration for DSI interrupt that is now enabled */
Jerome Coutant 0:c0f3bbab73d2 1708 HAL_NVIC_SetPriority(DSI_IRQn, 3, 0);
Jerome Coutant 0:c0f3bbab73d2 1709 HAL_NVIC_EnableIRQ(DSI_IRQn);
Jerome Coutant 0:c0f3bbab73d2 1710 }
Jerome Coutant 0:c0f3bbab73d2 1711
Jerome Coutant 0:c0f3bbab73d2 1712 /**
Jerome Coutant 0:c0f3bbab73d2 1713 * @brief Draws a pixel on LCD.
Jerome Coutant 0:c0f3bbab73d2 1714 * @param Xpos: X position
Jerome Coutant 0:c0f3bbab73d2 1715 * @param Ypos: Y position
Jerome Coutant 0:c0f3bbab73d2 1716 * @param RGB_Code: Pixel color in ARGB mode (8-8-8-8)
Jerome Coutant 0:c0f3bbab73d2 1717 */
Jerome Coutant 0:c0f3bbab73d2 1718 void BSP_LCD_DrawPixel(uint16_t Xpos, uint16_t Ypos, uint32_t RGB_Code)
Jerome Coutant 0:c0f3bbab73d2 1719 {
Jerome Coutant 0:c0f3bbab73d2 1720 /* Write data value to all SDRAM memory */
Jerome Coutant 0:c0f3bbab73d2 1721 *(__IO uint32_t*) (hltdc_discovery.LayerCfg[ActiveLayer].FBStartAdress + (4*(Ypos*BSP_LCD_GetXSize() + Xpos))) = RGB_Code;
Jerome Coutant 0:c0f3bbab73d2 1722 }
Jerome Coutant 0:c0f3bbab73d2 1723
Jerome Coutant 0:c0f3bbab73d2 1724
Jerome Coutant 0:c0f3bbab73d2 1725 /**
Jerome Coutant 0:c0f3bbab73d2 1726 * @brief Draws a character on LCD.
Jerome Coutant 0:c0f3bbab73d2 1727 * @param Xpos: Line where to display the character shape
Jerome Coutant 0:c0f3bbab73d2 1728 * @param Ypos: Start column address
Jerome Coutant 0:c0f3bbab73d2 1729 * @param c: Pointer to the character data
Jerome Coutant 0:c0f3bbab73d2 1730 */
Jerome Coutant 0:c0f3bbab73d2 1731 static void DrawChar(uint16_t Xpos, uint16_t Ypos, const uint8_t *c)
Jerome Coutant 0:c0f3bbab73d2 1732 {
Jerome Coutant 0:c0f3bbab73d2 1733 uint32_t i = 0, j = 0;
Jerome Coutant 0:c0f3bbab73d2 1734 uint16_t height, width;
Jerome Coutant 0:c0f3bbab73d2 1735 uint8_t offset;
Jerome Coutant 0:c0f3bbab73d2 1736 uint8_t *pchar;
Jerome Coutant 0:c0f3bbab73d2 1737 uint32_t line;
Jerome Coutant 0:c0f3bbab73d2 1738
Jerome Coutant 0:c0f3bbab73d2 1739 height = DrawProp[ActiveLayer].pFont->Height;
Jerome Coutant 0:c0f3bbab73d2 1740 width = DrawProp[ActiveLayer].pFont->Width;
Jerome Coutant 0:c0f3bbab73d2 1741
Jerome Coutant 0:c0f3bbab73d2 1742 offset = 8 *((width + 7)/8) - width ;
Jerome Coutant 0:c0f3bbab73d2 1743
Jerome Coutant 0:c0f3bbab73d2 1744 for(i = 0; i < height; i++)
Jerome Coutant 0:c0f3bbab73d2 1745 {
Jerome Coutant 0:c0f3bbab73d2 1746 pchar = ((uint8_t *)c + (width + 7)/8 * i);
Jerome Coutant 0:c0f3bbab73d2 1747
Jerome Coutant 0:c0f3bbab73d2 1748 switch(((width + 7)/8))
Jerome Coutant 0:c0f3bbab73d2 1749 {
Jerome Coutant 0:c0f3bbab73d2 1750
Jerome Coutant 0:c0f3bbab73d2 1751 case 1:
Jerome Coutant 0:c0f3bbab73d2 1752 line = pchar[0];
Jerome Coutant 0:c0f3bbab73d2 1753 break;
Jerome Coutant 0:c0f3bbab73d2 1754
Jerome Coutant 0:c0f3bbab73d2 1755 case 2:
Jerome Coutant 0:c0f3bbab73d2 1756 line = (pchar[0]<< 8) | pchar[1];
Jerome Coutant 0:c0f3bbab73d2 1757 break;
Jerome Coutant 0:c0f3bbab73d2 1758
Jerome Coutant 0:c0f3bbab73d2 1759 case 3:
Jerome Coutant 0:c0f3bbab73d2 1760 default:
Jerome Coutant 0:c0f3bbab73d2 1761 line = (pchar[0]<< 16) | (pchar[1]<< 8) | pchar[2];
Jerome Coutant 0:c0f3bbab73d2 1762 break;
Jerome Coutant 0:c0f3bbab73d2 1763 }
Jerome Coutant 0:c0f3bbab73d2 1764
Jerome Coutant 0:c0f3bbab73d2 1765 for (j = 0; j < width; j++)
Jerome Coutant 0:c0f3bbab73d2 1766 {
Jerome Coutant 0:c0f3bbab73d2 1767 if(line & (1 << (width- j + offset- 1)))
Jerome Coutant 0:c0f3bbab73d2 1768 {
Jerome Coutant 0:c0f3bbab73d2 1769 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].TextColor);
Jerome Coutant 0:c0f3bbab73d2 1770 }
Jerome Coutant 0:c0f3bbab73d2 1771 else
Jerome Coutant 0:c0f3bbab73d2 1772 {
Jerome Coutant 0:c0f3bbab73d2 1773 BSP_LCD_DrawPixel((Xpos + j), Ypos, DrawProp[ActiveLayer].BackColor);
Jerome Coutant 0:c0f3bbab73d2 1774 }
Jerome Coutant 0:c0f3bbab73d2 1775 }
Jerome Coutant 0:c0f3bbab73d2 1776 Ypos++;
Jerome Coutant 0:c0f3bbab73d2 1777 }
Jerome Coutant 0:c0f3bbab73d2 1778 }
Jerome Coutant 0:c0f3bbab73d2 1779
Jerome Coutant 0:c0f3bbab73d2 1780 /**
Jerome Coutant 0:c0f3bbab73d2 1781 * @brief Fills a triangle (between 3 points).
Jerome Coutant 0:c0f3bbab73d2 1782 * @param x1: Point 1 X position
Jerome Coutant 0:c0f3bbab73d2 1783 * @param y1: Point 1 Y position
Jerome Coutant 0:c0f3bbab73d2 1784 * @param x2: Point 2 X position
Jerome Coutant 0:c0f3bbab73d2 1785 * @param y2: Point 2 Y position
Jerome Coutant 0:c0f3bbab73d2 1786 * @param x3: Point 3 X position
Jerome Coutant 0:c0f3bbab73d2 1787 * @param y3: Point 3 Y position
Jerome Coutant 0:c0f3bbab73d2 1788 */
Jerome Coutant 0:c0f3bbab73d2 1789 static void FillTriangle(uint16_t x1, uint16_t x2, uint16_t x3, uint16_t y1, uint16_t y2, uint16_t y3)
Jerome Coutant 0:c0f3bbab73d2 1790 {
Jerome Coutant 0:c0f3bbab73d2 1791 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
Jerome Coutant 0:c0f3bbab73d2 1792 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
Jerome Coutant 0:c0f3bbab73d2 1793 curpixel = 0;
Jerome Coutant 0:c0f3bbab73d2 1794
Jerome Coutant 0:c0f3bbab73d2 1795 deltax = ABS(x2 - x1); /* The difference between the x's */
Jerome Coutant 0:c0f3bbab73d2 1796 deltay = ABS(y2 - y1); /* The difference between the y's */
Jerome Coutant 0:c0f3bbab73d2 1797 x = x1; /* Start x off at the first pixel */
Jerome Coutant 0:c0f3bbab73d2 1798 y = y1; /* Start y off at the first pixel */
Jerome Coutant 0:c0f3bbab73d2 1799
Jerome Coutant 0:c0f3bbab73d2 1800 if (x2 >= x1) /* The x-values are increasing */
Jerome Coutant 0:c0f3bbab73d2 1801 {
Jerome Coutant 0:c0f3bbab73d2 1802 xinc1 = 1;
Jerome Coutant 0:c0f3bbab73d2 1803 xinc2 = 1;
Jerome Coutant 0:c0f3bbab73d2 1804 }
Jerome Coutant 0:c0f3bbab73d2 1805 else /* The x-values are decreasing */
Jerome Coutant 0:c0f3bbab73d2 1806 {
Jerome Coutant 0:c0f3bbab73d2 1807 xinc1 = -1;
Jerome Coutant 0:c0f3bbab73d2 1808 xinc2 = -1;
Jerome Coutant 0:c0f3bbab73d2 1809 }
Jerome Coutant 0:c0f3bbab73d2 1810
Jerome Coutant 0:c0f3bbab73d2 1811 if (y2 >= y1) /* The y-values are increasing */
Jerome Coutant 0:c0f3bbab73d2 1812 {
Jerome Coutant 0:c0f3bbab73d2 1813 yinc1 = 1;
Jerome Coutant 0:c0f3bbab73d2 1814 yinc2 = 1;
Jerome Coutant 0:c0f3bbab73d2 1815 }
Jerome Coutant 0:c0f3bbab73d2 1816 else /* The y-values are decreasing */
Jerome Coutant 0:c0f3bbab73d2 1817 {
Jerome Coutant 0:c0f3bbab73d2 1818 yinc1 = -1;
Jerome Coutant 0:c0f3bbab73d2 1819 yinc2 = -1;
Jerome Coutant 0:c0f3bbab73d2 1820 }
Jerome Coutant 0:c0f3bbab73d2 1821
Jerome Coutant 0:c0f3bbab73d2 1822 if (deltax >= deltay) /* There is at least one x-value for every y-value */
Jerome Coutant 0:c0f3bbab73d2 1823 {
Jerome Coutant 0:c0f3bbab73d2 1824 xinc1 = 0; /* Don't change the x when numerator >= denominator */
Jerome Coutant 0:c0f3bbab73d2 1825 yinc2 = 0; /* Don't change the y for every iteration */
Jerome Coutant 0:c0f3bbab73d2 1826 den = deltax;
Jerome Coutant 0:c0f3bbab73d2 1827 num = deltax / 2;
Jerome Coutant 0:c0f3bbab73d2 1828 numadd = deltay;
Jerome Coutant 0:c0f3bbab73d2 1829 numpixels = deltax; /* There are more x-values than y-values */
Jerome Coutant 0:c0f3bbab73d2 1830 }
Jerome Coutant 0:c0f3bbab73d2 1831 else /* There is at least one y-value for every x-value */
Jerome Coutant 0:c0f3bbab73d2 1832 {
Jerome Coutant 0:c0f3bbab73d2 1833 xinc2 = 0; /* Don't change the x for every iteration */
Jerome Coutant 0:c0f3bbab73d2 1834 yinc1 = 0; /* Don't change the y when numerator >= denominator */
Jerome Coutant 0:c0f3bbab73d2 1835 den = deltay;
Jerome Coutant 0:c0f3bbab73d2 1836 num = deltay / 2;
Jerome Coutant 0:c0f3bbab73d2 1837 numadd = deltax;
Jerome Coutant 0:c0f3bbab73d2 1838 numpixels = deltay; /* There are more y-values than x-values */
Jerome Coutant 0:c0f3bbab73d2 1839 }
Jerome Coutant 0:c0f3bbab73d2 1840
Jerome Coutant 0:c0f3bbab73d2 1841 for (curpixel = 0; curpixel <= numpixels; curpixel++)
Jerome Coutant 0:c0f3bbab73d2 1842 {
Jerome Coutant 0:c0f3bbab73d2 1843 BSP_LCD_DrawLine(x, y, x3, y3);
Jerome Coutant 0:c0f3bbab73d2 1844
Jerome Coutant 0:c0f3bbab73d2 1845 num += numadd; /* Increase the numerator by the top of the fraction */
Jerome Coutant 0:c0f3bbab73d2 1846 if (num >= den) /* Check if numerator >= denominator */
Jerome Coutant 0:c0f3bbab73d2 1847 {
Jerome Coutant 0:c0f3bbab73d2 1848 num -= den; /* Calculate the new numerator value */
Jerome Coutant 0:c0f3bbab73d2 1849 x += xinc1; /* Change the x as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1850 y += yinc1; /* Change the y as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1851 }
Jerome Coutant 0:c0f3bbab73d2 1852 x += xinc2; /* Change the x as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1853 y += yinc2; /* Change the y as appropriate */
Jerome Coutant 0:c0f3bbab73d2 1854 }
Jerome Coutant 0:c0f3bbab73d2 1855 }
Jerome Coutant 0:c0f3bbab73d2 1856
Jerome Coutant 0:c0f3bbab73d2 1857 /**
Jerome Coutant 0:c0f3bbab73d2 1858 * @brief Fills a buffer.
Jerome Coutant 0:c0f3bbab73d2 1859 * @param LayerIndex: Layer index
Jerome Coutant 0:c0f3bbab73d2 1860 * @param pDst: Pointer to destination buffer
Jerome Coutant 0:c0f3bbab73d2 1861 * @param xSize: Buffer width
Jerome Coutant 0:c0f3bbab73d2 1862 * @param ySize: Buffer height
Jerome Coutant 0:c0f3bbab73d2 1863 * @param OffLine: Offset
Jerome Coutant 0:c0f3bbab73d2 1864 * @param ColorIndex: Color index
Jerome Coutant 0:c0f3bbab73d2 1865 */
Jerome Coutant 0:c0f3bbab73d2 1866 static void LL_FillBuffer(uint32_t LayerIndex, void *pDst, uint32_t xSize, uint32_t ySize, uint32_t OffLine, uint32_t ColorIndex)
Jerome Coutant 0:c0f3bbab73d2 1867 {
Jerome Coutant 0:c0f3bbab73d2 1868 /* Register to memory mode with ARGB8888 as color Mode */
Jerome Coutant 0:c0f3bbab73d2 1869 hdma2d_discovery.Init.Mode = DMA2D_R2M;
Jerome Coutant 0:c0f3bbab73d2 1870 hdma2d_discovery.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
Jerome Coutant 0:c0f3bbab73d2 1871 hdma2d_discovery.Init.OutputOffset = OffLine;
Jerome Coutant 0:c0f3bbab73d2 1872
Jerome Coutant 0:c0f3bbab73d2 1873 hdma2d_discovery.Instance = DMA2D;
Jerome Coutant 0:c0f3bbab73d2 1874
Jerome Coutant 0:c0f3bbab73d2 1875 /* DMA2D Initialization */
Jerome Coutant 0:c0f3bbab73d2 1876 if(HAL_DMA2D_Init(&hdma2d_discovery) == HAL_OK)
Jerome Coutant 0:c0f3bbab73d2 1877 {
Jerome Coutant 0:c0f3bbab73d2 1878 if(HAL_DMA2D_ConfigLayer(&hdma2d_discovery, LayerIndex) == HAL_OK)
Jerome Coutant 0:c0f3bbab73d2 1879 {
Jerome Coutant 0:c0f3bbab73d2 1880 if (HAL_DMA2D_Start(&hdma2d_discovery, ColorIndex, (uint32_t)pDst, xSize, ySize) == HAL_OK)
Jerome Coutant 0:c0f3bbab73d2 1881 {
Jerome Coutant 0:c0f3bbab73d2 1882 /* Polling For DMA transfer */
Jerome Coutant 0:c0f3bbab73d2 1883 HAL_DMA2D_PollForTransfer(&hdma2d_discovery, 10);
Jerome Coutant 0:c0f3bbab73d2 1884 }
Jerome Coutant 0:c0f3bbab73d2 1885 }
Jerome Coutant 0:c0f3bbab73d2 1886 }
Jerome Coutant 0:c0f3bbab73d2 1887 }
Jerome Coutant 0:c0f3bbab73d2 1888
Jerome Coutant 0:c0f3bbab73d2 1889 /**
Jerome Coutant 0:c0f3bbab73d2 1890 * @brief Converts a line to an ARGB8888 pixel format.
Jerome Coutant 0:c0f3bbab73d2 1891 * @param pSrc: Pointer to source buffer
Jerome Coutant 0:c0f3bbab73d2 1892 * @param pDst: Output color
Jerome Coutant 0:c0f3bbab73d2 1893 * @param xSize: Buffer width
Jerome Coutant 0:c0f3bbab73d2 1894 * @param ColorMode: Input color mode
Jerome Coutant 0:c0f3bbab73d2 1895 */
Jerome Coutant 0:c0f3bbab73d2 1896 static void LL_ConvertLineToARGB8888(void *pSrc, void *pDst, uint32_t xSize, uint32_t ColorMode)
Jerome Coutant 0:c0f3bbab73d2 1897 {
Jerome Coutant 0:c0f3bbab73d2 1898 /* Configure the DMA2D Mode, Color Mode and output offset */
Jerome Coutant 0:c0f3bbab73d2 1899 hdma2d_discovery.Init.Mode = DMA2D_M2M_PFC;
Jerome Coutant 0:c0f3bbab73d2 1900 hdma2d_discovery.Init.ColorMode = DMA2D_OUTPUT_ARGB8888;
Jerome Coutant 0:c0f3bbab73d2 1901 hdma2d_discovery.Init.OutputOffset = 0;
Jerome Coutant 0:c0f3bbab73d2 1902
Jerome Coutant 0:c0f3bbab73d2 1903 /* Foreground Configuration */
Jerome Coutant 0:c0f3bbab73d2 1904 hdma2d_discovery.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
Jerome Coutant 0:c0f3bbab73d2 1905 hdma2d_discovery.LayerCfg[1].InputAlpha = 0xFF;
Jerome Coutant 0:c0f3bbab73d2 1906 hdma2d_discovery.LayerCfg[1].InputColorMode = ColorMode;
Jerome Coutant 0:c0f3bbab73d2 1907 hdma2d_discovery.LayerCfg[1].InputOffset = 0;
Jerome Coutant 0:c0f3bbab73d2 1908
Jerome Coutant 0:c0f3bbab73d2 1909 hdma2d_discovery.Instance = DMA2D;
Jerome Coutant 0:c0f3bbab73d2 1910
Jerome Coutant 0:c0f3bbab73d2 1911 /* DMA2D Initialization */
Jerome Coutant 0:c0f3bbab73d2 1912 if(HAL_DMA2D_Init(&hdma2d_discovery) == HAL_OK)
Jerome Coutant 0:c0f3bbab73d2 1913 {
Jerome Coutant 0:c0f3bbab73d2 1914 if(HAL_DMA2D_ConfigLayer(&hdma2d_discovery, 1) == HAL_OK)
Jerome Coutant 0:c0f3bbab73d2 1915 {
Jerome Coutant 0:c0f3bbab73d2 1916 if (HAL_DMA2D_Start(&hdma2d_discovery, (uint32_t)pSrc, (uint32_t)pDst, xSize, 1) == HAL_OK)
Jerome Coutant 0:c0f3bbab73d2 1917 {
Jerome Coutant 0:c0f3bbab73d2 1918 /* Polling For DMA transfer */
Jerome Coutant 0:c0f3bbab73d2 1919 HAL_DMA2D_PollForTransfer(&hdma2d_discovery, 10);
Jerome Coutant 0:c0f3bbab73d2 1920 }
Jerome Coutant 0:c0f3bbab73d2 1921 }
Jerome Coutant 0:c0f3bbab73d2 1922 }
Jerome Coutant 0:c0f3bbab73d2 1923 }
Jerome Coutant 0:c0f3bbab73d2 1924
Jerome Coutant 0:c0f3bbab73d2 1925 /**
Jerome Coutant 0:c0f3bbab73d2 1926 * @}
Jerome Coutant 0:c0f3bbab73d2 1927 */
Jerome Coutant 0:c0f3bbab73d2 1928
Jerome Coutant 0:c0f3bbab73d2 1929 /**
Jerome Coutant 0:c0f3bbab73d2 1930 * @}
Jerome Coutant 0:c0f3bbab73d2 1931 */
Jerome Coutant 0:c0f3bbab73d2 1932
Jerome Coutant 0:c0f3bbab73d2 1933 /**
Jerome Coutant 0:c0f3bbab73d2 1934 * @}
Jerome Coutant 0:c0f3bbab73d2 1935 */
Jerome Coutant 0:c0f3bbab73d2 1936
Jerome Coutant 0:c0f3bbab73d2 1937 /**
Jerome Coutant 0:c0f3bbab73d2 1938 * @}
Jerome Coutant 0:c0f3bbab73d2 1939 */
Jerome Coutant 0:c0f3bbab73d2 1940
Jerome Coutant 0:c0f3bbab73d2 1941 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/