标签:com class http blog div size width get log line 初始化
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);
Linux Framebuffer编程简介,布布扣,bubuko.com
Linux Framebuffer编程简介
标签:com class http blog div size width get log line 初始化
原文地址:http://www.cnblogs.com/ganrui/p/3694955.html