HDMI 显示器热插拔对应显示应用启停测试

By Toradex秦海

1). 简介

在前述文章中,我们介绍了如何基于 Weston Composito 实现多屏幕分别显示不同的应用,而进一步延申出的一个应用场景,就是多屏幕之一的 HDMI 屏幕需要进行热插拔,而在热插拔的同时其对应的显示应用也同时启动或者停止,以便不影响其他屏幕的显示。本文就基于前述文章同样的 NXP i.MX8MP 平台来测试如何实现这个功能场景。

本文所演示的平台来自于 Toradex Verdin i.MX8MP 嵌入式平台。

2. 准备

a). Verdin i.MX8MP ARM核心版配合Dahlia 载板,并连接调试串口用于测试。

b). Dahlia 载板分别由 DSI-HDMI 转接卡和 native HDMI 两个接口连接两台 HDMI 显示器以便于进行多屏显示测试。

3). 部署流程

a). 为了实现对于 native HDMI 接口连接的 HDMI-2 显示器热插拔动作的响应,需要通过 udev rule来捕获相应触发模块并进行动作。

./ 首先通过执行如下命令,然后操作硬件热插拔,获取被触发的 udev "KERNEL" 组件是 "card1","SUBSYSTEM" 是 "drm","Action" 是 "change"


root@verdin-imx8mp-06849028:~# udevadm monitor

monitor will print the received events for:

UDEV - the event which udev sends out after rule processing

KERNEL - the kernel uevent

KERNEL89.184407 change /devices/platform/display-subsystem/drm/card1 (drm)

UDEV 89.195674 change /devices/platform/display-subsystem/drm/card1 (drm)

KERNEL98.001197 change /devices/platform/display-subsystem/drm/card1 (drm)

UDEV 98.012452 change /devices/platform/display-subsystem/drm/card1 (drm)


./ 基于上述信息生成如下 udev rules 文件 - /etc/udev/rules.d/99-hdmi-hotplug.rules,这样无论当 HDMI 显示器连接还是断开的时候都会触发这个规则,并执行 hdmi-hotplug.sh 脚本代码。


When HDMI is attached or unattached

ACTION=="change", KERNEL=="card1", SUBSYSTEM=="drm", RUN+="/home/root/hdmi-hotplug.sh"


b). hdmi-hotplug.sh 脚本代码实现

./ native HDMI 对应系统 "/sys/class/drm/card1-HDMI-A-2" 设备,设备节点中有 "status" 项目对应当前 HDMI hotplug 状态


HDMI attached

root@verdin-imx8mp-06849028:~# cat /sys/class/drm/card1-HDMI-A-2/status

connected

HDMI unattached

root@verdin-imx8mp-06849028:~# cat /sys/class/drm/card1-HDMI-A-2/status

disconnected


./ 基于上述判断生成 hdmi-hotplug.sh 脚本来启动或者停止 smarthome Qt 应用(可以见章节1 提到的前述双屏显示文章)。在这里需要通过 systemd service 来启动应用,不能直接执行 smarthome 应用,否则在 hdmi-hotplug.sh 退出后应用也会同时退出。


#!/bin/bash

tty=/dev/ttymxc2

hdmistatus=$(cat /sys/class/drm/card1-HDMI-A-2/status)

if "$hdmistatus" = "connected" ; then

echo "HDMI connected..." > $tty

systemctl start smarthome-app-launch

else

echo "HDMI disconnected..." > $tty

systemctl stop smarthome-app-launch

fi


./ 赋予 hdmi-hotplug.sh 脚本可执行属性


root@verdin-imx8mp-06849028:~# chmod +x hdmi-hotplug.sh


c). 部署 smarthome-app-launch service 文件

./ smarthome-app-launch service 文件 - /lib/systemd/system/smarthome-app-launch.service


Unit

Description=Start a wayland application

After=weston.service

Requires=weston.service

Service

Type=simple

User=root

PAMName=login

Environment=WAYLAND_DISPLAY=/run/wayland-0

Environment=QT_QPA_PLATFORM=wayland-egl

WorkingDirectory=/usr/share/qtsmarthome-1.0/

ExecStart=/usr/share/qtsmarthome-1.0/smarthome

Restart=on-failure

RestartSec=1

Install

WantedBy=graphical.target


./ 更新 systemd service 文件


root@verdin-imx8mp-06849028:~# systemctl daemon-reload


d). 参考章节1 前述双屏显示文章同样内容,修改 /etc/xdg/weston/weston.ini 文件。


--- a/etc/xdg/weston/weston.ini

+++ b/etc/xdg/weston/weston.ini

@@ -4,6 +4,7 @@

idle-time=0

xwayland=true

#enable-overlay-view=1

+shell=kiosk-shell.so

shell

@@ -12,13 +13,16 @@

touchscreen_calibrator=true

calibration_helper=/usr/bin/toradex-save-touchscreen-calibration

-#output

-#name=HDMI-A-1

-#mode=1920x1080@60

+output

+name=HDMI-A-1

+app-ids=Qt5_CinematicExperience

+mode=1920x1080@60

#transform=rotate-90

-#output

-#name=HDMI-A-2

+output

+name=HDMI-A-2

+app-ids=smarthome

+mode=1920x1080

#mode=off

WIDTHxHEIGHT Resolution size width and height in pixels

off Disables the output


e). 另外,wayland-app-launch.service 是 Toradex Yocto Multimedia BSP 默认使能用于 Qt5_CinematicExperience 应用启动的 systemd service 文件,如果之前关闭了,可以通过下面命令使能。


root@verdin-imx8mp-06849028:~# systemctl enable wayland-app-launch


f). 最后所有上述修改完成后重新启动。

4 ). 测试

a). 重新启动后,当两个 HDMI 显示器都连接,可以通过屏幕观察以及如下进程查询确认两个 Qt 应用都分别显示在相应的显示器上面。


root@verdin-imx8mp-06849028:~# ps -aux |grep Qt5_CinematicExperience

root 522 38.3 3.8 1085948 153664 ? Ssl 06:20 0:41 /usr/share/cinematicexperienc

e-1.0/Qt5_CinematicExperience --fullscreen

root 569 0.0 0.0 2944 1280 ttymxc2 S+ 06:22 0:00 grep Qt5_CinematicExperience

root@verdin-imx8mp-06849028:~# ps -aux |grep smarthome

root 520 31.8 1.9 1007248 77160 ? Ssl 06:20 0:37 /usr/share/qtsmarthome-1.0/sm

arthome

root 571 0.0 0.0 2944 1152 ttymxc2 S+ 06:22 0:00 grep smarthome


b). 当将 native HDMI 连接的 HDMI-2 屏幕断开后,对应的 smarthome 应用也同时退出


root@verdin-imx8mp-06849028:~# HDMI disconnected...

root@verdin-imx8mp-06849028:~# ps -aux |grep smarthome

root 645 0.0 0.0 2944 1152 ttymxc2 S+ 06:28 0:00 grep smarthome


c). 当native HDMI 连接的 HDMI-2 屏幕重新连接后,对应的 smarthome 应用也同时启动


root@verdin-imx8mp-06849028:~# HDMI connected...

root@verdin-imx8mp-06849028:~# ps -aux |grep smarthome

root 650 72.3 1.8 1007248 74052 ? Ssl 06:28 0:04 /usr/share/qtsmarthome-1.0/sm

arthome

root 662 0.0 0.0 2944 1280 ttymxc2 S+ 06:28 0:00 grep smarthome


5 ). 总结

本文基于 NXP i.MX8MP 处理器平台测试了 Yocto Linux 下HDMI 显示器热插拔情况下对应显示应用同步启动和停止。

参考文档

https://blog.csdn.net/qq_17292655/article/details/134670878

相关推荐
Dlrb12117 小时前
ARM---IMX6ULL 的 PWM 模块介绍及其程序的编写
arm开发·arm·pwm·imx6ull·lcd屏幕
凉、介13 小时前
Armv8 原子性:体系结构保证与编程语义
linux·学习·嵌入式·arm·原子操作·atomic
Dlrb12113 天前
ARM---IMX6ULL的LCD模块简介及LCD驱动程序的编写
arm开发·lcd·arm·imx6ull·显存·像素
Hi202402173 天前
Cortex-A53 + GIC700 + Boot BRAM Vivado 全流程复现
arm·fpga·vivado
海浪鱼5 天前
Cortex M7-TRM 翻译系列之ITM(十二)
arm·m7
Dlrb12117 天前
ARM---I2C协议时序详解以及IMX6ULL使用I2C协议与AT24C02,LM75A芯片通信详解与示例代码
嵌入式硬件·arm·lm75a·i2c协议·at24c02·i2c时序
Dlrb121110 天前
ARM---IMX6ULL定时器详解与应用:EPIT与GPT定时器,高精度延时函数
arm开发·gpt·arm·定时器·epit·高精度延时
Dlrb121110 天前
ARM -IMX6ULL的中断系统、GIC、CP15协处理器详细讲解
arm开发·arm·imx6ull·中断·gic·cp15·协处理器
Dlrb121111 天前
ARM---I.MX6ULL时钟系统详解、时钟树、系统时钟配置等
单片机·嵌入式硬件·arm·imx6ull·pll·时钟树·cortex-a7
m0_7156467612 天前
20260720
linux·arm