Rockchip RK3399 - DRM crtc基础知识

一、LCD硬件原理

1.1 CRT介绍

CRT是阴极射线管(Cathode Ray Tube)的缩写,它是一种使用电子束在荧光屏上创建图像的显示设备。CRT显示器在过去很长一段时间内是主流的显示技术,现已被液晶显示屏或其他新兴技术所替代。

CRT显示器中,扫描电子束从左到右、从上到下移动,照亮屏幕上的荧光点,从而创建图像。电子束每秒多次扫描整个屏幕,产生闪烁效果,需要与正在显示的内容同步。

随着LCDLEDOLED等新型显示技术的出现,底层原理已经发生了变化。这些显示器不再使用扫描电子束,而是使用可以单独控制发光或阻挡光的像素矩阵。这使得图像更加清晰,刷新率更快,能源效率也得到了提高。

然而,刷新显示的基本概念并没有发生很大变化。显示内容仍然通过向每个像素发送信号来控制其亮度和颜色来进行更新。这些信号由显示控制器根据输入视频信号生成,并且它们确定屏幕上显示的内容。

1.2 LCD示意图

下图是LCD示意图,里面的每个点就是一个像素点。它里面有一个电子枪,一边移动,一边发出各种颜色的光。用动态图表示如下:

img

电子枪是如何移动的?

  • 有一条Pixel Clock时钟线与LCD相连,每发出一次Pixel Clock,电子枪就移动一个像素。

颜色如何确定?

  • 由连接LCD的三组线RGB三原色混合而成:R(Red)、G(Green)、B(Blue)确定。

电子枪如何得知应跳到下一行?

  • 有一条HSYNC信号线与LCD相连,每发出一次脉冲(高低电平),电子枪就跳到下一行,该信号叫做行同步信号。

电子枪如何得知应跳到原点?

  • 有一条VSYNC信号线与LCD相连,每发出一次脉冲(高低电平),电子枪就跳到原点,该信号叫做帧同步信号。

RGB线上的数据从何而来?

  • 内存里面划分一块显存(FrameBuffer),里面存放了要显示的数据,LCD控制器(比如RK3399VOP)从里面将数据读出来,通过显示接口(比如mipilvdshdmiedp、``dp)传给电子枪,电子枪再依次打到显示屏上。
img

因此要想在显示设备上显示图像,至少需要3个信号:

  • Pixel Clock:时钟信号,在每个时钟周期更新屏幕上一个像素;
  • HSYNC:水平同步信号,引脚每发出一个脉冲,表示一行的数据开始发送;
  • VSYNC:垂直同步信号,引脚每发出一个脉冲,表示一帧的数据开始发送。
1.3 时序参数

在上图中我们发现除了Pixel ClockHSYNCVSYNC信号外,还包含了大量的时序参数,这里我们一一介绍:

  • HBPD(hback porch):行同步信号的后肩,单位为1个Pixel Clock时钟周期;
  • HFPD(hfront porch):行同步信号的前肩,单位为1个Pixel Clock时钟周期;
  • HSPW(hsync pulse):行同步信号的脉宽,单位为1个Pixel Clock时钟周期;
  • HOZVAL(hdisplay):LCD的水平宽度;
  • VBPD(vback porch):帧同步信号的后肩,单位为1个HSYNC时钟周期;
  • VFPD(vfront porch):帧同步信号的前肩,单位为1个HSYNC时钟周期;
  • VSPW(vsync pulse):帧同步信号的脉宽,单位为1个HSYNC时钟周期;
  • LINEVAL (vdisplay):LCD的垂直宽度;

如果这部分内容看不到,可以参考我之前写的这篇文章:Mini2440裸机开发之LCD基础。

二、CRTC核心数据结构

DRM框架中,CRTCFramebuffer中读取待显示的图像,并按照响应的格式输出给encoder,其主要承担的作用为:

  • 配置适合显示的显示模式、分辨率、刷新率等参数,并输出相应的时序;
  • 扫描Framebuffer发送到一个或多个显示器;
  • 更新Framebuffer

概括下就是,对显示器进行扫描,产生时序信号的模块、负责帧切换、电源控制、色彩调整等等。

2.1 struct drm_crtc

