码迷,mamicode.com
首页 > 系统相关 > 详细

linux使用framebuffer的代码

时间:2018-11-30 17:28:03      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:pre   sys   perror   res   null   dwr   int   munmap   nis   

#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的代码

标签:pre   sys   perror   res   null   dwr   int   munmap   nis   

原文地址:https://www.cnblogs.com/qiuchangyong/p/10045222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!