TP
TP驱动模型
主要包含Input模块HDI(Hardware Driver Interface)接口定义及其实现,对上层输入服务提供操作input设备的驱动能力接口,HDI接口主要包括如下三大类:
- InputManager:管理输入设备,包括输入设备的打开、关闭、设备列表信息获取等;
- InputReporter:负责输入事件的上报,包括注册、注销数据上报回调函数等;
- InputController:提供input设备的业务控制接口,包括获取器件信息及设备类型、设置电源状态等。
图 1 INPUT模块HDI接口层框架图
相关目录下源代码目录结构如下所示
/drivers/peripheral/input
├── hal # input模块的hal层代码
│ └── include # input模块hal层内部的头文件
│ └── src # input模块hal层代码的具体实现
├── interfaces # input模块对上层服务提供的驱动能力接口
│ └── include # input模块对外提供的接口定义
├── test # input模块的测试代码
│ └── unittest # input模块的单元测试代码
TP HDF驱动适配
TP驱动涉及的文件及目录
dayu200平台默认支持GT5688这颗TP IC。
开发板移植touch驱动涉及的文件及目录:
1、 Makefile文件: drivers\adapter\khdf\linux\model\input\Makefile
2、 vendor\hihope\rk3568\hdf_config\khdf\device_info\device_info.hcs
3、 vendor\hihope\rk3568\hdf_config\khdf\input\input_config.hcs
4、 drivers\framework\model\input\driver\touchscreen
TP驱动的适配涉及TP驱动和hcs配置
tp驱动的适配依赖hdf的input模型,hdf的input模型提供了TP,KEY,HID等场景的设备注册,管理,数据转发层,hcs解析等场景的支持能力。hdf的input模型可大致抽象为驱动管理层、公共驱动层以及器件驱动三层。
从功能的角度看hdf input模块的框架如下:
因为hdf input模型的高度抽象集成,TP驱动的适配驱动主要涉及器件驱动层的适配。
在适配前,需要先明确tp所需要的的资源。
对于硬件资源,tp模组需要主机上的如下资源:
1.中断引脚
2.Reset引脚
3.使用的哪一组i2c,从设备的地址是什么
4.TP的初始化固件(这个通常由IC厂商提供)
5.触摸屏的分辨率
对于软件资源,在hdf上适配tp,需要依赖如下几个hdf基础模组:
1.Hdf gpio子系统 用于设置gpio pin脚以及一些中断资源
2.Hdf i2c 子系统 用于进行i2c通信
3.Input模型
器件驱动主要围绕如下结构体展开
static struct TouchChipOps g_gt911ChipOps = {
.Init = ChipInit,
.Detect = ChipDetect,
.Resume = ChipResume,
.Suspend = ChipSuspend,
.DataHandle = ChipDataHandle,
.UpdateFirmware = UpdateFirmware,
.SetAbility = SetAbility,
};
ChipInit负责器件驱动的初始化动作
ChipDetect负责初始化后的器件有效性检测
SetAbility设置按键属性
ChipDataHandle负责解析键值
UpdateFirmware负责升级固件
ChipSuspend负责器件的休眠
ChipResume负责器件的唤醒
按照器件的特性实现如上接口回调,并将该结构体注册进input模型即可
HCS 配置
device_info.hcs中加入新的器件节点
device_touch_chip :: device {
device0 :: deviceNode {
policy = 0;
priority = 180;
preload = 0;//0表示默认加载
permission = 0660;
moduleName = "HDF_TOUCH_GT911";//需要和器件driver中保持一致
serviceName = "hdf_touch_gt911_service";
deviceMatchAttr = "zsj_gt911_5p5";
}
}
input_config.hcs中加入器件的特性
chipConfig {
template touchChip {
match_attr = "";
chipName = "gt911";
vendorName = "zsj";
chipInfo = "AAAA11222"; // 4-ProjectName, 2-TP IC, 3-TP Module
/* 0:i2c 1:spi*/
busType = 0;
deviceAddr = 0x5D;
/* 0:None 1:Rising 2:Failing 4:High-level 8:Low-level */
irqFlag = 2;
maxSpeed = 400;
chipVersion = 0; //parse Coord TypeA
powerSequence {
/* [type, status, dir , delay]
<type> 0:none 1:vcc-1.8v 2:vci-3.3v 3:reset 4:int
<status> 0:off or low 1:on or high 2:no ops
<dir> 0:input 1:output 2:no ops
<delay> meanings delay xms, 20: delay 20ms
*/
powerOnSeq = [4, 0, 1, 5,
3, 0, 1, 10,
3, 1, 1, 60,
4, 2, 0, 50];
suspendSeq = [3, 0, 2, 10];
resumeSeq = [3, 1, 2, 10];
powerOffSeq = [3, 0, 2, 10,
1, 0, 2, 20];
}
}
显示适配
显示适配需要完成的工作:图形服务HDI接口适配、GPU适配、LCD驱动适配
显示HDI
显示HDI对图形服务提供显示驱动能力,包括显示图层的管理、显示内存的管理及硬件加速等。 显示HDI需要适配两部分:gralloc 和 display_device。
gralloc适配
gralloc模块提供显示内存管理功能,OpenHarmony提供了使用与Hi3516DV300参考实现,厂商可根据实际情况参考适配,该实现基于drm开发。
drm设备节点定义在//drivers_peripheral/display/hal/default_standard/srd/display_gralloc/display_gralloc_gbm.c文件中,可根据实际情况修改
const char *g_drmFileNode = "/dev/dri/card0";
该实现中存在一个海思的私有ioctl命令码 DRM_IOCTL_HISILICON_GEM_FD_TO_PHYADDR 定义在//drivers_peripheral/display/hal/default_standard/src/display_gralloc/hisilicon_drm.h 文件中, 在//drivers_peripheral/display/hal/default_standard/src/display_gralloc/display_gralloc_gbm.c文件中调用,属于海思的私有功能,适配时根据实际情况修改
...
InitBufferHandle(bo, fd, info, priBuffer);
priBuffer->hdl.phyAddr = GetPhysicalAddr(grallocManager->drmFd, fd);
*buffer = &priBuffer->hdl;
...
display device适配
display device模块提供显示设备管理、layer管理、硬件加速等功能。
OpenHarmony提供了 基于drm的Hi3516DV300芯片的参考实现,该实现默认支持硬件合成;
如开发板不支持硬件合成,需要在drm_display.cpp文件中跳过gfx的初始化,
drivers_peripheral/blob/master/display/hal/default_standard/src/display_device/drm/drm_display.cpp
int32_t DrmDisplay::Init()
{
...
...
ret = HdiDisplay::Init();
DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("init failed"));
auto preComp = std::make_unique<HdiGfxComposition>();
DISPLAY_CHK_RETURN((preComp == nullptr), DISPLAY_FAILURE,
DISPLAY_LOGE("can not new HdiGfxComposition errno %{public}d", errno));
ret = preComp->Init(); // gfx初始化,这里需要跳过
DISPLAY_CHK_RETURN((ret != DISPLAY_SUCCESS), DISPLAY_FAILURE, DISPLAY_LOGE("can not init HdiGfxComposition")); // 或者不判断返回值
...
}
同时在//drivers_peripheral/display/hal/default_standard/src/display_device/hdi_gfx_composition.cpp文件中修改set_layers方法,全部使用CPU合成显示
int32_t HdiGfxComposition::SetLayers(std::vector<HdiLayer *> &layers, HdiLayer &clientLayer)
{
DISPLAY_LOGD("layers size %{public}zd", layers.size());
mClientLayer = &clientLayer;
mCompLayers.clear();
for (auto &layer : layers) {
if (CanHandle(*layer)) {
#if 0 // CPU合成
layer->SetDeviceSelect(COMPOSITION_CLIENT);
#else
if ((layer->GetCompositionType() != COMPOSITION_VIDEO) &&
(layer->GetCompositionType() != COMPOSITION_CURSOR)) {
layer->SetDeviceSelect(COMPOSITION_DEVICE);
} else {
layer->SetDeviceSelect(layer->GetCompositionType());
}
#endif
mCompLayers.push_back(layer);
}
}
DISPLAY_LOGD("composer layers size %{public}zd", mCompLayers.size());
return DISPLAY_SUCCESS;
}
测试验证
hello_composer测试模块:Rosen图形框架提供的测试程序,主要显示流程,HDI接口等功能是否正常。默认随系统编译。
代码路径:
foundation/graphic/graphic/rosen/samples/composer/
├── BUILD.gn
├── hello_composer.cpp
├── hello_composer.h
├── layer_context.cpp
├── layer_context.h
└── main.cpp
具体验证如下:
- 关闭render service
service_control stop render_service
- 关闭 foundation进程
service_control stop foundation
- 运行hello_composer 测试相关接口
./hello_composer
devicetest测试:HDI显示模块提供的测试模块,主要测试HDI接口、显示buffer、驱动等能力,测试时也需要关闭render service和 foundation进程。
代码路径:/drivers/peripheral/display/test/unittest/standard
├── BUILD.gn
├── common
│ ├── display_test.h
│ ├── display_test_utils.cpp
│ └── display_test_utils.h
├── display_device
│ ├── hdi_composition_check.cpp
│ ├── hdi_composition_check.h
│ ├── hdi_device_test.cpp
│ ├── hdi_device_test.h
│ ├── hdi_test_device_common.h
│ ├── hdi_test_device.cpp
│ ├── hdi_test_device.h
│ ├── hdi_test_display.cpp
│ ├── hdi_test_display.h
│ ├── hdi_test_layer.cpp
│ ├── hdi_test_layer.h
│ ├── hdi_test_render_utils.cpp
│ └── hdi_test_render_utils.h
└── display_gralloc
├── display_gralloc_test.cpp
└── display_gralloc_test.h
GPU
编译器clang
prebuilts/clang/ohos/linux-x86_64/llvm
musl库
./build.sh --product-name rk3568 --build-target musl_all
编译完成后,会在 out/{product_name}/obj/third_party/musl/usr/lib目录下生成对应的头文件和库:
32位对应arm-linux-ohos
64位对应aarch64-linux-ohos
源码目录:
third_party/musl
GPU 编译参数参考
TARGET_CFLAG