fbee
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/sys_linuxfb.c Thu Feb 07 16:03:32 2013 +0200 1.3 @@ -0,0 +1,57 @@ 1.4 +#include <stdio.h> 1.5 +#include <string.h> 1.6 +#include <errno.h> 1.7 +#include <unistd.h> 1.8 +#include <fcntl.h> 1.9 +#include <sys/ioctl.h> 1.10 +#include <sys/select.h> 1.11 +#include <linux/fb.h> 1.12 + 1.13 +static int fbfd; 1.14 +static void *framebuf; 1.15 + 1.16 +static int width, height, bpp; 1.17 +static int dirty; 1.18 + 1.19 +int fbee_sys_init(void) 1.20 +{ 1.21 + struct fb_var_screeninfo sinf; 1.22 + struct termios termios; 1.23 + 1.24 + /* open framebuffer device */ 1.25 + if((fbfd = open("/dev/fb0", O_RDWR)) == -1) { 1.26 + fprintf(stderr, "failed to open /dev/fb0: %s\n", strerror(errno)); 1.27 + return -1; 1.28 + } 1.29 + 1.30 + if(ioctl(fbfd, FBIOGET_VSCREENINFO, &sinf) == -1) { 1.31 + fprintf(stderr, "failed to retreive screen information for fb0: %s\n", strerror(errno)); 1.32 + close(fbfd); 1.33 + fbfd = -1; 1.34 + return -1; 1.35 + } 1.36 + width = sinf.width; 1.37 + height = sinf.height; 1.38 + bpp = sinf.bits_per_pixel; 1.39 + 1.40 + if((framebuf = mmap(0, width * height * bpp / 8, PROT_READ | PROT_WRITE, 1.41 + MAP_SHARED, fbfd, 0)) == (void*)-1) { 1.42 + fprintf(stderr, "failed to map framebuffer: %s\n", strerror(errno)); 1.43 + return -1; 1.44 + } 1.45 + 1.46 + 1.47 + /* set terminal in raw mode */ 1.48 + if(tcgetattr(0, &termios) == -1) { 1.49 + fprintf(stderr, "failed to get terminal information: %s\n", strerror(errno)); 1.50 + munmap(framebuf, width * height * bpp / 8); 1.51 + return -1; 1.52 + } 1.53 + 1.54 + /* open /dev/psaux for mouse input */ 1.55 + if((mousefd = open("/dev/psaux", O_RDONLY | O_NONBLOCK)) == -1) { 1.56 + fprintf(stderr, "Failed to open the mouse device: %s, mouse will be unavailable.\n", strerror(errno)); 1.57 + } 1.58 + 1.59 + return 0; 1.60 +}