📄 screendrv.c
字号:
#include "UtilFunc.h"
#include "stdio.h"
#include "stdlib.h"
#include "RegCtl.h"
#include "XsGpioDrv.h"
#include "SitsangBrdRegs.h"
#include "SitsangBrdDrv.h"
#include "XsClkMgrDrv.h"
#include "XsPwmDrv.h"
#include <string.h>
#include "systypes.h"
#include "xslcdcontroller.h"
#include "screen.h"
//我的文件
#include "ScreenDrv.h"
#include "pixFont.h"
#define Maximum(a,b) ((a)>=(b)?(a):(b))
//局部声明
//#define debuglcd //调试中
#ifdef debuglcd
#include "XsUartDrv.h"
#endif
#ifndef LCD_SIZE_TO_PAGES
#define LCD_PAGE_SIZE 8192
#define LCD_PAGE_MASK 0xFFF
#define LCD_PAGE_SHIFT 12
#define LCD_SIZE_TO_PAGES(a) ( ((a) >> LCD_PAGE_SHIFT) + ((a) & LCD_PAGE_MASK ? 1 : 0) )
#endif
//changed by chf.
VScreen_T VSGLOBAL;
unsigned char LcdFD[24+16];
unsigned char FrameBuffer[614448+8];//全局缓冲区
unsigned short * pPixel=NULL;
static void setupLcd(Panel_Info_T * infoP)
{
int lines;
struct lcdregs * lcdP;
lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,oum,1);//LCD Output Fifo Underrun Mask:underrun interrupts are masked
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,qdm,1);//LCD Quick Disable Interrupt Mask:1, the quick disable interrupt is masked
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,cms,0);//Color|Monochrome Select:0 ,color
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,sds,infoP->dualPanel);
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,pas,infoP->activeDisplay);
// temp disable int.
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,ldm,1);//LCD Disable Done Mask:1 = LCD disable done condition does not generate an interrupt
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,sfm,1);//Start of Frame Mask:1=disable
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,ium,1);//Input FIFO Underrun Mask:1=disable
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,efm,1);//End of Frame Mask::1=disable
/* Little endian mode
*/
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,ble,0);
/* Four pixels per clock
*/
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,dpd,0);//Double-Pixel Data (DPD) pin mode:0=send 4 pixel values each pixel clock transition.
/* Disable palette DMA
*/
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,pdd,0);//Palette DMA Request Delay:bus clocks to wait before requesting another burst of palette data
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,bm,1);//Branch Mask-interrupt when change to another frame ::1=disable
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,oum,0);//Output FIFO Underrun mask:0=enable interrupt
/* Pixels per line
*/
// temp panelWidth - 16
IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,ppl,infoP->panelWidth-1);
/* Horiz sync pulse width
*/
IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,hsw,infoP->horizSyncPW);
/* End of line wait
*/
IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,elw,infoP->horizELW);
/* Start of line wait
*/
IOW_REG_FIELD(struct lccr1Bits,&lcdP->lccr1,blw,infoP->horizBLW);
/* If dual panel we split the lines for vertical lines per panel as
* both run in parallel.
*/
if (infoP->dualPanel)
lines = infoP->panelHeight/2 + infoP->extraLines;
else
lines = infoP->panelHeight + infoP->extraLines;
IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,lpp,lines-1);
/* Vertical sync width
*/
IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,vsw,infoP->vertSyncPW);
/* End of frame wait
*/
IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,efw,infoP->vertEFW);
/* Start of frame wait
*/
IOW_REG_FIELD(struct lccr2Bits,&lcdP->lccr2,bfw,infoP->vertBFW);
/* AC bias for passive display
*/
IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,acb,infoP->acBiasCount);
IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,api,0);
/* Set vsync polarity
*/
IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,vsp,infoP->frameSyncPol);
/* Set hsync polarity
*/
IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,hsp,infoP->horizSyncPol);
/* Set PCLK edge polarity
*/
IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,pcp,infoP->clockPol);
/* Set enable polarity
*/
IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,oep,infoP->outputEnaPol);
//temp
IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,bpp,4);
// IOW_REG_FIELD(struct lccr3Bits,&lcdP->lccr3,dpc,1);
/* No offsets in LCD mode (single frame buffer)
*/
}
#define LCD_ROUND_PAGE(_a) (((unsigned)(_a)+(LCD_PAGE_SIZE-1))/LCD_PAGE_SIZE)
int allocateFrameBuffer1(void *FrameBufferP1)
{
DM_FrameBuffer_T * frameBufferP;
LCDFrameDescriptorT *pFD;
UINT i;
UINT frameBufferSize;
int h = 640;
int v = 480;
struct lcdregs * lcdP;
// 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 * (16/8) + sizeof(DM_FrameBuffer_T));
#ifdef debuglcd
PrintfUartDef("frameBuffer Calling \r\n");
PrintfUartDef("frameBuffer size is %d\r\n", frameBufferSize);
PrintfUartDef("frameBuffer address is %x-to-%x\r\n", (UINT)FrameBufferP1,((UINT)(FrameBufferP1)+614447));
#endif
// now move the pointer to the frame buffer to after the structure
frameBufferP = (DM_FrameBuffer_T*)FrameBufferP1;
#ifdef debuglcd
PrintfUartDef("frameBufferP is 0x%x \r\n",(UINT)frameBufferP);
#endif
frameBufferP->bufP = (unsigned short *)(((((UINT)(frameBufferP + 1))+7)/8)*8);
#ifdef debuglcd
PrintfUartDef("frameBufferP->bufP is 0x%x \r\n",(UINT)(unsigned short *)(frameBufferP + 1));
#endif
frameBufferP->pixelP = (unsigned short *)(((((UINT)(frameBufferP + 1))+7)/8)*8);
//初始化全局的pixel指针,在PrintPix和copyPix中使用
pPixel=(unsigned short *)(((((UINT)(frameBufferP + 1))+7)/8)*8);
#ifdef debuglcd
PrintfUartDef("frameBufferP->pixelP is 0x%x \r\n",(UINT)(unsigned short *)(frameBufferP + 1));
#endif
frameBufferP->numPage = frameBufferSize;
#ifdef debuglcd
PrintfUartDef("framesize is %d\r\n",frameBufferSize);
#endif
// 使用蓝色清理缓冲区
for (i=0; i < h * v; i += 2) {
frameBufferP->pixelP[i] = (RGB565_COLOR_BLUE & 0xFFFF);
frameBufferP->pixelP[i+1] = (RGB565_COLOR_BLUE & 0xFFFF0000) >> 16;
}
//setup DMA
//需要16字节对齐
i=(UINT)LcdFD;
i=((i+15)/16)*16;
pFD = (LCDFrameDescriptorT*)i;
pFD->FDADR = (UINT32)pFD;
pFD->FSADR = (UINT32)frameBufferP->pixelP;
pFD->FIDR = 0x00000001;
pFD->LDCMD = (UINT32)640*480*2;
lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
lcdP->FDADR0 = (UINT32)pFD;
//--------------------------------------------//
return 1;
}
static void clearStatusReg(void)
{
struct lcdregs * lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,ber,1);//Bus error status, nonmaskable interrupt:DMA has attempted an access to a reserved/nonexistent location in external memory.
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,abc,1);//The AC bias transition counter has decremented to zero
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iol,1);
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iul,1);//Input FIFO Underrun Lower Panel Status
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iou,1);
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,iuu,1);//Input FIFO Underrun Upper Panel Status
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,ool,1);
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,oul,1);
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,oou,1);
IOW_REG_FIELD(struct lcsrBits,&lcdP->lcsr,ouu,1);
}
static void off()
{
struct lcdregs * lcdP;
int timeout,wasRunning;
lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
timeout = 1000; // 1 second.
wasRunning = lcdP->lccr0.len;
IOW_REG_FIELD(struct lccr0Bits,&lcdP->lccr0,dis,0);
if (wasRunning) {
while(!lcdP->lcsr.lfd) {
//--------------需要重新实现------------------
Util_DelayUs(1000);
if (!timeout--) { // Workaround, also good practice anyways.
break;
}
}
}
}
void InitLcdGraphics ( )
{
//unsigned DATA;
DM_FrameBuffer_T * Buffer;
struct lcdregs * lcdP = (struct lcdregs *) LCD_BASE_PHYSICAL;
int i;
//Toshiba LTM04C380K 4", (640*480)
Panel_Info_T Toshiba_LTM04C380K =
{640, // width
480, // height
0, // No extra lines
Panel_TypeLcd, // Panel type
0, // Single panel
1, // Active display
16, // bits per pixel
65,//3,//65, // horizontal sync pulse width
95,//139,//95, // horizontal end of line pixel clock wait count
1,//15,//0x1, // horizontal beginning of line pixel clock wait count
0, // Reserved
1,//3,//0x1, // vertical sync pulse width
0,//34,//0, // vertical end of frame line clock wait count
45,//5,//45, // vertical beginning of frame clock wait count
0, // Reserved
1, // frameSyncPol
1, // horizSyncPol
1, // clockPol
0, // outputEnablePol
0, // AC bias counter
0, // Reserved
};
Buffer = (DM_FrameBuffer_T*)FrameBuffer;
#ifdef debuglcd
PrintfUartDef("Buffer = (DM_FrameBuffer_T*)FrameBuffer\r\n");
#endif
///////////////////////
//LCD GPIO pin setting
// set pon direction
LOAD_FIELD(GPIO_GPDR1_ADDR, 0x3f, GXXR_GPIO58_OFS, 6); //GPIO pin 58~63(6 pins) as output
LOAD_FIELD(GPIO_GPDR2_ADDR, 0x3fff, GXXR_GPIO64_OFS, 14); //GPIO pin 64~77(14 pins) as output
#ifdef debuglcd
PrintfUartDef("LCD GPIO pin setting\r\n");
#endif
//set alternative function
LOAD_FIELD(GPIO_GAFR1_U_ADDR, 0xaaa, GAFR_AF58_OFS, 12); //GPIO pin 58~63
LOAD_FIELD(GPIO_GAFR2_L_ADDR, 0xaaaaaaa, GAFR_AF64_OFS, 28);//GPIO pin 64~77
#ifdef debuglcd
PrintfUartDef("set alternative function\r\n");
#endif
//print message
#ifdef debuglcd
PrintfUartDef("Screen width:%d\r\n", Toshiba_LTM04C380K.panelWidth);
PrintfUartDef("Screen height:%d\r\n",Toshiba_LTM04C380K.panelHeight);
#endif
//setup lcd register
setupLcd(&Toshiba_LTM04C380K);
#ifdef debuglcd
PrintfUartDef("setupLcd(&Toshiba_LTM04C380K)\r\n");
#endif
//enable LCD clock
CLKMGR_ENABLE_CLK(CKEN_CK_LCD_OFS);
// pcd = (LCLK / 2 / PixelClock) - 1, where LCLK = 100MHz, PixelClock = 25MHz
IOW_REG_FIELD(struct lccr3Bits, &lcdP->lccr3, pcd, 1);//pcd:Pixel Clock Divisor
//获取初始化DMA内存
i=allocateFrameBuffer1((void *)FrameBuffer);//初始化16 bpp 所需要的600k缓冲区
clearStatusReg();
//InitPWM();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -