⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd_1763.c

📁 当前流行的屏驱动
💻 C
字号:
/******************************************************************************

 C   S O U R C E   F I L E

 Copyright 2005 SISIS, Inc. All Rights Reserved.

*******************************************************************************

 Project Name : HS32002 SDK
 Project No.  : 
 Title        : 
 Template Ver : 0.1
 File Name    : lcd_Toshiba.h
 Last Modified: 2006/05/31
 
 Current Version:      0.1
 Authors:              Jupiter.Huang
 Date:                 2006/05/31
 Description  : modify function interface,add function Lcd_Ioctl(). 

 Current Version:      0.1
 Authors:              Keying Fang
 Date:                 2005/10/10

 Assumptions  : NA
 
 Dependency Comments : NA
 
 Project Specific Data : NA
 
******************************************************************************/
/**************************************************************************************/
/************************      Global Varible         *********************************/
/**************************************************************************************/
static INT32 BACK_LIGHT_VALUE = 0xDDDD;
static INT32 FLAG_LCD = 0;

static TEIM_Reg* regEMI = EIM_Reg_Address;

 UINT8 chip_id=0x89;
/**************************************************************************************/
/************************      Internal function      *********************************/
/**************************************************************************************/
/*----  set EMI  ----*/
void InitCS0()
{
	//CS0 control register configuration// 
	regEMI->CS0U = 0x0000f300; // 0x0000d200;
	regEMI->CS0L = 0x28280D01;  
}

void  Delay(unsigned int t)
{
	unsigned int n,m;
	for(n=0;n<t;n++)
	for(m=0;m<1000;m++);
}

void WriteCommand( UINT16 command)
{	
	GPIO_SetOutput(LCD_RS_PORT, 0, 1<<LCD_RS_BIT);
	(*EXT_CHIP_CMD_ADDR) = command;
		
}

void WriteData( UINT16 command)
{	
	GPIO_SetOutput(LCD_RS_PORT, 1<<LCD_RS_BIT, 0);

	(*EXT_CHIP_DATA_ADDR) = command;		
}

/*----  set LCD reg  ----*/
INT32 WriteReg( UINT16 command, UINT16 value)
{	
	
	GPIO_SetOutput(LCD_RS_PORT, 0, 1<<LCD_RS_BIT);
	
	(*EXT_CHIP_CMD_ADDR) = command;
	
	
	GPIO_SetOutput(LCD_RS_PORT, 1<<LCD_RS_BIT, 0);
	
	(*EXT_CHIP_DATA_ADDR) = value;
	
	return 0;
}
/*----  read LCD reg  ----*/
UINT8 ReadReg( UINT16 command)
{
	UINT8 read_value;
	
	GPIO_SetOutput(LCD_RS_PORT, 0, 1<<LCD_RS_BIT);
	
	(*EXT_CHIP_CMD_ADDR) = command;
	
	read_value=(*EXT_CHIP_DATA_ADDR);
	
	return read_value;
}

void SetLCDWindows(UINT16 xstart,UINT16 xend,UINT16 ystart,UINT16 yend)
{
	//U16 HorPos;
	
	//HorPos    = (U16)(xstart | (xend<<8));
	
	//  确定范围
	WriteReg(0x0046,(xend << 8) | xstart);   	//x	
	WriteReg(0x0048,ystart);   	//x	    
	WriteReg(0x0047,yend);   	//y
	WriteReg(0x0020,xstart);   	//y   
	WriteReg(0x0021,ystart);  	
	//WriteCommand(0x0022);   	//yend	
}

/******* enable_back_light ***********/ 
void pwm_enable_backlight(void)
{	
#if IS_LCD_BACKLIGHT_PWM == 0
	GPIO_SetOutput(LCD_BACKUP_LIGHT_PORT, 1<<LCD_BACKUP_LIGHT_BIT, 0);	

#else
	PWMCTL pwmctl;
	
	/*config PA01 for LCD blacklight*/
	GPIO_SetPeriA(GPIO_PORTA,BIT1,1);
	
	pwmctl.value_period = 0xFFFE;
	pwmctl.value_sample = BACK_LIGHT_VALUE;
	
	PWM_Start(&pwmctl);
#endif	
	
}

/********** modify back light *********/
void pwm_set_backlight(UINT16 value)
{
#if IS_LCD_BACKLIGHT_PWM == 0
#else
	PWMCTL pwmctl;
	pwmctl.value_sample = value;
	PWM_Ioctl(SET_PWM_SAMPLE, &pwmctl);
#endif
}


