📄 lcddriver.c
字号:
/*
;************************************************************************************************************
;* 北京精仪达盛科技有限公司
;* 研 发 部
;*
;* http://www.techshine.com
;*
;*--------------------------------------------- 文件信息 ----------------------------------------------------
;*
;* 文件名称 : LCDdriver.c
;* 文件功能 : 该文件为S3C2410硬件平台LCD驱动。
;* 补充说明 :
;*-------------------------------------------- 最新版本信息 -------------------------------------------------
;* 修改作者 : ARM开发小组
;* 修改日期 : 2005/08/4
;* 版本声明 : V1.0.1
;*-------------------------------------------- 历史版本信息 -------------------------------------------------
;* 文件作者 : ARM开发小组
;* 创建日期 : 2004/04/20
;* 版本声明 : v1.0.0
;*-----------------------------------------------------------------------------------------------------------
;*-----------------------------------------------------------------------------------------------------------
;************************************************************************************************************
;*/
#include "LCDdriver.h"
#include <string.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
//Color STN
U32 (*frameBuffer12Bit)[SCR_XSIZE_CSTN*3/8];
U32 (*frameBuffer8Bit)[SCR_XSIZE_CSTN / 4];
#define BYTESPERLINE (LCD_XSIZE_CSTN)
typedef unsigned long tOff;
#if (Color_Bit == 8)
#define XY2OFF(x,y) (tOff)((tOff)y*(tOff)BYTESPERLINE + (x))
#endif
#define READ_MEM(Off, Data) Data = LCD_READ_MEM(Off)
#define WRITE_MEM(Off, Data) LCD_WRITE_MEM(Off, Data)
#define GETPIXEL(x, y) GetPixelIndex(x, y)
#define SETPIXEL(x, y, c) SetPixel(x, y, c)
extern U16 LCD_COLOR;
void (*PutPixel)(U32,U32,U32);
/*
*************************************************************************************************************
- 函数名称 : U16 LCD_Init(U8 Lcd_Bpp)
- 函数说明 : LCD硬件初始化函数
- 输入参数 :
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_Init(int type) {
//Save the wasted power consumption on GPIO.
rIISPSR=(2<<5)|(2<<0); //IIS_LRCK=44.1Khz @384fs,PCLK=50Mhz.
rGPHCON = rGPHCON & ~(0xf<<18)|(0x5<<18); //CLKOUT 0,1=OUTPUT to reduce the power consumption.
switch(type){
case MODE_CSTN_12BIT:
frameBuffer12Bit=(U32 (*)[SCR_XSIZE_CSTN*3/8])LCDFRAMEBUFFER;
// Packed Type : The L.C.M of 12 and 32 is 96.
rLCDCON1=(CLKVAL_CSTN<<8)|(MVAL_USED<<7)|(2<<5)|(4<<1)|0;
// 8-bit single scan,12bpp CSTN,ENVID=off
rLCDCON2=(0<<24)|(LINEVAL_CSTN<<14)|(0<<6)|0;
rLCDCON3=(WDLY_CSTN<<19)|(HOZVAL_CSTN<<8)|(LINEBLANK_CSTN<<0);
rLCDCON4=(MVAL<<8)|(WLH_CSTN<<0);
rLCDCON5=0;
//BPP24BL:x,FRM565:x,INVVCLK:x,INVVLINE:x,INVVFRAME:x,INVVD:x,
//INVVDEN:x,INVPWREN:x,INVLEND:x,PWREN:x,ENLEND:x,BSWP:x,HWSWP:x
rLCDSADDR1=(((U32)frameBuffer12Bit>>22)<<21)|M5D((U32)frameBuffer12Bit>>1);
rLCDSADDR2=M5D(((U32)frameBuffer12Bit+((SCR_XSIZE_CSTN*3/2)*LCD_YSIZE_CSTN))>>1);
rLCDSADDR3=(((SCR_XSIZE_CSTN-LCD_XSIZE_CSTN)*3/4)<<11)|(LCD_XSIZE_CSTN*3/4);
rDITHMODE=0;
break;
case MODE_CSTN_8BIT:
frameBuffer8Bit=(U32 (*)[SCR_XSIZE_CSTN / 4])LCDFRAMEBUFFER;
// Packed Type : The L.C.M of 12 and 32 is 96.
rLCDCON1=(CLKVAL_CSTN<<8)|(MVAL_USED<<7)|(2<<5)|(3<<1)|0;
// 8-bit single scan,8bpp CSTN,ENVID=off
rLCDCON2=(0<<24)|(LINEVAL_CSTN<<14)|(0<<6)|0;
rLCDCON3=(WDLY_CSTN<<19)|(HOZVAL_CSTN<<8)|(LINEBLANK_CSTN<<0);
rLCDCON4=(MVAL<<8)|(WLH_CSTN<<0);
rLCDCON5= 0;
//BPP24BL:x,FRM565:x,INVVCLK:x,INVVLINE:x,INVVFRAME:x,INVVD:x,
//INVVDEN:x,INVPWREN:x,INVLEND:x,PWREN:x,ENLEND:x,BSWP:x,HWSWP:x
rLCDSADDR1=(((U32)frameBuffer8Bit>>22)<<21)|M5D((U32)frameBuffer8Bit>>1);
rLCDSADDR2=M5D(((U32)frameBuffer8Bit+((SCR_XSIZE_CSTN )*LCD_YSIZE_CSTN))>>1);
rLCDSADDR3=(((SCR_XSIZE_CSTN-LCD_XSIZE_CSTN)/2)<<11)|(LCD_XSIZE_CSTN / 2);
rDITHMODE=0;
rREDLUT =0xfdb96420;
rGREENLUT=0xfdb96420;
rBLUELUT =0xfb40;
break;
default:
break;
}
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_DrawPixel (U16 x, U16 y)
- 函数说明 : 画点函数
- 输入参数 : x,y
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_DrawPixel (U16 x, U16 y)
{
SetPixel(x, y, LCD_COLOR);
}
/*
*************************************************************************************************************
- 函数名称 : U16 LCD_READ_MEM(U32 off)
- 函数说明 : 针对硬件的读点函数
- 输入参数 : x,y,c
- 输出参数 : 无
*************************************************************************************************************
*/
U16 LCD_READ_MEM(U32 off)
{
return (*((U8*)LCDFRAMEBUFFER + (off)));
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_WRITE_MEM( U32 off,U8 Data)
- 函数说明 : 针对硬件的画点函数
- 输入参数 : x,y,c
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_WRITE_MEM( U32 off,U8 Data)
{
(* ((U8*)LCDFRAMEBUFFER + (off)) ) = Data;
}
/*
*************************************************************************************************************
- 函数名称 : static void SetPixel(U16 x,U16 y,int c)
- 函数说明 : 针对硬件的画点函数
- 输入参数 : x,y,c
- 输出参数 : 无
*************************************************************************************************************
*/
static void SetPixel(U16 x, U16 y, U32 c)
{
PutPixel(x,y,c);
}
/*
*************************************************************************************************************
- 函数名称 : U32 GetPixelIndex(U16 x, U16 y)
- 函数说明 : 针对硬件的得到点的颜色的函数
- 输入参数 : x,y
- 输出参数 : color
*************************************************************************************************************
*/
U32 GetPixelIndex(U16 x, U16 y)
{
U32 col;
U8 Data;
tOff Off = XY2OFF(x,y);
READ_MEM(Off,Data);
col = Data;
return col;
}
/*
*************************************************************************************************************
- 函数名称 : U32 LCD_GetPixel(U16 x, U16 y)
- 函数说明 : 得到点值的函数
- 输入参数 : x,y
- 输出参数 : colof
*************************************************************************************************************
*/
U32 LCD_GetPixel(U16 x, U16 y)
{
return GETPIXEL(x,y);
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_DrawHLine (U16 x0, U16 y, U16 x1)
- 函数说明 : 画水平线函数
- 输入参数 : x,y,x1
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_DrawHLine (U16 x0, U16 y0, U16 x1)
{
while (x0 <= x1)
{
SETPIXEL(x0, y0, LCD_COLOR);
x0++;
}
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_DrawVLine (U16 x, U16 y0, U16 y1)
- 函数说明 : 画竖直线函数
- 输入参数 : x,y,x1
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_DrawVLine(U16 x0, U16 y0, U16 y1)
{
while (y0 <= y1)
{
SETPIXEL(x0, y0, LCD_COLOR);
y0++;
}
}
/*
*************************************************************************************************************
- 函数名称 : void LCD_FillRect(U16 x0, U16 y0, U16 x1, U16 y1)
- 函数说明 : 填充矩形函数
- 输入参数 : x0,y0,x1,y1
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_FillRect(U16 x0, U16 y0, U16 x1, U16 y1)
{
for (; y0 <= y1; y0++)
{
LCD_DrawHLine(x0,y0, x1);
}
}
/*
*************************************************************************************************************
- 函数名称 : DrawBitLine1BPP
- 函数说明 : 绘制位图函数
- 输入参数 : x0,y0,x1,y1
- 输出参数 : 无
*************************************************************************************************************
*/
static void DrawBitLine1BPP(U16 x, U16 y, U8 const*p, U16 Diff, U16 xsize, const U16*pTrans)
{
U16 pixels;
U32 Index0 = *(pTrans + 0);
U32 Index1 = LCD_COLOR;
pixels = *p;
switch (Diff&7)
{
case 0:
goto WriteBit0;
case 1:
goto WriteBit1;
case 2:
goto WriteBit2;
case 3:
goto WriteBit3;
case 4:
goto WriteBit4;
case 5:
goto WriteBit5;
case 6:
goto WriteBit6;
case 7:
goto WriteBit7;
}
WriteBit0:
SETPIXEL(x+0, y, (pixels&(1<<7)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit1:
SETPIXEL(x+1, y, (pixels&(1<<6)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit2:
SETPIXEL(x+2, y, (pixels&(1<<5)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit3:
SETPIXEL(x+3, y, (pixels&(1<<4)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit4:
SETPIXEL(x+4, y, (pixels&(1<<3)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit5:
SETPIXEL(x+5, y, (pixels&(1<<2)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit6:
SETPIXEL(x+6, y, (pixels&(1<<1)) ? Index1 : Index0);
if (!--xsize)
return;
WriteBit7:
SETPIXEL(x+7, y, (pixels&(1<<0)) ? Index1 : Index0);
if (!--xsize)
return;
x+=8;
pixels = *(++p);
goto WriteBit0;
}
/*
*************************************************************************************************************
- 函数名称 : LCD_L0_DrawBitmap
- 函数说明 : 绘制位图函数
- 输入参数 :
- 输出参数 : 无
*************************************************************************************************************
*/
void LCD_L0_DrawBitmap(U16 x0, U16 y0,U16 xsize, U16 ysize,U16 BitsPerPixel,U16 BytesPerLine,
const U8* pData, U16 Diff,
const U16* pTrans)
{
U16 i;
switch (BitsPerPixel)
{
case 1:
for (i=0; i<ysize; i++)
{
DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);
pData += BytesPerLine;
}
break;
}
}
void Glib_Init(int type)
{
switch(type)
{
case MODE_CSTN_8BIT:
PutPixel=_PutCstn8Bit;
break;
case MODE_CSTN_12BIT:
PutPixel=_PutCstn12Bit;
break;
default:
break;
}
}
void _PutCstn8Bit(U32 x,U32 y,U32 c)
{
if(x<SCR_XSIZE_CSTN&& y<SCR_YSIZE_CSTN)
frameBuffer8Bit[(y)][(x)/4]=( frameBuffer8Bit[(y)][x/4]
& ~(0xff000000>>((x)%4)*8) ) | ( (c&0x000000ff)<<((4-1-((x)%4))*8) );
}
void _PutCstn12Bit(U32 x,U32 y,U32 c)
{
U32 z;
z=((x)%8);
if(x<SCR_XSIZE_CSTN&& y<SCR_YSIZE_CSTN)
{
if((z%3)!=2)
frameBuffer12Bit[(y)][(x)*3/8]=
( frameBuffer12Bit[(y)][(x)*3/8] & ~(0xfff00000>>(((z/3)*4)+((z)%3)*12) )
| ( (c&0xfff)<<(20-(((z/3)*4)+((z)%3)*12))) );
else
{
if(z==2)
{
frameBuffer12Bit[(y)][(x)*3/8]=( (frameBuffer12Bit[(y)][(x)*3/8]
& ~(0xff)) | ((c&0xff0)>>4) );
frameBuffer12Bit[(y)][((x)*3/8)+1]=( (frameBuffer12Bit[(y)][((x)*3/8)+1]
& ~(0xf0000000)) | ((c&0xf)<<28) );
}
else if(z==5)
{
frameBuffer12Bit[(y)][(x)*3/8]=( (frameBuffer12Bit[(y)][(x)*3/8]
& ~(0xf)) | ((c&0xf00)>>8) );
frameBuffer12Bit[(y)][((x)*3/8)+1]=( (frameBuffer12Bit[(y)][((x)*3/8)+1]
& ~(0xff000000)) | ((c&0xff)<<24) );
}
}
}
}
void Lcd_CstnOnOff(int onoff)
{
// 1:CSTN Panel on 0:CSTN Panel off //
if(onoff==1)
rLCDCON1|=1; // ENVID=ON
else
rLCDCON1 =rLCDCON1 & 0x3fffe; // ENVID Off
rGPBUP=rGPBUP|(1<<5); // Pull-up disable
rGPBDAT=rGPBDAT&(~(1<<5))|(onoff<<5); // GPB5=On or Off
rGPBCON=rGPBCON&(~(3<<10))|(1<<10); //GPD9=output
}
/*
*****************************************************************************************************************
** 结束文件 **
*****************************************************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -