• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Porting the Driver Subsystem
2
3
4The driver subsystem provides OpenHarmony-dedicated APIs for peripheral device operations, including FLASH, GPIO, I2C, PWM, UART, and WATCHDOG APIs.
5
6
7OpenHarmony provides two driver adaptation modes: using the driver subsystem and using the HDF driver framework. Because the resources of the mini system are limited, the IoT subsystem mode is recommended.
8
9
10## Procedure
11
12Vendors need to implement their functions based on the interface definitions provided by OpenHarmony. The header files defined by the interfaces of the IoT subsystem are as follows:
13
14
15```
16base/iot_hardware/peripheral/
17├── BUILD.gn
18└── interfaces
19    └── kits
20        ├── iot_errno.h
21        ├── iot_flash.h
22        ├── iot_gpio.h
23        ├── iot_i2c.h
24        ├── iot_pwm.h
25        ├── iot_uart.h
26        ├── iot_watchdog.h
27        ├── lowpower.h
28        └── reset.h
29```
30
31The content of the **base/iot_hardware/peripheral/BUILD.gn** file is as follows:
32
33
34```
35import("//build/lite/config/subsystem/lite_subsystem.gni")
36import("//build/lite/ndk/ndk.gni")
37
38lite_subsystem("iothardware") {
39  subsystem_components = [
40    "$ohos_vendor_adapter_dir/hals/iot_hardware/wifiiot_lite:hal_iothardware",
41  ]
42}
43if (ohos_kernel_type == "liteos_m") {
44  ndk_lib("iothardware_ndk") {
45    deps = [
46      "$ohos_vendor_adapter_dir/hals/iot_hardware/wifiiot_lite:hal_iothardware", # Vendor dependent adaptation.
47    ]
48    head_files = [ "//base/iot_hardware/peripheral/interfaces/kits" ]
49  }
50}
51```
52
53As shown above, the directory for storing vendor adaptation interfaces is **$ohos_vendor_adapter_dir/hals/iot_hardware/wifiiot_lite**, where the target in the **BUILD.gn file** is **hal_iothardware**.
54
55
56## Example
57
581. Add the iot_hardware subsystem to the **config.json** file.
59
60   Path: **vendor/MyVendorCompany/MyProduct/config.json**
61
62   The sample code is as follows:
63
64
65   ```
66   {
67       subsystem": "iot_hardware",
68       components": [
69           { "component": "iot_controller", "features":[] }
70       ]
71   },
72   ```
73
742. Add an adaptation file.
75
76   In the **vendor/MyVendorCompany/MyProduct/config.json** file, set **vendor_adapter_dir** to **//device/MyDeviceCompany/MyBoard/adapter**.
77
78   Perform adaptation in the **vendor_adapter_dir** directory.
79
80
81   ```
82   hals/iot_hardware/wifiiot_lite
83   ├── BUILD.gn
84   ├── iot_flash.c
85   ├── iot_gpio.c
86   ├── iot_i2c.c
87   ├── iot_lowpower.c
88   ├── iot_pwm.c
89   ├── iot_reset.c
90   ├── iot_uart.c
91   └── iot_watchdog.c
92   ```
93
94   The content of **BUILD.gn** is as follows:
95
96
97   ```
98   static_library("hal_iothardware") {   # Target name
99       sources = [                       # Source file adapted by the vendor
100         "iot_watchdog.c",
101         "iot_reset.c",
102         "iot_flash.c",
103         "iot_i2c.c",
104         "iot_gpio.c",
105         "iot_pwm.c",
106         "iot_uart.c"
107       ]
108       include_dirs = [ ]
109   }
110   ```
111
112   In the preceding example, **include_dirs** must contain two paths based on the site requirements:
113
114   - Path to the header file of the IoT subsystem
115
116   - Path to the SDK header file used by the IoT subsystem
117