From 58ef012d44266b1d4fe3e778e1c919957be102c4 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sun, 1 Dec 2019 19:39:14 -0700 Subject: [PATCH] add the framebuffer info, mapping the frame buffer, and actually putting something on screen --- src/fbinit.c | 66 +++++++++++++++++++++++++++++++--------------------- src/fbinit.h | 25 ++++++++++++++++++++ src/main.c | 7 ++++++ 3 files changed, 72 insertions(+), 26 deletions(-) diff --git a/src/fbinit.c b/src/fbinit.c index a1477c7..890968d 100644 --- a/src/fbinit.c +++ b/src/fbinit.c @@ -1,39 +1,24 @@ #include +#include #include #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 FBINFO local_info; +PCFBINFO Fb_Info = &local_info; -static void dump_var_info(const struct fb_var_screeninfo *p) +uint16_t *Fb_Ptr = NULL; + +inline static unsigned makemask(unsigned offset, unsigned length) { - 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--"); + return ((1 << length) - 1) << offset; } int Fb_setup(void) @@ -54,7 +39,8 @@ int Fb_setup(void) return -1; } - dump_fixed_info(&fixed); + local_info.linebytes = fixed.line_length; + local_info.screenbytes = fixed.smem_len; if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var)) { @@ -62,9 +48,32 @@ int Fb_setup(void) return -1; } - dump_var_info(&var); + local_info.width = var.xres; + local_info.height = var.yres; + local_info.virtual_width = var.xres_virtual; + local_info.virtual_height = var.yres_virtual; + local_info.bpp = var.bits_per_pixel; + local_info.red_offset = var.red.offset; + local_info.red_length = var.red.length; + local_info.red_mask = makemask(var.red.offset, var.red.length); + local_info.green_offset = var.green.offset; + local_info.green_length = var.green.length; + local_info.green_mask = makemask(var.green.offset, var.green.length); + local_info.blue_offset = var.blue.offset; + local_info.blue_length = var.blue.length; + local_info.blue_mask = makemask(var.blue.offset, var.blue.length); - /* additional initialization here */ + Fb_Ptr = (uint16_t *)mmap(0, fixed.smem_len, PROT_READ|PROT_WRITE, MAP_SHARED, fb_fd, 0); + if ((int)Fb_Ptr == -1) + { + Log(LFATAL, "Unable to memmap framebuffer (%d)", errno); + Fb_Ptr = NULL; + close(fb_fd); + fb_fd = -1; + return -1; + } + + /* additional setup here */ return 0; } @@ -73,5 +82,10 @@ void Fb_cleanup(void) { /* additional cleanup here */ + memset(Fb_Ptr, 0, local_info.screenbytes); + munmap((void *)Fb_Ptr, local_info.screenbytes); + Fb_Ptr = NULL; + close(fb_fd); + fb_fd = -1; } diff --git a/src/fbinit.h b/src/fbinit.h index 40737f3..a4612d4 100644 --- a/src/fbinit.h +++ b/src/fbinit.h @@ -1,6 +1,31 @@ #ifndef __FBINIT_H_INCLUDED #define __FBINIT_H_INCLUDED +#include + +typedef struct tagFBINFO { + uint32_t width; + uint32_t height; + uint32_t virtual_width; + uint32_t virtual_height; + uint32_t bpp; + uint32_t linebytes; + uint32_t screenbytes; + uint16_t red_offset; + uint16_t red_length; + uint16_t red_mask; + uint16_t green_offset; + uint16_t green_length; + uint16_t green_mask; + uint16_t blue_offset; + uint16_t blue_length; + uint16_t blue_mask; +} FBINFO; +typedef const FBINFO * const PCFBINFO; + +extern PCFBINFO Fb_Info; +extern uint16_t *Fb_Ptr; + extern int Fb_setup(void); extern void Fb_cleanup(void); diff --git a/src/main.c b/src/main.c index f0d546f..afb7cc6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,5 @@ #include +#include #include "gpio.h" #include "log.h" #include "fbinit.h" @@ -9,6 +10,7 @@ int main(int argc, char *argv[]) { int running = 1; MSG msg; + char *tmp; Time_init(); if (Fb_setup() != 0) @@ -21,6 +23,11 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; atexit(Sys_disable_input); + /* temporary drawing here */ + tmp = (char *)Fb_Ptr; + memset(tmp, 0xFF, Fb-Info->screenbytes / 2); + memset(tmp + (Fb-Info->screenbytes / 2), 0x1B, Fb-Info->screenbytes / 2); + Log(LINFO, "System ready."); while (running)