From 3595dfdbbdb8ad843742589ff59efa86b071075d Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sun, 1 Dec 2019 18:53:54 -0700 Subject: [PATCH] add framebuffer initialization --- src/Makefile | 2 +- src/fbinit.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/fbinit.h | 7 +++++ src/main.c | 4 +++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/fbinit.c create mode 100644 src/fbinit.h diff --git a/src/Makefile b/src/Makefile index 08f0b3a..ac35150 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,4 +1,4 @@ -OBJS=main.o sysinput.o log.o gpio.o msg_queue.o time_func.o +OBJS=main.o sysinput.o fbinit.o log.o gpio.o msg_queue.o time_func.o LIBS=-lbcm2835 -lpthread upiwin: $(OBJS) diff --git a/src/fbinit.c b/src/fbinit.c new file mode 100644 index 0000000..477dc8f --- /dev/null +++ b/src/fbinit.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include +#include +#include "log.h" +#include "fbinit.h" + +static int fb_fd = -1; + +static void dump_fixed_info(const struct fb_fix_screeninfo *p) +{ + Log(LDEBUG, "--Fixed screen info follows--"); + Log(LDEBUG, "ID=%s SMEM@0x%08x/%u TYPE=%u TYPEAUX=%u VIZ=%u", + p->id, p->smem_start, p->smem_len, p->type, p->type_aux, p->visual); + Log(LDEBUG, "XPAN=%u YPAN=%u YWRAP=%u LINELEN=%u", p->xpanstep, p->ypanstep, p->ywrapstep, p->line_length); + Log(LDEBUG, "MMIO@0x%08x/%u ACCEL=%02x CAP=%08x", p->mmio_start, p->mmio_len, p->accel, p->capabilities); + Log(LDEBUG, "--ends--"); +} + +static void dump_var_info(const struct fb_var_screeninfo *p) +{ + Log(LDEBUG, "--Variable screen info follows--"); + Log(LDEBUG, "RES=(%u,%u) VRES=(%u,%u) OFS=(%u,%u) BPP=%u GS=%u", p->xres, p->yres, + p->xres_virtual, p->yres_virtual, p->xoffset, p->yoffset, p->bits_per_pixel, p->grayscale); + Log(LDEBUG, "RedBits: ofs=%u len=%u mright=%u", p->red.offset, p->red.length, p->red.msb_right); + Log(LDEBUG, "GreenBits: ofs=%u len=%u mright=%u", p->green.offset, p->green.length, p->green.msb_right); + Log(LDEBUG, "BlueBits: ofs=%u len=%u mright=%u", p->blue.offset, p->blue.length, p->blue.msb_right); + Log(LDEBUG, "XparBits: ofs=%u len=%u mright=%u", p->transp.offset, p->transp.length, p->transp.msb_right); + Log(LDEBUG, "NONSTD=%u ACTIV=%u PSIZ=(%u,%u) AFLG=%08x", + p->nonstd, p->activate, p->width, p->height, p->accel_flags); + Log(LDEBUG, "PIXCLK=%u LM=%u RM=%u TM=%u BM=%u HSYNC=%u VSYNC=%u", p->pixclock, p->left_margin, p->right_margin, + p->upper_margin, p->lower_margin, p->hsync_len, p->vsync_len); + Log(LDEBUG, "SYNC=%u VMODE=%u ROT=%u COLORSP=%u", p->sync, p->vmode, p->rotate, p->colorspace); + Log(LDEBUG, "--ends--"); +} + +int Fb_setup(void) +{ + struct fb_fix_screeninfo fixed; + struct fb_var_screeninfo var; + + fb_fd = open("/dev/fb1", O_RDWR); + if (fb_fd == -1) + { + Log(LFATAL, "Unable to open framebuffer (%d)", errno); + return -1; + } + + if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixed)) + { + Log(LFATAL, "Could not get fixed screen info (%d)", errno); + return -1; + } + + dump_fixed_info(&fixed); + + if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var)) + { + Log(LFATAL, "Could not get variable screen info (%d)", errno); + return -1; + } + + dump_fixed_info(&var); + + /* additional initialization here */ + + return 0; +} + +void Fb_cleanup(void) +{ + /* additional cleanup here */ + + close(fb_fd); +} diff --git a/src/fbinit.h b/src/fbinit.h new file mode 100644 index 0000000..40737f3 --- /dev/null +++ b/src/fbinit.h @@ -0,0 +1,7 @@ +#ifndef __FBINIT_H_INCLUDED +#define __FBINIT_H_INCLUDED + +extern int Fb_setup(void); +extern void Fb_cleanup(void); + +#endif /* __FBINIT_H_INCLUDED */ diff --git a/src/main.c b/src/main.c index 868fbee..f0d546f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include #include "gpio.h" #include "log.h" +#include "fbinit.h" #include "time_func.h" #include "sysinput.h" @@ -10,6 +11,9 @@ int main(int argc, char *argv[]) MSG msg; Time_init(); + if (Fb_setup() != 0) + return EXIT_FAILURE; + atexit(Fb_cleanup); if (Gpio_setup() != 0) return EXIT_FAILURE; atexit(Gpio_cleanup);