linux内核使用struct drm_crtc来表示一个CRTC控制器,包括显示模式、分辨率、刷新率等参数。定义在include/drm/drm_crtc.h

/*** struct drm_crtc - central CRTC control structure** Each CRTC may have one or more connectors associated with it.  This structure* allows the CRTC to be controlled.*/
struct drm_crtc {/** @dev: parent DRM device */struct drm_device *dev;/** @port: OF node used by drm_of_find_possible_crtcs(). */struct device_node *port;/*** @head:** List of all CRTCs on @dev, linked from &drm_mode_config.crtc_list.* Invariant over the lifetime of @dev and therefore does not need* locking.*/struct list_head head;/** @name: human readable name, can be overwritten by the driver */char *name;/*** @mutex:** This provides a read lock for the overall CRTC state (mode, dpms* state, ...) and a write lock for everything which can be update* without a full modeset (fb, cursor data, CRTC properties ...). A full* modeset also need to grab &drm_mode_config.connection_mutex.** For atomic drivers specifically this protects @state.*/struct drm_modeset_lock mutex;/** @base: base KMS object for ID tracking etc. */struct drm_mode_object base;/*** @primary:* Primary plane for this CRTC. Note that this is only* relevant for legacy IOCTL, it specifies the plane implicitly used by* the SETCRTC and PAGE_FLIP IOCTLs. It does not have any significance* beyond that.*/struct drm_plane *primary;/*** @cursor:* Cursor plane for this CRTC. Note that this is only relevant for* legacy IOCTL, it specifies the plane implicitly used by the SETCURSOR* and SETCURSOR2 IOCTLs. It does not have any significance* beyond that.*/struct drm_plane *cursor;/*** @index: Position inside the mode_config.list, can be used as an array* index. It is invariant over the lifetime of the CRTC.*/unsigned index;/*** @cursor_x: Current x position of the cursor, used for universal* cursor planes because the SETCURSOR IOCTL only can update the* framebuffer without supplying the coordinates. Drivers should not use* this directly, atomic drivers should look at &drm_plane_state.crtc_x* of the cursor plane instead.*/int cursor_x;/*** @cursor_y: Current y position of the cursor, used for universal* cursor planes because the SETCURSOR IOCTL only can update the* framebuffer without supplying the coordinates. Drivers should not use* this directly, atomic drivers should look at &drm_plane_state.crtc_y* of the cursor plane instead.*/int cursor_y;/*** @enabled:** Is this CRTC enabled? Should only be used by legacy drivers, atomic* drivers should instead consult &drm_crtc_state.enable and* &drm_crtc_state.active. Atomic drivers can update this by calling* drm_atomic_helper_update_legacy_modeset_state().*/bool enabled;/*** @mode:** Current mode timings. Should only be used by legacy drivers, atomic* drivers should instead consult &drm_crtc_state.mode. Atomic drivers* can update this by calling* drm_atomic_helper_update_legacy_modeset_state().*/struct drm_display_mode mode;/*** @hwmode:** Programmed mode in hw, after adjustments for encoders, crtc, panel* scaling etc. Should only be used by legacy drivers, for high* precision vblank timestamps in* drm_crtc_vblank_helper_get_vblank_timestamp().** Note that atomic drivers should not use this, but instead use* &drm_crtc_state.adjusted_mode. And for high-precision timestamps* drm_crtc_vblank_helper_get_vblank_timestamp() used* &drm_vblank_crtc.hwmode,* which is filled out by calling drm_calc_timestamping_constants().*/struct drm_display_mode hwmode;/*** @x:* x position on screen. Should only be used by legacy drivers, atomic* drivers should look at &drm_plane_state.crtc_x of the primary plane* instead. Updated by calling* drm_atomic_helper_update_legacy_modeset_state().*/int x;/*** @y:* y position on screen. Should only be used by legacy drivers, atomic* drivers should look at &drm_plane_state.crtc_y of the primary plane* instead. Updated by calling* drm_atomic_helper_update_legacy_modeset_state().*/int y;/** @funcs: CRTC control functions */const struct drm_crtc_funcs *funcs;/*** @gamma_size: Size of legacy gamma ramp reported to userspace. Set up* by calling drm_mode_crtc_set_gamma_size().** Note that atomic drivers need to instead use* &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().*/uint32_t gamma_size;/*** @gamma_store: Gamma ramp values used by the legacy SETGAMMA and* GETGAMMA IOCTls. Set up by calling drm_mode_crtc_set_gamma_size().** Note that atomic drivers need to instead use* &drm_crtc_state.gamma_lut. See drm_crtc_enable_color_mgmt().*/uint16_t *gamma_store;/** @helper_private: mid-layer private data */const struct drm_crtc_helper_funcs *helper_private;/** @properties: property tracking for this CRTC */struct drm_object_properties properties;/*** @scaling_filter_property: property to apply a particular filter while* scaling.*/struct drm_property *scaling_filter_property;/*** @state:** Current atomic state for this CRTC.** This is protected by @mutex. Note that nonblocking atomic commits* access the current CRTC state without taking locks. Either by going* through the &struct drm_atomic_state pointers, see* for_each_oldnew_crtc_in_state(), for_each_old_crtc_in_state() and* for_each_new_crtc_in_state(). Or through careful ordering of atomic* commit operations as implemented in the atomic helpers, see* &struct drm_crtc_commit.*/struct drm_crtc_state *state;/*** @commit_list:** List of &drm_crtc_commit structures tracking pending commits.* Protected by @commit_lock. This list holds its own full reference,* as does the ongoing commit.** "Note that the commit for a state change is also tracked in* &drm_crtc_state.commit. For accessing the immediately preceding* commit in an atomic update it is recommended to just use that* pointer in the old CRTC state, since accessing that doesn't need* any locking or list-walking. @commit_list should only be used to* stall for framebuffer cleanup that's signalled through* &drm_crtc_commit.cleanup_done."*/struct list_head commit_list;/*** @commit_lock:** Spinlock to protect @commit_list.*/spinlock_t commit_lock;/*** @debugfs_entry:** Debugfs directory for this CRTC.*/struct dentry *debugfs_entry;/*** @crc:** Configuration settings of CRC capture.*/struct drm_crtc_crc crc;/*** @fence_context:** timeline context used for fence operations.*/unsigned int fence_context;/*** @fence_lock:** spinlock to protect the fences in the fence_context.*/spinlock_t fence_lock;/*** @fence_seqno:** Seqno variable used as monotonic counter for the fences* created on the CRTC's timeline.*/unsigned long fence_seqno;/*** @timeline_name:** The name of the CRTC's fence timeline.*/char timeline_name[32];/*** @self_refresh_data: Holds the state for the self refresh helpers** Initialized via drm_self_refresh_helper_init().*/struct drm_self_refresh_data *self_refresh_data;
};

