OLED_GUI.c 23.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
/******************************************************************************
****************************Upper application layer****************************
* | file      	:	OLED_GUI.c
* |	version		:	V1.0
* | date		:	2017-11-09
* | function	:	
Achieve drawing: draw points, lines, boxes, circles and their size, 
				solid dotted line, solid rectangle hollow rectangle, 
				solid circle hollow circle.
Achieve display characters: Display a single character, string, number
Achieve time display: adaptive size display time minutes and seconds		
******************************************************************************/
#include <stdio.h>

#include "OLED_GUI.h"

extern OLED_DIS sOLED_DIS;
extern COLOR Buffer[OLED_WIDTH / 2 * OLED_HEIGHT];
/******************************************************************************
function:	Coordinate conversion
******************************************************************************/
void GUI_Swop(POINT Point1, POINT Point2)
{
    POINT Temp;
    Temp = Point1;
    Point1 = Point2;
    Point2 = Temp;
}

/******************************************************************************
function:	Draw Point(Xpoint, Ypoint) Fill the color
parameter:
	Xpoint		:   The x coordinate of the point
	Ypoint		:   The y coordinate of the point
	Color		:   Set color
	Dot_Pixel	:	point size
******************************************************************************/
void GUI_DrawPoint(POINT Xpoint, POINT Ypoint, COLOR Color,
                   DOT_PIXEL Dot_Pixel, DOT_STYLE DOT_STYLE)
{
    if(Xpoint > sOLED_DIS.OLED_Dis_Column || Ypoint > sOLED_DIS.OLED_Dis_Page) {
		printf("GUI_DrawPoint Input exceeds the normal display range\r\n");
        return;
    }

    uint16_t XDir_Num ,YDir_Num;
    if(DOT_STYLE == DOT_STYLE_DFT) {
        for(XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
            for(YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
//				printf("YDir_Num = %d\r\n",YDir_Num);
                OLED_SetColor(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
            }
        }
    } else {
        for(XDir_Num = 0; XDir_Num <  Dot_Pixel; XDir_Num++) {
            for(YDir_Num = 0; YDir_Num <  Dot_Pixel; YDir_Num++) {
                OLED_SetColor(Xpoint + XDir_Num, Ypoint + YDir_Num, Color);
            }
        }
    }
}

/******************************************************************************
function:	Draw a line of arbitrary slope
parameter:
	Xstart :Starting x point coordinates
	Ystart :Starting x point coordinates
	Xend   :End point x coordinate
	Yend   :End point y coordinate
	Color  :The color of the line segment
******************************************************************************/
void GUI_DrawLine(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend,
                  COLOR Color, LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel)
{
    if(Xstart > sOLED_DIS.OLED_Dis_Column || Ystart > sOLED_DIS.OLED_Dis_Page ||
       Xend > sOLED_DIS.OLED_Dis_Column || Yend > sOLED_DIS.OLED_Dis_Page) {
		   printf("GUI_DrawLine Input exceeds the normal display range\r\n");
        return;
    }

    if(Xstart > Xend)
        GUI_Swop(Xstart,Xend);
    if(Ystart > Yend)
        GUI_Swop(Ystart,Yend);

    POINT Xpoint = Xstart;
    POINT Ypoint = Ystart;
    int32_t dx =(int32_t)Xend -(int32_t)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
    int32_t dy =(int32_t)Yend -(int32_t)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;

    // Increment direction, 1 is positive, -1 is counter;
    int32_t XAddway = Xstart < Xend ? 1 : -1;
    int32_t YAddway = Ystart < Yend ? 1 : -1;

    //Cumulative error
    int32_t Esp = dx + dy;
    int8_t Line_Style_Temp = 0;

    for(;;) {
        Line_Style_Temp++;
        //Painted dotted line, 2 point is really virtual
        if(Line_Style == LINE_DOTTED && Line_Style_Temp %3 == 0) {
            //printf("LINE_DOTTED\r\n");
            GUI_DrawPoint(Xpoint, Ypoint, OLED_BACKGROUND, Dot_Pixel, DOT_STYLE_DFT);
            Line_Style_Temp = 0;
        } else {
            GUI_DrawPoint(Xpoint, Ypoint, Color, Dot_Pixel, DOT_STYLE_DFT);
        }
        if(2 * Esp >= dy) {
            if(Xpoint == Xend) break;
            Esp += dy;
            Xpoint += XAddway;
        }
        if(2 * Esp <= dx) {
            if(Ypoint == Yend) break;
            Esp += dx;
            Ypoint += YAddway;
        }
    }
}

/******************************************************************************
function:	Draw a rectangle
parameter:
	Xstart :Rectangular  Starting x point coordinates
	Ystart :Rectangular  Starting x point coordinates
	Xend   :Rectangular  End point x coordinate
	Yend   :Rectangular  End point y coordinate
	Color  :The color of the Rectangular segment
	Filled : Whether it is filled--- 1 solid 0:empty
******************************************************************************/
void GUI_DrawRectangle(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend,
                       COLOR Color, DRAW_FILL Filled, DOT_PIXEL Dot_Pixel )
{
    if(Xstart > sOLED_DIS.OLED_Dis_Column || Ystart > sOLED_DIS.OLED_Dis_Page ||
       Xend > sOLED_DIS.OLED_Dis_Column || Yend > sOLED_DIS.OLED_Dis_Page) {
		   printf("Input exceeds the normal display range\r\n");
        return;
    }

    if(Xstart > Xend)
        GUI_Swop(Xstart,Xend);
    if(Ystart > Yend)
        GUI_Swop(Ystart,Yend);

    POINT Ypoint;
    if(Filled ) {
        for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {
            GUI_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , LINE_SOLID, Dot_Pixel);
        }
    } else {
        GUI_DrawLine(Xstart, Ystart, Xend, Ystart, Color , LINE_SOLID, Dot_Pixel);
        GUI_DrawLine(Xstart, Ystart, Xstart, Yend, Color , LINE_SOLID, Dot_Pixel);
        GUI_DrawLine(Xend, Yend, Xend, Ystart, Color , LINE_SOLID, Dot_Pixel);
        GUI_DrawLine(Xend, Yend, Xstart, Yend, Color , LINE_SOLID, Dot_Pixel);
    }
}

