Display Parameters

本文深入解析了显示系统中的关键概念,如像素时钟(Dotclock)、点时钟(Pixclock)及其计算方法,详细阐述了左、右、上、下边距,水平与垂直同步信号的长度及极性等参数的含义。通过实例计算,帮助读者理解如何根据刷新率计算像素时钟值,以及DPI的计算公式。

从事与显示系统有关的工作时,常接触一些术语和概念,并涉及到像素时钟与点时钟的计算,现总结如下:

1.Dotclock 与 Pixclock

Display Parameters

Sometimes, configuring the properties associated with your display panel might be the only driver changes that you need to make to enable video on your device, so let’s start learning about video drivers by looking at common display parameters. We will assume that the associated driver conforms to the frame buffer interface, and use the fbset utility to obtain display characteristics:

$ fbset
mode "1024x768-60"
    # D: 65.003 MHz, H: 48.365 kHz, V: 60.006 Hz
    geometry 1024 768 1024 768 8
    timings 15384 168 16 30 2 136 6
    hsync high
    vsync high
    rgba 8/0,8/0,8/0,0/0
endmode

The D: value in the output stands for the dotclock, which is the speed at which the video hardware draws pixels on the display. The value of 65.003MHz in the preceding output means that it’ll take (1/65.003*1000000) or about 15,384 picoseconds for the video controller to draw a single pixel. This duration is called the pixclock and is shown as the first numeric parameter in the line starting with timings. The numbers against “geometry” announce that the visible and virtual resolutions are 1024x768 (SVGA) and that the bits required to store information pertaining to a pixel is 8.

The H: value specifies the horizontal scan rate, which is the number of horizontal display lines scanned by the video hardware in one second. This is the inverse of the pixclock times the X-resolution. The V: value is the rate at which the entire display is refreshed. This is the inverse of the pixclock times the visible X-resolution times the visible Y-resolution, which is around 60Hz in this example. In other words, the LCD is refreshed 60 times in a second.

Video controllers issue a horizontal sync (HSYNC) pulse at the end of each line and a vertical sync (VSYNC) pulse after each display frame. The durations of HSYNC (in terms of pixels) and VSYNC (in terms of pixel lines) are shown as the last two parameters in the line starting with “timings.” The larger your display, the bigger the likely values of HSYNC and VSYNC. The four numbers before the HSYNC duration in the timings line announce the length of the right display margin (or horizontal front porch), left margin (or horizontal back porch), lower margin (or vertical front porch), and upper margin (or vertical back porch), respectively. Documentation/fb/framebuffer.txt and the man page of fb.modes pictorially show these parameters.

To tie these parameters together, let’s calculate the pixclock value for a given refresh rate, which is 60.006Hz in our example:

dotclock = (X-resolution + left margin + right margin
           + HSYNC length) * (Y-resolution + upper margin
           + lower margin + VSYNC length) * refresh rate
         = (1024 + 168 + 16 + 136) * (768 + 30 + 2 + 6) * 60.006
         = 65.003 MHz
pixclock = 1e12/dotclock
         = 15384 picoseconds (which matches with the fbset output
                              above)

2.术语解析

  • Left Margin:行切换,从同步到绘图之间的延迟,表示从水平同步信号开始到一行的有效数据开始之间的 VCLK 的个数,等同于 HBP(Horizontal Back Porch);
  • Right Margin:行切换,从绘图到同步之间的延迟,表示一行的有效数据结束到下一个水平同步信号开始之间的 VCLK 的个数,等同于 HFP(Horizontal Front Porch, Horizontal Sync Offset);
  • Upper Margin:帧切换,从同步到绘图之间的延迟,表示在一帧图像开始时,垂直同步信号以后的无效的行数,等同于 VBP(Vertical Back Porch);
  • Lower Margin:帧切换,从绘图到同步之间的延迟,表示在一帧图像结束后,垂直同步信号以前的无效的行数,等同于 VFB(Vertical Front Porch, Vertical Sync Offset);
  • HSYNC Len:水平同步的长度,表示水平同步信号的宽度,用 VCLK 计算,等同于 HSPW(Horizontal Sync Pulse Width, Horizontal Sync Pulse, XPULSE);
  • VSYNC Len:垂直同步的长度,表示垂直同步脉冲的宽度,用行数计算,等同于 VSPW(Vertical Sync Pulse Width, Vertical Sync Pulse, YPULSE);
  • HSYNC POL:水平脉冲极性;
  • VSYNC POL:垂直脉冲极性。

