linux使用framebuffer的代码
Posted 知明而行无过
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux使用framebuffer的代码相关的知识,希望对你有一定的参考价值。
#include <linux/fb.h> #include <sys/mman.h> #include <sys/ioctl.h> #include <string.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h>//int close(int fd); struct fb_dev { int fb; void *fb_mem; int fb_width, fb_height, fb_line_len, fb_size; int fb_bpp; } fbdev; int fb_stat(int fd) { struct fb_fix_screeninfo fb_finfo; struct fb_var_screeninfo fb_vinfo; if (ioctl(fd, FBIOGET_FSCREENINFO, &fb_finfo)) { perror(__func__); return (-1); } if (ioctl(fd, FBIOGET_VSCREENINFO, &fb_vinfo)) { perror(__func__); return (-1); } fbdev.fb_width = fb_vinfo.xres; fbdev.fb_height = fb_vinfo.yres; fbdev.fb_bpp = fb_vinfo.bits_per_pixel; fbdev.fb_line_len = fb_finfo.line_length; //fbdev.fb_size = fb_finfo.smem_len; fbdev.fb_size = fb_vinfo.xres * fb_vinfo.yres * fb_vinfo.bits_per_pixel / 8; return (0); } int main(int argc, char **argv) { int fb; if ((fb = open("/dev/fb0", O_RDWR)) < 0) { perror(__func__); return (-1); } fb_stat(fb); fbdev.fb_mem = mmap (NULL, fbdev.fb_size, PROT_READ|PROT_WRITE, MAP_SHARED, fb, 0); fbdev.fb = fb; unsigned char *dst = ((unsigned char *) fbdev.fb_mem); memset(dst, 0x7f, fbdev.fb_size); sleep(1); munmap(fbdev.fb_mem,fbdev.fb_size); close(fb); return 0; }
以上代码仅供参考。
以上是关于linux使用framebuffer的代码的主要内容,如果未能解决你的问题,请参考以下文章
直接访问linux framebuffer - copyarea
Linux下读取framebuffer(/dev/fb0)出来的数据全部是0,为啥会这样