92 lines
2.1 KiB
C
92 lines
2.1 KiB
C
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/mman.h>
|
|
#include <linux/fb.h>
|
|
#include "log.h"
|
|
#include "fbinit.h"
|
|
|
|
static int fb_fd = -1;
|
|
|
|
static FBINFO local_info;
|
|
PCFBINFO Fb_Info = &local_info;
|
|
|
|
uint16_t *Fb_Ptr = NULL;
|
|
|
|
inline static unsigned makemask(unsigned offset, unsigned length)
|
|
{
|
|
return ((1 << length) - 1) << offset;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
local_info.linebytes = fixed.line_length;
|
|
local_info.screenbytes = fixed.smem_len;
|
|
|
|
if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var))
|
|
{
|
|
Log(LFATAL, "Could not get variable screen info (%d)", errno);
|
|
return -1;
|
|
}
|
|
|
|
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);
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|