📄 lcd.c
字号:
// Implemention of LCD panel.
#include "def.h"
#include "config.h"
#include "2440addr.h"
#include "lcd.h"
#include "gpio.h"
extern void DM_WaitMs(UINT32 msVal);
/*
*******************************************************************************
* LOCAL DEFINITIONS
*******************************************************************************
*/
static LcdContextT Lcd;
static DM_FrameBuffer_T g_framebuffer;
// Display format and color space
static int colorSpace;
static int displayType;
static int colorDepth;
// Offset from edge and top of pixel area in frame buffer for active data
static int horizOffset;
static int vertOffset;
// Size of the frame buffer (and display)
static int horizPixel;
static int vertPixel;
static int extraLines;
// Offset in frame buffer for second field in interlace mode, zero for
// non interlace mode.
static int fieldOffset;
// Pointer to hardware regs, setup at init time.
// Currently active frame buffer and default buffer
static DM_FrameBuffer_T *curFbP;
//static DM_FrameBuffer_T * nextFbP;
static DM_FrameBuffer_T *defaultFbP;
static char Panel_Used = Twochip_SamsungPanel; //handy0718
#if UT_Rel_91
static USHORT spidata[]={ //finey 20060707
0x0c40, //VDISP = 2
//0x02a0, //HDISP = 8 //default removed by finey 20060714
0x0a82, //PANEL3 = 65 (512-6.65)/7.75 //changed by fieny 20060714
0x0e33, //FUNC2 CLK REVERSE
0x0980, //PANEL5 10000000
0x0d40, //PANEL7 01000000
0x0608 //FUNC1 NORMAL MODE
};
#endif
/*
*******************************************************************************
*
* FUNCTION: allocateFrameBuffer
*
* DESCRIPTION: computes and allocates memory for a frame buffer. This is a
* simpified version that just gets the buffer and does not
* attempt to initialize the buffer with any line drawing stuff.
*
* INPUT PARAMETERS: int bpp - bits per pixel
* int h - horizontal pixels
* int v - vertical pixels
* int extra - extra lines required to pad buffer
*
* RETURNS: DM_FrameBuffer_T * - a pointer to a frame buffer
*
* GLOBAL EFFECTS: none
*
* ASSUMPTIONS: none
*
* CALLS: none
*
* CALLED BY: none
*
* PROTOTYPE: none
*
*******************************************************************************
*/
static
DM_FrameBuffer_T *allocateFrameBuffer(int bpp, int h, int v, int extra)
{
UINT frameBufferSize;
DM_FrameBuffer_T *frameBufferPtr;
// In the case of this display, using 16 bits
// per pixel means the palette RAM is not used.
// Acquire a frame buffer address from the memory manager. But first compute the
// frame buffer size.
frameBufferSize =
(h * v * (bpp / 8) + (2 * extra * v) + sizeof(DM_FrameBuffer_T));
// for now force the frame buffer into sram
frameBufferPtr = &g_framebuffer;
// now move the pointer to the frame buffer to after the structure
frameBufferPtr->bufP = (unsigned short *) FRAMEBUF_VBASE;
frameBufferPtr->pixelP = (unsigned short *) FRAMEBUF_VBASE;
frameBufferPtr->numPage = frameBufferSize;
// should force the screen to be half height
frameBufferPtr->horizPixel = h;
frameBufferPtr->vertPixel = v;
frameBufferPtr->extraLines = extra;
/*
// Blank the buffer
for (i=0; i < h * (v+extra*2); i += 2) {
frameBufferPtr->pixelP[i] = (RGB565_COLOR_BLUE & 0xFFFF);
frameBufferPtr->pixelP[i+1] = (RGB565_COLOR_BLUE & 0xFFFF0000) >> 16;
}
*/
return frameBufferPtr;
}
// Return the current frame buffer pointer
static
DM_FrameBuffer_T *getFrameBuffer(LcdContextT * ctxP)
{
return curFbP;
}
// Allocate and initialize a frame buffer
static
DM_FrameBuffer_T *newFrameBuffer(LcdContextT * ctxP)
{
return curFbP;
}
// Queue the frame buffer for the next display frame
static
void setFrameBuffer(LcdContextT * ctxP, DM_FrameBuffer_T * fbP)
{
}
// Get the screen/frame buffer geometry
static
void getGeometry(LcdContextT * ctxP, int *hP, int *vP)
{
if (hP)
*hP = horizPixel;
if (vP)
*vP = vertPixel;
}
// Get offsets into visible regions. This can't be hidden from upper levels
// because the LCD needs to send all pixels, overscan displays will simply
// hide some of them.
static
void getOffsets(LcdContextT * ctxP, int *hP, int *vP, int *fP)
{
if (hP)
*hP = horizOffset;
if (vP)
*vP = vertOffset;
if (fP)
*fP = fieldOffset;
}
// Turn the display off and wait for it to complete its current frame.
static
void off(LcdContextT * ctxP)
{
}
// Turn the display on
static
void on(LcdContextT * ctxP)
{
//nothing to be done, we have turn LCD on MQEnableDisplay()
}
// Return the current display type
static
int getDisplayType(LcdContextT * ctxP)
{
return displayType;
}
// Return the current color space
static
int getColorSpace(LcdContextT * ctxP)
{
return colorSpace;
}
// Return the current color depth
static
int getColorDepth(LcdContextT * ctxP)
{
return colorDepth;
}
//////////////////////Read ADC handy 0718
DWORD ReadADC()
{
int i = 0;
int ch=3;//
int reladc = 0;
DWORD dwCount;
rADCCON=(1<<14)+(9<<6)+(ch<<3);
//rADCMUX = ch;
for(i=0;i<1;i++); //delay to set up the next channel
rADCTSC = rADCTSC & 0xfb; //Normal ADC conversion & No TS operation
rADCCON|=0x1; //start ADC
dwCount = 0 ;
while((rADCCON & 0x1) && (dwCount++ < 1000)) //check if Enable_start is low
{
DM_WaitMs(1);
}
dwCount = 0 ;
while(!(rADCCON & 0x8000) && (dwCount++ < 1000)) //check if EC(End of Conversion) flag is high
{
DM_WaitMs(1);
}
reladc=rADCDAT0&0x3ff;
return reladc;
}
/////handy0117 start
static
void LCD_SPI_Write(unsigned char Index,unsigned short REG_DATA)
{
unsigned char DeviceID = 0x74;
unsigned char lcd_Index = (unsigned char)(Index & 0xff);
unsigned char lcd_data0 = (unsigned char)((REG_DATA >> 8)& 0xff);
unsigned char lcd_data1 = (unsigned char)( REG_DATA & 0xff);
rGPEDAT &= ~(1<<11); //nLCD_CS low
while(!(rSPSTA0&0x1)); //Check for Trasfer ready Flag high
rSPTDAT0 = (DeviceID | 0x0); //Send Device ID code
while(!(rSPSTA0&0x1)); //Check for Trasfer ready Flag high
rSPTDAT0 = 0x00; //Write register 8 bit
while(!(rSPSTA0&0x1)); //Check for Trasfer ready Flag high
rSPTDAT0 = lcd_Index; //Write register 8 bit
while(!(rSPSTA0&0x1)); //Check for Trasfer ready Flag high
rGPEDAT |= (1<<11); //nLCD_CS high
DM_WaitMs(4*1);
rGPEDAT &= ~(1<<11); //nLCD_CS low
while(!(rSPSTA0&0x1)); //Check for Trasfer ready Flag high
rSPTDAT0 = (DeviceID | 0x2); //Send Device ID code
while(!(rSPSTA0&0x1)); //Check for Trasfer ready Flag high
rSPTDAT0 = lcd_data0; //Write the data first 8 bit
while(!(rSPSTA0&0x1)); //Check for Trasfer ready Flag high
rSPTDAT0 = lcd_data1; //Write the data second 8 bit
while(!(rSPSTA0&0x1));
rGPEDAT |= (1<<11); //nLCD_CS high
DM_WaitMs(4*1); //need to delay 50us
}
static
void LCD_PowerOnSPI(void)
{
Uart_Printf("LCD_Power on spi start\r\n");
//handy 0429 start
rCLKCON |= ( 0x1 << 18 );//Bridge_00_007_20070129
rGPEUP |= 0x3<<11;
rGPECON = ( rGPECON & ~0x00c00000 ) | 0x00400000;
rGPEDAT &= ~0x0800;//LCD_PWR_on# (GPE11) low
//GPE12--- SPIMOSI0
rGPECON = ( rGPECON & ~0x03000000 ) | 0x02000000;
//GPE13---SPICLK0
rGPECON = ( rGPECON & ~0x0c000000 ) | 0x08000000;
rSPPRE0 =39; //Baud rate = PCLK/2/(Prescaler value+1)
// rSPPIN0=0x2; //set the SPI pin control register(P22-9)
rSPCON0=(0<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(0<<0); //set the SPI control register(P22-7)
//handy 0429 end
/////handy0718 start
if(Panel_Used == Onechip_SamsungPanel){
DM_WaitMs (4*50);
rGPCDAT |= (0x1<<0);//LCD_RESET# clear high(GPC0)
}
else{ //twochip_SamsungPanel
rGPCDAT &= ~(0x1<<0);//LCD_RESET# clear low(GPC0)
DM_WaitMs (4*10);
rGPCDAT |= (0x1<<0);//LCD_RESET# clear high(GPC0)
}
DM_WaitMs (4*10);
if(Panel_Used == Onechip_SamsungPanel){
//power on
LCD_SPI_Write(0x07,0x0000);
DM_WaitMs (4*20);
LCD_SPI_Write(0x12,0x1618);
LCD_SPI_Write(0x11,0x222F);
LCD_SPI_Write(0x13,0x40CA);
LCD_SPI_Write(0x10,0x3108);
DM_WaitMs (4*150);
LCD_SPI_Write(0x12,0x1658);
DM_WaitMs (4*120);
LCD_SPI_Write(0x01,0x2B1D);
LCD_SPI_Write(0x02,0x0300);
LCD_SPI_Write(0x03,0xD000);//need dataenable
LCD_SPI_Write(0x08,0x0008);//vbp 10
LCD_SPI_Write(0x09,0x0021);//hbp = 33 ?? 24/8?
LCD_SPI_Write(0x76,0x2213);
LCD_SPI_Write(0x0B,0x33E1);
LCD_SPI_Write(0x0C,0x0020);
LCD_SPI_Write(0x76,0x0000);
LCD_SPI_Write(0x0D,0x0000);
LCD_SPI_Write(0x0E,0x0000);
LCD_SPI_Write(0x14,0x0000);
LCD_SPI_Write(0x15,0x0803);
LCD_SPI_Write(0x16,0x0008);
LCD_SPI_Write(0x30,0x0209);
LCD_SPI_Write(0x31,0x0404);
LCD_SPI_Write(0x32,0x0E07);
LCD_SPI_Write(0x33,0x0602);
LCD_SPI_Write(0x34,0x0707);
LCD_SPI_Write(0x35,0x0707);
LCD_SPI_Write(0x36,0x0707);
LCD_SPI_Write(0x37,0x0206);
LCD_SPI_Write(0x38,0x0F06);
LCD_SPI_Write(0x39,0x0611);
//display on
LCD_SPI_Write(0x07,0x0001);
DM_WaitMs (4*50);
LCD_SPI_Write(0x07,0x0101);
DM_WaitMs (4*50);
LCD_SPI_Write(0x76,0x2213);
LCD_SPI_Write(0x1C,0x6650);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -