input
Introduction
This 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:
- Input Manager: manages input devices, including enabling and disabling input devices and obtaining the device list.
- Input Reporter: reports input events, including registering and unregistering data reporting callbacks.
- Input Controller: controls input devices, including obtaining the device information and device type, and setting power supply status.
Figure 1 HDI architecture of the input module

Directory Structure
The source code directory structure is as follows:
/drivers/peripheral/input
├── hal # HAL code
│ └── include # HAL header files
│ └── src # HAL code implementation
├── interfaces # Driver capability APIs provided for upper-layer services
│ └── include # APIs exposed externally
├── test # Test code
│ └── unittest # Unit test code
Available APIs
The 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.
Table 1 describes major HDI APIs provided by the input module.
Table 1 Major HDI APIs of the input module
Usage Guidelines
The core function of this repository is to provide HDIs for upper-layer input system services to implement input driver capabilities.
The following sample code describes how to use the input HDIs:
#include "input_manager.h"
#define DEV_INDEX 1
IInputInterface *g_inputInterface;
InputReportEventCb g_callback;
/* Define the callback for data reporting. */
static void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count)
{
if (pkgs == NULL || count > MAX_PKG_NUM) {
return;
}
for (uint32_t i = 0; i < count; i++) {
HDF_LOGI("%s: pkgs[%d] = 0x%x, 0x%x, %d", __func__, i, pkgs[i]->type, pkgs[i]->code, pkgs[i]->value);
}
}
int InputServiceSample(void)
{
uint32_t devType = INIT_DEFAULT_VALUE;
/* Get interfaces of input driver capabilities. */
int ret = GetInputInterface(&g_inputInterface);
if (ret != INPUT_SUCCESS) {
HDF_LOGE("%s: get input interfaces failed, ret = %d", __func__, ret);
return ret;
}
INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
/* Open a specified input device file. */
ret = g_inputInterface->iInputManager->OpenInputDevice(DEV_INDEX);
if (ret) {
HDF_LOGE("%s: open input device failed, ret = %d", __func__, ret);
return ret;
}
INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
/* Get the type of the input device. */
ret = g_inputInterface->iInputController->GetDeviceType(DEV_INDEX, &devType);
if (ret) {
HDF_LOGE("%s: get device type failed, ret: %d", __FUNCTION__, ret);
return ret;
}
HDF_LOGI("%s: device1's type is %u\n", __FUNCTION__, devType);
/* Register the data reporting callback for a specified input device. */
g_callback.ReportEventPkgCallback = ReportEventPkgCallback;
INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR);
ret = g_inputInterface->iInputReporter->RegisterReportCallback(DEV_INDEX, &g_callback);
if (ret) {
HDF_LOGE("%s: register callback failed, ret: %d", __FUNCTION__, ret);
return ret;
}
HDF_LOGI("%s: wait 10s for testing, pls touch the panel now", __FUNCTION__);
OsalMSleep(KEEP_ALIVE_TIME_MS);
/* Unregister the callback of the specified input device. */
ret = g_inputInterface->iInputReporter->UnregisterReportCallback(DEV_INDEX);
if (ret) {
HDF_LOGE("%s: unregister callback failed, ret: %d", __FUNCTION__, ret);
return ret;
}
/* Close a specified input device file. */
ret = g_inputInterface->iInputManager->CloseInputDevice(DEV_INDEX);
if (ret) {
HDF_LOGE("%s: close device failed, ret: %d", __FUNCTION__, ret);
return ret;
}
return 0;
}