显示层面头文件
定义结构体,为显示统一标准
int (*DeviceInit)(void);
显示类驱动初始化
int (*ShowPixel)(int iPenX, int iPenY, unsigned int dwColor);
对某一点进行瞄色
int (*CleanScreen)(unsigned int dwBackColor);
清屏
int RegisterDispOpr(PT_DispOpr ptDispOpr);
注册相应链表
#ifndef _DISP_MANAGER_H
#define _DISP_MANAGER_H typedef struct DispOpr {
char *name;
int iXres;
int iYres;
int iBpp;
int (*DeviceInit)(void);
int (*ShowPixel)(int iPenX, int iPenY, unsigned int dwColor);
int (*CleanScreen)(unsigned int dwBackColor);
struct DispOpr *ptNext;
}T_DispOpr, *PT_DispOpr; int RegisterDispOpr(PT_DispOpr ptDispOpr);
void ShowDispOpr(void);
int DisplayInit(void);
int FBInit(void); #endif /* _DISP_MANAGER_H */
书写规范 命名变量 全局为g 结构体为t 指针为p int型为i unsigned 为u 变量名单个单词首字母大写
static int FBDeviceInit(void);
static int FBShowPixel(int iPenX, int iPenY, unsigned int dwColor);
static int FBCleanScreen(unsigned int dwBackColor); static int g_iFBFD;
struct fb_var_screeninfo g_tVar; /* Current var */
struct fb_fix_screeninfo g_tFix; /* Current fix */
static int g_iScreenSize; //????′óD?
static unsigned char * g_pucFBMem;
static int g_iLineWidth;
static int g_iPixelWidth; /* 11?ìò????á11ì?£? éè??£?×¢2á */
//gè??? t?á11ì?
static T_DispOpr g_tFBispopr = {
.name = "fb",
.DeviceInit = FBDeviceInit();
.ShowPixel = FBShowPixel();
.CleanScreen = FBCleanScreen(); }; static int FBDeviceInit(void)
{ g_iFBFD = open("FB_DEVICE_NAME",O_RDWR);
if(g_iFBFD < 0)
{
DBG_PRINTF("can't open FB_DEVICE_NAME \n");
return -1;
}
if(ioctl(g_iFBFD, FBIOGET_VSCREENINFO, &g_tVar))
{
DBG_PRINTF("can't get var \n");
return -1;
}
if(ioctl(g_iFBFD, FBIOGET_FSCREENINFO, &g_tFix))
{
DBG_PRINTF("can't get fix \n");
return -1;
} g_tFBispopr.iXres = g_tVar.xres;
g_tFBispopr.iYres = g_tVar.yres;
g_tFBispopr.iBpp = g_tVar.bits_per_pixel; g_iScreenSize = var.xres * var.yres * var.bits_per_pixel / 8; //μ¥??×??ú g_pucFBMem = (unsigned char *)mmap(NULL, screen_size, \
PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
if(g_pucFBMem == (unsigned char *) -1)
{
DBG_PRINTF("can't mmap \n");
return -1;
}
memset(g_pucFBMem, 0, g_iScreenSize); return 0;
} static int FBShowPixel(int iPenX, int iPenY, unsigned int dwColor)
{
unsigned char *pucPen_8 = g_pucFBMem + iPenY * g_iLineWidth + iPenX * g_iPixelWidth; //μ±?°??????ó|?ú′?????
unsigned short *pwPen_16;
unsigned int *pdwPen_32; unsigned int red, blue, green; pwPen_16 = (unsigned short *)pucPen_8;
pdwPen_32 = (unsigned int *)pucPen_8; switch( g_tFBispopr.iBpp )
{
case 8:
{
*pucPen_8 = dwColor; //??ó|μ÷é?°???é? break;
}
case 16:
{
/* 5*6*5 */
red = (dwColor >> 16) & 0xff;
green = (dwColor >> 8) & 0xff;
blue = (dwColor >> 0) & 0xff; dwColor = ((red >> 3 ) << 11) | ((green >> 2) << 5) | ( blue >> 3); /* ??é?êy?Y?a???? */
*pwPen_16 = dwColor; break;
}
case 32:
{
*pdwPen_32 = dwColor; break;
} }
default:
{
DBG_PRINTF("can't surport %dbpp \n", g_tFBispopr.iBpp);
return -1;
break;
}
return 0; } static int FBCleanScreen(unsigned int dwBackColor)
{
unsigned char *pucPen_8 = g_pucFBMem;
unsigned short *pwPen_16;
unsigned int *pdwPen_32; unsigned int red, blue, green;
int i = 0; pwPen_16 = (unsigned short *)pucPen_8;
pdwPen_32 = (unsigned int *)pucPen_8; switch( g_tFBispopr.iBpp )
{
case 8:
{
memset(pucPen_8, dwBackColor, g_iScreenSize); break;
}
case 16:
{
/* 5*6*5 */
red = (dwBackColor >> 16) & 0xff;
green = (dwBackColor >> 8) & 0xff;
blue = (dwBackColor >> 0) & 0xff; dwBackColor = ((red >> 3 ) << 11) | ((green >> 2) << 5) | ( blue >> 3);
for(i = 0 ; i< g_iScreenSize; i++)
{
*pwPen_16 = dwBackColor;
pwPen_16 ++;
i += 2;
} break;
}
case 32:
{
for(i = 0 ; i< g_iScreenSize; i++)
{
*pdwPen_32 = dwBackColor;
pdwPen_32 ++;
i += 4;
}
break;
} }
default:
{
DBG_PRINTF("can't surport %dbpp \n", g_tFBispopr.iBpp);
return -1;
break;
}
return 0; } int FBInit(void)
{
RegisterDispOpr( &g_tFBispopr);
return 0;
}