1c1d0c72aSopenharmony_ci# HDF<a name="EN-US_TOPIC_0000001078041442"></a> 2c1d0c72aSopenharmony_ci 3c1d0c72aSopenharmony_ci- [Introduction](#section11660541593) 4c1d0c72aSopenharmony_ci- [Directory Structure](#section161941989596) 5c1d0c72aSopenharmony_ci- [Usage](#section1312121216216) 6c1d0c72aSopenharmony_ci - [HDF](#section129654513264) 7c1d0c72aSopenharmony_ci - [Sensor](#section188637474417) 8c1d0c72aSopenharmony_ci - [Display](#section161502341317) 9c1d0c72aSopenharmony_ci - [Input](#section12629164020115) 10c1d0c72aSopenharmony_ci - [WLAN](#section11408103183114) 11c1d0c72aSopenharmony_ci 12c1d0c72aSopenharmony_ci- [Repositories Involved](#section1371113476307) 13c1d0c72aSopenharmony_ci 14c1d0c72aSopenharmony_ci## Introduction<a name="section11660541593"></a> 15c1d0c72aSopenharmony_ci 16c1d0c72aSopenharmony_ciThis 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. 17c1d0c72aSopenharmony_ci 18c1d0c72aSopenharmony_ci**Figure 1** Architecture of the HDF<a name="fig19330181162816"></a> 19c1d0c72aSopenharmony_ci 20c1d0c72aSopenharmony_ci 21c1d0c72aSopenharmony_ci## Directory Structure<a name="section161941989596"></a> 22c1d0c72aSopenharmony_ci 23c1d0c72aSopenharmony_ci``` 24c1d0c72aSopenharmony_ci/drivers/hdf_core/framework 25c1d0c72aSopenharmony_ci├── core # Core code for implementing the HDF 26c1d0c72aSopenharmony_ci│ ├── adapter # Kernel adaptation layer 27c1d0c72aSopenharmony_ci│ ├── common # Common basic code 28c1d0c72aSopenharmony_ci│ ├── host # Driver host environment module 29c1d0c72aSopenharmony_ci│ ├── manager # Management module 30c1d0c72aSopenharmony_ci│ └── shared # Code shared by the host and manager modules 31c1d0c72aSopenharmony_ci├── include # Header files for the HDF to provide capabilities externally 32c1d0c72aSopenharmony_ci│ ├── audio # Header files related to audio operations 33c1d0c72aSopenharmony_ci│ ├── bluetooth # Header files related to bluetooth operations 34c1d0c72aSopenharmony_ci│ ├── core # Header files exposed externally 35c1d0c72aSopenharmony_ci│ ├── ethernnet # Header files related to ethernnet operations 36c1d0c72aSopenharmony_ci│ ├── net # Header files related to network operations 37c1d0c72aSopenharmony_ci│ ├── osal # Header files of the OS adaptation layer 38c1d0c72aSopenharmony_ci│ ├── platform # Header files declaring platform APIs 39c1d0c72aSopenharmony_ci│ ├── utils # Header files declaring common capabilities 40c1d0c72aSopenharmony_ci│ └── wifi # Header files for the WLAN module to provide capabilities externally 41c1d0c72aSopenharmony_ci├── model # Universal framework module for drivers 42c1d0c72aSopenharmony_ci│ ├── audio # Audio framework module 43c1d0c72aSopenharmony_ci│ ├── display # Display framework module 44c1d0c72aSopenharmony_ci│ ├── input # Input framework module 45c1d0c72aSopenharmony_ci│ ├── misc # Misc framework module, including dsoftbus, light, vibrator 46c1d0c72aSopenharmony_ci│ ├── network # WLAN framework module 47c1d0c72aSopenharmony_ci│ └── sensor # Sensor driver module 48c1d0c72aSopenharmony_ci│ └── storage # Storage driver module 49c1d0c72aSopenharmony_ci│ └── usb # Usb driver module 50c1d0c72aSopenharmony_ci├── sample # Sample code 51c1d0c72aSopenharmony_ci├── support # Basic capabilities 52c1d0c72aSopenharmony_ci│ └── platform # Platform driver framework and APIs, including GPIO, I2C, and SPI 53c1d0c72aSopenharmony_ci│ └── posix # Posix APIs, including Mem, Mutex, Sem, Spinlock, Thread and Time 54c1d0c72aSopenharmony_ci├── test # Testcase 55c1d0c72aSopenharmony_ci├── tools # Source code related to the tools of the HDF 56c1d0c72aSopenharmony_ci│ └── hc-gen # Source code of the configuration management tool 57c1d0c72aSopenharmony_ci│ └── hcs-view # 58c1d0c72aSopenharmony_ci│ └── hdf-dbg # 59c1d0c72aSopenharmony_ci│ └── hdf-dev_eco_tool # 60c1d0c72aSopenharmony_ci│ └── hdf-gen # 61c1d0c72aSopenharmony_ci│ └── idl-gen # 62c1d0c72aSopenharmony_ci│ └── leagecy # 63c1d0c72aSopenharmony_ci└── utils # Basic data structures and algorithms 64c1d0c72aSopenharmony_ci``` 65c1d0c72aSopenharmony_ci 66c1d0c72aSopenharmony_ci## Usage<a name="section1312121216216"></a> 67c1d0c72aSopenharmony_ci 68c1d0c72aSopenharmony_ci### HDF<a name="section129654513264"></a> 69c1d0c72aSopenharmony_ci 70c1d0c72aSopenharmony_ciTo 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. 71c1d0c72aSopenharmony_ci 72c1d0c72aSopenharmony_ciDriver development based on the HDF consists of the following three parts: 73c1d0c72aSopenharmony_ci 74c1d0c72aSopenharmony_ci- Driver: Develop the functions. 75c1d0c72aSopenharmony_ci 76c1d0c72aSopenharmony_ci- Information configuration: Present the loading information of the driver. 77c1d0c72aSopenharmony_ci 78c1d0c72aSopenharmony_ci- Resource configuration: Configure the hardware information of the driver. 79c1d0c72aSopenharmony_ci 80c1d0c72aSopenharmony_ciYou need to complete the logic code for the functions of a driver by the following APIs. 81c1d0c72aSopenharmony_ci 82c1d0c72aSopenharmony_ciThe first part that catches your eyes is the driver entry, which is described through **DriverEntry**. 83c1d0c72aSopenharmony_ci 84c1d0c72aSopenharmony_ciThree APIs are available, namely **Bind**, **Init**, and **Release**. 85c1d0c72aSopenharmony_ci 86c1d0c72aSopenharmony_ci``` 87c1d0c72aSopenharmony_cistruct HdfDriverEntry g_deviceSample = { 88c1d0c72aSopenharmony_ci .moduleVersion = 1, 89c1d0c72aSopenharmony_ci .moduleName = "sample_driver", 90c1d0c72aSopenharmony_ci .Bind = SampleDriverBind, 91c1d0c72aSopenharmony_ci .Init = SampleDriverInit, 92c1d0c72aSopenharmony_ci .Release = SampleDriverRelease, 93c1d0c72aSopenharmony_ci}; 94c1d0c72aSopenharmony_ci``` 95c1d0c72aSopenharmony_ci 96c1d0c72aSopenharmony_ci**Bind**: This API is used to bind driver devices and its functions. 97c1d0c72aSopenharmony_ci 98c1d0c72aSopenharmony_ci``` 99c1d0c72aSopenharmony_ciint32_t SampleDriverBind(struct HdfDeviceObject *deviceObject) 100c1d0c72aSopenharmony_ci{ 101c1d0c72aSopenharmony_ci return HDF_SUCCESS; 102c1d0c72aSopenharmony_ci} 103c1d0c72aSopenharmony_ci``` 104c1d0c72aSopenharmony_ci 105c1d0c72aSopenharmony_ci**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. 106c1d0c72aSopenharmony_ci 107c1d0c72aSopenharmony_ci``` 108c1d0c72aSopenharmony_ciint32_t SampleDriverInit(struct HdfDeviceObject *deviceObject) 109c1d0c72aSopenharmony_ci{ 110c1d0c72aSopenharmony_ci return HDF_SUCCESS; 111c1d0c72aSopenharmony_ci} 112c1d0c72aSopenharmony_ci``` 113c1d0c72aSopenharmony_ci 114c1d0c72aSopenharmony_ci**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. 115c1d0c72aSopenharmony_ci 116c1d0c72aSopenharmony_ci``` 117c1d0c72aSopenharmony_civoid SampleDriverRelease(struct HdfDeviceObject *deviceObject) 118c1d0c72aSopenharmony_ci{ 119c1d0c72aSopenharmony_ci // Release all resources. 120c1d0c72aSopenharmony_ci return; 121c1d0c72aSopenharmony_ci} 122c1d0c72aSopenharmony_ci``` 123c1d0c72aSopenharmony_ci 124c1d0c72aSopenharmony_ciFor details, see [HDF Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-hdf-manage.md). 125c1d0c72aSopenharmony_ci 126c1d0c72aSopenharmony_ci### Sensor<a name="section188637474417"></a> 127c1d0c72aSopenharmony_ci 128c1d0c72aSopenharmony_ciThe sensor driver module is developed based on the HDF and supports functions such as cross-OS migration and differentiated device configuration. 129c1d0c72aSopenharmony_ci 130c1d0c72aSopenharmony_ci- 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. 131c1d0c72aSopenharmony_ci- 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. 132c1d0c72aSopenharmony_ci 133c1d0c72aSopenharmony_ciFor details, see [Sensor Driver Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-sensor-des.md). 134c1d0c72aSopenharmony_ci 135c1d0c72aSopenharmony_ci### Display<a name="section161502341317"></a> 136c1d0c72aSopenharmony_ci 137c1d0c72aSopenharmony_ciThe 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. 138c1d0c72aSopenharmony_ci 139c1d0c72aSopenharmony_ci- 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. 140c1d0c72aSopenharmony_ci- 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. 141c1d0c72aSopenharmony_ci 142c1d0c72aSopenharmony_ciFor details, see [LCD Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-lcd-des.md). 143c1d0c72aSopenharmony_ci 144c1d0c72aSopenharmony_ci### Input<a name="section12629164020115"></a> 145c1d0c72aSopenharmony_ci 146c1d0c72aSopenharmony_ciThe 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. 147c1d0c72aSopenharmony_ci 148c1d0c72aSopenharmony_ci- 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. 149c1d0c72aSopenharmony_ci- 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. 150c1d0c72aSopenharmony_ci 151c1d0c72aSopenharmony_ciFor details, see [Touchscreen Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-touch-des.md). 152c1d0c72aSopenharmony_ci 153c1d0c72aSopenharmony_ci### WLAN<a name="section11408103183114"></a> 154c1d0c72aSopenharmony_ci 155c1d0c72aSopenharmony_ciThe 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. 156c1d0c72aSopenharmony_ci 157c1d0c72aSopenharmony_ci- 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. 158c1d0c72aSopenharmony_ci- 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. 159c1d0c72aSopenharmony_ci 160c1d0c72aSopenharmony_ciFor details, see [WLAN Overview](https://gitee.com/openharmony/docs/blob/master/en/device-dev/driver/driver-peripherals-external-des.md). 161c1d0c72aSopenharmony_ci 162c1d0c72aSopenharmony_ci## Repositories Involved<a name="section1371113476307"></a> 163c1d0c72aSopenharmony_ci 164c1d0c72aSopenharmony_ci[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md) 165c1d0c72aSopenharmony_ci 166c1d0c72aSopenharmony_ci[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) 167c1d0c72aSopenharmony_ci 168c1d0c72aSopenharmony_ci[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md) 169c1d0c72aSopenharmony_ci 170c1d0c72aSopenharmony_ci[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) 171c1d0c72aSopenharmony_ci 172c1d0c72aSopenharmony_ci[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README.md) 173c1d0c72aSopenharmony_ci 174