查看: 2620|回复: 0

[原创] 基于ubantu的缓冲帧的显示(转)

[复制链接]
  • TA的每日心情
    开心
    2013-12-17 13:39
  • 签到天数: 48 天

    连续签到: 1 天

    [LV.5]常住居民I

    发表于 2013-12-18 13:37:53 | 显示全部楼层 |阅读模式
    分享到:
    常用ubantu的同学们可能经常会遇到设置开机进入文本模式的选择问题,今天就写一下这方面的一点小技巧,相信会对每个人都有一定的帮助。
    具体步骤如下:
    (1)、修改启动菜单配置文件
    # vi /etc/default/grub
    修改
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
    为:
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash text vga=0x311"

    注释:
    这里text表示进入文本模式,vga=0x311表示使用Framebuffer显示驱动,
    0x311是指示色深和分辨率的参数
          | 640x480 800x600 1024x768 1280x1024
    ------+-----------------------------------------------------
    256   | 0x301     0x303     0x305       0x307
    32k   | 0x310     0x313     0x316       0x319
    16bpp | 0x311     0x314     0x317       0x31A
    16M   | 0x312     0x315     0x318       0x31B
    (2)、更新启动菜单
    $ sudo update-grub
    写入到/boot/grub/grub.cfg
    (3)、修改initramfs
    $ sudo gedit /etc/initramfs-tools/modules
    添加:
    vesafb
    (4)、
    $ sudo gedit /etc/modprobe.d/blacklist-framebuffer.conf
    用#注释以下行
    # blacklist vesafb
    (5)、更新initramfs
    $ sudo update-initramfs -u
    (生成新的initrd)
    (6)、
    然后重启机器,即可进入Framebuffer
    如果要切换回X11,可以输入:
    $ startx
    (7)、图形界面切换到字符界面
    A、atl+ctrl+shift+F1
    B、ctrl+c
    写了一个对LCD的测试代码:
    #include <unistd.h>
    #include <stdio.h>
    #include <fcntl.h>
    #include <linux/fb.h>
    #include <sys/mman.h>
    int main()
    {
        int fbfd = 0;
        struct fb_var_screeninfo vinfo;
        struct fb_fix_screeninfo finfo;
        long int screensize = 0;
        char *fbp = 0;
        int x = 0, y = 0;
        long int location = 0;

        // Open the file for reading and writing
        fbfd = open("/dev/fb0", O_RDWR);
        if (0 > fbfd) {
            printf("Error: cannot open framebuffer device.\n");
            exit(1);
        }
        printf("The framebuffer device was opened successfully.\n");

        // Get variable screen information
        if (0 > ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
            printf("Error reading variable information.\n");
            exit(3);
        }

        printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

        // Figure out the size of the screen in bytes
        screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

        // Map the device to memory
        fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
                           fbfd, 0);
        if ( fbp == MAP_FAILED) {
            printf("Error: failed to map framebuffer device to memory.\n");
            exit(4);
        }
        printf("The framebuffer device was mapped to memory successfully.\n");

    unsigned short *lcd = (unsigned short *)fbp;
    // Figure out where in memory to put the pixel
        for (int x = 0; x < vinfo.xres; x++)
    {
    for (int y = 0; y < vinfo.yres; y++)
            {
    *lcd++ = (0x1F << 11);
    //*lcd++ = (0x3F << 5);
    //*lcd++ = (0x1F);
            }
    }

    munmap(fbp, screensize);
        printf("The framebuffer device was munmapped to memory successfully.\n");
        close(fbfd);
        printf("The framebuffer device was closed successfully.\n");
        return 0;
    }

    是不是很有用处呢,小处处处见真知,童鞋们加油哦!
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-12-12 10:38 , Processed in 0.111868 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.