/******************************************************************************
function:	Use the 8-point method to draw a circle of the
				specified size at the specified position.
parameter:
	X_Center  :Center X coordinate
	Y_Center  :Center Y coordinate
	Radius    :circle Radius
	Color     :The color of the :circle segment
	Filled    : Whether it is filled: 1 filling 0:Do not
******************************************************************************/
void GUI_DrawCircle(POINT X_Center, POINT Y_Center, LENGTH Radius,
                    COLOR Color, DRAW_FILL  Draw_Fill , DOT_PIXEL Dot_Pixel)
{
    if(X_Center > sOLED_DIS.OLED_Dis_Column || Y_Center >= sOLED_DIS.OLED_Dis_Page) {
		printf("GUI_DrawCircle Input exceeds the normal display range\r\n");
        return;
    }

    //Draw a circle from(0, R) as a starting point
    int16_t XCurrent, YCurrent;
    XCurrent = 0;
    YCurrent = Radius;

    //Cumulative error,judge the next point of the logo
    int16_t Esp = 3 -(Radius << 1 );

    int16_t sCountY;
    if(Draw_Fill == DRAW_FULL) {
        while(XCurrent <= YCurrent ) { //Realistic circles
            for(sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {
                GUI_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );             //1
                GUI_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );             //2
                GUI_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );             //3
                GUI_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );             //4
                GUI_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );             //5
                GUI_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );             //6
                GUI_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );             //7
                GUI_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT );
            }
            if(Esp < 0 )
                Esp += 4 * XCurrent + 6;
            else {
                Esp += 10 + 4 *(XCurrent - YCurrent );
                YCurrent --;
            }
            XCurrent ++;
        }
    } else { //Draw a hollow circle
        while(XCurrent <= YCurrent ) {
            GUI_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //1
            GUI_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //2
            GUI_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //3
            GUI_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //4
            GUI_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //5
            GUI_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //6
            GUI_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //7
            GUI_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Dot_Pixel, DOT_STYLE_DFT );             //0

            if(Esp < 0 )
                Esp += 4 * XCurrent + 6;
            else {
                Esp += 10 + 4 *(XCurrent - YCurrent );
                YCurrent --;
            }
            XCurrent ++;
        }
    }
}

