1e41f4b71Sopenharmony_ci# Driver Overview
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Introduction
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciOpenHarmony uses the multi-kernel (Linux kernel and LiteOS) design, which allows the operating system to select suitable kernels from the abstraction layer for devices with diverse resources. The OpenHarmony driver subsystem is designed to streamline device drivers to work with different kernels on the same hardware with the minimum workloads on driver code porting and maintenance.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ciThe OpenHarmony driver subsystem provides the following features and capabilities to shorten the driver development period and simplify third-party device driver integration:
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci- Elastic framework
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci  Based on the traditional driver framework, the OpenHarmony driver subsystem provides an elastic framework to support deployment on devices with hundreds KB to hundreds MB memory.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci- Standardized driver interfaces
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci  The OpenHarmony driver subsystem provides diverse driver APIs compatible with the APIs of future-proof smartphones, tablets, and smart TVs.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci- Component-based driver model
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci  The OpenHarmony driver subsystem provides the component-based driver model to implement refined driver management. You can configure components as required and focus on the interaction between the hardware and driver. The driver subsystem is also prebuilt with template-based driver model components, such as the network device model.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci- Unified configuration UI
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci  The OpenHarmony driver subsystem provides a unified configuration tool to generate and convert driver configuration across different platforms.
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci## HDF
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ciThe Hardware Driver Foundation (HDF) provides driver framework capabilities, including driver loading, driver service management, and driver messaging mechanism. It strives to build a unified driver platform to back up a more precise and efficient environment for one-time development for multi-device deployment.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciThe HDF is built in an object-oriented programming model in C language. It provides a unified platform base for different kernels through platform decoupling and kernel decoupling. 
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciThe following figure shows the HDF architecture.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci  **Figure 1** HDF architecture 
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci![](figures/HDF-architecture.png)
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ciThe HDF architecture consists of the following:
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci- Hardware Device Interface (HDI) layer: provides unified and stable APIs for hardware operations.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci- HDF: provides unified hardware resource management, driver loading management, device node management, device power management, and driver service models. It consists of the device management, service management, Device Host, and PnPManager modules.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci- Unified configuration interface (DevEco Studio): supports abstract description of hardware resources to shield hardware differences, and enables development of universal driver code that is not bound to configuration information. You can use HC-Gen to quickly generate configuration files. This unified configuration interface improves development and porting efficiency.
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci- Operating system abstraction layer (OSAL): provides encapsulated kernel operation APIs, including the APIs for the memory, locks, threads, and semaphores, to shield operation differences between different systems.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci- Platform driver layer: provides unified APIs for peripheral drivers to operate board hardware, such as I2C, SPI, and UART buses, and uniformly abstracts the APIs for board hardware operations.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci- Peripheral driver model: provides common driver abstraction models for peripheral drivers to provide standard device drivers and implement driver model abstraction. With standard device driver models, you can deploy drivers through configuration without independent development. The driver model abstraction makes the drivers more general by shielding the interaction between drivers and different system components.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci## Driver Development
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci### Platform Drivers
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ciThe OpenHarmony platform driver (platform device driver) layer provides access APIs for system and peripheral drivers. The platform devices refer to buses, such as I2C and UART, and specific hardware resources, such as GPIO and RTC. 
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ciAs an important part of the OpenHarmony driver framework, the platform driver framework provides standard models for implementing a variety of platform device drivers based on the HDF, OSAL, and driver configuration and management mechanism. It provides standard APIs for peripherals to access platform devices regardless of the difference in underlying hardware. It also provides platform device drivers unified APIs for interface adaptation, making you focus only on hardware control.
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ciThe platform driver framework provides the following:
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci- Unified APIs for accessing platform devices. The platform device operation APIs are encapsulated in a unified manner to shield hardware differences between SoC platforms and differences between OSs.
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci- Unified platform driver adaptation APIs. Unified adaptation APIs are provided for platform device drivers. You only need to focus on the hardware control, rather than the device management and common service processes.
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci- Common capabilities irrelevant to SoCs, such as device registration, management, and access control.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciCurrently, the platform driver framework supports devices, including the ADC, DAC, GPIO, HDMI, I2C, I3C, MIPI CSI, MIPI DSI, MMC, pin, PWM, regulator, RTC, SDIO, SPI, UART, and watchdog.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci### Peripheral Drivers
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ciBased on the HDF and platform driver framework, OpenHarmony provides common driver models for peripheral drivers. These models provide standard peripheral drivers to reduce repeated development. In addition, the abstraction of peripheral driver models shields the interaction between drivers and different system devices, making the driver development more general.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ciCurrently, OpenHarmony supports peripherals, covering audio devices, cameras, codecs, LCDs, lights, motion devices, sensors, touchscreens, USBs, vibrators, WLAN devices, and devices for face authentication, fingerprint authentication, PIN authentication, and user authentication.
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci### Driver Code Repositories
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ciThe following table describes the code repositories of the HDF.
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**Table 1** HDF code repositories
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci| Repository| Description|
88e41f4b71Sopenharmony_ci| -------- | -------- |
89e41f4b71Sopenharmony_ci| drivers/hdf_core/framework | Provides common platform-independent frameworks:<br>- **framework/core**:<br>&nbsp;&nbsp;-&nbsp;Provides capabilities of loading and starting drivers.<br>&nbsp;&nbsp;-&nbsp;Implements elastic deployment and expansion of the driver framework through the object manager.<br>- **framework/model**:<br>&nbsp;&nbsp;Provides driver models, such as the network device model.<br>- **framework/ability**:<br>&nbsp;&nbsp;Provides basic drive ability models, such as the I/O communication model.<br>- **framework/tools**:<br>&nbsp;&nbsp;Provides tools for converting HDI APIs and configuring and building drivers.<br>-&nbsp;**framework/support**:<br>&nbsp;&nbsp;Provides standardized platform driver interfaces and system interface abstraction capabilities. |
90e41f4b71Sopenharmony_ci| drivers/hdf_core/adapter | Provides adaptation code and build scripts for LiteOS-M and LiteOS-A kernels and user-mode interface libraries. |
91e41f4b71Sopenharmony_ci| drivers/hdf_core//adapter/khdf/linux | Provides adaptation code and build scripts for Linux. |
92e41f4b71Sopenharmony_ci| drivers/peripheral | Provides the hardware abstraction layer for peripheral modules, such as the display, input, sensor, WLAN, audio, and camera.|
93e41f4b71Sopenharmony_ci| drivers/interface | Defines the HDI APIs of peripheral modules, such as the display, input, sensor, WLAN, audio, and camera.|
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci### How to Use
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci- To adapt an OpenHarmony driver to a new platform device, use the standard models and APIs provided by the OpenHarmony platform driver framework for interface adaptation. You only need to focus on hardware control, without caring about the device management and common service processes. For details, see **Developing Platform Drivers**.
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci- After the platform driver adaptation, you can use the APIs provided by the OpenHarmony platform driver framework for the system and peripheral drivers to further develop services and applications. For details, see **Using Platform Drivers**.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci- The OpenHarmony HDF provides a variety of standard peripheral driver models. These models shield hardware differences and provide stable and standard APIs for upper-layer services. You can use these models to develop peripheral drivers. For details, see **Using Peripheral Drivers**.
103