16,245
社区成员
发帖
与我相关
我的任务
分享
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <linux/fb.h>
#define WIN0 0
#define WIN1 1
#define WIN2 2
#define WIN3 3
#define WIN4 4
#define WIN_MAX 5
const char * fb_file_path[ WIN_MAX ] = {
/* WIN0 */"/dev/fb3",
/* WIN1 */"/dev/fb4",
/* WIN2 */"/dev/fb0",
/* WIN3 */"/dev/fb1",
/* WIN4 */"/dev/fb2"
};
const int fb_x[ WIN_MAX ] = {
/* WIN0 */500,
/* WIN1 */400,
/* WIN2 */300,
/* WIN3 */200,
/* WIN4 */100
};
const int fb_color[ WIN_MAX ] = {
/* WIN0 */0x10FFFFFF,
/* WIN1 */0x10FF0000,
/* WIN2 */0x1000FF00,
/* WIN3 */0x100000FF,
/* WIN4 */0x10000000,
};
void draw_framebuffer( int win, int fd, int xres, int yres )
{
int i, j;
int *p;
int color;
p = mmap( NULL, xres*yres*4, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0 );
if( !p ){
printf( "mmap failed\n" );
return;
}
/* draw default color with alpha : all pass through*/
for( j = 0; j < yres; j++ ){
for( i = 0; i < xres ; i++ ){
*( p + j * xres + i ) = 0x00FFFFFF;
}
}
/* draw color */
for( j = 0; j < yres; j++ ){
for( i = 0; i < fb_x[win] ; i++ ){
*( p + j * xres + i ) = fb_color[win];
}
}
munmap( p, xres*yres*4 );
}
int main( int argc, char *argv[] )
{
int i;
int ret;
struct fb_var_screeninfo var;
int blank;
int fd[ WIN_MAX ];
/* initial */
memset( fd, -1, sizeof( fd ) );
/* open framebuffer */
for( i=0; i<WIN_MAX; i++ ){
fd[i] = open( fb_file_path[i], O_RDWR );
if( fd[i] < 0 ){
printf( "open %s failed\n", fb_file_path[i] );
goto end;
}
}
printf( "open framebuffer ok\n" );
/* set screen info */
ret = ioctl( fd[WIN2], FBIOGET_VSCREENINFO, &var );
if( ret < 0 ){
printf( "ioctl %s FBIOGET_VSCREENINFO failed\n", fb_file_path[WIN2] );
goto end;
}
var.activate = FB_ACTIVATE_FORCE;
var.yres_virtual = var.yres;
for( i=0; i<WIN_MAX; i++ ){
ret = ioctl( fd[i], FBIOPUT_VSCREENINFO, &var );
if( ret < 0 ){
printf( "ioctl %s FBIOPUT_VSCREENINFO failed\n", fb_file_path[i] );
goto end;
}
}
printf( "set screeninfo ok\n" );
/* draw some color */
for( i=0; i<WIN_MAX; i++ ){
draw_framebuffer( i, fd[i], var.xres, var.yres );
}
printf( "draw color ok\n" );
/* show window */
blank = FB_BLANK_UNBLANK;
for( i=0; i<WIN_MAX; i++ ){
ret = ioctl( fd[i], FBIOBLANK, blank );
if( ret < 0 ){
printf( "ioctl %s FBIOBLANK failed\n", fb_file_path[i] );
goto end;
}
}
printf( "show window ok\n" );
/* wait input */
getchar();
end:
return 0;
}
从这段代码我发现原来手册里面说的这个几个window与fb的对应关系原来不是fb0对应win0的关系。。。具体的对应关系如下:
/* WIN0 */"/dev/fb3",
/* WIN1 */"/dev/fb4",
/* WIN2 */"/dev/fb0",
/* WIN3 */"/dev/fb1",
/* WIN4 */"/dev/fb2"
优先级关系:win4>win3>win2>win1>win0,也就是win4在最上面,win0在最下面
这个例子在我的tiny4412上面显示出了几个色块。说明这几个fb都是可用的。。。
那接下来还是考虑我这个QT的GUI 如何能在显示在视频的上面的问题。。几个fb都可用。。但是为什么我将export QWS_DISPLAY=LinuxFb:/dev/fb1 就无法显示出QT GUI呢。。。奇怪啊。。只有设置成fb0才可以显示出来。。。#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <linux/fb.h>
#define WIN_MAX 5
const char * fb_file_path[5] = {
"/dev/fb0",
"/dev/fb1",
"/dev/fb2",
"/dev/fb3",
"/dev/fb4"
};
int color[5] = {
0x50ffffff,
0x50ff0000,
0x5000ff00,
0x500000ff,
0x50000000,
};
int main(int argc, char *argv[])
{
int i,j,k;
int ret;
struct fb_var_screeninfo var;
int blank;
int fd[5];
int width;
int height;
int *p[5];
/* open framebuffer */
for(i=0; i<WIN_MAX; i++)
{
fd[i] = open(fb_file_path[i], O_RDWR);
if( fd[i] < 0 )
{
printf("open %s failed\n", fb_file_path[i]);
goto end;
}
printf("open %s success:%d\n", fb_file_path[i],fd[i]);
}
ret = ioctl(fd[0], FBIOGET_VSCREENINFO, &var);
if(ret < 0)
{
printf("ioctl %s FBIOGET_VSCREENINFO failed\n", fb_file_path[0]);
goto end;
}
width = var.xres;
height = var.yres;
printf("width:%d,height:%d\n",width, height);
printf("set screeninfo ok\n");
for(i=0; i<WIN_MAX; i++)
{
p[i] = (int *)mmap(NULL, width * height * 4, PROT_READ|PROT_WRITE, MAP_SHARED, fd[i], 0);
if((p[i] == NULL) || (p[i] == -1))
{
printf("the mmap:%d is NULL\n",i);
goto end;
}
}
for(k = 0; k < WIN_MAX; k++)
{
for(i = 0; i < height - (k * 100); i++)
for(j = 0; j < width; j++)
{
p[k][i * width + j] = color[k];
}
printf("draw %d, 0x%08lx\n",k, color[k]);
}
while(1)
{
for(i = 0; i < height; i++)
{
for(j = 0; j < width; j++)
{
p[4][i * width + j] = 0x50ff0000;
}
usleep(1000);
}
for(i = 0; i < height; i++)
{
for(j = 0; j < width; j++)
{
p[4][i * width + j] = 0x00000000;
}
usleep(1000);
}
}
end:
return 0;
}
按照网上那个例子的说法应该是显示几个颜色的色条块。。。但是实际上我这只显示了fb0的颜色。。。其他的都没有出现。。。但是/dev/下面确实是存在5个fb的啊。。为什么其他的都不能在lCD上显示呢。。难道这个fb0在最上面?把其他的都给盖住了?