linux源码framebuffer,Linux Framebuffer编程实例源码介绍

Linux Framebuffer编程实例源码介绍程序要获取Framebuffer设备的相关参数信息的话,就要通过ioctl()系统调用来完成。头文件中定义了所有的ioctl命令字,但最常用的ioctl命令字是下面这两个:FBIOGET_FSCREENINFO和FBIOGET_VSCREENINFO。

前一个返回与Framebuffer有关的固定的信息,比如图形硬件上实际的帧缓存空间的大小、能否硬件加速等信息。而后一个返回的是与Framebuffer有关的可变信息。可变的信息就是指Framebuffer的长度、宽度以及颜色深度等信息。

控制framebuffer设备的一般步骤如下:

1) 打开设备,映射framebuffer

2)依照硬件要求,准备好数据

3)把数据复制到framebuffer

打开设备,映射framebuffe

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;

}

数据准备,假设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)));

}

把想要显示的数据复制到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;

}

}

}

以上就是Linux Framebuffer编程的过程。

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

static void *fbbuf;

unsigned int bpp;

unsigned int screen_size;

struct fb_var_screeninfo fbvar;

struct fb_fix_screeninfo finfo;

int openfb(char *devname)

{

int fd;

fd = open(devname, O_RDWR);

if (ioctl(fd, FBIOGET_VSCREENINFO, &fbvar) < 0)

return -1;

printf(“the clock is %d\n”, fbvar.pixclock);

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;

}

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)));

}

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 * 240 + j] = pixel;

}

}

}

int main () {

unsigned int r, g, b;

int fp=0;

unsigned int count;

r = 0;

g = 0;

b = 0;

fp = openfb (“/dev/fb0″);

if (fp < 0){

printf(“Error : Can not open framebuffer device\n”);

exit(1);

}

while(1) {

for (count = 0; count < 100; count++) {

r = 0xff;

fill_pixel(make_pixel(0, r, g, b), 0, 0, 240, 320);

}

for (count = 0; count < 100; count++) {

r = 0×00;

fill_pixel(make_pixel(0, r, g, b), 0, 0, 240, 320);

}

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值