//   verification methods.  LCD Studio provides no warranty regarding the use 
//   or functionality of this code.
//---------------------------------------------------------------------------


/**************************************************/		
// I2C power module controller		
/**************************************************/ 
//
void DisplayOn()
{		
	Set_POWER(1,1,1,1);//1.8V ON, 2.8V ON, 5V ON, BL ON
 //Set_POWER(1,1,1,1);//1.8V ON, 2.8V ON, 5V ON, BL ON


DCS_Short_Read_NP(0xDA, 1, BUFFER+0);	
DCS_Short_Read_NP(0xDB, 1, BUFFER+1);	
DCS_Short_Read_NP(0xDC, 1, BUFFER+2);	
/*

Generic_Long_Write_3P(0xFF,0x98,0x81,0x01);

DCS_Short_Read_NP(0xe8, 1, BUFFER+0);	

	if (memcmp("0"))
	{

		Set_TEXT(1, 1, 0x22);//OTP FAIL	
	}
	else 
	{
               
			
       Set_TEXT(1, 0, 0x11);//OTP PASS
	}

*/


}
//
void PowerOffSequence()
{
	DCS_Short_Write_NP(0x28);
	Delay(200);
	DCS_Short_Write_NP(0x10);
	Delay(100);
	Set_STANDBY();//Video transfer stop
	Delay(500);

	Set_RESET(1,0);//MIPI RESET 1, LCD RESET 0
	Delay(50);
	Set_RESET(0,0);//MIPI RESET 0, LCD RESET 0
	Delay(50);

	Set_POWER(1,1,0,1);//1.8V ON, 2.8V ON, 5V OFF, BL ON
	Delay(150);

	Set_BOOST(4.2, 4.2, 0x81, 50);//VDD, VEE, OFF:VDD->VEE, 10ms
	Delay(500);

	Set_POWER(1,1,0,1);//1.8V ON, 2.8V OFF, 5V OFF, BL ON
	Delay(150);
	Set_POWER(0,0,0,0);//1.8V OFF, 2.8V OFF, 5V OFF, BL OFF
}

/**************************************************/		
// Read function (Option)		
/**************************************************/ 
//
void ReadOperation()
{
	//Clean memory: BUFFER	
	memset(0);//BUFFER size: 8 Bytes

	//Read value to BUFFER
	DCS_Short_Read_NP(0xF0, 1, BUFFER+0);
}