/*---- LCD Initial ----*/
void LcdInit()
{
	
	int i;
	for(i=0; i<0xFF; i++);//delay 
	/*open back light*/
	//pwm_enable_backlight();
	
	GPIO_SetOutput(LCD_RESET_PORT, 1<<LCD_RESET_BIT, 0);
	GPIO_SetOutput(LCD_POWER_ON_PORT, 1<<LCD_POWER_ON_BIT, 0);
	//************* Start Initial Sequence ********//
	//WriteReg(0x00,0x0001);
	//Delay(10);   	//delay 10ms
	
	//WriteReg(0x11,0x0111);
	WriteReg(0x11,0x0112);
	WriteReg(0x12,0x100d);
	WriteReg(0x13,0x1434);
	WriteReg(0x10,0x1530);	// 0101 0010 0101 0000
	Delay(50);    	//delay 50ms
	WriteReg(0x12,0x101d);	// 0000 0001 0000 0001
	//WriteReg(0x13,0x3430); //
	WriteReg(0x13,0x3030);	// 0011 0100 0011 0000
	Delay(20);   	//delay 200ms
	
	WriteReg(0x01,0x0000);
	WriteReg(0x02,0x0700);
	WriteReg(0x03,0x1038);
	WriteReg(0x04,0x0141);
	WriteReg(0x07,0x0005);
	WriteReg(0x08,0x0202);
	WriteReg(0x0b,0x0000);
	WriteReg(0x0c,0x0001);
	WriteReg(0x0e,0x0015);
	WriteReg(0xa1,0x1000);
	WriteReg(0xa4,0x7300);
	//WriteReg(0xa2,0x000f);//53k  //WriteReg(0xa2,0x0005);82k
    WriteReg(0xa2,0x000a);
    WriteReg(0x30,0x0202);
    WriteReg(0x31,0x0000);
    WriteReg(0x32,0x0404);
    WriteReg(0x33,0x0203);
    WriteReg(0x34,0x0207);
    WriteReg(0x35,0x0202);
    WriteReg(0x36,0x0707);
    WriteReg(0x37,0x0002);
    WriteReg(0x38,0x0f00);
    WriteReg(0x39,0x0002);
	
    WriteReg(0x40,0x0000);
    WriteReg(0x41,0x0000);
    WriteReg(0x42,0x0140);
    WriteReg(0x43,0x0000);
    WriteReg(0x44,0x0000);
    WriteReg(0x45,0x0000);
    WriteReg(0x46,0xef00);
    WriteReg(0x47,0x0141); // WriteReg(0x47,0x0140);
    WriteReg(0x48,0x0000);
	Delay(200);  	
    WriteReg(0x07,0x0021);
	Delay(200);  		
    WriteReg(0x07,0x0023);
	Delay(200);  		
    WriteReg(0x07,0x0037);
	Delay(200);  		
    WriteReg(0x20,0x0000);
    WriteReg(0x21,0x0000);
	WriteCommand(0x0022);   ;// Display Data Write...
	
}

/*---- LCD final ----*/ 
INT32 LcdFina()
{
#if IS_LCD_BACKLIGHT_PWM == 0
	GPIO_SetOutput(LCD_BACKUP_LIGHT_PORT, 0, 1<<LCD_BACKUP_LIGHT_BIT);
#else	
	GPIO_SetOutput(GPIO_PORTA, 0, BIT1);
#endif

	return 0;
}

/**************************************************************************************/
/************************      LCD APP function      **********************************/
/**************************************************************************************/ 
//open the LCD      
INT32 lcd_Open(BOOL enableIrq) //need modify
{
	if(FLAG_LCD == 0)
	{
		DMACTL dmactl;
		volatile UINT32 *pBUCR4 = (volatile UINT32 *)0x00209198;
		dmactl.channel = CHANNEL4_LCD_TX;
		dmactl.priority = PRIORITY;
		if(enableIrq == TRUE)
		{
			dmactl.isintenable = INTENABLE;
		}
		else
		{
			dmactl.isintenable = INTDISABLE;
		}
		dmactl.mdir = INCREASE;
		dmactl.srcmode = LINEAR;
		dmactl.dstmode = LINEAR;
		dmactl.srcsize = D32;
		dmactl.dstsize = D32;
		dmactl.burstlen = 32;
		dmactl.reqsrc = REQ_EXDMA;	
		
		InitCS0();
		LcdInit();	
		DMAChannel_Open(&dmactl);  
		*pBUCR4 = 80;
		
	}
	
	FLAG_LCD++;	  
	
	return 0;   
}




/************************************************************
Parameter :	topLeftX : the coordinate of x 

  topLeftY : the coordinate of x
  
	width: the width of picture window
	height: the height of picture window
	
	  *picBuf: the point of picture
	  
		note:  topLeftX+width<=220
		topLeftY+height<=176
		
************************************************************/


