fbee

changeset 1:2471e9b63432 tip

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 07 Feb 2013 16:03:32 +0200
parents 88a2049be27b
children
files .hgignore Makefile src/sys_linuxfb.c
diffstat 3 files changed, 86 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Thu Feb 07 16:03:32 2013 +0200
     1.3 @@ -0,0 +1,4 @@
     1.4 +\.o$
     1.5 +\.swp$
     1.6 +\.d$
     1.7 +^libfbee.a$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile	Thu Feb 07 16:03:32 2013 +0200
     2.3 @@ -0,0 +1,25 @@
     2.4 +gfxsys_cflags = `sdl-config --cflags`
     2.5 +gfxsys_ldflags = `sdl-config --libs`
     2.6 +
     2.7 +src = $(wildcard src/*.c)
     2.8 +obj = $(src:.c=.o)
     2.9 +lib_a = libfbee.a
    2.10 +bin = fbee_test
    2.11 +
    2.12 +inc = -Iinclude -Isrc
    2.13 +
    2.14 +CFLAGS = -pedantic -Wall -g $(inc) $(gfxsys_cflags)
    2.15 +LDFLAGS = $(gfxsys_ldflags)
    2.16 +
    2.17 +$(bin): test.o $(lib_a)
    2.18 +	$(CC) -o $@ test.o $(lib_a) $(LDFLAGS)
    2.19 +
    2.20 +$(lib_a): $(obj)
    2.21 +	$(AR) rcs $@ $(obj)
    2.22 +
    2.23 +%.d: %.c
    2.24 +	@$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
    2.25 +
    2.26 +.PHONY: clean
    2.27 +clean:
    2.28 +	rm -f $(obj) $(bin) test.o $(lib_a)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/sys_linuxfb.c	Thu Feb 07 16:03:32 2013 +0200
     3.3 @@ -0,0 +1,57 @@
     3.4 +#include <stdio.h>
     3.5 +#include <string.h>
     3.6 +#include <errno.h>
     3.7 +#include <unistd.h>
     3.8 +#include <fcntl.h>
     3.9 +#include <sys/ioctl.h>
    3.10 +#include <sys/select.h>
    3.11 +#include <linux/fb.h>
    3.12 +
    3.13 +static int fbfd;
    3.14 +static void *framebuf;
    3.15 +
    3.16 +static int width, height, bpp;
    3.17 +static int dirty;
    3.18 +
    3.19 +int fbee_sys_init(void)
    3.20 +{
    3.21 +	struct fb_var_screeninfo sinf;
    3.22 +	struct termios termios;
    3.23 +
    3.24 +	/* open framebuffer device */
    3.25 +	if((fbfd = open("/dev/fb0", O_RDWR)) == -1) {
    3.26 +		fprintf(stderr, "failed to open /dev/fb0: %s\n", strerror(errno));
    3.27 +		return -1;
    3.28 +	}
    3.29 +
    3.30 +	if(ioctl(fbfd, FBIOGET_VSCREENINFO, &sinf) == -1) {
    3.31 +		fprintf(stderr, "failed to retreive screen information for fb0: %s\n", strerror(errno));
    3.32 +		close(fbfd);
    3.33 +		fbfd = -1;
    3.34 +		return -1;
    3.35 +	}
    3.36 +	width = sinf.width;
    3.37 +	height = sinf.height;
    3.38 +	bpp = sinf.bits_per_pixel;
    3.39 +
    3.40 +	if((framebuf = mmap(0, width * height * bpp / 8, PROT_READ | PROT_WRITE,
    3.41 +					MAP_SHARED, fbfd, 0)) == (void*)-1) {
    3.42 +		fprintf(stderr, "failed to map framebuffer: %s\n", strerror(errno));
    3.43 +		return -1;
    3.44 +	}
    3.45 +
    3.46 +
    3.47 +	/* set terminal in raw mode */
    3.48 +	if(tcgetattr(0, &termios) == -1) {
    3.49 +		fprintf(stderr, "failed to get terminal information: %s\n", strerror(errno));
    3.50 +		munmap(framebuf, width * height * bpp / 8);
    3.51 +		return -1;
    3.52 +	}
    3.53 +
    3.54 +	/* open /dev/psaux for mouse input */
    3.55 +	if((mousefd = open("/dev/psaux", O_RDONLY | O_NONBLOCK)) == -1) {
    3.56 +		fprintf(stderr, "Failed to open the mouse device: %s, mouse will be unavailable.\n", strerror(errno));
    3.57 +	}
    3.58 +
    3.59 +	return 0;
    3.60 +}