1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| #include <stdio.h> #include <sys/ioctl.h> #include <fcntl.h> #include <unistd.h> #include <stdint.h> #include <errno.h> #include <string.h> #include <linux/fb.h> #include <sys/mman.h>
int main(int argc, char const *argv[]) { int i, j, fd, var;
struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo;
if (argc < 2) { fprintf(stderr, "Example: %s /dev/fb0\n", argv[0]); return -1; }
fd = open(argv[1], O_RDWR); if (fd < 0) { fprintf(stderr, "Can't open file %s: %s\n", argv[1], strerror(errno)); return -1; }
if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo)) { perror("Can't get FBIOGET_VSCREENINFO"); return -1; }
if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo)) { perror("Can't get FBIOGET_VSCREENINFO"); return -1; }
printf("vinfo.xres = %d\n", vinfo.xres); printf("vinfo.yres = %d\n", vinfo.yres); printf("vinfo.bits_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);
int screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
char *fbp = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (fbp == MAP_FAILED) { perror("mmap error"); return -1; }
memset(fbp, 0xff, screensize); for (int x = 0; x < vinfo.xres; x++) { for (int y = 0; y < vinfo.yres; y++) { int location = (x + vinfo.xoffset) * (vinfo.bits_per_pixel / 8) + (y + vinfo.yoffset) * finfo.line_length;
*(fbp + location) = 0xff; *(fbp + location + 1) = 0x00; } } munmap(fbp, screensize); close(fd); printf("all ok\n");
return 0; }
|