Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1371458
  • 博文数量: 198
  • 博客积分: 1629
  • 博客等级: 上尉
  • 技术积分: 2743
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-01 15:41
文章分类
文章存档

2023年(6)

2022年(20)

2021年(8)

2020年(3)

2018年(17)

2017年(3)

2016年(3)

2015年(9)

2014年(13)

2013年(17)

2012年(77)

2011年(22)

分类: LINUX

2012-05-24 10:35:51

    #include
    #include
    #include
    #include
    #include
#define fb_write16(b,addr) (*(volatile unsigned short int *) (addr) = (b))

unsigned short int color_lut[16] = 
{
0x0000, /* 0x0000, 0 oúé«*/
0x0015, /* 0x0015,  1 à¶é«*/
0x07f5, /* 0x07F5,  2*/
0xfb40, /* 0xFB40,  3*/
0x0661, /* 0x0661,  4*/
0xd45f, /* 0xD45F,  5*/
0x6af3, /* 0x6A3F,  6*/
0xdefb, /* 0xDEFB,  7*/
0x2570, /* 0x2570,  8*/
0x057f, /* 0x057F,  9*/
0x57ea, /* 0x57EA,  10*/
0x57ff, /* 0x57FF,  11*/
0xf800, /* 0xF800,  12*/
0xfabf, /* 0xFABF,  13*/
0xffea, /* 0xFFEA,  14*/
0xffff, /* 0xFFFF   15*/
};

int fbfd = 0;
char *fbp = 0;
long int location = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
void draw_rect();

int main()
{
        int i = 0;
        long int screensize = 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);
        }

        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 ((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");
draw_rect();

        munmap(fbp, screensize);
        close(fbfd);
        return 0;
    }
void draw_rect()
{
unsigned char *dst;
unsigned int location;
int x, y;
printf("line length %d,xoffset %d\n",finfo.line_length,vinfo.xoffset);

for( y = 0; y < vinfo.yres; y++ ) {
for( x = 0; x < vinfo.xres; x++ )
{
location=y*finfo.line_length+(x+vinfo.xoffset)*(vinfo.bits_per_pixel/8);
dst=fbp+location; 
fb_write16(color_lut[x/40], dst);
}
    }
return;
}
阅读(3156) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

youngfn2015-02-06 12:57:09

你好,我在测试framebuffer时映射失败,于是我打印了设备信息,其中finfo.smem_len和line_length 都是0,这是意味着我没有framebuffer驱动吗?