zoukankan      html  css  js  c++  java
  • 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;
    }

    以上代码仅供参考。

  • 相关阅读:
    mysql的root用户无法建库的问题
    jmeter连库获取sql结果存为参数给下一接口用
    webservice接口问题
    今日杂记-20190623
    接口测试
    pyenv和virtualenv管理python的版本(多个版本同时用)
    安装禅道
    经典题,类中的变量
    CSS简介
    python单元测试unittest
  • 原文地址:https://www.cnblogs.com/qiuchangyong/p/10045222.html
Copyright © 2011-2022 走看看