void main()
{
	Set_RESET(1,1);//MIPI RESET 1, LCD RESET 1
	Delay(200);

	Set_POWER(1,0,0,0);//1.8V ON, 2.8V OFF, 5V OFF, BL OFF
	Delay(150);
	Set_POWER(1,1,1,0);//1.8V ON, 2.8V ON, 5V ON, BL OFF
	Delay(150);

	Set_BOOST(4.2, 4.2, 0x01, 50);//VDD, VEE, ON:VDD->VEE, 10ms
	Delay(50);

	Set_RESET(0,0);//MIPI RESET 0, LCD RESET 0
	Delay(100);
	Set_RESET(1,1);//MIPI RESET 1, LCD RESET 1
	Delay(200);

	//Tips:	Set_BOOST([0], [1], [2], [3])
	//		[0]	VDD
	//		[1]	VEE
	//		[2]	Power On:	0x01 VDD On -> Delay -> VEE On
	//					0x02 VEE On -> Delay -> VDD On
	//					0x03 Both On Together
	//			Power Off:	0x81 VDD Off -> Delay -> VEE Off
	//					0x82 VEE Off -> Delay -> VDD Off
	//					0x83 Both Off Together
	//		[3]	Delay: Unit 200uS

	/*************************************************/
	//SSD2828 initial setting - LP mode
	/*************************************************/

	SSD_LANE(4, 0);

	//Tips:	SSD_LANE([0], [1])
	//		[0]	Lane Select:	1 - 1 Lane
	//						2 - 2 Lane
	//						3 - 3 Lane
	//						4 - 4 Lane
	//		[1]	Lane Speed:	0 - Auto setting (Only for Non-burst mode)
	//						x - User setting (Mbps per lane)

	/**************************************************/		
	//LCDD (Peripheral) Setting		
     /**************************************************/	
 

///////////////////////////////    F

Generic_Short_Write_1P(0xFE,0xA0);
Generic_Short_Write_1P(0x2B,0x18);
Generic_Short_Write_1P(0xFE,0x70);
Generic_Short_Write_1P(0x7D,0x35);
Generic_Short_Write_1P(0x5D,0x0A);
Generic_Short_Write_1P(0x5A,0x79);
Generic_Short_Write_1P(0x5C,0x00);
Generic_Short_Write_1P(0x52,0x00);
Generic_Short_Write_1P(0xFE,0xD0);
Generic_Short_Write_1P(0x40,0x02);
Generic_Short_Write_1P(0x13,0x40);
Generic_Short_Write_1P(0xFE,0x40);
Generic_Short_Write_1P(0x05,0x08);
Generic_Short_Write_1P(0x06,0x08);
Generic_Short_Write_1P(0x08,0x08);
Generic_Short_Write_1P(0x09,0x08);
Generic_Short_Write_1P(0x0A,0xCA);
Generic_Short_Write_1P(0x0B,0x88);
Generic_Short_Write_1P(0x20,0x93);
Generic_Short_Write_1P(0x21,0x93);
Generic_Short_Write_1P(0x24,0x02);
Generic_Short_Write_1P(0x26,0x02);
Generic_Short_Write_1P(0x28,0x05);
Generic_Short_Write_1P(0x2A,0x05);
Generic_Short_Write_1P(0x74,0x2F);
Generic_Short_Write_1P(0x75,0x1E);  // ovss  3833A -2.5v £¨0x19£©£» 331e  -2.4v £¨0x1e£©
Generic_Short_Write_1P(0xAD,0x00);
Generic_Short_Write_1P(0xFE,0x60);
Generic_Short_Write_1P(0x00,0xCC);
Generic_Short_Write_1P(0x01,0x00);
Generic_Short_Write_1P(0x02,0x04);
Generic_Short_Write_1P(0x03,0x00);
Generic_Short_Write_1P(0x04,0x00);
Generic_Short_Write_1P(0x05,0x07);
Generic_Short_Write_1P(0x06,0x00);
Generic_Short_Write_1P(0x07,0x88);
Generic_Short_Write_1P(0x08,0x00);
Generic_Short_Write_1P(0x09,0xCC);
Generic_Short_Write_1P(0x0A,0x00);
Generic_Short_Write_1P(0x0B,0x04);
Generic_Short_Write_1P(0x0C,0x00);
Generic_Short_Write_1P(0x0D,0x00);
Generic_Short_Write_1P(0x0E,0x05);
Generic_Short_Write_1P(0x0F,0x00);
Generic_Short_Write_1P(0x10,0x88);
Generic_Short_Write_1P(0x11,0x00);
Generic_Short_Write_1P(0x12,0xCC);
Generic_Short_Write_1P(0x13,0x0F);
Generic_Short_Write_1P(0x14,0xFF);
Generic_Short_Write_1P(0x15,0x04);
Generic_Short_Write_1P(0x16,0x00);
Generic_Short_Write_1P(0x17,0x06);
Generic_Short_Write_1P(0x18,0x00);
Generic_Short_Write_1P(0x19,0x96);
Generic_Short_Write_1P(0x1A,0x00);
Generic_Short_Write_1P(0x24,0xCC);
Generic_Short_Write_1P(0x25,0x00);
Generic_Short_Write_1P(0x26,0x02);
Generic_Short_Write_1P(0x27,0x00);
Generic_Short_Write_1P(0x28,0x00);
Generic_Short_Write_1P(0x29,0x06);
Generic_Short_Write_1P(0x2A,0x06);
Generic_Short_Write_1P(0x2B,0x82);
Generic_Short_Write_1P(0x2D,0x00);
Generic_Short_Write_1P(0x2F,0xCC);
Generic_Short_Write_1P(0x30,0x00);
Generic_Short_Write_1P(0x31,0x02);
Generic_Short_Write_1P(0x32,0x00);
Generic_Short_Write_1P(0x33,0x00);
Generic_Short_Write_1P(0x34,0x07);
Generic_Short_Write_1P(0x35,0x06);
Generic_Short_Write_1P(0x36,0x82);
Generic_Short_Write_1P(0x37,0x00);
Generic_Short_Write_1P(0x38,0xCC);
Generic_Short_Write_1P(0x39,0x00);
Generic_Short_Write_1P(0x3A,0x02);
Generic_Short_Write_1P(0x3B,0x00);
Generic_Short_Write_1P(0x3D,0x00);
Generic_Short_Write_1P(0x3F,0x07);
Generic_Short_Write_1P(0x40,0x00);
Generic_Short_Write_1P(0x41,0x88);
Generic_Short_Write_1P(0x42,0x00);
Generic_Short_Write_1P(0x43,0xCC);
Generic_Short_Write_1P(0x44,0x00);
Generic_Short_Write_1P(0x45,0x02);
Generic_Short_Write_1P(0x46,0x00);
Generic_Short_Write_1P(0x47,0x00);
Generic_Short_Write_1P(0x48,0x06);
Generic_Short_Write_1P(0x49,0x02);
Generic_Short_Write_1P(0x4A,0x8A);
Generic_Short_Write_1P(0x4B,0x00);
Generic_Short_Write_1P(0x5F,0xCA);
Generic_Short_Write_1P(0x60,0x01);
Generic_Short_Write_1P(0x61,0xE8);
Generic_Short_Write_1P(0x62,0x09);
Generic_Short_Write_1P(0x63,0x00);
Generic_Short_Write_1P(0x64,0x07);
Generic_Short_Write_1P(0x65,0x00);
Generic_Short_Write_1P(0x66,0x30);
Generic_Short_Write_1P(0x67,0x00);
Generic_Short_Write_1P(0x9B,0x03);
Generic_Short_Write_1P(0xA9,0x07);
Generic_Short_Write_1P(0xAA,0x06);
Generic_Short_Write_1P(0xAB,0x02);
Generic_Short_Write_1P(0xAC,0x10);
Generic_Short_Write_1P(0xAD,0x11);
Generic_Short_Write_1P(0xAE,0x05);
Generic_Short_Write_1P(0xAF,0x04);
Generic_Short_Write_1P(0xB0,0x10);
Generic_Short_Write_1P(0xB1,0x10);
Generic_Short_Write_1P(0xB2,0x10);
Generic_Short_Write_1P(0xB3,0x10);
Generic_Short_Write_1P(0xB4,0x10);
Generic_Short_Write_1P(0xB5,0x10);
Generic_Short_Write_1P(0xB6,0x10);
Generic_Short_Write_1P(0xB7,0x10);
Generic_Short_Write_1P(0xB8,0x10);
Generic_Short_Write_1P(0xB9,0x10);
Generic_Short_Write_1P(0xBA,0x04);
Generic_Short_Write_1P(0xBB,0x05);
Generic_Short_Write_1P(0xBC,0x00);
Generic_Short_Write_1P(0xBD,0x01);
Generic_Short_Write_1P(0xBE,0x0A);
Generic_Short_Write_1P(0xBF,0x10);
Generic_Short_Write_1P(0xC0,0x11);
Generic_Short_Write_1P(0xFE,0xA0);
Generic_Short_Write_1P(0x22,0x00);
Generic_Short_Write_1P(0xFE,0x00);
Generic_Short_Write_1P(0xC2,0x08);
Generic_Long_Write_2P(0x44,0x00,0x00);
Generic_Short_Write_1P(0x35,0x00);  


//Generic_Short_Write_1P(0xFE,0x70);
//Generic_Short_Write_1P(0x5D,0x0A);
//Generic_Short_Write_1P(0xFE,0xA0);
//Generic_Short_Write_1P(0x22,0x00);
Generic_Short_Write_1P(0xFE,0x60);
Generic_Short_Write_1P(0x67,0x80);
Generic_Short_Write_1P(0xFE,0x00);
Generic_Short_Write_1P(0x51,0xFF);


Generic_Short_Write_1P(0x53,0x28);
/*
Generic_Short_Write_1P(0x35,0x00);
Generic_Long_Write_2P(0x51,0x00,0xFF);
Generic_Short_Write_1P(0x6F,0x01);  
*/


DCS_Short_Write_NP(0x11);
Delay (200);
DCS_Short_Write_NP(0x29);
Delay (40);

	/*************************************************/
	//SSD2828 initial setting - HS mode
	/*************************************************/

	SSD_MODE(0, 1);

	//Tips:	SSD_MODE([0], [1])
	//		[0]	Video Mode:	0 - Non burst mode with sync pulses
	//						1 - Non burst mode with sync events
	//						2 - Burst mode
	//						3 - Command mode
	//		[1]	HS Mode:		0 - No operation
	//						1 - Enable HS mode						1 - Enable HS mode
}