Revision: 57666
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 5, 2012 01:00 by akiko
Initial Code
// written by Boris Posavec (akiko/agt), 2012.
// this is just a snippet, not compilable without some other files from the project.
// demonstrates how to open, mmap, and communicate with /dev/fbN devices
// on OMAP.
#include "sys/omapfb.h"
int fb0_fd = 0;
int fb1_fd = 0;
#define TS_DEV0 "/dev/fb0"
#define TS_DEV1 "/dev/fb1"
struct fb_fix_screeninfo fixinfo;
struct fb_var_screeninfo varinfo;
struct omapfb_mem_info meminfo;
struct omapfb_plane_info planeinfo;
enum fbdev_t
{
FBDEV_0,
FBDEV_1,
};
int __read_varinfo(fbdev_t dev)
{
int fb = (dev == FBDEV_0 ? fb0_fd : fb1_fd);
if (ioctl(fb, FBIOGET_VSCREENINFO, &varinfo) == -1)
{
LOG("error: %s\n", strerror(errno));
return -1;
}
return 0;
}
int __write_varinfo(fbdev_t dev)
{
int fb = (dev == FBDEV_0 ? fb0_fd : fb1_fd);
if (ioctl(fb, FBIOPUT_VSCREENINFO, &varinfo) == -1)
{
LOG("error: %s\n", strerror(errno));
return -1;
}
return 0;
}
bool fb_init()
{
int res;
fb0_fd = open(TS_DEV, O_RDWR);
if (fb0_fd == -1)
{
LOG("Error: cannot open %s \n", TS_DEV);
return false;
}
res = ioctl(fb0_fd, OMAPFB_QUERY_MEM, &meminfo);
if (res != 0)
{
LOG("Error: cannot query omap mem for %s, %d\n", TS_DEV, res);
return false;
}
LOG("fb memsize: %d\n", meminfo.size);
// mmap it
fb0 = (unsigned char*) mmap(NULL, meminfo.size, PROT_WRITE, MAP_SHARED, fb0_fd, 0);
if (fb0 == MAP_FAILED)
{
LOG("Error: cannot map %s\n", TS_DEV0);
return false;
}
LOG("%s mapped OK.\n", TS_DEV1);
// Setup overlay.
fb1_fd = open(TS_DEV1, O_RDWR);
if (fb1_fd == -1)
{
LOG("Error: cannot open %s \n", TS_DEV1);
return false;
}
res = ioctl(fb1_fd, OMAPFB_QUERY_MEM, &meminfo);
if (res != 0)
{
LOG("Error: cannot query omap mem for %s, %d\n", TS_DEV1, res);
return false;
}
LOG("fb memsize: %d\n", meminfo.size);
// mmap it
fb1 = (unsigned char*) mmap(NULL, meminfo.size, PROT_WRITE, MAP_SHARED, fb1_fd, 0);
if (fb1 == MAP_FAILED)
{
LOG("Error: cannot map %s\n", TS_DEV1);
return false;
}
LOG("%s mapped OK.\n", TS_DEV1);
// Enable overlay
ioctl(fb1_fd, OMAPFB_QUERY_PLANE, &planeinfo);
fprintf(stderr, "x, y, w, h, chnout, enabled: %d %d %d %d %d %d\n", planeinfo.pos_x, planeinfo.pos_y, planeinfo.out_width, planeinfo.out_height, planeinfo.channel_out, planeinfo.enabled);
planeinfo.enabled = 1;
ioctl(fb1_fd, OMAPFB_SETUP_PLANE, &planeinfo);
// Enable overlaying, set white as chroma key color
execute_shell_cmd("echo \"1\" > /sys/devices/platform/omapdss/manager0/alpha_blending_enabled");
execute_shell_cmd("echo \"1\" > /sys/devices/platform/omapdss/manager0/trans_key_enabled");
execute_shell_cmd("echo \"0xf81f\" > /sys/devices/platform/omapdss/manager0/trans_key_value");
// Rotate 180deg
execute_shell_cmd("echo \"1\" > /sys/class/graphics/fb0/rotate"); // gui/input
execute_shell_cmd("echo \"3\" > /sys/class/graphics/fb1/rotate"); // camera
// get current xres, yres
__read_varinfo(FBDEV_0);
xres = varinfo.xres;
yres = varinfo.yres;
bpp = varinfo.bits_per_pixel;
return true;
}
Initial URL
dev.modmancer.com
Initial Description
demonstrates how to open, mmap, and communicate with /dev/fbN devices on OMAP. won't compile such as, but it's enough to give an insight in how-to.
Initial Title
/dev/fb poking on OMAP
Initial Tags
Initial Language
C