INT32 lcd_Write(INT16 topLeftX, INT16 topLeftY, INT16 width, INT16 height, UINT16 *picBuf)
{
	int j;
	int lcdInterface;
	int len;
	UINT16 * temp_picBuf;
	DMACTL dmactl;
	
	
	regEMI->CS0U = 0x00000600;
	regEMI->CS0L =0x44441D01;
	SetLCDWindows(topLeftY,topLeftY+height-1,topLeftX,topLeftX+width-1);     
	WriteCommand(0x0022);
	
	
	
	GPIO_SetOutput(LCD_RS_PORT, 1<<LCD_RS_BIT, 0);
	lcdInterface = (int)0x10000000;
	
	
	
	temp_picBuf = picBuf + width * (height-1);
	
	for(j=0;j<width;j++)
	{
		(*EXT_CHIP_DATA_ADDR) = 0;
	}
	
	len=width*(height-1)*2;
	dmactl.channel = CHANNEL4_LCD_TX;
	dmactl.srcaddr = (UINT32)picBuf;
	dmactl.dstaddr = (UINT32)EXT_CHIP_DATA_ADDR;
	dmactl.len= len;
	
	if(len <= LCD_BUFFER_MAXSIZE)
	{
		MMU_CleanDCacheMVA((UINT32)picBuf,(UINT32)(picBuf+76800-320));
		if(DMA_Start(&dmactl))
			return 1;
	}
	return 0;

}


INT32 LCD_Clean()
{
	INT32 i;
	UINT16 Clean_Buf[76800];
	for(i=0;i<76800;i++)
	{
		Clean_Buf[i] = 0x0000;
	}
	LCD_Write(0,0,320,240,Clean_Buf);
	return 0;
}




/************************************************************
Parameter :	topLeftX : the coordinate of x 

 topLeftY : the coordinate of x
  
	width: the width of window you want to clear
	height: the height of window you want to clear
	
	  ColorValue: the color you want to set in the claer window
	  note:  topLeftX+width<=220
	  topLeftY+height<=176
************************************************************/
INT32 WindowScreenClear(INT16 topLeftX, INT16 topLeftY, INT16 width, INT16 height, UINT16 ColorValue)
{
	int i,j;
	int len;
	
    /* CS1 repair*/
	
    /* CS1 repair*/
	//	regEMI->CS0U = 0x00000500;
	//	regEMI->CS0L = 0x44442D01;
	
	SetLCDWindows(topLeftY,topLeftY+height-1,topLeftX,topLeftX+width-1);
	
	//WriteCommand(0x0021);
   	WriteCommand(0x0022);
	
	len=width*height;	
	
	GPIO_SetOutput(LCD_RS_PORT, 1<<LCD_RS_BIT, 0);
	
	
	for(i=0;i<height;i++)
	{
		for(j=0;j<width;j++)
		{
			(*EXT_CHIP_DATA_ADDR) = ColorValue;
		}
	}
	
	return len;
	
}


INT32 LCD_Close(void)
{
	
	FLAG_LCD--;
	if(FLAG_LCD == 0)
	{
		DMACTL dmactl;
		dmactl.channel = CHANNEL4_LCD_TX;
		WindowScreenClear(0, 0, 320, 240, 0xffff);		
		LcdFina();
		DMA_Stop(&dmactl);
	}
	return 0;                     
}

/*********** lcd IO control ******************/

INT32 LCD_Ioctl(INT32 cmd, INT32 para, void *buf)
{	
	switch(cmd)
	{
	case GET_LCD_INFO:
		{
			LCD_INFO *lcd_info = (LCD_INFO *)buf;
			lcd_info->LCD_WIDTH = LCD_PHY_PIXEL_CX;
			lcd_info->LCD_HEIGHT = LCD_PHY_PIXEL_CY;
			lcd_info->LCD_BITS_PER_PIXEL = LCD_PIXEL_BITS;
			lcd_info->LCD_PIXEL_PALETTE = LCD_PIXEL_RGB;
			break;
		}
		
	case LCD_BACKLIGHT_DOWN:
		{
			if(BACK_LIGHT_VALUE <= 0)
			{
				BACK_LIGHT_VALUE = 0;
			}
			else
			{
				BACK_LIGHT_VALUE -= BACK_LIGHT_UNIT;	
			}
			pwm_set_backlight(BACK_LIGHT_VALUE);
			break;
		}
		
	case LCD_BACKLIGHT_UP:
		{
			if(BACK_LIGHT_VALUE >= BACK_LIGHT_MAX_VALUE)
				BACK_LIGHT_VALUE = BACK_LIGHT_MAX_VALUE;
			else
				BACK_LIGHT_VALUE += BACK_LIGHT_UNIT;
			
			pwm_set_backlight(BACK_LIGHT_VALUE);
			break;
			
		}
		
	case LCD_BACKLIGHT_ENABLE:
		{
#if IS_LCD_BACKLIGHT_PWM == 0
			GPIO_SetOutput(LCD_BACKUP_LIGHT_PORT, 1<<LCD_BACKUP_LIGHT_BIT, 0);	
#else	
            pwm_set_backlight(BACK_LIGHT_VALUE);
#endif
			break;
		}
		
	case LCD_BACKLIGHT_DISABLE:
		{
#if IS_LCD_BACKLIGHT_PWM == 0
			GPIO_SetOutput(LCD_BACKUP_LIGHT_PORT, 0, 1<<LCD_BACKUP_LIGHT_BIT);	
#else
			pwm_set_backlight(0xff00);
#endif
			break;
		}
		
	case CLEAN_SCREEN:
		{
			LCD_Clean();
			break;
		}
		
	default:
		return -1;
	}
	
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -