Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO_L496AG-LCD-prova_1 DISCO_L496AG-LCD-prova_2 DISCO_L496AG-LCD-demo DISCO_L496AG-SRAM-demo
st7789h2.c
00001 /** 00002 ****************************************************************************** 00003 * @file st7789h2.c 00004 * @author MCD Application Team 00005 * @brief This file includes the LCD driver for st7789h2 LCD. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 00020 /* Includes ------------------------------------------------------------------*/ 00021 #include "st7789h2.h" 00022 00023 /** @addtogroup BSP 00024 * @{ 00025 */ 00026 00027 /** @addtogroup Components 00028 * @{ 00029 */ 00030 00031 /** @defgroup ST7789H2 00032 * @brief This file provides a set of functions needed to drive the 00033 * FRIDA FRD154BP2901 LCD. 00034 * @{ 00035 */ 00036 00037 /** @defgroup ST7789H2_Private_TypesDefinitions ST7789H2 Private TypesDefinitions 00038 * @{ 00039 */ 00040 typedef struct { 00041 uint8_t red; 00042 uint8_t green; 00043 uint8_t blue; 00044 } ST7789H2_Rgb888; 00045 00046 /** 00047 * @} 00048 */ 00049 00050 /** @defgroup ST7789H2_Private_Defines ST7789H2 Private Defines 00051 * @{ 00052 */ 00053 00054 /** 00055 * @} 00056 */ 00057 00058 /** @defgroup ST7789H2_Private_Macros ST7789H2 Private Macros 00059 * @{ 00060 */ 00061 00062 /** 00063 * @} 00064 */ 00065 00066 /** @defgroup ST7789H2_Private_Variables ST7789H2 Private Variables 00067 * @{ 00068 */ 00069 LCD_DrvTypeDef ST7789H2_drv = 00070 { 00071 ST7789H2_Init, 00072 ST7789H2_ReadID, 00073 ST7789H2_DisplayOn, 00074 ST7789H2_DisplayOff, 00075 ST7789H2_SetCursor, 00076 ST7789H2_WritePixel, 00077 ST7789H2_ReadPixel, 00078 ST7789H2_SetDisplayWindow, 00079 ST7789H2_DrawHLine, 00080 ST7789H2_DrawVLine, 00081 ST7789H2_GetLcdPixelWidth, 00082 ST7789H2_GetLcdPixelHeight, 00083 ST7789H2_DrawBitmap, 00084 ST7789H2_DrawRGBImage, 00085 }; 00086 00087 static uint16_t WindowsXstart = 0; 00088 static uint16_t WindowsYstart = 0; 00089 static uint16_t WindowsXend = ST7789H2_LCD_PIXEL_WIDTH-1; 00090 static uint16_t WindowsYend = ST7789H2_LCD_PIXEL_HEIGHT-1; 00091 /** 00092 * @} 00093 */ 00094 00095 /** @defgroup ST7789H2_Private_FunctionPrototypes ST7789H2 Private FunctionPrototypes 00096 * @{ 00097 */ 00098 static ST7789H2_Rgb888 ST7789H2_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos); 00099 static void ST7789H2_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata); 00100 00101 /** 00102 * @} 00103 */ 00104 00105 /** @defgroup ST7789H2_Private_Functions ST7789H2 Private Functions 00106 * @{ 00107 */ 00108 00109 /** 00110 * @brief Initialize the st7789h2 LCD Component. 00111 * @param None 00112 * @retval None 00113 */ 00114 void ST7789H2_Init(void) 00115 { 00116 uint8_t parameter[14]; 00117 00118 /* Initialize st7789h2 low level bus layer ----------------------------------*/ 00119 LCD_IO_Init(); 00120 /* Sleep In Command */ 00121 ST7789H2_WriteReg(ST7789H2_SLEEP_IN, (uint8_t*)NULL, 0); 00122 /* Wait for 10ms */ 00123 LCD_IO_Delay(10); 00124 00125 /* SW Reset Command */ 00126 ST7789H2_WriteReg(0x01, (uint8_t*)NULL, 0); 00127 /* Wait for 200ms */ 00128 LCD_IO_Delay(200); 00129 00130 /* Sleep Out Command */ 00131 ST7789H2_WriteReg(ST7789H2_SLEEP_OUT, (uint8_t*)NULL, 0); 00132 /* Wait for 120ms */ 00133 LCD_IO_Delay(120); 00134 00135 /* Normal display for Driver Down side */ 00136 parameter[0] = 0x00; 00137 ST7789H2_WriteReg(ST7789H2_NORMAL_DISPLAY, parameter, 1); 00138 00139 /* Color mode 16bits/pixel */ 00140 parameter[0] = 0x05; 00141 ST7789H2_WriteReg(ST7789H2_COLOR_MODE, parameter, 1); 00142 00143 /* Display inversion On */ 00144 ST7789H2_WriteReg(ST7789H2_DISPLAY_INVERSION, (uint8_t*)NULL, 0); 00145 00146 /* Set Column address CASET */ 00147 parameter[0] = 0x00; 00148 parameter[1] = 0x00; 00149 parameter[2] = 0x00; 00150 parameter[3] = 0xEF; 00151 ST7789H2_WriteReg(ST7789H2_CASET, parameter, 4); 00152 /* Set Row address RASET */ 00153 parameter[0] = 0x00; 00154 parameter[1] = 0x00; 00155 parameter[2] = 0x00; 00156 parameter[3] = 0xEF; 00157 ST7789H2_WriteReg(ST7789H2_RASET, parameter, 4); 00158 00159 /*--------------- ST7789H2 Frame rate setting -------------------------------*/ 00160 /* PORCH control setting */ 00161 parameter[0] = 0x0C; 00162 parameter[1] = 0x0C; 00163 parameter[2] = 0x00; 00164 parameter[3] = 0x33; 00165 parameter[4] = 0x33; 00166 ST7789H2_WriteReg(ST7789H2_PORCH_CTRL, parameter, 5); 00167 00168 /* GATE control setting */ 00169 parameter[0] = 0x35; 00170 ST7789H2_WriteReg(ST7789H2_GATE_CTRL, parameter, 1); 00171 00172 /*--------------- ST7789H2 Power setting ------------------------------------*/ 00173 /* VCOM setting */ 00174 parameter[0] = 0x1F; 00175 ST7789H2_WriteReg(ST7789H2_VCOM_SET, parameter, 1); 00176 00177 /* LCM Control setting */ 00178 parameter[0] = 0x2C; 00179 ST7789H2_WriteReg(ST7789H2_LCM_CTRL, parameter, 1); 00180 00181 /* VDV and VRH Command Enable */ 00182 parameter[0] = 0x01; 00183 parameter[1] = 0xC3; 00184 ST7789H2_WriteReg(ST7789H2_VDV_VRH_EN, parameter, 2); 00185 00186 /* VDV Set */ 00187 parameter[0] = 0x20; 00188 ST7789H2_WriteReg(ST7789H2_VDV_SET, parameter, 1); 00189 00190 /* Frame Rate Control in normal mode */ 00191 parameter[0] = 0x0F; 00192 ST7789H2_WriteReg(ST7789H2_FR_CTRL, parameter, 1); 00193 00194 /* Power Control */ 00195 parameter[0] = 0xA4; 00196 parameter[1] = 0xA1; 00197 ST7789H2_WriteReg(ST7789H2_POWER_CTRL, parameter, 2); 00198 00199 /*--------------- ST7789H2 Gamma setting ------------------------------------*/ 00200 /* Positive Voltage Gamma Control */ 00201 parameter[0] = 0xD0; 00202 parameter[1] = 0x08; 00203 parameter[2] = 0x11; 00204 parameter[3] = 0x08; 00205 parameter[4] = 0x0C; 00206 parameter[5] = 0x15; 00207 parameter[6] = 0x39; 00208 parameter[7] = 0x33; 00209 parameter[8] = 0x50; 00210 parameter[9] = 0x36; 00211 parameter[10] = 0x13; 00212 parameter[11] = 0x14; 00213 parameter[12] = 0x29; 00214 parameter[13] = 0x2D; 00215 ST7789H2_WriteReg(ST7789H2_PV_GAMMA_CTRL, parameter, 14); 00216 00217 /* Negative Voltage Gamma Control */ 00218 parameter[0] = 0xD0; 00219 parameter[1] = 0x08; 00220 parameter[2] = 0x10; 00221 parameter[3] = 0x08; 00222 parameter[4] = 0x06; 00223 parameter[5] = 0x06; 00224 parameter[6] = 0x39; 00225 parameter[7] = 0x44; 00226 parameter[8] = 0x51; 00227 parameter[9] = 0x0B; 00228 parameter[10] = 0x16; 00229 parameter[11] = 0x14; 00230 parameter[12] = 0x2F; 00231 parameter[13] = 0x31; 00232 ST7789H2_WriteReg(ST7789H2_NV_GAMMA_CTRL, parameter, 14); 00233 00234 /* Display ON command */ 00235 ST7789H2_DisplayOn(); 00236 00237 /* Tearing Effect Line On: Option (00h:VSYNC Interface OFF, 01h:VSYNC Interface ON) */ 00238 parameter[0] = 0x00; 00239 ST7789H2_WriteReg(ST7789H2_TEARING_EFFECT, parameter, 1); 00240 00241 } 00242 00243 /** 00244 * @brief Set the Display Orientation. 00245 * @param orientation: ST7789H2_ORIENTATION_PORTRAIT, ST7789H2_ORIENTATION_LANDSCAPE 00246 * or ST7789H2_ORIENTATION_LANDSCAPE_ROT180 00247 * @retval None 00248 */ 00249 void ST7789H2_SetOrientation(uint32_t orientation) 00250 { 00251 uint8_t parameter[6]; 00252 00253 if(orientation == ST7789H2_ORIENTATION_LANDSCAPE) 00254 { 00255 parameter[0] = 0x00; 00256 } 00257 else if(orientation == ST7789H2_ORIENTATION_LANDSCAPE_ROT180) 00258 { 00259 /* Vertical Scrolling Definition */ 00260 /* TFA describes the Top Fixed Area */ 00261 parameter[0] = 0x00; 00262 parameter[1] = 0x00; 00263 /* VSA describes the height of the Vertical Scrolling Area */ 00264 parameter[2] = 0x01; 00265 parameter[3] = 0xF0; 00266 /* BFA describes the Bottom Fixed Area */ 00267 parameter[4] = 0x00; 00268 parameter[5] = 0x00; 00269 ST7789H2_WriteReg(ST7789H2_VSCRDEF, parameter, 6); 00270 00271 /* Vertical Scroll Start Address of RAM */ 00272 /* GRAM row nbr (320) - Display row nbr (240) = 80 = 0x50 */ 00273 parameter[0] = 0x00; 00274 parameter[1] = 0x50; 00275 ST7789H2_WriteReg(ST7789H2_VSCSAD, parameter, 2); 00276 00277 parameter[0] = 0xC0; 00278 } 00279 else 00280 { 00281 parameter[0] = 0x60; 00282 } 00283 ST7789H2_WriteReg(ST7789H2_NORMAL_DISPLAY, parameter, 1); 00284 } 00285 00286 /** 00287 * @brief Enables the Display. 00288 * @param None 00289 * @retval None 00290 */ 00291 void ST7789H2_DisplayOn(void) 00292 { 00293 /* Display ON command */ 00294 ST7789H2_WriteReg(ST7789H2_DISPLAY_ON, (uint8_t*)NULL, 0); 00295 00296 /* Sleep Out command */ 00297 ST7789H2_WriteReg(ST7789H2_SLEEP_OUT, (uint8_t*)NULL, 0); 00298 } 00299 00300 /** 00301 * @brief Disables the Display. 00302 * @param None 00303 * @retval None 00304 */ 00305 void ST7789H2_DisplayOff(void) 00306 { 00307 uint8_t parameter[1]; 00308 parameter[0] = 0xFE; 00309 /* Display OFF command */ 00310 ST7789H2_WriteReg(ST7789H2_DISPLAY_OFF, parameter, 1); 00311 /* Sleep In Command */ 00312 ST7789H2_WriteReg(ST7789H2_SLEEP_IN, (uint8_t*)NULL, 0); 00313 /* Wait for 10ms */ 00314 LCD_IO_Delay(10); 00315 } 00316 00317 /** 00318 * @brief Get the LCD pixel Width. 00319 * @param None 00320 * @retval The Lcd Pixel Width 00321 */ 00322 uint16_t ST7789H2_GetLcdPixelWidth(void) 00323 { 00324 return (uint16_t)ST7789H2_LCD_PIXEL_WIDTH; 00325 } 00326 00327 /** 00328 * @brief Get the LCD pixel Height. 00329 * @param None 00330 * @retval The Lcd Pixel Height 00331 */ 00332 uint16_t ST7789H2_GetLcdPixelHeight(void) 00333 { 00334 return (uint16_t)ST7789H2_LCD_PIXEL_HEIGHT; 00335 } 00336 00337 /** 00338 * @brief Get the st7789h2 ID. 00339 * @param None 00340 * @retval The st7789h2 ID 00341 */ 00342 uint16_t ST7789H2_ReadID(void) 00343 { 00344 LCD_IO_Init(); 00345 00346 return ST7789H2_ReadReg(ST7789H2_LCD_ID); 00347 } 00348 00349 /** 00350 * @brief Set Cursor position. 00351 * @param Xpos: specifies the X position. 00352 * @param Ypos: specifies the Y position. 00353 * @retval None 00354 */ 00355 void ST7789H2_SetCursor(uint16_t Xpos, uint16_t Ypos) 00356 { 00357 uint8_t parameter[4]; 00358 /* CASET: Comumn Addrses Set */ 00359 parameter[0] = 0x00; 00360 parameter[1] = 0x00 + Xpos; 00361 parameter[2] = 0x00; 00362 parameter[3] = 0xEF + Xpos; 00363 ST7789H2_WriteReg(ST7789H2_CASET, parameter, 4); 00364 /* RASET: Row Addrses Set */ 00365 parameter[0] = 0x00; 00366 parameter[1] = 0x00 + Ypos; 00367 parameter[2] = 0x00; 00368 parameter[3] = 0xEF + Ypos; 00369 ST7789H2_WriteReg(ST7789H2_RASET, parameter, 4); 00370 } 00371 00372 /** 00373 * @brief Write pixel. 00374 * @param Xpos: specifies the X position. 00375 * @param Ypos: specifies the Y position. 00376 * @param RGBCode: the RGB pixel color in RGB565 format 00377 * @retval None 00378 */ 00379 void ST7789H2_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode) 00380 { 00381 /* Set Cursor */ 00382 ST7789H2_SetCursor(Xpos, Ypos); 00383 00384 /* Prepare to write to LCD RAM */ 00385 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */ 00386 00387 /* Write RAM data */ 00388 LCD_IO_WriteData(RGBCode); 00389 } 00390 00391 /** 00392 * @brief Read pixel. 00393 * @param Xpos: specifies the X position. 00394 * @param Ypos: specifies the Y position. 00395 * @retval The RGB pixel color in RGB565 format 00396 */ 00397 uint16_t ST7789H2_ReadPixel(uint16_t Xpos, uint16_t Ypos) 00398 { 00399 ST7789H2_Rgb888 rgb888; 00400 uint8_t r, g, b; 00401 uint16_t rgb565; 00402 00403 /* Set Cursor */ 00404 ST7789H2_SetCursor(Xpos, Ypos); 00405 00406 /* Read RGB888 data from LCD RAM */ 00407 rgb888 = ST7789H2_ReadPixel_rgb888(Xpos, Ypos); 00408 00409 /* Convert RGB888 to RGB565 */ 00410 r = ((rgb888.red & 0xF8) >> 3); /* Extract the red component 5 most significant bits */ 00411 g = ((rgb888.green & 0xFC) >> 2); /* Extract the green component 6 most significant bits */ 00412 b = ((rgb888.blue & 0xF8) >> 3); /* Extract the blue component 5 most significant bits */ 00413 00414 rgb565 = ((uint16_t)(r) << 11) + ((uint16_t)(g) << 5) + ((uint16_t)(b) << 0); 00415 00416 return (rgb565); 00417 } 00418 00419 /** 00420 * @brief Writes to the selected LCD register. 00421 * @param Command: command value (or register address as named in st7789h2 doc). 00422 * @param Parameters: pointer on parameters value (if command uses one or several parameters). 00423 * @param NbParameters: number of command parameters (0 if no parameter) 00424 * @retval None 00425 */ 00426 void ST7789H2_WriteReg(uint8_t Command, uint8_t *Parameters, uint8_t NbParameters) 00427 { 00428 uint8_t i; 00429 00430 /* Send command */ 00431 LCD_IO_WriteReg(Command); 00432 00433 /* Send command's parameters if any */ 00434 for (i=0; i<NbParameters; i++) 00435 { 00436 LCD_IO_WriteData(Parameters[i]); 00437 } 00438 } 00439 00440 /** 00441 * @brief Reads the selected LCD Register. 00442 * @param Command: command value (or register address as named in st7789h2 doc). 00443 * @retval Register Value. 00444 */ 00445 uint8_t ST7789H2_ReadReg(uint8_t Command) 00446 { 00447 /* Send command */ 00448 LCD_IO_WriteReg(Command); 00449 00450 /* Read dummy data */ 00451 LCD_IO_ReadData(); 00452 00453 /* Read register value */ 00454 return (LCD_IO_ReadData()); 00455 } 00456 00457 /** 00458 * @brief Sets a display window 00459 * @param Xpos: specifies the X bottom left position. 00460 * @param Ypos: specifies the Y bottom left position. 00461 * @param Height: display window height. 00462 * @param Width: display window width. 00463 * @retval None 00464 */ 00465 void ST7789H2_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) 00466 { 00467 if (Xpos < ST7789H2_LCD_PIXEL_WIDTH) 00468 { 00469 WindowsXstart = Xpos; 00470 } 00471 else 00472 { 00473 WindowsXstart = 0; 00474 } 00475 00476 if (Ypos < ST7789H2_LCD_PIXEL_HEIGHT) 00477 { 00478 WindowsYstart = Ypos; 00479 } 00480 else 00481 { 00482 WindowsYstart = 0; 00483 } 00484 00485 if (Width + Xpos <= ST7789H2_LCD_PIXEL_WIDTH) 00486 { 00487 WindowsXend = Width + Xpos - 1; 00488 } 00489 else 00490 { 00491 WindowsXend = ST7789H2_LCD_PIXEL_WIDTH - 1; 00492 } 00493 00494 if (Height + Ypos <= ST7789H2_LCD_PIXEL_HEIGHT) 00495 { 00496 WindowsYend = Height + Ypos - 1; 00497 } 00498 else 00499 { 00500 WindowsYend = ST7789H2_LCD_PIXEL_HEIGHT-1; 00501 } 00502 } 00503 00504 /** 00505 * @brief Draw vertical line. 00506 * @param RGBCode: Specifies the RGB color in RGB565 format 00507 * @param Xpos: specifies the X position. 00508 * @param Ypos: specifies the Y position. 00509 * @param Length: specifies the Line length. 00510 * @retval None 00511 */ 00512 void ST7789H2_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00513 { 00514 uint16_t counter = 0; 00515 00516 /* Set Cursor */ 00517 ST7789H2_SetCursor(Xpos, Ypos); 00518 00519 /* Prepare to write to LCD RAM */ 00520 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */ 00521 00522 /* Sent a complete line */ 00523 for(counter = 0; counter < Length; counter++) 00524 { 00525 LCD_IO_WriteData(RGBCode); 00526 } 00527 } 00528 00529 /** 00530 * @brief Draw vertical line. 00531 * @param RGBCode: Specifies the RGB color 00532 * @param Xpos: specifies the X position. 00533 * @param Ypos: specifies the Y position. 00534 * @param Length: specifies the Line length. 00535 * @retval None 00536 */ 00537 void ST7789H2_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length) 00538 { 00539 uint16_t counter = 0; 00540 00541 /* Set Cursor */ 00542 ST7789H2_SetCursor(Xpos, Ypos); 00543 00544 /* Prepare to write to LCD RAM */ 00545 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */ 00546 00547 /* Fill a complete vertical line */ 00548 for(counter = 0; counter < Length; counter++) 00549 { 00550 ST7789H2_WritePixel(Xpos, Ypos + counter, RGBCode); 00551 } 00552 } 00553 00554 /** 00555 * @brief Displays a bitmap picture. 00556 * @param BmpAddress: Bmp picture address. 00557 * @param Xpos: Bmp X position in the LCD 00558 * @param Ypos: Bmp Y position in the LCD 00559 * @retval None 00560 */ 00561 void ST7789H2_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp) 00562 { 00563 uint32_t index = 0, size = 0; 00564 uint32_t posY; 00565 uint32_t nb_line = 0; 00566 uint16_t Xsize = WindowsXend - WindowsXstart + 1; 00567 uint16_t Ysize = WindowsYend - WindowsYstart + 1; 00568 00569 /* Read bitmap size */ 00570 size = *(volatile uint16_t *) (pbmp + 2); 00571 size |= (*(volatile uint16_t *) (pbmp + 4)) << 16; 00572 /* Get bitmap data address offset */ 00573 index = *(volatile uint16_t *) (pbmp + 10); 00574 index |= (*(volatile uint16_t *) (pbmp + 12)) << 16; 00575 size = (size - index)/2; 00576 pbmp += index; 00577 00578 for (posY = (Ypos + Ysize); posY > Ypos; posY--) /* In BMP files the line order is inverted */ 00579 { 00580 /* Set Cursor */ 00581 ST7789H2_SetCursor(Xpos, posY - 1); 00582 00583 /* Draw one line of the picture */ 00584 ST7789H2_DrawRGBHLine(Xpos, posY - 1, Xsize, (pbmp + (nb_line * Xsize * 2))); 00585 nb_line++; 00586 } 00587 } 00588 00589 /** 00590 * @brief Displays picture. 00591 * @param pdata: picture address. 00592 * @param Xpos: Image X position in the LCD 00593 * @param Ypos: Image Y position in the LCD 00594 * @param Xsize: Image X size in the LCD 00595 * @param Ysize: Image Y size in the LCD 00596 * @retval None 00597 */ 00598 void ST7789H2_DrawRGBImage(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint16_t Ysize, uint8_t *pdata) 00599 { 00600 uint32_t posY; 00601 uint32_t nb_line = 0; 00602 00603 for (posY = Ypos; posY < (Ypos + Ysize); posY ++) 00604 { 00605 /* Set Cursor */ 00606 ST7789H2_SetCursor(Xpos, posY); 00607 00608 /* Draw one line of the picture */ 00609 ST7789H2_DrawRGBHLine(Xpos, posY, Xsize, (pdata + (nb_line * Xsize * 2))); 00610 nb_line++; 00611 } 00612 } 00613 00614 00615 /****************************************************************************** 00616 Static Functions 00617 *******************************************************************************/ 00618 00619 /** 00620 * @brief Read pixel from LCD RAM in RGB888 format 00621 * @param Xpos: specifies the X position. 00622 * @param Ypos: specifies the Y position. 00623 * @retval Each RGB pixel color components in a structure 00624 */ 00625 static ST7789H2_Rgb888 ST7789H2_ReadPixel_rgb888(uint16_t Xpos, uint16_t Ypos) 00626 { 00627 ST7789H2_Rgb888 rgb888; 00628 uint16_t rgb888_part1, rgb888_part2; 00629 00630 /* In LCD RAM, pixels are 24 bits packed and read with 16 bits access 00631 * Here is the pixels components arrangement in memory : 00632 * bits: 15 14 13 12 11 10 09 08 | 07 06 05 04 03 02 01 00 00633 * address 0 : red pixel 0 X X | green pixel 0 X X 00634 * address 1 : blue pixel 0 X X | red pixel 1 X X 00635 * address 2 : green pixel 1 X X | blue pixel 1 X X 00636 */ 00637 00638 /* Set Cursor */ 00639 ST7789H2_SetCursor(Xpos, Ypos); 00640 /* Prepare to read LCD RAM */ 00641 ST7789H2_WriteReg(ST7789H2_READ_RAM, (uint8_t*)NULL, 0); /* RAM read data command */ 00642 /* Dummy read */ 00643 LCD_IO_ReadData(); 00644 /* Read first part of the RGB888 data */ 00645 rgb888_part1 = LCD_IO_ReadData(); 00646 /* Read first part of the RGB888 data */ 00647 rgb888_part2 = LCD_IO_ReadData(); 00648 00649 /* red component */ 00650 rgb888.red = (rgb888_part1 & 0xFC00) >> 8; 00651 /* green component */ 00652 rgb888.green = (rgb888_part1 & 0x00FC) >> 0; 00653 /* blue component */ 00654 rgb888.blue = (rgb888_part2 & 0xFC00) >> 8; 00655 00656 return rgb888; 00657 } 00658 00659 00660 /** 00661 * @brief Displays a single picture line. 00662 * @param pdata: picture address. 00663 * @param Xpos: Image X position in the LCD 00664 * @param Ypos: Image Y position in the LCD 00665 * @param Xsize: Image X size in the LCD 00666 * @retval None 00667 */ 00668 static void ST7789H2_DrawRGBHLine(uint16_t Xpos, uint16_t Ypos, uint16_t Xsize, uint8_t *pdata) 00669 { 00670 uint32_t i = 0; 00671 uint32_t posX; 00672 uint16_t *rgb565 = (uint16_t*)pdata; 00673 00674 /* Prepare to write to LCD RAM */ 00675 ST7789H2_WriteReg(ST7789H2_WRITE_RAM, (uint8_t*)NULL, 0); /* RAM write data command */ 00676 00677 for (posX = Xpos; posX < (Xsize + Xpos); posX++) 00678 { 00679 if ((posX >= WindowsXstart) && (Ypos >= WindowsYstart) && /* Check we are in the defined window */ 00680 (posX <= WindowsXend) && (Ypos <= WindowsYend)) 00681 { 00682 if (posX != (Xsize + Xpos)) /* When writing last pixel when size is odd, the third part is not written */ 00683 { 00684 LCD_IO_WriteData(rgb565[i]); 00685 } 00686 i++; 00687 } 00688 } 00689 } 00690 00691 /** 00692 * @} 00693 */ 00694 00695 /** 00696 * @} 00697 */ 00698 00699 /** 00700 * @} 00701 */ 00702 00703 /** 00704 * @} 00705 */ 00706 00707 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 15:07:44 by
1.7.2