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;
    }

    以上代码仅供参考。

  • 相关阅读:
    【AtCoder】ARC097 (C
    【51nod】1123 X^A Mod B (任意模数的K次剩余)
    【洛谷】P4207 [NOI2005]月下柠檬树
    【POJ】2454.Jersey Politics
    【POJ】2069.Super Star
    【POJ】2420.A Star not a Tree?(模拟退火)
    【POJ】1026.Cipher
    【POJ】3270.Cow Sorting
    【POJ】1286.Necklace of Beads
    【POJ】1067.取石子游戏
  • 原文地址:https://www.cnblogs.com/qiuchangyong/p/10045222.html
Copyright © 2011-2022 走看看