1、展示问题
设备树配置如下
应用程序如下
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
int main(int argc, char* argv[])
{
struct fb_var_screeninfo fb_var;
struct fb_fix_screeninfo fb_fix;
int fd;
fd = open("/dev/fb0", O_RDWR);
ioctl(fd, FBIOGET_FSCREENINFO, &fb_fix);//固定信息
ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);//可变信息
//ioctl(fd, FBIOPUT_VSCREENINFO, &fb_var);
printf("分辨率:%d x %d\n", fb_var.xres, fb_var.yres);
printf("色深:%d\n", fb_var.bits_per_pixel);
printf("每行占用字节:%d\n", fb_fix.line_length);
printf("像素格式: R<%d %d> G<%d %d> B<%d %d>\n",
fb_var.red.offset, fb_var.red.length,
fb_var.green.offset, fb_var.green.length,
fb_var.blue.offset, fb_var.blue.length);
close(fd);
exit(0);//正常退出程序
return 0;
}
打印输出效果
2、问题分析
在确认了应用程序和设备树没有出错的情况下,初步认为是驱动导致的。
查找源码
在Vscode中搜索bits_per_pixel,发现在linux源码的drivers/video/fbdev/mxsfb.c中有用到bits_per_pixel。如下图
图中代码455行,只要设备树中的bits_per_pixel不是32也不是16,就令bits_per_pixel=32。
3、小结:由于我设备树中bits_per_pixel=24,不等于32,也不等于16,所以bits_per_pixel=32。
4、补充
从mxsfb.c的458行开始,是判断RGB为565、888的源码,从中可以得出结果:
bits-per-pixel
:RGB565
值为<16>
,RGB888/666
值为<32>
。