/***************************************************************************************
 * Project  :
 * Experimental Platform :STM32F103RBT6 + 7.3inch E-Paper Display
 * Hardware Connection :STM32F103 -> 7.3inch E-Paper
 *			PB12 --> CS 
 *			PB13 --> CLK
 *			PB15 --> MOSI
 *			PA8  --> DC
 *      PA12 --> BUSY
 *      PA11 --> RST
 *      GND  --> GND
 *      3.3V --> VCC
 * Web Site    :www.seengreat.com
***************************************************************************************/

/******************************
 * Definition of screen coordinates:
 * 0------------> x (1~800) 
 * |
 * |
 * |
 * |
 * y (1~480)
******************************/


#include "sys.h"
#include "usart.h"
#include "gpio.h"
#include "delay.h"
#include "7in3_epd.h"
#include "timer.h"
#include "epd_gui.h"
#include "fonts.h"
#include "image.h"
#include <stdlib.h> 

unsigned char Backimage[19500];

void delayms(u16 time)
{    
   u16 i=0;  
   while(time--)
   {
      i=12000;
      while(i--) ;    
   }
}

int main()
{	
	delay_init();	    
	SystemInit();
	Uart1Init(115200,0,0);
	delayms(100);
	EPD_GPIO_Init();//gpio port initialisation, using spi communication
	printf("System Init...\r\n");
	while(1)
	{
		EPD_init(); //Full screen refresh initialization.
		EPD_7IN3F_Clear(EPD_7IN3F_WHITE);
		EPD_sleep();
		delayms(1000);
		printf("display image start...\r\n");
		EPD_init_fast();
		EPD_7IN3F_Display(gImage_7in3f, 200, 90, 400, 300);
		printf("display image end\r\n");
		EPD_sleep();//Enter the sleep mode and please do not delete it, otherwise it will reduce the lifespan of the screen.
		delayms(4000); //Delay for 4s.
//	
		printf("display colors...\r\n");		
		EPD_init(); 
		Display_colors();
		EPD_sleep();
		delayms(4000);
		printf("display colors end...\r\n");
		
		EPD_init();		
		EPD_7IN3F_Clear(EPD_7IN3F_WHITE);//Clear the screen
		EPD_sleep();
		delayms(400);
		printf("e-Paper clear successful...\r\n");
	
	  EPD_init();	
    Image_Init(Backimage, 250, 150, 0, WHITE);//Create Image
    Gui_SetScale(6);
		// Drawing on the image
    // 1.Select Image
    Gui_Clear(WHITE);//Clear the color of the picture
		printf("Gui_Clear\r\n");
    // 2.Drawing on the image
    printf("Drawing:BlackImage\r\n");
    Gui_Draw_Point(10, 10, EPD_7IN3F_RED, PIXEL_1X1, DOT_STYLE_DFT);
//		printf("pixel0=%02x\r\n",Image.img[0]);
    Gui_Draw_Point(10, 20, EPD_7IN3F_BLUE, PIXEL_2X2, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 30, EPD_7IN3F_GREEN, PIXEL_3X3, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 40, EPD_7IN3F_YELLOW, PIXEL_4X4, DOT_STYLE_DFT);
    //Gui_Draw_Point(10, 50, EPD_7IN3F_ORANGE, PIXEL_5X5, DOT_STYLE_DFT);
		Gui_Draw_Rectangle(20, 20, 50, 50, BLACK, EMPTY, PIXEL_1X1);
    //Gui_Draw_Rectangle(80, 20, 110, 50, EPD_7IN3F_BLACK, FULL, PIXEL_1X1);
    Gui_Draw_Circle(35, 35, 20, BLACK, EMPTY, PIXEL_1X1);
   // Gui_Draw_Circle(95, 35, 20, WHITE, FULL, PIXEL_1X1);
	//Gui_Draw_Num(20, 20, 123456789, &Font8, WHITE, EPD_7IN3F_BLACK);
   // Gui_Draw_Num(20, 40, 987654321, &Font8,EPD_7IN3F_BLACK, WHITE );
    Gui_Draw_Str_EN(20, 60, "SEENGREAT", &Font16, EPD_7IN3F_WHITE, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(20, 90, "SEENGREAT" ,&Font20, EPD_7IN3F_WHITE,EPD_7IN3F_GREEN);
    Gui_Draw_Str_EN(20, 120, "SEENGREAT", &Font24, EPD_7IN3F_WHITE, EPD_7IN3F_BLUE);
		Gui_Draw_Str_EN(100, 0, "Welcome", &Font24, EPD_7IN3F_WHITE, EPD_7IN3F_YELLOW);
    Gui_Draw_Str_EN(100, 30, "Welcome", &Font24, EPD_7IN3F_RED, EPD_7IN3F_YELLOW);
    //Gui_Draw_Str_EN(100, 60, "Welcome", &Font24,  EPD_7IN3F_ORANGE, EPD_7IN3F_YELLOW);
		printf("show draw start...\r\n");
		//EPD_7IN3F_Display(BlackImage,0 , 0, 250, 150);//Displaying images on an ink screen
		EPD_7IN3F_Display_Gui(0, 0, 250, 150);
		EPD_sleep();
		printf("show draw end...\r\n");
		delayms(3000); 
		
		EPD_init();
		printf("clear start...\r\n");
		EPD_7IN3F_Clear(WHITE);//Clear the screen
		printf("clear end...\r\n");
		EPD_sleep();//
		printf("epd Sleep...\r\n");
//	delayms(2000); 
		while(1);							
	}

}			

