上一章我们简单介绍了LCD的一些基本原理。当然更深奥的还有,比如gamma,dither,HUE,satuation.OSD等等.
我们知道我们是用framebuffer来实现显示的.
显存:framebuffer.由DDRAM中划去一部分内存供显存使用.
从而操作lcd相当于操作显存.
lcd控制器(s5pv210里面有lcd控制器)会周期的获取framebuffer中的数据。经过处理丢给 显示屏的lcd 驱动器
lcd驱动器分析,解码,将数据显示到lcd上.
lcd驱动开发的工作:
配置lcd 控制器,让lcd 控制器周期性的读取显存中的数据
然后按照一定的时序和格式讲数据发送给lcd驱动器.驱动器会驱动lcd屏进行显示.
1)申请显存
framebuffer:导出lcd物理缓冲区(显存)导入到用户空间(0-3G)
用户空间要显示一幅图片到lcd,在用户空间直接操作显存,将要显示的图片copy到
显存中的相应位置上就可以了
这边就先不多讲了,因为时间太晚,太累。我们画一个这样的图片:
用户空间代码:
#include
#include
#include
#include
#include #define _COLOR_RED 0x00ff0000 #define _COLOR_GREEN 0x0000ff00 #define _COLOR_BLUE 0x000000ff static struct fb_fix_screeninfo fb_fix ={0}; static struct fb_var_screeninfo fb_var ={0}; long screen_size=0; int *fb32 =NULL; int main() { int fd = -1; int x,y; fd =open("/dev/fb0",O_RDWR); if(fd < 0) { printf("open dev fb0 fail.\n"); return -1; } //get lcd param ioctl(fd,FBIOGET_FSCREENINFO,&fb_fix); ioctl(fd,FBIOGET_VSCREENINFO,&fb_var); screen_size = fb_var.xres*fb_var.yres*(fb_var.bits_per_pixel/8); fb32 =mmap(0,screen_size,PROT_READ |PROT_WRITE,MAP_SHARED,fd,0); if(fb32 == NULL) { printf("mmap framebuffer fail.\n"); return -1; } if(fb_var.bits_per_pixel == 8) { printf("8bpp framebuffer test.\n"); } else if(fb_var.bits_per_pixel == 16) { printf("16bpp framebuffer test.\n"); } else if(fb_var.bits_per_pixel == 24) { printf("24bpp framebuffer test.\n"); } else if(fb_var.bits_per_pixel == 32) { printf("32bpp framebuffer test.\n"); } for(y=0;y< fb_var.yres/3;y++) { for(x=0;x< fb_var.xres;x++) { *(fb32 +y*fb_var.xres + x) = _COLOR_RED; } } for(;y< fb_var.yres*2/3;y++) { for(x=0;x< fb_var.xres;x++) { *(fb32 +y*fb_var.xres + x) = _COLOR_GREEN; } } for(;y< fb_var.yres;y++) { for(x=0;x< fb_var.xres;x++) { *(fb32 +y*fb_var.xres + x) = _COLOR_BLUE; } } munmap(fb32,screen_size); close(fd); return 0; }
实验效果:
可以看到,和我们预期的一样。其中那边有一个小黑框那是光标,我们不管。