⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fbtest.c

📁 ARM开发实例emed linuxexamples.tar.gz
💻 C
字号:
#include <unistd.h>#include <stdio.h>#include <fcntl.h>#include <linux/fb.h>#include <sys/mman.h>#define RED_COLOR    0xE0#define GREEN_COLOR  0x1C#define BLUE_COLOR   0x03/* * framebuffer application code, the start code of Linux GUI application * compile : *          $/usr/local/arm/2.95.3/bin/arm-linux-gcc -o fbtest fbtest.c *          $cp fbtest /tftpboot/examples * run in target: *          #mount 192.168.1.180:/tftpboot/ /mnt/nfs *          #cd /mnt/nfs/examples *          #./fbtest */int main(int argc, char **argv){    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 (!fbfd) {        printf("Error: cannot open framebuffer device.\n");        exit(1);    }    printf("The framebuffer device was opened successfully.\n");    // Get fixed screen information    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {        printf("Error reading fixed information.\n");        exit(2);    }    // Get variable screen information    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {        printf("Error reading variable information.\n");        exit(3);    }    // Figure out the size of the screen in bytes    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;    printf("%dx%d, %dbpp, screensize = %d\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel, screensize );    // Map the device to memory    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,                       fbfd, 0);    if ((int)fbp == -1) {        printf("Error: failed to map framebuffer device to memory.\n");        exit(4);    }    printf("The framebuffer device was mapped to memory successfully.\n");    x = 100; y = 100;       // Where we are going to put the pixel    if(vinfo.bits_per_pixel == 8)  // 8bpp only    {        // 8bpp framebuffer test        printf("8bpp framebuffer test\n");        printf("a byte in fbp is a pixel of LCD, just set the value of fbp to put color to LCD\n");        printf("byte format:\n");        printf("  bit:| 7  6  5 |  4  3  2 | 1  0 |\n");        printf("      |  red    |   green  | blue |\n");        // Red Screen        printf("Red Screen\n");        for(y = 0; y < 240; y++)        {            for(x = 0; x < 320; x++)            {                *(fbp + y * 320 + x) = RED_COLOR;            }        }        sleep(2);        // Green Screen        printf("Green Screen\n");        for(y = 0; y < 240; y++)        {            for(x = 0; x < 320; x++)            {                *(fbp + y * 320 + x) = GREEN_COLOR;            }        }        sleep(2);        // Blue Screen        printf("Blue Screen\n");        for(y = 0; y < 240; y++)        {            for(x = 0; x < 320; x++)            {                *(fbp + y * 320 + x) = BLUE_COLOR;            }        }        sleep(2);        // Grid Screen        printf("Grid Screen\n");        for(y = 0; y < 240; y++)        {            for(x = 0; x < 320; x++)            {                *(fbp + y * 320 + x) = x;            }        }        sleep(2);    }else    {        printf("8bpp only!!!\n");    }    munmap(fbp, screensize);    close(fbfd);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -