From 36be8e70fafe6286e01ce06fca6e5dbff5071caf Mon Sep 17 00:00:00 2001 From: shawn_he Date: Tue, 7 Jun 2022 13:57:26 +0800 Subject: [PATCH] update docs Signed-off-by: shawn_he --- en/device_api/hdi/usb/usb_info.h | 149 +++++++ en/device_api/hdi/usb/usbd_client.h | 537 ++++++++++++++++++++++++ en/device_api/hdi/usb/usbd_subscriber.h | 131 ++++++ en/device_api/hdi/usb/usbd_type.h | 144 +++++++ 4 files changed, 961 insertions(+) create mode 100644 en/device_api/hdi/usb/usb_info.h create mode 100644 en/device_api/hdi/usb/usbd_client.h create mode 100644 en/device_api/hdi/usb/usbd_subscriber.h create mode 100644 en/device_api/hdi/usb/usbd_type.h diff --git a/en/device_api/hdi/usb/usb_info.h b/en/device_api/hdi/usb/usb_info.h new file mode 100644 index 00000000..4a89e842 --- /dev/null +++ b/en/device_api/hdi/usb/usb_info.h @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup USB + * @{ + * + * @brief Defines the standard APIs of the USB function. + * + * This module declares the custom data types and functions used to obtain descriptors, interface objects, and request objects, and to submit requests. + * + * @since 3.0 + * @version 1.0 + */ + +/** + * @file usb_info.h + * + * @brief Declares the data types used by the USB driver service subscriber. + * + * @since 3.0 + * @version 1.0 + */ + +#ifndef USB_INFO_H +#define USB_INFO_H + +#include +#include + +namespace OHOS { +namespace USB { +/** + * @brief Defines the USB device information. + * + */ +struct USBDeviceInfo { + /** USB device status */ + int32_t status; + /** USB bus ID */ + int32_t busNum; + /** USB device ID */ + int32_t devNum; +}; + +/** + * @brief Defines the USB device information. + * + */ +class UsbInfo { +public: + /** + * @brief Sets USB device status. + * + * @param status USB device status. + * + * @since 3.0 + * @version 1.0 + */ + void setDevInfoStatus(int32_t status) + { + devInfo.status = status; + } + + /** + * @brief Sets the USB bus ID. + * + * @param busNum USB bus ID. + * + * @since 3.0 + * @version 1.0 + */ + void setDevInfoBusNum(int32_t busNum) + { + devInfo.busNum = busNum; + } + + /** + * @brief Sets the USB device ID. + * + * @param devNum USB device ID. + * + * @since 3.0 + * @version 1.0 + */ + void setDevInfoDevNum(int32_t devNum) + { + devInfo.devNum = devNum; + } + + /** + * @brief Obtains the USB device status. + * + * @param status USB device status. + * + * @since 3.0 + * @version 1.0 + */ + int32_t getDevInfoStatus() const + { + return devInfo.status; + } + + /** + * @brief Obtains the USB bus ID. + * + * @param busNum USB bus ID. + * + * @since 3.0 + * @version 1.0 + */ + int32_t getDevInfoBusNum() const + { + return devInfo.busNum; + } + + /** + * @brief Obtains the USB device ID. + * + * @param devNum USB device ID. + * + * @since 3.0 + * @version 1.0 + */ + int32_t getDevInfoDevNum() const + { + return devInfo.devNum; + } + +private: + /** USB device information */ + USBDeviceInfo devInfo; +}; +} /** namespace USB */ +} /** namespace OHOS */ + +#endif /** USBMGR_USB_INFO_H */ diff --git a/en/device_api/hdi/usb/usbd_client.h b/en/device_api/hdi/usb/usbd_client.h new file mode 100644 index 00000000..1227219d --- /dev/null +++ b/en/device_api/hdi/usb/usbd_client.h @@ -0,0 +1,537 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup USB + * @{ + * + * @brief Defines the standard APIs of the USB function. + * + * This module declares the custom data types and functions used to obtain descriptors, interface objects, and request objects, and to submit requests. + * + * @since 3.0 + * @version 1.0 + */ + +/** + * @file usbd_client.h + * + * @brief Declares the standard USB driver APIs. + * + * @since 3.0 + * @version 1.0 + */ + +#ifndef USBD_CLIENT_H +#define USBD_CLIENT_H + +#include "usb_param.h" +#include "usbd_subscriber.h" + +namespace OHOS { +namespace USB { +class UsbdClient { +public: + static UsbdClient &GetInstance(); + + /** + * @brief Opens a USB device to set up a connection. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t OpenDevice(const UsbDev &dev); + + /** + * @brief Closes a USB device to release all system resources related to the device. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t CloseDevice(const UsbDev &dev); + + /** + * @brief Obtains the USB device descriptor. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param descriptor USB device descriptor. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t GetDeviceDescriptor(const UsbDev &dev, std::vector &descriptor); + + /** + * @brief Obtains the string descriptor of a USB device based on the specified string ID. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param descId USB string ID. + * @param descriptor String descriptor used to obtain the USB device configuration. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t GetStringDescriptor(const UsbDev &dev, uint8_t descId, std::vector &descriptor); + + /** + * @brief Obtains the configuration descriptor of a USB device based on the specified configuration ID. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param descId USB configuration ID. + * @param descriptor Configuration descriptor used to obtain the USB device configuration. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t GetConfigDescriptor(const UsbDev &dev, uint8_t descId, std::vector &descriptor); + + /** + * @brief Obtains the raw descriptor. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param descriptor Raw descriptor of the USB device. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t GetRawDescriptor(const UsbDev &dev, std::vector &descriptor); + + /** + * @brief Obtains the file descriptor. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param fd File descriptor of the USB device. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t GetFileDescriptor(const UsbDev &dev, int32_t &fd); + + /** + * @brief Sets the USB device configuration. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param configIndex Index of the USB device configuration. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t SetConfig(const UsbDev &dev, uint8_t configIndex); + + /** + * @brief Obtains the USB device configuration. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param configIndex Index of the USB device configuration. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t GetConfig(const UsbDev &dev, uint8_t &configIndex); + + /** + * @brief Claims a USB interface exclusively. This must be done before data transfer. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param interfaceid USB interface ID. + * @param force Whether to perform the operation forcibly. The value **1"" means to perform the operation forcibly, and the value **0** indicates the opposite. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t ClaimInterface(const UsbDev &dev, uint8_t interfaceid, uint8_t force); + + /** + * @brief Releases a USB interface. This is usually done after data transfer. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param interfaceid USB interface ID. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t ReleaseInterface(const UsbDev &dev, uint8_t interfaceid); + + /** + * @brief Sets the alternate settings for the specified USB interface. This allows you to switch between two interfaces with the same ID but different alternate settings. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param interfaceid USB interface ID. + * @param altIndex Index of the alternate settings of the USB interface. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * @since 3.0 + * @version 1.0 + */ + int32_t SetInterface(const UsbDev &dev, uint8_t interfaceid, uint8_t altIndex); + + /** + * @brief Reads data on a specified endpoint during bulk transfer. The endpoint must be in the data reading direction. You can specify a timeout duration if needed. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param timeout Timeout interval. + * @param data Data to be read. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t BulkTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector &data); + + /** + * @brief Writes data on a specified endpoint during bulk transfer. The endpoint must be in the data writing direction. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param timeout Timeout interval. + * @param data Data to be written. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t BulkTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, + const std::vector &data); + + /** + * @brief Performs control transfer for endpoint 0 of the device. The data transfer direction is determined by the request type. If the result of requestType& + * USB_ENDPOINT_DIR_MASK is USB_DIR_OUT, the endpoint is in the data writing direction; if the result is USB_DIR_IN, the endpoint is in the data reading direction. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param ctrl Control data packet structure. For details, see {@link UsbCtrlTransfer}. + * @param data Data to be read or written. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t ControlTransfer(const UsbDev &dev, const UsbCtrlTransfer &ctrl, std::vector &data); + + /** + * @brief Reads data on a specified endpoint during interrupt transfer. The endpoint must be in the data reading direction. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param timeout Timeout interval. + * @param data Data to be read. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t InterruptTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector &data); + + /** + * @brief Writes data on a specified endpoint during interrupt transfer. The endpoint must be in the data writing direction. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param timeout Timeout interval. + * @param data Data to be written. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t InterruptTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector &data); + + /** + * @brief Reads data on a specified endpoint during isochronous transfer. The endpoint must be in the data reading direction. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param timeout Timeout interval. + * @param data Data to be read. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t IsoTransferRead(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector &data); + + /** + * @brief Writes data on a specified endpoint during isochronous transfer. The endpoint must be in the data writing direction. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param timeout Timeout interval. + * @param data Data to be read. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t IsoTransferWrite(const UsbDev &dev, const UsbPipe &pipe, int32_t timeout, std::vector &data); + + /** + * @brief Sends or receives requests for isochronous transfer on a specified endpoint. The data transfer direction is determined by the endpoint direction. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param clientData Client data. + * @param buffer Buffer for data transfer. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t RequestQueue(const UsbDev &dev, const UsbPipe &pipe, const std::vector &clientData, + const std::vector &buffer); + + /** + * @brief Waits for the operation result of the isochronous transfer request in RequestQueue. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param clientData Client data. + * @param buffer Buffer for data transfer. + * @param timeout Timeout interval. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t RequestWait(const UsbDev &dev, std::vector &clientData, std::vector &buffer, + int32_t timeout); + + /** + * @brief Cancels the data transfer requests to be processed. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t RequestCancel(const UsbDev &dev, const UsbPipe &pipe); + + /** + * @brief Obtains the list of functions (represented by bit field) supported by the current USB device. + * + * @param funcs List of functions supported by the current USB device. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t GetCurrentFunctions(int32_t &funcs); + + /** + * @brief Sets the list of functions (represented by bit field) supported by the current USB device. + * + * @param funcs List of functions supported by the current USB device. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t SetCurrentFunctions(int32_t funcs); + + /** + * @brief Sets the role of a port. + * + * @param portId Port ID. + * @param powerRole Power role. + * @param dataRole Data role. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t SetPortRole(int32_t portId, int32_t powerRole, int32_t dataRole); + + /** + * @brief Queries the current settings of a port. + * + * @param portId Port ID. + * @param powerRole Power role. + * @param dataRole Data role. + * @param mode Port mode. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t QueryPort(int32_t &portId, int32_t &powerRole, int32_t &dataRole, int32_t &mode); + + /** + * @brief Binds a subscriber. + * + * @param subscriber Subscriber to bind. For details, see {@link UsbdSubscriber}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t BindUsbdSubscriber(const sptr &subscriber); + + /** + * @brief Unbinds a subscriber. + * + * @param subscriber Subscriber to unbind. For details, see {@link UsbdSubscriber}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t UnbindUsbdSubscriber(const sptr &subscriber); + + /** + * @brief Registers a callback for isochronous bulk transfer. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param cb Reference to the callback. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t RegBulkCallback(const UsbDev &dev, const UsbPipe &pipe, const sptr &cb); + + /** + * @brief Unregisters the callback for isochronous bulk transfer. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t UnRegBulkCallback(const UsbDev &dev, const UsbPipe &pipe); + + /** + * @brief Reads data during isochronous bulk transfer. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param ashmem Shared memory, which is used to store the read data. For details, see {@link Ashmem}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t BulkRead(const UsbDev &dev, const UsbPipe &pipe, sptr &ashmem); + + /** + * @brief Writes data during isochronous bulk transfer. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * @param ashmem Shared memory, which is used to store the written data. For details, see {@link Ashmem}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t BulkWrite(const UsbDev &dev, const UsbPipe &pipe, sptr &ashmem); + + /** + * @brief Cancels the isochronous bulk transfer. The read and write operations on the current USB interface will be cancelled. + * + * @param dev USB device address. For details, see {@link UsbDev}. + * @param pipe USB device pipe. For details, see {@link UsbPipe}. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t BulkCancel(const UsbDev &dev, const UsbPipe &pipe); +}; +} /** namespace USB */ +} /** namespace OHOS */ +#endif // USBD_CLIENT_H diff --git a/en/device_api/hdi/usb/usbd_subscriber.h b/en/device_api/hdi/usb/usbd_subscriber.h new file mode 100644 index 00000000..fa9c38ee --- /dev/null +++ b/en/device_api/hdi/usb/usbd_subscriber.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup USB + * @{ + * + * @brief Defines the standard APIs of the USB function. + * + * This module declares the custom data types and functions used to obtain descriptors, interface objects, and request objects, and to submit requests. + * + * @since 3.0 + * @version 1.0 + */ + +/** + * @file usbd_subscriber.h + * + * @brief Declares a USB driver service subscriber. + * + * @since 3.0 + * @version 1.0 + */ + +#ifndef USBD_SUBSCRIBER_H +#define USBD_SUBSCRIBER_H + +#include "ipc_object_stub.h" +#include "usb_info.h" +#include "usbd_type.h" + +namespace OHOS { +namespace USB { +class UsbdSubscriber : public IPCObjectStub { +public: + explicit UsbdSubscriber() : IPCObjectStub(u"ohos.usb.IUsbManagerSubscriber") {}; + virtual ~UsbdSubscriber() = default; + + /** + * @brief Subscribes to USB device events. + * + * @param UsbInfo USB device information. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + virtual int32_t DeviceEvent(const UsbInfo &info) = 0; + + /** + * @brief Subscribes to port change events. + * + * @param portId Port ID. + * @param powerRole Power role. + * @param dataRole Data role. + * @param mode Port mode. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + virtual int32_t PortChangedEvent(int32_t portId, int32_t powerRole, int32_t dataRole, int32_t mode) = 0; + + /** + * @brief Initiates a remote request. + * + * @param code Command word. + * @param data Data to be parsed. + * @param reply Response data. + * @param option Option data. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + /** + * @brief Parses USB device information. + * + * @param code Command word. + * @param reply Response data. + * @param option Option data. + * @param info USB device information. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + static int32_t ParserUsbInfo(MessageParcel &data, MessageParcel &reply, MessageOption &option, UsbInfo &info); + + /** + * @brief Parses USB device port information. + * + * @param code Command word. + * @param reply Response data. + * @param option Option data. + * @param info USB device port information. + * + * @return **0**: The operation is successful. + * @return A non-0 value: The operation has failed. + * + * @since 3.0 + * @version 1.0 + */ + static int32_t ParserPortInfo(MessageParcel &data, MessageParcel &reply, MessageOption &option, PortInfo &info); +}; +} /** namespace USB */ +} /** namespace OHOS */ +#endif /** USBD_SUBSCRIBER_H */ diff --git a/en/device_api/hdi/usb/usbd_type.h b/en/device_api/hdi/usb/usbd_type.h new file mode 100644 index 00000000..554e6076 --- /dev/null +++ b/en/device_api/hdi/usb/usbd_type.h @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup USB + * @{ + * + * @brief Defines the standard APIs of the USB function. + * + * This module declares the custom data types and functions used to obtain descriptors, interface objects, and request objects, and to submit requests. + * + * @since 3.0 + * @version 1.0 + */ + +/** + * @file usbd_type.h + * + * @brief Declares the custom data types used in the APIs of the USB driver module. + * + * Such data types include command words and data directions. + * + * @since 3.0 + * @version 1.0 + */ + +#ifndef USBD_TYPE_H +#define USBD_TYPE_H + +#include +#include +#include +#include + +/** Maximum number of USB interfaces */ +#define USB_MAX_INTERFACES 32 + +/** Bit mask for extracting the USB Endpoint direction from the address */ +static const int32_t USB_ENDPOINT_DIR_MASK = 0x80; + +/** Data direction of the USB Endpoint from the device to the host */ +static const int32_t USB_ENDPOINT_DIR_IN = 0x80; + +/** Data direction of the USB Endpoint from the host to the device */ +static const int32_t USB_ENDPOINT_DIR_OUT = 0; + +/** Request callback */ +typedef void (*UsbdRequestCallback)(uint8_t *requestArg); + +/** + * @brief Defines the command word for bulk callback. + * + */ +enum UsbdBulkCbCmd { + /** Bulk callback reading */ + CMD_USBD_BULK_CALLBACK_READ, + /** Bulk callback writing */ + CMD_USBD_BULK_CALLBACK_WRITE, +}; + +/** + * @brief Defines hot swap events of the USB host and device. + * + */ +enum UsbdDeviceAction { + /** Device connected to the host */ + ACT_DEVUP = 0, + /** Device removed from the host */ + ACT_DEVDOWN, + /** Device connected */ + ACT_UPDEVICE, + /** Device disconnected */ + ACT_DOWNDEVICE, +}; + +namespace OHOS { +namespace USB { +/** + * @brief Defines a USB device. + * + */ +struct UsbDev { + /** USB bus ID */ + uint8_t busNum; + /** USB device address */ + uint8_t devAddr; +}; + +/** + * @brief Defines a USB pipe. + * + */ +struct UsbPipe { + /** USB interface ID */ + uint8_t interfaceId; + /** USB endpoint ID */ + uint8_t endpointId; +}; + +/** + * @brief Performs USB control transfer. + * + */ +struct UsbCtrlTransfer { + /** Request type */ + int32_t requestType; + /** Request command word */ + int32_t requestCmd; + /** Request value */ + int32_t value; + /** Index */ + int32_t index; + /** Timeout interval */ + int32_t timeout; +}; + +/** + * @brief Defines the USB device information. + * + */ +struct USBDeviceInfo { + /** USB device status */ + int32_t status; + /** USB bus ID */ + int32_t busNum; + /** USB device ID */ + int32_t devNum; +}; +} /** namespace USB */ +} /** namespace OHOS */ + +#endif /** USBD_TYPE_H */ -- Gitee