(1) 进入内核源码目录中,make menuconfig -> Device Drivers -> Graphics support -> [M]Support for frame buffer devices
重新编译内核 make uImage ,然后make modules,将driver/video/下的 fb.ko、cfbfillrect.ko、cfbimgblt.ko、cfbcopyarea.ko拷贝到210的根文件中,分别 insmod 安装到内核中。
(2) 安装lcd.ko驱动模块
(3) 应用层读写 frame buffer 测试程序框架
#include#include #include #include #include #include int main(){ int fbfd = 0; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; long int screensize = 0; char *fbp = NULL; int x,y,r = 0,g = 0, b = 0; unsigned int rgb; /*打开设备文件*/ fbfd = open("/dev/fb0", O_RDWR); /*取得屏幕相关参数*/ ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo); ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo); /*计算屏幕缓冲区大小*/ screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; /*映射屏幕缓冲区到用户地址空间*/ fbp=(char*)mmap(0,screensize,PROT_READ | PROT_WRITE,MAP_SHARED, fbfd, 0); if((int)fbp == -1) { printf("Error: failed to map framebuffer device to memory .\n"); return -1; } /*下面可通过fbp指针操作缓冲区:显示红 */ for(y = 0;y<(vinfo.yres);y++)//vinfo.yres = 272 { for(x = 0;x < vinfo.xres;x++)//vinfo.xres=480 { long location = x*3 + y * vinfo.xres * 3;//用户缓冲区地址移动,一个像素3字节(24位真彩色) r = 256; g = 0; b = 0; rgb = (r << 16) | (g << 8) | b; //分别获得相应颜色 *((unsigned short *)(fbp + location)) = rgb; } } /*释放缓冲区,关闭设备*/ munmap(fbp, screensize); close(fbfd);}
或者直接使用:cat xxxfile > /dev/fb0 现象:出现花屏。