Framebuffer的初始化

来源:互联网 发布:网络老虎机mg出分技术 编辑:程序博客网 时间:2024/06/06 13:17

1 #include <stdio.h>
  2 #include <fcntl.h>
  3 #include <sys/ioctl.h>
  4 #include <sys/types.h>
  5 #include <linux/fb.h>
  6 #include <stdlib.h>
  7 #include <sys/mman.h>
  8
  9 #include "types.h"
 10
 11
 12 int fb_init(FB_SCR *fb_scr)
 13 {
 14
 15     struct fb_var_screeninfo fb_var;
 16     int fd;
 17     int ret;
 18     int *p;
 19
 20     fd = open("/dev/fb0", O_RDWR);
 21     if(fd == -1)
 22     {
 23         perror("fail to open");
 24         exit(0);
 25     }

 26     ret = ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
 27
 28
 29     printf("width: %d/thigh: %d/tbpp: %d/n", fb_var.xres, fb_var.yres, fb_var.bits_per_pixel);
 30
 31     p = mmap(NULL, fb_var.xres*fb_var.yres*fb_var.bits_per_pixel/32, PROT_WRITE|PROT_WRITE, MAP_SHARED, fd,     0);
 32     if(p == NULL)
 33     {
 34         perror("fail to mmap");
 35         exit(0);
 36     }
 37     fb_scr->x_res = fb_var.xres;
 38     fb_scr->y_res = fb_var.yres;
 39     fb_scr->bits_per_pixel = fb_var.bits_per_pixel;
 40     fb_scr->mem = (void *)p;
 41
 42
 43     close(fb_var);
 44
 45
 46
 47 }