分类: LINUX
2008-08-20 18:24:59
好,现在可以让我们开始实现直接写屏:
好象很简单哦~
fbtools.h
#ifndef_FBTOOLS_H_
#define_FBTOOLS_H_
#include<linux/fb.h>
/*aframebufferdevicestructure*/
typedefstructfbdev{
intfb;
unsignedlongfb_mem_offset;
unsignedlongfb_mem;
structfb_fix_screeninfofb_fix;
structfb_var_screeninfofb_var;
chardev[20];
}FBDEV,*PFBDEV;
/*open&initaframebuffer*/
/*tousethisfunction,
youmustsetFBDEV.dev="/dev/fb0"
or"/dev/fbX"*/
/*it''syourframebuffer.*/
intfb_open(PFBDEVpFbdev);
/*closeaframebuffer*/
intfb_close(PFBDEVpFbdev);
/*getdisplaydepth*/
intget_display_depth(PFBDEVpFbdev);
/*fullscreenclear*/
voidfb_memset(void*addr,intc,size_tlen);
#endif
fbtools.c
代码:
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
#include<sys/ioctl.h>
#include<sys/mman.h>
#include<asm/page.h>
#include"fbtools.h"
#defineTRUE1
#defineFALSE0
#defineMAX(x,y)((x)>(y)?(x):(y))
#defineMIN(x,y)((x)<(y)?(x):(y))
/*open&initaframebuffer*/
intfb_open(PFBDEVpFbdev)
{
pFbdev->fb=open(pFbdev->dev,O_RDWR);
if(pFbdev->fb<0)
{
printf("Erroropening%s:%m.Checkkernelconfig\n",pFbdev->dev);
returnFALSE;
}
if(-1==ioctl(pFbdev->fb,FBIOGET_VSCREENINFO,&(pFbdev->fb_var)))
{
printf("ioctlFBIOGET_VSCREENINFO\n");
returnFALSE;
}
if(-1==ioctl(pFbdev->fb,FBIOGET_FSCREENINFO,&(pFbdev->fb_fix)))
{
printf("ioctlFBIOGET_FSCREENINFO\n");
returnFALSE;
}
/*mapphysicsaddresstovirtualaddress*/
pFbdev->fb_mem_offset=(unsignedlong)(pFbdev->fb_fix.smem_start)&(~PAGE_MASK);
pFbdev->fb_mem=(unsignedlongint)mmap(NULL,pFbdev->fb_fix.smem_len
pFbdev->fb_mem_offset,
PROT_READ|PROT_WRITE,MAP_SHARED,pFbdev->fb,0);
if(-1L==(long)pFbdev->fb_mem)
{
printf(