int fbfd,screensize;
// Open the file for reading and writing
fbfd = open( ptr, O_RDWR); // ptr为/dev/fb0
if (fbfd < 0)
{
printf("Error: cannot open framebuffer device.%x\n",fbfd);
return ERR_FRAME_BUFFER;
}
printf("The framebuffer device was opened successfully.\n");
vd->fbfd = fbfd; // 保存打开FrameBuffer设备的句柄
// Get fixed screen information 获取FrameBuffer固定不变的信息
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &vd->finfo))
{
printf("Error reading fixed information.\n");
return ERR_FRAME_BUFFER;
}
// Get variable screen information 获取FrameBuffer屏幕可变的信息
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vd->vinfo))
{
printf("Error reading variable information.\n");
return ERR_FRAME_BUFFER;
}
printf("%dx%d, %dbpp, xoffset=%d ,yoffset=%d \n", vd->vinfo.xres, vd->vinfo.yres, vd->vinfo.bits_per_pixel,vd->vinfo.xoffset,vd->vinfo.yoffset );
// Figure out the size of the screen in bytes
screensize = vd->vinfo.xres * vd->vinfo.yres * vd->vinfo.bits_per_pixel / 8;
printf("\nscreensize=%d\n",screensize );
// Map the device to memory
vd->fbp = (char *)mmap(0,screensizes,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0); // 影射Framebuffer设备到内存
printf("errno is: %d\n",errno);
if ((int)vd->fbp == -1)
{
printf("Error: failed to map framebuffer device to memory.\n");
return ERR_FRAME_BUFFER;
}
printf("The framebuffer device was mapped to memory successfully.\n");
return 0;
结果如下
[email protected]://work/nfsdir/rootfs# gcc -o video video.c
video.c: In function ‘udps_respon’:
video.c:418: warning: format not a string literal and no format arguments
[email protected]://work/nfsdir/rootfs# ./video
The framebuffer device was opened successfully.
640x480, 4bpp, xoffset=0 ,yoffset=0
screensize=153600
errno is: 22
Error: failed to map framebuffer device to memory.
可我把vd->fbp = (char *)mmap(0,screensizes,PROT_READ|PROT_WRITE,MAP_SHARED,fbfd,0);screensizes改成10000后没有报错 我设置的太大了吗
------解决方案--------------------
你可以把错误信息打出来看看