?? lcd_9320.c
字號:
/****************************************************************************
*
* Copyright (c) 2005 , Shanghai Jiao Da HISYS Technology Co.,Ltd.
* All rights reserved.
*
* ProjectName: Nightingale
* FileName: lcd_truly24.c
* Description: The LCD Driver of Nightingale
*
*
* Current Version: 0.1
* Authors: Keying Fang
* Date: 20/11/2006
*
*
* Previous Version:
* Authors:
* Date:
*
*
******************************************************************************/
//#include "lcd_kgm.h"
#include "dma.h"
#include "timer.h"
#include "gpio.h"
#include "pwm.h"
/**************************************************************************************/
/************************ Global Varible *********************************/
/**************************************************************************************/
static INT32 BACK_LIGHT_VALUE = 0xCCCC;
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 = 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 ----*/
void ReadCommand( UINT16 *command)
{
// GPIO_SetOutput(GPIO_PORTB, BIT3, 0);//set 1 for PB3(RS =1) in order to read cmd
GPIO_SetOutput(LCD_RS_PORT, 1<<LCD_RS_BIT, 0);
*command = (*EXT_CHIP_DATA_ADDR);
}
void SetLCDWindows(UINT16 xstart,UINT16 xend,UINT16 ystart,UINT16 yend )
{
// 將counter init...
WriteReg(0x0020,xstart); //x start command
WriteReg(0x0021,ystart); //y start command
// 確定范圍
WriteReg(0x0050,xstart); //x
WriteReg(0x0051,xend); //x
WriteReg(0x0052,ystart); //y
WriteReg(0x0053,yend); //y
WriteCommand(0x0022); //yend
}
/******* enable_back_light ***********/
void pwm_enable_backlight(void)
{
PWMCTL pwmctl;
/*config PA01 for LCD blacklight*/
GPIO_SetPeriA(LCD_BACKLIGHT_PORT,1<<LCD_BACKLIGHT_BIT,1);
pwmctl.value_period = 0xFFFE;
pwmctl.value_sample = BACK_LIGHT_VALUE;
PWM_Start(&pwmctl);
}
/********** modify back light *********/
void pwm_set_backlight(UINT16 value)
{
PWMCTL pwmctl;
pwmctl.value_sample = value;
PWM_Ioctl(SET_PWM_SAMPLE, &pwmctl);
}
/*---- LCD Initial ----*/
void LcdInit(void)
{
UINT16 a;
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);//1
Delay(50);
//************* Start Initial Sequence ********//
WriteReg(0x0000, 0x0001); // Start internal OSC.
Delay(50);
ReadCommand(&a);
WriteReg(0x0001, 0x0100); // set SS and SM bit
WriteReg(0x0002, 0x0700); // set 1 line inversion
WriteReg(0x0003, 0x1028); // set GRAM write direction and BGR=1.
WriteReg(0x0004, 0x0000); // Resize register
WriteReg(0x0007, 0x0000); //chg // Resize register
WriteReg(0x0008, 0x0202); // set the back porch and front porch
WriteReg(0x0009, 0x0100); //chg // set non-display area refresh cycle ISC[3:0]
WriteReg(0x000A, 0x0008); //chg // FMARK function
WriteReg(0x000C, 0x0000); // RGB interface setting
WriteReg(0x000D, 0x0000); //chg // Frame marker Position
WriteReg(0x000F, 0x0000); // RGB interface polarity
//*************Power On sequence ***************//
WriteReg(0x0010, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB
WriteReg(0x0011, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]
WriteReg(0x0012, 0x0000); // VREG1OUT voltage
WriteReg(0x0013, 0x0000); // VDV[4:0] for VCOM amplitude
Delay(200); // Dis-charge capacitor power voltage
WriteReg(0x0010, 0x1090); //17b0 // SAP, BT[3:0], AP, DSTB, SLP, STB
WriteReg(0x0011, 0x0010); // DC1[2:0], DC0[2:0], VC[2:0]
Delay(50); // Delay 50ms
WriteReg(0x0012, 0x0111); //13a // VREG1OUT voltage
Delay(50); // Delay 50ms
WriteReg(0x0013, 0x1800); //1a00 // VDV[4:0] for VCOM amplitude
WriteReg(0x0029, 0x000C); // VCM[4:0] for VCOMH
Delay(50);
WriteReg(0x0020, 0x0000); // GRAM horizontal Address
WriteReg(0x0021, 0x0000); // GRAM Vertical Address
// ---- Adjust the Gamma Curve ------- //
WriteReg(0x0030, 0x0000);
WriteReg(0x0031, 0x0505);
WriteReg(0x0032, 0x0004);
WriteReg(0x0035, 0x0006);
WriteReg(0x0036, 0x0707);
WriteReg(0x0037, 0x0105);
WriteReg(0x0038, 0x0002);
WriteReg(0x0039, 0x0707);
WriteReg(0x003C, 0x0704);
WriteReg(0x003D, 0x0807);
//------------------ Set GRAM area -------------//
WriteReg(0x0050, 0x0000); // Horizontal GRAM Start Address
WriteReg(0x0051, 0x00EF); // Horizontal GRAM End Address
WriteReg(0x0052, 0x0000); // Vertical GRAM Start Address
WriteReg(0x0053, 0x013F); // Vertical GRAM Start Address
WriteReg(0x0060, 0x2700); // Gate Scan Line
WriteReg(0x0061, 0x0001); // NDL,VLE, REV
WriteReg(0x006A, 0x0000); // set scrolling line
//-------------- Partial Display Control -------//
WriteReg(0x0080, 0x0000);
WriteReg(0x0081, 0x0000);
WriteReg(0x0082, 0x0000);
WriteReg(0x0083, 0x0000);
WriteReg(0x0084, 0x0000);
WriteReg(0x0085, 0x0000);
//-------------- Panel Control -----------------//
WriteReg(0x0090, 0x0010);
WriteReg(0x0092, 0x0000);
WriteReg(0x0093, 0x0003);
WriteReg(0x0095, 0x0110);
WriteReg(0x0097, 0x0000);
WriteReg(0x0098, 0x0000);
WriteReg(0x0007, 0x0173); // 65K color and display ON
}
/*---- LCD final ----*/
INT32 LcdFina()
{
// Step1: nPWDN = 0
// Step2: VDD2.8 Power OFF
//config PA1 for LED_ON
GPIO_SetOutput(GPIO_PORTA, 0, BIT1);
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.ischptr = 0;
dmactl.mdir = INCREASE;
dmactl.srcmode = LINEAR;
dmactl.dstmode = LINEAR;
dmactl.srcsize = D32;
dmactl.dstsize = D32;
dmactl.burstlen = 32; //change by huangwei
dmactl.reqsrc = REQ_EXDMA;
*pBUCR4 = 120;
InitCS0();
LcdInit();
Delay(600); //313 9320屏驅動所加delay
DMA_Open();
DMAChannel_Open(&dmactl);
}
FLAG_LCD++;
return 0;
}
/************************************************************
Parameter : topLeftX : the coordinate of x
topLeftY : the coordinate of y
width: the width of picture window
height: the height of picture window
*picBuf: the point of picture
note: topLeftX+width<=320
topLeftY+height<=240
************************************************************/
INT32 lcd_Write(INT16 topLeftX, INT16 topLeftY, INT16 width, INT16 height, UINT16 *picBuf)
{
int i;
int lcdInterface;
int len;
UINT16 * temp_picBuf;
// UINT16 tmp0,tmp1,tmp2,tmp3;
DMACTL dmactl;
regEMI->CS0U = 0x00000800;//0x00000800;0x00000600
regEMI->CS0L = 0x11110D01;//0x11110D01; 0x44441d01
SetLCDWindows(topLeftY,topLeftY+height-1,topLeftX,topLeftX+width-1);
GPIO_SetOutput(LCD_RS_PORT, 1<<LCD_RS_BIT, 0);
lcdInterface = (int)0x10000000;
temp_picBuf = picBuf + width * (height-1);
for(i=0;i<width;i++)
{
(*EXT_CHIP_DATA_ADDR) = 0;
}
#if 0
len = width ;
i = len;// - len%16;
//zzy add on 20060605當顯示的行數(shù)為0時程序會執(zhí)行相當多次
if(i<=0)
{
return 0;
}
temp_picBuf = picBuf + width * (height-1);
__asm
{
loop_lwrite:
ldrh tmp0, [temp_picBuf], #2
ldrh tmp1, [temp_picBuf], #2
strh tmp0, [lcdInterface, #4]
ldrh tmp2, [temp_picBuf], #2
strh tmp1, [lcdInterface, #4]
ldrh tmp3, [temp_picBuf], #2
strh tmp2, [lcdInterface, #4]
ldrh tmp0, [temp_picBuf], #2
strh tmp3, [lcdInterface, #4]
ldrh tmp1, [temp_picBuf], #2
strh tmp0, [lcdInterface, #4]
ldrh tmp2, [temp_picBuf], #2
strh tmp1, [lcdInterface, #4]
ldrh tmp3, [temp_picBuf], #2
strh tmp2, [lcdInterface, #4]
ldrh tmp0, [temp_picBuf], #2
strh tmp3, [lcdInterface, #4]
ldrh tmp1, [temp_picBuf], #2
strh tmp0, [lcdInterface, #4]
ldrh tmp2, [temp_picBuf], #2
strh tmp1, [lcdInterface, #4]
ldrh tmp3, [temp_picBuf], #2
strh tmp2, [lcdInterface, #4]
ldrh tmp0, [temp_picBuf], #2
strh tmp3, [lcdInterface, #4]
ldrh tmp1, [temp_picBuf], #2
strh tmp0, [lcdInterface, #4]
ldrh tmp2, [temp_picBuf], #2
strh tmp1, [lcdInterface, #4]
ldrh tmp3, [temp_picBuf], #2
strh tmp2, [lcdInterface, #4]
subs i, i, 16
strh tmp3, [lcdInterface, #4]
bne loop_lwrite
}
#endif
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(VOID)
{
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 y
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<=320
topLeftY+height<=240
************************************************************/
INT32 WindowScreenClear(INT16 topLeftX, INT16 topLeftY, INT16 width, INT16 height, UINT16 ColorValue)
{
int i,j;
int len=width*height;
/* CS1 repair*/
regEMI->CS0U = 0x00000500;
regEMI->CS0L = 0x44442D01;
SetLCDWindows(topLeftY,topLeftY+height-1,topLeftX,topLeftX+width-1);
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;
}
/****************************************************************
Parameter: None
****************************************************************/
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);
DMAChannel_Close(&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:
{
pwm_set_backlight(BACK_LIGHT_VALUE);
break;
}
case LCD_BACKLIGHT_DISABLE:
{
pwm_set_backlight(0);
break;
}
case CLEAN_SCREEN:
{
LCD_Clean();
break;
}
default:
return -1;
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -