add framebuffer initialization

This commit is contained in:
Amy G. Bowersox 2019-12-01 18:53:54 -07:00
parent b550994eff
commit 3595dfdbbd
4 changed files with 88 additions and 1 deletions

View File

@ -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)

76
src/fbinit.c Normal file
View File

@ -0,0 +1,76 @@
#include <stddef.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#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);
}

7
src/fbinit.h Normal file
View File

@ -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 */

View File

@ -1,6 +1,7 @@
#include <stdlib.h>
#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);