分享

FrameBuffer编程二(简单程序下)

 just_person 2012-08-01

1、开发平台sc6410,编译器arm-linux-gcc 4.3

以下为源代码:

#include <fcntl.h> 
#include <sys/ioctl.h> 
#include <sys/types.h> 
#include <sys/stat.h> 
#include <sys/mman.h> 
#include <unistd.h> 
#include <string.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <linux/types.h> 
#include <linux/fb.h> 
#include <linux/videodev2.h>

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 = NULL; 
    int x = 0 , y = 0; 
    long int location = 0 ; 
    int sav = 0;

//open framebuffer device 
    fbfd = open("/dev/fb0",O_RDWR); 
    if(!fbfd){ 
            printf("Error:cannot open the framebuffer device!\n"); 
            exit(1); 
        }    
    printf("well you open the framebuffer sucessful!\n"); 
//get the fixed screen information 
    if(ioctl(fbfd,FBIOGET_FSCREENINFO,&finfo)){ 
            printf("Error reading fixed information\n"); 
            exit(2); 
        } 
//get the variable screen information 
    if(ioctl(fbfd,FBIOGET_VSCREENINFO,&vinfo)){ 
            printf("Error reading variable information\n"); 
            exit(3); 
        } 
//show these information 
    printf("vinfo.xres=%d\n",vinfo.xres); 
    printf("vinfo.yres=%d\n",vinfo.yres); 
    printf("vinfo.bit_per_bits=%d\n",vinfo.bits_per_pixel); 
    printf("vinfo.xoffset=%d\n",vinfo.xoffset); 
    printf("vinfo.yoffset=%d\n",vinfo.yoffset); 
    printf("finfo.line_length=%d\n",finfo.line_length);    
    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((int)fbp == -1){ 
        printf("Error:failed to map framebuffer device to memory\n"); 
        exit(4); 
    } 
    memset(fbp,0,screensize); 
//plot the screen the colour for black 
    for(x=0;x<vinfo.xres;x++) 
        for(y=0;y<vinfo.yres;y++){ 
            location =(x+vinfo.xoffset)*(vinfo.bits_per_pixel/8)+(y+vinfo.yoffset)*finfo.line_length; 
            *(fbp+location)=0xFF; 
            *(fbp+location+1)=0x00; 
            }    
    sleep(10); 
//release the memory 
    munmap(fbp,screensize); 
    close(fbfd); 
    return 0; 
}

编译下载到开发板上运行的结果截图为(而你的开发板的显示屏会变蓝色):

2011-8-19-20-43

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多