/******************************************************************************
function:	Show English characters
parameter:
	Xpoint           :X coordinate
	Ypoint           :Y coordinate
	Acsii_Char       :To display the English characters
	Font             :A structure pointer that displays a character size
	Color_Background : Select the background color of the English character
	Color_Foreground : Select the foreground color of the English character
******************************************************************************/
void GUI_DisChar(POINT Xpoint, POINT Ypoint, const char Acsii_Char,
                 sFONT* Font, COLOR Color_Background, COLOR Color_Foreground)
{
    POINT Page, Column;

    if(Xpoint > sOLED_DIS.OLED_Dis_Column || Ypoint > sOLED_DIS.OLED_Dis_Page) {
		printf("GUI_DisChar Input exceeds the normal display range\r\n");
        return;
    }

    uint32_t Char_Offset =(Acsii_Char - ' ') * Font->Height *(Font->Width / 8 +(Font->Width % 8 ? 1 : 0));
    const unsigned char *ptr = &Font->table[Char_Offset];

    for(Page = 0; Page < Font->Height; Page ++ ) {
        for(Column = 0; Column < Font->Width; Column ++ ) {

            //To determine whether the font background color and screen background color is consistent
            if(FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
                if(*ptr &(0x80 >>(Column % 8)))
                    GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
            } else {
                if(*ptr &(0x80 >>(Column % 8))) {
                    GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
                } else {
                    GUI_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
                }
            }
            //One pixel is 8 bits
            if(Column % 8 == 7)
                ptr++;
        }/* Write a line */
        if(Font->Width % 8 != 0)
            ptr++;
    }/* Write all */
}

/******************************************************************************
function:	Display the string
parameter:
	Xstart           :X coordinate
	Ystart           :Y coordinate
	pString          :The first address of the English string to be displayed
	Font             :A structure pointer that displays a character size
	Color_Background : Select the background color of the English character
	Color_Foreground : Select the foreground color of the English character
******************************************************************************/
void GUI_DisString_EN(POINT Xstart, POINT Ystart, const char * pString,
                      sFONT* Font,COLOR Color_Background, COLOR Color_Foreground )
{
    POINT Xpoint = Xstart;
    POINT Ypoint = Ystart;

    if(Xstart > sOLED_DIS.OLED_Dis_Column || Ystart > sOLED_DIS.OLED_Dis_Page) {
		printf("GUI_DisString_EN Input exceeds the normal display range\r\n");
        return;
    }

    while(* pString != '\0') {
        //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the height of the character
        if((Xpoint + Font->Width ) > sOLED_DIS.OLED_Dis_Column ) {
            Xpoint = Xstart;
            Ypoint += Font->Height;
        }

        // If the Y direction is full, reposition to(Xstart, Ystart)
        if((Ypoint  + Font->Height ) > sOLED_DIS.OLED_Dis_Page ) {
            Xpoint = Xstart;
            Ypoint = Ystart;
        }
        GUI_DisChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);

        //The next character of the address
        pString ++;

        //The next word of the abscissa increases the font of the broadband
        Xpoint += Font->Width;
    }
}

/******************************************************************************
function:	Display the string
parameter:
	Xstart           :X coordinate
	Ystart           : Y coordinate
	Nummber          : The number displayed
	Font             :A structure pointer that displays a character size
	Color_Background : Select the background color of the English character
	Color_Foreground : Select the foreground color of the English character
******************************************************************************/
#define  ARRAY_LEN 255
void GUI_DisNum(POINT Xpoint, POINT Ypoint, int32_t Nummber,
                sFONT* Font,COLOR Color_Background, COLOR Color_Foreground )
{

    int16_t Num_Bit = 0, Str_Bit = 0;
    uint8_t Str_Array[ARRAY_LEN] = {0},Num_Array[ARRAY_LEN] = {0};
    uint8_t *pStr = Str_Array;

    if(Xpoint > sOLED_DIS.OLED_Dis_Column || Ypoint > sOLED_DIS.OLED_Dis_Page) {
		printf("GUI_DisNum Input exceeds the normal display range\r\n");
        return;
    }

		if (!Nummber)
		{
				Num_Array[Num_Bit] = Nummber % 10 + '0';
        Num_Bit++;
		}
    //Converts a number to a string
    while(Nummber) {
        Num_Array[Num_Bit] = Nummber % 10 + '0';
        Num_Bit++;
        Nummber /= 10;
    }

    //The string is inverted
    while(Num_Bit > 0) {
        Str_Array[Str_Bit] = Num_Array[Num_Bit -1];
        Str_Bit ++;
        Num_Bit --;
    }

    //show
    GUI_DisString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground );
}