可以用以下三张图来表示:

可以用以下两张图来表示:

TFT 屏工作时序
Active Front Sync Back

+----------+---------------------------------------------+----------+-------+
|          |                ↑                            |          |       |
|          |                |Upper Margin                |          |       |
|          |                ↓                            |          |       |
+----------###############################################----------+-------+
|          #                ↑                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|   Left   #                |                            #  Right   | HSYNC |
|  Margin  #                |       X-Res                #  Margin  |  Len  |
|<-------->#<---------------+--------------------------->#<-------->|<----->|
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |Y-Res                       #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                |                            #          |       |
|          #                ↓                            #          |       |
+----------###############################################----------+-------+
|          |                ↑                            |          |       |
|          |                |Lower Margin                |          |       |
|          |                ↓                            |          |       |
+----------+---------------------------------------------+----------+-------+
|          |                ↑                            |          |       |
|          |                |VSYNC Len                   |          |       |
|          |                ↓                            |          |       |
+----------+---------------------------------------------+----------+-------+

pixclock = 1e12/dotclock,其中 x1e12 是为了将时间单位统一为皮秒(picoseconds)。

  • Horizontal Active:X Resolution;
  • Horizontal Blanking Interval:HFP + HSPW + HBP;
  • Vertical Active:Y Resolution;
  • Vertical Blanking Interval:VFB + VSPW + VBP。

LCD提供的外部接口信号:

  • VSYNC/VFRAME/STV:垂直同步信号(TFT)/帧同步信号(STN)/SEC TFT 信号;
  • HSYNC/VLINE/CPV:水平同步信号(TFT)/行同步脉冲信号(STN)/SEC TFT 信号;
  • VCLK/LCD_HCLK:象素时钟信号(TFT/STN)/SEC TFT 信号;
  • VD[23:0]:LCD 像素数据输出端口(TFT/STN/SEC TFT);
  • VDEN/VM/TP:数据使能信号(TFT)/LCD 驱动交流偏置信号(STN)/SEC TFT 信号;
  • LEND/STH:行结束信号(TFT)/SEC TFT 信号;
  • LCD_LPCOE:SEC TFT OE 信号;
  • LCD_LPCREV:SEC TFT REV 信号;
  • LCD_LPCREVB:SEC TFT REVB 信号。

3.DPI 的计算

sqrt(水平分分辨率^2+垂直分辨率^2)/屏幕尺寸

例如,5 英寸,分辨率为 1920x1080 的屏幕,其 DPI 为:

