📄 lcd.c
字号:
/**************************************************
** 文件名:lcdn.c
** 版本号:V 1.0
** 版权说明:本源码由天嵌科技编写并维护。
** 文件说明:实现LCD驱动器的驱动和LCD现实的功能
***************************************************/
#include "config.h"
// GPB1/TOUT1 for Backlight control(PWM)
#define GPB1_TO_OUT() (rGPBUP &= 0xfffd, rGPBCON &= 0xfffffff3, rGPBCON |= 0x00000004)
#define GPB1_TO_1() (rGPBDAT |= 0x0002)
#define GPB1_TO_0() (rGPBDAT &= 0xfffd)
//extern void Uart_Printf(char *f, ...) ;
/*
extern unsigned char __CHS[];
extern unsigned char __VGA[];
*/
//volatile static
unsigned short LCD_BUFFER[SCR_YSIZE_TFT][SCR_XSIZE_TFT];//240*320
/**************************************************************
320×240 16Bpp TFT LCD功能模块初始化
**************************************************************/
static void Lcd_PowerEnable(int invpwren,int pwren);
static void Lcd_Init(void)
{
rGPCUP = 0x00000000;
rGPCCON = 0xaaaa02a9;
// rGPDUP=0xffffffff; // Disable Pull-up register
rGPDUP = 0x00000000;
rGPDCON=0xaaaaaaaa; //Initialize VD[15:8]
rLCDCON1=(CLKVAL_TFT << 8)|(MVAL_USED << 7)|(3 <<5 )|(12 << 1)|0;
// TFT LCD panel,16bpp TFT,ENVID=off
rLCDCON2=(VBPD << 24)|(LINEVAL_TFT << 14)|(VFPD << 6)|(VSPW);
rLCDCON3=(HBPD << 19)|(HOZVAL_TFT << 8)|(HFPD);
rLCDCON4=(MVAL << 8)|(HSPW);
rLCDCON5 = (1 << 11) | (0 << 10) | (1 << 9) | (1 << 8) | (0 << 7) | (0 << 6)
| (1 << 3) |(BSWP << 1) | (HWSWP);
//5:6:5 VCLK posedge BSWP=0,HWSWP=1;
rLCDSADDR1=(((U32)LCD_BUFFER>>22)<<21)|M5D((U32)LCD_BUFFER>>1);
rLCDSADDR2=M5D( ((U32)LCD_BUFFER+(SCR_XSIZE_TFT * LCD_YSIZE_TFT * 2)) >> 1 );
rLCDSADDR3=(((SCR_XSIZE_TFT - LCD_XSIZE_TFT) / 1) << 11)|(LCD_XSIZE_TFT / 1);
rLCDINTMSK|=(3); // MASK LCD Sub Interrupt
rTCONSEL &= (~7) ; // Disable LPC3480
rTPAL=0; // Disable Temp Palette
}
/**************************************************************
LCD视频和控制信号输出或者停止,1开启视频输出
**************************************************************/
static void Lcd_EnvidOnOff(int onoff)
{
if(onoff == 1)
rLCDCON1 |= 1; // ENVID=ON
else
rLCDCON1 = rLCDCON1 & 0x3fffe; // ENVID Off
}
/**************************************************************
320×240 16Bpp TFT LCD 电源控制引脚使能
**************************************************************/
static void Lcd_PowerEnable(int invpwren,int pwren)
{
//GPG4 is setted as LCD_PWREN
rGPGUP = rGPGUP & ( ~(1 << 4)) |(1 << 4); // Pull-up disable
rGPGCON = rGPGCON & ( ~(3 << 8)) |(3 << 8); //GPG4=LCD_PWREN
rGPGDAT = rGPGDAT | (1 << 4) ;
// invpwren=pwren;
//Enable LCD POWER ENABLE Function
rLCDCON5 = rLCDCON5 & ( ~(1 << 3)) |(pwren << 3); // PWREN
rLCDCON5 = rLCDCON5 & ( ~(1 << 5)) |(invpwren << 5); // INVPWREN
}
/**************************************************************
320×240 16Bpp TFT LCD移动观察窗口
**************************************************************/
static void Lcd_MoveViewPort(int vx, int vy)
{
U32 addr;
SET_IF();
#if (LCD_XSIZE_TFT < 32)
while((rLCDCON1 >> 18) <= 1); // if x<32
#else
while((rLCDCON1 >> 18) == 0); // if x>32
#endif
addr = (U32)LCD_BUFFER + (vx * 2) + vy * (SCR_XSIZE_TFT * 2);
rLCDSADDR1 = ( (addr >> 22) << 21 ) | M5D(addr >> 1);
rLCDSADDR2 = M5D(((addr + (SCR_XSIZE_TFT * LCD_YSIZE_TFT * 2)) >> 1));
CLR_IF();
}
/**************************************************************
320×240 16Bpp TFT LCD移动观察窗口
**************************************************************/
static void MoveViewPort(void)
{
int vx=0,vy=0,vd=1;
Uart_Printf("\n*Move the LCD view windos:\n");
Uart_Printf(" press 8 is up\n");
Uart_Printf(" press 2 is down\n");
Uart_Printf(" press 4 is left\n");
Uart_Printf(" press 6 is right\n");
Uart_Printf(" press Enter to exit!\n");
while(1)
{
switch( Uart_GetKey() )
{
case '8':
if(vy>=vd)vy-=vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '4':
if(vx>=vd)vx-=vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '6':
if(vx<=(SCR_XSIZE_TFT - LCD_XSIZE_TFT -vd))vx += vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '2':
if(vy<=(SCR_YSIZE_TFT - LCD_YSIZE_TFT -vd))vy += vd;
Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
Lcd_MoveViewPort(vx,vy);
break;
case '\r':
return;
default:
break;
}
//Uart_Printf("vx=%3d,vy=%3d\n",vx,vy);
//Lcd_MoveViewPort(vx,vy);
}
}
/**************************************************************
320×240 16Bpp TFT LCD单个象素的显示数据输出
**************************************************************/
void PutPixel(U32 x,U32 y, U16 c )
{
if ( (x < SCR_XSIZE_TFT) && (y < SCR_YSIZE_TFT) )
LCD_BUFFER[(y)][(x)] = c;
}
void GUI_Point(U32 x,U32 y, U16 c )
{
if ( (x < SCR_XSIZE_TFT) && (y < SCR_YSIZE_TFT) )
LCD_BUFFER[(y)][(x)] = c;
}
/**************************************************************
320×240 16Bpp TFT LCD全屏填充特定颜色单元或清屏
**************************************************************/
void Lcd_ClearScr( U16 c)
{
unsigned int x,y ;
for( y = 0 ; y < SCR_YSIZE_TFT ; y++ )
{
for( x = 0 ; x < SCR_XSIZE_TFT ; x++ )
{
LCD_BUFFER[y][x] = c ;
}
}
}
/**************************************************************
LCD屏幕显示垂直翻转
// LCD display is flipped vertically
// But, think the algorithm by mathematics point.
// 3I2
// 4 I 1
// --+-- <-8 octants mathematical cordinate
// 5 I 8
// 6I7
**************************************************************/
void Glib_Line(int x1,int y1,int x2,int y2,int color)
{
int dx,dy,e;
dx = x2 -x1;
dy = y2 -y1;
if(dx >= 0)
{
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 1/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1+=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 2/8 octant
{
e=dx-dy/2;
while(y1<=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1+=1;
e+=dx;
}
}
}
else // dy<0
{
dy=-dy; // dy=abs(dy)
if(dx>=dy) // 8/8 octant
{
e=dy-dx/2;
while(x1<=x2)
{
PutPixel(x1,y1,color);
if(e>0){y1-=1;e-=dx;}
x1+=1;
e+=dy;
}
}
else // 7/8 octant
{
e=dx-dy/2;
while(y1>=y2)
{
PutPixel(x1,y1,color);
if(e>0){x1+=1;e-=dy;}
y1-=1;
e+=dx;
}
}
}
}
else //dx<0
{
dx=-dx; //dx=abs(dx)
if(dy >= 0) // dy>=0
{
if(dx>=dy) // 4/8 octant
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -