• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# input<a name="EN-US_TOPIC_0000001124789109"></a>
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section161941989596)
5    -   [Available APIs](#section1551164914237)
6    -   [Usage Guidelines](#section129654513264)
7
8-   [Repositories Involved](#section1371113476307)
9
10## Introduction<a name="section11660541593"></a>
11
12This repository mainly defines and implements the following types of Hardware Driver Interfaces \(HDIs\) of the input module, allowing upper-layer input services to perform operations for the input devices:
13
14-   **Input Manager**: manages input devices, including enabling and disabling input devices and obtaining the device list.
15-   **Input Reporter**: reports input events, including registering and unregistering data reporting callbacks.
16-   **Input Controller**: controls input devices, including obtaining the device information and device type, and setting power supply status.
17
18**Figure  1**  HDI architecture of the input module<a name="fig9489629122818"></a>
19![](figures/hdi-architecture-of-the-input-module.png "hdi-architecture-of-the-input-module")
20
21## Directory Structure<a name="section161941989596"></a>
22
23The source code directory structure is as follows:
24
25```
26/drivers/peripheral/input
27├── hal                # HAL code
28│   └── include       # HAL header files
29│   └── src           # HAL code implementation
30├── interfaces         # Driver capability APIs provided for upper-layer services
31│   └── include       # APIs exposed externally
32├── test               # Test code
33│   └── unittest      # Unit test code
34```
35
36### Available APIs<a name="section1551164914237"></a>
37
38The input driver provides input services with driver capability APIs that can be directly called. The APIs involve the Input Manager module, Input Reporter module, and Input Controller module. For example, you can call the APIs to enable or disable an input device, register a listener callback, query the device information, and control the power status.
39
40[Table 1](#table1513255710559)  describes major HDI APIs provided by the input module.
41
42**Table  1**  Major HDI APIs of the input module
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>Header File</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>API</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>Description</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>Opens a specified input device file.</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>Closes a specified input device file.</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>Gets information about a specified input device.</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>Gets information about all input devices in the device list.</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>Registers a callback for reporting subscribed data of specified input devices.</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>Unregisters the callback for reporting subscribed data of specified input devices.</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>Reports input event data by the registered callback.</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>Sets the power status.</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>Gets the power status.</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>Gets the type of the input device based on the specified device index.</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>Gets the chip information of the specified device.</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>Gets the module vendor name of the specified device.</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>Gets the driver chip name of the specified device.</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>Sets the gesture mode.</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>Conducts a capacitance self-test.</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>Executes the specified extra command.</p>
147</td>
148</tr>
149</tbody>
150</table>
151
152### Usage Guidelines<a name="section129654513264"></a>
153
154The core function of this repository is to provide HDIs for upper-layer input system services to implement input driver capabilities.
155
156The following sample code describes how to use the input HDIs:
157
158```
159#include "input_manager.h"
160#define DEV_INDEX 1
161
162IInputInterface *g_inputInterface;
163InputReportEventCb g_callback;
164
165/* Define the callback for data reporting. */
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    /* Get interfaces of input driver capabilities. */
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    /* Open a specified input device file. */
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    /* Get the type of the input device. */
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    /* Register the data reporting callback for a specified input device. */
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    /* Unregister the callback of the specified input device. */
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    /* Close a specified input device file. */
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## Repositories Involved<a name="section1371113476307"></a>
234
235[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md)
236
237[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
238
239[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
240
241[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
242
243[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral)
244
245