#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#define WIDTH 480
#define HEIGHT 480
#define BYTES_PER_PIXEL 4
int main() {
int fb = open("/dev/fb0", O_RDWR);
if (fb == -1) {
perror("Unable to open framebuffer");
return 1;
}
struct fb_var_screeninfo vinfo;
ioctl(fb, FBIOGET_VSCREENINFO, &vinfo);
printf("vinfo.xres=%d, vinfo.yres=%d\n", vinfo.xres, vinfo.yres);
printf("vinfo.xres_virtual=%d, vinfo.yres_virtual=%d\n", vinfo.xres_virtual, vinfo.yres_virtual);
ioctl(fb, FBIOGET_VSCREENINFO, &vinfo);
unsigned char *fbp = mmap(0, vinfo.yres_virtual * vinfo.xres * BYTES_PER_PIXEL, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0);
// 填充第一个缓冲区
for (int y = 0; y < vinfo.yres; y++)
for (int x = 0; x < vinfo.xres; x++)
*((unsigned long*)(fbp + 4*x + 4*y*vinfo.xres)) = 0xFF00FFFF;
// 填充第二个缓冲区
for (int y = vinfo.yres; y < 2*vinfo.yres; y++)
for (int x = 0; x < vinfo.xres; x++)
*((unsigned long*)(fbp + 4*x + 4*y*vinfo.xres)) = 0xFFFF00FF;
int i = 0;
while(1)
{
// 切换到第二个缓冲区
vinfo.yoffset = (i++%2)*HEIGHT;
printf("vinfo.yoffset = %d\n", vinfo.yoffset);
if(0 != ioctl(fb, FBIOPAN_DISPLAY, &vinfo))
{
printf("fb iopan display error.\n");
}
sleep(1);
}
munmap(fbp, vinfo.yres_virtual * vinfo.xres * BYTES_PER_PIXEL);
close(fb);
return 0;
}
离线
离线