在本人 的应用中采用的LCD是320*240的FSTN,在此主要描述LCD应用方面的移植工作最基 本的移植工作涉及的三个文件夹里面的文件修改,分别是:
一config文件夹
(1) guiconf.h文件
uCGUI的配置文件,负责配置GUI对OS,window manager,DMA,触 摸屏,Unicode码的支持;以及设置默认字体和各种控件的默认颜色等在我的应用中配置如下:
#define GUI_OS (0) /* Compile with multitasking support */
#define GUI_WINSUPPORT (1) /* Use window manager if true (1) */
#define GUI_SUPPORT_MEMDEV (1) /* Support memory devices */
#define GUI_SUPPORT_TOUCH (1) /* Support a touch screen (req. win-manager) */
#define GUI_SUPPORT_UNICODE (1) /* Support mixed ASCII/UNICODE strings */
#define GUI_ALLOC_SIZE 12500 /* Size of dynamic memory */
#define GUI_DEFAULT_FONT &GUI_Font6x8
(2) lcdconf.h文件
配置LCD显示器,如分辨率,颜色位数,以及LCD控制器的 其它设置在我的应用中配置如下:
//lcd颜色数,必须定义,LCDMONO(单色),LCDG4(四级灰度),LCDG16(16级灰度)
#define LCDG16
#define LCD_CONTROLLER 0
#define LCD_INTERFACEBITS 4
#ifdef LCDG16
#define LCD_BITSPERPIXEL 4
#define LCD_FIXEDPALETTE 4
#endif
//以下是S3C44B0X LCD控制器的配置
#i nclude "..\inc\option.h"
#define SCR_XSIZE (240)
#define SCR_YSIZE (320)
#define LCD_XSIZE (240)
#define LCD_YSIZE (320)
#define M5D(n) ((n) & 0x1fffff)
#define ARRAY_SIZE_MONO (SCR_XSIZE/8*SCR_YSIZE)
#define ARRAY_SIZE_G4 (SCR_XSIZE/4*SCR_YSIZE)
#define ARRAY_SIZE_G16 (SCR_XSIZE/2*SCR_YSIZE)//存储空间以字节为单位,我的LCD是4线单扫描的
#define ARRAY_SIZE_C256 (SCR_XSIZE * SCR_YSIZE)
#define HOZVAL (LCD_XSIZE/4-1)
#define HOZVAL_COLOR (LCD_XSIZE*3/8-1)
#define LINEVAL (LCD_YSIZE-1)
#define MVAL (13)
#define FRAME_RATE 70
#define CLKVAL_MONO (10) //60Mhz, CLKVAL=10 -> 152 Hz
// 30 -> 51.6Hz
// 50 -> 30 Hz
#define CLKVAL_G4 (10)
//#define CLKVAL_G16 (10)
#define CLKVAL_G16 (30) //modify by hjl
#define CLKVAL_C256 (MCLK/(FRAME_RATE*(LINEVAL+1))-26)/(2*(HOZVAL_COLOR+1))
//#define MVAL_USED 0
#define MVAL_USED 1 //modify by hjl
2lcddriver文 件夹
此文件夹中有 一文件LCDWin.c是用来在window环境下仿真UCGUI用的,可将其备份起来,然后另建一文件LCD44b0.c代替它,做为44B0X环境下 的LCD驱动程序在LCD44b0.c中主要完成
读写一个象素的 函数画线填充绘图和LCD模块硬件接口初始化函数移植工作最基本的工作实现SetPixel()和GetPixelIndex(),和硬件接口初始化就可 以, 优化可以慢慢熟悉后再进行.程序中LCD_LO_x之类的函数是uC/GUI中无控制器LCD的接口函数,我的应用程序如下:
/*
*********************************************************
---------------------------------------------------------
File : lcd44b0.c
Purpose : S3C44B0X的lcd控制器的驱动,用于uC/GUI
Data : 2003-7-9 13:46
---------------------------------------------------------
*********************************************************
*/
#i nclude /* needed for definition of NULL */
#i nclude "LCD_Private.H" /* private modul definitions & config */
#i nclude "GUI_Private.H"
#i nclude "GUIDebug.h"
#i nclude "LCD_0.h" /* Defines for first display */
//********************************************************
//
#i nclude
#i nclude "..\inc\44b.h"
#i nclude "..\inc\44blib.h"
#i nclude "..\inc\def.h"
//********************************************************
#if (LCD_CONTROLLER == 0 ) && (!defined(WIN32) | defined(LCD_SIMCONTROLLER))
/*
*********************************************************
* *
* Compiler specific settings *
* *
*********************************************************
*/
#ifdef WIN32 /* Avoid warnings in MS-compiler */
#pragma warning(disable : 4244) // warning C4244: '=' : conversion from 'long ' to 'unsigned char ', possible loss of data
#pragma warning(disable : 4761) // warning C4761: integral size mismatch in argument; conversion supplied
#endif
/*
*********************************************************
* *
* Defaults for configuration *
* *
*********************************************************
*/
#define COLOR LCD_COLORINDEX
#ifdef LCDMONO
U32 (*frameBuffer1)[SCR_XSIZE/32];
#endif
#ifdef LCDG4
U32 (*frameBuffer4)[SCR_XSIZE/16];
#endif
#ifdef LCDG16
U32 (*frameBuffer16)[SCR_XSIZE/8];
#endif
#ifdef LCDC256
U8 frameBuffer256[SCR_YSIZE][SCR_XSIZE];
#endif
/*
*********************************************************
* *
* Internal set pixel routines *
* *
*********************************************************
*/
static void SetPixel(int x, int y, LCD_PIXELINDEX c) {
// c=LCD_NUM_COLORS-1-c;
// 设置坐标对应象素点的输出值,并保留同一字存储空间的其他象素点的输出值不变
//黑白
#ifdef LCDMONO
if(xframeBuffer1[(y)][(x)/32]=( frameBuffer1[(y)][(x)/32] & ~(0x80000000>>((x)%32)*1) )
| ( (c)<< ((32-1-((x)%32))*1) );
#endif
//4级灰度
#ifdef LCDG4
if(xframeBuffer4[(y)][(x)/16]=( frameBuffer4[(y)][x/16] & ~(0xc0000000>>((x)%16)*2) )
| ( (c)<<((16-1-((x)%16))*2) );
#endif
//16级灰度
#ifdef LCDG16
if(xframeBuffer16[(y)][(x)/8]=( frameBuffer16[(y)][x/8] & ~(0xf0000000>>((x)%8)*4) )
| ( (c)<<((8-1-((x)%8))*4) );
#endif
//
#ifdef LCDC256
if(xframeBuffer256[(y)][4*(x/4+1)-1-x%4]=c;
// 以4个象素为一组,低象素放在最高位例如frameBuffer256[0][3]
//frameBuffer256[0][2]frameBuffer256[0][1]frameBuffer256[0][0]
// 第1个象素放在frameBuffer256[0][3],第4个象素放在frameBuffer256[0][0]
#endif
}
unsigned int GetPixelIndex(int x, int y) {
//返回坐标对应象素点的当前值,以4个象素为一组,低象素放在最高位
LCD_PIXELINDEX col;
//黑白
#ifdef LCDMONO
col=( frameBuffer1[(y)][(x)/32] >> ( 32-1-(x%32)*1 ) ) & 0x1;
return col;
#endif
//4级灰度
#ifdef LCDG4
col=( frameBuffer4[(y)][(x)/16] >> ( 32-2-(x%16)*2 ) ) & 0x3;
return col;
#endif
//16级灰度
#ifdef LCDG16
col=( frameBuffer16[(y)][(x)/8] >> ( 32-4-(x%8)*4 ) ) & 0xf;
return col;
#endif
//
#ifdef LCDC256
col=frameBuffer256[(y)][4*(x/4+1)-1-x%4];
return col;
#endif
}
static void XorPixel (int x, int y) {
LCD_PIXELINDEX Index = GetPixelIndex(x,y);
SetPixel(x,y,LCD_NUM_COLORS-1-Index);
}
/*
*********************************************************
* *
* LCD_L0_XorPixel *
* *
*********************************************************
Purpose: This routine is called by emWin. It writes 1 pixel into the
display.
*/
void LCD_L0_XorPixel(int x, int y) {
XorPixel(x, y);
}
void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex) {
SetPixel(x, y, ColorIndex);
}
/*
*********************************************************
* *
* LCD_L0_DrawHLine optimized *
* *
* 16 bit bus, Using BITBLT *
* *
*********************************************************
*/
void LCD_L0_DrawHLine (int x0, int y, int x1)
{
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
{
while (x0 <= x1)
{
XorPixel(x0, y);
x0++;
}
} else
{
while (x0 <= x1)
{
SetPixel(x0, y, COLOR);
x0++;
}
}
}
/*
*********************************************************
* *
* LCD_L0_DrawVLine optimized *
* *
* 16 bit bus, using BITBLT *
* *
*********************************************************
*/
void LCD_L0_DrawVLine (int x, int y0, int y1) {
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
while (y0 <= y1) {
XorPixel(x, y0);
y0++;
}
} else {
while (y0 <= y1) {
SetPixel(x, y0, COLOR);
y0++;
}
}
}
/*
*********************************************************
* *
* LCD_FillRect *
* *
*********************************************************
*/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
#if !LCD_SWAP_XY
for (; y0 <= y1; y0++) {
LCD_L0_DrawHLine(x0,y0, x1);
}
#else
for (; x0 <= x1; x0++) {
LCD_L0_DrawVLine(x0,y0, y1);
}
#endif
}
/*
**********************************************************
* *
* Draw a line *
* *
**********************************************************
*/
static void DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
// LCD_PIXELINDEX aColor[2];
U16 Pixels = ((*p) << 8) | (*(p + 1));
U8 RemPixels;
p++;
// aColor[0] = *pTrans;
// aColor[1] = *(pTrans + 1);
x += Diff;
RemPixels = 16 - Diff;
Pixels <<= Diff;
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
do {
if (RemPixels==0) {
Pixels = ((*(p + 1)) << 8) | (*(p + 2));
p += 2;
RemPixels = 16;
}
if (Pixels & 0x8000) {
XorPixel(x, y);
}
RemPixels--;
Pixels <<=1;
x++;
} while (--xsize);
}
else {
do {
if (RemPixels==0) {
Pixels = ((*(p + 1)) << 8) | (*(p + 2));
p += 2;
RemPixels = 16;
}
if (Pixels & 0x8000) {
SetPixel(x, y, *(pTrans+1));
}
RemPixels--;
Pixels <<=1;
x++;
} while (--xsize);
}
}
/*
*********************************************************
* *
* Universal draw Bitmap routine *
* *
*********************************************************
*/
void LCD_L0_DrawBitmap (int x0, int y0,
int xsize, int ysize,
int BitsPerPixel,
int BytesPerLine,
const U8* pData, int Diff,
const LCD_PIXELINDEX* pTrans) {
int i;
for (i=0; iDrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);
pData += BytesPerLine;
}
}
/********************************************************
* *
* LCD_L0_SetOrg *
* *
*********************************************************
Purpose: Sets the original position of the virtual display.
Has no function at this point with the PC-driver.
*/
int OrgX, OrgY;
void LCD_L0_SetOrg(int x, int y) {
OrgX = x;
OrgY = y;
}