/******************************************************************************
function:	Display the bit map,1 byte = 8bit = 8 points
parameter:
	Xpoint :X coordinate
	Ypoint : Y coordinate
	pMap   : Pointing to the picture
	Width  :Bitmap Width
	Height : Bitmap Height
note:
	This function is suitable for bitmap, because a 16-bit data accounted for 16 points
******************************************************************************/
void GUI_Disbitmap(POINT Xpoint, POINT Ypoint, const unsigned char *pMap,
						POINT Width, POINT Height)
{
    POINT i, j, byteWidth = (Width + 7)/8;
    for(j = 0; j < Height; j++) {
        for(i = 0; i <Width; i ++) {
            if(*(pMap + j*byteWidth + i/8) & (128 >> (i & 7))) {
                GUI_DrawPoint(Xpoint+i, Ypoint+j, WHITE, DOT_PIXEL_DFT, DOT_STYLE_DFT);
            }
        }
    }
}

/******************************************************************************
function:	Display the Gray map,1 byte = 8bit = 2 points
parameter:
	Xpoint :X coordinate
	Ypoint : Y coordinate
	pMap   : Pointing to the picture
	Width  :Bitmap Width
	Height : Bitmap Height
note:
	This function is suitable for bitmap, because a 4-bit data accounted for 1 points
	Please use the Image2lcd generated array
******************************************************************************/
void GUI_DisGrayMap(POINT Xpoint, POINT Ypoint, const unsigned char *pBmp)
{
	//Get the Map header Gray, width, height
	char Gray;
	Gray = *(pBmp + 1);
	POINT Height,Width;
	Width = (*(pBmp + 3) << 8) | (*(pBmp + 2));
	Height = (*(pBmp + 5) << 8) | (*(pBmp + 4));
	
    POINT i, j;
	if(Gray == 0x04){//Sixteen gray levels
		pBmp = pBmp + 6;
		for(j = 0; j < Height; j++)
			for(i = 0; i < Width / 2; i++){
				GUI_DrawPoint(Xpoint + i * 2, Ypoint + j, ~(*pBmp >> 4), DOT_PIXEL_DFT, DOT_STYLE_DFT);
				GUI_DrawPoint(Xpoint + i * 2 + 1, Ypoint + j, ~*pBmp , DOT_PIXEL_DFT, DOT_STYLE_DFT);
				pBmp++;				
			}
	}else{
		printf("Does not support type\r\n");
		return;
	}
}

/******************************************************************************
function:	According to the display area adaptive display time
parameter:
		xStart :   X direction Start coordinates
		Ystart :   Y direction Start coordinates
		Xend   :   X direction end coordinates
		Yend   :   Y direction end coordinates
		pTime  :   Pointer to the definition of the structure
		Color  :   Set show color
note:
******************************************************************************/
void GUI_Showtime(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend,
					DEV_TIME *pTime,COLOR Color)
{
	uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
	sFONT *Font;
	OLED_SetWindow(Xstart, Ystart, Xend, Yend);
	OLED_ClearWindow(Xstart, Ystart, Xend, Yend, BLACK);
	
	//According to the display area adaptive font size
	POINT Dx = (Xend - Xstart) / 7;//Determine the spacing between characters
	POINT Dy = Yend - Ystart;      //determine the font size
	if(Dx > Font24.Width && Dy > Font24.Height){
		Font = &Font24;
	}else if((Dx > Font20.Width && Dx < Font24.Width) && 
			(Dy > Font20.Height && Dy < Font24.Height)){
		Font = &Font20;
	}else if((Dx > Font16.Width && Dx < Font20.Width) && 
			(Dy > Font16.Height && Dy < Font20.Height)){
		Font = &Font16;
	}else if((Dx > Font12.Width && Dx < Font16.Width) && 
			(Dy > Font12.Height && Dy < Font16.Height)){
		Font = &Font12;
	}else if((Dx > Font8.Width && Dx < Font12.Width) && 
			(Dy > Font8.Height && Dy < Font12.Height)){
		Font = &Font8;
	}else{
		printf("Please change the display area size, or add a larger font to modify\r\n");
	}
	
	//Write data into the cache
	GUI_DisChar(Xstart                           , Ystart, value[pTime->Hour / 10], Font, FONT_BACKGROUND, Color);
	GUI_DisChar(Xstart + Dx                      , Ystart, value[pTime->Hour % 10], Font, FONT_BACKGROUND, Color);
	GUI_DisChar(Xstart + Dx  + Dx / 4 + Dx / 2   , Ystart, ':'                    , Font, FONT_BACKGROUND, Color);
	GUI_DisChar(Xstart + Dx * 2 + Dx / 2         , Ystart, value[pTime->Min / 10] , Font, FONT_BACKGROUND, Color);
	GUI_DisChar(Xstart + Dx * 3 + Dx / 2         , Ystart, value[pTime->Min % 10] , Font, FONT_BACKGROUND, Color);
	GUI_DisChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':'                    , Font, FONT_BACKGROUND, Color);
	GUI_DisChar(Xstart + Dx * 5                  , Ystart, value[pTime->Sec / 10] , Font, FONT_BACKGROUND, Color);
	GUI_DisChar(Xstart + Dx * 6                  , Ystart, value[pTime->Sec % 10] , Font, FONT_BACKGROUND, Color);
	
	OLED_DisWindow(Xstart, Ystart, Xend, Yend); 
}
/******************************************************************************
function:	OLED_Show
note:
	OLED Clear,
	Draw Line,
	Draw Rectangle,
	Draw Rings,
	Draw Olympic Rings,
	Display String,
	Show Pic
******************************************************************************/
void GUI_Show(void)
{
	//printf("Clear... \r\n");
	OLED_Clear(OLED_BACKGROUND);//OLED_BACKGROUND
	OLED_Display();

	//printf("Draw Line \r\n");
	GUI_DrawLine(0, 1                          , sOLED_DIS.OLED_Dis_Column - 1, 1                          , WHITE, LINE_SOLID , DOT_PIXEL_2X2);
	GUI_DrawLine(0, 4                          , sOLED_DIS.OLED_Dis_Column - 1, 4                          , WHITE, LINE_DOTTED, DOT_PIXEL_DFT);
	GUI_DrawLine(0, sOLED_DIS.OLED_Dis_Page - 5, sOLED_DIS.OLED_Dis_Column - 1, sOLED_DIS.OLED_Dis_Page - 5, WHITE, LINE_DOTTED, DOT_PIXEL_DFT);
	GUI_DrawLine(0, sOLED_DIS.OLED_Dis_Page - 1, sOLED_DIS.OLED_Dis_Column - 1, sOLED_DIS.OLED_Dis_Page - 1, WHITE, LINE_SOLID , DOT_PIXEL_2X2);

	//printf("Draw Rectangle \r\n");
	GUI_DrawRectangle(5 , 7 , sOLED_DIS.OLED_Dis_Column - 5 , sOLED_DIS.OLED_Dis_Page - 7, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);
	GUI_DrawRectangle(10, 10, sOLED_DIS.OLED_Dis_Column - 10, 20                         , WHITE, DRAW_FULL , DOT_PIXEL_DFT);

	//printf("Draw Rings\r\n");
	GUI_DrawCircle(10, 30, 3, WHITE, DRAW_FULL , DOT_PIXEL_DFT);
	GUI_DrawCircle(10, 40, 3, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);
	GUI_DrawCircle(10, 50, 3, WHITE, DRAW_FULL , DOT_PIXEL_DFT);
	GUI_DrawCircle(sOLED_DIS.OLED_Dis_Column - 10, 30, 3, WHITE, DRAW_FULL , DOT_PIXEL_DFT);
	GUI_DrawCircle(sOLED_DIS.OLED_Dis_Column - 10, 40, 3, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);
	GUI_DrawCircle(sOLED_DIS.OLED_Dis_Column - 10, 50, 3, WHITE, DRAW_FULL , DOT_PIXEL_DFT);

	//printf("Draw Olympic Rings\r\n");
	uint16_t Cx1 = 35, Cy1 = 85, Cr = 12;
	uint16_t Cx2 = Cx1 + (2.5 * Cr), Cy2 = Cy1;
	uint16_t Cx3 = Cx1 + (5 * Cr), Cy3 = Cy1;
	uint16_t Cx4 = (Cx1 + Cx2) / 2, Cy4 = Cy1 + Cr;
	uint16_t Cx5 = (Cx2 + Cx3) / 2, Cy5 = Cy1 + Cr;

	GUI_DrawCircle(Cx1, Cy1, Cr, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);
	GUI_DrawCircle(Cx2, Cy2, Cr, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);
	GUI_DrawCircle(Cx3, Cy3, Cr, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);
	GUI_DrawCircle(Cx4, Cy4, Cr, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);
	GUI_DrawCircle(Cx5, Cy5, Cr, WHITE, DRAW_EMPTY, DOT_PIXEL_DFT);

	//printf("Display String \r\n");
	GUI_DisString_EN(30, 25, "WaveShare"   , &Font12, FONT_BACKGROUND, WHITE);
	GUI_DisString_EN(28, 35, "Electronic"  , &Font12, FONT_BACKGROUND, WHITE);
	GUI_DisString_EN(18, 45, "1.5inch OLED", &Font12, FONT_BACKGROUND, WHITE);
	
	//printf("Showing...\r\n");
	OLED_Display();
	Driver_Delay_ms(2000);
}


/*----------------------------------------------------------------------------
  User Function 
 *----------------------------------------------------------------------------*/
void OLED_Config(void)
{
	/* Init GPIO Port C for non-secure OLED control */
	GPIO_SetMode(PC_NS, BIT12 | BIT11, GPIO_MODE_OUTPUT);
	PC11_NS = 1;		//OLED_DC(DATA or COMMAND)
	PC12_NS = 1;		//OLED_RST
	
	
  /* USER CODE BEGIN 2 */  
	if(OLED_PRINT)
		printf("**********1.5inch OLED Init**********\r\n");
	System_Init();
  
	if(OLED_PRINT)
		printf("OLED_Init()...\r\n");
	OLED_Init(SCAN_DIR_DFT);//SCAN_DIR_DFT = D2U_L2R
	
	if(OLED_PRINT)
		printf("OLED_Show()...\r\n");	
	GUI_Show();
	
	if(OLED_PRINT)
		printf("************************************\r\n");
	OLED_Clear(OLED_BACKGROUND);//OLED_BACKGROUND
	OLED_Display();
}

void OLED_Background_On()
{
	OLED_SetWindow(0, 0, 127, 127);
	OLED_ClearWindow(0, 0, 127, 127, BLACK);
	
	if(OLED_PRINT)
		printf("Show toolbar icons\n");
	GUI_Disbitmap(0  , 2, Signal816  , 16, 8);
	GUI_Disbitmap(24 , 2, Bluetooth88, 8 , 8);
	GUI_Disbitmap(40 , 2, Msg816     , 16, 8);
	GUI_Disbitmap(64 , 2, GPRS88     , 8 , 8);
	GUI_Disbitmap(90 , 2, Alarm88    , 8 , 8);
	GUI_Disbitmap(112, 2, Bat816     , 16, 8);

	if(OLED_PRINT)
		printf("Show background(16 gray map)\n");
	GUI_DisGrayMap(0, 0, gImage_background);
	
	
	OLED_DisWindow(0, 0, 127, 127);
}

void OLED_BPM(uint32_t bpm)
{	
	if(bpm == 9999)
	{
		OLED_SetWindow(0, 10, 127, 50);
		OLED_ClearWindow(0, 10, 127, 50, BLACK);
		OLED_DisWindow(0, 10, 127, 50);
		return ;
	}
	
	if(OLED_PRINT)
		printf("Show Heart Rate\n");
	OLED_SetWindow(0, 10, 127, 50);
	GUI_DisNum(22 , 25, bpm, &Font24, FONT_BACKGROUND, WHITE);
	OLED_DisWindow(0, 10, 127, 50);
}

void OLED_Off(void)
{
	OLED_Clear(OLED_BACKGROUND);//OLED_BACKGROUND
	OLED_Display();
}