BSP driver for DISCO_L496AG

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

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:d83f1c8ca282 1 /**
bcostm 0:d83f1c8ca282 2 ******************************************************************************
bcostm 0:d83f1c8ca282 3 * @file st7789h2.c
bcostm 0:d83f1c8ca282 4 * @author MCD Application Team
bcostm 0:d83f1c8ca282 5 * @brief This file includes the LCD driver for st7789h2 LCD.
bcostm 0:d83f1c8ca282 6 ******************************************************************************
bcostm 0:d83f1c8ca282 7 * @attention
bcostm 0:d83f1c8ca282 8 *
Jerome Coutant 2:106c7b82e064 9 * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
Jerome Coutant 2:106c7b82e064 10 * All rights reserved.</center></h2>
bcostm 0:d83f1c8ca282 11 *
Jerome Coutant 2:106c7b82e064 12 * This software component is licensed by ST under BSD 3-Clause license,
Jerome Coutant 2:106c7b82e064 13 * the "License"; You may not use this file except in compliance with the
Jerome Coutant 2:106c7b82e064 14 * License. You may obtain a copy of the License at:
Jerome Coutant 2:106c7b82e064 15 * opensource.org/licenses/BSD-3-Clause
bcostm 0:d83f1c8ca282 16 *
bcostm 0:d83f1c8ca282 17 ******************************************************************************
bcostm 0:d83f1c8ca282 18 */
bcostm 0:d83f1c8ca282 19
bcostm 0:d83f1c8ca282 20 /* Includes ------------------------------------------------------------------*/
bcostm 0:d83f1c8ca282 21 #include "st7789h2.h"
bcostm 0:d83f1c8ca282 22
bcostm 0:d83f1c8ca282 23 /** @addtogroup BSP
bcostm 0:d83f1c8ca282 24 * @{
bcostm 0:d83f1c8ca282 25 */
bcostm 0:d83f1c8ca282 26
bcostm 0:d83f1c8ca282 27 /** @addtogroup Components
bcostm 0:d83f1c8ca282 28 * @{
bcostm 0:d83f1c8ca282 29 */
bcostm 0:d83f1c8ca282 30
bcostm 0:d83f1c8ca282 31 /** @defgroup ST7789H2
bcostm 0:d83f1c8ca282 32 * @brief This file provides a set of functions needed to drive the
bcostm 0:d83f1c8ca282 33 * FRIDA FRD154BP2901 LCD.
bcostm 0:d83f1c8ca282 34 * @{
bcostm 0:d83f1c8ca282 35 */
bcostm 0:d83f1c8ca282 36
bcostm 0:d83f1c8ca282 37 /** @defgroup ST7789H2_Private_TypesDefinitions ST7789H2 Private TypesDefinitions
bcostm 0:d83f1c8ca282 38 * @{
bcostm 0:d83f1c8ca282 39 */
bcostm 0:d83f1c8ca282 40 typedef struct {
bcostm 0:d83f1c8ca282 41 uint8_t red;
bcostm 0:d83f1c8ca282 42 uint8_t green;
bcostm 0:d83f1c8ca282 43 uint8_t blue;
bcostm 0:d83f1c8ca282 44 } ST7789H2_Rgb888;
bcostm 0:d83f1c8ca282 45
bcostm 0:d83f1c8ca282 46 /**
bcostm 0:d83f1c8ca282 47 * @}
bcostm 0:d83f1c8ca282 48 */
bcostm 0:d83f1c8ca282 49
bcostm 0:d83f1c8ca282 50 /** @defgroup ST7789H2_Private_Defines ST7789H2 Private Defines
bcostm 0:d83f1c8ca282 51 * @{
bcostm 0:d83f1c8ca282 52 */
bcostm 0:d83f1c8ca282 53
bcostm 0:d83f1c8ca282 54 /**
bcostm 0:d83f1c8ca282 55 * @}
bcostm 0:d83f1c8ca282 56 */
bcostm 0:d83f1c8ca282 57
bcostm 0:d83f1c8ca282 58 /** @defgroup ST7789H2_Private_Macros ST7789H2 Private Macros
bcostm 0:d83f1c8ca282 59 * @{
bcostm 0:d83f1c8ca282 60 */
bcostm 0:d83f1c8ca282 61
bcostm 0:d83f1c8ca282 62 /**
bcostm 0:d83f1c8ca282 63 * @}
bcostm 0:d83f1c8ca282 64 */
bcostm 0:d83f1c8ca282 65
bcostm 0:d83f1c8ca282 66 /** @defgroup ST7789H2_Private_Variables ST7789H2 Private Variables
bcostm 0:d83f1c8ca282 67 * @{
bcostm 0:d83f1c8ca282 68 */
bcostm 0:d83f1c8ca282 69 LCD_DrvTypeDef ST7789H2_drv =
bcostm 0:d83f1c8ca282 70 {
bcostm 0:d83f1c8ca282 71 ST7789H2_Init,
bcostm 0:d83f1c8ca282 72 ST7789H2_ReadID,
bcostm 0:d83f1c8ca282 73 ST7789H2_DisplayOn,
bcostm 0:d83f1c8ca282 74 ST7789H2_DisplayOff,
bcostm 0:d83f1c8ca282 75 ST7789H2_SetCursor,
bcostm 0:d83f1c8ca282 76 ST7789H2_WritePixel,
bcostm 0:d83f1c8ca282 77 ST7789H2_ReadPixel,
bcostm 0:d83f1c8ca282 78 ST7789H2_SetDisplayWindow,
bcostm 0:d83f1c8ca282 79 ST7789H2_DrawHLine,
bcostm 0:d83f1c8ca282 80 ST7789H2_DrawVLine,
bcostm 0:d83f1c8ca282 81 ST7789H2_GetLcdPixelWidth,
bcostm 0:d83f1c8ca282 82 ST7789H2_GetLcdPixelHeight,
bcostm 0:d83f1c8ca282 83 ST7789H2_DrawBitmap,
bcostm 0:d83f1c8ca282 84 ST7789H2_DrawRGBImage,
bcostm 0:d83f1c8ca282 85 };
bcostm 0:d83f1c8ca282 86
bcostm 0:d83f1c8ca282 87 static uint16_t WindowsXstart = 0;
bcostm 0:d83f1c8ca282 88 static uint16_t WindowsYstart = 0;
bcostm 0:d83f1c8ca282 89 static uint16_t WindowsXend = ST7789H2_LCD_PIXEL_WIDTH-1;
bcostm 0:d83f1c8ca282 90 static uint16_t WindowsYend = ST7789H2_LCD_PIXEL_HEIGHT-1;
bcostm 0:d83f1c8ca282 91 /**
bcostm 0:d83f1c8ca282 92 * @}
bcostm 0:d83f1c8ca282 93 */
bcostm 0:d83f1c8ca282 94
bcostm 0:d83f1c8ca282 95 /** @defgroup ST7789H2_Private_FunctionPrototypes ST7789H2 Private FunctionPrototypes
bcostm 0:d83f1c8ca282 96 * @{
bcostm 0:d83f1c8ca282 97 */
bcostm 0:d83f1c8ca282 98 static ST7789H2_Rgb888 ST7789H2_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos);
bcostm 0:d83f1c8ca282 99 static void ST7789H2_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata);
bcostm 0:d83f1c8ca282 100
bcostm 0:d83f1c8ca282 101 /**
bcostm 0:d83f1c8ca282 102 * @}
bcostm 0:d83f1c8ca282 103 */
bcostm 0:d83f1c8ca282 104
bcostm 0:d83f1c8ca282 105 /** @defgroup ST7789H2_Private_Functions ST7789H2 Private Functions
bcostm 0:d83f1c8ca282 106 * @{
bcostm 0:d83f1c8ca282 107 */
bcostm 0:d83f1c8ca282 108
bcostm 0:d83f1c8ca282 109 /**
bcostm 0:d83f1c8ca282 110 * @brief Initialize the st7789h2 LCD Component.
bcostm 0:d83f1c8ca282 111 * @param None
bcostm 0:d83f1c8ca282 112 * @retval None
bcostm 0:d83f1c8ca282 113 */
bcostm 0:d83f1c8ca282 114 void ST7789H2_Init(void)
bcostm 0:d83f1c8ca282 115 {
bcostm 0:d83f1c8ca282 116 uint8_t parameter[14];
bcostm 0:d83f1c8ca282 117
bcostm 0:d83f1c8ca282 118 /* Initialize st7789h2 low level bus layer ----------------------------------*/
bcostm 0:d83f1c8ca282 119 LCD_IO_Init();
bcostm 0:d83f1c8ca282 120 /* Sleep In Command */
bcostm 0:d83f1c8ca282 121 ST7789H2_WriteReg(ST7789H2_SLEEP_IN, (uint8_t*)NULL, 0);
bcostm 0:d83f1c8ca282 122 /* Wait for 10ms */
bcostm 0:d83f1c8ca282 123 LCD_IO_Delay(10);
bcostm 0:d83f1c8ca282 124
bcostm 0:d83f1c8ca282 125 /* SW Reset Command */
bcostm 0:d83f1c8ca282 126 ST7789H2_WriteReg(0x01, (uint8_t*)NULL, 0);
bcostm 0:d83f1c8ca282 127 /* Wait for 200ms */
bcostm 0:d83f1c8ca282 128 LCD_IO_Delay(200);
bcostm 0:d83f1c8ca282 129
bcostm 0:d83f1c8ca282 130 /* Sleep Out Command */
bcostm 0:d83f1c8ca282 131 ST7789H2_WriteReg(ST7789H2_SLEEP_OUT, (uint8_t*)NULL, 0);
bcostm 0:d83f1c8ca282 132 /* Wait for 120ms */
bcostm 0:d83f1c8ca282 133 LCD_IO_Delay(120);
bcostm 0:d83f1c8ca282 134
bcostm 0:d83f1c8ca282 135 /* Normal display for Driver Down side */
bcostm 0:d83f1c8ca282 136 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 137 ST7789H2_WriteReg(ST7789H2_NORMAL_DISPLAY, parameter, 1);
bcostm 0:d83f1c8ca282 138
bcostm 0:d83f1c8ca282 139 /* Color mode 16bits/pixel */
bcostm 0:d83f1c8ca282 140 parameter[0] = 0x05;
bcostm 0:d83f1c8ca282 141 ST7789H2_WriteReg(ST7789H2_COLOR_MODE, parameter, 1);
bcostm 0:d83f1c8ca282 142
bcostm 0:d83f1c8ca282 143 /* Display inversion On */
bcostm 0:d83f1c8ca282 144 ST7789H2_WriteReg(ST7789H2_DISPLAY_INVERSION, (uint8_t*)NULL, 0);
bcostm 0:d83f1c8ca282 145
bcostm 0:d83f1c8ca282 146 /* Set Column address CASET */
bcostm 0:d83f1c8ca282 147 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 148 parameter[1] = 0x00;
bcostm 0:d83f1c8ca282 149 parameter[2] = 0x00;
bcostm 0:d83f1c8ca282 150 parameter[3] = 0xEF;
bcostm 0:d83f1c8ca282 151 ST7789H2_WriteReg(ST7789H2_CASET, parameter, 4);
bcostm 0:d83f1c8ca282 152 /* Set Row address RASET */
bcostm 0:d83f1c8ca282 153 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 154 parameter[1] = 0x00;
bcostm 0:d83f1c8ca282 155 parameter[2] = 0x00;
bcostm 0:d83f1c8ca282 156 parameter[3] = 0xEF;
bcostm 0:d83f1c8ca282 157 ST7789H2_WriteReg(ST7789H2_RASET, parameter, 4);
bcostm 0:d83f1c8ca282 158
bcostm 0:d83f1c8ca282 159 /*--------------- ST7789H2 Frame rate setting -------------------------------*/
bcostm 0:d83f1c8ca282 160 /* PORCH control setting */
bcostm 0:d83f1c8ca282 161 parameter[0] = 0x0C;
bcostm 0:d83f1c8ca282 162 parameter[1] = 0x0C;
bcostm 0:d83f1c8ca282 163 parameter[2] = 0x00;
bcostm 0:d83f1c8ca282 164 parameter[3] = 0x33;
bcostm 0:d83f1c8ca282 165 parameter[4] = 0x33;
bcostm 0:d83f1c8ca282 166 ST7789H2_WriteReg(ST7789H2_PORCH_CTRL, parameter, 5);
bcostm 0:d83f1c8ca282 167
bcostm 0:d83f1c8ca282 168 /* GATE control setting */
bcostm 0:d83f1c8ca282 169 parameter[0] = 0x35;
bcostm 0:d83f1c8ca282 170 ST7789H2_WriteReg(ST7789H2_GATE_CTRL, parameter, 1);
bcostm 0:d83f1c8ca282 171
bcostm 0:d83f1c8ca282 172 /*--------------- ST7789H2 Power setting ------------------------------------*/
bcostm 0:d83f1c8ca282 173 /* VCOM setting */
bcostm 0:d83f1c8ca282 174 parameter[0] = 0x1F;
bcostm 0:d83f1c8ca282 175 ST7789H2_WriteReg(ST7789H2_VCOM_SET, parameter, 1);
bcostm 0:d83f1c8ca282 176
bcostm 0:d83f1c8ca282 177 /* LCM Control setting */
bcostm 0:d83f1c8ca282 178 parameter[0] = 0x2C;
bcostm 0:d83f1c8ca282 179 ST7789H2_WriteReg(ST7789H2_LCM_CTRL, parameter, 1);
bcostm 0:d83f1c8ca282 180
bcostm 0:d83f1c8ca282 181 /* VDV and VRH Command Enable */
bcostm 0:d83f1c8ca282 182 parameter[0] = 0x01;
bcostm 0:d83f1c8ca282 183 parameter[1] = 0xC3;
bcostm 0:d83f1c8ca282 184 ST7789H2_WriteReg(ST7789H2_VDV_VRH_EN, parameter, 2);
bcostm 0:d83f1c8ca282 185
bcostm 0:d83f1c8ca282 186 /* VDV Set */
bcostm 0:d83f1c8ca282 187 parameter[0] = 0x20;
bcostm 0:d83f1c8ca282 188 ST7789H2_WriteReg(ST7789H2_VDV_SET, parameter, 1);
bcostm 0:d83f1c8ca282 189
bcostm 0:d83f1c8ca282 190 /* Frame Rate Control in normal mode */
bcostm 0:d83f1c8ca282 191 parameter[0] = 0x0F;
bcostm 0:d83f1c8ca282 192 ST7789H2_WriteReg(ST7789H2_FR_CTRL, parameter, 1);
bcostm 0:d83f1c8ca282 193
bcostm 0:d83f1c8ca282 194 /* Power Control */
bcostm 0:d83f1c8ca282 195 parameter[0] = 0xA4;
bcostm 0:d83f1c8ca282 196 parameter[1] = 0xA1;
Jerome Coutant 2:106c7b82e064 197 ST7789H2_WriteReg(ST7789H2_POWER_CTRL, parameter, 2);
bcostm 0:d83f1c8ca282 198
bcostm 0:d83f1c8ca282 199 /*--------------- ST7789H2 Gamma setting ------------------------------------*/
bcostm 0:d83f1c8ca282 200 /* Positive Voltage Gamma Control */
bcostm 0:d83f1c8ca282 201 parameter[0] = 0xD0;
bcostm 0:d83f1c8ca282 202 parameter[1] = 0x08;
bcostm 0:d83f1c8ca282 203 parameter[2] = 0x11;
bcostm 0:d83f1c8ca282 204 parameter[3] = 0x08;
bcostm 0:d83f1c8ca282 205 parameter[4] = 0x0C;
bcostm 0:d83f1c8ca282 206 parameter[5] = 0x15;
bcostm 0:d83f1c8ca282 207 parameter[6] = 0x39;
bcostm 0:d83f1c8ca282 208 parameter[7] = 0x33;
bcostm 0:d83f1c8ca282 209 parameter[8] = 0x50;
bcostm 0:d83f1c8ca282 210 parameter[9] = 0x36;
bcostm 0:d83f1c8ca282 211 parameter[10] = 0x13;
bcostm 0:d83f1c8ca282 212 parameter[11] = 0x14;
bcostm 0:d83f1c8ca282 213 parameter[12] = 0x29;
bcostm 0:d83f1c8ca282 214 parameter[13] = 0x2D;
bcostm 0:d83f1c8ca282 215 ST7789H2_WriteReg(ST7789H2_PV_GAMMA_CTRL, parameter, 14);
bcostm 0:d83f1c8ca282 216
bcostm 0:d83f1c8ca282 217 /* Negative Voltage Gamma Control */
bcostm 0:d83f1c8ca282 218 parameter[0] = 0xD0;
bcostm 0:d83f1c8ca282 219 parameter[1] = 0x08;
bcostm 0:d83f1c8ca282 220 parameter[2] = 0x10;
bcostm 0:d83f1c8ca282 221 parameter[3] = 0x08;
bcostm 0:d83f1c8ca282 222 parameter[4] = 0x06;
bcostm 0:d83f1c8ca282 223 parameter[5] = 0x06;
bcostm 0:d83f1c8ca282 224 parameter[6] = 0x39;
bcostm 0:d83f1c8ca282 225 parameter[7] = 0x44;
bcostm 0:d83f1c8ca282 226 parameter[8] = 0x51;
bcostm 0:d83f1c8ca282 227 parameter[9] = 0x0B;
bcostm 0:d83f1c8ca282 228 parameter[10] = 0x16;
bcostm 0:d83f1c8ca282 229 parameter[11] = 0x14;
bcostm 0:d83f1c8ca282 230 parameter[12] = 0x2F;
bcostm 0:d83f1c8ca282 231 parameter[13] = 0x31;
bcostm 0:d83f1c8ca282 232 ST7789H2_WriteReg(ST7789H2_NV_GAMMA_CTRL, parameter, 14);
bcostm 0:d83f1c8ca282 233
bcostm 0:d83f1c8ca282 234 /* Display ON command */
bcostm 0:d83f1c8ca282 235 ST7789H2_DisplayOn();
bcostm 0:d83f1c8ca282 236
bcostm 0:d83f1c8ca282 237 /* Tearing Effect Line On: Option (00h:VSYNC Interface OFF, 01h:VSYNC Interface ON) */
bcostm 0:d83f1c8ca282 238 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 239 ST7789H2_WriteReg(ST7789H2_TEARING_EFFECT, parameter, 1);
bcostm 0:d83f1c8ca282 240
bcostm 0:d83f1c8ca282 241 }
bcostm 0:d83f1c8ca282 242
bcostm 0:d83f1c8ca282 243 /**
bcostm 0:d83f1c8ca282 244 * @brief Set the Display Orientation.
bcostm 0:d83f1c8ca282 245 * @param orientation: ST7789H2_ORIENTATION_PORTRAIT, ST7789H2_ORIENTATION_LANDSCAPE
bcostm 0:d83f1c8ca282 246 * or ST7789H2_ORIENTATION_LANDSCAPE_ROT180
bcostm 0:d83f1c8ca282 247 * @retval None
bcostm 0:d83f1c8ca282 248 */
bcostm 0:d83f1c8ca282 249 void ST7789H2_SetOrientation(uint32_t orientation)
bcostm 0:d83f1c8ca282 250 {
bcostm 0:d83f1c8ca282 251 uint8_t parameter[6];
bcostm 0:d83f1c8ca282 252
bcostm 0:d83f1c8ca282 253 if(orientation == ST7789H2_ORIENTATION_LANDSCAPE)
bcostm 0:d83f1c8ca282 254 {
bcostm 0:d83f1c8ca282 255 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 256 }
bcostm 0:d83f1c8ca282 257 else if(orientation == ST7789H2_ORIENTATION_LANDSCAPE_ROT180)
bcostm 0:d83f1c8ca282 258 {
bcostm 0:d83f1c8ca282 259 /* Vertical Scrolling Definition */
bcostm 0:d83f1c8ca282 260 /* TFA describes the Top Fixed Area */
bcostm 0:d83f1c8ca282 261 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 262 parameter[1] = 0x00;
bcostm 0:d83f1c8ca282 263 /* VSA describes the height of the Vertical Scrolling Area */
bcostm 0:d83f1c8ca282 264 parameter[2] = 0x01;
bcostm 0:d83f1c8ca282 265 parameter[3] = 0xF0;
bcostm 0:d83f1c8ca282 266 /* BFA describes the Bottom Fixed Area */
bcostm 0:d83f1c8ca282 267 parameter[4] = 0x00;
bcostm 0:d83f1c8ca282 268 parameter[5] = 0x00;
bcostm 0:d83f1c8ca282 269 ST7789H2_WriteReg(ST7789H2_VSCRDEF, parameter, 6);
bcostm 0:d83f1c8ca282 270
bcostm 0:d83f1c8ca282 271 /* Vertical Scroll Start Address of RAM */
bcostm 0:d83f1c8ca282 272 /* GRAM row nbr (320) - Display row nbr (240) = 80 = 0x50 */
bcostm 0:d83f1c8ca282 273 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 274 parameter[1] = 0x50;
bcostm 0:d83f1c8ca282 275 ST7789H2_WriteReg(ST7789H2_VSCSAD, parameter, 2);
bcostm 0:d83f1c8ca282 276
bcostm 0:d83f1c8ca282 277 parameter[0] = 0xC0;
bcostm 0:d83f1c8ca282 278 }
bcostm 0:d83f1c8ca282 279 else
bcostm 0:d83f1c8ca282 280 {
bcostm 0:d83f1c8ca282 281 parameter[0] = 0x60;
bcostm 0:d83f1c8ca282 282 }
bcostm 0:d83f1c8ca282 283 ST7789H2_WriteReg(ST7789H2_NORMAL_DISPLAY, parameter, 1);
bcostm 0:d83f1c8ca282 284 }
bcostm 0:d83f1c8ca282 285
bcostm 0:d83f1c8ca282 286 /**
bcostm 0:d83f1c8ca282 287 * @brief Enables the Display.
bcostm 0:d83f1c8ca282 288 * @param None
bcostm 0:d83f1c8ca282 289 * @retval None
bcostm 0:d83f1c8ca282 290 */
bcostm 0:d83f1c8ca282 291 void ST7789H2_DisplayOn(void)
bcostm 0:d83f1c8ca282 292 {
bcostm 0:d83f1c8ca282 293 /* Display ON command */
bcostm 0:d83f1c8ca282 294 ST7789H2_WriteReg(ST7789H2_DISPLAY_ON, (uint8_t*)NULL, 0);
bcostm 0:d83f1c8ca282 295
bcostm 0:d83f1c8ca282 296 /* Sleep Out command */
bcostm 0:d83f1c8ca282 297 ST7789H2_WriteReg(ST7789H2_SLEEP_OUT, (uint8_t*)NULL, 0);
bcostm 0:d83f1c8ca282 298 }
bcostm 0:d83f1c8ca282 299
bcostm 0:d83f1c8ca282 300 /**
bcostm 0:d83f1c8ca282 301 * @brief Disables the Display.
bcostm 0:d83f1c8ca282 302 * @param None
bcostm 0:d83f1c8ca282 303 * @retval None
bcostm 0:d83f1c8ca282 304 */
bcostm 0:d83f1c8ca282 305 void ST7789H2_DisplayOff(void)
bcostm 0:d83f1c8ca282 306 {
bcostm 0:d83f1c8ca282 307 uint8_t parameter[1];
bcostm 0:d83f1c8ca282 308 parameter[0] = 0xFE;
bcostm 0:d83f1c8ca282 309 /* Display OFF command */
bcostm 0:d83f1c8ca282 310 ST7789H2_WriteReg(ST7789H2_DISPLAY_OFF, parameter, 1);
bcostm 0:d83f1c8ca282 311 /* Sleep In Command */
bcostm 0:d83f1c8ca282 312 ST7789H2_WriteReg(ST7789H2_SLEEP_IN, (uint8_t*)NULL, 0);
bcostm 0:d83f1c8ca282 313 /* Wait for 10ms */
bcostm 0:d83f1c8ca282 314 LCD_IO_Delay(10);
bcostm 0:d83f1c8ca282 315 }
bcostm 0:d83f1c8ca282 316
bcostm 0:d83f1c8ca282 317 /**
bcostm 0:d83f1c8ca282 318 * @brief Get the LCD pixel Width.
bcostm 0:d83f1c8ca282 319 * @param None
bcostm 0:d83f1c8ca282 320 * @retval The Lcd Pixel Width
bcostm 0:d83f1c8ca282 321 */
bcostm 0:d83f1c8ca282 322 uint16_t ST7789H2_GetLcdPixelWidth(void)
bcostm 0:d83f1c8ca282 323 {
bcostm 0:d83f1c8ca282 324 return (uint16_t)ST7789H2_LCD_PIXEL_WIDTH;
bcostm 0:d83f1c8ca282 325 }
bcostm 0:d83f1c8ca282 326
bcostm 0:d83f1c8ca282 327 /**
bcostm 0:d83f1c8ca282 328 * @brief Get the LCD pixel Height.
bcostm 0:d83f1c8ca282 329 * @param None
bcostm 0:d83f1c8ca282 330 * @retval The Lcd Pixel Height
bcostm 0:d83f1c8ca282 331 */
bcostm 0:d83f1c8ca282 332 uint16_t ST7789H2_GetLcdPixelHeight(void)
bcostm 0:d83f1c8ca282 333 {
bcostm 0:d83f1c8ca282 334 return (uint16_t)ST7789H2_LCD_PIXEL_HEIGHT;
bcostm 0:d83f1c8ca282 335 }
bcostm 0:d83f1c8ca282 336
bcostm 0:d83f1c8ca282 337 /**
bcostm 0:d83f1c8ca282 338 * @brief Get the st7789h2 ID.
bcostm 0:d83f1c8ca282 339 * @param None
bcostm 0:d83f1c8ca282 340 * @retval The st7789h2 ID
bcostm 0:d83f1c8ca282 341 */
bcostm 0:d83f1c8ca282 342 uint16_t ST7789H2_ReadID(void)
bcostm 0:d83f1c8ca282 343 {
bcostm 0:d83f1c8ca282 344 LCD_IO_Init();
bcostm 0:d83f1c8ca282 345
bcostm 0:d83f1c8ca282 346 return ST7789H2_ReadReg(ST7789H2_LCD_ID);
bcostm 0:d83f1c8ca282 347 }
bcostm 0:d83f1c8ca282 348
bcostm 0:d83f1c8ca282 349 /**
bcostm 0:d83f1c8ca282 350 * @brief Set Cursor position.
bcostm 0:d83f1c8ca282 351 * @param Xpos: specifies the X position.
bcostm 0:d83f1c8ca282 352 * @param Ypos: specifies the Y position.
bcostm 0:d83f1c8ca282 353 * @retval None
bcostm 0:d83f1c8ca282 354 */
bcostm 0:d83f1c8ca282 355 void ST7789H2_SetCursor(uint16_t Xpos, uint16_t Ypos)
bcostm 0:d83f1c8ca282 356 {
bcostm 0:d83f1c8ca282 357 uint8_t parameter[4];
bcostm 0:d83f1c8ca282 358 /* CASET: Comumn Addrses Set */
bcostm 0:d83f1c8ca282 359 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 360 parameter[1] = 0x00 + Xpos;
bcostm 0:d83f1c8ca282 361 parameter[2] = 0x00;
bcostm 0:d83f1c8ca282 362 parameter[3] = 0xEF + Xpos;
bcostm 0:d83f1c8ca282 363 ST7789H2_WriteReg(ST7789H2_CASET, parameter, 4);
bcostm 0:d83f1c8ca282 364 /* RASET: Row Addrses Set */
bcostm 0:d83f1c8ca282 365 parameter[0] = 0x00;
bcostm 0:d83f1c8ca282 366 parameter[1] = 0x00 + Ypos;
bcostm 0:d83f1c8ca282 367 parameter[2] = 0x00;
bcostm 0:d83f1c8ca282 368 parameter[3] = 0xEF + Ypos;
bcostm 0:d83f1c8ca282 369 ST7789H2_WriteReg(ST7789H2_RASET, parameter, 4);
bcostm 0:d83f1c8ca282 370 }
bcostm 0:d83f1c8ca282 371
bcostm 0:d83f1c8ca282 372 /**
bcostm 0:d83f1c8ca282 373 * @brief Write pixel.
bcostm 0:d83f1c8ca282 374 * @param Xpos: specifies the X position.
bcostm 0:d83f1c8ca282 375 * @param Ypos: specifies the Y position.
bcostm 0:d83f1c8ca282 376 * @param RGBCode: the RGB pixel color in RGB565 format
bcostm 0:d83f1c8ca282 377 * @retval None
bcostm 0:d83f1c8ca282 378 */
bcostm 0:d83f1c8ca282 379 void ST7789H2_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
bcostm 0:d83f1c8ca282 380 {
bcostm 0:d83f1c8ca282 381 /* Set Cursor */
bcostm 0:d83f1c8ca282 382 ST7789H2_SetCursor(Xpos, Ypos);
bcostm 0:d83f1c8ca282 383
bcostm 0:d83f1c8ca282 384 /* Prepare to write to LCD RAM */
bcostm 0:d83f1c8ca282 385 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
bcostm 0:d83f1c8ca282 386
bcostm 0:d83f1c8ca282 387 /* Write RAM data */
bcostm 0:d83f1c8ca282 388 LCD_IO_WriteData(RGBCode);
bcostm 0:d83f1c8ca282 389 }
bcostm 0:d83f1c8ca282 390
bcostm 0:d83f1c8ca282 391 /**
bcostm 0:d83f1c8ca282 392 * @brief Read pixel.
bcostm 0:d83f1c8ca282 393 * @param Xpos: specifies the X position.
bcostm 0:d83f1c8ca282 394 * @param Ypos: specifies the Y position.
bcostm 0:d83f1c8ca282 395 * @retval The RGB pixel color in RGB565 format
bcostm 0:d83f1c8ca282 396 */
bcostm 0:d83f1c8ca282 397 uint16_t ST7789H2_ReadPixel(uint16_t Xpos, uint16_t Ypos)
bcostm 0:d83f1c8ca282 398 {
bcostm 0:d83f1c8ca282 399 ST7789H2_Rgb888 rgb888;
bcostm 0:d83f1c8ca282 400 uint8_t r, g, b;
bcostm 0:d83f1c8ca282 401 uint16_t rgb565;
bcostm 0:d83f1c8ca282 402
bcostm 0:d83f1c8ca282 403 /* Set Cursor */
bcostm 0:d83f1c8ca282 404 ST7789H2_SetCursor(Xpos, Ypos);
bcostm 0:d83f1c8ca282 405
bcostm 0:d83f1c8ca282 406 /* Read RGB888 data from LCD RAM */
bcostm 0:d83f1c8ca282 407 rgb888 = ST7789H2_ReadPixel_rgb888(Xpos, Ypos);
bcostm 0:d83f1c8ca282 408
bcostm 0:d83f1c8ca282 409 /* Convert RGB888 to RGB565 */
bcostm 0:d83f1c8ca282 410 r = ((rgb888.red & 0xF8) >> 3); /* Extract the red component 5 most significant bits */
bcostm 0:d83f1c8ca282 411 g = ((rgb888.green & 0xFC) >> 2); /* Extract the green component 6 most significant bits */
bcostm 0:d83f1c8ca282 412 b = ((rgb888.blue & 0xF8) >> 3); /* Extract the blue component 5 most significant bits */
bcostm 0:d83f1c8ca282 413
bcostm 0:d83f1c8ca282 414 rgb565 = ((uint16_t)(r) << 11) + ((uint16_t)(g) << 5) + ((uint16_t)(b) << 0);
bcostm 0:d83f1c8ca282 415
bcostm 0:d83f1c8ca282 416 return (rgb565);
bcostm 0:d83f1c8ca282 417 }
bcostm 0:d83f1c8ca282 418
bcostm 0:d83f1c8ca282 419 /**
bcostm 0:d83f1c8ca282 420 * @brief Writes to the selected LCD register.
bcostm 0:d83f1c8ca282 421 * @param Command: command value (or register address as named in st7789h2 doc).
bcostm 0:d83f1c8ca282 422 * @param Parameters: pointer on parameters value (if command uses one or several parameters).
bcostm 0:d83f1c8ca282 423 * @param NbParameters: number of command parameters (0 if no parameter)
bcostm 0:d83f1c8ca282 424 * @retval None
bcostm 0:d83f1c8ca282 425 */
bcostm 0:d83f1c8ca282 426 void ST7789H2_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters)
bcostm 0:d83f1c8ca282 427 {
bcostm 0:d83f1c8ca282 428 uint8_t i;
bcostm 0:d83f1c8ca282 429
bcostm 0:d83f1c8ca282 430 /* Send command */
bcostm 0:d83f1c8ca282 431 LCD_IO_WriteReg(Command);
bcostm 0:d83f1c8ca282 432
bcostm 0:d83f1c8ca282 433 /* Send command's parameters if any */
bcostm 0:d83f1c8ca282 434 for (i=0; i<NbParameters; i++)
bcostm 0:d83f1c8ca282 435 {
bcostm 0:d83f1c8ca282 436 LCD_IO_WriteData(Parameters[i]);
bcostm 0:d83f1c8ca282 437 }
bcostm 0:d83f1c8ca282 438 }
bcostm 0:d83f1c8ca282 439
bcostm 0:d83f1c8ca282 440 /**
bcostm 0:d83f1c8ca282 441 * @brief Reads the selected LCD Register.
bcostm 0:d83f1c8ca282 442 * @param Command: command value (or register address as named in st7789h2 doc).
bcostm 0:d83f1c8ca282 443 * @retval Register Value.
bcostm 0:d83f1c8ca282 444 */
bcostm 0:d83f1c8ca282 445 uint8_t ST7789H2_ReadReg(uint8_t Command)
bcostm 0:d83f1c8ca282 446 {
bcostm 0:d83f1c8ca282 447 /* Send command */
bcostm 0:d83f1c8ca282 448 LCD_IO_WriteReg(Command);
bcostm 0:d83f1c8ca282 449
bcostm 0:d83f1c8ca282 450 /* Read dummy data */
bcostm 0:d83f1c8ca282 451 LCD_IO_ReadData();
bcostm 0:d83f1c8ca282 452
bcostm 0:d83f1c8ca282 453 /* Read register value */
bcostm 0:d83f1c8ca282 454 return (LCD_IO_ReadData());
bcostm 0:d83f1c8ca282 455 }
bcostm 0:d83f1c8ca282 456
bcostm 0:d83f1c8ca282 457 /**
bcostm 0:d83f1c8ca282 458 * @brief Sets a display window
bcostm 0:d83f1c8ca282 459 * @param Xpos: specifies the X bottom left position.
bcostm 0:d83f1c8ca282 460 * @param Ypos: specifies the Y bottom left position.
bcostm 0:d83f1c8ca282 461 * @param Height: display window height.
bcostm 0:d83f1c8ca282 462 * @param Width: display window width.
bcostm 0:d83f1c8ca282 463 * @retval None
bcostm 0:d83f1c8ca282 464 */
bcostm 0:d83f1c8ca282 465 void ST7789H2_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
bcostm 0:d83f1c8ca282 466 {
bcostm 0:d83f1c8ca282 467 if (Xpos < ST7789H2_LCD_PIXEL_WIDTH)
bcostm 0:d83f1c8ca282 468 {
bcostm 0:d83f1c8ca282 469 WindowsXstart = Xpos;
bcostm 0:d83f1c8ca282 470 }
bcostm 0:d83f1c8ca282 471 else
bcostm 0:d83f1c8ca282 472 {
bcostm 0:d83f1c8ca282 473 WindowsXstart = 0;
bcostm 0:d83f1c8ca282 474 }
bcostm 0:d83f1c8ca282 475
bcostm 0:d83f1c8ca282 476 if (Ypos < ST7789H2_LCD_PIXEL_HEIGHT)
bcostm 0:d83f1c8ca282 477 {
bcostm 0:d83f1c8ca282 478 WindowsYstart = Ypos;
bcostm 0:d83f1c8ca282 479 }
bcostm 0:d83f1c8ca282 480 else
bcostm 0:d83f1c8ca282 481 {
bcostm 0:d83f1c8ca282 482 WindowsYstart = 0;
bcostm 0:d83f1c8ca282 483 }
bcostm 0:d83f1c8ca282 484
bcostm 0:d83f1c8ca282 485 if (Width + Xpos <= ST7789H2_LCD_PIXEL_WIDTH)
bcostm 0:d83f1c8ca282 486 {
bcostm 0:d83f1c8ca282 487 WindowsXend = Width + Xpos - 1;
bcostm 0:d83f1c8ca282 488 }
bcostm 0:d83f1c8ca282 489 else
bcostm 0:d83f1c8ca282 490 {
bcostm 0:d83f1c8ca282 491 WindowsXend = ST7789H2_LCD_PIXEL_WIDTH - 1;
bcostm 0:d83f1c8ca282 492 }
bcostm 0:d83f1c8ca282 493
bcostm 0:d83f1c8ca282 494 if (Height + Ypos <= ST7789H2_LCD_PIXEL_HEIGHT)
bcostm 0:d83f1c8ca282 495 {
bcostm 0:d83f1c8ca282 496 WindowsYend = Height + Ypos - 1;
bcostm 0:d83f1c8ca282 497 }
bcostm 0:d83f1c8ca282 498 else
bcostm 0:d83f1c8ca282 499 {
bcostm 0:d83f1c8ca282 500 WindowsYend = ST7789H2_LCD_PIXEL_HEIGHT-1;
bcostm 0:d83f1c8ca282 501 }
bcostm 0:d83f1c8ca282 502 }
bcostm 0:d83f1c8ca282 503
bcostm 0:d83f1c8ca282 504 /**
bcostm 0:d83f1c8ca282 505 * @brief Draw vertical line.
bcostm 0:d83f1c8ca282 506 * @param RGBCode: Specifies the RGB color in RGB565 format
bcostm 0:d83f1c8ca282 507 * @param Xpos: specifies the X position.
bcostm 0:d83f1c8ca282 508 * @param Ypos: specifies the Y position.
bcostm 0:d83f1c8ca282 509 * @param Length: specifies the Line length.
bcostm 0:d83f1c8ca282 510 * @retval None
bcostm 0:d83f1c8ca282 511 */
bcostm 0:d83f1c8ca282 512 void ST7789H2_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bcostm 0:d83f1c8ca282 513 {
bcostm 0:d83f1c8ca282 514 uint16_t counter = 0;
bcostm 0:d83f1c8ca282 515
bcostm 0:d83f1c8ca282 516 /* Set Cursor */
bcostm 0:d83f1c8ca282 517 ST7789H2_SetCursor(Xpos, Ypos);
bcostm 0:d83f1c8ca282 518
bcostm 0:d83f1c8ca282 519 /* Prepare to write to LCD RAM */
bcostm 0:d83f1c8ca282 520 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
bcostm 0:d83f1c8ca282 521
bcostm 0:d83f1c8ca282 522 /* Sent a complete line */
bcostm 0:d83f1c8ca282 523 for(counter = 0; counter < Length; counter++)
bcostm 0:d83f1c8ca282 524 {
bcostm 0:d83f1c8ca282 525 LCD_IO_WriteData(RGBCode);
bcostm 0:d83f1c8ca282 526 }
bcostm 0:d83f1c8ca282 527 }
bcostm 0:d83f1c8ca282 528
bcostm 0:d83f1c8ca282 529 /**
bcostm 0:d83f1c8ca282 530 * @brief Draw vertical line.
bcostm 0:d83f1c8ca282 531 * @param RGBCode: Specifies the RGB color
bcostm 0:d83f1c8ca282 532 * @param Xpos: specifies the X position.
bcostm 0:d83f1c8ca282 533 * @param Ypos: specifies the Y position.
bcostm 0:d83f1c8ca282 534 * @param Length: specifies the Line length.
bcostm 0:d83f1c8ca282 535 * @retval None
bcostm 0:d83f1c8ca282 536 */
bcostm 0:d83f1c8ca282 537 void ST7789H2_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
bcostm 0:d83f1c8ca282 538 {
bcostm 0:d83f1c8ca282 539 uint16_t counter = 0;
bcostm 0:d83f1c8ca282 540
bcostm 0:d83f1c8ca282 541 /* Set Cursor */
bcostm 0:d83f1c8ca282 542 ST7789H2_SetCursor(Xpos, Ypos);
bcostm 0:d83f1c8ca282 543
bcostm 0:d83f1c8ca282 544 /* Prepare to write to LCD RAM */
bcostm 0:d83f1c8ca282 545 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
bcostm 0:d83f1c8ca282 546
bcostm 0:d83f1c8ca282 547 /* Fill a complete vertical line */
bcostm 0:d83f1c8ca282 548 for(counter = 0; counter < Length; counter++)
bcostm 0:d83f1c8ca282 549 {
bcostm 0:d83f1c8ca282 550 ST7789H2_WritePixel(Xpos, Ypos + counter, RGBCode);
bcostm 0:d83f1c8ca282 551 }
bcostm 0:d83f1c8ca282 552 }
bcostm 0:d83f1c8ca282 553
bcostm 0:d83f1c8ca282 554 /**
bcostm 0:d83f1c8ca282 555 * @brief Displays a bitmap picture.
bcostm 0:d83f1c8ca282 556 * @param BmpAddress: Bmp picture address.
bcostm 0:d83f1c8ca282 557 * @param Xpos: Bmp X position in the LCD
bcostm 0:d83f1c8ca282 558 * @param Ypos: Bmp Y position in the LCD
bcostm 0:d83f1c8ca282 559 * @retval None
bcostm 0:d83f1c8ca282 560 */
bcostm 0:d83f1c8ca282 561 void ST7789H2_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
bcostm 0:d83f1c8ca282 562 {
bcostm 0:d83f1c8ca282 563 uint32_t index = 0, size = 0;
bcostm 0:d83f1c8ca282 564 uint32_t posY;
bcostm 0:d83f1c8ca282 565 uint32_t nb_line = 0;
bcostm 0:d83f1c8ca282 566 uint16_t Xsize = WindowsXend - WindowsXstart + 1;
bcostm 0:d83f1c8ca282 567 uint16_t Ysize = WindowsYend - WindowsYstart + 1;
bcostm 0:d83f1c8ca282 568
bcostm 0:d83f1c8ca282 569 /* Read bitmap size */
bcostm 0:d83f1c8ca282 570 size = *(volatile uint16_t *) (pbmp + 2);
bcostm 0:d83f1c8ca282 571 size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
bcostm 0:d83f1c8ca282 572 /* Get bitmap data address offset */
bcostm 0:d83f1c8ca282 573 index = *(volatile uint16_t *) (pbmp + 10);
bcostm 0:d83f1c8ca282 574 index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
bcostm 0:d83f1c8ca282 575 size = (size - index)/2;
bcostm 0:d83f1c8ca282 576 pbmp += index;
bcostm 0:d83f1c8ca282 577
bcostm 0:d83f1c8ca282 578 for (posY = (Ypos + Ysize); posY > Ypos; posY--) /* In BMP files the line order is inverted */
bcostm 0:d83f1c8ca282 579 {
bcostm 0:d83f1c8ca282 580 /* Set Cursor */
bcostm 0:d83f1c8ca282 581 ST7789H2_SetCursor(Xpos, posY - 1);
bcostm 0:d83f1c8ca282 582
bcostm 0:d83f1c8ca282 583 /* Draw one line of the picture */
bcostm 0:d83f1c8ca282 584 ST7789H2_DrawRGBHLine(Xpos, posY - 1, Xsize, (pbmp + (nb_line * Xsize * 2)));
bcostm 0:d83f1c8ca282 585 nb_line++;
bcostm 0:d83f1c8ca282 586 }
bcostm 0:d83f1c8ca282 587 }
bcostm 0:d83f1c8ca282 588
bcostm 0:d83f1c8ca282 589 /**
bcostm 0:d83f1c8ca282 590 * @brief Displays picture.
bcostm 0:d83f1c8ca282 591 * @param pdata: picture address.
bcostm 0:d83f1c8ca282 592 * @param Xpos: Image X position in the LCD
bcostm 0:d83f1c8ca282 593 * @param Ypos: Image Y position in the LCD
bcostm 0:d83f1c8ca282 594 * @param Xsize: Image X size in the LCD
bcostm 0:d83f1c8ca282 595 * @param Ysize: Image Y size in the LCD
bcostm 0:d83f1c8ca282 596 * @retval None
bcostm 0:d83f1c8ca282 597 */
bcostm 0:d83f1c8ca282 598 void ST7789H2_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata)
bcostm 0:d83f1c8ca282 599 {
bcostm 0:d83f1c8ca282 600 uint32_t posY;
bcostm 0:d83f1c8ca282 601 uint32_t nb_line = 0;
bcostm 0:d83f1c8ca282 602
bcostm 0:d83f1c8ca282 603 for (posY = Ypos; posY < (Ypos + Ysize); posY ++)
bcostm 0:d83f1c8ca282 604 {
bcostm 0:d83f1c8ca282 605 /* Set Cursor */
bcostm 0:d83f1c8ca282 606 ST7789H2_SetCursor(Xpos, posY);
bcostm 0:d83f1c8ca282 607
bcostm 0:d83f1c8ca282 608 /* Draw one line of the picture */
bcostm 0:d83f1c8ca282 609 ST7789H2_DrawRGBHLine(Xpos, posY, Xsize, (pdata + (nb_line * Xsize * 2)));
bcostm 0:d83f1c8ca282 610 nb_line++;
bcostm 0:d83f1c8ca282 611 }
bcostm 0:d83f1c8ca282 612 }
bcostm 0:d83f1c8ca282 613
bcostm 0:d83f1c8ca282 614
bcostm 0:d83f1c8ca282 615 /******************************************************************************
bcostm 0:d83f1c8ca282 616 Static Functions
bcostm 0:d83f1c8ca282 617 *******************************************************************************/
bcostm 0:d83f1c8ca282 618
bcostm 0:d83f1c8ca282 619 /**
bcostm 0:d83f1c8ca282 620 * @brief Read pixel from LCD RAM in RGB888 format
bcostm 0:d83f1c8ca282 621 * @param Xpos: specifies the X position.
bcostm 0:d83f1c8ca282 622 * @param Ypos: specifies the Y position.
bcostm 0:d83f1c8ca282 623 * @retval Each RGB pixel color components in a structure
bcostm 0:d83f1c8ca282 624 */
bcostm 0:d83f1c8ca282 625 static ST7789H2_Rgb888 ST7789H2_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos)
bcostm 0:d83f1c8ca282 626 {
bcostm 0:d83f1c8ca282 627 ST7789H2_Rgb888 rgb888;
bcostm 0:d83f1c8ca282 628 uint16_t rgb888_part1, rgb888_part2;
bcostm 0:d83f1c8ca282 629
bcostm 0:d83f1c8ca282 630 /* In LCD RAM, pixels are 24 bits packed and read with 16 bits access
bcostm 0:d83f1c8ca282 631 * Here is the pixels components arrangement in memory :
bcostm 0:d83f1c8ca282 632 * bits: 15 14 13 12 11 10 09 08 | 07 06 05 04 03 02 01 00
bcostm 0:d83f1c8ca282 633 * address 0 : red pixel 0 X X | green pixel 0 X X
bcostm 0:d83f1c8ca282 634 * address 1 : blue pixel 0 X X | red pixel 1 X X
bcostm 0:d83f1c8ca282 635 * address 2 : green pixel 1 X X | blue pixel 1 X X
bcostm 0:d83f1c8ca282 636 */
bcostm 0:d83f1c8ca282 637
bcostm 0:d83f1c8ca282 638 /* Set Cursor */
bcostm 0:d83f1c8ca282 639 ST7789H2_SetCursor(Xpos, Ypos);
bcostm 0:d83f1c8ca282 640 /* Prepare to read LCD RAM */
bcostm 0:d83f1c8ca282 641 ST7789H2_WriteReg(ST7789H2_READ_RAM, (uint8_t*)NULL, 0); /* RAM read data command */
bcostm 0:d83f1c8ca282 642 /* Dummy read */
bcostm 0:d83f1c8ca282 643 LCD_IO_ReadData();
bcostm 0:d83f1c8ca282 644 /* Read first part of the RGB888 data */
bcostm 0:d83f1c8ca282 645 rgb888_part1 = LCD_IO_ReadData();
bcostm 0:d83f1c8ca282 646 /* Read first part of the RGB888 data */
bcostm 0:d83f1c8ca282 647 rgb888_part2 = LCD_IO_ReadData();
bcostm 0:d83f1c8ca282 648
bcostm 0:d83f1c8ca282 649 /* red component */
bcostm 0:d83f1c8ca282 650 rgb888.red = (rgb888_part1 & 0xFC00) >> 8;
bcostm 0:d83f1c8ca282 651 /* green component */
bcostm 0:d83f1c8ca282 652 rgb888.green = (rgb888_part1 & 0x00FC) >> 0;
bcostm 0:d83f1c8ca282 653 /* blue component */
bcostm 0:d83f1c8ca282 654 rgb888.blue = (rgb888_part2 & 0xFC00) >> 8;
bcostm 0:d83f1c8ca282 655
bcostm 0:d83f1c8ca282 656 return rgb888;
bcostm 0:d83f1c8ca282 657 }
bcostm 0:d83f1c8ca282 658
bcostm 0:d83f1c8ca282 659
bcostm 0:d83f1c8ca282 660 /**
bcostm 0:d83f1c8ca282 661 * @brief Displays a single picture line.
bcostm 0:d83f1c8ca282 662 * @param pdata: picture address.
bcostm 0:d83f1c8ca282 663 * @param Xpos: Image X position in the LCD
bcostm 0:d83f1c8ca282 664 * @param Ypos: Image Y position in the LCD
bcostm 0:d83f1c8ca282 665 * @param Xsize: Image X size in the LCD
bcostm 0:d83f1c8ca282 666 * @retval None
bcostm 0:d83f1c8ca282 667 */
bcostm 0:d83f1c8ca282 668 static void ST7789H2_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata)
bcostm 0:d83f1c8ca282 669 {
bcostm 0:d83f1c8ca282 670 uint32_t i = 0;
bcostm 0:d83f1c8ca282 671 uint32_t posX;
bcostm 0:d83f1c8ca282 672 uint16_t *rgb565 = (uint16_t*)pdata;
bcostm 0:d83f1c8ca282 673
bcostm 0:d83f1c8ca282 674 /* Prepare to write to LCD RAM */
bcostm 0:d83f1c8ca282 675 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */
bcostm 0:d83f1c8ca282 676
bcostm 0:d83f1c8ca282 677 for (posX = Xpos; posX < (Xsize + Xpos); posX++)
bcostm 0:d83f1c8ca282 678 {
bcostm 0:d83f1c8ca282 679 if ((posX >= WindowsXstart) && (Ypos >= WindowsYstart) && /* Check we are in the defined window */
bcostm 0:d83f1c8ca282 680 (posX <= WindowsXend) && (Ypos <= WindowsYend))
bcostm 0:d83f1c8ca282 681 {
bcostm 0:d83f1c8ca282 682 if (posX != (Xsize + Xpos)) /* When writing last pixel when size is odd, the third part is not written */
bcostm 0:d83f1c8ca282 683 {
bcostm 0:d83f1c8ca282 684 LCD_IO_WriteData(rgb565[i]);
bcostm 0:d83f1c8ca282 685 }
bcostm 0:d83f1c8ca282 686 i++;
bcostm 0:d83f1c8ca282 687 }
bcostm 0:d83f1c8ca282 688 }
bcostm 0:d83f1c8ca282 689 }
bcostm 0:d83f1c8ca282 690
bcostm 0:d83f1c8ca282 691 /**
bcostm 0:d83f1c8ca282 692 * @}
bcostm 0:d83f1c8ca282 693 */
bcostm 0:d83f1c8ca282 694
bcostm 0:d83f1c8ca282 695 /**
bcostm 0:d83f1c8ca282 696 * @}
bcostm 0:d83f1c8ca282 697 */
bcostm 0:d83f1c8ca282 698
bcostm 0:d83f1c8ca282 699 /**
bcostm 0:d83f1c8ca282 700 * @}
bcostm 0:d83f1c8ca282 701 */
bcostm 0:d83f1c8ca282 702
bcostm 0:d83f1c8ca282 703 /**
bcostm 0:d83f1c8ca282 704 * @}
bcostm 0:d83f1c8ca282 705 */
bcostm 0:d83f1c8ca282 706
bcostm 0:d83f1c8ca282 707 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/