• Home
Name Date Size #Lines LOC

..--

core/12-May-2024-10,5738,043

figures/12-May-2024-

include/12-May-2024-14,6713,806

model/12-May-2024-54,62243,849

sample/12-May-2024-1,4271,107

support/12-May-2024-39,76029,149

test/unittest/12-May-2024-34,57428,279

tools/12-May-2024-49,55840,327

utils/12-May-2024-5,6444,011

.clang-formatD12-May-2024892 2928

.gitignoreD12-May-202419 21

LICENSED12-May-20242.4 KiB5245

OAT.xmlD12-May-20246.4 KiB9245

README.mdD12-May-202410.1 KiB165116

README_zh.mdD12-May-20249.8 KiB165116

README.md

1# HDF<a name="EN-US_TOPIC_0000001078041442"></a>
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section161941989596)
5-   [Usage](#section1312121216216)
6    -   [HDF](#section129654513264)
7    -   [Sensor](#section188637474417)
8    -   [Display](#section161502341317)
9    -   [Input](#section12629164020115)
10    -   [WLAN](#section11408103183114)
11
12-   [Repositories Involved](#section1371113476307)
13
14## Introduction<a name="section11660541593"></a>
15
16This repository stores the core source code information of the OpenHarmony driver subsystem, including the driver framework, configuration management, configuration parsing, universal framework model, and unified hardware driver interfaces. It is designed to provide a more precise and efficient development environment, where you can perform one-time development for multi-system deployment.
17
18**Figure  1**  Architecture of the HDF<a name="fig19330181162816"></a>
19![](figures/architecture-of-the-hdf.png)
20
21## Directory Structure<a name="section161941989596"></a>
22
23```
24/drivers/framework
25├── ability        # Capabilities for the driver development, such as the message model libraries
26│   ├── config     # Parsing code of the configuration
27│   └── sbuf       # Data serialization code
28├── core           # Core code for implementing the HDF
29│   ├── adapter    # Kernel adaptation layer
30│   ├── common     # Common basic code
31│   ├── host       # Driver host environment module
32│   ├── manager    # Management module
33│   └── shared     # Code shared by the host and manager modules
34├── include        # Header files for the HDF to provide capabilities externally
35│   ├── config     # Header files declaring capabilities for parsing configuration
36│   ├── core       # Header files exposed externally
37│   ├── net        # Header files related to network operations
38│   ├── osal       # Header files of the OS adaptation layer
39│   ├── platform   # Header files declaring platform APIs
40│   ├── utils      # Header files declaring common capabilities
41│   └── wifi       # Header files for the WLAN module to provide capabilities externally
42├── model          # Universal framework module for drivers
43│   ├── display    # Display framework module
44│   ├── input      # Input framework module
45│   ├── network    # WLAN framework module
46│   └── sensor     # Sensor driver module
47├── support        # Basic capabilities
48│   └── platform   # Platform driver framework and APIs, including GPIO, I2C, and SPI
49├── tools          # Source code related to the tools of the HDF
50│   └── hc-gen     # Source code of the configuration management tool
51└── utils          # Basic data structures and algorithms
52```
53
54## Usage<a name="section1312121216216"></a>
55
56### HDF<a name="section129654513264"></a>
57
58To develop a driver based on the HDF, you only need to register and configure required APIs. The driver framework will load and initialize the driver based on the parsing content.
59
60Driver development based on the HDF consists of the following three parts:
61
62-   Driver: Develop the functions.
63
64-   Information configuration: Present the loading information of the driver.
65
66-   Resource configuration: Configure the hardware information of the driver.
67
68You need to complete the logic code for the functions of a driver by the following APIs.
69
70The first part that catches your eyes is the driver entry, which is described through  **DriverEntry**.
71
72Three APIs are available, namely  **Bind**,  **Init**, and  **Release**.
73
74```
75struct HdfDriverEntry g_deviceSample = {
76    .moduleVersion = 1,
77    .moduleName = "sample_driver",
78    .Bind = SampleDriverBind,
79    .Init = SampleDriverInit,
80    .Release = SampleDriverRelease,
81};
82```
83
84**Bind**: This API is used to bind driver devices and its functions.
85
86```
87int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject)
88{
89    // TODO: Bind device service to device object.
90    // And you can also initialize device resources here.
91    return HDF_SUCCESS;
92}
93```
94
95**Init**: When devices are successfully bound, the HDF calls  **Init**  to initialize the driver. After initialization is complete, the HDF will determine whether to create external service interfaces based on the configuration file. If the driver fails to be initialized, the driver framework will automatically release the created device interface.
96
97```
98int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject)
99{
100    // TODO: Init hardware or other resources here.
101    return HDF_SUCCESS;
102}
103```
104
105**Release**: When you need to uninstall a driver, the HDF calls this function to release the driver resources. Then, other internal resources will be released.
106
107```
108void SampleDriverRelease(struct HdfDeviceObject *deviceObject)
109{
110    // Release all resources.
111    return;
112}
113```
114
115For details, see  [HDF Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-hdf.md).
116
117### Sensor<a name="section188637474417"></a>
118
119The sensor driver module is developed based on the HDF and supports functions such as cross-OS migration and differentiated device configuration.
120
121-   APIs for implementing sensor driver module capabilities: Implement the capabilities of registering, loading, and deregistering sensor drivers as well as detecting sensor device depending on the HDF, normalize APIs for sensor devices of the same type, and offer APIs for parsing register configurations, abstract APIs for bus access, and abstract platform APIs.
122-   APIs to be implemented by developers: Based on the HDF Configuration Source \(HCS\), implement differentiated configuration for sensors of the same type and serialized configuration of sensor device parameters, and offer APIs for some sensor device operations to simplify the sensor driver development.
123
124For details, see  [Sensor Driver Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-sensor-des.md).
125
126### Display<a name="section161502341317"></a>
127
128The display driver model that is developed based on the HDF shields the differences among chip platforms, achieving cross-platform migration of the OS. It also abstracts the common service logic of peripherals and configures differentiated adaptation APIs so that a driver model can be compatible with different peripheral. In this way, third-party vendors can efficiently access the OpenHarmony driver ecosystem.
129
130-   APIs for implementing display driver module capabilities: Implement the Hardware Driver Interfaces \(HDIs\) and their adaptation with the chip platform. In addition, the kernel-mode driver abstracts the common services of the panel driver and provides capabilities of initializing the panel, obtaining the panel configuration, powering on/off the panel, and implementing the backlight control.
131-   APIs to be implemented by developers: Complete the board-level HCS configuration and private data configuration of the panel, or offer differentiated APIs for some components to ensure efficient development of the display driver.
132
133For details, see  [LCD Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-lcd-des.md).
134
135### Input<a name="section12629164020115"></a>
136
137The input driver model is developed based on the HDF, provides unified driver APIs for upper-layer input services, and is decoupled from the chip platform. In addition, it abstracts several types of common platform drivers based on different input devices and is compatible with those input devices through configuration and differentiated peripheral APIs.
138
139-   APIs for implementing input driver module capabilities: Implement the HDIs and provide capabilities of managing devices, controlling services, and reporting data. Besides, the input driver model provides a unified driver for different input devices and the capabilities of registering/unregistering an input device, reporting event data, parsing configuration, and loading a common driver.
140-   APIs to be implemented by developers: Based on the provided platform driver, add the device descriptions as well as private configuration of the input device and implement differentiated APIs to greatly shorten the time required for developing input drivers.
141
142For details, see  [Touchscreen Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-touch-des.md).
143
144### WLAN<a name="section11408103183114"></a>
145
146The WLAN module is developed based on the HDF and supports cross-OS migration, component adaptation, and modular assembly and compilation. Based on the unified APIs provided by the WLAN module, driver developers of WLAN vendors can adapt their driver code and developers of the Hardware Driver Interfaces \(HDIs\) are capable of creating, disabling, scanning, and connecting to WLAN hotspots.
147
148-   APIs for implementing WLAN driver module capabilities: Implement the APIs of the WLAN HDI layer and provide capabilities of setting/obtaining the MAC address, obtaining the feature type, and setting the transmit power for upper-layer input services, as well as the capabilities of creating/releasing a  **WifiModule**, connecting to/disconnecting from a WLAN hotspot, and applying for/releasing a  **NetBuf**  for developers.
149-   APIs to be implemented by developers: Based on the provided platform driver, complete the board-level HCS configuration as well as the differentiated WLAN configuration, and offer APIs for initializing, deregistering, enabling, and disabling a network device.
150
151For details, see  [WLAN Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-external-des.md).
152
153## Repositories Involved<a name="section1371113476307"></a>
154
155[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver-subsystem.md)
156
157[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
158
159[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
160
161[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
162
163[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README.md)
164
165

README_zh.md

1# Hdf Framework<a name="ZH-CN_TOPIC_0000001078041442"></a>
2
3-   [简介](#section11660541593)
4-   [目录](#section161941989596)
5-   [说明](#section1312121216216)
6    -   [驱动框架使用说明](#section129654513264)
7    -   [Sensor框架模型说明](#section188637474417)
8    -   [Display框架模型说明](#section161502341317)
9    -   [Input框架模型说明](#section12629164020115)
10    -   [WLAN框架模型说明](#section11408103183114)
11
12-   [相关仓](#section1371113476307)
13
14## 简介<a name="section11660541593"></a>
15
16该仓主要存放OpenHarmony驱动子系统核心源码信息(包括驱动框架、配置管理、配置解析、驱动通用框架模型、硬件通用平台能力接口等),旨在为开发者提供更精准、更高效的开发环境,力求做到一次开发,多系统部署。
17
18**图 1**  驱动框架的架构图<a name="fig1181155517618"></a>
19![](figures/architecture-of-the-hdf.png)
20
21## 目录<a name="section161941989596"></a>
22
23```
24/drivers/framework
25├── ability        #提供驱动开发的能力支持,如消息模型库等
26│   ├── config     #配置解析代码
27│   └── sbuf       #数据序列化代码
28├── core           #实现驱动框架的核心代码
29│   ├── adapter    #实现对内核操作接口适配,提供抽象化的接口供开发者使用
30│   ├── common     #驱动框架公共基础代码
31│   ├── host       #驱动宿主环境模块
32│   ├── manager    #驱动框架管理模块
33│   └── shared     #host和manager共享模块代码
34├── include        #驱动框架对外提供能力的头文件
35│   ├── config     #提供配置解析能力的头文件
36│   ├── core       #驱动框架对外提供的头文件
37│   ├── net        #网络数据操作相关的头文件
38│   ├── osal       #系统适配相关接口的头文件
39│   ├── platform   #平台设备相关接口的头文件
40│   ├── utils      #驱动框架公共能力的头文件
41│   └── wifi       #WLAN对外提供能力的头文件
42├── model          #提供驱动通用框架模型
43│   ├── display    #显示框架模型
44│   ├── input      #输入框架模型
45│   ├── network    #WLAN框架模型
46│   └── sensor     #Sensor驱动模型
47├── support        #提系统的基础能力
48│   └── platform   #平台设备驱动框架及访问接口,范围包括GPIO、I2C、SPI等
49├── tools          #hdf框架工具相关的源码
50│   └── hc-gen     #配置管理工具源码
51└── utils          #提供基础数据结构和算法等
52```
53
54## 说明<a name="section1312121216216"></a>
55
56### 驱动框架使用说明<a name="section129654513264"></a>
57
58基于HDF(驱动框架)开发驱动,用户只需注册自己所需的接口和配置,然后驱动框架就会解析配置的内容,完成驱动加载和初始化动作。
59
60开发者基于HDF驱动框架开发的驱动主要包含三大部分:
61
621、驱动程序部分----完成驱动的功能逻辑。
63
642、驱动配置信息----指示驱动的加载信息内容。
65
663、驱动资源配置----配置驱动的硬件配置信息。
67
68驱动程序主要是完成驱动功能的逻辑代码:
69
70对于开发者首先看到的是驱动入口部分,驱动入口部分通过DriverEntry进行描述。
71
72其中主要包含Bind, Init 和Release三个接口。
73
74```
75struct HdfDriverEntry g_deviceSample = {
76    .moduleVersion = 1,
77    .moduleName = "sample_driver",
78    .Bind = SampleDriverBind,
79    .Init = SampleDriverInit,
80    .Release = SampleDriverRelease,
81};
82```
83
84Bind接口描述:该接口的作用主要是完成驱动设备和设备服务接口的bind动作。
85
86```
87int32_t SampleDriverBind(struct HdfDeviceObject *deviceObject)
88{
89    // TODO: Bind device service to device object.
90    // And you can also initialize device resources here.
91    return HDF_SUCCESS;
92}
93```
94
95Init接口描述:当框架完成设备绑定动作后,就开始调用驱动初始化接口,当初始化成功后,驱动框架根据配置文件决定是否对外创建设备服务接口,还是只是对当前服务接口可见。如果Init初始化失败的话,驱动框架就会主动释放创建的设备接口等信息。
96
97```
98int32_t SampleDriverInit(struct HdfDeviceObject *deviceObject)
99{
100    // TODO: Init hardware or other resources here.
101    return HDF_SUCCESS;
102}
103```
104
105Release接口描述:当用户需要卸载驱动时,驱动框架先通过该接口通知驱动程序释放资源。然后在执行其他内部资源释放。
106
107```
108void SampleDriverRelease(struct HdfDeviceObject *deviceObject)
109{
110    // Release all resources.
111    return;
112}
113```
114
115HDF驱动框架详细开发请参考[驱动开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-hdf.md)116
117### Sensor框架模型说明<a name="section188637474417"></a>
118
119基于HDF(**H**ardware  **D**river  **F**oundation)驱动框架开发的Sensor驱动模型,实现跨操作系统迁移,器件差异配置等功能,具体包括下面两部分:
120
121-   Sensor驱动模型基础能力部分:依赖HDF驱动框架实现Sensor器件驱动的注册,加载,去注册,器件探测等能力,提供同一类型Sensor器件驱动归一接口, 寄存器配置解析操作接口,总线访问抽象接口,平台抽象接口。
122-   开发者实现的部分:依赖HDF驱动框架的HCS\(**H**DF  **C**onfiguration  **S**ource\)配置管理,根据同类型Sensor差异化配置,实现Sensor器件参数序列化配置和器件部分操作接口,简化Sensor器件驱动开发。
123
124基于Sensor驱动模型开发Sensor器件驱动请参考[Sensor驱动开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-peripherals-sensor-des.md)125
126### Display框架模型说明<a name="section161502341317"></a>
127
128基于OpenHarmony驱动框架的Display驱动模型,对上屏蔽了芯片平台差异,方便操作系统跨平台迁移;向下抽象外设驱动公共业务逻辑,通过配置或差异化适配接口,实现一套驱动模型可兼容不同的外设器件,使得三方厂商可以高效、便捷的切入鸿蒙驱动生态。
129
130-   Display驱动模型基础能力部分:包括HDI(**H**ardware  **D**river  **I**nterfaces)接口的定义及其实现框架,以及芯片平台对HDI接口的适配实现;内核驱动部分抽象了Panel驱动的公共业务,提供基础的Panel初始化、器件配置信息获取、上下电、背光设置等公共流程。
131-   驱动开发者实现的部分:需要完成板级的HCS配置及Panel私有数据配置,或者实现部分器件差异化接口,保证显示屏驱动开发高效便捷。
132
133基于Display驱动模型开发LCD器件驱动请参考[LCD驱动开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-peripherals-lcd-des.md)134
135### Input框架模型说明<a name="section12629164020115"></a>
136
137基于OpenHarmony驱动框架的Input驱动模型,不依赖于芯片平台,对上层输入服务提供统一的驱动接口;在具体的驱动模型实现中,针对不同类别的输入设备,抽象出几类公共的平台驱动,通过配置及差异化的适配接口,使得驱动模型可兼容不同的输入设备。
138
139-   Input驱动模型基础能力部分:包括Input HDI层的接口定义及公共实现,对上层输入服务提供设备管理、业务控制、数据上报等驱动能力接口;而Input驱动模型提供不同类型Input设备的归一化驱动, 包括输入设备的注册和注销、event数据的上报通道、配置信息的解析、公共驱动的加载等能力。
140-   开发者实现的部分:根据驱动模型提供的平台驱动,需要完成设备描述配置及器件私有配置,以及实现预留的器件差异化接口,借由此驱动模型,可大幅缩减Input设备驱动的开发周期。
141
142基于Input驱动模型开发Touchscreen器件驱动请参考[Touchscreen驱动开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-peripherals-touch-des.md)143
144### WLAN框架模型说明<a name="section11408103183114"></a>
145
146基于OpenHarmony驱动框架的WLAN驱动模型,可实现跨操作系统迁移,自适应器件差异,模块化拼装编译等功能。各WLAN厂商驱动开发人员可根据WLAN模块提供的向下统一接口适配各自的驱动代码,HDI层开发人员可根据WLAN模块提供的向上统一接口获取如下能力:建立/关闭WLAN热点、扫描、关联WLAN热点等。
147
148-   WLAN驱动模型基础能力部分:包括WLAN HDI层的接口定义及公共实现,对上层输入服务提供如设置MAC地址,获取设备的MAC地址,获取特性的类型,设置发射功率等能力;对驱动开发者提供创建/释放WifiModule,关联/取消关联,申请/释放NetBuf等能力。
149-   驱动开发者实现的部分:根据驱动模型提供的平台驱动,需要完成板级的HCS配置及WLAN芯片的私有配置,以及实现预留的初始化/注销网络设备、打开/关闭网络设备等相关接口。
150
151基于WLAN驱动模型开发WLAN器件驱动请参考[WLAN驱动开发指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/driver/driver-peripherals-external-des.md)152
153## 相关仓<a name="section1371113476307"></a>
154
155[驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
156
157[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
158
159[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
160
161[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
162
163[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README_zh.md)
164
165