fbset与fb_videomode参数对应计算【转】
转自:http://cnlearn.linksprite.com/?p=7372
<a href="http://cnlearn.linksprite.com/wp-content/uploads/2014/09/2010-01-01-000950_1920x1080_scrot.png"><img class="aligncenter" src="http://cnlearn.linksprite.com/wp-content/uploads/2014/09/2010-01-01-000950_1920x1080_scrot.png" alt="2010-01-01-000950_1920x1080_scrot" /></a> Linux内核的amba lcd控制器使用clcd_panel结构体表示一个LCD屏的硬件参数: /* include/linux/fb.h */
struct fb_videomode {
const char *name; /* optional */
u32 refresh; /* optional */
u32 xres;
u32 yres;
u32 pixclock;
u32 left_margin;
u32 right_margin;
u32 upper_margin;
u32 lower_margin;
u32 hsync_len;
u32 vsync_len;
u32 sync;
u32 vmode;
u32 flag;
};
const char *name; /* optional */
u32 refresh; /* optional */
u32 xres;
u32 yres;
u32 pixclock;
u32 left_margin;
u32 right_margin;
u32 upper_margin;
u32 lower_margin;
u32 hsync_len;
u32 vsync_len;
u32 sync;
u32 vmode;
u32 flag;
};
/* include/linux/amba/clcd.h */
struct clcd_panel {
struct fb_videomode mode;
signed short width; /* width in mm */
signed short height; /* height in mm */
u32 tim2;
u32 tim3;
u32 cntl;
unsigned int bpp:8,
fixedtimings:1,
grayscale:1;
unsigned int connector;
};
struct fb_videomode mode;
signed short width; /* width in mm */
signed short height; /* height in mm */
u32 tim2;
u32 tim3;
u32 cntl;
unsigned int bpp:8,
fixedtimings:1,
grayscale:1;
unsigned int connector;
};
可以看出来,里面很重要的是fb_videomode,先科普一下fb_videomode各个参数的意义:
名称 | 在数据手册中的简称 | 中文名 | 意义 | 备注 |
name | No | 名字 | 液晶屏名字(可选) | No |
refresh | No | 刷新频率 | 刷新频率(内核中很多例子都赋值为60) | No |
xres | No | 行宽 | 每行的像素个数 | No |
yres | No | 屏幕高度 | 屏幕的行数 | No |
pixclock | No | 像素时钟 | 每个像素时钟周期的长度,单位是皮秒(10的负12次方分之1秒) | No |
left_margin | HBP (Horizontal Back Porch) | 水平后沿 | 在每行或每列的象素数据开始输出时要插入的象 素时钟周期数 |
No |
right_margin | HFP (Horizontal Front Porch ) | 水平前沿 | 在每行或每列的象素结束到LCD 行时钟输出脉冲 之间的象素时钟数 |
No |
upper_margin | VBP (Vertical Back Porch) | 垂直后沿 | 在垂直同步周期之后帧开头时的无效行数 | No |
lower_margin | VFP (Vertical Front Porch) | 垂直前沿 | 本帧数据输出结束到下一帧垂直同步周期开始之 前的无效行数 |
No |
hsync_len | HPW (HSYNC plus width) | 行同步脉宽 | 单位:像素时钟周期 | 也有手册简称为HWH(HSYNC width) |
vsync_len | VPW (VSYNC width) | 垂直同步脉宽 | 单位:显示一行的时间th | 也有手册简称为VWH(VSYNC width) |
sync | No | 同步极性设置 | 可以根据需要设置FB_SYNC_HOR_HIGH_ACT(水平同步高电平有效)和FB_SYNC_VERT_HIGH_ACT(垂直同步高电平有效) | No |
vmode | No | No | 在内核中的大多数示例都直接置为FB_VMODE_NONINTERLACED。interlaced的意思是交错[隔行]扫描,电视中使用2:1的交错率, 即每帧分两场,垂直扫描两次,一场扫描奇数行,另一场扫描偶数行。很显然LCD目前不是这种模式。 | No |
flag | No | No | 目前没有看到用法 | No |
说明:
(1)Linux对LCD的抽象是以图像为中心的,而LCD手册则以同步信号为中心,所以内核中的left_margin是指在每一行之前(前面自然对应左边)的空闲周期数,而它对应LCD数据手册中的水平后沿(HBP Horizontal Back Porch),是指在行同步信号之后的空闲周期。参照物不同而已,但是说的是同一个东西。
(2)水平同步信号有时也成为行同步型号,垂直同步信号有人称为场同步信号。
(3)对于LCD的frambuffer抽象模型请参考内核中的文档:Documention/fb/frambuffer.txt。
(4)fb_videomode各个成员的用处是我自己参照内核代码中的include/linux/amba/clcd.h中的clcdfb_decode()函数总结的,不保证护绝对正确。
好了,现在来看个实际的,我先把各个参数的值从内核中打印出来:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
root@ubuntu:~# fbset -a "1920x1080-50" [ 47.631053 ] new_mode.refresh; = 50 [ 47.631056 ] new_mode.xres; = 1920 [ 47.631060 ] new_mode.yres; = 1080 [ 47.631063 ] new_mode.pixclock; = 6734 [ 47.631067 ] new_mode.left_margin; = 148 [ 47.631070 ] new_mode.right_margin;= 528 [ 47.631074 ] new_mode.upper_margin;= 36 [ 47.631077 ] new_mode.lower_margin;= 4 [ 47.631080 ] new_mode.hsync_len; = 44 [ 47.631083 ] new_mode.vsync_len; = 5 [ 47.631086 ] new_mode.sync; = 3 [ 47.631089 ] new_mode.vmode; = 0 [ 47.631093 ] new_mode.flag; = 32 |
在看看fbset的值:
1
2
3
4
5
6
7
8
9
10
11
|
root@ubuntu:~# fbset mode "1920x1080-50" # D: 148.500 MHz, H: 56.250 kHz, V: 50.000 Hz geometry 1920 1080 1920 1629 32 timings 6734 148 528 36 4 44 5 hsync high vsync high accel true rgba 0 / 0 , 0 / 0 , 0 / 0 , 0 / 0 endmode |
下面看看怎么计算的:
pixclock={(xres+left_margin+right_margin+hsync_len) x (yres+upper_margin+lower_margin+vsync_len) x refresh }/1
对应参数看看:
{(1920+148+528+44)x (1080+36 +4+5) x 50}/1
=(2640 x 1125 x 50 )/1
=(2970000×50)/1
=148500000/1
=6.7340067340067340067340067340067e-9 ≈ 6.734
也就是pixclock/1000;
【作者】sky
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
分类:
【lcd驱动】
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
2019-02-15 在代码中获取调用者函数的名字【转】
2019-02-15 手动跟踪函数的调用过程【转】
2019-02-15 用户态使用 glibc/backtrace 追踪函数调用堆栈定位段错误【转】
2017-02-15 Device Tree Usage 【转】
2016-02-15 【笔记】一些linux实用函数技巧【原创】
2016-02-15 创建git标签【转】