1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HID_DDK_API_H 16 #define HID_DDK_API_H 17 18 /** 19 * @addtogroup HidDdk 20 * @{ 21 * 22 * @brief Provides HID DDK interfaces, including creating a device, sending an event, and destroying a device. 23 * 24 * @syscap SystemCapability.Driver.HID.Extension 25 * @since 11 26 * @version 1.0 27 */ 28 29 /** 30 * @file hid_ddk_api.h 31 * 32 * @brief Declares the HID DDK interfaces for the host to access an input device. 33 * 34 * @kit DriverDevelopmentKit 35 * File to include: <hid/hid_ddk_api.h> 36 * @since 11 37 * @version 1.0 38 */ 39 40 #include <stdint.h> 41 #include "hid_ddk_types.h" 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif /* __cplusplus */ 46 47 /** 48 * @brief Creates a device. 49 * 50 * @permission ohos.permission.ACCESS_DDK_HID 51 * @param hidDevice Pointer to the basic information required for creating a device, including the device name, 52 * vendor ID, and product ID. 53 * @param hidEventProperties Pointer to the events of the device to be observed, including the event type and 54 * properties of the key event, absolute coordinate event, and relative coordinate event. 55 * @return device ID (a non-negative number), if the operation is successful; 56 * {@link HID_DDK_NO_PERM} permission check failed. 57 * {@link HID_DDK_INVALID_OPERATION} connect hid ddk service failed. 58 * {@link HID_DDK_INVALID_PARAMETER} parameter check failed. Possible causes: 1.hidDevice is null;\n 59 * 2.hidEventProperties is null; 3.properties length exceeds 7; 4.hidEventTypes length exceeds 5;\n 60 * 5.hidKeys length exceeds 100; 6.hidAbs length exceeds 26; 7.hidRelBits length exceeds 13;\n 61 * 8.hidMiscellaneous length exceeds 6. 62 * {@link HID_DDK_FAILURE} the number of device reaches the maximum 200. 63 * @since 11 64 * @version 1.0 65 */ 66 int32_t OH_Hid_CreateDevice(Hid_Device *hidDevice, Hid_EventProperties *hidEventProperties); 67 68 /** 69 * @brief Sends an event list to a device. 70 * 71 * @permission ohos.permission.ACCESS_DDK_HID 72 * @param deviceId ID of the device, to which the event list is sent. 73 * @param items List of events to sent. The event information includes the event type (<b>Hid_EventType</b>), 74 * event code (<b>Hid_SynEvent</b> for a synchronization event code, <b>Hid_KeyCode</b> for a key code, 75 * <b>Hid_AbsAxes</b> for an absolute coordinate code, <b>Hid_RelAxes</b> for a relative coordinate event, 76 * and <b>Hid_MscEvent</b> for other input event code), and value input by the device. 77 * @param length Length of the event list (number of events sent at a time). 78 * @return {@link HID_DDK_SUCCESS} operation successful. 79 * {@link HID_DDK_NO_PERM} permission check failed. 80 * {@link HID_DDK_INVALID_OPERATION} connect hid ddk service failed or the caller is not the creator of device. 81 * {@link HID_DDK_INVALID_PARAMETER} parameter check failed. Possible causes: 1.deviceId is less than 0;\n 82 * 2.length exceeds 7; 3.items is null. 83 * {@link HID_DDK_NULL_PTR} the inject of device is null. 84 * {@link HID_DDK_FAILURE} the device does not exit. 85 * @since 11 86 * @version 1.0 87 */ 88 int32_t OH_Hid_EmitEvent(int32_t deviceId, const Hid_EmitItem items[], uint16_t length); 89 90 /** 91 * @brief Destroys a device. 92 * 93 * @permission ohos.permission.ACCESS_DDK_HID 94 * @param deviceId ID of the device to destroy. 95 * @return {@link HID_DDK_SUCCESS} operation successful. 96 * {@link HID_DDK_NO_PERM} permission check failed. 97 * {@link HID_DDK_INVALID_OPERATION} connect hid ddk service failed or the caller is not the creator of device. 98 * {@link HID_DDK_FAILURE} the device does not exit. 99 * @since 11 100 * @version 1.0 101 */ 102 int32_t OH_Hid_DestroyDevice(int32_t deviceId); 103 104 #ifdef __cplusplus 105 } 106 #endif /* __cplusplus */ 107 108 #endif // HID_DDK_API_H 109