DPI=sqrt(1920^2+1080^2)/5
<think>嗯,用户问的是如何将读取二进制文件后的Basic Display Parameters & Features字段转为可读字符。我需要先理解用户的具体需求。可能他们处理的是某种二进制文件,比如显示器EDID数据或者类似的硬件信息结构。EDID确实包含这样的字段,所以用户可能在处理这类数据。 首先,用户可能已经读取了二进制数据,现在需要解析特定部分。我需要考虑二进制数据的结构。通常,像EDID这样的标准格式会有固定的偏移和长度。例如,Basic Display Parameters可能包括分辨率、屏幕尺寸等,而Features可能包含支持的功能如DPMS待机模式等。 接下来是如何将这些二进制数据转换为可读的信息。用户可能需要知道如何找到正确的偏移量,然后解析每个字节的各个位或字段。例如,EDID的第20字节开始可能有这些参数。每个bit代表不同的特性,比如bit0是否支持待机,bit1是否支持挂起等。 需要告诉用户步骤:首先定位字段的位置,然后按位解析每个标志,然后将这些标志转换为对应的文本描述。例如,如果某一位是1,表示支持某个功能,否则不支持。可能需要使用位掩码和移位操作来检查各个位。 另外,用户可能需要示例代码来说明这个过程。用Python的话,可以用struct模块来解包二进制数据,或者直接通过索引访问字节。然后使用按位运算来判断各个位的值,并映射到对应的描述。 还要注意不同标准或格式可能有不同的结构,用户可能需要查阅相关文档来确定具体的偏移和位定义。提醒用户根据实际情况调整代码中的偏移量和解析逻辑。 最后,确保用户明白整个过程:确定结构、提取字节、位操作、映射到可读字符串。如果有具体的标准,比如EDID,可以建议参考相关标准文档来确认字段布局。</think>将二进制文件中的 **Basic Display Parameters & Features** 这类字段转换为可读字符,通常需要以下步骤: --- ### **1. 理解二进制文件格式** 首先需要明确二进制文件的**结构定义**(例如:协议文档、数据规范)。例如: - **EDID(显示器扩展标识数据)**:`Basic Display Parameters & Features` 是 EDID 中的特定字段,记录了显示器的基础参数(分辨率、屏幕尺寸等)和功能特性(是否支持 DPMS 节能模式等)。 - **自定义二进制文件**:需根据设计文档确定字段的偏移量、数据类型(如字节、整数、位掩码)等。 --- ### **2. 定位字段位置** - 通过文档或规范,确定目标字段在二进制数据中的**偏移量(Offset)**和**长度(Length)**。 - 例如:EDID 的 `Basic Display Parameters` 可能从第 20 字节开始,`Features` 可能是一个 1 字节的位掩码。 --- ### **3. 读取二进制数据** 使用编程语言(如 Python、C++)读取二进制文件,并提取目标字段的字节数据: ```python with open("file.bin", "rb") as f: data = f.read() # 假设 Features 字段位于第 10 字节,长度为 1 字节 features_byte = data[9] # 索引从 0 开始 ``` --- ### **4. 解析位掩码(Bitmask)** 许多 "Features" 字段使用 **位掩码(Bitmask)** 表示多个布尔特性。例如: - 一个字节(8 bits)可以表示 8 个独立的功能是否启用。 - 需要根据文档解析每一位的含义: ```python # 示例:假设第 0 位表示 "支持待机模式",第 1 位表示 "支持挂起模式" features = { "Standby Mode": (features_byte & 0b00000001) != 0, "Suspend Mode": (features_byte & 0b00000010) != 0, # 其他位同理... } ``` --- ### **5. 数值字段转换** 对于非位掩码的数值字段(如分辨率、尺寸),需根据规范转换: - **整数类型**:直接转换为十进制(如 `int.from_bytes()`)。 - **ASCII 字符**:直接解码(如 `bytes.decode("ascii")`)。 - **枚举值**:映射到预定义字符串(如 `0x01 -> "sRGB"`)。 --- ### **6. 完整示例(Python EDID 解析片段)** 假设解析 EDID 的 `Features` 字段(位于第 24 字节): ```python # 读取 EDID 文件 with open("edid.bin", "rb") as f: edid = f.read() features_byte = edid[24] # 解析 Features 字节的各个位 feature_flags = { "DPMS Standby": (features_byte & 0x80) != 0, # 第7位 "DPMS Suspend": (features_byte & 0x40) != 0, # 第6位 "DPMS Active-Off": (features_byte & 0x20) != 0, # 第5位 "Display Type": "RGB" if (features_byte & 0x08) else "Non-RGB", # 第3位 # 其他位根据文档添加... } # 输出可读结果 for feature, value in feature_flags.items(): print(f"{feature}: {value}") ``` --- ### **7. 注意事项** - **字节序(Endianness)**:注意大端序(Big-Endian)或小端序(Little-Endian)。 - **数据对齐**:某些字段可能跨越多个字节。 - **文档依赖**:必须参考对应二进制格式的官方文档。 如果需要更具体的帮助,请提供目标二进制文件的格式定义!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lionchan187

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值