设为首页 加入收藏

TOP

Linux Framebuffer编程简介
2014-11-24 11:22:49 来源: 作者: 【 】 浏览:0
Tags:Linux Framebuffer 编程 简介

Linux下,Framebuffer设备文件名通常是/dev/fb0,1,2等。控制framebuffer设备的一般步骤如下:


1) 打开设备,映射framebuffer
2)依照硬件要求,准备好数据
3)把数据复制到framebuffer


例子程序如下:


1)打开设备,映射framebuffer
static void *fbbuf;
int openfb(char *devname)
{
int fd;
fd = open(devname, O_RDWR);
if (ioctl(fd, FBIOGET_VSCREENINFO, &fbvar) < 0)
return -1;
bpp = fbvar.bits_per_pixel;
screen_size = fbvar.xres * fbvar.yres * bpp / 8;
fbbuf = mmap(0, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
return fd;
}


2)数据准备,假设lcd控制器被初始化为565,16bit格式的
static inline int make_pixel(unsigned int a, unsigned int r, unsigned int g, unsigned int b)
{
return (unsigned int)(((r>>3)<<11)|((g>>2)<<5|(b>>3)));
}


3) 把想要显示的数据复制到framebuffer,假设把framebuffer填充成一种颜色
static void fill_pixel(unsigned int pixel, int x0, int y0, int w, int h)
{
int i, j;
unsigned short *pbuf = (unsigned short *)fbbuf;
for (i = y0; i < h; i ++) {
for (j = x0; j < w; j ++) {
pbuf[i * screen_width + j] = pixel;
}
}
}


下面程序把lcd屏幕填充成蓝色


fill_pixel(make_pixel(0, 0, 0,0xff), 0, 0, screen_width, screen_height);


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇FrameBuffer在Linux中的实现和机制 下一篇S3C6410开发:利用触摸屏获取事件..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python 数据分析与可 (2025-12-26 21:51:20)
·从零开始学Python之 (2025-12-26 21:51:17)
·超长干货:Python实 (2025-12-26 21:51:14)
·为什么 Java 社区至 (2025-12-26 21:19:10)
·Java多线程阻塞队列 (2025-12-26 21:19:07)