fbee

view src/sys_linuxfb.c @ 1:2471e9b63432

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 07 Feb 2013 16:03:32 +0200
parents
children
line source
1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <sys/ioctl.h>
7 #include <sys/select.h>
8 #include <linux/fb.h>
10 static int fbfd;
11 static void *framebuf;
13 static int width, height, bpp;
14 static int dirty;
16 int fbee_sys_init(void)
17 {
18 struct fb_var_screeninfo sinf;
19 struct termios termios;
21 /* open framebuffer device */
22 if((fbfd = open("/dev/fb0", O_RDWR)) == -1) {
23 fprintf(stderr, "failed to open /dev/fb0: %s\n", strerror(errno));
24 return -1;
25 }
27 if(ioctl(fbfd, FBIOGET_VSCREENINFO, &sinf) == -1) {
28 fprintf(stderr, "failed to retreive screen information for fb0: %s\n", strerror(errno));
29 close(fbfd);
30 fbfd = -1;
31 return -1;
32 }
33 width = sinf.width;
34 height = sinf.height;
35 bpp = sinf.bits_per_pixel;
37 if((framebuf = mmap(0, width * height * bpp / 8, PROT_READ | PROT_WRITE,
38 MAP_SHARED, fbfd, 0)) == (void*)-1) {
39 fprintf(stderr, "failed to map framebuffer: %s\n", strerror(errno));
40 return -1;
41 }
44 /* set terminal in raw mode */
45 if(tcgetattr(0, &termios) == -1) {
46 fprintf(stderr, "failed to get terminal information: %s\n", strerror(errno));
47 munmap(framebuf, width * height * bpp / 8);
48 return -1;
49 }
51 /* open /dev/psaux for mouse input */
52 if((mousefd = open("/dev/psaux", O_RDONLY | O_NONBLOCK)) == -1) {
53 fprintf(stderr, "Failed to open the mouse device: %s, mouse will be unavailable.\n", strerror(errno));
54 }
56 return 0;
57 }