该结构体包含以下成员变量:

  • dev:该CRTC所属的DRM设备;
  • port:设备节点,被drm_of_find_possible_crtcs()使用;
  • head:链表节点,用于将当前节点添加到&drm_mode_config.crtc_list链表;
  • name:名称,可以被驱动程序覆盖;
  • mutex:用于保护CRTC状态的互斥锁;
  • basestruct drm_mode_object
  • primary:与该CRTC相关的primary plane
  • cursor:与该CRTC相关的cursor plane
  • index:在mode_config.list中的位置,可以用作数组索引;
  • cursor_x:光标的x坐标;
  • cursor_y:光标的y坐标;
  • enabled:指示该CRTC是否已启用;
  • mode:当前模式时序信息;
  • hwmode:硬件中编程的模式;
  • x:在屏幕上的x坐标;
  • y:在屏幕上的y坐标;
  • funcsCRTC控制函数;
  • gamma_size:报告给用户空间的legacy gamma ramp大小;
  • gamma_storelegacy gamma values数据存储区域;
  • helper_private:中间层私有数据;
  • properties:跟踪该CRTC的属性;
  • scaling_filter_property:应用于缩放时的特定滤镜的属性;
  • state:当前CRTC的原子状态;
  • commit_list:跟踪挂起提交的列表;
  • commit_lock:保护commit_list的自旋锁;
  • debugfs_entry:用于调试的目录条目;
  • crcCRC捕获的配置设置;
  • fence_context:用于围栏操作的时间线上下文;
  • fence_lock:保护时间线上的围栏的自旋锁;
  • fence_seqno:用作CRTC时间线上创建的围栏的单调计数器;
  • timeline_nameCRTC时间线的名称;
  • self_refresh_data:保存自刷新辅助程序状态的数据;
