1/* 2 * Copyright (c) 2022 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 16/* * 17 * @addtogroup HdiUsb 18 * @{ 19 * 20 * @brief Provides unified APIs for usb services to access usb drivers. 21 * 22 * A usb service can obtain a usb driver object or agent and then call APIs provided by this object or agent to 23 * access different types of usb devices based on the usb IDs, thereby obtaining usb information, 24 * subscribing to or unsubscribing from usb data, enabling or disabling a usb, 25 * setting the usb data reporting mode, and setting usb options such as the accuracy and measurement range. 26 * 27 * @since 5.0 28 */ 29 30/* * 31 * @file IUsbInterface.idl 32 * 33 * @brief Declares the APIs provided by the usb module for obtaining usb information, subscribing to or 34 * unsubscribing from usb data, enabling or disabling a usb, setting the usb data reporting mode, 35 * and setting usb options such as the accuracy and measurement range. 36 * 37 * @since 5.0 38 * @version 1.1 39 */ 40 41package ohos.hdi.usb.v1_1; 42 43import ohos.hdi.usb.v1_1.UsbTypes; 44import ohos.hdi.usb.v1_0.UsbTypes; 45import ohos.hdi.usb.v1_0.IUsbdSubscriber; 46import ohos.hdi.usb.v1_0.IUsbdBulkCallback; 47import ohos.hdi.usb.v1_0.IUsbInterface; 48 49/* * 50 * @brief Defines the functions for performing basic operations on usb. 51 * 52 * The operations include obtaining usb information, subscribing to or unsubscribing from usb data, 53 * enabling or disabling a usb, setting the usb data reporting mode, and setting usb options such as 54 * the accuracy and measurement range. 55 */ 56interface IUsbInterface extends ohos.hdi.usb.v1_0.IUsbInterface{ 57 58 /* * 59 * @brief Obtain the activation information of the USB device interface. 60 * 61 * @param dev Indicates the USB device address. 62 * @param interfaceid Indicates the interface ID of the USB device. 63 * @param unactivated Indicates whether the interface unactivated. 64 * 65 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 66 * @since 5.0 67 */ 68 GetInterfaceActiveStatus ([in] struct UsbDev dev, [in] unsigned char interfaceid, [out] boolean unactivated ); 69 70 /* * 71 * @brief Obtains USB device speed. 72 * 73 * @param dev Indicates the USB device address. 74 * @param speed Indicates the USB device speed. 75 * 76 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 77 * @since 5.0 78 */ 79 GetDeviceSpeed ([in] struct UsbDev dev, [out] unsigned char speed ); 80 81 /* * 82 * @brief Obtains the file descriptor. 83 * 84 * @param dev Indicates the USB device address. 85 * @param fd USB device file descriptor 86 * 87 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 88 * @since 5.0 89 * @version 1.0 90 */ 91 GetDeviceFileDescriptor([in] struct UsbDev dev, [out] FileDescriptor fd); 92 93 /* * 94 * @brief Reads data on a specified endpoint during bulk transfer. The endpoint must be in the data reading 95 * direction. You can specify a timeout duration if needed. 96 * 97 * @param dev Indicates the USB device address. 98 * @param pipe Indicates the pipe of the USB device. 99 * @param timeout Indicates the timeout duration. 100 * @param length the maximum number of bytes to receive into the data buffer. 101 * @param data Indicates the read data. 102 * 103 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 104 * @since 5.0 105 * @version 1.0 106 */ 107 BulkTransferReadwithLength([in] struct UsbDev dev, [in] struct UsbPipe pipe, [in] int timeout, [in] int length, [out] unsigned char[] data); 108 109 /* * 110 * @brief Performs control transfer for endpoint 0 of the device. The data transfer direction is determined by the 111 * request type. If the result of <b>requestType</b>& 112 * <b>USB_ENDPOINT_DIR_MASK</b> is <b>USB_DIR_OUT</b>, the endpoint is in the data writing direction; if the result 113 * is <b>USB_DIR_IN</b>, the endpoint is in the data reading direction. 114 * 115 * @param dev Indicates the USB device address. 116 * @param ctrl Indicates the control data packet structure. 117 * @param data Indicates the read data. 118 * 119 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 120 * @since 5.0 121 * @version 1.0 122 */ 123 ControlTransferReadwithLength([in] struct UsbDev dev, [in] struct UsbCtrlTransferParams ctrl, [out] unsigned char[] data); 124 125 /* * 126 * @brief Get Accessory Info. 127 * 128 * @param accessoryInfo Indicates the accessory information. 129 * 130 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 131 * @since 5.0 132 * @version 1.0 133 */ 134 GetAccessoryInfo([out] String[] accessoryInfo); 135 136 /* * 137 * @brief Open the Accessory descriptor. 138 * 139 * @param fd accessory file descriptor. 140 * 141 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 142 * @since 5.0 143 * @version 1.0 144 */ 145 OpenAccessory([out] FileDescriptor fd); 146 147 /* * 148 * @brief Close the Accessory descriptor. 149 * 150 * @param fd accessory file descriptor. 151 * 152 * @return Returns <b>0</b> if the operation is successful; returns a non-0 value if the operation fails. 153 * @since 5.0 154 * @version 1.0 155 */ 156 CloseAccessory([in] FileDescriptor fd); 157}