1 Star 0 Fork 982

wawanala / drivers_peripheral

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 15.25 KB
一键复制 编辑 原始数据 按行查看 历史
王勃懿 提交于 2023-04-24 09:15 . fix:modify dead url

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

Header File

API

Description

input_manager.h

int32_t (*OpenInputDevice)(uint32_t devIndex);

Opens a specified input device file.

int32_t (*CloseInputDevice)(uint32_t devIndex);

Closes a specified input device file.

int32_t (*GetInputDevice)(uint32_t devIndex, DeviceInfo **devInfo);

Gets information about a specified input device.

int32_t (*GetInputDeviceList)(uint32_t *devNum, DeviceInfo **devList, uint32_t size);

Gets information about all input devices in the device list.

input_reporter.h

int32_t (*RegisterReportCallback)(uint32_t devIndex, InputReportEventCb *callback);

Registers a callback for reporting subscribed data of specified input devices.

int32_t (*UnregisterReportCallback)(uint32_t devIndex);

Unregisters the callback for reporting subscribed data of specified input devices.

void (*ReportEventPkgCallback)(const EventPackage **pkgs, uint32_t count);

Reports input event data by the registered callback.

input_controller.h

int32_t (*SetPowerStatus)(uint32_t devIndex, uint32_t status);

Sets the power status.

int32_t (*GetPowerStatus)(uint32_t devIndex, uint32_t *status);

Gets the power status.

int32_t (*GetDeviceType)(uint32_t devIndex, uint32_t *deviceType);

Gets the type of the input device based on the specified device index.

int32_t (*GetChipInfo)(uint32_t devIndex, char *chipInfo, uint32_t length);

Gets the chip information of the specified device.

int32_t (*GetVendorName)(uint32_t devIndex, char *vendorName, uint32_t length);

Gets the module vendor name of the specified device.

int32_t (*GetChipName)(uint32_t devIndex, char *chipName, uint32_t length);

Gets the driver chip name of the specified device.

int32_t (*SetGestureMode)(uint32_t devIndex, uint32_t gestureMode);

Sets the gesture mode.

int32_t (*RunCapacitanceTest)(uint32_t devIndex, uint32_t testType, char *result, uint32_t length);

Conducts a capacitance self-test.

int32_t (*RunExtraCommand)(uint32_t devIndex, InputExtraCmd *cmd);

Executes the specified extra command.

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;
}

Repositories Involved

Driver subsystem

drivers_framework

drivers_adapter

drivers_adapter_khdf_linux

drivers_peripheral

1
https://gitee.com/wawanala/drivers_peripheral.git
git@gitee.com:wawanala/drivers_peripheral.git
wawanala
drivers_peripheral
drivers_peripheral
master

搜索帮助