在linux下如何启用framebuffer
时间:2006-05-31 来源:liubo1977
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
timeout=10
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title Red Hat Linux (2.4.18-14)
root (hd0,0)
kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/ hdc=ide-scsi vga=0x314
initrd /boot/initrd-2.4.18-14.img 2、其中vga=0x314表示800*600*16位,其它的取值见下表:
色彩 | 640x400 | 640x480 | 800x600 | 1024x768 | 1280x1024 | 1600x1200 |
4bits | ? | ? | 0x302 | ? | ? | ? |
8bits | 0x300 | 0x301 | 0x303 | 0x305 | 0x307 | 0x31C |
15bits | ? | 0x310 | 0x313 | 0x316 | 0x319 | 0x31D |
16bits | ? | 0x311 | 0x314 | 0x317 | 0x31A | 0x31E |
24bits | ? | 0x312 | 0x315 | 0x318 | 0x31B | 0x31F |
32bits | ? | ? | ? | ? | ? | ? |
3、测试framebuffer的例子如下:
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
int main()
{
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long int screensize = 0;
char *fbp = 0;
int x = 0, y = 0,i;
long int location = 0;
/* Open the file for reading and writing */
fbfd = open("/dev/fb0", O_RDWR);
if (!fbfd) {
printf("Error: cannot open framebuffer device.\n");
exit(1);
}
printf("The framebuffer device was opened successfully.\n");
/* Get fixed screen information */
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf("Error reading fixed information.\n");
exit(2);
}
/* Get variable screen information */
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf("Error reading variable information.\n");
exit(3);
}
/* Figure out the size of the screen in bytes */
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
/* Map the device to memory */
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"); exit(4);
}
printf("The framebuffer device was mapped to memory successfully.\n");
x = 100; y = 100; /* Where we are going to put the pixel */
/* Figure out where in memory to put the pixel */
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
for(i=0;i<400;i++)
{
*(fbp + location+i) = 100; /* Some blue */
*(fbp + location +i+ 1) = 15; /* A little green */
*(fbp + location +i+ 2) = 200; /* A lot of red */
*(fbp + location +i+3) = 0; /* No transparency */
}
munmap(fbp, screensize);
close(fbfd);
return 0;
}
4、关于fbset工具。这是一个可以查看和设置framebuffer的工具。
5、一篇有用的参考文献:
http://bbs.linuxsir.org/showthread.php?t=211427