• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Input<a name="ZH-CN_TOPIC_0000001124789109"></a>
2
3-   [简介](#section11660541593)
4-   [目录](#section161941989596)
5    -   [接口说明](#section1551164914237)
6    -   [使用说明](#section129654513264)
7
8-   [相关仓](#section1371113476307)
9
10## 简介<a name="section11660541593"></a>
11
12该仓下主要包含Input模块HDI(Hardware Driver Interface)接口定义及其实现,对上层输入服务提供操作input设备的驱动能力接口,HDI接口主要包括如下三大类:
13
14-   InputManager:管理输入设备,包括输入设备的打开、关闭、设备列表信息获取等;
15-   InputReporter:负责输入事件的上报,包括注册、注销数据上报回调函数等;
16-   InputController:提供input设备的业务控制接口,包括获取器件信息及设备类型、设置电源状态等。
17
18**图 1**  INPUT模块HDI接口层框架图<a name="fig9489629122818"></a>
19![](figures/hdi-architecture-of-the-input-module.png "hdi-architecture-of-the-input-module")
20
21## 目录<a name="section161941989596"></a>
22
23该仓下源代码目录结构如下所示
24
25```
26/drivers/peripheral/input
27├── hal                # input模块的hal层代码
28│   └── include       # input模块hal层内部的头文件
29│   └── src           # input模块hal层代码的具体实现
30├── interfaces         # input模块对上层服务提供的驱动能力接口
31│   └── include       # input模块对外提供的接口定义
32├── test               # input模块的测试代码
33│   └── unittest      # input模块的单元测试代码
34```
35
36### 接口说明<a name="section1551164914237"></a>
37
38Input驱动提供给系统服务Input Service可直接调用的驱动能力接口,按照属性分类三类:input设备管理模块、input数据上报模块、input业务控制模块,例如提供输入设备打开及关闭接口、注册设备监听的回调接口、设备信息查询接口、电源状态控制接口等。
39
40提供的部分接口说明如[表1 Input HDI接口列表](#table1513255710559)所示:
41
42**表 1**  Input HDI接口列表
43
44<a name="table1513255710559"></a>
45<table><thead align="left"><tr id="row171321857155517"><th class="cellrowborder" align="center" valign="top" width="12.031203120312032%" id="mcps1.2.4.1.1"><p id="p6132957115511"><a name="p6132957115511"></a><a name="p6132957115511"></a>头文件</p>
46</th>
47<th class="cellrowborder" align="center" valign="top" width="66.006600660066%" id="mcps1.2.4.1.2"><p id="p14132125715552"><a name="p14132125715552"></a><a name="p14132125715552"></a>接口名称</p>
48</th>
49<th class="cellrowborder" align="center" valign="top" width="21.96219621962196%" id="mcps1.2.4.1.3"><p id="p18132205755516"><a name="p18132205755516"></a><a name="p18132205755516"></a>功能描述</p>
50</th>
51</tr>
52</thead>
53<tbody><tr id="row13132357165514"><td class="cellrowborder" rowspan="4" align="left" valign="top" width="12.031203120312032%" headers="mcps1.2.4.1.1 "><p id="p15674038913"><a name="p15674038913"></a><a name="p15674038913"></a></p>
54<p id="p825185015460"><a name="p825185015460"></a><a name="p825185015460"></a>input_manager.h</p>
55<p id="p2133757135510"><a name="p2133757135510"></a><a name="p2133757135510"></a></p>
56</td>
57<td class="cellrowborder" valign="top" width="66.006600660066%" headers="mcps1.2.4.1.2 "><p id="p11132857135517"><a name="p11132857135517"></a><a name="p11132857135517"></a>int32_t (*OpenInputDevice)(uint32_t devIndex);</p>
58</td>
59<td class="cellrowborder" align="center" valign="top" width="21.96219621962196%" headers="mcps1.2.4.1.3 "><p id="p8233134675314"><a name="p8233134675314"></a><a name="p8233134675314"></a>打开input设备</p>
60</td>
61</tr>
62<tr id="row9132135715515"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p106067813482"><a name="p106067813482"></a><a name="p106067813482"></a>int32_t (*CloseInputDevice)(uint32_t devIndex);</p>
63</td>
64<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p8233144617532"><a name="p8233144617532"></a><a name="p8233144617532"></a>关闭input设备</p>
65</td>
66</tr>
67<tr id="row2973185044814"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1974125024812"><a name="p1974125024812"></a><a name="p1974125024812"></a>int32_t (*GetInputDevice)(uint32_t devIndex, DeviceInfo **devInfo);</p>
68</td>
69<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p152331046155310"><a name="p152331046155310"></a><a name="p152331046155310"></a>获取指定ID的设备信息</p>
70</td>
71</tr>
72<tr id="row171330575555"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p913315573557"><a name="p913315573557"></a><a name="p913315573557"></a>int32_t (*GetInputDeviceList)(uint32_t *devNum, DeviceInfo **devList, uint32_t size);</p>
73</td>
74<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p1523319466539"><a name="p1523319466539"></a><a name="p1523319466539"></a>获取所有设备列表信息</p>
75</td>
76</tr>
77<tr id="row1513316577554"><td class="cellrowborder" rowspan="3" align="left" valign="top" width="12.031203120312032%" headers="mcps1.2.4.1.1 "><p id="p14171441118"><a name="p14171441118"></a><a name="p14171441118"></a></p>
78<p id="p57063567463"><a name="p57063567463"></a><a name="p57063567463"></a>input_reporter.h</p>
79</td>
80<td class="cellrowborder" valign="top" width="66.006600660066%" headers="mcps1.2.4.1.2 "><p id="p14794193010499"><a name="p14794193010499"></a><a name="p14794193010499"></a>int32_t (*RegisterReportCallback)(uint32_t devIndex, InputReportEventCb *callback);</p>
81</td>
82<td class="cellrowborder" align="center" valign="top" width="21.96219621962196%" headers="mcps1.2.4.1.3 "><p id="p72331046145316"><a name="p72331046145316"></a><a name="p72331046145316"></a>注册input设备的回调</p>
83</td>
84</tr>
85<tr id="row171331657185514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p123921240124910"><a name="p123921240124910"></a><a name="p123921240124910"></a>int32_t (*UnregisterReportCallback)(uint32_t devIndex);</p>
86</td>
87<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p19233174675311"><a name="p19233174675311"></a><a name="p19233174675311"></a>注销input设备的回调</p>
88</td>
89</tr>
90<tr id="row41331557165518"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p11499124705012"><a name="p11499124705012"></a><a name="p11499124705012"></a>void (*ReportEventPkgCallback)(const EventPackage **pkgs, uint32_t count);</p>
91</td>
92<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p52331246135315"><a name="p52331246135315"></a><a name="p52331246135315"></a>上报数据的回调函数</p>
93</td>
94</tr>
95<tr id="row1452521025813"><td class="cellrowborder" rowspan="9" align="left" valign="top" width="12.031203120312032%" headers="mcps1.2.4.1.1 "><p id="p1285144710118"><a name="p1285144710118"></a><a name="p1285144710118"></a></p>
96<p id="p854114711117"><a name="p854114711117"></a><a name="p854114711117"></a></p>
97<p id="p15741647517"><a name="p15741647517"></a><a name="p15741647517"></a></p>
98<p id="p7909447418"><a name="p7909447418"></a><a name="p7909447418"></a></p>
99<p id="p12525910165811"><a name="p12525910165811"></a><a name="p12525910165811"></a>input_controller.h</p>
100<p id="p942322013262"><a name="p942322013262"></a><a name="p942322013262"></a></p>
101<p id="p1040515339526"><a name="p1040515339526"></a><a name="p1040515339526"></a></p>
102<p id="p19405533115216"><a name="p19405533115216"></a><a name="p19405533115216"></a></p>
103</td>
104<td class="cellrowborder" valign="top" width="66.006600660066%" headers="mcps1.2.4.1.2 "><p id="p14402132815113"><a name="p14402132815113"></a><a name="p14402132815113"></a>int32_t (*SetPowerStatus)(uint32_t devIndex, uint32_t status);</p>
105</td>
106<td class="cellrowborder" align="center" valign="top" width="21.96219621962196%" headers="mcps1.2.4.1.3 "><p id="p1510016065413"><a name="p1510016065413"></a><a name="p1510016065413"></a>设置电源状态</p>
107</td>
108</tr>
109<tr id="row172902161193"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p2062643555111"><a name="p2062643555111"></a><a name="p2062643555111"></a>int32_t (*GetPowerStatus)(uint32_t devIndex, uint32_t *status);</p>
110</td>
111<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p1323394615539"><a name="p1323394615539"></a><a name="p1323394615539"></a>获取电源状态</p>
112</td>
113</tr>
114<tr id="row1948179195"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p8207194414510"><a name="p8207194414510"></a><a name="p8207194414510"></a>int32_t (*GetDeviceType)(uint32_t devIndex, uint32_t *deviceType);</p>
115</td>
116<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p18233154655317"><a name="p18233154655317"></a><a name="p18233154655317"></a>获取设备类型</p>
117</td>
118</tr>
119<tr id="row1331121813197"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1321125217514"><a name="p1321125217514"></a><a name="p1321125217514"></a>int32_t (*GetChipInfo)(uint32_t devIndex, char *chipInfo, uint32_t length);</p>
120</td>
121<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p14233104614536"><a name="p14233104614536"></a><a name="p14233104614536"></a>获取器件编码信息</p>
122</td>
123</tr>
124<tr id="row1393181951920"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79410191191"><a name="p79410191191"></a><a name="p79410191191"></a>int32_t (*GetVendorName)(uint32_t devIndex, char *vendorName, uint32_t length);</p>
125</td>
126<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p7233124695317"><a name="p7233124695317"></a><a name="p7233124695317"></a>获取模组厂商名</p>
127</td>
128</tr>
129<tr id="row8960121911198"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p17712110185218"><a name="p17712110185218"></a><a name="p17712110185218"></a>int32_t (*GetChipName)(uint32_t devIndex, char *chipName, uint32_t length);</p>
130</td>
131<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p923316468539"><a name="p923316468539"></a><a name="p923316468539"></a>获取芯片厂商名</p>
132</td>
133</tr>
134<tr id="row10812112081919"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p20738171735219"><a name="p20738171735219"></a><a name="p20738171735219"></a>int32_t (*SetGestureMode)(uint32_t devIndex, uint32_t gestureMode);</p>
135</td>
136<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p5233546175310"><a name="p5233546175310"></a><a name="p5233546175310"></a>设置手势模式</p>
137</td>
138</tr>
139<tr id="row12422102092613"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p56701925155215"><a name="p56701925155215"></a><a name="p56701925155215"></a>int32_t (*RunCapacitanceTest)(uint32_t devIndex, uint32_t testType, char *result, uint32_t length);</p>
140</td>
141<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p13234346125310"><a name="p13234346125310"></a><a name="p13234346125310"></a>执行容值自检测试</p>
142</td>
143</tr>
144<tr id="row124041233155211"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16405113375215"><a name="p16405113375215"></a><a name="p16405113375215"></a>int32_t (*RunExtraCommand)(uint32_t devIndex, InputExtraCmd *cmd);</p>
145</td>
146<td class="cellrowborder" align="center" valign="top" headers="mcps1.2.4.1.2 "><p id="p192341246185314"><a name="p192341246185314"></a><a name="p192341246185314"></a>执行拓展指令</p>
147</td>
148</tr>
149</tbody>
150</table>
151
152### 使用说明<a name="section129654513264"></a>
153
154该仓核心功能是提供Input驱动能力接口供上层输入系统服务调用,提供的驱动能力接口统一归属为HDI接口层。
155
156通过如下简要示例代码说明Input HDI接口的使用:
157
158```
159#include "input_manager.h"
160#define DEV_INDEX 1
161
162IInputInterface *g_inputInterface;
163InputReportEventCb g_callback;
164
165/* 定义数据上报的回调函数 */
166static void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count)
167{
168    if (pkgs == NULL || count > MAX_PKG_NUM) {
169        return;
170    }
171    for (uint32_t i = 0; i < count; i++) {
172        HDF_LOGI("%s: pkgs[%d] = 0x%x, 0x%x, %d", __func__, i, pkgs[i]->type, pkgs[i]->code, pkgs[i]->value);
173    }
174}
175
176int InputServiceSample(void)
177{
178    uint32_t devType = INIT_DEFAULT_VALUE;
179
180    /* 获取Input驱动能力接口 */
181    int ret = GetInputInterface(&g_inputInterface);
182    if (ret != INPUT_SUCCESS) {
183        HDF_LOGE("%s: get input interfaces failed, ret = %d", __func__, ret);
184        return ret;
185    }
186
187    INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
188    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
189    /* 打开特定的input设备 */
190    ret = g_inputInterface->iInputManager->OpenInputDevice(DEV_INDEX);
191    if (ret) {
192        HDF_LOGE("%s: open input device failed, ret = %d", __func__, ret);
193 	return ret;
194    }
195
196    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
197    /* 获取对应input设备的类型 */
198    ret = g_inputInterface->iInputController->GetDeviceType(DEV_INDEX, &devType);
199    if (ret) {
200        HDF_LOGE("%s: get device type failed, ret: %d", __FUNCTION__, ret);
201        return ret;
202    }
203    HDF_LOGI("%s: device1's type is %u\n", __FUNCTION__, devType);
204
205    /* 给特定的input设备注册数据上报回调函数 */
206    g_callback.ReportEventPkgCallback = ReportEventPkgCallback;
207    INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR);
208    ret  = g_inputInterface->iInputReporter->RegisterReportCallback(DEV_INDEX, &g_callback);
209    if (ret) {
210        HDF_LOGE("%s: register callback failed, ret: %d", __FUNCTION__, ret);
211	return ret;
212    }
213    HDF_LOGI("%s: wait 10s for testing, pls touch the panel now", __FUNCTION__);
214    OsalMSleep(KEEP_ALIVE_TIME_MS);
215
216    /* 注销特定input设备上的回调函数 */
217    ret  = g_inputInterface->iInputReporter->UnregisterReportCallback(DEV_INDEX);
218    if (ret) {
219        HDF_LOGE("%s: unregister callback failed, ret: %d", __FUNCTION__, ret);
220        return ret;
221    }
222
223    /* 关闭特定的input设备 */
224    ret = g_inputInterface->iInputManager->CloseInputDevice(DEV_INDEX);
225    if (ret) {
226        HDF_LOGE("%s: close device failed, ret: %d", __FUNCTION__, ret);
227	return ret;
228    }
229    return 0;
230}
231```
232
233## 相关仓<a name="section1371113476307"></a>
234
235[驱动子系统](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)
236
237[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
238
239[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
240
241[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
242
243[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral)
244
245