2.1.1 struct drm_display_mode

struct drm_display_mode用于表示显示模式,包含了显示的何种时序参数。定义在include/drm/drm_modes.h

/*** struct drm_display_mode - DRM kernel-internal display mode structure* @hdisplay: horizontal display size* @hsync_start: horizontal sync start* @hsync_end: horizontal sync end* @htotal: horizontal total size* @hskew: horizontal skew?!* @vdisplay: vertical display size* @vsync_start: vertical sync start* @vsync_end: vertical sync end* @vtotal: vertical total size* @vscan: vertical scan?!* @crtc_hdisplay: hardware mode horizontal display size* @crtc_hblank_start: hardware mode horizontal blank start* @crtc_hblank_end: hardware mode horizontal blank end* @crtc_hsync_start: hardware mode horizontal sync start* @crtc_hsync_end: hardware mode horizontal sync end* @crtc_htotal: hardware mode horizontal total size* @crtc_hskew: hardware mode horizontal skew?!* @crtc_vdisplay: hardware mode vertical display size* @crtc_vblank_start: hardware mode vertical blank start* @crtc_vblank_end: hardware mode vertical blank end* @crtc_vsync_start: hardware mode vertical sync start* @crtc_vsync_end: hardware mode vertical sync end* @crtc_vtotal: hardware mode vertical total size** This is the kernel API display mode information structure. For the* user-space version see struct drm_mode_modeinfo.** 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/118097.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

laravel 中 npm run 同时执行多个命令

在使用laravel 启动项目时 经常需要同时运行两个命令。 1.前端既是 npm run dev 2.后端php则是 php artisan serve 可以安装 使用 concurrently 进行并行启动 concurrently - npm npm install concurrently --save 之后修改 package.json 在 scripts 中增加 (多条…

算法|每日一题|掷骰子等于目标和的方法数|动态规划

1155.掷骰子等于目标和的方法数 原题地址: 力扣每日一题:掷骰子等于目标和的方法数 这里有 n 个一样的骰子,每个骰子上都有 k 个面,分别标号为 1 到 k 。 给定三个整数 n , k 和 target ,返回可能的方式(从总共 kn 种…

useLayoutEffect和useEffect的区别

使用方式 这两个函数的使用方式其实非常简单,他们都接受一个函数一个数组,只有在数组里面的值改变的情况下才会再次执行 effect。所以对于使用方式我就不过多介绍了,不清楚的可以先参考官网 。 差异 useEffect 是异步执行的,而…

一招解决“请在微信客户端中打开链接”

一招解决“请在微信客户端中打开链接”-遇见你与你分享 在浏览器访问网站,却提示“请在微信客户端打开链接”。虽然这个情况你可能从未遇到过,但对于爱折腾的小伙伴,确是一道拦路虎 其实解决办法很简单,就是新建一个UA&#xff1…

ubuntu vbox 5.2 资源 virtualbox-dkms

各种 linux 包 https://pkgs.org/search/?qpython3.6 配置 python 默认版本 查看已安装python $ u82:~/Py_demo$ ls /usr/bin/python* /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.8设置默认版本 $ u82:~/Py_demo$ sudo update-alternatives…

产品使用说明书小程序开发制作方案

使用说明书小程序定位为一个用户友好、易于操作的指南工具。它旨在为用户提供清晰、简洁的设备使用说明,帮助他们更好地理解和使用各种智能设备。 一、使用说明书小程序可以在以下场景中使用: 购买新设备后,用户可以通过小程序快速了解设备的…

Ubuntu 22.04配置/etc/rc.local开机自启文件

1.查看系统版本 rootbogon-virtual-machine:~# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04 LTS Release: 22.04 Codename: jammy rootbogon-virtual-machine:~ 2. 解决 /etc/rc.local 开机启动问题 看rc-loc…

BP神经网络

BP神经网络 B P BP BP神经网络1.激活函数常用的激活函数 2.神经网络结构符号约定 3.损失函数回归问题分类问题 4.反向传播求解梯度矩阵梯度下降法反向传播公式推导(四个基础等式)等式一 输出层误差等式二 隐藏层误差等式三 参数变化率等式四 参数更新 反…

linux重置root密码

重启Linux系统主机并出现引导界面时,按下键盘上的e键进入内核编辑界面 然后再lvrhel/swap 后面加上 rd.break 然后按下ctrlx组合键运行修改后的内核程序,大约30s过后,系统会进入紧急救援模式 然后依次输入以下命令: mount -o remount,rw …

UI 自动化测试框架:PO模式+数据驱动

1. PO 设计模式简介 什么是 PO 模式? PO(PageObject)设计模式将某个页面的所有元素对象定位和对元素对象的操作封装成一个 Page 类,并以页面为单位来写测试用例,实现页面对象和测试用例的分离。 PO 模式的设计思想与…

进阶课4——随机森林

1.定义 随机森林是一种集成学习方法,它利用多棵树对样本进行训练并预测。 随机森林指的是利用多棵树对样本进行训练并预测的一种分类器,每棵树都由随机选择的一部分特征进行训练和构建。通过多棵树的集成,可以增加模型的多样性和泛化能力。…

windows安装mysql-8.0.35

打开cmd(以管理员身份运行),切换到mysql下的bin目录 mysqld --initialize 执行完毕之后,在data目录下会生成很多文件。 打开cmd(以管理员身份运行),切换到mysql下的bin目录,如果刚才的cmd没有关闭,可以继续mysqld -…

C语言汇总

汇总一(linux环境) /bin :bin是二进制(binary)英文缩写。 /boot:存放的都是系统启动时要用到的程序。 /dev:包含了所有Linux系统中使用的外部设备。 /etc:存放了系统管理时要用到的…

【Android】MQTT

目录 MQTT 协议简介应用场景优点缺点 部署服务端下载安装包启动服务器 搭建客户端下载SDK添加依赖配置MQTT服务和权限建立连接订阅主题发布消息取消订阅断开连接 MQTT客户端工具最终效果实现传感器数据采集与监测功能思路 MQTT 协议 简介 MQTT(Message Queuing Te…

Centos7卸载minio

如果是按照上一篇文章安装的minio 1.停止minio pkill minio2.删除相关配置文件(在/usr/local目录下执行) rm -rf minio 如果配置了开机自启 1.取消注册minio服务 chkconfig --del startMinio.sh2.禁用开机自启动 chkconfig startMinio.sh off3.删除启动脚本 rm /etc/rc…

Windows Server扩展卷变灰怎么办?

当Windows Server中的某一个分区,特别是系统(C)分区磁盘空间不足时,您可能需要使用内置磁盘管理工具的“扩展卷”功能扩展分区了。但不幸的是,当您尝试扩展C盘驱动器时,很有可能会出现Windows Server扩展卷…

Android底层摸索改BUG(一):Android系统状态栏显示不下Wifi图标

这是我入职的第一个BUG,头疼,隔壁实习生一周解决了,我多花了几天 其中最大的原因就是我思考复杂了,在公司系统上,此BUG标题为: 请确认Wifi优先级,状态栏Wifi被忽略 BUG意思就是:当…

云原生Docker Cgroups资源控制操作

目录 资源控制 cgroups四大功能 CPU 资源控制 设置CPU使用率上限 进行CPU压力测试 设置50%的比例分配CPU使用时间上限 设置CPU资源占用比(设置多个容器时才有效) 设置容器绑定指定的CPU 对内存使用的限制 限制容器可以使用的最大内存 限制可用的…

2023年5个美国代理IP推荐,最佳代理花落谁家?

美国代理IP指的是代理服务器位于美国的IP地址,对于跨境业务来说,这些代理IP地址可以用于隐藏用户的真实IP地址,将其网络流量路由通过美国的服务器,以实现一些特定的目的。由于近年来,面向美国市场的跨境商家越来越多&a…

软件测试面试1000问(含文档)

前前后后面试了有20多家的公司吧,最近抽空把当时的录音整理了下,然后给大家分享下 开头都是差不多,就让做一个自我介绍,这个不用再给大家普及了吧 同时,我也准备了一份软件测试视频教程(含接口、自动化、…