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.
Dependencies: MAX17055 MAX32620FTHR MAX77650 SerialGPS
LCD_GUI.cpp
00001 #include "LCD_GUI.h" 00002 #include <stdio.h> 00003 #include "fonts.h" 00004 #include "font8.h" 00005 #include "font12.h" 00006 #include "font16.h" 00007 #include "font20.h" 00008 #include "font24.h" 00009 00010 extern LCD_DIS sLCD_DIS; 00011 00012 void GUI_Swop(POINT Point1, POINT Point2) 00013 { 00014 POINT Temp; 00015 Temp = Point1; 00016 Point1 = Point2; 00017 Point2 = Temp; 00018 } 00019 00020 /******************************************************************************** 00021 function: Draw Point(Xpoint, Ypoint) Fill the color 00022 parameter: 00023 Xpoint : The x coordinate of the point 00024 Ypoint : The y coordinate of the point 00025 Color : Set color 00026 Dot_Pixel : point size 00027 ********************************************************************************/ 00028 void GUI_DrawPoint(POINT Xpoint, POINT Ypoint, COLOR Color, 00029 DOT_PIXEL Dot_Pixel, DOT_STYLE DOT_STYLE) 00030 { 00031 if(Xpoint > sLCD_DIS.LCD_Dis_Column || Ypoint > sLCD_DIS.LCD_Dis_Page) { 00032 return; 00033 } 00034 00035 uint16_t XDir_Num ,YDir_Num; 00036 if(DOT_STYLE == DOT_STYLE_DFT) { 00037 for(XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) { 00038 for(YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) { 00039 LCD_SetPointlColor(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color); 00040 } 00041 } 00042 } else { 00043 for(XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) { 00044 for(YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) { 00045 LCD_SetPointlColor(Xpoint + XDir_Num - 1 , Ypoint + YDir_Num -1 , Color); 00046 } 00047 } 00048 } 00049 } 00050 00051 /******************************************************************************** 00052 function: Draw a line of arbitrary slope 00053 parameter: 00054 Xstart :Starting x point coordinates 00055 Ystart :Starting x point coordinates 00056 Xend :End point x coordinate 00057 Yend :End point y coordinate 00058 Color :The color of the line segment 00059 ********************************************************************************/ 00060 void GUI_DrawLine(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend, 00061 COLOR Color, LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel) 00062 { 00063 00064 if(Xstart > sLCD_DIS.LCD_Dis_Column || Ystart > sLCD_DIS.LCD_Dis_Page || 00065 Xend > sLCD_DIS.LCD_Dis_Column || Yend > sLCD_DIS.LCD_Dis_Page) { 00066 return; 00067 } 00068 00069 if(Xstart > Xend) 00070 GUI_Swop(Xstart,Xend); 00071 if(Ystart > Yend) 00072 GUI_Swop(Ystart,Yend); 00073 00074 POINT Xpoint = Xstart; 00075 POINT Ypoint = Ystart; 00076 int32_t dx =(int32_t)Xend -(int32_t)Xstart >= 0 ? Xend - Xstart : Xstart - Xend; 00077 int32_t dy =(int32_t)Yend -(int32_t)Ystart <= 0 ? Yend - Ystart : Ystart - Yend; 00078 00079 // Increment direction, 1 is positive, -1 is counter; 00080 int32_t XAddway = Xstart < Xend ? 1 : -1; 00081 int32_t YAddway = Ystart < Yend ? 1 : -1; 00082 00083 //Cumulative error 00084 int32_t Esp = dx + dy; 00085 int8_t Line_Style_Temp = 0; 00086 00087 for(;;) { 00088 Line_Style_Temp++; 00089 //Painted dotted line, 2 point is really virtual 00090 if(Line_Style == LINE_DOTTED && Line_Style_Temp %3 == 0) { 00091 //printf("LINE_DOTTED\r\n"); 00092 GUI_DrawPoint(Xpoint, Ypoint, GUI_BACKGROUND, Dot_Pixel, DOT_STYLE_DFT); 00093 Line_Style_Temp = 0; 00094 } else { 00095 GUI_DrawPoint(Xpoint, Ypoint, Color, Dot_Pixel, DOT_STYLE_DFT); 00096 } 00097 if(2 * Esp >= dy) { 00098 if(Xpoint == Xend) break; 00099 Esp += dy; 00100 Xpoint += XAddway; 00101 } 00102 if(2 * Esp <= dx) { 00103 if(Ypoint == Yend) break; 00104 Esp += dx; 00105 Ypoint += YAddway; 00106 } 00107 } 00108 } 00109 00110 /******************************************************************************** 00111 function: Draw a rectangle 00112 parameter: 00113 Xstart :Rectangular Starting x point coordinates 00114 Ystart :Rectangular Starting x point coordinates 00115 Xend :Rectangular End point x coordinate 00116 Yend :Rectangular End point y coordinate 00117 Color :The color of the Rectangular segment 00118 Filled : Whether it is filled--- 1 solid 0:empty 00119 ********************************************************************************/ 00120 void GUI_DrawRectangle(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend, 00121 COLOR Color, DRAW_FILL Filled, DOT_PIXEL Dot_Pixel ) 00122 { 00123 if(Xstart > sLCD_DIS.LCD_Dis_Column || Ystart > sLCD_DIS.LCD_Dis_Page || 00124 Xend > sLCD_DIS.LCD_Dis_Column || Yend > sLCD_DIS.LCD_Dis_Page) { 00125 return; 00126 } 00127 00128 if(Xstart > Xend) 00129 GUI_Swop(Xstart,Xend); 00130 if(Ystart > Yend) 00131 GUI_Swop(Ystart,Yend); 00132 00133 POINT Ypoint; 00134 if(Filled ) { 00135 for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) { 00136 GUI_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , LINE_SOLID, Dot_Pixel); 00137 } 00138 } else { 00139 GUI_DrawLine(Xstart, Ystart, Xend, Ystart, Color , LINE_SOLID, Dot_Pixel); 00140 GUI_DrawLine(Xstart, Ystart, Xstart, Yend, Color , LINE_SOLID, Dot_Pixel); 00141 GUI_DrawLine(Xend, Yend, Xend, Ystart, Color , LINE_SOLID, Dot_Pixel); 00142 GUI_DrawLine(Xend, Yend, Xstart, Yend, Color , LINE_SOLID, Dot_Pixel); 00143 } 00144 } 00145 00146 /******************************************************************************** 00147 function: Use the 8-point method to draw a circle of the 00148 specified size at the specified position. 00149 parameter: 00150 X_Center :Center X coordinate 00151 Y_Center :Center Y coordinate 00152 Radius :circle Radius 00153 Color :The color of the :circle segment 00154 Filled : Whether it is filled: 1 filling 0:Do not 00155 ********************************************************************************/ 00156 void GUI_DrawCircle(POINT X_Center, POINT Y_Center, LENGTH Radius, 00157 COLOR Color, DRAW_FILL Draw_Fill , DOT_PIXEL Dot_Pixel) 00158 { 00159 if(X_Center > sLCD_DIS.LCD_Dis_Column || Y_Center >= sLCD_DIS.LCD_Dis_Page) { 00160 return; 00161 } 00162 00163 //Draw a circle from(0, R) as a starting point 00164 int16_t XCurrent, YCurrent; 00165 XCurrent = 0; 00166 YCurrent = Radius; 00167 00168 //Cumulative error,judge the next point of the logo 00169 int16_t Esp = 3 -(Radius << 1 ); 00170 00171 int16_t sCountY; 00172 if(Draw_Fill == DRAW_FULL) { 00173 while(XCurrent <= YCurrent ) { //Realistic circles 00174 for(sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) { 00175 GUI_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); //1 00176 GUI_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); //2 00177 GUI_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); //3 00178 GUI_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); //4 00179 GUI_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); //5 00180 GUI_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); //6 00181 GUI_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); //7 00182 GUI_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT ); 00183 } 00184 if(Esp < 0 ) 00185 Esp += 4 * XCurrent + 6; 00186 else { 00187 Esp += 10 + 4 *(XCurrent - YCurrent ); 00188 YCurrent --; 00189 } 00190 XCurrent ++; 00191 } 00192 } else { //Draw a hollow circle 00193 while(XCurrent <= YCurrent ) { 00194 GUI_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //1 00195 GUI_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //2 00196 GUI_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //3 00197 GUI_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //4 00198 GUI_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //5 00199 GUI_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //6 00200 GUI_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //7 00201 GUI_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT ); //0 00202 00203 if(Esp < 0 ) 00204 Esp += 4 * XCurrent + 6; 00205 else { 00206 Esp += 10 + 4 *(XCurrent - YCurrent ); 00207 YCurrent --; 00208 } 00209 XCurrent ++; 00210 } 00211 } 00212 } 00213 00214 /******************************************************************************** 00215 function: Show English characters 00216 parameter: 00217 Xpoint :X coordinate 00218 Ypoint :Y coordinate 00219 Acsii_Char :To display the English characters 00220 Font :A structure pointer that displays a character size 00221 Color_Background : Select the background color of the English character 00222 Color_Foreground : Select the foreground color of the English character 00223 ********************************************************************************/ 00224 void GUI_DisChar(POINT Xpoint, POINT Ypoint, const char Acsii_Char, 00225 sFONT* Font, COLOR Color_Background, COLOR Color_Foreground) 00226 { 00227 POINT Page, Column; 00228 00229 if(Xpoint >= sLCD_DIS.LCD_Dis_Column || Ypoint >= sLCD_DIS.LCD_Dis_Page) { 00230 return; 00231 } 00232 00233 uint32_t Char_Offset =(Acsii_Char - ' ') * Font->Height *(Font->Width / 8 +(Font->Width % 8 ? 1 : 0)); 00234 const unsigned char *ptr = &Font->table[Char_Offset]; 00235 00236 for(Page = 0; Page < Font->Height; Page ++ ) { 00237 for(Column = 0; Column < Font->Width; Column ++ ) { 00238 00239 //To determine whether the font background color and screen background color is consistent 00240 if(FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan 00241 if(*ptr &(0x80 >>(Column % 8))) 00242 GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT); 00243 } else { 00244 if(*ptr &(0x80 >>(Column % 8))) { 00245 GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT); 00246 } else { 00247 GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT); 00248 } 00249 } 00250 //One pixel is 8 bits 00251 if(Column % 8 == 7) 00252 ptr++; 00253 }/* Write a line */ 00254 if(Font->Width % 8 != 0) 00255 ptr++; 00256 }/* Write all */ 00257 } 00258 00259 /******************************************************************************** 00260 function: Display the string 00261 parameter: 00262 Xstart :X coordinate 00263 Ystart :Y coordinate 00264 pString :The first address of the English string to be displayed 00265 Font :A structure pointer that displays a character size 00266 Color_Background : Select the background color of the English character 00267 Color_Foreground : Select the foreground color of the English character 00268 ********************************************************************************/ 00269 void GUI_DisString_EN(POINT Xstart, POINT Ystart, const char * pString, 00270 sFONT* Font,COLOR Color_Background, COLOR Color_Foreground ) 00271 { 00272 POINT Xpoint = Xstart; 00273 POINT Ypoint = Ystart; 00274 00275 if(Xstart >= sLCD_DIS.LCD_Dis_Column || Ystart >= sLCD_DIS.LCD_Dis_Page) { 00276 return; 00277 } 00278 00279 while(* pString != '\0') { 00280 //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the height of the character 00281 if((Xpoint + Font->Width ) > sLCD_DIS.LCD_Dis_Column ) { 00282 Xpoint = Xstart; 00283 Ypoint += Font->Height; 00284 } 00285 00286 // If the Y direction is full, reposition to(Xstart, Ystart) 00287 if((Ypoint + Font->Height ) > sLCD_DIS.LCD_Dis_Page ) { 00288 Xpoint = Xstart; 00289 Ypoint = Ystart; 00290 } 00291 GUI_DisChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground); 00292 00293 //The next character of the address 00294 pString ++; 00295 00296 //The next word of the abscissa increases the font of the broadband 00297 Xpoint += Font->Width + 1; 00298 } 00299 } 00300 00301 /****************************************WHITE**************************************** 00302 function: Display the string 00303 parameter: 00304 Xstart :X coordinate 00305 Ystart : Y coordinate 00306 Nummber: The number displayed 00307 Font :A structure pointer that displays a character size 00308 Color_Background : Select the background color of the English character 00309 Color_Foreground : Select the foreground color of the English character 00310 ********************************************************************************/ 00311 #define ARRAY_LEN 255 00312 void GUI_DisNum(POINT Xpoint, POINT Ypoint, int32_t Nummber, 00313 sFONT* Font,COLOR Color_Background, COLOR Color_Foreground ) 00314 { 00315 00316 int16_t Num_Bit = 0, Str_Bit = 0; 00317 uint8_t Str_Array[ARRAY_LEN] = {0},Num_Array[ARRAY_LEN] = {0}; 00318 uint8_t *pStr = Str_Array; 00319 00320 if(Xpoint >= sLCD_DIS.LCD_Dis_Column || Ypoint >= sLCD_DIS.LCD_Dis_Page) { 00321 return; 00322 } 00323 00324 //Converts a number to a string 00325 while(Nummber) { 00326 Num_Array[Num_Bit] = Nummber % 10 + '0'; 00327 Num_Bit++; 00328 Nummber /= 10; 00329 } 00330 00331 //The string is inverted 00332 while(Num_Bit > 0) { 00333 Str_Array[Str_Bit] = Num_Array[Num_Bit -1]; 00334 Str_Bit ++; 00335 Num_Bit --; 00336 } 00337 00338 //show 00339 GUI_DisString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground ); 00340 } 00341 00342 void GUI_Disbitmap(POINT Xpoint, POINT Ypoint, const unsigned char *pBmp, 00343 POINT Width, POINT Height) 00344 { 00345 POINT i, j, byteWidth = (Width + 7)/8; 00346 for(j = 0; j < Height; j++) { 00347 for(i = 0; i <Width; i ++) { 00348 if(*(pBmp + j*byteWidth + i/8) & (128 >> (i & 7))) { 00349 GUI_DrawPoint(Xpoint+i, Ypoint+j, WHITE, DOT_PIXEL_DFT, DOT_STYLE_DFT); 00350 } 00351 } 00352 } 00353 } 00354 00355 /** 00356 * @brief This function paints an image with a specific heigh and width on the display at a specific coordinate. 00357 * @param picture[] Integer array containg picture image in rgb565 format 00358 * @param width Image width 00359 * @param height Image height 00360 * @param x X coordinates of image 00361 * @param y Y coordinates of image 00362 * @return none 00363 */ 00364 void GUI_DisplayImage(POINT Xpoint, POINT Ypoint,COLOR picture[],POINT Width, POINT Height) 00365 { 00366 unsigned int i,j,k; 00367 k=0; 00368 for(i=0;i<Width;i++) 00369 { 00370 for(j=0;j<Height;j++) 00371 { 00372 GUI_DrawPoint(Xpoint+i, Ypoint+j, picture[k], DOT_PIXEL_DFT, DOT_STYLE_DFT); 00373 k++; 00374 } 00375 } 00376 } 00377 00378 /******************************************************************************** 00379 function: LCD_Show 00380 parameter: 00381 ********************************************************************************/ 00382 void GUI_Show(void) 00383 { 00384 LCD_Clear(GUI_BACKGROUND); 00385 00386 printf("GUI Draw Line \r\n"); 00387 GUI_DrawLine(0, 10, sLCD_DIS.LCD_Dis_Column, 10, RED,LINE_SOLID, DOT_PIXEL_2X2); 00388 //GUI_DrawLine(0, sLCD_DIS.LCD_Dis_Page - 10, sLCD_DIS.LCD_Dis_Column, sLCD_DIS.LCD_Dis_Page - 10, RED,LINE_SOLID, DOT_PIXEL_2X2); 00389 GUI_DrawLine(0, 20, sLCD_DIS.LCD_Dis_Column, 20, RED,LINE_DOTTED, DOT_PIXEL_DFT); 00390 //GUI_DrawLine(0, sLCD_DIS.LCD_Dis_Page - 20, sLCD_DIS.LCD_Dis_Column, sLCD_DIS.LCD_Dis_Page - 20, RED,LINE_DOTTED, DOT_PIXEL_DFT); 00391 00392 printf("GUI Draw Rectangle \r\n"); 00393 GUI_DrawRectangle(0,0,160,9,BLUE, DRAW_FULL, DOT_PIXEL_1X1); 00394 //GUI_DrawRectangle(1,1,128,128,RED,DRAW_EMPTY,DOT_PIXEL_2X2); 00395 00396 printf("GUI Draw Olympic Rings\r\n"); 00397 uint16_t Cx1 = 40, Cy1 = 85, Cr = 12; 00398 uint16_t Cx2 = Cx1 + (2.5 * Cr), Cy2 = Cy1; 00399 uint16_t Cx3 = Cx1 + (5 * Cr), Cy3 = Cy1; 00400 uint16_t Cx4 = ( Cx1 + Cx2 )/2, Cy4 = Cy1 + Cr; 00401 uint16_t Cx5 = ( Cx2 + Cx3 )/2, Cy5 = Cy1 + Cr; 00402 00403 GUI_DrawCircle( Cx1, Cy1, Cr, BLUE, DRAW_EMPTY, DOT_PIXEL_DFT); 00404 GUI_DrawCircle( Cx2, Cy2, Cr, BLACK, DRAW_EMPTY, DOT_PIXEL_DFT); 00405 GUI_DrawCircle( Cx3, Cy3, Cr, RED, DRAW_EMPTY, DOT_PIXEL_DFT); 00406 GUI_DrawCircle( Cx4, Cy4, Cr, YELLOW, DRAW_EMPTY, DOT_PIXEL_DFT); 00407 GUI_DrawCircle( Cx5, Cy5, Cr, GREEN, DRAW_EMPTY, DOT_PIXEL_DFT); 00408 00409 printf("GUI Draw Realistic circles\r\n"); 00410 GUI_DrawCircle(15, 110, 10, BRRED, DRAW_FULL, DOT_PIXEL_DFT); 00411 GUI_DrawCircle(sLCD_DIS.LCD_Dis_Column - 15, 110, 10, BRRED, DRAW_FULL, DOT_PIXEL_DFT); 00412 00413 printf("GUI Display String \r\n"); 00414 GUI_DisString_EN(35,20,"ZYNQ",&Font12,GUI_BACKGROUND,BLUE); 00415 GUI_DisString_EN(32,33,"ST7735",&Font12,GUI_BACKGROUND,BLUE); 00416 GUI_DisString_EN(28,45,"1.44inch TFTLCD",&Font8,RED,GRED); 00417 00418 printf("GUI Display Nummber \r\n"); 00419 GUI_DisNum(28,55,1234567890,&Font20,GUI_BACKGROUND,BLUE); 00420 } 00421 00422
Generated on Thu Jul 14 2022 11:13:12 by
1.7.2